Skip to content

Commit

Permalink
Merge pull request #506 from AllenX2018/add-json_equal-test-case
Browse files Browse the repository at this point in the history
fix typo & add negative test case for test_equal_complex
  • Loading branch information
akheron committed Oct 17, 2019
2 parents c436bec + 010092c commit 9e1c37c
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions test/suites/api/test_equal.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ static void test_equal_object()

static void test_equal_complex()
{
json_t *value1, *value2;
json_t *value1, *value2, *value3;

const char *complex_json =
"{"
Expand All @@ -176,15 +176,25 @@ static void test_equal_complex()

value1 = json_loads(complex_json, 0, NULL);
value2 = json_loads(complex_json, 0, NULL);
value3 = json_loads(complex_json, 0, NULL);
if(!value1 || !value2)
fail("unable to parse JSON");
if(!json_equal(value1, value2))
fail("json_equal fails for two inequal strings");
fail("json_equal fails for two equal objects");

json_array_set_new(json_object_get(json_object_get(value2, "object"),
"array-in-object"), 1, json_false());
if(json_equal(value1, value2))
fail("json_equal fails for two inequal objects");

json_object_set_new(json_object_get(json_object_get(value3, "object"),
"object-in-object"), "foo", json_string("baz"));
if(json_equal(value1, value3))
fail("json_equal fails for two inequal objects");

json_decref(value1);
json_decref(value2);

/* TODO: There's no negative test case here */
json_decref(value3);
}

static void run_tests()
Expand Down

0 comments on commit 9e1c37c

Please sign in to comment.