From 8925b93f70213a7b88521ea134d0c7daf18bb1a5 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Fri, 25 Apr 2014 06:20:27 +0200 Subject: [PATCH] New test: test/ui/syntax-gen-test.c Added a test to provide some confidence that the syntax generation functions work. --- tests/automake.mk | 14 ++++++++++++- tests/ui/syntax-gen-test.c | 41 ++++++++++++++++++++++++++++++++++++++ tests/ui/syntax-gen.at | 17 ++++++++++++++++ 3 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 tests/ui/syntax-gen-test.c create mode 100644 tests/ui/syntax-gen.at diff --git a/tests/automake.mk b/tests/automake.mk index 31bf0b2033..7fd773cb20 100644 --- a/tests/automake.mk +++ b/tests/automake.mk @@ -31,7 +31,9 @@ check_PROGRAMS += \ tests/libpspp/tower-test \ tests/libpspp/u8-istream-test \ tests/libpspp/zip-test \ - tests/output/render-test + tests/output/render-test \ + tests/ui/syntax-gen-test + check-programs: $(check_PROGRAMS) @@ -214,6 +216,15 @@ tests_output_render_test_LDADD = \ 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 = \ + src/ui/libuicommon.la \ + src/libpspp-core.la \ + $(CAIRO_LIBS) + + EXTRA_DIST += \ tests/coverage.sh \ tests/data/bcd-in.expected.cmp.gz \ @@ -361,6 +372,7 @@ TESTSUITE_AT = \ tests/output/paper-size.at \ tests/output/render.at \ tests/ui/terminal/main.at \ + tests/ui/syntax-gen.at \ tests/perl-module.at TESTSUITE = $(srcdir)/tests/testsuite diff --git a/tests/ui/syntax-gen-test.c b/tests/ui/syntax-gen-test.c new file mode 100644 index 0000000000..2c669290df --- /dev/null +++ b/tests/ui/syntax-gen-test.c @@ -0,0 +1,41 @@ +#include + +#include "ui/syntax-gen.h" + +#include + +static void +test_runner (const char *format, ...) +{ + struct string syntax; + va_list args; + va_start (args, format); + + ds_init_empty (&syntax); + + syntax_gen_pspp_valist (&syntax, format, args); + + va_end (args); + + puts (ds_cstr (&syntax)); + + ds_destroy (&syntax); +} + +int +main (void) +{ + test_runner ("A simple string: %ssEND", "Hello world"); + test_runner ("A syntax string: %sqEND", "Hello world"); + test_runner ("A syntax string containing \": %sqEND", "here\"is the quote"); + test_runner ("A syntax string containing non-printables: %sqEND", "A CtrlL char"); + test_runner ("An integer: %dEND", 98765); + test_runner ("A floating point number: %gEND", 3.142); + test_runner ("A floating point number with default precision: %fEND", 1.234); + test_runner ("A literal %%"); + + test_runner ("and %ss a %sq of %d different %f examples %g of 100%% conversions.", + "finally", "concatination", 6, 20.309, 23.09); + + return 0; +} diff --git a/tests/ui/syntax-gen.at b/tests/ui/syntax-gen.at new file mode 100644 index 0000000000..7a446d7e03 --- /dev/null +++ b/tests/ui/syntax-gen.at @@ -0,0 +1,17 @@ +AT_BANNER([SYNTAX GENERATOR]) + +AT_SETUP([Syntax Generation - printf like]) + +AT_CHECK([$abs_top_builddir/tests/ui/syntax-gen-test],[0],[dnl +A simple string: Hello worldEND +A syntax string: "Hello world"END +A syntax string containing ": 'here"is the quote'END +A syntax string containing non-printables: X'41204374726C4C0C63686172'END +An integer: 98765END +A floating point number: 3.142END +A floating point number with default precision: 1.234000END +A literal % +and finally a "concatination" of 6 different 20.309000 examples 23.09 of 100% conversions. +]) + +AT_CLEANUP -- 2.30.2