Fix missing @clicksequence problem with older Texinfo versions.
[pspp-builds.git] / tests / libpspp / str-test.c
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2008 Free Software Foundation, Inc.
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program 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
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
16
17 #include <config.h>
18
19 #include <libpspp/str.h>
20
21 #include <assert.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 \f
25 /* Currently running test. */
26 static const char *test_name;
27
28 /* Exit with a failure code.
29    (Place a breakpoint on this function while debugging.) */
30 static void
31 check_die (void)
32 {
33   exit (EXIT_FAILURE);
34 }
35 \f
36 static void
37 check_26adic (unsigned long int number, const char *expected_string)
38 {
39   char string[8];
40   str_format_26adic (number, string, sizeof string);
41   if (strcmp (string, expected_string))
42     {
43       printf ("base-26 of %lu: expected \"%s\", got \"%s\"\n",
44               number, expected_string, string);
45       check_die ();
46     }
47 }
48
49 static void
50 test_str_format_26adic (void)
51 {
52   check_26adic (0, "");
53   check_26adic (1, "A");
54   check_26adic (2, "B");
55   check_26adic (26, "Z");
56   check_26adic (27, "AA");
57   check_26adic (28, "AB");
58   check_26adic (29, "AC");
59   check_26adic (18278, "ZZZ");
60   check_26adic (18279, "AAAA");
61   check_26adic (19010, "ABCD");
62 }
63 \f
64 /* Main program. */
65
66 /* Runs TEST_FUNCTION and prints a message about NAME. */
67 static void
68 run_test (void (*test_function) (void), const char *name)
69 {
70   test_name = name;
71   putchar ('.');
72   fflush (stdout);
73   test_function ();
74 }
75
76 int
77 main (void)
78 {
79   run_test (test_str_format_26adic, "format 26-adic strings");
80   putchar ('\n');
81
82   return 0;
83 }