[libgdata/wip/calendar-v3: 3/3] calendar: WIP more v3 work



commit a424a30ca0a567f49e2e47209e78ac4b3cc9c787
Author: Philip Withnall <philip tecnocode co uk>
Date:   Sun Feb 1 23:26:13 2015 +0000

    calendar: WIP more v3 work

 gdata/gdata-entry.c                              |    2 +
 gdata/gdata-service.c                            |    1 +
 gdata/services/calendar/gdata-calendar-event.c   |  181 +++++++---
 gdata/services/calendar/gdata-calendar-service.c |   49 +++-
 gdata/tests/calendar.c                           |  412 ++++++++++++----------
 5 files changed, 393 insertions(+), 252 deletions(-)
---
diff --git a/gdata/gdata-entry.c b/gdata/gdata-entry.c
index c4430ea..262bb08 100644
--- a/gdata/gdata-entry.c
+++ b/gdata/gdata-entry.c
@@ -881,7 +881,9 @@ gdata_entry_add_category (GDataEntry *self, GDataCategory *category)
 
        /* Check to see if it's a kind category and if it matches the entry's predetermined kind */
        if (g_strcmp0 (gdata_category_get_scheme (category), "http://schemas.google.com/g/2005#kind";) == 0) {
+#if 0
                GDataEntryClass *klass = GDATA_ENTRY_GET_CLASS (self);
+#endif
                GList *element;
 
 #if 0
diff --git a/gdata/gdata-service.c b/gdata/gdata-service.c
index 300824b..f3898c0 100644
--- a/gdata/gdata-service.c
+++ b/gdata/gdata-service.c
@@ -1850,6 +1850,7 @@ gdata_service_delete_entry (GDataService *self, GDataAuthorizationDomain *domain
        } else {
                _link = gdata_entry_look_up_link (entry, GDATA_LINK_EDIT);
        }
+       g_message ("%p: looking up link %s", entry, klass->get_content_type ());
        g_assert (_link != NULL);
 
        fixed_uri = _gdata_service_fix_uri_scheme (gdata_link_get_uri (_link));
diff --git a/gdata/services/calendar/gdata-calendar-event.c b/gdata/services/calendar/gdata-calendar-event.c
index 902414b..16008e4 100644
--- a/gdata/services/calendar/gdata-calendar-event.c
+++ b/gdata/services/calendar/gdata-calendar-event.c
@@ -119,6 +119,16 @@ struct _GDataCalendarEventPrivate {
        gchar *recurrence;
        gchar *original_event_id;
        gchar *original_event_uri;
+
+       /* Parsing state. */
+       struct {
+               gint64 start_time;
+               gint64 end_time;
+               gboolean seen_start;
+               gboolean seen_end;
+               gboolean start_is_date;
+               gboolean end_is_date;
+       } parser;
 };
 
 enum {
@@ -616,17 +626,13 @@ static gboolean
 parse_json (GDataParsable *parsable, JsonReader *reader, gpointer user_data, GError **error)
 {
        gboolean success;
-       gchar *summary = NULL;
-       gint64 start_time = -1, end_time = -1;
-       gboolean seen_start = FALSE, seen_end = FALSE, added_when = FALSE;
-       gboolean start_is_date = FALSE, end_is_date = FALSE;
+       gchar *summary = NULL, *description = NULL;
        GDataCalendarEvent *self = GDATA_CALENDAR_EVENT (parsable);
 
 g_message ("parsing %s", json_reader_get_member_name (reader));
        /* TODO:
   "htmlLink": string,
   "created": datetime,
-  "description": string,
   "location": string,
   "colorId": string,
   "creator": {
@@ -710,9 +716,9 @@ TODO: set original_event_uri iff original_event_id is set
         */
 
        if (g_strcmp0 (json_reader_get_member_name (reader), "start") == 0) {
-               seen_start = TRUE;
+               self->priv->parser.seen_start = TRUE;
        } else if (g_strcmp0 (json_reader_get_member_name (reader), "end") == 0) {
-               seen_end = TRUE;
+               self->priv->parser.seen_end = TRUE;
        }
 
        if (gdata_parser_string_from_json_member (reader, "recurringEventId", P_DEFAULT, 
&self->priv->original_event_id, &success, error) ||
@@ -727,28 +733,46 @@ TODO: set original_event_uri iff original_event_id is set
            gdata_parser_string_from_json_member (reader, "transparency", P_DEFAULT, 
&self->priv->transparency, &success, error) ||
            gdata_parser_string_from_json_member (reader, "visibility", P_DEFAULT, &self->priv->visibility, 
&success, error) ||
            gdata_parser_string_from_json_member (reader, "summary", P_DEFAULT, &summary, &success, error) ||
-           date_object_from_json (reader, "start", P_DEFAULT, &start_time, &start_is_date, &success, error) 
||
-           date_object_from_json (reader, "end", P_DEFAULT, &end_time, &end_is_date, &success, error)) {
+           gdata_parser_string_from_json_member (reader, "description", P_DEFAULT, &description, &success, 
error) ||
+           date_object_from_json (reader, "start", P_DEFAULT, &self->priv->parser.start_time, 
&self->priv->parser.start_is_date, &success, error) ||
+           date_object_from_json (reader, "end", P_DEFAULT, &self->priv->parser.end_time, 
&self->priv->parser.end_is_date, &success, error) ||
+           gdata_parser_string_from_json_member (reader, "recurringEventId", P_DEFAULT, 
&self->priv->original_event_id, &success, error)) {
                if (success) {
                        if (summary != NULL) {
                                gdata_entry_set_title (GDATA_ENTRY (parsable), summary);
                        }
 
+                       if (description != NULL) {
+                               gdata_entry_set_content (GDATA_ENTRY (parsable), description);
+                       }
+
                        if (self->priv->edited != -1) {
                                _gdata_entry_set_updated (GDATA_ENTRY (parsable),
                                                          self->priv->edited);
                        }
 
-                       if (seen_start && seen_end && !added_when) {
+                       if (self->priv->original_event_id != NULL) {
+                               g_free (self->priv->original_event_uri);
+                               self->priv->original_event_uri = g_strconcat 
("https://www.googleapis.com/calendar/v3/events/";,
+                                                                             self->priv->original_event_id, 
NULL);
+                       }
+
+                       if (self->priv->parser.seen_start && self->priv->parser.seen_end) {
                                GDataGDWhen *when;
 
-                               when = gdata_gd_when_new (start_time, end_time, start_is_date || end_is_date);
+                               when = gdata_gd_when_new (self->priv->parser.start_time,
+                                                         self->priv->parser.end_time,
+                                                         self->priv->parser.start_is_date ||
+                                                         self->priv->parser.end_is_date);
                                self->priv->times = g_list_prepend (self->priv->times, when);  /* transfer 
ownership */
-                               added_when = TRUE;
+
+                               self->priv->parser.seen_start = FALSE;
+                               self->priv->parser.seen_end = FALSE;
                        }
                }
 
                g_free (summary);
+               g_free (description);
 
                return success;
        } else if (g_strcmp0 (json_reader_get_member_name (reader), "recurrence") == 0) {
@@ -791,26 +815,9 @@ TODO: set original_event_uri iff original_event_id is set
                self->priv->recurrence = g_string_free (recurrence, FALSE);
 
                return TRUE;
-       } else if (g_strcmp0 (json_reader_get_member_name (reader), "id") == 0) {
-               GDataLink *_link;
-               const gchar *id;
-               gchar *uri;
-
-               /* Calendar entries don’t contain their own selfLink, so we have
-                * to add one manually. */
-               id = json_reader_get_string_value (reader);
-               if (id != NULL && *id != '\0') {
-                       uri = g_strconcat ("https://www.googleapis.com/calendar/v3/calendars/";, id, NULL);
-                       _link = gdata_link_new (uri, GDATA_LINK_SELF);
-                       gdata_entry_add_link (GDATA_ENTRY (parsable), _link);
-                       g_object_unref (_link);
-                       g_free (uri);
-               }
-
-               g_free (summary);
-               return GDATA_PARSABLE_CLASS (gdata_calendar_event_parent_class)->parse_json (parsable, 
reader, user_data, error);
        } else {
                g_free (summary);
+               g_free (description);
                return GDATA_PARSABLE_CLASS (gdata_calendar_event_parent_class)->parse_json (parsable, 
reader, user_data, error);
        }
 
@@ -821,14 +828,13 @@ static void
 get_json (GDataParsable *parsable, JsonBuilder *builder)
 {
        GList *l;
-       const gchar *id, *etag, *title;
+       const gchar *id, *etag, *title, *description;
+       GDataGDWho *organiser_who = NULL;  /* unowned */
        GDataCalendarEventPrivate *priv = GDATA_CALENDAR_EVENT (parsable)->priv;
 
 /* TODO:
   "htmlLink": string,
   "created": datetime,
-  "description": string,
-  "location": string,
   "colorId": string,
   "creator": {
     "id": string,
@@ -836,31 +842,11 @@ get_json (GDataParsable *parsable, JsonBuilder *builder)
     "displayName": string,
     "self": boolean
   },
-  "organizer": {
-    "id": string,
-    "email": string,
-    "displayName": string,
-    "self": boolean
-  },
   "originalStartTime": {
     "date": date,
     "dateTime": datetime,
     "timeZone": string
   },
-  "attendees": [
-    {
-      "id": string,
-      "email": string,
-      "displayName": string,
-      "organizer": boolean,
-      "self": boolean,
-      "resource": boolean,
-      "optional": boolean,
-      "responseStatus": string,
-      "comment": string,
-      "additionalGuests": integer
-    }
-  ],
   "attendeesOmitted": boolean,
   "extendedProperties": {
     "private": {
@@ -898,10 +884,6 @@ get_json (GDataParsable *parsable, JsonBuilder *builder)
     "url": string,
     "title": string
   }
-
-
-       GList *people;
-       GList *places;
 */
 
 
@@ -929,6 +911,12 @@ get_json (GDataParsable *parsable, JsonBuilder *builder)
                json_builder_add_string_value (builder, title);
        }
 
+       description = gdata_entry_get_content (GDATA_ENTRY (parsable));
+       if (description != NULL) {
+               json_builder_set_member_name (builder, "description");
+               json_builder_add_string_value (builder, description);
+       }
+
        /* Add all the calendar-specific JSON */
        json_builder_set_member_name (builder, "anyoneCanAddSelf");
        json_builder_add_boolean_value (builder, priv->anyone_can_add_self);
@@ -1054,8 +1042,87 @@ get_json (GDataParsable *parsable, JsonBuilder *builder)
                if (l->next != NULL) {
                        g_warning ("Ignoring secondary times; they are no "
                                   "longer supported by the server-side API.");
+                       break;
                }
        }
+
+       /* Locations. */
+       for (l = priv->places; l != NULL; l = l->next) {
+               GDataGDWhere *where;  /* unowned */
+               const gchar *location;
+
+               where = l->data;
+               location = gdata_gd_where_get_value_string (where);
+
+               json_builder_set_member_name (builder, "location");
+               json_builder_add_string_value (builder, location);
+
+               /* Only use the first location. :-(
+                * FIXME: There must be a better solution. */
+               if (l->next != NULL) {
+                       g_warning ("Ignoring secondary locations; they are no "
+                                  "longer supported by the server-side API.");
+                       break;
+               }
+       }
+
+       /* People. */
+       json_builder_set_member_name (builder, "attendees");
+       json_builder_begin_array (builder);
+
+       for (l = priv->people; l != NULL; l = l->next) {
+               GDataGDWho *who;  /* unowned */
+               const gchar *display_name, *email_address;
+
+               who = l->data;
+
+               json_builder_begin_object (builder);
+
+               display_name = gdata_gd_who_get_value_string (who);
+               if (display_name != NULL) {
+                       json_builder_set_member_name (builder, "displayName");
+                       json_builder_add_string_value (builder, display_name);
+               }
+
+               email_address = gdata_gd_who_get_email_address (who);
+               if (email_address != NULL) {
+                       json_builder_set_member_name (builder, "email");
+                       json_builder_add_string_value (builder, email_address);
+               }
+
+               if (g_strcmp0 (gdata_gd_who_get_relation_type (who),
+                              GDATA_GD_WHO_EVENT_ORGANIZER) == 0) {
+                       json_builder_set_member_name (builder, "organizer");
+                       json_builder_add_boolean_value (builder, TRUE);
+
+                       organiser_who = who;
+               }
+
+               json_builder_end_object (builder);
+       }
+
+       json_builder_end_array (builder);
+
+       if (organiser_who != NULL) {
+               const gchar *display_name, *email_address;
+
+               json_builder_set_member_name (builder, "organizer");
+               json_builder_begin_object (builder);
+
+               display_name = gdata_gd_who_get_value_string (organiser_who);
+               if (display_name != NULL) {
+                       json_builder_set_member_name (builder, "displayName");
+                       json_builder_add_string_value (builder, display_name);
+               }
+
+               email_address = gdata_gd_who_get_email_address (organiser_who);
+               if (email_address != NULL) {
+                       json_builder_set_member_name (builder, "email");
+                       json_builder_add_string_value (builder, email_address);
+               }
+
+               json_builder_end_object (builder);
+       }
 }
 
 static const gchar *
diff --git a/gdata/services/calendar/gdata-calendar-service.c 
b/gdata/services/calendar/gdata-calendar-service.c
index 4f5b0fc..11f270e 100644
--- a/gdata/services/calendar/gdata-calendar-service.c
+++ b/gdata/services/calendar/gdata-calendar-service.c
@@ -382,8 +382,10 @@ parse_error_response (GDataService *self,
                                              * server. */
                                             _("The requested resource was not found: %s"),
                                             message);
-                       } else if (g_strcmp0 (domain, "global") == 0 &&
-                                  g_strcmp0 (reason, "required") == 0) {
+                       } else if ((g_strcmp0 (domain, "global") == 0 &&
+                                   g_strcmp0 (reason, "required") == 0) ||
+                                  (g_strcmp0 (domain, "global") == 0 &&
+                                   g_strcmp0 (reason, "conditionNotMet") == 0)) {
                                /* Client-side protocol error. */
                                g_set_error (error, GDATA_SERVICE_ERROR,
                                             GDATA_SERVICE_ERROR_PROTOCOL_ERROR,
@@ -707,6 +709,40 @@ build_events_uri (GDataCalendarCalendar *calendar)
        return g_string_free (uri, FALSE);
 }
 
+static void
+set_event_id (GDataCalendarEvent *event,
+              GDataCalendarCalendar *calendar)
+{
+       GDataLink *_link = NULL;  /* owned */
+       const gchar *id, *calendar_id;
+       gchar *uri = NULL;  /* owned */
+
+       id = gdata_entry_get_id (GDATA_ENTRY (event));
+       calendar_id = gdata_entry_get_id (GDATA_ENTRY (calendar));
+
+       uri = g_strconcat ("https://www.googleapis.com/calendar/v3/calendars/";,
+                          calendar_id, "/events/", id, NULL);
+       _link = gdata_link_new (uri, GDATA_LINK_SELF);
+       gdata_entry_add_link (GDATA_ENTRY (event), _link);
+       g_object_unref (_link);
+       g_free (uri);
+}
+
+static void
+set_event_ids (GDataFeed *feed,
+               GDataCalendarCalendar *calendar)
+{
+       GList/*<unowned GDataEntry>*/ *entries, *i;  /* unowned */
+
+       /* Add a selfLink to each event, since they don’t contain one by
+        * default in the data returned by the server. */
+       entries = gdata_feed_get_entries (feed);
+
+       for (i = entries; i != NULL; i = i->next) {
+               set_event_id (GDATA_CALENDAR_EVENT (i->data), calendar);
+       }
+}
+
 /**
  * gdata_calendar_service_query_events:
  * @self: a #GDataCalendarService
@@ -754,6 +790,9 @@ gdata_calendar_service_query_events (GDataCalendarService *self, GDataCalendarCa
                                    error);
        g_free (request_uri);
 
+       /* Set the events’ IDs. */
+       set_event_ids (feed, calendar);
+
        return feed;
 }
 
@@ -815,6 +854,8 @@ gdata_calendar_service_query_events_async (GDataCalendarService *self, GDataCale
                                   progress_callback, progress_user_data,
                                   destroy_progress_user_data, callback,
                                   user_data);
+/* TODO:       Set the events’ IDs.
+       set_event_ids (feed, calendar); */
        g_free (request_uri);
 }
 
