diff options
author | Nathaniel McCallum <npmccallum@redhat.com> | 2017-04-18 11:05:38 -0400 |
---|---|---|
committer | Nathaniel McCallum <npmccallum@redhat.com> | 2017-04-19 07:19:29 -0400 |
commit | 28666cead0a4c946b234d42f25b8a9db81f9bbdf (patch) | |
tree | 76461c6f2846a8d4acab5948be306de3650f7e17 /test/suites | |
parent | 74028ff958ce9ded8cf58bdee3151d3df94bafc4 (diff) | |
download | jansson-28666cead0a4c946b234d42f25b8a9db81f9bbdf.zip jansson-28666cead0a4c946b234d42f25b8a9db81f9bbdf.tar.gz jansson-28666cead0a4c946b234d42f25b8a9db81f9bbdf.tar.bz2 |
Enable optional object/array members in json_pack()
Diffstat (limited to 'test/suites')
-rw-r--r-- | test/suites/api/test_pack.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/test/suites/api/test_pack.c b/test/suites/api/test_pack.c index 798a057..65783b1 100644 --- a/test/suites/api/test_pack.c +++ b/test/suites/api/test_pack.c @@ -240,6 +240,18 @@ static void run_tests() fail("json_pack object refcount failed"); json_decref(value); + /* object with optional members */ + value = json_pack("{s:s,s:o,s:O}", "a", NULL, "b", NULL, "c", NULL); + if(value) + fail("json_pack object optional incorrectly succeeded"); + value = json_pack("{s:**}", "a", NULL); + if(value) + fail("json_pack object optional invalid incorrectly succeeded"); + value = json_pack("{s:s*,s:o*,s:O*}", "a", NULL, "b", NULL, "c", NULL); + if(!json_is_object(value) || json_object_size(value) != 0) + fail("json_pack object optional failed"); + json_decref(value); + /* simple array */ value = json_pack("[i,i,i]", 0, 1, 2); if(!json_is_array(value) || json_array_size(value) != 3) @@ -253,6 +265,18 @@ static void run_tests() } json_decref(value); + /* simple array with optional members */ + value = json_pack("[s,o,O]", NULL, NULL, NULL); + if(value) + fail("json_pack array optional incorrectly succeeded"); + value = json_pack("[**]", NULL); + if(value) + fail("json_pack array optional invalid incorrectly succeeded"); + value = json_pack("[s*,o*,O*]", NULL, NULL, NULL); + if(!json_is_array(value) || json_array_size(value) != 0) + fail("json_pack array optional failed"); + json_decref(value); + /* Whitespace; regular string */ value = json_pack(" s ", "test"); if(!json_is_string(value) || strcmp("test", json_string_value(value))) |