diff options
author | Chip Salzenberg <chip@pobox.com> | 2012-04-03 18:00:29 -0700 |
---|---|---|
committer | Chip Salzenberg <chip@pobox.com> | 2013-09-27 17:32:06 -0700 |
commit | 9c259c07aa53381df5819ef61627342c932d626f (patch) | |
tree | c13313ce1ae36aeaea0a441c8335bee67cc689a5 /test/suites/api | |
parent | e4d6a9f6f4f90aa7bb1b5e09d146ac8d2cb3cd1d (diff) | |
download | jansson-9c259c07aa53381df5819ef61627342c932d626f.zip jansson-9c259c07aa53381df5819ef61627342c932d626f.tar.gz jansson-9c259c07aa53381df5819ef61627342c932d626f.tar.bz2 |
Support \u0000 - add size_t string lengths to API, load and dump \u000, etc.
Also:
Steal strings during parsing for half the mallocs!
Change all input-caused assertions to errors. No crashes please, we're programmers.
Diffstat (limited to 'test/suites/api')
-rw-r--r-- | test/suites/api/test_pack.c | 36 | ||||
-rw-r--r-- | test/suites/api/test_unpack.c | 8 |
2 files changed, 38 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 */ diff --git a/test/suites/api/test_unpack.c b/test/suites/api/test_unpack.c index bec8666..7f049dd 100644 --- a/test/suites/api/test_unpack.c +++ b/test/suites/api/test_unpack.c @@ -17,6 +17,7 @@ static void run_tests() int i1, i2, i3; json_int_t I1; int rv; + size_t z; double f; char *s; @@ -81,6 +82,13 @@ static void run_tests() fail("json_unpack string failed"); json_decref(j); + /* string with length (size_t) */ + j = json_string("foo"); + rv = json_unpack(j, "s%", &s, &z); + if(rv || strcmp(s, "foo") || z != 3) + fail("json_unpack string with length (size_t) failed"); + json_decref(j); + /* empty object */ j = json_object(); if(json_unpack(j, "{}")) |