aboutsummaryrefslogtreecommitdiffstats
path: root/test/rspamd_expression_test.c
diff options
context:
space:
mode:
authorcebka@cebka-laptop <cebka@cebka-laptop>2008-10-13 19:06:07 +0400
committercebka@cebka-laptop <cebka@cebka-laptop>2008-10-13 19:06:07 +0400
commitda93e9d6351e238ff66d04b9a7a712f161e2defc (patch)
tree3613023247d7e80dc4e3fc74b9ebf6b9a1464662 /test/rspamd_expression_test.c
parent6c55c3314c9599fa1d97d7afd6a31b1982805265 (diff)
downloadrspamd-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/rspamd_expression_test.c')
-rw-r--r--test/rspamd_expression_test.c57
1 files changed, 57 insertions, 0 deletions
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);
+}