diff options
author | cebka@cebka-laptop <cebka@cebka-laptop> | 2008-10-13 19:06:07 +0400 |
---|---|---|
committer | cebka@cebka-laptop <cebka@cebka-laptop> | 2008-10-13 19:06:07 +0400 |
commit | da93e9d6351e238ff66d04b9a7a712f161e2defc (patch) | |
tree | 3613023247d7e80dc4e3fc74b9ebf6b9a1464662 /test | |
parent | 6c55c3314c9599fa1d97d7afd6a31b1982805265 (diff) | |
download | rspamd-da93e9d6351e238ff66d04b9a7a712f161e2defc.tar.gz rspamd-da93e9d6351e238ff66d04b9a7a712f161e2defc.zip |
* Implement expression parser (convertor to inverse polish record)
* Improve configure system by implementing dependencies
* Add .depend files for subdirs that requre it
* Write simple test for expressions parser
Diffstat (limited to 'test')
-rw-r--r-- | test/.depends | 7 | ||||
-rw-r--r-- | test/Makefile.in | 4 | ||||
-rw-r--r-- | test/rspamd_expression_test.c | 57 | ||||
-rw-r--r-- | test/rspamd_memcached_test.c | 2 | ||||
-rw-r--r-- | test/rspamd_test_suite.c | 5 | ||||
-rw-r--r-- | test/tests.h | 3 |
6 files changed, 71 insertions, 7 deletions
diff --git a/test/.depends b/test/.depends new file mode 100644 index 000000000..52848a04a --- /dev/null +++ b/test/.depends @@ -0,0 +1,7 @@ +#if HAVE_STRLCPY_H +../strlcpy.c +#endif +../mem_pool.c +../url.c +../util.c +../memcached.c diff --git a/test/Makefile.in b/test/Makefile.in index 14a2646b9..08f041e4e 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -2,8 +2,8 @@ all: rspamd_test_suite -rspamd_test_suite: $(OBJECTS) ../url.o ../util.o ../memcached.o - $(CC) $(PTHREAD_LDFLAGS) $(LDFLAGS) $(OBJECTS) ../url.o ../util.o ../memcached.o ../mem_pool.o $(LIBS) -o rspamd_test_suite +rspamd_test_suite: $(OBJECTS) $(OBJ_DEPENDS) + $(CC) $(PTHREAD_LDFLAGS) $(LDFLAGS) $(OBJECTS) $(OBJ_DEPENDS) $(LIBS) -o rspamd_test_suite run_test: rspamd_test_suite gtester --verbose -k -o=rspamd_test.xml ./rspamd_test_suite diff --git a/test/rspamd_expression_test.c b/test/rspamd_expression_test.c new file mode 100644 index 000000000..5d8e2a6f2 --- /dev/null +++ b/test/rspamd_expression_test.c @@ -0,0 +1,57 @@ +#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 <string.h> +#include <stdio.h> + +#include "../config.h" +#include "../main.h" +#include "../cfg_file.h" +#include "tests.h" + +/* Vector of test expressions */ +char *test_expressions[] = { + "(A&B|!C)&!(D|E)", + "/test&!/&!/\\/|/", + NULL +}; + +void +rspamd_expression_test_func () +{ + memory_pool_t *pool; + struct expression *cur; + char **line, *outstr; + int r, s; + + pool = memory_pool_new (1024); + + line = test_expressions; + while (*line) { + r = 0; + cur = parse_expression (pool, *line); + s = strlen (*line) + 1; + outstr = memory_pool_alloc (pool, s); + while (cur) { + if (cur->type == EXPR_OPERAND) { + r += snprintf (outstr + r, s - r, "%s", (char *)cur->content.operand); + } + else { + r += snprintf (outstr + r, s - r, "%c", cur->content.operation); + } + cur = cur->next; + } + msg_debug ("Parsed expression: '%s' -> '%s'", *line, outstr); + line ++; + } + + memory_pool_delete (pool); +} diff --git a/test/rspamd_memcached_test.c b/test/rspamd_memcached_test.c index 1993c756e..60ae1d3eb 100644 --- a/test/rspamd_memcached_test.c +++ b/test/rspamd_memcached_test.c @@ -33,7 +33,7 @@ memcached_callback (memcached_ctx_t *ctx, memc_error_t error, void *data) break; case CMD_READ: g_assert (error == OK); - g_assert (!strcmp(ctx->param->buf, buf)); + g_assert (!memcmp(ctx->param->buf, buf, ctx->param->bufsize)); msg_debug ("Read ok"); memc_close_ctx (ctx); tv.tv_sec = 0; diff --git a/test/rspamd_test_suite.c b/test/rspamd_test_suite.c index 90e64b112..dba448a2c 100644 --- a/test/rspamd_test_suite.c +++ b/test/rspamd_test_suite.c @@ -13,10 +13,6 @@ #include "../cfg_file.h" #include "tests.h" -#ifdef HAVE_STRLCPY_H -#include "../strlcpy.c" -#endif - int main (int argc, char **argv) { @@ -27,6 +23,7 @@ main (int argc, char **argv) g_test_add_func ("/rspamd/memcached", rspamd_memcached_test_func); g_test_add_func ("/rspamd/mem_pool", rspamd_mem_pool_test_func); g_test_add_func ("/rspamd/url", rspamd_url_test_func); + g_test_add_func ("/rspamd/expression", rspamd_expression_test_func); g_test_run (); } diff --git a/test/tests.h b/test/tests.h index 3eddf92fc..7ff763623 100644 --- a/test/tests.h +++ b/test/tests.h @@ -14,4 +14,7 @@ void rspamd_memcached_test_func (); /* Memory pools */ void rspamd_mem_pool_test_func (); +/* Expressions */ +void rspamd_expression_test_func (); + #endif |