Skip to content

Commit

Permalink
Add: tests of gvm_json_obj_check_str
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmundell authored and bjoernricks committed Feb 7, 2025
1 parent ae513e3 commit 90c5498
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions util/json_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,50 @@ Ensure (json, gvm_json_obj_double_0_when_missing)
assert_that_double (d, is_equal_to_double (0));
}

/* gvm_json_obj_check_str */

Ensure (json, gvm_json_obj_check_str_0_when_has)
{
cJSON *json;

json = cJSON_Parse ("{ \"eg\": \"abc\" }");
assert_that (json, is_not_null);
assert_that (gvm_json_obj_check_str (json, "eg", NULL), is_equal_to (0));
cJSON_Delete (json);
}

Ensure (json, gvm_json_obj_check_str_1_when_missing)
{
cJSON *json;

json = cJSON_Parse ("{ \"eg\": \"abc\" }");
assert_that (json, is_not_null);
assert_that (gvm_json_obj_check_str (json, "err", NULL), is_equal_to (1));
cJSON_Delete (json);
}

Ensure (json, gvm_json_obj_check_str_1_when_int)
{
cJSON *json;

json = cJSON_Parse ("{ \"eg\": 29 }");
assert_that (json, is_not_null);
assert_that (gvm_json_obj_check_str (json, "eg", NULL), is_equal_to (1));
cJSON_Delete (json);
}

Ensure (json, gvm_json_obj_check_str_0_and_val_when_has)
{
cJSON *json;
gchar *ret;

json = cJSON_Parse ("{ \"eg\": \"abc\" }");
assert_that (json, is_not_null);
assert_that (gvm_json_obj_check_str (json, "eg", &ret), is_equal_to (0));
assert_that (ret, is_equal_to_string ("abc"));
cJSON_Delete (json);
}

/* gvm_json_obj_str */

Ensure (json, gvm_json_obj_str_gets_value)
Expand Down Expand Up @@ -195,6 +239,12 @@ main (int argc, char **argv)
add_test_with_context (suite, json,
gvm_json_obj_check_int_0_and_val_when_has);

add_test_with_context (suite, json, gvm_json_obj_check_str_0_when_has);
add_test_with_context (suite, json, gvm_json_obj_check_str_1_when_missing);
add_test_with_context (suite, json, gvm_json_obj_check_str_1_when_int);
add_test_with_context (suite, json,
gvm_json_obj_check_str_0_and_val_when_has);

if (argc > 1)
return run_single_test (suite, argv[1], create_text_reporter ());
return run_test_suite (suite, create_text_reporter ());
Expand Down

0 comments on commit 90c5498

Please sign in to comment.