Skip to content

Commit

Permalink
Add: tests of gvm_json_obj_double
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmundell committed Jan 23, 2025
1 parent 3847c1b commit 6e6bd02
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions util/json_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ AfterEach (json)
{
}

/* gvm_json_string_escape */

Ensure (json, can_json_escape_strings)
{
const char *unescaped_string = "\"'Abc\\\b\f\n\r\t\001Äöü'\"";
Expand All @@ -36,6 +38,30 @@ Ensure (json, can_json_escape_strings)
g_free (escaped_string);
}

/* gvm_json_obj_double */

Ensure (json, gvm_json_obj_double_gets_value)
{
cJSON *json;
double d;

json = cJSON_Parse ("{ \"eg\": 2.3 }");
assert_that (json, is_not_null);
d = gvm_json_obj_double (json, "eg");
assert_that_double (d, is_equal_to_double(2.3));
}

Ensure (json, gvm_json_obj_double_0_when_missing)
{
cJSON *json;
double d;

json = cJSON_Parse ("{ \"eg\": 2.3 }");
assert_that (json, is_not_null);
d = gvm_json_obj_double (json, "err");
assert_that_double (d, is_equal_to_double(0));
}

int
main (int argc, char **argv)
{
Expand All @@ -45,6 +71,9 @@ main (int argc, char **argv)

add_test_with_context (suite, json, can_json_escape_strings);

add_test_with_context (suite, json, gvm_json_obj_double_gets_value);
add_test_with_context (suite, json, gvm_json_obj_double_0_when_missing);

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 6e6bd02

Please sign in to comment.