summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorcebka@mailsupport.rambler.ru <cebka@mailsupport.rambler.ru>2008-09-16 18:42:02 +0400
committercebka@mailsupport.rambler.ru <cebka@mailsupport.rambler.ru>2008-09-16 18:42:02 +0400
commit4ad814a6c631883bbb55ae3db2f8806c63f31c9a (patch)
tree93cc3253d8046dfa7ca28f64c2cb01546e32eead /test
parent9e442d87b2907ff011a80b8a795c6710b6665705 (diff)
downloadrspamd-4ad814a6c631883bbb55ae3db2f8806c63f31c9a.tar.gz
rspamd-4ad814a6c631883bbb55ae3db2f8806c63f31c9a.zip
* Write test case for async memcached library
* Fix memcached async library to pass test :)
Diffstat (limited to 'test')
-rw-r--r--test/Makefile.in4
-rw-r--r--test/rspamd_memcached_test.c85
-rw-r--r--test/rspamd_test_suite.c3
-rw-r--r--test/tests.h3
4 files changed, 91 insertions, 4 deletions
diff --git a/test/Makefile.in b/test/Makefile.in
index 1d46e2e2f..ddd298c7c 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -2,8 +2,8 @@
all: rspamd_test_suite
-rspamd_test_suite: $(OBJECTS) ../url.o ../util.o
- $(CC) $(PTHREAD_LDFLAGS) $(LDFLAGS) $(OBJECTS) ../url.o ../util.o $(LIBS) -o rspamd_test_suite
+rspamd_test_suite: $(OBJECTS) ../url.o ../util.o ../memcached.o
+ $(CC) $(PTHREAD_LDFLAGS) $(LDFLAGS) $(OBJECTS) ../url.o ../util.o ../memcached.o $(LIBS) -o rspamd_test_suite
run_test: rspamd_test_suite
gtester --verbose -k -o=rspamd_test.xml ./rspamd_test_suite
diff --git a/test/rspamd_memcached_test.c b/test/rspamd_memcached_test.c
new file mode 100644
index 000000000..1993c756e
--- /dev/null
+++ b/test/rspamd_memcached_test.c
@@ -0,0 +1,85 @@
+#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 <event.h>
+
+#include "../config.h"
+#include "../main.h"
+#include "../cfg_file.h"
+#include "../memcached.h"
+#include "tests.h"
+
+u_char *buf = "test";
+
+static void
+memcached_callback (memcached_ctx_t *ctx, memc_error_t error, void *data)
+{
+ struct timeval tv;
+
+ switch (ctx->op) {
+ case CMD_CONNECT:
+ g_assert (error == OK);
+ msg_debug ("Connect ok");
+ memc_set (ctx, ctx->param, 60);
+ break;
+ case CMD_READ:
+ g_assert (error == OK);
+ g_assert (!strcmp(ctx->param->buf, buf));
+ msg_debug ("Read ok");
+ memc_close_ctx (ctx);
+ tv.tv_sec = 0;
+ tv.tv_usec = 0;
+ event_loopexit (&tv);
+ break;
+ case CMD_WRITE:
+ g_assert (error == OK);
+ msg_debug ("Write ok");
+ ctx->param->buf = g_malloc (sizeof (buf));
+ bzero (ctx->param->buf, sizeof (buf));
+ memc_get (ctx, ctx->param);
+ break;
+ }
+}
+
+void
+rspamd_memcached_test_func ()
+{
+ memcached_ctx_t *ctx;
+ memcached_param_t *param;
+ struct in_addr addr;
+
+ ctx = g_malloc (sizeof (memcached_ctx_t));
+ param = g_malloc (sizeof (memcached_param_t));
+ bzero (ctx, sizeof (memcached_ctx_t));
+ bzero (param, sizeof (memcached_param_t));
+
+ event_init ();
+
+ ctx->callback = memcached_callback;
+ ctx->callback_data = (void *)param;
+ ctx->protocol = TCP_TEXT;
+ inet_aton ("127.0.0.1", &addr);
+ memcpy (&ctx->addr, &addr, sizeof (struct in_addr));
+ ctx->port = htons (11211);
+ ctx->timeout.tv_sec = 1;
+ ctx->timeout.tv_usec = 0;
+ ctx->sock = -1;
+ ctx->options = MEMC_OPT_DEBUG;
+ strlcpy (param->key, buf, sizeof (param->key));
+ param->buf = buf;
+ param->bufsize = strlen (buf);
+ ctx->param = param;
+ g_assert (memc_init_ctx (ctx) != -1);
+
+ event_loop (0);
+}
+
diff --git a/test/rspamd_test_suite.c b/test/rspamd_test_suite.c
index 7b699f40b..09db78496 100644
--- a/test/rspamd_test_suite.c
+++ b/test/rspamd_test_suite.c
@@ -21,8 +21,7 @@ main (int argc, char **argv)
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/rspamd/url", rspamd_url_test_func);
+ g_test_add_func ("/rspamd/memcached", rspamd_memcached_test_func);
g_test_run ();
-
- g_mem_profile ();
}
diff --git a/test/tests.h b/test/tests.h
index c0e1858a2..85e111b2b 100644
--- a/test/tests.h
+++ b/test/tests.h
@@ -8,4 +8,7 @@
/* URL parser test */
void rspamd_url_test_func ();
+/* Memceched library test */
+void rspamd_memcached_test_func ();
+
#endif