[json-glib] generator: Add tests for updated string escaping routine
- From: Stefan Walter <stefw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [json-glib] generator: Add tests for updated string escaping routine
- Date: Wed, 21 May 2014 13:58:00 +0000 (UTC)
commit 8bbc873dccb0426ce7e2ad0974b1397506454674
Author: Stef Walter <stefw redhat com>
Date: Wed May 21 12:14:57 2014 +0200
generator: Add tests for updated string escaping routine
https://bugzilla.gnome.org/show_bug.cgi?id=730425
json-glib/tests/generator.c | 47 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 47 insertions(+), 0 deletions(-)
---
diff --git a/json-glib/tests/generator.c b/json-glib/tests/generator.c
index a96153c..f156fde 100644
--- a/json-glib/tests/generator.c
+++ b/json-glib/tests/generator.c
@@ -375,10 +375,48 @@ test_pretty (void)
g_object_unref (parser);
}
+typedef struct {
+ const gchar *str;
+ const gchar *expect;
+} FixtureString;
+
+static const FixtureString string_fixtures[] = {
+ { "abc", "\"abc\"" },
+ { "a\x7fxc", "\"a\\u007fxc\"" },
+ { "a\033xc", "\"a\\u001bxc\"" },
+ { "a\nxc", "\"a\\nxc\"" },
+ { "a\\xc", "\"a\\\\xc\"" },
+ { "Barney B\303\244r", "\"Barney B\303\244r\"" },
+};
+
+static void
+test_string_encode (gconstpointer data)
+{
+ const FixtureString *fixture = data;
+ JsonGenerator *generator = json_generator_new ();
+ JsonNode *node;
+ gsize length;
+ gchar *output;
+
+ node = json_node_init_string (json_node_alloc (), fixture->str);\
+ json_generator_set_root (generator, node);
+
+ output = json_generator_to_data (generator, &length);
+ g_assert_cmpstr (output, ==, fixture->expect);
+ g_assert_cmpuint (length, ==, strlen (fixture->expect));
+ g_free (output);
+ json_node_free (node);
+
+ g_object_unref (generator);
+}
int
main (int argc,
char *argv[])
{
+ gchar *escaped;
+ gchar *name;
+ gint i;
+
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/generator/empty-array", test_empty_array);
@@ -390,5 +428,14 @@ main (int argc,
g_test_add_func ("/generator/decimal-separator", test_decimal_separator);
g_test_add_func ("/generator/pretty", test_pretty);
+ for (i = 0; i < G_N_ELEMENTS (string_fixtures); i++)
+ {
+ escaped = g_strescape (string_fixtures[i].str, NULL);
+ name = g_strdup_printf ("/generator/string/%s", escaped);
+ g_test_add_data_func (name, string_fixtures + i, test_string_encode);
+ g_free (escaped);
+ g_free (name);
+ }
+
return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]