aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPetri Lehtinen <petri@digip.org>2014-12-19 08:35:31 +0200
committerPetri Lehtinen <petri@digip.org>2014-12-19 08:35:46 +0200
commit890760b2fb780c05446b3ad14f25e536312c21f9 (patch)
treebfe4e8e1fb1b7e30510cf9a63180946c45b6795a /test
parent15653c47dd9a7d5714d1332704214446b71a5352 (diff)
downloadjansson-890760b2fb780c05446b3ad14f25e536312c21f9.zip
jansson-890760b2fb780c05446b3ad14f25e536312c21f9.tar.gz
jansson-890760b2fb780c05446b3ad14f25e536312c21f9.tar.bz2
Increase test coverage
Diffstat (limited to 'test')
-rw-r--r--test/suites/api/test_dump.c19
-rw-r--r--test/suites/api/test_load.c15
-rw-r--r--test/suites/api/test_object.c33
3 files changed, 67 insertions, 0 deletions
diff --git a/test/suites/api/test_dump.c b/test/suites/api/test_dump.c
index 8731752..ac4a883 100644
--- a/test/suites/api/test_dump.c
+++ b/test/suites/api/test_dump.c
@@ -194,6 +194,24 @@ static void encode_nul_byte()
json_decref(json);
}
+static void dump_file()
+{
+ json_t *json;
+ int result;
+
+ result = json_dump_file(NULL, "", 0);
+ if (result != -1)
+ fail("json_dump_file succeeded with invalid args");
+
+ json = json_object();
+ result = json_dump_file(json, "json_dump_file.json", 0);
+ if (result != 0)
+ fail("json_dump_file failed");
+
+ json_decref(json);
+ remove("json_dump_file.json");
+}
+
static void run_tests()
{
encode_null();
@@ -202,4 +220,5 @@ static void run_tests()
encode_other_than_array_or_object();
escape_slashes();
encode_nul_byte();
+ dump_file();
}
diff --git a/test/suites/api/test_load.c b/test/suites/api/test_load.c
index 80d159f..8d1e9f4 100644
--- a/test/suites/api/test_load.c
+++ b/test/suites/api/test_load.c
@@ -34,6 +34,20 @@ static void file_not_found()
fail("json_load_file returned an invalid error message");
}
+static void very_long_file_name() {
+ json_t *json;
+ json_error_t error;
+
+ json = json_load_file("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 0, &error);
+ if(json)
+ fail("json_load_file returned non-NULL for a nonexistent file");
+ if(error.line != -1)
+ fail("json_load_file returned an invalid line number");
+
+ if (strncmp(error.source, "...aaa", 6) != 0)
+ fail("error source was set incorrectly");
+}
+
static void reject_duplicates()
{
json_error_t error;
@@ -191,6 +205,7 @@ static void position()
static void run_tests()
{
file_not_found();
+ very_long_file_name();
reject_duplicates();
disable_eof_check();
decode_any();
diff --git a/test/suites/api/test_object.c b/test/suites/api/test_object.c
index 5b30738..aff83f9 100644
--- a/test/suites/api/test_object.c
+++ b/test/suites/api/test_object.c
@@ -139,6 +139,32 @@ static void test_update()
json_decref(object);
}
+static void test_set_many_keys()
+{
+ json_t *object, *value;
+ const char *keys = "abcdefghijklmnopqrstuvwxyz";
+ char buf[2];
+ size_t i;
+
+ object = json_object();
+ if (!object)
+ fail("unable to create object");
+
+ value = json_string("a");
+ if (!value)
+ fail("unable to create string");
+
+ buf[1] = '\0';
+ for (i = 0; i < strlen(keys); i++) {
+ buf[0] = keys[i];
+ if (json_object_set(object, buf, value))
+ fail("unable to set object key");
+ }
+
+ json_decref(object);
+ json_decref(value);
+}
+
static void test_conditional_updates()
{
json_t *object, *other;
@@ -374,6 +400,12 @@ static void test_misc()
if(!json_object_set(object, NULL, string))
fail("able to set NULL key");
+ if(json_object_del(object, "a"))
+ fail("unable to del the only key");
+
+ if(json_object_set(object, "a", string))
+ fail("unable to set value");
+
if(!json_object_set(object, "a", NULL))
fail("able to set NULL value");
@@ -518,6 +550,7 @@ static void run_tests()
test_misc();
test_clear();
test_update();
+ test_set_many_keys();
test_conditional_updates();
test_circular();
test_set_nocheck();