aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2009-03-11 12:35:52 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2009-03-11 12:36:26 +0200
commit43e8d1ad415cd8af7f56f0346097dd2882e23628 (patch)
tree37626ff7a5eaea3b185c6f98017de1200ce30ea9 /tests
parentb597bbb6893be07010e286f6a6195ed3c323a16b (diff)
downloadwydawca-43e8d1ad415cd8af7f56f0346097dd2882e23628.tar.gz
wydawca-43e8d1ad415cd8af7f56f0346097dd2882e23628.tar.bz2
Start writing wordsplit.
* doc/wydawca.texi: Update. * gconf/argcv.h, gconf/argcv.c: Remove. * gconf/wordsplit.c, gconf/wordsplit.h: New files. * gconf/Makefile.am (libgconf_a_SOURCES): Remove argcv, add wordsplit * gconf/gconf-lex.l, gconf/gconf-preproc.c: Use wordsplit, instead of argcv_get * src/directive.c, src/method.c: Likewise. * src/wydawca.h: Likewise. * tests/wordsplit.at: New file. * tests/wstest.c, tests/wsbatch.c: New files. * tests/Makefile.am (TESTSUITE_AT): Add wordsplit.at Build wstest and wsbatch. * tests/testsuite.at: Add wordsplit.at.
Diffstat (limited to 'tests')
-rw-r--r--tests/.gitignore2
-rw-r--r--tests/Makefile.am7
-rw-r--r--tests/testsuite.at1
-rw-r--r--tests/wordsplit.at24
-rw-r--r--tests/wsbatch.c146
-rw-r--r--tests/wstest.c141
6 files changed, 320 insertions, 1 deletions
diff --git a/tests/.gitignore b/tests/.gitignore
index 5c6ad40..15381c3 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -3,6 +3,8 @@ atlocal
package.m4
testsuite
testsuite.dir
testsuite.log
source
dest
+wstest
+wsbatch
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 6afb799..aa8b029 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -42,13 +42,14 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac
TESTSUITE_AT = \
testsuite.at\
notify-upl.at\
mailstats.at\
upload.at\
upload-dry.at\
- version.at
+ version.at\
+ wordsplit.at
TESTSUITE = $(srcdir)/testsuite
M4=m4
AUTOTEST = $(AUTOM4TE) --language=autotest
$(TESTSUITE): package.m4 $(TESTSUITE_AT)
@@ -65,7 +66,11 @@ check-local: atconfig atlocal $(TESTSUITE)
$(SHELL) $(TESTSUITE)
# Run the test suite on the *installed* tree.
#installcheck-local:
# $(SHELL) $(TESTSUITE) AUTOTEST_PATH=$(exec_prefix)/bin
+check_PROGRAMS = wstest wsbatch
+INCLUDES = -I$(top_srcdir)/gconf -I$(top_srcdir)/gnu -I../gnu
+LDADD=../gconf/libgconf.a ../gnu/libgnu.a
+
diff --git a/tests/testsuite.at b/tests/testsuite.at
index 75709c8..dc50951 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -19,10 +19,11 @@ m4_version_prereq([2.52g])
m4_define([AT_SKIP_TEST],[exit 77])
AT_INIT
AT_TESTED([wydawca])
m4_include([version.at])
+m4_include([wordsplit.at])
m4_include([upload-dry.at])
m4_include([upload.at])
m4_include([notify-upl.at])
m4_include([mailstats.at])
diff --git a/tests/wordsplit.at b/tests/wordsplit.at
new file mode 100644
index 0000000..355bf69
--- /dev/null
+++ b/tests/wordsplit.at
@@ -0,0 +1,24 @@
+# Check for wworking word splitter -*- Autotest -*-
+# Copyright (C) 2009 Sergey Poznyakoff
+#
+# Wydawca 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, or (at your option)
+# any later version.
+#
+# Wydawca 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 Wydawca. If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([wordsplit])
+
+AT_CHECK([wsbatch],
+ [0],
+ [Tests: 13
+])
+
+AT_CLEANUP
diff --git a/tests/wsbatch.c b/tests/wsbatch.c
new file mode 100644
index 0000000..5d986db
--- /dev/null
+++ b/tests/wsbatch.c
@@ -0,0 +1,146 @@
+/* wordsplit - a word splitter
+ Copyright (C) 2009 Sergey Poznyakoff
+
+ 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 <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wordsplit.h>
+
+size_t errors = 0;
+size_t count = 0;
+
+void
+runtest (const char **input, struct wordsplit *wsinit, int flags)
+{
+ int i;
+
+ for (i = 0; input[i]; i++)
+ {
+ size_t j;
+ const char *text = input[i];
+ struct wordsplit ws = *wsinit;
+ i++;
+ for (j = 0; input[i+j]; j++);
+
+ count++;
+ if (wordsplit (text, &ws, flags))
+ {
+ fprintf (stderr, "E: %s: parse failed\n", input);
+ errors++;
+ }
+ else if (ws.ws_wordc != j)
+ {
+ fprintf (stderr, "E: %s: wrong number of fields (%lu/%lu)\n",
+ text, ws.ws_wordc, j);
+ errors++;
+ }
+ else
+ {
+ size_t k;
+
+ for (k = 0; k < ws.ws_wordc; k++)
+ if (strcmp (ws.ws_wordv[k], input[i + k]))
+ {
+ fprintf (stderr, "E: %s: word %lu mismatch: %s/%s\n",
+ text, k, ws.ws_wordv[k], input[i + k]);
+ errors++;
+ break;
+ }
+ }
+ i += j;
+ }
+}
+
+const char *testv[] = {
+ "a bcd", "a", "bcd", NULL,
+ "a bcd \tef 13 456", "a", "bcd", "ef", "13", "456", NULL,
+ "a \"s p a c e\" b", "a", "s p a c e", "b", NULL,
+ "a \"s p \\\" a \\\\ c e\" b", "a", "s p \" a \\ c e", "b", NULL,
+ "a\\tb \"a\\tb\" 'a\\tb'", "a\tb", "a\tb", "a\\tb", NULL,
+ "\\\\\\a\\b\\f\\n\\r\\t\\v", "\\\a\b\f\n\r\t\v", NULL,
+ "a w13ord #comment", "a", "w13ord", "#comment", NULL,
+ NULL
+};
+
+const char *testcmt[] = {
+ "a bcd", "a", "bcd", NULL,
+ "a w13ord #comment", "a", "w13ord", NULL,
+ "#comment", NULL,
+ NULL
+};
+
+const char *testcol[] = {
+ "gray:x:1000:100:Sergey Poznyakoff:/home/gray:/bin/bash",
+ "gray",
+ "x",
+ "1000",
+ "100",
+ "Sergey Poznyakoff",
+ "/home/gray",
+ "/bin/bash",
+ NULL,
+
+ "mail::8:12:\"mail pseudo user\":/:\n",
+ "mail",
+ "",
+ "8",
+ "12",
+ "\"mail pseudo user\"",
+ "/",
+ "",
+ NULL,
+
+ NULL
+};
+
+const char *testcol2[] = {
+ "set x=foo,y=bar",
+ "set", " ",
+ "x", "=",
+ "foo", ",",
+ "y", "=", "bar",
+ NULL,
+
+ NULL
+};
+
+int
+main ()
+{
+ struct wordsplit ws;
+
+ runtest (testv, &ws, WRDSF_DEFFLAGS);
+
+ ws.ws_comment = "#";
+ runtest (testcmt, &ws, WRDSF_DEFFLAGS|WRDSF_COMMENT);
+
+ ws.ws_delim = ":\n";
+ runtest (testcol, &ws, WRDSF_NOVAR | WRDSF_NOCMD | WRDSF_DELIM);
+
+ ws.ws_delim = " =,";
+ runtest (testcol2, &ws,
+ WRDSF_NOVAR | WRDSF_NOCMD | WRDSF_DELIM | WRDSF_RETURN_DELIMS);
+
+ printf ("Tests: %lu\n", count);
+ if (errors)
+ printf ("Failures: %lu\n", errors);
+ return errors ? 1 : 0;
+}
+
diff --git a/tests/wstest.c b/tests/wstest.c
new file mode 100644
index 0000000..0b4a5ff
--- /dev/null
+++ b/tests/wstest.c
@@ -0,0 +1,141 @@
+/* wordsplit - a word splitter
+ Copyright (C) 2009 Sergey Poznyakoff
+
+ 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 <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wordsplit.h>
+
+struct flgtab
+{
+ char *name;
+ int flag;
+};
+
+struct flgtab flgtab[] = {
+#define FLG(n) { #n, n }
+ FLG(WRDSF_SHOWERR),
+ FLG(WRDSF_ENOMEMABRT),
+ FLG(WRDSF_WS),
+ FLG(WRDSF_QUOTE),
+ FLG(WRDSF_SQUEEZE_DELIMS),
+ FLG(WRDSF_RETURN_DELIMS),
+ FLG(WRDSF_SED_EXPR),
+ FLG(WRDSF_DEFFLAGS),
+ { NULL }
+#undef FLG
+};
+
+int
+str2flag (const char *opt)
+{
+ struct flgtab *f;
+ for (f = flgtab; f->name; f++)
+ if (strcmp (f->name, opt) == 0)
+ return f->flag;
+ return 0;
+}
+
+int
+main (int argc, char **argv)
+{
+ struct wordsplit ws;
+ int flags = 0;
+ int f;
+ size_t i;
+ char *text;
+
+ char *progname = argv[0];
+
+ while (--argc)
+ {
+ char *opt = *++argv;
+ if (strncmp (opt, "delim=", 6) == 0)
+ {
+ ws.ws_delim = opt + 6;
+ flags |= WRDSF_DELIM;
+ }
+ else if (strncmp (opt, "comment=", 8) == 0)
+ {
+ ws.ws_comment = opt + 8;
+ flags |= WRDSF_COMMENT;
+ }
+ else if ((opt[0] == '!' || opt[0] == '~')
+ && strncmp (opt+1, "WRDSF_", 6) == 0)
+ {
+ f = str2flag (opt + 1);
+ if (!f)
+ {
+ fprintf (stderr, "%s: unknown flag: %s\n", progname, opt+1);
+ exit (1);
+ }
+ flags &= ~f;
+ }
+ else if (strncmp (opt, "WRDSF_", 6) == 0)
+ {
+ f = str2flag (opt);
+ if (!f)
+ {
+ fprintf (stderr, "%s: unknown flag: %s\n", progname, opt);
+ exit (1);
+ }
+ flags |= f;
+ }
+ else if (strcmp (opt, "--") == 0)
+ break;
+ else
+ break;
+ }
+
+ if (!flags)
+ flags = WRDSF_DEFFLAGS;
+
+ if (argc == 0)
+ {
+ fprintf (stderr, "%s: not enough arguments\n", progname);
+ return 1;
+ }
+ text = *argv++;
+ argc--;
+
+ if (wordsplit (text, &ws, flags))
+ {
+ fprintf (stderr, "%s: parse error\n", progname);
+ return 1;
+ }
+
+ if (ws.ws_wordc != argc)
+ {
+ fprintf (stderr, "%s: wrong number of fields (%lu/%d)\n",
+ progname, (unsigned long) ws.ws_wordc, argc);
+ return 1;
+ }
+
+ for (i = 0; i < ws.ws_wordc; i++)
+ if (strcmp (ws.ws_wordv[i], argv[i]))
+ {
+ fprintf (stderr, "%s: word %lu mismatch (got %s)\n",
+ progname, (unsigned long) i, ws.ws_wordv[i]);
+ return 1;
+ }
+
+ wordsplit_free (&ws);
+ return 0;
+}

Return to:

Send suggestions and report system problems to the System administrator.