From 44b8068c58d0f9323ba9dc74cb220daa46650b63 Mon Sep 17 00:00:00 2001 From: c9s Date: Mon, 2 Jun 2014 05:59:57 +0800 Subject: [PATCH] check_json.c --- tests/check_json.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 tests/check_json.c diff --git a/tests/check_json.c b/tests/check_json.c new file mode 100644 index 0000000..f15109e --- /dev/null +++ b/tests/check_json.c @@ -0,0 +1,58 @@ +/* + * check_json.c + * Copyright (C) 2014 c9s + * + * Distributed under terms of the MIT license. + */ +#include "config.h" +#include +#include +#include +#include +#include "r3.h" +#include "r3_str.h" +#include "zmalloc.h" + +START_TEST (test_json_encode) +{ + node * n; + n = r3_tree_create(10); + + ck_assert(n); + + r3_tree_insert_path(n, "/zoo", NULL); + r3_tree_insert_path(n, "/foo", NULL); + r3_tree_insert_path(n, "/bar", NULL); + + r3_tree_insert_route(n, METHOD_GET, "/post/get", NULL); + r3_tree_insert_route(n, METHOD_POST, "/post/post", NULL); + + r3_tree_compile(n, NULL); + + json_object * obj = r3_node_to_json_object(n); + ck_assert(obj); + + const char *json = r3_node_to_json_pretty_string(n); + + printf("JSON: %s\n",json); +} +END_TEST + +Suite* r3_suite (void) { + Suite *suite = suite_create("json test"); + TCase *tcase = tcase_create("json test"); + tcase_add_test(tcase, test_json_encode); + suite_add_tcase(suite, tcase); + return suite; +} + +int main (int argc, char *argv[]) { + int number_failed; + Suite *suite = r3_suite(); + SRunner *runner = srunner_create(suite); + srunner_run_all(runner, CK_NORMAL); + number_failed = srunner_ntests_failed(runner); + srunner_free(runner); + return number_failed; +} +