diff options
Diffstat (limited to 'test/suites/api/test_pack.c')
-rw-r--r-- | test/suites/api/test_pack.c | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/test/suites/api/test_pack.c b/test/suites/api/test_pack.c index b6ac2e5..348d8b2 100644 --- a/test/suites/api/test_pack.c +++ b/test/suites/api/test_pack.c @@ -83,7 +83,7 @@ static void run_tests() fail("json_pack string refcount failed"); json_decref(value); - /* string and length */ + /* string and length (int) */ value = json_pack("s#", "test asdf", 4); if(!json_is_string(value) || strcmp("test", json_string_value(value))) fail("json_pack string and length failed"); @@ -91,14 +91,30 @@ static void run_tests() fail("json_pack string and length refcount failed"); json_decref(value); - /* string and length, non-NUL terminated string */ - value = json_pack("s#", buffer, 4); + /* string and length (size_t) */ + value = json_pack("s%", "test asdf", (size_t)4); if(!json_is_string(value) || strcmp("test", json_string_value(value))) fail("json_pack string and length failed"); if(value->refcount != (size_t)1) fail("json_pack string and length refcount failed"); json_decref(value); + /* string and length (int), non-NUL terminated string */ + value = json_pack("s#", buffer, 4); + if(!json_is_string(value) || strcmp("test", json_string_value(value))) + fail("json_pack string and length (int) failed"); + if(value->refcount != (size_t)1) + fail("json_pack string and length (int) refcount failed"); + json_decref(value); + + /* string and length (size_t), non-NUL terminated string */ + value = json_pack("s%", buffer, (size_t)4); + if(!json_is_string(value) || strcmp("test", json_string_value(value))) + fail("json_pack string and length (size_t) failed"); + if(value->refcount != (size_t)1) + fail("json_pack string and length (size_t) refcount failed"); + json_decref(value); + /* string concatenation */ value = json_pack("s++", "te", "st", "ing"); if(!json_is_string(value) || strcmp("testing", json_string_value(value))) @@ -107,12 +123,20 @@ static void run_tests() fail("json_pack string concatenation refcount failed"); json_decref(value); - /* string concatenation and length */ + /* string concatenation and length (int) */ value = json_pack("s#+#+", "test", 1, "test", 2, "test"); if(!json_is_string(value) || strcmp("ttetest", json_string_value(value))) - fail("json_pack string concatenation and length failed"); + fail("json_pack string concatenation and length (int) failed"); + if(value->refcount != (size_t)1) + fail("json_pack string concatenation and length (int) refcount failed"); + json_decref(value); + + /* string concatenation and length (size_t) */ + value = json_pack("s%+%+", "test", (size_t)1, "test", (size_t)2, "test"); + if(!json_is_string(value) || strcmp("ttetest", json_string_value(value))) + fail("json_pack string concatenation and length (size_t) failed"); if(value->refcount != (size_t)1) - fail("json_pack string concatenation and length refcount failed"); + fail("json_pack string concatenation and length (size_t) refcount failed"); json_decref(value); /* empty object */ |