diff options
author | chenguoping <chenguopingdota@163.com> | 2020-01-03 10:05:09 +0800 |
---|---|---|
committer | dota17 <chenguopingdota@163.com> | 2020-04-14 10:03:58 +0800 |
commit | f56c5c1a603f625d200055ee646df2d99a8a9b5e (patch) | |
tree | 9fac2ed63ae92829fe3f4bee2d18c6827bb7ac3c | |
parent | 4742a2ab1db2303307b3f994a709552e572f6d65 (diff) | |
download | json-c-f56c5c1a603f625d200055ee646df2d99a8a9b5e.tar.gz |
Increased the test coverage of json_object_iterator.c from 0% to 100%
-rw-r--r-- | tests/CMakeLists.txt | 3 | ||||
-rw-r--r-- | tests/test_object_iterator.c | 40 | ||||
-rw-r--r-- | tests/test_object_iterator.expected | 14 | ||||
l--------- | tests/test_object_iterator.test | 1 |
4 files changed, 57 insertions, 1 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f18d9f3..a871573 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -33,7 +33,8 @@ foreach(TESTNAME test_set_serializer test_set_value test_util_file - test_visit) + test_visit + test_object_iterator) add_executable(${TESTNAME} ${TESTNAME}.c) add_test(NAME ${TESTNAME} COMMAND ${PROJECT_SOURCE_DIR}/tests/${TESTNAME}.test) diff --git a/tests/test_object_iterator.c b/tests/test_object_iterator.c new file mode 100644 index 0000000..5bc5101 --- /dev/null +++ b/tests/test_object_iterator.c @@ -0,0 +1,40 @@ +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include "config.h" + +#include "json_object.h" +#include "json_tokener.h" +#include "json_object_iterator.h" + +int main(int atgc, char **argv) +{ + const char *input = "{\n\ + \"string_of_digits\": \"123\",\n\ + \"regular_number\": 222,\n\ + \"decimal_number\": 99.55,\n\ + \"boolean_true\": true,\n\ + \"boolean_false\": false,\n\ + \"big_number\": 2147483649,\n\ + \"a_null\": null,\n\ + }"; + + struct json_object *new_obj; + struct json_object_iterator it; + struct json_object_iterator itEnd; + + it = json_object_iter_init_default(); + new_obj = json_tokener_parse(input); + it = json_object_iter_begin(new_obj); + itEnd = json_object_iter_end(new_obj); + + while (!json_object_iter_equal(&it,&itEnd)) { + printf("%s\n",json_object_iter_peek_name(&it)); + printf("%s\n",json_object_to_json_string(json_object_iter_peek_value(&it))); + json_object_iter_next(&it); + } + + json_object_put(new_obj); + + return 0; +} diff --git a/tests/test_object_iterator.expected b/tests/test_object_iterator.expected new file mode 100644 index 0000000..e56e288 --- /dev/null +++ b/tests/test_object_iterator.expected @@ -0,0 +1,14 @@ +string_of_digits +"123" +regular_number +222 +decimal_number +99.55 +boolean_true +true +boolean_false +false +big_number +2147483649 +a_null +null diff --git a/tests/test_object_iterator.test b/tests/test_object_iterator.test new file mode 120000 index 0000000..58a13f4 --- /dev/null +++ b/tests/test_object_iterator.test @@ -0,0 +1 @@ +test_basic.test
\ No newline at end of file |