]> git.ipfire.org Git - thirdparty/glibc.git/blame - resolv/tst-p_secstodate.c
hurd: Fix build
[thirdparty/glibc.git] / resolv / tst-p_secstodate.c
CommitLineData
754034c4 1/* Test __p_secstodate compat symbol.
04277e02 2 Copyright (C) 2017-2019 Free Software Foundation, Inc.
f120cda6
JM
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 <http://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
754034c4
JM
26#include <shlib-compat.h>
27
28#if TEST_COMPAT (libresolv, GLIBC_2_0, GLIBC_2_27)
29
30char *__p_secstodate (unsigned long int);
31compat_symbol_reference (libresolv, __p_secstodate, __p_secstodate, GLIBC_2_0);
32
f120cda6
JM
33struct test
34{
754034c4 35 /* Argument to __p_secstodate. */
f120cda6
JM
36 unsigned long int in;
37 /* Expected output. */
38 const char *out;
39};
40
41static const struct test tests[] =
42 {
43 { 0UL, "19700101000000" },
44 { 12345UL, "19700101032545" },
45 { 999999999UL, "20010909014639" },
46 { 2147483647UL, "20380119031407" },
47 { 2147483648UL, "<overflow>" },
48 { 4294967295UL, "<overflow>" },
754034c4 49# if ULONG_MAX > 0xffffffffUL
f120cda6
JM
50 { 4294967296UL, "<overflow>" },
51 { 9999999999UL, "<overflow>" },
52 { LONG_MAX, "<overflow>" },
53 { ULONG_MAX, "<overflow>" },
754034c4 54# endif
f120cda6
JM
55 };
56
57static int
58do_test (void)
59{
60 int ret = 0;
61 for (size_t i = 0; i < array_length (tests); i++)
62 {
754034c4 63 char *p = __p_secstodate (tests[i].in);
f120cda6
JM
64 printf ("Test %zu: %lu -> %s\n", i, tests[i].in, p);
65 if (strcmp (p, tests[i].out) != 0)
66 {
67 printf ("test %zu failed", i);
68 ret = 1;
69 }
70 }
71 return ret;
72}
73
754034c4
JM
74#else
75
76static int
77do_test (void)
78{
79 return 77;
80}
81
82#endif
83
f120cda6 84#include <support/test-driver.c>