aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPetri Lehtinen <petri@digip.org>2015-08-26 17:32:55 +0300
committerPetri Lehtinen <petri@digip.org>2015-08-26 17:32:55 +0300
commit4c4f692bd6814e598c9aa538a3c9979cdf05d566 (patch)
tree23ce6dcfa5e465d32c9af5c7edf73855320a419e /test
parentfef27e6d3efa755a75888db1167f34fa80695b9e (diff)
downloadjansson-4c4f692bd6814e598c9aa538a3c9979cdf05d566.zip
jansson-4c4f692bd6814e598c9aa538a3c9979cdf05d566.tar.gz
jansson-4c4f692bd6814e598c9aa538a3c9979cdf05d566.tar.bz2
Add json_object_foreach_safe
Fixes #230.
Diffstat (limited to 'test')
-rw-r--r--test/suites/api/test_object.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/suites/api/test_object.c b/test/suites/api/test_object.c
index c7acb40..01cc8fd 100644
--- a/test/suites/api/test_object.c
+++ b/test/suites/api/test_object.c
@@ -545,6 +545,24 @@ static void test_object_foreach()
json_decref(object2);
}
+static void test_object_foreach_safe()
+{
+ const char *key;
+ void *tmp;
+ json_t *object, *value;
+
+ object = json_pack("{sisisi}", "foo", 1, "bar", 2, "baz", 3);
+
+ json_object_foreach_safe(object, tmp, key, value) {
+ json_object_del(object, key);
+ }
+
+ if(json_object_size(object) != 0)
+ fail("json_object_foreach_safe failed to iterate all key-value pairs");
+
+ json_decref(object);
+}
+
static void run_tests()
{
test_misc();
@@ -557,4 +575,5 @@ static void run_tests()
test_iterators();
test_preserve_order();
test_object_foreach();
+ test_object_foreach_safe();
}