summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2008-09-08 18:18:56 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2008-09-08 18:18:56 +0400
commit946ddcfbc4c7cdd3df426eb5f9a15f4a3fc3c640 (patch)
treeb47dc46e90b8b1e2c84d5f72070e90b6b546ed52 /test
parent32d41689d6328e9075bf4c6a822f0fe22207838b (diff)
downloadrspamd-946ddcfbc4c7cdd3df426eb5f9a15f4a3fc3c640.tar.gz
rspamd-946ddcfbc4c7cdd3df426eb5f9a15f4a3fc3c640.zip
* Add initial test suite using glib test suite
Diffstat (limited to 'test')
-rw-r--r--test/Makefile.in13
-rw-r--r--test/rspamd_test_suite.c25
-rw-r--r--test/rspamd_url_test.c78
-rw-r--r--test/tests.h11
4 files changed, 127 insertions, 0 deletions
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 <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
index 000000000..29be737e1
--- /dev/null
+++ b/test/rspamd_url_test.c
@@ -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
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