diff options
author | Petri Lehtinen <petri@digip.org> | 2009-09-06 22:24:55 +0300 |
---|---|---|
committer | Petri Lehtinen <petri@digip.org> | 2009-09-06 22:24:55 +0300 |
commit | 234ee4728124d8d07412d159b45dd10854b6d6d8 (patch) | |
tree | 01c5714c029aed649720a09f5d1d85d28ebcbf9d /test | |
parent | 98a8c1aebff7a414f0830bc4f6b7bee19405f865 (diff) | |
download | jansson-234ee4728124d8d07412d159b45dd10854b6d6d8.zip jansson-234ee4728124d8d07412d159b45dd10854b6d6d8.tar.gz jansson-234ee4728124d8d07412d159b45dd10854b6d6d8.tar.bz2 |
Better argument validation
All pointer arguments are now tested for NULL. json_string() now also
tests that strdup() succeeds. This is to ensure that no NULL values
end up in data structures.
Also desribe the different sources of errors in documentation.
Diffstat (limited to 'test')
-rw-r--r-- | test/testprogs/test_array.c | 20 | ||||
-rw-r--r-- | test/testprogs/test_object.c | 16 | ||||
-rw-r--r-- | test/testprogs/test_simple.c | 4 |
3 files changed, 37 insertions, 3 deletions
diff --git a/test/testprogs/test_array.c b/test/testprogs/test_array.c index 97a8513..b597afb 100644 --- a/test/testprogs/test_array.c +++ b/test/testprogs/test_array.c @@ -27,6 +27,9 @@ int main() if(json_array_size(array) != 0) fail("empty array has nonzero size"); + if(!json_array_append(array, NULL)) + fail("able to append NULL"); + if(json_array_append(array, five)) fail("unable to append"); @@ -54,6 +57,9 @@ int main() if(json_array_set(array, 0, seven)) fail("unable to set value"); + if(!json_array_set(array, 0, NULL)) + fail("able to set NULL"); + if(json_array_size(array) != 2) fail("wrong array size"); @@ -85,16 +91,26 @@ int main() fail("got wrong value"); } - json_array_set_new(array, 15, json_integer(123)); + if(json_array_set_new(array, 15, json_integer(123))) + fail("unable to set new value"); + value = json_array_get(array, 15); if(!json_is_integer(value) || json_integer_value(value) != 123) fail("json_array_set_new works incorrectly"); - json_array_append_new(array, json_integer(321)); + if(!json_array_set_new(array, 15, NULL)) + fail("able to set_new NULL value"); + + if(json_array_append_new(array, json_integer(321))) + fail("unable to append new value"); + value = json_array_get(array, json_array_size(array) - 1); if(!json_is_integer(value) || json_integer_value(value) != 321) fail("json_array_append_new works incorrectly"); + if(!json_array_append_new(array, NULL)) + fail("able to append_new NULL value"); + json_decref(five); json_decref(seven); json_decref(array); diff --git a/test/testprogs/test_object.c b/test/testprogs/test_object.c index f9839c7..540109e 100644 --- a/test/testprogs/test_object.c +++ b/test/testprogs/test_object.c @@ -29,6 +29,12 @@ int main() if(json_object_set(object, "a", string)) fail("unable to set value"); + if(!json_object_set(object, NULL, string)) + fail("able to set NULL key"); + + if(!json_object_set(object, "a", NULL)) + fail("able to set NULL value"); + iter = json_object_iter(object); if(!iter) fail("unable to get iterator"); @@ -105,11 +111,19 @@ int main() fail("unable to set value"); - json_object_set_new(object, "foo", json_integer(123)); + if(json_object_set_new(object, "foo", json_integer(123))) + fail("unable to set new value"); + value = json_object_get(object, "foo"); if(!json_is_integer(value) || json_integer_value(value) != 123) fail("json_object_set_new works incorrectly"); + if(!json_object_set_new(object, NULL, json_integer(432))) + fail("able to set_new NULL key"); + + if(!json_object_set_new(object, "foo", NULL)) + fail("able to set_new NULL value"); + json_decref(string); json_decref(other_string); json_decref(object); diff --git a/test/testprogs/test_simple.c b/test/testprogs/test_simple.c index 86f841b..4491ed2 100644 --- a/test/testprogs/test_simple.c +++ b/test/testprogs/test_simple.c @@ -58,6 +58,10 @@ int main() fail("invalid string value"); json_decref(value); + value = json_string(NULL); + if(value) + fail("json_string(NULL) failed"); + value = json_integer(123); if(!value) fail("json_integer failed"); |