test-a64l.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /* Test program for the l64a and a64l functions.
  2. Copyright (C) 2001-2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Andreas Schwab <schwab@suse.de>.
  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. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, see
  15. <http://www.gnu.org/licenses/>. */
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. /* Prototype for our test function. */
  20. extern int do_test (int argc, char *argv[]);
  21. #include <test-skeleton.c>
  22. struct a64l_test
  23. {
  24. const char *base64;
  25. long int value;
  26. };
  27. static const struct a64l_test tests[] =
  28. {
  29. { "./", 64 },
  30. { "", 0 },
  31. { "/", 1 },
  32. { "FT", 2001 },
  33. { "zzzzz1", 0xffffffff },
  34. { "zzzz1", 0x3ffffff },
  35. { "zzz1", 0xfffff },
  36. { "zz1", 0x3fff },
  37. { "z1", 0xff },
  38. { "1", 0x3 },
  39. { NULL, 0 }
  40. };
  41. int
  42. do_test (int argc, char ** argv)
  43. {
  44. const struct a64l_test *at;
  45. long int l;
  46. const char *s;
  47. int status = 0;
  48. for (at = tests; at->base64 != NULL; ++at)
  49. {
  50. printf ("a64l (\"%s\")", at->base64);
  51. l = a64l (at->base64);
  52. if (l == at->value)
  53. puts ("\tOK");
  54. else
  55. {
  56. printf ("\tBAD\n returns %ld, expected %ld\n", l, at->value);
  57. status = 1;
  58. }
  59. printf ("l64a (%ld)", at->value);
  60. s = l64a (at->value);
  61. if (strcmp (s, at->base64) == 0)
  62. puts ("\tOK");
  63. else
  64. {
  65. printf ("\tBAD\n returns \"%s\", expected \"%s\"\n", s, at->base64);
  66. status = 1;
  67. }
  68. }
  69. return status ? EXIT_FAILURE : EXIT_SUCCESS;
  70. }