summaryrefslogtreecommitdiff
path: root/gdata/tests/general.c
diff options
context:
space:
mode:
authorPhilip Withnall <philip@tecnocode.co.uk>2013-08-29 23:04:55 -0600
committerPhilip Withnall <philip@tecnocode.co.uk>2013-08-29 23:04:55 -0600
commitadfc260f9bb69adfce623882276b8578279baf63 (patch)
tree7ef7500de33f243d6a4e6dd192f22f57f235a216 /gdata/tests/general.c
parente18bec0f183b660cb7c4066dcc9e6577a819a895 (diff)
downloadlibgdata-adfc260f9bb69adfce623882276b8578279baf63.tar.gz
core: Finish JSON supporttasks-integration
This adds test cases which cover all of the new code, and fixes a number of small bugs. extra_json support is now complete.
Diffstat (limited to 'gdata/tests/general.c')
-rw-r--r--gdata/tests/general.c95
1 files changed, 90 insertions, 5 deletions
diff --git a/gdata/tests/general.c b/gdata/tests/general.c
index f8f2c787..88831e86 100644
--- a/gdata/tests/general.c
+++ b/gdata/tests/general.c
@@ -553,11 +553,23 @@ test_entry_parse_json (void)
"\"etag\":\"some-etag\","
"\"id\":\"some-id\","
"\"kind\":\"kind#kind\","
- "\"unhandled-member\":false"
+ "\"unhandled-boolean\":false,"
+ "\"unhandled-string\":\"this-is-a-string---sometimes\","
+ "\"unhandled-int\":15,"
+ "\"unhandled-double\":42.42,"
+ "\"unhandled-object\":{"
+ "\"a\":true,"
+ "\"b\":true"
+ "},"
+ "\"unhandled-array\":["
+ "1,"
+ "2,"
+ "3"
+ "],"
+ "\"unhandled-null\":null"
"}", -1, &error));
g_assert_no_error (error);
g_assert (GDATA_IS_ENTRY (entry));
- g_clear_error (&error);
/* Now check the outputted JSON from the entry still has the unhandled nodes. */
gdata_test_assert_json (entry,
@@ -568,13 +580,35 @@ test_entry_parse_json (void)
"\"etag\":\"some-etag\","
"\"selfLink\":\"http://example.com/\","
"\"kind\":\"kind#kind\","
- "\"unhandled-member\":false"
+ "\"unhandled-boolean\":false,"
+ "\"unhandled-string\":\"this-is-a-string---sometimes\","
+ "\"unhandled-int\":15,"
+ "\"unhandled-double\":42.42,"
+ "\"unhandled-object\":{"
+ "\"a\":true,"
+ "\"b\":true"
+ "},"
+ "\"unhandled-array\":["
+ "1,"
+ "2,"
+ "3"
+ "],"
+ "\"unhandled-null\":null"
"}");
g_object_unref (entry);
+
+ /* Test parsing of empty titles. */
+ entry = GDATA_ENTRY (gdata_parsable_new_from_json (GDATA_TYPE_ENTRY,
+ "{"
+ "\"title\":\"\""
+ "}", -1, &error));
+ g_assert_no_error (error);
+ g_assert (GDATA_IS_ENTRY (entry));
+ g_object_unref (entry);
}
static void
-test_entry_error_handling (void)
+test_entry_error_handling_xml (void)
{
GDataEntry *entry;
GError *error = NULL;
@@ -606,6 +640,56 @@ test_entry_error_handling (void)
}
static void
+test_entry_error_handling_json (void)
+{
+ GDataEntry *entry;
+ GError *error = NULL;
+
+#define TEST_JSON_ERROR_HANDLING(x) \
+ entry = GDATA_ENTRY (gdata_parsable_new_from_json (GDATA_TYPE_ENTRY,x, -1, &error));\
+ g_assert_error (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_PROTOCOL_ERROR);\
+ g_assert (entry == NULL);\
+ g_clear_error (&error)
+#define TEST_JSON_ERROR_HANDLING_PARSER(x) \
+ entry = GDATA_ENTRY (gdata_parsable_new_from_json (GDATA_TYPE_ENTRY,x, -1, &error));\
+ g_assert_error (error, GDATA_PARSER_ERROR, GDATA_PARSER_ERROR_PARSING_STRING);\
+ g_assert (entry == NULL);\
+ g_clear_error (&error)
+
+ /* General structure. */
+ TEST_JSON_ERROR_HANDLING_PARSER ("[true,false,true]"); /* root node is not an object */
+ TEST_JSON_ERROR_HANDLING_PARSER ("false"); /* root node is not an object */
+ TEST_JSON_ERROR_HANDLING_PARSER ("invalid json"); /* totally invalid JSON */
+
+ /* id */
+ TEST_JSON_ERROR_HANDLING ("{\"id\":\"\"}"); /* empty */
+ TEST_JSON_ERROR_HANDLING ("{\"id\":null}"); /* invalid type */
+
+ /* updated */
+ TEST_JSON_ERROR_HANDLING ("{\"updated\":\"not correct\"}"); /* incorrect format */
+ TEST_JSON_ERROR_HANDLING ("{\"updated\":false}"); /* invalid type */
+ TEST_JSON_ERROR_HANDLING ("{\"updated\":\"\"}"); /* empty */
+
+ /* title */
+ TEST_JSON_ERROR_HANDLING ("{\"title\":false}"); /* invalid type */
+
+ /* etag */
+ TEST_JSON_ERROR_HANDLING ("{\"etag\":\"\"}"); /* empty */
+ TEST_JSON_ERROR_HANDLING ("{\"etag\":false}"); /* invalid type */
+
+ /* selfLink */
+ TEST_JSON_ERROR_HANDLING ("{\"selfLink\":\"\"}"); /* empty */
+ TEST_JSON_ERROR_HANDLING ("{\"selfLink\":false}"); /* invalid type */
+
+ /* kind */
+ TEST_JSON_ERROR_HANDLING ("{\"kind\":\"\"}"); /* empty */
+ TEST_JSON_ERROR_HANDLING ("{\"kind\":false}"); /* invalid type */
+
+#undef TEST_JSON_ERROR_HANDLING_PARSER
+#undef TEST_JSON_ERROR_HANDLING
+}
+
+static void
test_entry_escaping (void)
{
GDataEntry *entry;
@@ -4082,7 +4166,8 @@ main (int argc, char *argv[])
g_test_add_func ("/entry/get_json", test_entry_get_json);
g_test_add_func ("/entry/parse_xml", test_entry_parse_xml);
g_test_add_func ("/entry/parse_json", test_entry_parse_json);
- g_test_add_func ("/entry/error_handling", test_entry_error_handling);
+ g_test_add_func ("/entry/error_handling/xml", test_entry_error_handling_xml);
+ g_test_add_func ("/entry/error_handling/json", test_entry_error_handling_json);
g_test_add_func ("/entry/escaping", test_entry_escaping);
g_test_add_func ("/entry/links/remove", test_entry_links_remove);