diff options
author | Yorhel <git@yorhel.nl> | 2012-03-15 19:11:45 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2012-03-15 19:11:45 +0100 |
commit | 15c680134b7f435d53f6426ad5a71a3329a81d28 (patch) | |
tree | c15d2a0d0b3b7e14de69941e1a7c9a1209c51767 | |
parent | 105b71d23e9e1c1c357340fef748cc95880a45da (diff) |
Moved tests and Makefile to subdir + split json tests in separate file
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | Makefile | 12 | ||||
-rw-r--r-- | test/Makefile | 23 | ||||
-rw-r--r-- | test/json.c (renamed from test.c) | 50 | ||||
-rw-r--r-- | test/pthread.c | 58 |
5 files changed, 85 insertions, 61 deletions
@@ -1,2 +1,3 @@ *.o -test +test/json +test/pthread diff --git a/Makefile b/Makefile deleted file mode 100644 index caf01b9..0000000 --- a/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -CC=gcc -CFLAGS=-Wall -Wextra -g -O3 -DTANJA_THREADSAFE -LDFLAGS=-lm - -tanja.o: Makefile tanja.c tanja.h - $(CC) $(CFLAGS) -c tanja.c -o tanja.o - -tanja_pthread.o: tanja.o tanja_pthread.c - $(CC) $(CFLAGS) -c tanja_pthread.c -o tanja_pthread.o - -test: test.c tanja_pthread.o - $(CC) $(CFLAGS) $(LDFLAGS) tanja.o tanja_pthread.o test.c -lpthread -o test diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..ae473e1 --- /dev/null +++ b/test/Makefile @@ -0,0 +1,23 @@ +CC=gcc +CFLAGS=-I.. -Wall -Wextra -g -O2 +LDFLAGS=-lm + +.PHONY: all clean test + +COMP=$(CC) $(CFLAGS) $(LDFLAGS) ../tanja.c +DEP=../tanja.c ../tanja.h ../khash.h +THREAD=-DTANJA_THREADSAFE -lpthread + +all: test + +json: $(DEP) json.c + $(COMP) json.c -o json + +pthread: $(DEP) ../tanja_pthread.c pthread.c + $(COMP) $(THREAD) ../tanja_pthread.c pthread.c -o pthread + +test: json + prove ./json + +clean: + rm -f json pthread @@ -1,27 +1,7 @@ -#include <stdlib.h> #include <stdio.h> -#include <string.h> -#include <unistd.h> #include <stdlib.h> -#include <pthread.h> -#include "tanja.h" - - -extern tn_session *tn_session_pthread(tn_node *, pthread_t *); -extern tn_link *tn_link_pthread_fd(tn_node *, int, int, int, pthread_t *); - -void do_quit(tn_session *s, tn_tuple *tup, tn_returnpath *p, void *d) { - if(d) {} - if(p) {} - tn_tuple_unref(tup); - tn_session_close(s); - printf("Closing!\n"); -} - -void print_error(tn_link *l, int code, char *msg) { - if(l) {} - printf("Link error #%d: %s\n", code, msg?msg:"(empty)"); -} +#include <string.h> +#include <tanja.h> static int test_num = 0; @@ -136,32 +116,6 @@ int main() { test_tuples(); printf("1..%d\n", test_num); return 0; - tn_tuple *t = tn_tuple_new("i*sam", 1293, strdup("som\\\"e_strin\01g"), - tn_array_new("i", INT64_MIN), - tn_map_new("sn", strdup("k\ney"), strdup("va\rlue"), strdup("number\""), 1.5e10) - ); - char *buf = tn_json_fmt(t); - puts(buf); - free(buf); - tn_tuple_unref(t); - tn_node *n = tn_node_create(); - - pthread_t th; - tn_session *s = tn_session_pthread(n, &th); - - tn_session_register(s, tn_tuple_new(""), 0, do_quit, NULL); - tn_session_send(s, tn_tuple_new("i", 1), NULL, NULL); - - pthread_join(th, NULL); - - // And now a link with STDIO - tn_link *l = tn_link_pthread_fd(n, 1, STDIN_FILENO, STDOUT_FILENO, &th); - tn_link_on_error(l, print_error); - tn_link_start(l); - pthread_join(th, NULL); - - tn_node_unref(n); - return 0; } // vim:noet:sw=4:ts=4 diff --git a/test/pthread.c b/test/pthread.c new file mode 100644 index 0000000..6d85df2 --- /dev/null +++ b/test/pthread.c @@ -0,0 +1,58 @@ +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include <stdlib.h> +#include <pthread.h> +#include "tanja.h" + + +// TODO: Turn this into some automated test or something + +extern tn_session *tn_session_pthread(tn_node *, pthread_t *); +extern tn_link *tn_link_pthread_fd(tn_node *, int, int, int, pthread_t *); + +void do_quit(tn_session *s, tn_tuple *tup, tn_returnpath *p, void *d) { + if(d) {} + if(p) {} + tn_tuple_unref(tup); + tn_session_close(s); + printf("Closing!\n"); +} + +void print_error(tn_link *l, int code, char *msg) { + if(l) {} + printf("Link error #%d: %s\n", code, msg?msg:"(empty)"); +} + + +int main() { + tn_tuple *t = tn_tuple_new("i*sam", 1293, strdup("som\\\"e_strin\01g"), + tn_array_new("i", INT64_MIN), + tn_map_new("sn", strdup("k\ney"), strdup("va\rlue"), strdup("number\""), 1.5e10) + ); + char *buf = tn_json_fmt(t); + puts(buf); + free(buf); + tn_tuple_unref(t); + tn_node *n = tn_node_create(); + + pthread_t th; + tn_session *s = tn_session_pthread(n, &th); + + tn_session_register(s, tn_tuple_new(""), 0, do_quit, NULL); + tn_session_send(s, tn_tuple_new("i", 1), NULL, NULL); + + pthread_join(th, NULL); + + // And now a link with STDIO + tn_link *l = tn_link_pthread_fd(n, 1, STDIN_FILENO, STDOUT_FILENO, &th); + tn_link_on_error(l, print_error); + tn_link_start(l); + pthread_join(th, NULL); + + tn_node_unref(n); + return 0; +} + +// vim:noet:sw=4:ts=4 |