[json-glib] tests/invalid: Improve test coverage



commit b9e93111a1200492b71476f7b3a1c60588a90a15
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Fri Oct 26 10:10:53 2012 +0100

    tests/invalid: Improve test coverage

 json-glib/tests/invalid.c |   32 ++++++++++++++++++++++++++++++++
 1 files changed, 32 insertions(+), 0 deletions(-)
---
diff --git a/json-glib/tests/invalid.c b/json-glib/tests/invalid.c
index a1f056c..6d9a6a8 100644
--- a/json-glib/tests/invalid.c
+++ b/json-glib/tests/invalid.c
@@ -64,6 +64,33 @@ test_invalid_assignment (gconstpointer user_data)
 }
 
 static void
+test_invalid_value (gconstpointer user_data)
+{
+  const char *json = user_data;
+  GError *error = NULL;
+  JsonParser *parser;
+  gboolean res;
+
+  parser = json_parser_new ();
+  g_assert (JSON_IS_PARSER (parser));
+
+  if (g_test_verbose ())
+    g_print ("invalid data: '%s'...", json);
+
+  res = json_parser_load_from_data (parser, json, -1, &error);
+
+  g_assert (!res);
+  g_assert (error != NULL);
+
+  if (g_test_verbose ())
+    g_print ("expected error: %s\n", error->message);
+
+  g_clear_error (&error);
+
+  g_object_unref (parser);
+}
+
+static void
 test_invalid_array (gconstpointer user_data)
 {
   const char *json = user_data;
@@ -157,6 +184,9 @@ static const struct
   { "bareword-4", "[ 3, 2, 1, lift_off ]", test_invalid_bareword },
   { "bareword-5", "{ foo : 42 }", test_invalid_bareword },
 
+  /* values */
+  { "values-1", "[ -false ]", test_invalid_value },
+
   /* assignment */
   { "assignment-1", "var foo", test_invalid_assignment },
   { "assignment-2", "var foo = no", test_invalid_assignment },
@@ -175,6 +205,8 @@ static const struct
   { "object-3", "{ \"foo\", 42 }", test_invalid_object },
   { "object-4", "{ \"foo\" : 42 ]", test_invalid_object },
   { "object-5", "{ \"blah\" }", test_invalid_object },
+  { "object-6", "{ \"a\" : 0 \"b\" : 1 }", test_invalid_object },
+  { "object-7", "{ \"\" : false }", test_invalid_object },
 
   /* trailing commas */
   { "trailing-comma-1", "[ true, ]", test_trailing_comma },



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