@@ -894,6 +935,8 @@ gdata_calendar_service_insert_calendar_event (GDataCalendarService *self,
                                            cancellable, error);
        g_free (uri);
 
+       set_event_id (GDATA_CALENDAR_EVENT (entry), calendar);
+
        return GDATA_CALENDAR_EVENT (entry);
 }
 
@@ -975,5 +1018,5 @@ gdata_calendar_service_insert_calendar_event_async (GDataCalendarService *self,
                                          get_calendar_authorization_domain (),
                                          uri, GDATA_ENTRY (event), cancellable,
                                          callback, user_data);
-       g_free (uri);
+       g_free (uri);/* TODO: self link */
 }
diff --git a/gdata/tests/calendar.c b/gdata/tests/calendar.c
index f808dce..4994d01 100644
--- a/gdata/tests/calendar.c
+++ b/gdata/tests/calendar.c
@@ -583,7 +583,7 @@ G_STMT_START {
 } G_STMT_END);
 
 static void
-test_event_xml (void)
+test_event_json (void)
 {
        GDataCalendarEvent *event;
        GDataGDWhere *where;
@@ -609,174 +609,203 @@ test_event_xml (void)
        gdata_calendar_event_add_time (event, when);
        g_object_unref (when);
 
-       /* Check the XML */
-       gdata_test_assert_xml (event,
-               "<?xml version='1.0' encoding='UTF-8'?>"
-               "<entry xmlns='http://www.w3.org/2005/Atom' "
-                      "xmlns:gd='http://schemas.google.com/g/2005' "
-                      "xmlns:gCal='http://schemas.google.com/gCal/2005' "
-                      "xmlns:app='http://www.w3.org/2007/app'>"
-                       "<title type='text'>Tennis with Beth</title>"
-                       "<content type='text'>Meet for a quick lesson.</content>"
-                       "<category term='http://schemas.google.com/g/2005#event' 
scheme='http://schemas.google.com/g/2005#kind'/>"
-                       "<gd:eventStatus value='http://schemas.google.com/g/2005#event.confirmed'/>"
-                       "<gd:transparency value='http://schemas.google.com/g/2005#event.opaque'/>"
-                       "<gCal:guestsCanModify value='false'/>"
-                       "<gCal:guestsCanInviteOthers value='false'/>"
-                       "<gCal:guestsCanSeeGuests value='false'/>"
-                       "<gCal:anyoneCanAddSelf value='false'/>"
-                       "<gd:when startTime='2009-04-17T15:00:00Z' endTime='2009-04-17T17:00:00Z'/>"
-                       "<gd:who email='john smith example com' "
-                               "rel='http://schemas.google.com/g/2005#event.organizer' "
-                               "valueString='John Smith\342\200\275'/>"
-                       "<gd:where valueString='Rolling Lawn Courts'/>"
-               "</entry>");
+       /* Check the JSON */
+       gdata_test_assert_json (event, "{"
+               "'summary': 'Tennis with Beth',"
+               "'description': 'Meet for a quick lesson.',"
+               "'kind': 'calendar#event',"
+               "'status': 'http://schemas.google.com/g/2005#event.confirmed',"
+               "'transparency': 'http://schemas.google.com/g/2005#event.opaque',"
+               "'guestsCanModify': false,"
+               "'guestsCanInviteOthers': false,"
+               "'guestsCanSeeOtherGuests': false,"
+               "'anyoneCanAddSelf': false,"
+               "'start': {"
+                       "'dateTime': '2009-04-17T15:00:00Z',"
+                       "'timeZone': 'UTC'"
+               "},"
+               "'end': {"
+                       "'dateTime': '2009-04-17T17:00:00Z',"
+                       "'timeZone': 'UTC'"
+               "},"
+               "'attendees': ["
+                       "{"
+                               "'email': 'john smith example com',"
+                               "'displayName': 'John Smith‽',"
+                               "'organizer': true"
+                       "}"
+               "],"
+               "'organizer': {"
+                       "'email': 'john smith example com',"
+                       "'displayName': 'John Smith‽'"
+               "},"
+               "'location': 'Rolling Lawn Courts'"
+       "}");
 }
 
 static void
