diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2008-11-28 19:29:00 +0300 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2008-11-28 19:29:00 +0300 |
commit | 06661f20cbb9d2f1d0f8a68fb7bc46dcd97c6276 (patch) | |
tree | d1054848d24437038adb3f75cbfc028c94e69548 /test/rspamd_statfile_test.c | |
parent | f1fdc9c6c1fa897f6eac5abc4cd193b55d31e7bc (diff) | |
download | rspamd-06661f20cbb9d2f1d0f8a68fb7bc46dcd97c6276.tar.gz rspamd-06661f20cbb9d2f1d0f8a68fb7bc46dcd97c6276.zip |
* Write functions to operate blocks in stat files
* Write test case for statistics files API
Diffstat (limited to 'test/rspamd_statfile_test.c')
-rw-r--r-- | test/rspamd_statfile_test.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/test/rspamd_statfile_test.c b/test/rspamd_statfile_test.c new file mode 100644 index 000000000..6537bcfaf --- /dev/null +++ b/test/rspamd_statfile_test.c @@ -0,0 +1,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); + +} |