Skip to content
Snippets Groups Projects
Commit a3e2e20e authored by Jakob Olsson's avatar Jakob Olsson
Browse files

prepare nested array cmocka test

parent 83329806
Branches
No related tags found
No related merge requests found
...@@ -290,7 +290,7 @@ static void test_json_add_array_nested_object(void **state) ...@@ -290,7 +290,7 @@ static void test_json_add_array_nested_object(void **state)
json_object_object_add(file_obj, "array", arr); json_object_object_add(file_obj, "array", arr);
set_by_string(NULL, &modify_obj, "{\"array\": [{\"nested\": {\"nested1\": {\"integer\": 1}}}]}", json_type_object); set_by_string(NULL, &modify_obj, "{\"array\": [{\"nested\": {\"nested1\": {\"integer\": 1}}}]}", json_type_object);
set_by_string("array[-1].nested.nested1.integer", &modify_obj, "1", json_type_int); set_by_string("array[5].nested.nested1.integer", &modify_obj, "1", json_type_int);
set_by_string("array[-1].nested.nested1", &modify_obj, "{\"integer\": 1}", json_type_object); set_by_string("array[-1].nested.nested1", &modify_obj, "{\"integer\": 1}", json_type_object);
set_by_string("array[-1].nested", &modify_obj, "{\"nested1\": {\"integer\": 1}}", json_type_object); set_by_string("array[-1].nested", &modify_obj, "{\"nested1\": {\"integer\": 1}}", json_type_object);
set_by_string("array[-1]", &modify_obj, "{\"nested\": {\"nested1\": {\"integer\": 1}}}", json_type_object); set_by_string("array[-1]", &modify_obj, "{\"nested\": {\"nested1\": {\"integer\": 1}}}", json_type_object);
...@@ -301,6 +301,34 @@ static void test_json_add_array_nested_object(void **state) ...@@ -301,6 +301,34 @@ static void test_json_add_array_nested_object(void **state)
assert_int_equal(1, json_object_equal(modify_obj, file_obj)); assert_int_equal(1, json_object_equal(modify_obj, file_obj));
} }
static void test_json_add_array_nested_array(void **state)
{
(void) state;
struct json_object *arr = json_object_new_array();
struct json_object *nested_arr = json_object_new_array();
struct json_object *nested1_arr = json_object_new_array();
json_object_array_add(nested_arr, json_object_new_int(1));
json_object_array_add(nested_arr, json_object_new_int(2));
json_object_array_add(nested_arr, json_object_new_int(3));
json_object_array_add(nested1_arr, json_object_new_int(5));
json_object_array_add(nested1_arr, json_object_new_int(6));
json_object_array_add(nested1_arr, json_object_new_int(7));
json_object_array_add(arr, nested_arr);
json_object_array_add(arr, nested1_arr);
json_object_object_add(file_obj, "array", arr);
set_by_string("array[0][0]", &modify_obj, "1", json_type_int);
printf("file_obj=%s\n", json_object_get_string(file_obj));
printf("modify_obj=%s\n", json_object_get_string(modify_obj));
assert_int_equal(1, json_object_equal(modify_obj, file_obj));
}
static int setup (void** state) { static int setup (void** state) {
file_obj = path_to_obj("/home/jakob/git/json-editor-api/test.json"); file_obj = path_to_obj("/home/jakob/git/json-editor-api/test.json");
modify_obj = path_to_obj("/home/jakob/git/json-editor-api/test.json"); modify_obj = path_to_obj("/home/jakob/git/json-editor-api/test.json");
...@@ -329,6 +357,7 @@ int main(void) { ...@@ -329,6 +357,7 @@ int main(void) {
cmocka_unit_test_setup_teardown(test_json_add_array_int, setup, teardown), cmocka_unit_test_setup_teardown(test_json_add_array_int, setup, teardown),
cmocka_unit_test_setup_teardown(test_json_add_array_object, setup, teardown), cmocka_unit_test_setup_teardown(test_json_add_array_object, setup, teardown),
cmocka_unit_test_setup_teardown(test_json_add_array_nested_object, setup, teardown), cmocka_unit_test_setup_teardown(test_json_add_array_nested_object, setup, teardown),
cmocka_unit_test_setup_teardown(test_json_add_array_nested_array, setup, teardown),
}; };
return cmocka_run_group_tests(tests, NULL, NULL); return cmocka_run_group_tests(tests, NULL, NULL);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment