(root)/
glibc-2.38/
resolv/
tst-p_secstodate.c
       1  /* Test __p_secstodate compat symbol.
       2     Copyright (C) 2017-2023 Free Software Foundation, Inc.
       3     This file is part of the GNU C Library.
       4  
       5     The GNU C Library is free software; you can redistribute it and/or
       6     modify it under the terms of the GNU Lesser General Public
       7     License as published by the Free Software Foundation; either
       8     version 2.1 of the License, or (at your option) any later version.
       9  
      10     The GNU C Library is distributed in the hope that it will be useful,
      11     but WITHOUT ANY WARRANTY; without even the implied warranty of
      12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      13     Lesser General Public License for more details.
      14  
      15     You should have received a copy of the GNU Lesser General Public
      16     License along with the GNU C Library; if not, see
      17     <https://www.gnu.org/licenses/>.  */
      18  
      19  #include <array_length.h>
      20  #include <limits.h>
      21  #include <resolv.h>
      22  #include <stdbool.h>
      23  #include <stdio.h>
      24  #include <string.h>
      25  
      26  #include <shlib-compat.h>
      27  
      28  char *__p_secstodate (unsigned long int);
      29  compat_symbol_reference (libresolv, __p_secstodate, __p_secstodate, GLIBC_2_0);
      30  
      31  struct test
      32  {
      33    /* Argument to __p_secstodate.  */
      34    unsigned long int in;
      35    /* Expected output.  */
      36    const char *out;
      37  };
      38  
      39  static const struct test tests[] =
      40    {
      41      { 0UL, "19700101000000" },
      42      { 12345UL, "19700101032545" },
      43      { 999999999UL, "20010909014639" },
      44      { 2147483647UL, "20380119031407" },
      45      { 2147483648UL, "<overflow>" },
      46      { 4294967295UL, "<overflow>" },
      47  # if ULONG_MAX > 0xffffffffUL
      48      { 4294967296UL, "<overflow>" },
      49      { 9999999999UL, "<overflow>" },
      50      { LONG_MAX, "<overflow>" },
      51      { ULONG_MAX, "<overflow>" },
      52  # endif
      53    };
      54  
      55  static int
      56  do_test (void)
      57  {
      58    int ret = 0;
      59    for (size_t i = 0; i < array_length (tests); i++)
      60      {
      61        char *p = __p_secstodate (tests[i].in);
      62        printf ("Test %zu: %lu -> %s\n", i, tests[i].in, p);
      63        if (strcmp (p, tests[i].out) != 0)
      64  	{
      65  	  printf ("test %zu failed", i);
      66  	  ret = 1;
      67  	}
      68      }
      69    return ret;
      70  }
      71  
      72  #include <support/test-driver.c>