Back to index

glibc  2.9
test-a64l.c
Go to the documentation of this file.
00001 /* Test program for the l64a and a64l functions.
00002    Copyright (C) 2001, 2002 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Andreas Schwab <schwab@suse.de>.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include <string.h>
00024 
00025 /* Prototype for our test function.  */
00026 extern int do_test (int argc, char *argv[]);
00027 #include <test-skeleton.c>
00028 
00029 struct a64l_test
00030 {
00031   const char *base64;
00032   long int value;
00033 };
00034 
00035 static const struct a64l_test tests[] =
00036   {
00037     { "./", 64 },
00038     { "", 0 },
00039     { "/", 1 },
00040     { "FT", 2001 },
00041     { "zzzzz1", 0xffffffff },
00042     { "zzzz1", 0x3ffffff },
00043     { "zzz1", 0xfffff },
00044     { "zz1", 0x3fff },
00045     { "z1", 0xff },
00046     { "1", 0x3 },
00047     { NULL, 0 }
00048   };
00049 
00050 int
00051 do_test (int argc, char ** argv)
00052 {
00053   const struct a64l_test *at;
00054   long int l;
00055   const char *s;
00056   int status = 0;
00057 
00058   for (at = tests; at->base64 != NULL; ++at)
00059     {
00060       printf ("a64l (\"%s\")", at->base64);
00061       l = a64l (at->base64);
00062       if (l == at->value)
00063        puts ("\tOK");
00064       else
00065        {
00066          printf ("\tBAD\n  returns %ld, expected %ld\n", l, at->value);
00067          status = 1;
00068        }
00069       printf ("l64a (%ld)", at->value);
00070       s = l64a (at->value);
00071       if (strcmp (s, at->base64) == 0)
00072        puts ("\tOK");
00073       else
00074        {
00075          printf ("\tBAD\n  returns \"%s\", expected \"%s\"\n", s, at->base64);
00076          status = 1;
00077        }
00078     }
00079 
00080   return status ? EXIT_FAILURE : EXIT_SUCCESS;
00081 }