diff options
| author | Emmanuele Bassi <ebassi@openedhand.com> | 2007-09-21 20:14:49 +0100 |
|---|---|---|
| committer | Emmanuele Bassi <ebassi@openedhand.com> | 2007-09-21 20:14:49 +0100 |
| commit | 7875c5f573fdc6c2a39e958d2032f4c26d1f91ff (patch) | |
| tree | fcdf634c36a232d6f0de2dd923253721966edc7c | |
| parent | 81ad2e5c61db2391d2d98a6b5df1247e3abf16ec (diff) | |
| download | json-glib-7875c5f573fdc6c2a39e958d2032f4c26d1f91ff.tar.gz | |
Start the test suite
Add the first two test units:
- test-01.c: build/empty test unit
- test-02.c: array test unit
Every test unit must follow the same naming policy, so we can add
a run-tests script later on and a pre-commit hook to invoke it
and catch regressions automagically.
| -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; +} |
