]> source.dussan.org Git - rspamd.git/commitdiff
* Add initial test suite using glib test suite
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Mon, 8 Sep 2008 14:18:56 +0000 (18:18 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Mon, 8 Sep 2008 14:18:56 +0000 (18:18 +0400)
Makefile.in
configure
test/Makefile.in [new file with mode: 0644]
test/rspamd_test_suite.c [new file with mode: 0644]
test/rspamd_url_test.c [new file with mode: 0644]
test/tests.h [new file with mode: 0644]

index 92d8683a173c533ac8d252659eee2b8017d486ec..bbc443cd258a86a2565d94275a3c4dd281b0b9a7 100644 (file)
@@ -1,4 +1,4 @@
-.PHONY: perl clean
+.PHONY: perl clean test
 
 all: perl $(TARGETS)
 
@@ -26,13 +26,18 @@ clean:
        rm -f *.o $(EXEC) *.core
        rm -f cfg_lex.c cfg_yacc.c cfg_yacc.h
        cd perl && make clean && cd ..
+       cd test && make clean && cd ..
 
 dist-clean: clean
        rm -f Makefile
+       rm -f test/Makefile
        rm -f config.log
        rm -f md5.h md5.c strlcpy.h strlcpy.c queue.h config.h modules.c modules.h
        cd perl && rm -f Makefile.old && rm -f Makefile.PL && cd ..
 
+test:
+       cd test && make
+
 creategroup:
        @echo "Create group $(RSPAMD_GROUP) before installing!" 
 
index 7130afa70c223dd23bd8551129d33caf6ad11b30..e7d0aad411a9ba018de05908680cdbf33d2f893b 100755 (executable)
--- a/configure
+++ b/configure
@@ -37,6 +37,7 @@ GROUP=postfix
 INSTALL="/usr/bin/install -v"
 MKDIR="/usr/bin/install -v -d"
 MANPATH="${PREFIX}/share/man"
+SUBDIRS="test"
 
 MAKEFILE="Makefile"
 MAKEFILE_IN="Makefile.in"
@@ -492,9 +493,30 @@ DEPS=$DEPS
 MANPATH=$MANPATH
 
 END
-       # Write build targets to makefile
+       # Write subdirs makefiles
+       for sub in $SUBDIRS ; do
+               cp $MAKEFILE $sub/$MAKEFILE
+               saved_pwd=`pwd`
+               old_objs=`echo $OBJECTS | sed -e 's/\([^. ]*\.o\)/..\/\1/g'`
+               old_srcs=`echo $SOURCES | sed -e 's/\([^. ]*\.c\)/..\/\1/g'`
+               cd $sub
+               sub_src="`echo *.c`"
+               sub_obj="`echo $sub_src | sed -e 's/\.c/\.o/g'`"
+               echo "SOURCES=$sub_src" >> $MAKEFILE
+               echo "OBJECTS=$sub_obj" >> $MAKEFILE
+               cat Makefile.in >> $MAKEFILE
+               for _sub_src in $sub_src ; do
+                       _sub_obj=`echo $_sub_src | sed -e 's/\.c/\.o/g'`
+                       cat >> $MAKEFILE << END
+${_sub_obj}: ${_sub_src}
+       \$(CC) \$(OPT_FLAGS) \$(CFLAGS) \$(PTHREAD_CFLAGS) -o ${_sub_obj} -c ${_sub_src}
 
+END
+               done
+               cd $saved_pwd
+       done
        cat $MAKEFILE_IN >> $MAKEFILE
+       # Write build targets to makefile
        cat >> $MAKEFILE << END
 ${EXEC}: \$(OBJECTS)
        \$(CC) \$(PTHREAD_LDFLAGS) \$(LDFLAGS) \$(OBJECTS) \$(LIBS) -o \$(EXEC)
diff --git a/test/Makefile.in b/test/Makefile.in
new file mode 100644 (file)
index 0000000..d7b6957
--- /dev/null
@@ -0,0 +1,13 @@
+.PHONY: clean
+
+all: rspamd_test_suite
+
+rspamd_test_suite: $(OBJECTS) ../url.o ../util.o
+       $(CC) $(PTHREAD_LDFLAGS) $(LDFLAGS) $(OBJECTS) ../url.o ../util.o $(LIBS) -o rspamd_test_suite
+
+run_test: rspamd_test_suite
+       gtester --verbose -k -o=rspamd_test.xml ./rspamd_test_suite
+       less rspamd_test.xml && rm -f rspamd_test.xml
+
+clean:
+       rm -f *.o rspamd_test_suite *.core rspamd_test.xml
diff --git a/test/rspamd_test_suite.c b/test/rspamd_test_suite.c
new file mode 100644 (file)
index 0000000..d9d7f63
--- /dev/null
@@ -0,0 +1,25 @@
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/wait.h>
+#include <sys/param.h>
+
+#include <netdb.h>
+#include <syslog.h>
+#include <fcntl.h>
+#include <stdlib.h>
+
+#include "../config.h"
+#include "../main.h"
+#include "../cfg_file.h"
+#include "tests.h"
+
+int
+main (int argc, char **argv)
+{
+       g_test_init (&argc, &argv, NULL);
+
+       g_test_add_func ("/rspamd/url", rspamd_url_test_func);
+
+       g_test_run ();
+
+}
diff --git a/test/rspamd_url_test.c b/test/rspamd_url_test.c
new file mode 100644 (file)
index 0000000..29be737
--- /dev/null
@@ -0,0 +1,78 @@
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/wait.h>
+#include <sys/param.h>
+
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <syslog.h>
+#include <fcntl.h>
+#include <stdlib.h>
+
+
+#include "../config.h"
+#include "../main.h"
+#include "../cfg_file.h"
+#include "../url.h"
+#include "tests.h"
+
+const char *test_text = "This is test file with http://TesT%45.com/././ url";
+const char *test_html = "<some_tag>This is test file with <a href=\"http://microsoft.com\">http://TesT%45.com/././ url</a></some_tag>";
+
+/* Function for using in glib test suite */
+void
+rspamd_url_test_func ()
+{
+       GByteArray *text, *html;
+       struct worker_task task;
+       struct uri *url;
+       int i = 0;
+
+       text = g_byte_array_new();
+       text->data = (gchar *)test_text;
+       text->len = sizeof (test_text);
+       html = g_byte_array_new();
+       text->data = (gchar *)test_html;
+       text->len = sizeof (test_html);
+       bzero (&task, sizeof (task));
+       TAILQ_INIT (&task.urls);
+       
+       g_test_timer_start ();
+       g_test_message ("* Testing text URL regexp parser *");
+       url_parse_text (&task, text);
+
+       TAILQ_FOREACH (url, &task.urls, next) {
+               g_test_message ("Found url: %s, hostname: %s, data: %s", struri (url), url->host, url->data);
+               i ++;
+       }
+
+       while (!TAILQ_EMPTY (&task.urls)) {
+               url = TAILQ_FIRST (&task.urls);
+               TAILQ_REMOVE (&task.urls, url, next);
+               g_free (url->string);
+               g_free (url);
+       }
+       g_assert (i == 1);
+
+       g_test_message ("Time elapsed: %.2f", g_test_timer_elapsed ());
+
+       i = 0;
+       g_test_timer_start ();
+       g_test_message ("* Testing html URL regexp parser *");
+       url_parse_html (&task, html);
+
+       TAILQ_FOREACH (url, &task.urls, next) {
+               g_test_message ("Found url: %s, hostname: %s, data: %s", struri (url), url->host, url->data);
+               i ++;
+       }
+
+       while (!TAILQ_EMPTY (&task.urls)) {
+               url = TAILQ_FIRST (&task.urls);
+               TAILQ_REMOVE (&task.urls, url, next);
+               g_free (url->string);
+               g_free (url);
+       }
+       g_assert (i == 2);
+       g_test_message ("Time elapsed: %.2f", g_test_timer_elapsed ());
+}
diff --git a/test/tests.h b/test/tests.h
new file mode 100644 (file)
index 0000000..c0e1858
--- /dev/null
@@ -0,0 +1,11 @@
+#ifndef RSPAMD_TESTS_H
+#define RSPAMD_TESTS_H
+
+/* 
+ * Here are described test functions for rspamd test suite 
+ */
+
+/* URL parser test */
+void rspamd_url_test_func ();
+
+#endif