1 /* Test program for the l64a and a64l functions.
2    Copyright (C) 2001-2022 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 <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 
23 /* Prototype for our test function.  */
24 extern int do_test (int argc, char *argv[]);
25 #include <test-skeleton.c>
26 
27 struct a64l_test
28 {
29   const char *base64;
30   long int value;
31 };
32 
33 static const struct a64l_test tests[] =
34   {
35     { "./", 64 },
36     { "", 0 },
37     { "/", 1 },
38     { "FT", 2001 },
39     { "zzzzz1", 0xffffffff },
40     { "zzzz1", 0x3ffffff },
41     { "zzz1", 0xfffff },
42     { "zz1", 0x3fff },
43     { "z1", 0xff },
44     { "1", 0x3 },
45     { NULL, 0 }
46   };
47 
48 int
do_test(int argc,char ** argv)49 do_test (int argc, char ** argv)
50 {
51   const struct a64l_test *at;
52   long int l;
53   const char *s;
54   int status = 0;
55 
56   for (at = tests; at->base64 != NULL; ++at)
57     {
58       printf ("a64l (\"%s\")", at->base64);
59       l = a64l (at->base64);
60       if (l == at->value)
61 	puts ("\tOK");
62       else
63 	{
64 	  printf ("\tBAD\n  returns %ld, expected %ld\n", l, at->value);
65 	  status = 1;
66 	}
67       printf ("l64a (%ld)", at->value);
68       s = l64a (at->value);
69       if (strcmp (s, at->base64) == 0)
70 	puts ("\tOK");
71       else
72 	{
73 	  printf ("\tBAD\n  returns \"%s\", expected \"%s\"\n", s, at->base64);
74 	  status = 1;
75 	}
76     }
77 
78   return status ? EXIT_FAILURE : EXIT_SUCCESS;
79 }
80