diff --git a/test/api_test.c b/test/api_test.c index be3d36445f19dddef0c2ada1aea1111cc115850e..02f2a5faa910c3f17e2748329c5f89003524b311 100644 --- a/test/api_test.c +++ b/test/api_test.c @@ -15,17 +15,39 @@ struct test_env { static void test_cfg_parse_success(void **state) { struct json_object *file = json_object_file_to_obj("test.json"); - struct json_object *obj = json_object_new_object(); - struct json_object *tot = json_object_new_object(); + struct json_object *expected = json_tokener_parse("{\ + \"test\":\"success\",\ + \"nested\": { \ + \"api\":\"test2\"\ + },\ + \"integer\": 1,\ + \"simple_array\": [1, 2, 3, 4],\ + \"array\": [[1, 2, 3],[4, 5, 6]],\ + \"complex_nested\": {\ + \"dummy\": {},\ + \"array\": [\ + {\ + \"test\":\"1\",\ + \"test2\":2\ + },\ + {\ + \"test\": \"3\",\ + \"test2\": 4\ + }\ + ]\ + }\ + }"); - assert_non_null(file); + printf("expected json: %s\n", json_object_get_string(file)); + printf("read from file: %s\n", json_object_get_string(expected)); - json_object_object_add(obj, "api", json_object_new_string("test2")); - json_object_object_add(tot, "nested", obj); - json_object_object_add(tot, "test", json_object_new_string("success")); + assert_non_null(file); + assert_non_null(expected); - assert_int_equal(1, json_object_equal(file, tot)); + assert_int_equal(1, json_object_equal(file, expected)); + json_object_put(file); + json_object_put(expected); } static void test_cfg_parse_fail(void **state) @@ -647,8 +669,8 @@ static int group_teardown(void** state) { int main(void) { const struct CMUnitTest tests[] = { - //cmocka_unit_test(test_cfg_parse_success), - //cmocka_unit_test(test_cfg_parse_fail), + cmocka_unit_test(test_cfg_parse_success), + cmocka_unit_test(test_cfg_parse_fail), cmocka_unit_test(test_build_from_scratch), cmocka_unit_test_setup_teardown(test_json_set_int, setup, teardown), cmocka_unit_test_setup_teardown(test_json_set_int_nested, setup, teardown),