diff options
author | David Harvey-Macaulay <alteous@outlook.com> | 2016-02-22 21:32:20 +0000 |
---|---|---|
committer | David Harvey-Macaulay <alteous@outlook.com> | 2016-02-23 19:28:56 +0000 |
commit | 107cfe94991190d20dd8d7a91e3078167ad62a6f (patch) | |
tree | f1df72056e8a410ba38ad266b5442b067cc04e18 /test/suites/api | |
parent | e08101704c46e7577f17942ce11990990131ff20 (diff) | |
download | jansson-107cfe94991190d20dd8d7a91e3078167ad62a6f.zip jansson-107cfe94991190d20dd8d7a91e3078167ad62a6f.tar.gz jansson-107cfe94991190d20dd8d7a91e3078167ad62a6f.tar.bz2 |
Implemented json_pack() format specifiers 's?', 'o?', and 'O?'.
Diffstat (limited to 'test/suites/api')
-rw-r--r-- | test/suites/api/test_pack.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/test/suites/api/test_pack.c b/test/suites/api/test_pack.c index 9a8a62c..24c49a4 100644 --- a/test/suites/api/test_pack.c +++ b/test/suites/api/test_pack.c @@ -83,6 +83,22 @@ static void run_tests() fail("json_pack string refcount failed"); json_decref(value); + /* nullable string (defined case) */ + value = json_pack("s?", "test"); + if(!json_is_string(value) || strcmp("test", json_string_value(value))) + fail("json_pack nullable string (defined case) failed"); + if(value->refcount != (size_t)1) + fail("json_pack nullable string (defined case) refcount failed"); + json_decref(value); + + /* nullable string (NULL case) */ + value = json_pack("s?", NULL); + if(!json_is_null(value)) + fail("json_pack nullable string (NULL case) failed"); + if(value->refcount != (size_t)-1) + fail("json_pack nullable string (NULL case) refcount failed"); + json_decref(value); + /* string and length (int) */ value = json_pack("s#", "test asdf", 4); if(!json_is_string(value) || strcmp("test", json_string_value(value))) @@ -163,6 +179,22 @@ static void run_tests() fail("json_pack integer refcount failed"); json_decref(value); + /* non-incref'd nullable object (defined case) */ + value = json_pack("o?", json_integer(1)); + if(!json_is_integer(value) || json_integer_value(value) != 1) + fail("json_pack nullable object (defined case) failed"); + if(value->refcount != (size_t)1) + fail("json_pack nullable object (defined case) refcount failed"); + json_decref(value); + + /* non-incref'd nullable object (NULL case) */ + value = json_pack("o?", NULL); + if(!json_is_null(value)) + fail("json_pack nullable object (NULL case) failed"); + if(value->refcount != (size_t)-1) + fail("json_pack nullable object (NULL case) refcount failed"); + json_decref(value); + /* incref'd object */ value = json_pack("O", json_integer(1)); if(!json_is_integer(value) || json_integer_value(value) != 1) @@ -172,6 +204,22 @@ static void run_tests() json_decref(value); json_decref(value); + /* incref'd nullable object (defined case) */ + value = json_pack("O?", json_integer(1)); + if(!json_is_integer(value) || json_integer_value(value) != 1) + fail("json_pack incref'd nullable object (defined case) failed"); + if(value->refcount != (size_t)2) + fail("json_pack incref'd nullable object (defined case) refcount failed"); + json_decref(value); + json_decref(value); + + /* incref'd nullable object (NULL case) */ + value = json_pack("O?", NULL); + if(!json_is_null(value)) + fail("json_pack incref'd nullable object (NULL case) failed"); + if(value->refcount != (size_t)-1) + fail("json_pack incref'd nullable object (NULL case) refcount failed"); + /* simple object */ value = json_pack("{s:[]}", "foo"); if(!json_is_object(value) || json_object_size(value) != 1) |