From: Ben Pfaff Date: Fri, 1 Jan 2021 06:43:57 +0000 (-0800) Subject: tests: Break off --draw-mode from render-test into ascii-test. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7c2b97b0c7172f4d6eb0b3022c56c0b61cb5f60f;p=pspp tests: Break off --draw-mode from render-test into ascii-test. My plan is for render-test to go away in favor of a comprehensive test for pivot tables, which are the only kinds of tables that actually matter. The --draw-mode tests are a different kind of beast, so it makes sense to keep them and put them in a different place. --- diff --git a/tests/automake.mk b/tests/automake.mk index cb70fd3e8e..523e570880 100644 --- a/tests/automake.mk +++ b/tests/automake.mk @@ -243,6 +243,13 @@ tests_output_render_test_LDADD = \ src/libpspp-core.la \ $(CAIRO_LIBS) +check_PROGRAMS += tests/output/ascii-test +tests_output_ascii_test_SOURCES = tests/output/ascii-test.c +tests_output_ascii_test_LDADD = \ + src/libpspp.la \ + src/libpspp-core.la \ + $(CAIRO_LIBS) + check_PROGRAMS += tests/ui/syntax-gen-test tests_ui_syntax_gen_test_SOURCES = tests/ui/syntax-gen-test.c tests_ui_syntax_gen_test_LDADD = \ diff --git a/tests/output/ascii-test.c b/tests/output/ascii-test.c new file mode 100644 index 0000000000..7c5d8a7cbd --- /dev/null +++ b/tests/output/ascii-test.c @@ -0,0 +1,225 @@ +/* PSPP - a program for statistical analysis. + Copyright (C) 2009, 2010, 2011, 2012, 2013, 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +#include +#include +#include +#include +#include + +#include "data/file-handle-def.h" +#include "libpspp/assertion.h" +#include "libpspp/compiler.h" +#include "libpspp/i18n.h" +#include "libpspp/string-map.h" +#include "output/ascii.h" +#include "output/driver.h" +#include "output/table.h" +#include "output/table-item.h" + +#include "gl/error.h" +#include "gl/progname.h" +#include "gl/xalloc.h" +#include "gl/xvasprintf.h" + +/* --emphasis: ASCII driver emphasis option. */ +static bool bold; +static bool underline; + +/* --box: ASCII driver box option. */ +static char *box; + +/* ASCII driver, for ASCII driver test mode. */ +static struct output_driver *ascii_driver; + +static const char *parse_options (int argc, char **argv); +static void usage (void) NO_RETURN; +static void draw (FILE *); + +int +main (int argc, char **argv) +{ + set_program_name (argv[0]); + i18n_init (); + output_engine_push (); + const char *input_file_name = parse_options (argc, argv); + + FILE *input = (!strcmp (input_file_name, "-") + ? stdin + : fopen (input_file_name, "r")); + if (!input) + error (1, errno, "%s: open failed", input_file_name); + + draw (input); + + if (input != stdin) + fclose (input); + + output_engine_pop (); + fh_done (); + + return 0; +} + +static struct output_driver * +configure_driver (int width, int min_break) +{ + struct string_map options = STRING_MAP_INITIALIZER (options); + string_map_insert (&options, "format", "txt"); + string_map_insert (&options, "output-file", "-"); + string_map_insert_nocopy (&options, xstrdup ("width"), + xasprintf ("%d", width)); + if (min_break >= 0) + string_map_insert_nocopy (&options, xstrdup ("min-hbreak"), + xasprintf ("%d", min_break)); + if (bold || underline) + string_map_insert (&options, "emphasis", "true"); + if (box != NULL) + string_map_insert (&options, "box", box); + + struct output_driver *driver = output_driver_create (&options); + string_map_destroy (&options); + if (!driver) + exit (EXIT_FAILURE); + output_driver_register (driver); + return driver; +} + +static const char * +parse_options (int argc, char **argv) +{ + int width = 79; + int min_break = -1; + + for (;;) + { + enum { + OPT_WIDTH = UCHAR_MAX + 1, + OPT_LENGTH, + OPT_MIN_BREAK, + OPT_EMPHASIS, + OPT_BOX, + OPT_HELP + }; + static const struct option options[] = + { + {"width", required_argument, NULL, OPT_WIDTH}, + {"length", required_argument, NULL, OPT_LENGTH}, + {"emphasis", required_argument, NULL, OPT_EMPHASIS}, + {"box", required_argument, NULL, OPT_BOX}, + {"help", no_argument, NULL, OPT_HELP}, + {NULL, 0, NULL, 0}, + }; + + int c = getopt_long (argc, argv, "o:", options, NULL); + if (c == -1) + break; + + switch (c) + { + case OPT_WIDTH: + width = atoi (optarg); + break; + + case OPT_EMPHASIS: + if (!strcmp (optarg, "bold")) + { + bold = true; + underline = false; + } + else if (!strcmp (optarg, "underline")) + { + bold = false; + underline = true; + } + else if (!strcmp (optarg, "none")) + { + bold = underline = false; + } + else + error (1, 0, "argument to --emphasis must be \"bold\" or " + "\"underline\" or \"none\""); + break; + + case OPT_BOX: + box = optarg; + break; + + case OPT_HELP: + usage (); + + case 0: + break; + + case '?': + exit(EXIT_FAILURE); + break; + + default: + NOT_REACHED (); + } + + } + + ascii_driver = configure_driver (width, min_break); + + if (optind + 1 != argc) + error (1, 0, "exactly one non-option argument required; " + "use --help for help"); + return argv[optind]; +} + +static void +usage (void) +{ + printf ("%s, to test PSPP ASCII driver drawing\n" + "usage: %s [OPTIONS] INPUT\n" + "\nOptions:\n" + " --width=WIDTH set page width in characters\n" + " --length=LINE set page length in lines\n", + program_name, program_name); + exit (EXIT_SUCCESS); +} + +static void +draw (FILE *stream) +{ + char buffer[1024]; + int line = 0; + + while (fgets (buffer, sizeof buffer, stream)) + { + char text[sizeof buffer]; + int length; + int emph; + int x, y; + + line++; + if (strchr ("#\r\n", buffer[0])) + continue; + + if (sscanf (buffer, "%d %d %d %[^\n]", &x, &y, &emph, text) == 4) + ascii_test_write (ascii_driver, text, x, y, emph ? bold : false, + emph ? underline : false); + else if (sscanf (buffer, "set-length %d %d", &y, &length) == 2) + ascii_test_set_length (ascii_driver, y, length); + else + error (1, 0, "line %d has invalid format", line); + } + ascii_test_flush (ascii_driver); +} diff --git a/tests/output/ascii.at b/tests/output/ascii.at index f966fc6f06..1ca7510667 100644 --- a/tests/output/ascii.at +++ b/tests/output/ascii.at @@ -83,7 +83,7 @@ AT_DATA([input], [dnl 0 18 1 か 4 18 1 くけ ]) -AT_CHECK([render-test --draw-mode --emph=none input], [0], [dnl +AT_CHECK([ascii-test --emph=none input], [0], [dnl aBCD eFGH iJKL @@ -104,7 +104,7 @@ kaきくけ かkiくけko かkiくけko ]) -AT_CHECK([render-test --draw-mode --emph=bold input], [0], [dnl +AT_CHECK([ascii-test --emph=bold input], [0], [dnl aBCD eFFGGHH iiJKL @@ -125,7 +125,7 @@ kkaaききくくけけ かkkiiくけkkoo かかkkiiくくけけkkoo ]) -AT_CHECK([render-test --draw-mode --emph=underline input], [0], [dnl +AT_CHECK([ascii-test --emph=underline input], [0], [dnl aBCD e_F_G_H _iJKL @@ -279,7 +279,7 @@ AT_DATA([input], [dnl 1 38 1 a 5 38 1 kuke ]) -AT_CHECK([render-test --draw-mode --emph=none input], [0], [dnl +AT_CHECK([ascii-test --emph=none input], [0], [dnl あきくけ あきくけ あきくけ @@ -320,7 +320,7 @@ kaいkukeお ?aい?kuke?さ ?aい?kuke?さ ]) -AT_CHECK([render-test --draw-mode --emph=bold input], [0], [dnl +AT_CHECK([ascii-test --emph=bold input], [0], [dnl あきくけ あききくくけけ ああきくけ @@ -361,7 +361,7 @@ kkaaいいkkuukkeeおお ?aいい?kuke?ささ ?aaいい?kkuukkee?ささ ]) -AT_CHECK([render-test --draw-mode --emph=underline input], [0], [dnl +AT_CHECK([ascii-test --emph=underline input], [0], [dnl あきくけ あ_き_く_け _あきくけ @@ -471,7 +471,7 @@ AT_DATA([input], [dnl 0 18 1 à 2 18 1 îo̧ũ ]) -AT_CHECK([render-test --draw-mode --emph=none input], [0], [dnl +AT_CHECK([ascii-test --emph=none input], [0], [dnl àxyz àxyz àxyz @@ -492,7 +492,7 @@ àeîo̧ũy àeîo̧ũy àeîo̧ũy ]) -AT_CHECK([render-test --draw-mode --emph=bold input], [0], [dnl +AT_CHECK([ascii-test --emph=bold input], [0], [dnl àxyz àxxyyzz aàxyz @@ -513,7 +513,7 @@ aàeiîoo̧uũy àeeîo̧ũyy aàeeiîoo̧uũyy ]) -AT_CHECK([render-test --draw-mode --emph=underline input], [0], [dnl +AT_CHECK([ascii-test --emph=underline input], [0], [dnl àxyz à_x_y_z _àxyz @@ -563,7 +563,7 @@ set-length 8 2 set-length 9 1 set-length 10 0 ]) -AT_CHECK([render-test --draw-mode input], [0], [dnl +AT_CHECK([ascii-test input], [0], [dnl àéî àéî àé @@ -577,26 +577,6 @@ à ]) AT_CLEANUP -AT_SETUP([ASCII driver Unicode box characters]) -AT_KEYWORDS([render rendering]) -AT_DATA([input], [3 3 -1*2 @abc -2*1 @d\ne\nf -2*1 @g\nh\ni -@j -1*2 @klm -]) -AT_CHECK([render-test --box=unicode input], [0], [dnl -╭───┬─╮ -│abc│d│ -├─┬─┤e│ -│g│j│f│ -│h├─┴─┤ -│i│klm│ -╰─┴───╯ -]) -AT_CLEANUP - AT_SETUP([ASCII driver syntax printback]) AT_DATA([ascii.sps], [dnl SET PRINTBACK=ON. diff --git a/tests/output/render.at b/tests/output/render.at index 8172e33571..67e3290b76 100644 --- a/tests/output/render.at +++ b/tests/output/render.at @@ -555,6 +555,27 @@ AT_CHECK([render-test input], [0],[dnl +-----+------+----+ ]) AT_CLEANUP + + +AT_SETUP([ASCII driver Unicode box characters]) +AT_KEYWORDS([render rendering]) +AT_DATA([input], [3 3 +1*2 @abc +2*1 @d\ne\nf +2*1 @g\nh\ni +@j +1*2 @klm +]) +AT_CHECK([render-test --box=unicode input], [0], [dnl +╭───┬─╮ +│abc│d│ +├─┬─┤e│ +│g│j│f│ +│h├─┴─┤ +│i│klm│ +╰─┴───╯ +]) +AT_CLEANUP AT_BANNER([output rendering -- horizontal page breaks])