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/array-test.c | |
| 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/array-test.c')
| -rw-r--r-- | json-glib/tests/array-test.c | 50 |
1 files changed, 50 insertions, 0 deletions
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 (); +} |
