aboutsummaryrefslogtreecommitdiffstats
path: root/test/rspamd_expression_test.c
blob: 5d8e2a6f21b0c79187054ff8b3b2bb917c31b928 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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);
}