aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPetri Lehtinen <petri@digip.org>2014-02-11 14:49:15 +0200
committerPetri Lehtinen <petri@digip.org>2014-02-11 14:49:15 +0200
commit17ec22f514ceb9277bea1e38cc8ea69eec1edd53 (patch)
tree55b75defa871dc7178a0f2c6cead32b2bd69b8f5 /test
parenta721d36f4143faa94c78e447515994891ce9c30f (diff)
parente83ded066a610f8de7caaa3942769321ededa84f (diff)
downloadjansson-17ec22f514ceb9277bea1e38cc8ea69eec1edd53.zip
jansson-17ec22f514ceb9277bea1e38cc8ea69eec1edd53.tar.gz
jansson-17ec22f514ceb9277bea1e38cc8ea69eec1edd53.tar.bz2
Merge branch '2.6'
Diffstat (limited to 'test')
-rw-r--r--test/bin/json_process.c16
-rw-r--r--test/suites/api/test_memory_funcs.c6
-rw-r--r--test/suites/api/test_object.c64
-rw-r--r--test/suites/encoding-flags/compact-object/env3
-rw-r--r--test/suites/encoding-flags/indent-compact-object/env3
-rw-r--r--test/suites/encoding-flags/indent-object/env3
-rw-r--r--test/suites/encoding-flags/object/env2
7 files changed, 66 insertions, 31 deletions
diff --git a/test/bin/json_process.c b/test/bin/json_process.c
index 0799aa8..724648c 100644
--- a/test/bin/json_process.c
+++ b/test/bin/json_process.c
@@ -37,6 +37,8 @@ struct config {
int sort_keys;
int strip;
int use_env;
+ int have_hashseed;
+ int hashseed;
} conf;
#define l_isspace(c) ((c) == ' ' || (c) == '\n' || (c) == '\r' || (c) == '\t')
@@ -108,6 +110,12 @@ static void read_conf(FILE *conffile)
conf.sort_keys = atoi(val);
if (!strcmp(line, "STRIP"))
conf.strip = atoi(val);
+ if (!strcmp(line, "HASHSEED")) {
+ conf.have_hashseed = 1;
+ conf.hashseed = atoi(val);
+ } else {
+ conf.have_hashseed = 0;
+ }
}
free(buffer);
@@ -188,6 +196,9 @@ int use_conf(char *test_path)
if (conf.sort_keys)
flags |= JSON_SORT_KEYS;
+ if (conf.have_hashseed)
+ json_object_seed(conf.hashseed);
+
if (conf.strip) {
/* Load to memory, strip leading and trailing whitespace */
buffer = loadfile(infile);
@@ -265,7 +276,10 @@ int use_env()
flags |= JSON_PRESERVE_ORDER;
if(getenv_int("JSON_SORT_KEYS"))
- flags |= JSON_SORT_KEYS;
+ flags |= JSON_SORT_KEYS;
+
+ if(getenv("HASHSEED"))
+ json_object_seed(getenv_int("HASHSEED"));
if(getenv_int("STRIP")) {
/* Load to memory, strip leading and trailing whitespace */
diff --git a/test/suites/api/test_memory_funcs.c b/test/suites/api/test_memory_funcs.c
index 8737389..84b1746 100644
--- a/test/suites/api/test_memory_funcs.c
+++ b/test/suites/api/test_memory_funcs.c
@@ -24,13 +24,13 @@ static void create_and_free_complex_object()
static void *my_malloc(size_t size)
{
- malloc_called += 1;
+ malloc_called = 1;
return malloc(size);
}
static void my_free(void *ptr)
{
- free_called += 1;
+ free_called = 1;
free(ptr);
}
@@ -39,7 +39,7 @@ static void test_simple()
json_set_alloc_funcs(my_malloc, my_free);
create_and_free_complex_object();
- if(malloc_called != 20 || free_called != 20)
+ if(malloc_called != 1 || free_called != 1)
fail("Custom allocation failed");
}
diff --git a/test/suites/api/test_object.c b/test/suites/api/test_object.c
index 6273b7c..5b30738 100644
--- a/test/suites/api/test_object.c
+++ b/test/suites/api/test_object.c
@@ -249,7 +249,11 @@ static void test_set_nocheck()
static void test_iterators()
{
+ int i;
json_t *object, *foo, *bar, *baz;
+ const char *iter_keys[3];
+ int have_key[3] = { 0, 0, 0 };
+ json_t *iter_values[3];
void *iter;
if(json_object_iter(NULL))
@@ -276,30 +280,50 @@ static void test_iterators()
iter = json_object_iter(object);
if(!iter)
fail("unable to get iterator");
- if(strcmp(json_object_iter_key(iter), "a"))
- fail("iterating failed: wrong key");
- if(json_object_iter_value(iter) != foo)
- fail("iterating failed: wrong value");
+ iter_keys[0] = json_object_iter_key(iter);
+ iter_values[0] = json_object_iter_value(iter);
iter = json_object_iter_next(object, iter);
if(!iter)
fail("unable to increment iterator");
- if(strcmp(json_object_iter_key(iter), "b"))
- fail("iterating failed: wrong key");
- if(json_object_iter_value(iter) != bar)
- fail("iterating failed: wrong value");
+ iter_keys[1] = json_object_iter_key(iter);
+ iter_values[1] = json_object_iter_value(iter);
iter = json_object_iter_next(object, iter);
if(!iter)
fail("unable to increment iterator");
- if(strcmp(json_object_iter_key(iter), "c"))
- fail("iterating failed: wrong key");
- if(json_object_iter_value(iter) != baz)
- fail("iterating failed: wrong value");
+ iter_keys[2] = json_object_iter_key(iter);
+ iter_values[2] = json_object_iter_value(iter);
if(json_object_iter_next(object, iter) != NULL)
fail("able to iterate over the end");
+ /* Check that keys have correct values */
+ for (i = 0; i < 3; i++) {
+ if (strcmp(iter_keys[i], "a") == 0) {
+ if (iter_values[i] != foo)
+ fail("wrong value for iter key a");
+ else
+ have_key[0] = 1;
+ } else if (strcmp(iter_keys[i], "b") == 0) {
+ if (iter_values[i] != bar)
+ fail("wrong value for iter key b");
+ else
+ have_key[1] = 1;
+ } else if (strcmp(iter_keys[i], "c") == 0) {
+ if (iter_values[i] != baz)
+ fail("wrong value for iter key c");
+ else
+ have_key[2] = 1;
+ }
+ }
+
+ /* Check that we got all keys */
+ for(i = 0; i < 3; i++) {
+ if(!have_key[i])
+ fail("a key wasn't iterated over");
+ }
+
if(json_object_iter_at(object, "foo"))
fail("json_object_iter_at() succeeds for non-existent key");
@@ -312,22 +336,14 @@ static void test_iterators()
if(json_object_iter_value(iter) != bar)
fail("iterating failed: wrong value");
- iter = json_object_iter_next(object, iter);
- if(!iter)
- fail("unable to increment iterator");
- if(strcmp(json_object_iter_key(iter), "c"))
- fail("iterating failed: wrong key");
- if(json_object_iter_value(iter) != baz)
- fail("iterating failed: wrong value");
-
- if(json_object_iter_set(object, iter, bar))
+ if(json_object_iter_set(object, iter, baz))
fail("unable to set value at iterator");
- if(strcmp(json_object_iter_key(iter), "c"))
+ if(strcmp(json_object_iter_key(iter), "b"))
fail("json_object_iter_key() fails after json_object_iter_set()");
- if(json_object_iter_value(iter) != bar)
+ if(json_object_iter_value(iter) != baz)
fail("json_object_iter_value() fails after json_object_iter_set()");
- if(json_object_get(object, "c") != bar)
+ if(json_object_get(object, "b") != baz)
fail("json_object_get() fails after json_object_iter_set()");
json_decref(object);
diff --git a/test/suites/encoding-flags/compact-object/env b/test/suites/encoding-flags/compact-object/env
index 4474aaf..93cb33d 100644
--- a/test/suites/encoding-flags/compact-object/env
+++ b/test/suites/encoding-flags/compact-object/env
@@ -1,2 +1,3 @@
JSON_COMPACT=1
-export JSON_COMPACT
+HASHSEED=1
+export JSON_COMPACT HASHSEED
diff --git a/test/suites/encoding-flags/indent-compact-object/env b/test/suites/encoding-flags/indent-compact-object/env
index 78fbfcc..c73acc1 100644
--- a/test/suites/encoding-flags/indent-compact-object/env
+++ b/test/suites/encoding-flags/indent-compact-object/env
@@ -1,3 +1,4 @@
JSON_INDENT=4
JSON_COMPACT=1
-export JSON_INDENT JSON_COMPACT
+HASHSEED=1
+export JSON_INDENT JSON_COMPACT HASHSEED
diff --git a/test/suites/encoding-flags/indent-object/env b/test/suites/encoding-flags/indent-object/env
index d220f83..961558c 100644
--- a/test/suites/encoding-flags/indent-object/env
+++ b/test/suites/encoding-flags/indent-object/env
@@ -1,2 +1,3 @@
JSON_INDENT=4
-export JSON_INDENT
+HASHSEED=1
+export JSON_INDENT HASHSEED
diff --git a/test/suites/encoding-flags/object/env b/test/suites/encoding-flags/object/env
new file mode 100644
index 0000000..9120b03
--- /dev/null
+++ b/test/suites/encoding-flags/object/env
@@ -0,0 +1,2 @@
+HASHSEED=1
+export HASHSEED