diff options
author | sternenseemann <0rpkxez4ksa01gb3typccl0i@systemli.org> | 2020-09-25 21:13:47 +0200 |
---|---|---|
committer | sternenseemann <0rpkxez4ksa01gb3typccl0i@systemli.org> | 2020-09-25 21:13:47 +0200 |
commit | baecfd220afc0dd0dca31101637e29d418e699f5 (patch) | |
tree | 0c074e83d7d2f0c0a8daabcf40716d8368819a32 | |
parent | dc8610fb0e71b0b848e7273d8c78d4089d7debfb (diff) |
test(routing): very simple sanity check
-rw-r--r-- | warteraum/test/all.do | 2 | ||||
-rw-r--r-- | warteraum/test/default.exe.do | 4 | ||||
-rwxr-xr-x | warteraum/test/run | 11 | ||||
-rw-r--r-- | warteraum/test/test.h | 2 | ||||
-rw-r--r-- | warteraum/test/test_routing.c | 33 |
5 files changed, 46 insertions, 6 deletions
diff --git a/warteraum/test/all.do b/warteraum/test/all.do index b1a5a94..6bd544d 100644 --- a/warteraum/test/all.do +++ b/warteraum/test/all.do @@ -1 +1 @@ -redo-ifchange test_queue.exe test_form.exe +redo-ifchange test_queue.exe test_form.exe test_routing.exe diff --git a/warteraum/test/default.exe.do b/warteraum/test/default.exe.do index c01fe3e..a1e90d3 100644 --- a/warteraum/test/default.exe.do +++ b/warteraum/test/default.exe.do @@ -11,6 +11,10 @@ case "$2" in OBJS="../form.o" redo-ifchange ../http_string.h ;; + test_routing) + OBJS="../routing.o" + redo-ifchange ../http_string.h + ;; esac redo-ifchange $OBJS diff --git a/warteraum/test/run b/warteraum/test/run index 50a1d2b..e78a487 100755 --- a/warteraum/test/run +++ b/warteraum/test/run @@ -5,7 +5,10 @@ cd "$(dirname "$0")" redo all -echo -e "\n# queue tests\n" -./test_queue.exe -echo -e "\n# form parsing tests\n" -./test_form.exe +TESTS="queue form routing" + +for t in $TESTS; do + + echo -e "\n# $t tests\n" + "./test_$t.exe" +done diff --git a/warteraum/test/test.h b/warteraum/test/test.h index 5e76d3f..b2663a2 100644 --- a/warteraum/test/test.h +++ b/warteraum/test/test.h @@ -10,7 +10,7 @@ #define TEST_INFO_WIDTH 50 #endif -static bool test_result; +static bool test_result = true; void test_case(char *info, bool result) { char *result_str = "okay"; diff --git a/warteraum/test/test_routing.c b/warteraum/test/test_routing.c new file mode 100644 index 0000000..8400d2c --- /dev/null +++ b/warteraum/test/test_routing.c @@ -0,0 +1,33 @@ +#include <stdbool.h> +#include <stdio.h> + +#define TEST_EXIT_ON_FAIL true +#include "test.h" + +#include "../http_string.h" +#include "../routing.h" + +int main(void) { + { + struct http_string_s root = STATIC_HTTP_STRING("/"); + struct http_string_s *segs = NULL; + + test_case("root returns no segments", split_segments(root, &segs) == 0); + + free(segs); + } + + { + struct http_string_s strange = STATIC_HTTP_STRING("/foo/ba%20r/baz?hello=world"); + struct http_string_s *segs = NULL; + + int count = split_segments(strange, &segs); + + test_case("correct amount of segments", count == 3); + test_case("correct segments", HTTP_STRING_IS(segs[0], "foo") + && HTTP_STRING_IS(segs[1], "ba%20r") + && HTTP_STRING_IS(segs[2], "baz?hello=world")); + + free(segs); + } +} |