[json-glib] [tests] Verify parsing base values
- From: Emmanuele Bassi <ebassi src gnome org>
- To: svn-commits-list gnome org
- Subject: [json-glib] [tests] Verify parsing base values
- Date: Sun, 28 Jun 2009 22:56:54 +0000 (UTC)
commit 4ecdd6bedb7961f3a33971aa1f2338115a60f7f3
Author: Emmanuele Bassi <ebassi gnome org>
Date: Sun Jun 28 23:48:36 2009 +0100
[tests] Verify parsing base values
A JSON document containing just a base value (null, true/false, an
integer, a floating point value or a string) is still a valid JSON
document, and JsonParser must create the correct JsonNode.
tests/test-parser.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 59 insertions(+), 0 deletions(-)
---
diff --git a/tests/test-parser.c b/tests/test-parser.c
index bf55972..1dc02ed 100644
--- a/tests/test-parser.c
+++ b/tests/test-parser.c
@@ -15,6 +15,17 @@ static const gchar *test_empty_object_string = "{ }";
static const struct {
const gchar *str;
+ JsonNodeType type;
+ GType gtype;
+} test_base_values[] = {
+ { "null", JSON_NODE_NULL, G_TYPE_INVALID },
+ { "42", JSON_NODE_VALUE, G_TYPE_INT },
+ { "true", JSON_NODE_VALUE, G_TYPE_BOOLEAN },
+ { "\"string\"", JSON_NODE_VALUE, G_TYPE_STRING }
+};
+
+static const struct {
+ const gchar *str;
gint len;
gint element;
JsonNodeType type;
@@ -70,6 +81,7 @@ static const struct
{ "{ \"test\" : \"foo \\u00e8\" }", "test", "foo è" }
};
+static guint n_test_base_values = G_N_ELEMENTS (test_base_values);
static guint n_test_simple_arrays = G_N_ELEMENTS (test_simple_arrays);
static guint n_test_nested_arrays = G_N_ELEMENTS (test_nested_arrays);
static guint n_test_simple_objects = G_N_ELEMENTS (test_simple_objects);
@@ -109,6 +121,52 @@ test_empty (void)
}
static void
+test_base_value (void)
+{
+ gint i;
+ JsonParser *parser;
+
+ parser = json_parser_new ();
+ g_assert (JSON_IS_PARSER (parser));
+
+ if (g_test_verbose ())
+ g_print ("checking json_parser_load_from_data with base-values...\n");
+
+ for (i = 0; i < n_test_base_values; i++)
+ {
+ GError *error = NULL;
+
+ if (!json_parser_load_from_data (parser, test_base_values[i].str, -1, &error))
+ {
+ if (g_test_verbose ())
+ g_print ("Error: %s\n", error->message);
+
+ g_error_free (error);
+ g_object_unref (parser);
+ exit (1);
+ }
+ else
+ {
+ JsonNode *root;
+
+ g_assert (NULL != json_parser_get_root (parser));
+
+ root = json_parser_get_root (parser);
+ g_assert (root != NULL);
+
+ if (g_test_verbose ())
+ g_print ("checking root node is of the desired type %s...\n",
+ test_base_values[i].gtype == G_TYPE_INVALID ? "<null>"
+ : g_type_name (test_base_values[i].gtype));
+ g_assert_cmpint (JSON_NODE_TYPE (root), ==, test_base_values[i].type);
+ g_assert_cmpint (json_node_get_value_type (root), ==, test_base_values[i].gtype);
+ }
+ }
+
+ g_object_unref (parser);
+}
+
+static void
test_empty_array (void)
{
JsonParser *parser;
@@ -520,6 +578,7 @@ main (int argc,
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/parser/empty-string", test_empty);
+ g_test_add_func ("/parser/base-value", test_base_value);
g_test_add_func ("/parser/empty-array", test_empty_array);
g_test_add_func ("/parser/simple-array", test_simple_array);
g_test_add_func ("/parser/nested-array", test_nested_array);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]