From febb6155806e22259459c073a3239dd6f109daaf Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Tue, 8 Jan 2013 16:32:57 +0900 Subject: [PATCH] Create a test for octal chars in plist strings. Both reading and writing. --- libs/util/test/Makefile.am | 8 ++++-- libs/util/test/test-plist.c | 53 +++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 libs/util/test/test-plist.c diff --git a/libs/util/test/Makefile.am b/libs/util/test/Makefile.am index 8560f3e18..b295a5b7e 100644 --- a/libs/util/test/Makefile.am +++ b/libs/util/test/Makefile.am @@ -3,8 +3,8 @@ AUTOMAKE_OPTIONS= foreign INCLUDES= -I$(top_srcdir)/include check_PROGRAMS= \ - test-dq test-half test-mat3 test-mat4 test-qfs test-quat test-set \ - test-vrect + test-dq test-half test-mat3 test-mat4 test-plist test-qfs test-quat \ + test-set test-vrect test_dq_SOURCES=test-dq.c test_dq_LDADD=$(top_builddir)/libs/util/libQFutil.la @@ -22,6 +22,10 @@ test_mat4_SOURCES=test-mat4.c test_mat4_LDADD=$(top_builddir)/libs/util/libQFutil.la test_mat4_DEPENDENCIES=$(top_builddir)/libs/util/libQFutil.la +test_plist_SOURCES=test-plist.c +test_plist_LDADD=$(top_builddir)/libs/util/libQFutil.la +test_plist_DEPENDENCIES=$(top_builddir)/libs/util/libQFutil.la + test_qfs_SOURCES=test-qfs.c test_qfs_LDADD=$(top_builddir)/libs/util/libQFutil.la test_qfs_DEPENDENCIES=$(top_builddir)/libs/util/libQFutil.la diff --git a/libs/util/test/test-plist.c b/libs/util/test/test-plist.c new file mode 100644 index 000000000..20ab1e94e --- /dev/null +++ b/libs/util/test/test-plist.c @@ -0,0 +1,53 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif +#include +#include "QF/qfplist.h" + +static const char *test_strings[] = { + "Guarding the entrance to the Grendal\n" + "Gorge is the Shadow Gate, a small keep\n" + "and monastary which was once the home\n" + "of the Shadow cult.\n\n" + "For years the Shadow Gate existed in\n" + "obscurity but after the cult discovered\n" + "the \3023\354\341\343\353\240\307\341\364\345 in the caves below\n" + "the empire took notice.\n" + "A batallion of Imperial Knights were\n" + "sent to the gate to destroy the cult\n" + "and claim the artifact for the King.", +}; +#define num_string_tests (sizeof (test_strings) / sizeof (test_strings[0])) + +static int +test_string_io (const char *str) +{ + plitem_t *item; + const char *res; + char *saved; + + item = PL_NewString (str); + saved = PL_WritePropertyList (item); + PL_Free (item); + item = PL_GetPropertyList (saved); + res = PL_String (item); + if (!strcmp (str, res)) + return 1; + printf ("expect: %s\n", str); + printf ("got : %s\n", res); + printf ("saved : %s\n", saved); + return 0; +} + +int +main (int argc, const char **argv) +{ + int res = 0; + size_t i; + + for (i = 0; i < num_string_tests; i ++) { + if (!test_string_io (test_strings[i])) + res = 1; + } + return res; +}