Added the regression test I wrote while fixing stripallbut() yesterday
authorArt Cancro <ajc@citadel.org>
Wed, 8 Dec 2010 03:17:47 +0000 (22:17 -0500)
committerArt Cancro <ajc@citadel.org>
Wed, 8 Dec 2010 03:17:47 +0000 (22:17 -0500)
libcitadel/tests/Makefile.in
libcitadel/tests/stripallbut_test.c [new file with mode: 0644]

index 32c7f1f48508115962e344978a8927e168d99e30..53732c7e00a50c96aafedc43baaae6ea15d4a745 100644 (file)
@@ -14,7 +14,7 @@ top_builddir=`pwd`
 
 # End of configuration section
 
-TARGETS=stringbuf_test stringbuf_IO_test stringbuf_conversion_test hashlist_test mimeparser_test mime_xdg_lookup_test wildfire_test
+TARGETS=stringbuf_test stringbuf_IO_test stringbuf_conversion_test hashlist_test mimeparser_test mime_xdg_lookup_test wildfire_test stripallbut_test
 all: $(TARGETS)
 
 
@@ -73,6 +73,13 @@ wildfire_test:       $(LIBOBJS) wildfire_test.o
        -o wildfire_test 
 
 
+stripallbut_test:      $(LIBOBJS) stripallbut_test.o 
+       $(CC) $(LDFLAGS) $(LIBOBJS) $(LIBS) \
+       stripallbut_test.o \
+       ../.libs/libcitadel.a \
+       -o stripallbut_test 
+
+
 .c.o:
        $(CC) $(CFLAGS) $(DEFS) -c  $<
 
diff --git a/libcitadel/tests/stripallbut_test.c b/libcitadel/tests/stripallbut_test.c
new file mode 100644 (file)
index 0000000..2e1d0cf
--- /dev/null
@@ -0,0 +1,71 @@
+#include <stdlib.h>
+#include <unistd.h>
+#include <ctype.h>
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+
+#include "../lib/libcitadel.h"
+
+main() {
+       int i;
+       long l;
+
+       char *teststrings[] = {
+               "Nmm <fghjk> tyutyu",
+               "Sdd <> ghhjjkk",
+               "<>",
+               "",
+               "Sdd <",
+               "Df Ghjkl>",
+               ">< bggt",
+               "FSDFSDFSDFSDF<><><>bggt",
+               "FSDFSDFSDF<><eoeo><>bggt",
+               "Abc<QWER>",
+               "><",
+               "Zxcv<dy<<lkj>>>"
+       };
+
+       char *strippedstrings[] = {
+               "fghjk",
+               "",
+               "",
+               "",
+               "Sdd <",
+               "Df Ghjkl>",
+               ">< bggt",
+               "FSDFSDFSDFSDF<><><>bggt",
+               "FSDFSDFSDF<><eoeo><>bggt",
+               "QWER",
+               "><",
+               "lkj"
+       };
+
+       long strippedlens[] = {
+               5,
+               0,
+               0,
+               0,
+               5,
+               9,
+               7,
+               23,
+               24,
+               4,
+               2,
+               3
+       };
+
+       char foo[128];
+
+       for (i=0; i<(sizeof(teststrings) / sizeof (char *)); ++i) {
+               printf("Testing stripallbut()\n");
+               strcpy(foo, teststrings[i]);
+               l = stripallbut(foo, '<', '>');
+
+               assert(!strcmp(foo, strippedstrings[i]));
+               assert(strlen(foo) == strippedlens[i]);
+       }
+
+       exit(0);
+}