diff options
author | Emmanuele Bassi <ebassi@openedhand.com> | 2008-03-02 17:44:27 +0000 |
---|---|---|
committer | Emmanuele Bassi <ebassi@openedhand.com> | 2008-03-02 17:44:27 +0000 |
commit | 7e6dab14302b94979672acf81eec8710ea95e288 (patch) | |
tree | 8a58612c416db2bbb3f1b4c17fc5ff7dd7bd471a /json-glib/tests | |
parent | 441ee88a6e024fc5ab2cf8355adad1fecc276088 (diff) | |
download | json-glib-7e6dab14302b94979672acf81eec8710ea95e288.tar.gz |
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.
Diffstat (limited to 'json-glib/tests')
-rw-r--r-- | json-glib/tests/Makefile.am | 10 | ||||
-rw-r--r-- | json-glib/tests/array-test.c | 50 |
2 files changed, 57 insertions, 3 deletions
diff --git a/json-glib/tests/Makefile.am b/json-glib/tests/Makefile.am index 03e4b6a..2f0fe99 100644 --- a/json-glib/tests/Makefile.am +++ b/json-glib/tests/Makefile.am @@ -10,6 +10,10 @@ INCLUDES = \ noinst_PROGRAMS = $(TEST_PROGS) progs_ldadd = $(top_builddir)/json-glib/libjson-glib-1.0.la -TEST_PROGS += node-test -node_test_SOURCES = node-test.c -node_test_LDADD = $(progs_ldadd) +TEST_PROGS += array-test +array_test_SOURCES = array-test.c +array_test_LDADD = $(progs_ldadd) + +TEST_PROGS += node-test +node_test_SOURCES = node-test.c +node_test_LDADD = $(progs_ldadd) 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 <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <glib.h> +#include <json-glib/json-types.h> + +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 (); +} |