diff options
| -rw-r--r-- | tests/Makefile.am | 12 | ||||
| -rw-r--r-- | tests/test-01.c | 31 | ||||
| -rw-r--r-- | tests/test-02.c | 52 |
3 files changed, 95 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index e69de29..0ad7195 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -0,0 +1,12 @@ +noinst_PROGRAMS = \ + test-01 \ + test-02 + +INCLUDES = -I$(top_srcdir) +LDADD = $(top_builddir)/json-glib/libjson-glib-1.0.la + +AM_CFLAGS = $(JSON_CFLAGS) +AM_LDFLAGS = $(JSON_LIBS) + +test_01_SOURCES = test-01.c +test_02_SOURCES = test-02.c diff --git a/tests/test-01.c b/tests/test-01.c new file mode 100644 index 0000000..c530aa9 --- /dev/null +++ b/tests/test-01.c @@ -0,0 +1,31 @@ +#include <stdlib.h> +#include <stdio.h> + +#include <json-glib/json-glib.h> + +static const gchar *test_empty = ""; + +int +main (int argc, char *argv[]) +{ + JsonParser *parser; + GError *error = NULL; + + g_type_init (); + + parser = json_parser_new (); + if (!json_parser_load_from_data (parser, test_empty, -1, &error)) + { + g_print ("Error: %s\n", error->message); + g_error_free (error); + g_object_unref (parser); + + return EXIT_FAILURE; + } + + g_assert (NULL == json_parser_get_toplevels (parser)); + + g_object_unref (parser); + + return EXIT_SUCCESS; +} diff --git a/tests/test-02.c b/tests/test-02.c new file mode 100644 index 0000000..cd09cbe --- /dev/null +++ b/tests/test-02.c @@ -0,0 +1,52 @@ +#include <stdlib.h> +#include <stdio.h> + +#include <json-glib/json-glib.h> + +static const gchar *test_arrays[] = { + "[ ]", + "[ true ]", + "[ true, false, null ]", + "[ 1, 2, 3.14, \"test\" ]", + "[ 42, [ ], null ]", + "[ [ ], [ true, [ true ] ] ]", + "[ [ false, true, 42 ], [ true, false, 3.14 ], \"test\" ]" +}; + +static guint n_test_arrays = G_N_ELEMENTS (test_arrays); + +int +main (int argc, char *argv[]) +{ + JsonParser *parser; + gint i; + GList *l; + + g_type_init (); + + parser = json_parser_new (); + + for (i = 0; i < n_test_arrays; i++) + { + GError *error = NULL; + + if (!json_parser_load_from_data (parser, test_arrays[i], -1, &error)) + { + g_print ("* Error, test %d:\n" + "* \t%s:\n" + "* Message: %s\n", + i, test_arrays[i], error->message); + g_error_free (error); + g_object_unref (parser); + return EXIT_FAILURE; + } + } + + l = json_parser_get_toplevels (parser); + g_assert (l != NULL); + g_assert (g_list_length (l) == n_test_arrays); + + g_object_unref (parser); + + return EXIT_SUCCESS; +} |