-test_event_xml_dates (void)
+test_event_json_dates (void)
 {
-       GDataCalendarEvent *event;
-       GList *i;
-       GDataGDWhen *when;
-       gint64 _time;
-       GError *error = NULL;
-
-       event = GDATA_CALENDAR_EVENT (gdata_parsable_new_from_xml (GDATA_TYPE_CALENDAR_EVENT,
-               "<entry xmlns='http://www.w3.org/2005/Atom' "
-                      "xmlns:gd='http://schemas.google.com/g/2005' "
-                      "xmlns:gCal='http://schemas.google.com/gCal/2005' "
-                      "xmlns:app='http://www.w3.org/2007/app'>"
-                       "<title type='text'>Tennis with Beth</title>"
-                       "<content type='text'>Meet for a quick lesson.</content>"
-                       "<category term='http://schemas.google.com/g/2005#event' 
scheme='http://schemas.google.com/g/2005#kind'/>"
-                       "<gd:when startTime='2009-04-17'/>"
-                       "<gd:when startTime='2009-04-17T15:00:00Z'/>"
-                       "<gd:when startTime='2009-04-27' endTime='20090506'/>"
-               "</entry>", -1, &error));
-       g_assert_no_error (error);
-       g_assert (GDATA_IS_ENTRY (event));
-       g_clear_error (&error);
-
-       /* Check the times */
-       i = gdata_calendar_event_get_times (event);
-
-       /* First time */
-       when = GDATA_GD_WHEN (i->data);
-       g_assert (i->next != NULL);
-       g_assert (gdata_gd_when_is_date (when) == TRUE);
-       _time = gdata_gd_when_get_start_time (when);
-       g_assert_cmpint (_time, ==, 1239926400);
-       _time = gdata_gd_when_get_end_time (when);
-       g_assert_cmpint (_time, ==, -1);
-       g_assert (gdata_gd_when_get_value_string (when) == NULL);
-       g_assert (gdata_gd_when_get_reminders (when) == NULL);
-
-       /* Second time */
-       i = i->next;
-       when = GDATA_GD_WHEN (i->data);
-       g_assert (i->next != NULL);
-       g_assert (gdata_gd_when_is_date (when) == FALSE);
-       _time = gdata_gd_when_get_start_time (when);
-       g_assert_cmpint (_time, ==, 1239926400 + 54000);
-       _time = gdata_gd_when_get_end_time (when);
-       g_assert_cmpint (_time, ==, -1);
-       g_assert (gdata_gd_when_get_value_string (when) == NULL);
-       g_assert (gdata_gd_when_get_reminders (when) == NULL);
-
-       /* Third time */
-       i = i->next;
-       when = GDATA_GD_WHEN (i->data);
-       g_assert (i->next == NULL);
-       g_assert (gdata_gd_when_is_date (when) == TRUE);
-       _time = gdata_gd_when_get_start_time (when);
-       g_assert_cmpint (_time, ==, 1239926400 + 864000);
-       _time = gdata_gd_when_get_end_time (when);
-       g_assert_cmpint (_time, ==, 1241568000);
-       g_assert (gdata_gd_when_get_value_string (when) == NULL);
-       g_assert (gdata_gd_when_get_reminders (when) == NULL);
-
-       /* Check the XML */
-       gdata_test_assert_xml (event,
-               "<?xml version='1.0' encoding='UTF-8'?>"
-               "<entry xmlns='http://www.w3.org/2005/Atom' "
-                      "xmlns:gd='http://schemas.google.com/g/2005' "
-                      "xmlns:gCal='http://schemas.google.com/gCal/2005' "
-                      "xmlns:app='http://www.w3.org/2007/app'>"
-                       "<title type='text'>Tennis with Beth</title>"
-                       "<content type='text'>Meet for a quick lesson.</content>"
-                       "<category term='http://schemas.google.com/g/2005#event' 
scheme='http://schemas.google.com/g/2005#kind'/>"
-                       "<gCal:guestsCanModify value='false'/>"
-                       "<gCal:guestsCanInviteOthers value='false'/>"
-                       "<gCal:guestsCanSeeGuests value='false'/>"
-                       "<gCal:anyoneCanAddSelf value='false'/>"
-                       "<gd:when startTime='2009-04-17'/>"
-                       "<gd:when startTime='2009-04-17T15:00:00Z'/>"
-                       "<gd:when startTime='2009-04-27' endTime='2009-05-06'/>"
-               "</entry>");
-
-       g_object_unref (event);
+       guint i;
+
+       const struct {
+               const gchar *json;
+               gboolean is_date;
+               gint64 start_time;
+               gint64 end_time;
+               const gchar *output_json;  /* NULL if equal to @json */
+       } test_vectors[] = {
+               /* Plain date, single day. */
+               { "'start': {"
+                       "'date': '2009-04-17',"
+                       "'timeZone': 'UTC'"
+               "},"
+               "'end': {"
+                       "'date': '2009-04-18',"
+                       "'timeZone': 'UTC'"
+               "}", TRUE, 1239926400, 1239926400 + 86400, NULL },
+               /* Full date and time. */
+               { "'start': {"
+                       "'dateTime': '2009-04-17T15:00:00Z',"
+                       "'timeZone': 'UTC'"
+               "},"
+               "'end': {"
+                       "'dateTime': '2009-04-17T16:00:00Z',"
+                       "'timeZone': 'UTC'"
+               "}", FALSE, 1239926400 + 54000, 1239926400 + 54000 + 3600, NULL },
+               /* Start and end time. */
+               { "'start': {"
+                       "'date': '2009-04-27',"
+                       "'timeZone': 'UTC'"
+               "},"
+               "'end': {"
+                       "'date': '20090506',"
+                       "'timeZone': 'UTC'"
+               "}", TRUE, 1239926400 + 864000, 1241568000, "'start': {"
+                       "'date': '2009-04-27',"
+                       "'timeZone': 'UTC'"
+               "},"
+               "'end': {"
+                       "'date': '2009-05-06',"
+                       "'timeZone': 'UTC'"
+               "}" },
+       };
+
+       for (i = 0; i < G_N_ELEMENTS (test_vectors); i++) {
+               gchar *json = NULL, *output_json = NULL;  /* owned */
+               GDataCalendarEvent *event;
+               GList *j;
+               GDataGDWhen *when;
+               gint64 _time;
+               GError *error = NULL;
+
+               json = g_strdup_printf ("{"
+                       "'summary': 'Tennis with Beth',"
+                       "'description': 'Meet for a quick lesson.',"
+                       "'kind': 'calendar#event',"
+                       "%s"
+               "}", test_vectors[i].json);
+               output_json = g_strdup_printf ("{"
+                       "'summary': 'Tennis with Beth',"
+                       "'description': 'Meet for a quick lesson.',"
+                       "'kind': 'calendar#event',"
+                       "'guestsCanModify': false,"
+                       "'guestsCanInviteOthers': false,"
+                       "'guestsCanSeeOtherGuests': false,"
+                       "'anyoneCanAddSelf': false,"
+                       "'attendees': [],"
+                       "%s"
+               "}", (test_vectors[i].output_json != NULL) ? test_vectors[i].output_json : 
test_vectors[i].json);
+
+               event = GDATA_CALENDAR_EVENT (gdata_parsable_new_from_json (GDATA_TYPE_CALENDAR_EVENT, json, 
-1, &error));
+               g_assert_no_error (error);
+               g_assert (GDATA_IS_ENTRY (event));
+               g_clear_error (&error);
+
+               /* Check the times */
+               j = gdata_calendar_event_get_times (event);
+               g_assert (j != NULL);
+
+               when = GDATA_GD_WHEN (j->data);
+               g_assert (gdata_gd_when_is_date (when) == test_vectors[i].is_date);
+               _time = gdata_gd_when_get_start_time (when);
+               g_assert_cmpint (_time, ==, test_vectors[i].start_time);
+               _time = gdata_gd_when_get_end_time (when);
+               g_assert_cmpint (_time, ==, test_vectors[i].end_time);
+               g_assert (gdata_gd_when_get_value_string (when) == NULL);
+               g_assert (gdata_gd_when_get_reminders (when) == NULL);
+
+               /* Should be no other times. */
+               g_assert (j->next == NULL);
+
+               /* Check the JSON */
+               gdata_test_assert_json (event, output_json);
+
+               g_object_unref (event);
+               g_free (output_json);
+               g_free (json);
+       }
 }
 
 static void
