From 7e6dab14302b94979672acf81eec8710ea95e288 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Sun, 2 Mar 2008 17:44:27 +0000 Subject: Add array-test to the JSON-GLib types unit tests This simple unit will test the JsonArray API, as part of the coverage test for the JSON-GLib types. --- json-glib/tests/array-test.c | 50 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 json-glib/tests/array-test.c (limited to 'json-glib/tests/array-test.c') diff --git a/json-glib/tests/array-test.c b/json-glib/tests/array-test.c new file mode 100644 index 0000000..1d06780 --- /dev/null +++ b/json-glib/tests/array-test.c @@ -0,0 +1,50 @@ +#include +#include +#include + +#include +#include + +static void +test_empty_array (void) +{ + JsonArray *array = json_array_new (); + + g_assert_cmpint (json_array_get_length (array), ==, 0); + g_assert (json_array_get_elements (array) == NULL); + + json_array_unref (array); +} + +static void +test_add_element (void) +{ + JsonArray *array = json_array_new (); + JsonNode *node = json_node_new (JSON_NODE_NULL); + + g_assert_cmpint (json_array_get_length (array), ==, 0); + + json_array_add_element (array, node); + g_assert_cmpint (json_array_get_length (array), ==, 1); + + node = json_array_get_element (array, 0); + g_assert_cmpint (JSON_NODE_TYPE (node), ==, JSON_NODE_NULL); + + json_array_remove_element (array, 0); + g_assert_cmpint (json_array_get_length (array), ==, 0); + + json_array_unref (array); +} + +int +main (int argc, + char *argv[]) +{ + g_type_init (); + g_test_init (&argc, &argv, NULL); + + g_test_add_func ("/array/empty-array", test_empty_array); + g_test_add_func ("/array/add-element", test_add_element); + + return g_test_run (); +} -- cgit v1.2.1 From 7eab612d9b200aef197fa1dffa4f89b936c76b1f Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Wed, 5 Mar 2008 15:46:41 +0000 Subject: Add element removal unit to the Array test Remove the json_array_remove_element() call from the add-element test unit and set up a separate test case for the element removal. This keeps the test cases clean. --- json-glib/tests/array-test.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'json-glib/tests/array-test.c') diff --git a/json-glib/tests/array-test.c b/json-glib/tests/array-test.c index 1d06780..f091ecd 100644 --- a/json-glib/tests/array-test.c +++ b/json-glib/tests/array-test.c @@ -30,6 +30,17 @@ test_add_element (void) node = json_array_get_element (array, 0); g_assert_cmpint (JSON_NODE_TYPE (node), ==, JSON_NODE_NULL); + json_array_unref (array); +} + +static void +test_remove_element (void) +{ + JsonArray *array = json_array_new (); + JsonNode *node = json_node_new (JSON_NODE_NULL); + + json_array_add_element (array, node); + json_array_remove_element (array, 0); g_assert_cmpint (json_array_get_length (array), ==, 0); @@ -45,6 +56,7 @@ main (int argc, g_test_add_func ("/array/empty-array", test_empty_array); g_test_add_func ("/array/add-element", test_add_element); + g_test_add_func ("/array/remove-element", test_remove_element); return g_test_run (); } -- cgit v1.2.1