From 4c4f692bd6814e598c9aa538a3c9979cdf05d566 Mon Sep 17 00:00:00 2001 From: Petri Lehtinen Date: Wed, 26 Aug 2015 17:32:55 +0300 Subject: Add json_object_foreach_safe Fixes #230. --- test/suites/api/test_object.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test') 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(); } -- cgit v1.1