From: Art Cancro Date: Wed, 8 Dec 2010 03:17:47 +0000 (-0500) Subject: Added the regression test I wrote while fixing stripallbut() yesterday X-Git-Tag: v8.01~531 X-Git-Url: https://code.citadel.org/?a=commitdiff_plain;h=7fb877fe4dbffb475e11d0af9be0e9aeca69360e;p=citadel.git Added the regression test I wrote while fixing stripallbut() yesterday --- diff --git a/libcitadel/tests/Makefile.in b/libcitadel/tests/Makefile.in index 32c7f1f48..53732c7e0 100644 --- a/libcitadel/tests/Makefile.in +++ b/libcitadel/tests/Makefile.in @@ -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 index 000000000..2e1d0cff0 --- /dev/null +++ b/libcitadel/tests/stripallbut_test.c @@ -0,0 +1,71 @@ +#include +#include +#include +#include +#include +#include + +#include "../lib/libcitadel.h" + +main() { + int i; + long l; + + char *teststrings[] = { + "Nmm tyutyu", + "Sdd <> ghhjjkk", + "<>", + "", + "Sdd <", + "Df Ghjkl>", + ">< bggt", + "FSDFSDFSDFSDF<><><>bggt", + "FSDFSDFSDF<><>bggt", + "Abc", + "><", + "Zxcv>>" + }; + + char *strippedstrings[] = { + "fghjk", + "", + "", + "", + "Sdd <", + "Df Ghjkl>", + ">< bggt", + "FSDFSDFSDFSDF<><><>bggt", + "FSDFSDFSDF<><>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); +}