From 3adf3e6a5acda08e941acbdff744940d94e07ade Mon Sep 17 00:00:00 2001 From: "luz.paz" Date: Fri, 20 Sep 2019 13:35:56 -0400 Subject: Fix various typos Found via `codespell -q 2` (v1.17.0.dev0) --- test/suites/api/test_array.c | 6 +++--- test/suites/api/test_object.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/suites/api/test_array.c b/test/suites/api/test_array.c index 9991fa0..a1a0934 100644 --- a/test/suites/api/test_array.c +++ b/test/suites/api/test_array.c @@ -186,7 +186,7 @@ static void test_insert(void) for(i = 0; i < 20; i++) { if(json_array_insert(array, 0, seven)) - fail("unable to insert value at the begining of an array"); + fail("unable to insert value at the beginning of an array"); } for(i = 0; i < 20; i++) { @@ -479,9 +479,9 @@ static void test_bad_args(void) if(!json_array_extend(num, arr)) fail("json_array_extend did not return error for first argument non-array"); if(!json_array_extend(arr, NULL)) - fail("json_array_extend did not return error for second arguemnt non-array"); + fail("json_array_extend did not return error for second argument non-array"); if(!json_array_extend(arr, num)) - fail("json_array_extend did not return error for second arguemnt non-array"); + fail("json_array_extend did not return error for second argument non-array"); if(num->refcount != 1) fail("unexpected reference count on num"); diff --git a/test/suites/api/test_object.c b/test/suites/api/test_object.c index 521ca81..5c8813d 100644 --- a/test/suites/api/test_object.c +++ b/test/suites/api/test_object.c @@ -59,7 +59,7 @@ static void test_update() /* update an empty object with an empty object */ if(json_object_update(object, other)) - fail("unable to update an emtpy object with an empty object"); + fail("unable to update an empty object with an empty object"); if(json_object_size(object) != 0) fail("invalid size after update"); -- cgit v1.1 From 78ea35c8e91489129c67e37df71ac86022ec59f9 Mon Sep 17 00:00:00 2001 From: AllenX2018 Date: Tue, 8 Oct 2019 16:19:40 +0800 Subject: fix issue #426 --- test/suites/api/test_dump.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'test') diff --git a/test/suites/api/test_dump.c b/test/suites/api/test_dump.c index cd4af63..c97a105 100644 --- a/test/suites/api/test_dump.c +++ b/test/suites/api/test_dump.c @@ -13,6 +13,10 @@ #include #endif #include "util.h" +#ifdef __MINGW32__ +#include +#define pipe(fds) _pipe(fds, 1024, _O_BINARY) +#endif static int encode_null_callback(const char *buffer, size_t size, void *data) { -- cgit v1.1 From cb4727c4a931a471f7d2f1594b162a71349b4dfe Mon Sep 17 00:00:00 2001 From: Henrique Cabral Date: Fri, 11 Jan 2019 12:50:37 +0000 Subject: Add json_object_update_recursive() Support merging values nested within objects. For instance, merging: { "foo": 1, "bar": { "baz": 2 } } with { "bar": { "baz": 3 } } results in { "foo": 1, "bar": { "baz": 3 } } instead of overwriting the value for the bar key. --- test/suites/api/test_object.c | 52 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'test') diff --git a/test/suites/api/test_object.c b/test/suites/api/test_object.c index 521ca81..ac10936 100644 --- a/test/suites/api/test_object.c +++ b/test/suites/api/test_object.c @@ -207,6 +207,57 @@ static void test_conditional_updates() json_decref(other); } +static void test_recursive_updates() +{ + json_t *invalid, *object, *other; + + invalid = json_integer(42); + + object = json_pack("{sis{si}}", "foo", 1, "bar", "baz", 2); + other = json_pack("{sisisi}", "foo", 3, "bar", 4, "baz", 5); + + if(!json_object_update_recursive(invalid, other)) + fail("json_object_update_recursive accepted non-object argument"); + + json_decref(invalid); + + if(json_object_update_recursive(object, other)) + fail("json_object_update_recursive failed"); + + if(json_object_size(object) != 3) + fail("invalid size after update"); + + if(json_integer_value(json_object_get(object, "foo")) != 3) + fail("json_object_update_recursive failed to update existing key"); + + if(json_integer_value(json_object_get(object, "bar")) != 4) + fail("json_object_update_recursive failed to overwrite object"); + + if(json_integer_value(json_object_get(object, "baz")) != 5) + fail("json_object_update_recursive didn't add new item"); + + json_decref(object); + json_decref(other); + + object = json_pack("{sis{si}}", "foo", 1, "bar", "baz", 2); + other = json_pack("{s{si}}", "bar", "baz", 3); + + if(json_object_update_recursive(object, other)) + fail("json_object_update_recursive failed"); + + if(json_object_size(object) != 2) + fail("invalid size after update"); + + if(!json_object_get(object, "foo")) + fail("json_object_update_recursive removed existing key"); + + if(json_integer_value(json_object_get(json_object_get(object, "bar"), "baz")) != 3) + fail("json_object_update_recursive failed to update nested value"); + + json_decref(object); + json_decref(other); +} + static void test_circular() { json_t *object1, *object2; @@ -667,6 +718,7 @@ static void run_tests() test_update(); test_set_many_keys(); test_conditional_updates(); + test_recursive_updates(); test_circular(); test_set_nocheck(); test_iterators(); -- cgit v1.1 From 00d2d274bc4260d9197d5003cfb4531f7eca494b Mon Sep 17 00:00:00 2001 From: allen Date: Sat, 12 Oct 2019 15:36:05 +0800 Subject: add loop check for json_object_update_recursive function --- test/suites/api/test_object.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/suites/api/test_object.c b/test/suites/api/test_object.c index ac10936..0493e98 100644 --- a/test/suites/api/test_object.c +++ b/test/suites/api/test_object.c @@ -209,7 +209,7 @@ static void test_conditional_updates() static void test_recursive_updates() { - json_t *invalid, *object, *other; + json_t *invalid, *object, *other, *barBefore, *barAfter; invalid = json_integer(42); @@ -241,6 +241,10 @@ static void test_recursive_updates() object = json_pack("{sis{si}}", "foo", 1, "bar", "baz", 2); other = json_pack("{s{si}}", "bar", "baz", 3); + barBefore = json_object_get(object, "bar"); + + if(!barBefore) + fail("can't get bar object before json_object_update_recursive"); if(json_object_update_recursive(object, other)) fail("json_object_update_recursive failed"); @@ -254,6 +258,33 @@ static void test_recursive_updates() if(json_integer_value(json_object_get(json_object_get(object, "bar"), "baz")) != 3) fail("json_object_update_recursive failed to update nested value"); + barAfter = json_object_get(object, "bar"); + if(!barAfter) + fail("can't get bar object after json_object_update_recursive"); + + if(barBefore != barAfter) + fail("bar object reference changed after json_object_update_recursive"); + + json_decref(object); + json_decref(other); + + /* check circular reference */ + object = json_pack("{s{s{si}}}", "foo", "bar", "baz", 2); + other = json_pack("{s{s{si}}}", "foo", "bar", "baz", 2); + json_object_set(json_object_get(json_object_get(object, "foo"), "bar"), "baz", + json_object_get(other, "foo")); + json_object_set(json_object_get(json_object_get(other, "foo"), "bar"), "baz", + json_object_get(other, "foo")); + + if(!json_object_update_recursive(object, other)) + fail("json_object_update_recursive update a circular reference!"); + + json_object_set_new(json_object_get(json_object_get(other, "foo"), "bar"), "baz", + json_integer(1)); + + if(json_object_update_recursive(object, other)) + fail("json_object_update_recursive failed!"); + json_decref(object); json_decref(other); } -- cgit v1.1 From fb602f331bb356aca4b2ec63c7db4da34773a381 Mon Sep 17 00:00:00 2001 From: allen Date: Mon, 14 Oct 2019 17:32:24 +0800 Subject: update the test case of json_object_update_recursive --- test/suites/api/test_object.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'test') diff --git a/test/suites/api/test_object.c b/test/suites/api/test_object.c index 0493e98..a646ae9 100644 --- a/test/suites/api/test_object.c +++ b/test/suites/api/test_object.c @@ -269,10 +269,8 @@ static void test_recursive_updates() json_decref(other); /* check circular reference */ - object = json_pack("{s{s{si}}}", "foo", "bar", "baz", 2); + object = json_pack("{s{s{s{si}}}}", "foo", "bar", "baz", "xxx", 2); other = json_pack("{s{s{si}}}", "foo", "bar", "baz", 2); - json_object_set(json_object_get(json_object_get(object, "foo"), "bar"), "baz", - json_object_get(other, "foo")); json_object_set(json_object_get(json_object_get(other, "foo"), "bar"), "baz", json_object_get(other, "foo")); -- cgit v1.1 From 010092c7bd21aabaea5d37162b30f526d46c25c4 Mon Sep 17 00:00:00 2001 From: allen Date: Tue, 15 Oct 2019 17:13:12 +0800 Subject: fix typo & add negative test case for test_equal_complex --- test/suites/api/test_equal.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/suites/api/test_equal.c b/test/suites/api/test_equal.c index 339bab6..ed1023f 100644 --- a/test/suites/api/test_equal.c +++ b/test/suites/api/test_equal.c @@ -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 = "{" @@ -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() -- cgit v1.1