summaryrefslogtreecommitdiff
path: root/json-glib/tests
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@linux.intel.com>2010-01-01 18:23:16 +0000
committerEmmanuele Bassi <ebassi@linux.intel.com>2010-01-01 18:23:16 +0000
commit3c33b61738d74b732805b497accec830b1a05796 (patch)
tree2987695d16778993ddabe511a27ea2494a9f3f5d /json-glib/tests
parentc8cc10985c3e7aac5ca1c03a7b443951929ed0cb (diff)
downloadjson-glib-3c33b61738d74b732805b497accec830b1a05796.tar.gz
tests: Verify Array.get_elements()
While verifying Array.foreach() we should also verify that the list we are iterating on is the same returned by the get_elements() method.
Diffstat (limited to 'json-glib/tests')
-rw-r--r--json-glib/tests/array-test.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/json-glib/tests/array-test.c b/json-glib/tests/array-test.c
index 7c29cdf..ce8242b 100644
--- a/json-glib/tests/array-test.c
+++ b/json-glib/tests/array-test.c
@@ -49,17 +49,19 @@ test_remove_element (void)
typedef struct _TestForeachFixture
{
+ GList *elements;
gint n_elements;
+ gint iterations;
} TestForeachFixture;
static const struct {
JsonNodeType element_type;
GType element_gtype;
} type_verify[] = {
- { JSON_NODE_VALUE, G_TYPE_INT64 },
+ { JSON_NODE_VALUE, G_TYPE_INT64 },
{ JSON_NODE_VALUE, G_TYPE_BOOLEAN },
- { JSON_NODE_VALUE, G_TYPE_STRING },
- { JSON_NODE_NULL, G_TYPE_INVALID }
+ { JSON_NODE_VALUE, G_TYPE_STRING },
+ { JSON_NODE_NULL, G_TYPE_INVALID }
};
static void
@@ -70,10 +72,11 @@ verify_foreach (JsonArray *array,
{
TestForeachFixture *fixture = user_data;
+ g_assert (g_list_find (fixture->elements, element_node));
g_assert (json_node_get_node_type (element_node) == type_verify[index_].element_type);
g_assert (json_node_get_value_type (element_node) == type_verify[index_].element_gtype);
- fixture->n_elements += 1;
+ fixture->iterations += 1;
}
static void
@@ -87,10 +90,19 @@ test_foreach_element (void)
json_array_add_string_element (array, "hello");
json_array_add_null_element (array);
+ fixture.elements = json_array_get_elements (array);
+ g_assert (fixture.elements != NULL);
+
+ fixture.n_elements = json_array_get_length (array);
+ g_assert_cmpint (fixture.n_elements, ==, g_list_length (fixture.elements));
+
+ fixture.iterations = 0;
+
json_array_foreach_element (array, verify_foreach, &fixture);
- g_assert_cmpint (fixture.n_elements, ==, json_array_get_length (array));
+ g_assert_cmpint (fixture.iterations, ==, fixture.n_elements);
+ g_list_free (fixture.elements);
json_array_unref (array);
}