[libgdata/wip/pwithnall/walbottle] tests: WIP work to add Walbottle support for unit testing



commit 253a26f460b1c303648cf3a7398c50ad278b24a9
Author: Philip Withnall <philip withnall collabora co uk>
Date:   Thu May 14 13:43:52 2015 +0100

    tests: WIP work to add Walbottle support for unit testing

 gdata/tests/tasks.c           |   33 +++++++++++++++++++
 gdata/tests/tasks.schema.json |   72 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 105 insertions(+), 0 deletions(-)
---
diff --git a/gdata/tests/tasks.c b/gdata/tests/tasks.c
index 4f0f895..cc2f8cc 100644
--- a/gdata/tests/tasks.c
+++ b/gdata/tests/tasks.c
@@ -25,6 +25,8 @@
 #include "common.h"
 #include "gdata-dummy-authorizer.h"
 
+#include "tasks.schema.json.h"
+
 static UhmServer *mock_server = NULL;  /* owned */
 
 #undef CLIENT_ID  /* from common.h */
@@ -422,6 +424,35 @@ test_task_parser_minimal (void)
        g_object_unref (task);
 }
 
+/* Test the task parser with generated JSON. */
+static void
+test_task_parser_generated (void)
+{
+       guint i;
+
+       for (i = 0; i < G_N_ELEMENTS (json_instances); i++) {
+               GDataTasksTask *task = NULL;  /* owned */
+               GError *error = NULL;
+
+               task = GDATA_TASKS_TASK (gdata_parsable_new_from_json (GDATA_TYPE_TASKS_TASK,
+                                                                      json_instances[i].json, -1,
+                                                                      &error));
+
+               if (json_instances[i].is_valid) {
+                       g_assert_no_error (error);
+                       g_assert (GDATA_IS_TASKS_TASK (task));
+                       gdata_test_compare_kind (GDATA_ENTRY (task), "tasks#task", NULL);
+
+                       g_clear_object (&task);
+               } else {
+                       g_assert (error != NULL);  /* TODO */
+                       g_assert (task == NULL);
+
+                       g_clear_error (&error);
+               }
+       }
+}
+
 /* Test the task parser with a maximal number of properties specified. */
 static void
 test_task_parser_normal (void)
@@ -1412,6 +1443,8 @@ main (int argc, char *argv[])
        g_test_add_func ("/tasks/task/escaping", test_task_escaping);
        g_test_add_func ("/tasks/task/parser/minimal",
                         test_task_parser_minimal);
+       g_test_add_func ("/tasks/task/parser/generated",
+                        test_task_parser_generated);
        g_test_add_func ("/tasks/task/parser/normal", test_task_parser_normal);
 
        g_test_add_func ("/tasks/tasklist/properties",
diff --git a/gdata/tests/tasks.schema.json b/gdata/tests/tasks.schema.json
new file mode 100644
index 0000000..9039ac7
--- /dev/null
+++ b/gdata/tests/tasks.schema.json
@@ -0,0 +1,72 @@
+{
+       "$schema": "http://json-schema.org/draft-04/schema#";,
+       "title": "Task",
+       "type": "object",
+       "properties": {
+               "title": {
+                       "type": "string"
+               },
+               "id": {
+                       "type": "string",
+                       "minLength": 1
+               },
+               "updated": {
+                       "type": "string",
+                       "minLength": 1,
+                       "format": "date-time"
+               },
+               "etag": {
+                       "type": "string",
+                       "minLength": 1
+               },
+               "selfLink": {
+                       "type": "string",
+                       "minLength": 1,
+                       "format": "uri"
+               },
+               "kind": {
+                       "type": "string",
+                       "minLength": 1,
+                       "enum": [
+                               "tasks#task"
+                       ]
+               },
+               "parent": {
+                       "type": "string"
+               },
+               "position": {
+                       "type": "string",
+                       "pattern": "[0-9]+"
+               },
+               "notes": {
+                       "type": "string"
+               },
+               "status": {
+                       "type": "string",
+                       "enum": [
+                               "needsAction"
+                       ]
+               },
+               "due": {
+                       "type": "string",
+                       "minLength": 1,
+                       "format": "date-time"
+               },
+               "completed": {
+                       "type": "string",
+                       "minLength": 1,
+                       "format": "date-time"
+               },
+               "deleted": {
+                       "type": "boolean"
+               },
+               "hidden": {
+                       "type": "boolean"
+               }
+       },
+       "required": [
+               "id",
+               "kind",
+               "updated"
+       ]
+}


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