aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Ghigonis <laurent@p1sec.com>2013-09-18 23:58:03 +0200
committerLaurent Ghigonis <laurent@p1sec.com>2013-09-18 23:58:03 +0200
commit0c315e9a4f04bb670c94f707bd42cf0f433cc40a (patch)
tree38554ed6fea6ccf09c8c382f3e6a6728d9c6498f
parentfix redis events 2 (diff)
downloadglouglou-0c315e9a4f04bb670c94f707bd42cf0f433cc40a.tar.xz
glouglou-0c315e9a4f04bb670c94f707bd42cf0f433cc40a.zip
redis notifications test
-rw-r--r--v3/glougloud/tests/Makefile48
-rw-r--r--v3/glougloud/tests/test_redis_parse_keyspace_notification.c46
2 files changed, 94 insertions, 0 deletions
diff --git a/v3/glougloud/tests/Makefile b/v3/glougloud/tests/Makefile
new file mode 100644
index 0000000..4543571
--- /dev/null
+++ b/v3/glougloud/tests/Makefile
@@ -0,0 +1,48 @@
+CFLAGS +=-L../ -Wall -g
+LDFLAGS=-L../ -levent -ldnet -ldl -lglouglou -lsendbuf -lhiredis
+
+SOURCES = $(shell echo *.c)
+OBJECTS = $(SOURCES:.c=.o)
+TARGETS = $(SOURCES:.c=)
+
+all: $(TARGETS)
+
+run: $(TARGETS)
+ @count=0 ;\
+ errors=0 ;\
+ for test in $(TARGETS); do \
+ echo =============================================================================== ;\
+ echo $$test ;\
+ LD_LIBRARY_PATH=$$LD_LIBRARY_PATH:../ ./$$test ;\
+ if [ $$? -eq 0 ]; then \
+ echo OK ;\
+ else \
+ echo FAILED ;\
+ errors=$$(($$errors + 1)) ;\
+ fi ;\
+ count=$$(($$count + 1)) ;\
+ done ;\
+ echo =============================================================================== ;\
+ echo "$$count tests executed, $$errors errors" ;\
+ exit $$errors
+
+run_loop:
+ @loopcount=20 ;\
+ count=1 ;\
+ while [ $$count -lt $$loopcount ]; do \
+ echo "###############################################################################" ;\
+ make run ;\
+ if [ $$? -ne 0 ]; then \
+ echo ERROR ;\
+ echo "###############################################################################" ;\
+ echo "$$count / $$loopcount loops of tests executed, last one did ERROR" ;\
+ exit $$? ;\
+ fi ;\
+ count=$$(($$count + 1)) ;\
+ done ;\
+ echo "###############################################################################" ;\
+ echo "$$count / $$loopcount loops of tests executed, all OK" ;\
+ exit 0
+
+clean:
+ rm -f $(TARGETS) $(OBJECTS)
diff --git a/v3/glougloud/tests/test_redis_parse_keyspace_notification.c b/v3/glougloud/tests/test_redis_parse_keyspace_notification.c
new file mode 100644
index 0000000..c63292b
--- /dev/null
+++ b/v3/glougloud/tests/test_redis_parse_keyspace_notification.c
@@ -0,0 +1,46 @@
+#include <string.h>
+#include <libglouglou.h>
+#include "../glougloud_internal.h"
+
+int
+main(void)
+{
+ int res;
+ char *ntf_type, *ntf_pattern, *ntf_event_type, *ntf_op, *ntf_target;
+ int ntf_db;
+ redisReply *reply;
+
+ reply = xcalloc(1, sizeof(redisReply));
+ reply->type = REDIS_REPLY_ARRAY;
+ reply->elements = 4;
+ reply->element = xcalloc(4, sizeof(redisReply *));
+ reply->element[0] = xcalloc(1, sizeof(redisReply));
+ reply->element[0]->type = REDIS_REPLY_STRING;
+ reply->element[1] = xcalloc(1, sizeof(redisReply));
+ reply->element[1]->type = REDIS_REPLY_STRING;
+ reply->element[2] = xcalloc(1, sizeof(redisReply));
+ reply->element[2]->type = REDIS_REPLY_STRING;
+ reply->element[3] = xcalloc(1, sizeof(redisReply));
+ reply->element[3]->type = REDIS_REPLY_STRING;
+
+#define test_num 1
+ reply->element[0]->str = strdup("pmessage");
+ reply->element[1]->str = strdup("__key*@*__:*");
+ reply->element[2]->str = strdup("__keyevent@0__:sadd");
+ reply->element[3]->str = strdup("/n/192.168.1.3");
+ res = redis_parse_keyspace_notification(reply,
+ &ntf_type, &ntf_pattern, &ntf_event_type,
+ &ntf_db, &ntf_op, &ntf_target);
+ if ( res < 0
+ || strcmp(ntf_type, "pmessage")
+ || strcmp(ntf_pattern, "__key*@*__:*")
+ || strcmp(ntf_event_type, "keyevent")
+ || (ntf_db != 0)
+ || strcmp(ntf_op, "sadd")
+ || strcmp(ntf_target, "/n/192.168.1.3") ) {
+ printf("Error on %d (%d): %s %s %s %d %s %s\n", test_num, res,
+ ntf_type, ntf_pattern, ntf_event_type, ntf_db, ntf_op, ntf_target);
+ }
+
+ return 0;
+}