Blame stdlib/test-a64l.c

Packit 6c4009
/* Test program for the l64a and a64l functions.
Packit 6c4009
   Copyright (C) 2001-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
   Contributed by Andreas Schwab <schwab@suse.de>.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#include <stdio.h>
Packit 6c4009
#include <stdlib.h>
Packit 6c4009
#include <string.h>
Packit 6c4009
Packit 6c4009
/* Prototype for our test function.  */
Packit 6c4009
extern int do_test (int argc, char *argv[]);
Packit 6c4009
#include <test-skeleton.c>
Packit 6c4009
Packit 6c4009
struct a64l_test
Packit 6c4009
{
Packit 6c4009
  const char *base64;
Packit 6c4009
  long int value;
Packit 6c4009
};
Packit 6c4009
Packit 6c4009
static const struct a64l_test tests[] =
Packit 6c4009
  {
Packit 6c4009
    { "./", 64 },
Packit 6c4009
    { "", 0 },
Packit 6c4009
    { "/", 1 },
Packit 6c4009
    { "FT", 2001 },
Packit 6c4009
    { "zzzzz1", 0xffffffff },
Packit 6c4009
    { "zzzz1", 0x3ffffff },
Packit 6c4009
    { "zzz1", 0xfffff },
Packit 6c4009
    { "zz1", 0x3fff },
Packit 6c4009
    { "z1", 0xff },
Packit 6c4009
    { "1", 0x3 },
Packit 6c4009
    { NULL, 0 }
Packit 6c4009
  };
Packit 6c4009
Packit 6c4009
int
Packit 6c4009
do_test (int argc, char ** argv)
Packit 6c4009
{
Packit 6c4009
  const struct a64l_test *at;
Packit 6c4009
  long int l;
Packit 6c4009
  const char *s;
Packit 6c4009
  int status = 0;
Packit 6c4009
Packit 6c4009
  for (at = tests; at->base64 != NULL; ++at)
Packit 6c4009
    {
Packit 6c4009
      printf ("a64l (\"%s\")", at->base64);
Packit 6c4009
      l = a64l (at->base64);
Packit 6c4009
      if (l == at->value)
Packit 6c4009
	puts ("\tOK");
Packit 6c4009
      else
Packit 6c4009
	{
Packit 6c4009
	  printf ("\tBAD\n  returns %ld, expected %ld\n", l, at->value);
Packit 6c4009
	  status = 1;
Packit 6c4009
	}
Packit 6c4009
      printf ("l64a (%ld)", at->value);
Packit 6c4009
      s = l64a (at->value);
Packit 6c4009
      if (strcmp (s, at->base64) == 0)
Packit 6c4009
	puts ("\tOK");
Packit 6c4009
      else
Packit 6c4009
	{
Packit 6c4009
	  printf ("\tBAD\n  returns \"%s\", expected \"%s\"\n", s, at->base64);
Packit 6c4009
	  status = 1;
Packit 6c4009
	}
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  return status ? EXIT_FAILURE : EXIT_SUCCESS;
Packit 6c4009
}