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

add failure verification tests

parent f38670f0
No related branches found
No related tags found
No related merge requests found
...@@ -540,6 +540,77 @@ static void test_json_write_to_file(void **state) ...@@ -540,6 +540,77 @@ static void test_json_write_to_file(void **state)
json_object_put(obj); json_object_put(obj);
} }
static void test_json_set_object_invalid_format(void **state)
{
struct test_env *e = (struct test_env *) *state;
struct json_object *obj = json_object_new_object();
json_object_object_add(obj, "test2", json_object_new_string("success"));
json_object_object_add(e->file_obj, "string", obj);
json_object_set_by_string(&e->modify_obj, "string", "{\"test2\":\"success\"", json_type_object);
printf("e->file_obj=%s\n", json_object_get_string(e->file_obj));
printf("e->modify_obj=%s\n", json_object_get_string(e->modify_obj));
assert_non_null(e->file_obj);
assert_non_null(e->modify_obj);
assert_int_not_equal(1, json_object_equal(e->modify_obj, e->file_obj));
}
static void test_json_set_array_invalid_format(void **state)
{
struct test_env *e = (struct test_env *) *state;
struct json_object *arr = json_object_new_array();
json_object_array_add(arr, json_object_new_int(1));
json_object_array_add(arr, json_object_new_int(2));
json_object_array_add(arr, json_object_new_int(3));
json_object_object_add(e->file_obj, "ints", arr);
json_object_set_by_string(&e->modify_obj, "ints", "[ 1, 2 3 ]", json_type_array);
printf("e->file_obj=%s\n", json_object_get_string(e->file_obj));
printf("e->modify_obj=%s\n", json_object_get_string(e->modify_obj));
assert_non_null(e->file_obj);
assert_non_null(e->modify_obj);
assert_int_not_equal(1, json_object_equal(e->modify_obj, e->file_obj));
}
static void test_json_set_wrong_type_string_to_int(void **state)
{
struct test_env *e = (struct test_env *) *state;
json_object_object_add(e->file_obj, "string", json_object_new_string("abc"));
json_object_set_by_string(&e->modify_obj, "string", "abc", json_type_int);
printf("e->file_obj=%s\n", json_object_get_string(e->file_obj));
printf("e->modify_obj=%s\n", json_object_get_string(e->modify_obj));
assert_non_null(e->file_obj);
assert_non_null(e->modify_obj);
assert_int_not_equal(1, json_object_equal(e->modify_obj, e->file_obj));
}
static void test_json_set_wrong_type_int_to_string(void **state)
{
struct test_env *e = (struct test_env *) *state;
json_object_object_add(e->file_obj, "string", json_object_new_int(1));
json_object_set_by_string(&e->modify_obj, "string", "1", json_type_string);
printf("e->file_obj=%s\n", json_object_get_string(e->file_obj));
printf("e->modify_obj=%s\n", json_object_get_string(e->modify_obj));
assert_non_null(e->modify_obj);
assert_int_not_equal(1, json_object_equal(e->modify_obj, e->file_obj));
}
static int setup (void** state) { static int setup (void** state) {
struct test_env *e = (struct test_env *) *state; struct test_env *e = (struct test_env *) *state;
...@@ -600,6 +671,10 @@ int main(void) { ...@@ -600,6 +671,10 @@ int main(void) {
cmocka_unit_test_setup_teardown(test_json_get_array_nested_int, setup, teardown), cmocka_unit_test_setup_teardown(test_json_get_array_nested_int, setup, teardown),
cmocka_unit_test_setup_teardown(test_json_get_object_array_nested_int, setup, teardown), cmocka_unit_test_setup_teardown(test_json_get_object_array_nested_int, setup, teardown),
cmocka_unit_test_setup_teardown(test_json_write_to_file, setup, teardown), cmocka_unit_test_setup_teardown(test_json_write_to_file, setup, teardown),
cmocka_unit_test_setup_teardown(test_json_set_object_invalid_format, setup, teardown),
cmocka_unit_test_setup_teardown(test_json_set_array_invalid_format, setup, teardown),
cmocka_unit_test_setup_teardown(test_json_set_wrong_type_string_to_int, setup, teardown),
cmocka_unit_test_setup_teardown(test_json_set_wrong_type_int_to_string, setup, teardown),
}; };
return cmocka_run_group_tests(tests, group_setup, group_teardown); return cmocka_run_group_tests(tests, group_setup, group_teardown);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment