diff options
author | Chip Salzenberg <chip@pobox.com> | 2013-10-03 19:07:50 -0700 |
---|---|---|
committer | Chip Salzenberg <chip@pobox.com> | 2013-10-03 19:07:50 -0700 |
commit | c7d479c74089e9251698f65a1202baf1ef3e8f16 (patch) | |
tree | bcdd88f18237bc4e214c6db4aa2064f5ac57b6b7 /test/suites/api | |
parent | a76dc45512acf8182f4fad5d3a9d5db6e08bbe9e (diff) | |
download | jansson-c7d479c74089e9251698f65a1202baf1ef3e8f16.zip jansson-c7d479c74089e9251698f65a1202baf1ef3e8f16.tar.gz jansson-c7d479c74089e9251698f65a1202baf1ef3e8f16.tar.bz2 |
in simple string tests, always check lengths too
Diffstat (limited to 'test/suites/api')
-rw-r--r-- | test/suites/api/test_simple.c | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/test/suites/api/test_simple.c b/test/suites/api/test_simple.c index d24d84e..ca97a7d 100644 --- a/test/suites/api/test_simple.c +++ b/test/suites/api/test_simple.c @@ -72,11 +72,22 @@ static void run_tests() fail("json_string failed"); if(strcmp(json_string_value(value), "foo")) fail("invalid string value"); + if (json_string_length(value) != 3) + fail("invalid string length"); - if(json_string_set(value, "bar")) + if(json_string_set(value, "barr")) fail("json_string_set failed"); - if(strcmp(json_string_value(value), "bar")) + if(strcmp(json_string_value(value), "barr")) fail("invalid string value"); + if (json_string_length(value) != 4) + fail("invalid string length"); + + if(json_string_setn(value, "hi\0ho", 5)) + fail("json_string_set failed"); + if(memcmp(json_string_value(value), "hi\0ho\0", 6)) + fail("invalid string value"); + if (json_string_length(value) != 5) + fail("invalid string length"); json_decref(value); @@ -94,11 +105,22 @@ static void run_tests() fail("json_string_nocheck failed"); if(strcmp(json_string_value(value), "foo")) fail("invalid string value"); + if (json_string_length(value) != 3) + fail("invalid string length"); - if(json_string_set_nocheck(value, "bar")) + if(json_string_set_nocheck(value, "barr")) fail("json_string_set_nocheck failed"); - if(strcmp(json_string_value(value), "bar")) + if(strcmp(json_string_value(value), "barr")) + fail("invalid string value"); + if (json_string_length(value) != 4) + fail("invalid string length"); + + if(json_string_setn_nocheck(value, "hi\0ho", 5)) + fail("json_string_set failed"); + if(memcmp(json_string_value(value), "hi\0ho\0", 6)) fail("invalid string value"); + if (json_string_length(value) != 5) + fail("invalid string length"); json_decref(value); @@ -108,11 +130,15 @@ static void run_tests() fail("json_string_nocheck failed"); if(strcmp(json_string_value(value), "qu\xff")) fail("invalid string value"); + if (json_string_length(value) != 3) + fail("invalid string length"); if(json_string_set_nocheck(value, "\xfd\xfe\xff")) fail("json_string_set_nocheck failed"); if(strcmp(json_string_value(value), "\xfd\xfe\xff")) fail("invalid string value"); + if (json_string_length(value) != 3) + fail("invalid string length"); json_decref(value); |