str: Make str_format_26adic() able to use lowercase.
[pspp] / tests / libpspp / str-test.c
index 4e3867f4d50ee3c95d8786a14ed4a8b44d104def..36d54157440a764b7311b1ac67daa977b4c0336e 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 2008 Free Software Foundation, Inc.
+   Copyright (C) 2008, 2010, 2014 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -22,9 +22,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 \f
-/* Currently running test. */
-static const char *test_name;
-
 /* Exit with a failure code.
    (Place a breakpoint on this function while debugging.) */
 static void
@@ -37,7 +34,7 @@ static void
 check_26adic (unsigned long int number, const char *expected_string)
 {
   char string[8];
-  str_format_26adic (number, string, sizeof string);
+  str_format_26adic (number, true, string, sizeof string);
   if (strcmp (string, expected_string))
     {
       printf ("base-26 of %lu: expected \"%s\", got \"%s\"\n",
@@ -47,7 +44,7 @@ check_26adic (unsigned long int number, const char *expected_string)
 }
 
 static void
-test_str_format_26adic (void)
+test_format_26adic (void)
 {
   check_26adic (0, "");
   check_26adic (1, "A");
@@ -63,21 +60,54 @@ test_str_format_26adic (void)
 \f
 /* Main program. */
 
-/* Runs TEST_FUNCTION and prints a message about NAME. */
-static void
-run_test (void (*test_function) (void), const char *name)
-{
-  test_name = name;
-  putchar ('.');
-  fflush (stdout);
-  test_function ();
-}
+struct test
+  {
+    const char *name;
+    const char *description;
+    void (*function) (void);
+  };
+
+static const struct test tests[] =
+  {
+    {
+      "format-26adic",
+      "format 26-adic strings",
+      test_format_26adic
+    }
+  };
+
+enum { N_TESTS = sizeof tests / sizeof *tests };
 
 int
-main (void)
+main (int argc, char *argv[])
 {
-  run_test (test_str_format_26adic, "format 26-adic strings");
-  putchar ('\n');
+  int i;
 
-  return 0;
+  if (argc != 2)
+    {
+      fprintf (stderr, "exactly one argument required; use --help for help\n");
+      return EXIT_FAILURE;
+    }
+  else if (!strcmp (argv[1], "--help"))
+    {
+      printf ("%s: test string library\n"
+              "usage: %s TEST-NAME\n"
+              "where TEST-NAME is one of the following:\n",
+              argv[0], argv[0]);
+      for (i = 0; i < N_TESTS; i++)
+        printf ("  %s\n    %s\n", tests[i].name, tests[i].description);
+      return 0;
+    }
+  else
+    {
+      for (i = 0; i < N_TESTS; i++)
+        if (!strcmp (argv[1], tests[i].name))
+          {
+            tests[i].function ();
+            return 0;
+          }
+
+      fprintf (stderr, "unknown test %s; use --help for help\n", argv[1]);
+      return EXIT_FAILURE;
+    }
 }