-test_event_xml_recurrence (void)
+test_event_json_recurrence (void)
 {
        GDataCalendarEvent *event;
        GError *error = NULL;
        gchar *id, *uri;
 
-       event = GDATA_CALENDAR_EVENT (gdata_parsable_new_from_xml (GDATA_TYPE_CALENDAR_EVENT,
-               "<entry xmlns='http://www.w3.org/2005/Atom' "
-                      "xmlns:gd='http://schemas.google.com/g/2005' "
-                      "xmlns:gCal='http://schemas.google.com/gCal/2005' "
-                      "xmlns:app='http://www.w3.org/2007/app'>"
-                       "<id>http://www.google.com/calendar/feeds/libgdata test googlemail 
com/events/g5928e82rrch95b25f8ud0dlsg_20090429T153000Z</id>"
-                       "<published>2009-04-25T15:22:47.000Z</published>"
-                       "<updated>2009-04-27T17:54:10.000Z</updated>"
-                       "<app:edited 
xmlns:app='http://www.w3.org/2007/app'>2009-04-27T17:54:10.000Z</app:edited>"
-                       "<category scheme='http://schemas.google.com/g/2005#kind' 
term='http://schemas.google.com/g/2005#event'/>"
-                       "<title>Test daily instance event</title>"
-                       "<content></content>"
-                       "<link rel='http://www.iana.org/assignments/relation/alternate' type='text/html' "
-                             "href='http://www.google.com/calendar/event?";
-                                   
"eid=ZzU5MjhlODJycmNoOTViMjVmOHVkMGRsc2dfMjAwOTA0MjlUMTUzMDAwWiBsaWJnZGF0YS50ZXN0QGdvb2dsZW1haWwuY29t' "
-                             "title='alternate'/>"
-                       "<link rel='http://www.iana.org/assignments/relation/self' 
type='application/atom+xml' "
-                             "href='http://www.google.com/calendar/feeds/libgdata test googlemail 
com/private/full/"
-                                   "g5928e82rrch95b25f8ud0dlsg_20090429T153000Z'/>"
-                       "<link rel='http://www.iana.org/assignments/relation/edit' 
type='application/atom+xml' "
-                             "href='http://www.google.com/calendar/feeds/libgdata test googlemail 
com/private/full/"
-                                   "g5928e82rrch95b25f8ud0dlsg_20090429T153000Z'/>"
-                       "<author>"
-                               "<name>GData Test</name>"
-                               "<email>libgdata test googlemail com</email>"
-                       "</author>"
-                       "<gd:originalEvent id='g5928e82rrch95b25f8ud0dlsg' "
-                                         "href='http://www.google.com/calendar/feeds/libgdata test 
googlemail com/private/full/"
-                                               "g5928e82rrch95b25f8ud0dlsg'>"
-                               "<gd:when startTime='2009-04-29T16:30:00.000+01:00'/>"
-                       "</gd:originalEvent>"
-                       "<gCal:guestsCanModify value='false'/>"
-                       "<gCal:guestsCanInviteOthers value='false'/>"
-                       "<gCal:guestsCanSeeGuests value='false'/>"
-                       "<gCal:anyoneCanAddSelf value='false'/>"
-                       "<gd:comments>"
-                               "<gd:feedLink href='http://www.google.com/calendar/feeds/libgdata test 
googlemail com/private/full/"
-                                                  "g5928e82rrch95b25f8ud0dlsg_20090429T153000Z/comments'/>"
-                       "</gd:comments>"
-                       "<gd:eventStatus value='http://schemas.google.com/g/2005#event.confirmed'/>"
-                       "<gd:visibility value='http://schemas.google.com/g/2005#event.private'/>"
-                       "<gd:transparency value='http://schemas.google.com/g/2005#event.opaque'/>"
-                       "<gCal:uid value='g5928e82rrch95b25f8ud0dlsg google com'/>"
-                       "<gCal:sequence value='0'/>"
-                       "<gd:when startTime='2009-04-29T17:30:00.000+01:00' 
endTime='2009-04-29T17:30:00.000+01:00'>"
-                               "<gd:reminder minutes='10' method='email'/>"
-                               "<gd:reminder minutes='10' method='alert'/>"
-                       "</gd:when>"
-                       "<gd:who rel='http://schemas.google.com/g/2005#event.organizer' valueString='GData 
Test' "
-                               "email='libgdata test googlemail com'/>"
-                       "<gd:where valueString=''/>"
-               "</entry>", -1, &error));
+       event = GDATA_CALENDAR_EVENT (gdata_parsable_new_from_json (GDATA_TYPE_CALENDAR_EVENT, "{"
+               "'id': 'https://www.googleapis.com/calendar/v3/calendars/libgdata test googlemail 
com/events/g5928e82rrch95b25f8ud0dlsg_20090429T153000Z',"
+               "'updated': '2009-04-27T17:54:10.000Z',"
+               "'summary': 'Test daily instance event',"
+               "'kind': 'calendar#event',"
+               "'creator': {"
+                       "'displayName': 'GData Test',"
+                       "'email': 'libgdata test googlemail com'"
+               "},"
+               "'recurringEventId': 'g5928e82rrch95b25f8ud0dlsg',"
+               "'originalStartTime': {"
+                       "'dateTime': '2009-04-29T16:30:00.000+01:00',"
+                       "'timeZone': 'UTC'"
+               "},"
+               "'guestsCanModify': false,"
+               "'guestsCanInviteOthers': false,"
+               "'guestsCanSeeOtherGuests': false,"
+               "'anyoneCanAddSelf': false,"
+               "'status': 'http://schemas.google.com/g/2005#event.confirmed',"
+               "'visibility': 'http://schemas.google.com/g/2005#event.private',"
+               "'transparency': 'http://schemas.google.com/g/2005#event.opaque',"
+               "'iCalUID': 'g5928e82rrch95b25f8ud0dlsg google com',"
+               "'sequence': '0',"
+               "'start': {"
+                       "'dateTime': '2009-04-29T17:30:00.000+01:00',"
+                       "'timeZone': 'UTC'"
+               "},"
+               "'end': {"
+                       "'dateTime': '2009-04-29T17:30:00.000+01:00',"
+                       "'timeZone': 'UTC'"
+               "},"
+               "'reminders': {"
+                       "'overrides': [{"
+                               "'method': 'email',"
+                               "'minutes': 10"
+                       "}, {"
+                               "'method': 'popup',"
+                               "'minutes': 10"
+                       "}]"
+               "},"
+               "'attendees': ["
+                       "{"
+                               "'email': 'libgdata test googlemail com',"
+                               "'displayName': 'GData Test',"
+                               "'organizer': true"
+                       "}"
+               "],"
+               "'organizer': {"
+                       "'email': 'libgdata test googlemail com',"
+                       "'displayName': 'GData Test'"
+               "}"
+       "}", -1, &error));
        g_assert_no_error (error);
        g_assert (GDATA_IS_ENTRY (event));
        g_clear_error (&error);
@@ -786,7 +815,9 @@ test_event_xml_recurrence (void)
 
        gdata_calendar_event_get_original_event_details (event, &id, &uri);
        g_assert_cmpstr (id, ==, "g5928e82rrch95b25f8ud0dlsg");
-       g_assert_cmpstr (uri, ==, "http://www.google.com/calendar/feeds/libgdata test googlemail 
com/private/full/g5928e82rrch95b25f8ud0dlsg");
+       /* TODO
+       g_assert_cmpstr (uri, ==, "https://www.googleapis.com/calendar/v3/calendars/libgdata test googlemail 
com/events/g5928e82rrch95b25f8ud0dlsg");
+       */
 
        g_free (id);
        g_free (uri);
@@ -801,8 +832,8 @@ test_calendar_escaping (void)
        calendar = gdata_calendar_calendar_new (NULL);
        gdata_calendar_calendar_set_timezone (calendar, "<timezone>");
 
-       /* Check the outputted XML is escaped properly */
-       gdata_test_assert_xml (calendar,
+       /* Check the outputted JSON is escaped properly */
+       gdata_test_assert_json (calendar,
                "<?xml version='1.0' encoding='UTF-8'?>"
                "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' "
                       "xmlns:gCal='http://schemas.google.com/gCal/2005' 
xmlns:app='http://www.w3.org/2007/app'>"
@@ -822,29 +853,26 @@ test_event_escaping (void)
        GDataCalendarEvent *event;
 
        event = gdata_calendar_event_new (NULL);
-       gdata_calendar_event_set_status (event, "<status>");
-       gdata_calendar_event_set_visibility (event, "<visibility>");
-       gdata_calendar_event_set_transparency (event, "<transparency>");
-       gdata_calendar_event_set_uid (event, "<uid>");
-       gdata_calendar_event_set_recurrence (event, "<recurrence>");
-
-       /* Check the outputted XML is escaped properly */
-       gdata_test_assert_xml (event,
-               "<?xml version='1.0' encoding='UTF-8'?>"
-               "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' "
-                      "xmlns:gCal='http://schemas.google.com/gCal/2005' 
xmlns:app='http://www.w3.org/2007/app'>"
-                       "<title type='text'></title>"
-                       "<category term='http://schemas.google.com/g/2005#event' 
scheme='http://schemas.google.com/g/2005#kind'/>"
-                       "<gd:eventStatus value='&lt;status&gt;'/>"
-                       "<gd:visibility value='&lt;visibility&gt;'/>"
-                       "<gd:transparency value='&lt;transparency&gt;'/>"
-                       "<gCal:uid value='&lt;uid&gt;'/>"
-                       "<gCal:guestsCanModify value='false'/>"
-                       "<gCal:guestsCanInviteOthers value='false'/>"
-                       "<gCal:guestsCanSeeGuests value='false'/>"
-                       "<gCal:anyoneCanAddSelf value='false'/>"
-                       "<gd:recurrence>&lt;recurrence&gt;</gd:recurrence>"
-               "</entry>");
+       gdata_calendar_event_set_status (event, "\"status\"");
+       gdata_calendar_event_set_visibility (event, "\"visibility\"");
+       gdata_calendar_event_set_transparency (event, "\"transparency\"");
+       gdata_calendar_event_set_uid (event, "\"uid\"");
+       gdata_calendar_event_set_recurrence (event, "\"recurrence\"");
+
+       /* Check the outputted JSON is escaped properly */
+       gdata_test_assert_json (event, "{"
+               "'kind': 'calendar#event',"
+               "'status': '\"status\"',"
+               "'transparency': '\"transparency\"',"
+               "'visibility': '\"visibility\"',"
+               "'iCalUID': '\"uid\"',"
+               "'recurrence': [ '\"recurrence\"' ],"
+               "'guestsCanModify': false,"
+               "'guestsCanInviteOthers': false,"
+               "'guestsCanSeeOtherGuests': false,"
+               "'anyoneCanAddSelf': false,"
+               "'attendees': []"
+       "}");
        g_object_unref (event);
 }
 
@@ -942,7 +970,7 @@ test_access_rule_properties (void)
 }
 
 static void
-test_access_rule_xml (void)
+test_access_rule_json (void)
 {
        GDataAccessRule *rule;
 
@@ -951,8 +979,8 @@ test_access_rule_xml (void)
        gdata_access_rule_set_role (rule, GDATA_CALENDAR_ACCESS_ROLE_EDITOR);
        gdata_access_rule_set_scope (rule, GDATA_ACCESS_SCOPE_USER, "darcy gmail com");
 
-       /* Check the XML */
-       gdata_test_assert_xml (rule,
+       /* Check the JSON */
+       gdata_test_assert_json (rule,
                "<?xml version='1.0' encoding='UTF-8'?>"
                "<entry xmlns='http://www.w3.org/2005/Atom' "
                       "xmlns:gd='http://schemas.google.com/g/2005' "
@@ -1600,7 +1628,7 @@ main (int argc, char *argv[])
        trace_directory = g_file_new_for_path (TEST_FILE_DIR "traces/calendar");
        uhm_server_set_trace_directory (mock_server, trace_directory);
        g_object_unref (trace_directory);
-
+#if 0
        authorizer = create_global_authorizer ();
 
        service = GDATA_SERVICE (gdata_calendar_service_new (authorizer));
@@ -1647,7 +1675,7 @@ main (int argc, char *argv[])
                    tear_down_temp_calendar_acls);
        g_test_add ("/calendar/access-rule/delete", TempCalendarAclsData, service, set_up_temp_calendar_acls, 
test_access_rule_delete,
                    tear_down_temp_calendar_acls);
-
+#endif
 #if 0
 TODO
        g_test_add_data_func ("/calendar/batch", service, test_batch);
@@ -1656,9 +1684,9 @@ TODO
                    teardown_batch_async);
 #endif
 
-       g_test_add_func ("/calendar/event/xml", test_event_xml);
-       g_test_add_func ("/calendar/event/xml/dates", test_event_xml_dates);
-       g_test_add_func ("/calendar/event/xml/recurrence", test_event_xml_recurrence);
+       g_test_add_func ("/calendar/event/json", test_event_json);
+       g_test_add_func ("/calendar/event/json/dates", test_event_json_dates);
+       g_test_add_func ("/calendar/event/json/recurrence", test_event_json_recurrence);
        g_test_add_func ("/calendar/event/escaping", test_event_escaping);
        g_test_add_func ("/calendar/event/parser/minimal",
                         test_calendar_event_parser_minimal);
@@ -1666,7 +1694,7 @@ TODO
        g_test_add_func ("/calendar/calendar/escaping", test_calendar_escaping);
 
        g_test_add_func ("/calendar/access-rule/properties", test_access_rule_properties);
-       g_test_add_func ("/calendar/access-rule/xml", test_access_rule_xml);
+       g_test_add_func ("/calendar/access-rule/json", test_access_rule_json);
 
        g_test_add_func ("/calendar/query/uri", test_query_uri);
        g_test_add_func ("/calendar/query/etag", test_query_etag);


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