From 946ddcfbc4c7cdd3df426eb5f9a15f4a3fc3c640 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 8 Sep 2008 18:18:56 +0400 Subject: [PATCH] * Add initial test suite using glib test suite --- Makefile.in | 7 +++- configure | 24 ++++++++++++- test/Makefile.in | 13 +++++++ test/rspamd_test_suite.c | 25 +++++++++++++ test/rspamd_url_test.c | 78 ++++++++++++++++++++++++++++++++++++++++ test/tests.h | 11 ++++++ 6 files changed, 156 insertions(+), 2 deletions(-) create mode 100644 test/Makefile.in create mode 100644 test/rspamd_test_suite.c create mode 100644 test/rspamd_url_test.c create mode 100644 test/tests.h diff --git a/Makefile.in b/Makefile.in index 92d8683a1..bbc443cd2 100644 --- a/Makefile.in +++ b/Makefile.in @@ -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!" diff --git a/configure b/configure index 7130afa70..e7d0aad41 100755 --- 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 index 000000000..d7b6957c8 --- /dev/null +++ b/test/Makefile.in @@ -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 index 000000000..d9d7f63fe --- /dev/null +++ b/test/rspamd_test_suite.c @@ -0,0 +1,25 @@ +#include +#include +#include +#include + +#include +#include +#include +#include + +#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 index 000000000..29be737e1 --- /dev/null +++ b/test/rspamd_url_test.c @@ -0,0 +1,78 @@ +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + + +#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 = "This is test file with http://TesT%45.com/././ url"; + +/* 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 index 000000000..c0e1858a2 --- /dev/null +++ b/test/tests.h @@ -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 -- 2.39.5