diff options
author | Philip Withnall <philip.withnall@collabora.co.uk> | 2015-09-24 11:06:34 +0100 |
---|---|---|
committer | Philip Withnall <philip.withnall@collabora.co.uk> | 2015-10-06 08:31:25 +0100 |
commit | d231976e240f2244c60df26a1a6600ecb325506a (patch) | |
tree | c0b3b15dfc4d0bdec97277fd27b2857654a21d36 /json-glib/tests | |
parent | 5185a8f8a58e5b455116eaa8c99c4b4c38a45929 (diff) | |
download | json-glib-d231976e240f2244c60df26a1a6600ecb325506a.tar.gz |
object: Add JsonObjectIter to ease iteration over JsonObject members
This is a stack-allocated iterator object similar to GHashTableIter
which allows allocation-free iteration over the members in a JsonObject.
It differs from json_object_foreach_member() in the order in which it
iterates — for JsonObjectIter the order is undefined.
https://bugzilla.gnome.org/show_bug.cgi?id=755509
Diffstat (limited to 'json-glib/tests')
-rw-r--r-- | json-glib/tests/object.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/json-glib/tests/object.c b/json-glib/tests/object.c index f109464..54b5934 100644 --- a/json-glib/tests/object.c +++ b/json-glib/tests/object.c @@ -140,6 +140,33 @@ test_foreach_member (void) } static void +test_iter (void) +{ + JsonObject *object = NULL; + TestForeachFixture fixture = { 0, }; + JsonObjectIter iter; + const gchar *member_name; + JsonNode *member_node; + + object = json_object_new (); + + json_object_set_int_member (object, "integer", 42); + json_object_set_boolean_member (object, "boolean", TRUE); + json_object_set_string_member (object, "string", "hello"); + json_object_set_double_member (object, "double", 3.14159); + json_object_set_null_member (object, "null"); + + json_object_iter_init (&iter, object); + + while (json_object_iter_next (&iter, &member_name, &member_node)) + verify_foreach (object, member_name, member_node, &fixture); + + g_assert_cmpint (fixture.n_members, ==, json_object_get_size (object)); + + json_object_unref (object); +} + +static void test_empty_member (void) { JsonObject *object = json_object_new (); @@ -173,6 +200,7 @@ main (int argc, g_test_add_func ("/object/set-member", test_set_member); g_test_add_func ("/object/remove-member", test_remove_member); g_test_add_func ("/object/foreach-member", test_foreach_member); + g_test_add_func ("/object/iter", test_iter); g_test_add_func ("/object/empty-member", test_empty_member); return g_test_run (); |