summaryrefslogtreecommitdiffstats
path: root/test/rspamd_statfile_test.c
blob: 6537bcfafe541671d7e09f80c4e6e61ecf03342b (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
58
59
#include <sys/types.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <sys/param.h>
#include <sys/stat.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 "../src/config.h"
#include "../src/main.h"
#include "../src/statfile.h"
#include "tests.h"

#define TEST_FILENAME "/tmp/rspamd_test.stat"
#define HASHES_NUM 1024

void 
rspamd_statfile_test_func ()
{
	statfile_pool_t *pool;
	uint32_t random_hashes[HASHES_NUM], i, v;
	time_t now;
	
	umask (S_IWGRP | S_IWOTH);
	pool = statfile_pool_new (10 * 1024 * 1024);

	now = time (NULL);
	/* Fill random array */
	srand (now);
	for (i = 0; i < HASHES_NUM; i ++) {
		random_hashes[i] = rand ();
	}

	/* Create new file */
	g_assert (statfile_pool_create (pool, TEST_FILENAME, 65535) != -1);
	g_assert (statfile_pool_open (pool, TEST_FILENAME) != -1);
	
	/* Get and set random blocks */
	statfile_pool_lock_file (pool, TEST_FILENAME);
	for (i = 0; i < HASHES_NUM; i ++) {
		statfile_pool_set_block (pool, TEST_FILENAME, random_hashes[i], random_hashes[i], now, random_hashes[i]);
	}
	statfile_pool_unlock_file (pool, TEST_FILENAME);

	for (i = 0; i < HASHES_NUM; i ++) {
		v = statfile_pool_get_block (pool, TEST_FILENAME, random_hashes[i], random_hashes[i], now);
		g_assert(v == random_hashes[i]);
	}

	statfile_pool_delete (pool);
	
}