[json-glib/json-glib-0-8] tests: Verify parsing bare values



commit 09170edebbbcb2952c39e9e11eb0bbf5cbd9b29f
Author: Mathias Hasselmann <mathias hasselmann gmx de>
Date:   Thu Oct 29 14:17:29 2009 +0000

    tests: Verify parsing bare values
    
    http://bugzilla.openedhand.com/show_bug.cgi?id=1856
    
    Signed-off-by: Emmanuele Bassi <ebassi linux intel com>
    
    (cherry picked from commit a25a1ded25e5d1f605cffd6da7a5e036151aa70c)

 tests/test-parser.c |   38 +++++++++++++++++++++++++++++++++-----
 1 files changed, 33 insertions(+), 5 deletions(-)
---
diff --git a/tests/test-parser.c b/tests/test-parser.c
index 04269f0..d722f67 100644
--- a/tests/test-parser.c
+++ b/tests/test-parser.c
@@ -13,16 +13,41 @@ static const gchar *test_empty_string = "";
 static const gchar *test_empty_array_string = "[ ]";
 static const gchar *test_empty_object_string = "{ }";
 
+static void
+verify_int_value (JsonNode *node)
+{
+  g_assert_cmpint (42, ==, json_node_get_int (node));
+}
+
+static void
+verify_boolean_value (JsonNode *node)
+{
+  g_assert_cmpint (TRUE, ==, json_node_get_boolean (node));
+}
+
+static void
+verify_string_value (JsonNode *node)
+{
+  g_assert_cmpstr ("string", ==, json_node_get_string (node));
+}
+
+static void
+verify_double_value (JsonNode *node)
+{
+  g_assert_cmpfloat (10.2e3, ==, json_node_get_double (node));
+}
+
 static const struct {
   const gchar *str;
   JsonNodeType type;
   GType gtype;
+  void (* verify_value) (JsonNode *node);
 } test_base_values[] = {
-  { "null",       JSON_NODE_NULL, G_TYPE_INVALID },
-  { "42",         JSON_NODE_VALUE, G_TYPE_INT64 },
-  { "true",       JSON_NODE_VALUE, G_TYPE_BOOLEAN },
-  { "\"string\"", JSON_NODE_VALUE, G_TYPE_STRING },
-  { "10.2e3",     JSON_NODE_VALUE, G_TYPE_DOUBLE }
+  { "null",       JSON_NODE_NULL,  G_TYPE_INVALID, NULL, },
+  { "42",         JSON_NODE_VALUE, G_TYPE_INT64,   verify_int_value },
+  { "true",       JSON_NODE_VALUE, G_TYPE_BOOLEAN, verify_boolean_value },
+  { "\"string\"", JSON_NODE_VALUE, G_TYPE_STRING,  verify_string_value },
+  { "10.2e3",     JSON_NODE_VALUE, G_TYPE_DOUBLE,  verify_double_value }
 };
 
 static const struct {
@@ -163,6 +188,9 @@ test_base_value (void)
                                                                  : 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);
+
+          if (test_base_values[i].verify_value)
+            test_base_values[i].verify_value (root);
        }
     }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]