New test: test/ui/syntax-gen-test.c
authorJohn Darrington <john@darrington.wattle.id.au>
Fri, 25 Apr 2014 04:20:27 +0000 (06:20 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Fri, 25 Apr 2014 17:14:44 +0000 (19:14 +0200)
Added a test to provide some confidence that the syntax generation
functions work.

tests/automake.mk
tests/ui/syntax-gen-test.c [new file with mode: 0644]
tests/ui/syntax-gen.at [new file with mode: 0644]

index 31bf0b20339228e5e4344ae3086a2780a1be7ee1..7fd773cb206baed76dafa03a14ad864c46726c59 100644 (file)
@@ -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 (file)
index 0000000..2c66929
--- /dev/null
@@ -0,0 +1,41 @@
+#include <config.h>
+
+#include "ui/syntax-gen.h"
+
+#include <stdio.h>
+
+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\fchar");
+  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 (file)
index 0000000..7a446d7
--- /dev/null
@@ -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