aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/.depends1
-rw-r--r--test/rspamd_statfile_test.c59
-rw-r--r--test/rspamd_test_suite.c1
-rw-r--r--test/tests.h3
4 files changed, 64 insertions, 0 deletions
diff --git a/test/.depends b/test/.depends
index 2c4e7865e..984f4699c 100644
--- a/test/.depends
+++ b/test/.depends
@@ -5,3 +5,4 @@
../src/url.c
../src/util.c
../src/memcached.c
+../src/statfile.c
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);
+
+}
diff --git a/test/rspamd_test_suite.c b/test/rspamd_test_suite.c
index 08de6fcf4..81291aa06 100644
--- a/test/rspamd_test_suite.c
+++ b/test/rspamd_test_suite.c
@@ -24,6 +24,7 @@ main (int argc, char **argv)
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_add_func ("/rspamd/statfile", rspamd_statfile_test_func);
g_test_run ();
}
diff --git a/test/tests.h b/test/tests.h
index 7ff763623..ed852f2d3 100644
--- a/test/tests.h
+++ b/test/tests.h
@@ -17,4 +17,7 @@ void rspamd_mem_pool_test_func ();
/* Expressions */
void rspamd_expression_test_func ();
+/* Stat file */
+void rspamd_statfile_test_func ();
+
#endif