[libgdata] [core] Move kind support to GDataEntry



commit ea180875d562fe38c846e04a258dd33194915b4f
Author: Philip Withnall <philip tecnocode co uk>
Date:   Wed Jun 16 15:55:17 2010 +0100

    [core] Move kind support to GDataEntry
    
    Add support for kinds in GDataEntry, consolidating the existing code for
    adding kind categories which existed in various GDataEntry subclasses before.

 gdata/gdata-access-rule.c                          |    9 ++---
 gdata/gdata-entry.c                                |   32 ++++++++++++++++++
 gdata/gdata-entry.h                                |    3 ++
 gdata/services/calendar/gdata-calendar-calendar.c  |    3 ++
 gdata/services/calendar/gdata-calendar-event.c     |    3 ++
 gdata/services/contacts/gdata-contacts-contact.c   |    8 +----
 gdata/services/documents/gdata-documents-folder.c  |    3 ++
 .../documents/gdata-documents-presentation.c       |    3 ++
 .../documents/gdata-documents-spreadsheet.c        |    3 ++
 gdata/services/documents/gdata-documents-text.c    |    3 ++
 gdata/services/picasaweb/gdata-picasaweb-album.c   |    3 ++
 gdata/services/picasaweb/gdata-picasaweb-file.c    |    1 +
 gdata/services/picasaweb/gdata-picasaweb-service.c |   14 --------
 gdata/services/picasaweb/gdata-picasaweb-user.c    |    3 ++
 gdata/services/youtube/gdata-youtube-service.c     |    6 ---
 gdata/services/youtube/gdata-youtube-video.c       |    1 +
 gdata/tests/calendar.c                             |    4 --
 gdata/tests/contacts.c                             |    2 +-
 gdata/tests/documents.c                            |   34 --------------------
 gdata/tests/picasaweb.c                            |    6 +++
 20 files changed, 72 insertions(+), 72 deletions(-)
---
diff --git a/gdata/gdata-access-rule.c b/gdata/gdata-access-rule.c
index d67e5b9..386cf3b 100644
--- a/gdata/gdata-access-rule.c
+++ b/gdata/gdata-access-rule.c
@@ -69,6 +69,7 @@ gdata_access_rule_class_init (GDataAccessRuleClass *klass)
 {
 	GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
 	GDataParsableClass *parsable_class = GDATA_PARSABLE_CLASS (klass);
+	GDataEntryClass *entry_class = GDATA_ENTRY_CLASS (klass);
 
 	g_type_class_add_private (klass, sizeof (GDataAccessRulePrivate));
 
@@ -80,6 +81,8 @@ gdata_access_rule_class_init (GDataAccessRuleClass *klass)
 	parsable_class->get_xml = get_xml;
 	parsable_class->get_namespaces = get_namespaces;
 
+	entry_class->kind_term = "http://schemas.google.com/acl/2007#accessRule";;
+
 	/**
 	 * GDataAccessRule:role:
 	 *
@@ -254,14 +257,8 @@ parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *node, gpointer user_da
 static void
 get_xml (GDataParsable *parsable, GString *xml_string)
 {
-	GDataCategory *category;
 	GDataAccessRulePrivate *priv = GDATA_ACCESS_RULE (parsable)->priv;
 
-	/* Ensure we have the correct category/kind */
-	category = gdata_category_new ("http://schemas.google.com/acl/2007#accessRule";, "http://schemas.google.com/g/2005#kind";, NULL);
-	gdata_entry_add_category (GDATA_ENTRY (parsable), category);
-	g_object_unref (category);
-
 	/* So it's valid Atom, set the title if one doesn't already exist */
 	if (gdata_entry_get_title (GDATA_ENTRY (parsable)) == NULL)
 		gdata_entry_set_title (GDATA_ENTRY (parsable), priv->role);
diff --git a/gdata/gdata-entry.c b/gdata/gdata-entry.c
index a925030..2f29d0c 100644
--- a/gdata/gdata-entry.c
+++ b/gdata/gdata-entry.c
@@ -43,6 +43,7 @@
 #include "atom/gdata-link.h"
 #include "atom/gdata-author.h"
 
+static void gdata_entry_constructed (GObject *object);
 static void gdata_entry_dispose (GObject *object);
 static void gdata_entry_finalize (GObject *object);
 static void gdata_entry_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
@@ -91,6 +92,7 @@ gdata_entry_class_init (GDataEntryClass *klass)
 
 	g_type_class_add_private (klass, sizeof (GDataEntryPrivate));
 
+	gobject_class->constructed = gdata_entry_constructed;
 	gobject_class->get_property = gdata_entry_get_property;
 	gobject_class->set_property = gdata_entry_set_property;
 	gobject_class->dispose = gdata_entry_dispose;
@@ -245,6 +247,25 @@ gdata_entry_init (GDataEntry *self)
 }
 
 static void
+gdata_entry_constructed (GObject *object)
+{
+	GDataEntryClass *klass = GDATA_ENTRY_GET_CLASS (object);
+	GObjectClass *parent_class = G_OBJECT_CLASS (gdata_entry_parent_class);
+
+	/* This can't be done in *_init() because the class properties haven't been properly set then */
+	if (klass->kind_term != NULL) {
+		/* Ensure we have the correct category/kind */
+		GDataCategory *category = gdata_category_new (klass->kind_term, "http://schemas.google.com/g/2005#kind";, NULL);
+		gdata_entry_add_category (GDATA_ENTRY (object), category);
+		g_object_unref (category);
+	}
+
+	/* Chain up to the parent class */
+	if (parent_class->constructed != NULL)
+		parent_class->constructed (object);
+}
+
+static void
 gdata_entry_dispose (GObject *object)
 {
 	GDataEntryPrivate *priv = GDATA_ENTRY (object)->priv;
@@ -651,6 +672,17 @@ gdata_entry_add_category (GDataEntry *self, GDataCategory *category)
 	g_return_if_fail (GDATA_IS_ENTRY (self));
 	g_return_if_fail (GDATA_IS_CATEGORY (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) {
+		GDataEntryClass *klass = GDATA_ENTRY_GET_CLASS (self);
+
+		if (klass->kind_term != NULL && g_strcmp0 (gdata_category_get_term (category), klass->kind_term) != 0) {
+			g_warning ("Adding a kind category term, '%s', to an entry of kind '%s'.",
+			           gdata_category_get_term (category), klass->kind_term);
+		}
+	}
+
+	/* Add the category if we don't already have it */
 	if (g_list_find_custom (self->priv->categories, category, (GCompareFunc) gdata_comparable_compare) == NULL)
 		self->priv->categories = g_list_prepend (self->priv->categories, g_object_ref (category));
 }
diff --git a/gdata/gdata-entry.h b/gdata/gdata-entry.h
index 3034117..a852691 100644
--- a/gdata/gdata-entry.h
+++ b/gdata/gdata-entry.h
@@ -53,6 +53,8 @@ typedef struct {
  * GDataEntryClass:
  * @parent: the parent class
  * @get_entry_uri: a function to build the entry URI for the entry, given its entry ID; free the URI with g_free()
+ * @kind_term: the term for this entry's kind category (see the
+ * <ulink type="http" url="http://code.google.com/apis/gdata/docs/2.0/elements.html#Introduction";>documentation on kinds</ulink>)
  *
  * The class structure for the #GDataEntry type.
  **/
@@ -60,6 +62,7 @@ typedef struct {
 	GDataParsableClass parent;
 
 	gchar *(*get_entry_uri) (const gchar *id); /* G_GNUC_WARN_UNUSED_RESULT G_GNUC_MALLOC */
+	const gchar *kind_term;
 } GDataEntryClass;
 
 GType gdata_entry_get_type (void) G_GNUC_CONST;
diff --git a/gdata/services/calendar/gdata-calendar-calendar.c b/gdata/services/calendar/gdata-calendar-calendar.c
index 2e1df86..8ad60d9 100644
--- a/gdata/services/calendar/gdata-calendar-calendar.c
+++ b/gdata/services/calendar/gdata-calendar-calendar.c
@@ -83,6 +83,7 @@ gdata_calendar_calendar_class_init (GDataCalendarCalendarClass *klass)
 {
 	GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
 	GDataParsableClass *parsable_class = GDATA_PARSABLE_CLASS (klass);
+	GDataEntryClass *entry_class = GDATA_ENTRY_CLASS (klass);
 
 	g_type_class_add_private (klass, sizeof (GDataCalendarCalendarPrivate));
 
@@ -94,6 +95,8 @@ gdata_calendar_calendar_class_init (GDataCalendarCalendarClass *klass)
 	parsable_class->get_xml = get_xml;
 	parsable_class->get_namespaces = get_namespaces;
 
+	entry_class->kind_term = "http://schemas.google.com/gCal/2005#calendarmeta";;
+
 	/**
 	 * GDataCalendarCalendar:timezone:
 	 *
diff --git a/gdata/services/calendar/gdata-calendar-event.c b/gdata/services/calendar/gdata-calendar-event.c
index 4c0053c..ff5ed79 100644
--- a/gdata/services/calendar/gdata-calendar-event.c
+++ b/gdata/services/calendar/gdata-calendar-event.c
@@ -93,6 +93,7 @@ gdata_calendar_event_class_init (GDataCalendarEventClass *klass)
 {
 	GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
 	GDataParsableClass *parsable_class = GDATA_PARSABLE_CLASS (klass);
+	GDataEntryClass *entry_class = GDATA_ENTRY_CLASS (klass);
 
 	g_type_class_add_private (klass, sizeof (GDataCalendarEventPrivate));
 
@@ -105,6 +106,8 @@ gdata_calendar_event_class_init (GDataCalendarEventClass *klass)
 	parsable_class->get_xml = get_xml;
 	parsable_class->get_namespaces = get_namespaces;
 
+	entry_class->kind_term = "http://schemas.google.com/g/2005#event";;
+
 	/**
 	 * GDataCalendarEvent:edited:
 	 *
diff --git a/gdata/services/contacts/gdata-contacts-contact.c b/gdata/services/contacts/gdata-contacts-contact.c
index b8e6de5..58e1c78 100644
--- a/gdata/services/contacts/gdata-contacts-contact.c
+++ b/gdata/services/contacts/gdata-contacts-contact.c
@@ -144,6 +144,7 @@ gdata_contacts_contact_class_init (GDataContactsContactClass *klass)
 	parsable_class->get_namespaces = get_namespaces;
 
 	entry_class->get_entry_uri = get_entry_uri;
+	entry_class->kind_term = "http://schemas.google.com/contact/2008#contact";;
 
 	/**
 	 * GDataContactsContact:edited:
@@ -407,8 +408,6 @@ notify_full_name_cb (GObject *gobject, GParamSpec *pspec, GDataContactsContact *
 static void
 gdata_contacts_contact_init (GDataContactsContact *self)
 {
-	GDataCategory *category;
-
 	self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GDATA_TYPE_CONTACTS_CONTACT, GDataContactsContactPrivate);
 	self->priv->extended_properties = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
 	self->priv->user_defined_fields = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
@@ -423,11 +422,6 @@ gdata_contacts_contact_init (GDataContactsContact *self)
 
 	/* Initialise the contact's birthday to a sane but invalid date */
 	g_date_clear (&(self->priv->birthday), 1);
-
-	/* Add the "contact" kind category */
-	category = gdata_category_new ("http://schemas.google.com/contact/2008#contact";, "http://schemas.google.com/g/2005#kind";, NULL);
-	gdata_entry_add_category (GDATA_ENTRY (self), category);
-	g_object_unref (category);
 }
 
 static void
diff --git a/gdata/services/documents/gdata-documents-folder.c b/gdata/services/documents/gdata-documents-folder.c
index 5458a50..f5ec041 100644
--- a/gdata/services/documents/gdata-documents-folder.c
+++ b/gdata/services/documents/gdata-documents-folder.c
@@ -51,7 +51,10 @@ static void
 gdata_documents_folder_class_init (GDataDocumentsFolderClass *klass)
 {
 	GDataParsableClass *parsable_class = GDATA_PARSABLE_CLASS (klass);
+	GDataEntryClass *entry_class = GDATA_ENTRY_CLASS (klass);
+
 	parsable_class->get_xml = get_xml;
+	entry_class->kind_term = "http://schemas.google.com/docs/2007#folder";;
 }
 
 static void
diff --git a/gdata/services/documents/gdata-documents-presentation.c b/gdata/services/documents/gdata-documents-presentation.c
index 8a8c746..e6dd547 100644
--- a/gdata/services/documents/gdata-documents-presentation.c
+++ b/gdata/services/documents/gdata-documents-presentation.c
@@ -60,7 +60,10 @@ static void
 gdata_documents_presentation_class_init (GDataDocumentsPresentationClass *klass)
 {
 	GDataParsableClass *parsable_class = GDATA_PARSABLE_CLASS (klass);
+	GDataEntryClass *entry_class = GDATA_ENTRY_CLASS (klass);
+
 	parsable_class->get_xml = get_xml;
+	entry_class->kind_term = "http://schemas.google.com/docs/2007#presentation";;
 }
 
 static void
diff --git a/gdata/services/documents/gdata-documents-spreadsheet.c b/gdata/services/documents/gdata-documents-spreadsheet.c
index 50da9ae..e682c72 100644
--- a/gdata/services/documents/gdata-documents-spreadsheet.c
+++ b/gdata/services/documents/gdata-documents-spreadsheet.c
@@ -60,7 +60,10 @@ static void
 gdata_documents_spreadsheet_class_init (GDataDocumentsSpreadsheetClass *klass)
 {
 	GDataParsableClass *parsable_class = GDATA_PARSABLE_CLASS (klass);
+	GDataEntryClass *entry_class = GDATA_ENTRY_CLASS (klass);
+
 	parsable_class->get_xml = get_xml;
+	entry_class->kind_term = "http://schemas.google.com/docs/2007#spreadsheet";;
 }
 
 static void
diff --git a/gdata/services/documents/gdata-documents-text.c b/gdata/services/documents/gdata-documents-text.c
index 18cf350..d92932c 100644
--- a/gdata/services/documents/gdata-documents-text.c
+++ b/gdata/services/documents/gdata-documents-text.c
@@ -62,7 +62,10 @@ static void
 gdata_documents_text_class_init (GDataDocumentsTextClass *klass)
 {
 	GDataParsableClass *parsable_class = GDATA_PARSABLE_CLASS (klass);
+	GDataEntryClass *entry_class = GDATA_ENTRY_CLASS (klass);
+
 	parsable_class->get_xml = get_xml;
+	entry_class->kind_term = "http://schemas.google.com/docs/2007#document";;
 }
 
 static void
diff --git a/gdata/services/picasaweb/gdata-picasaweb-album.c b/gdata/services/picasaweb/gdata-picasaweb-album.c
index 2610133..ba7e2e0 100644
--- a/gdata/services/picasaweb/gdata-picasaweb-album.c
+++ b/gdata/services/picasaweb/gdata-picasaweb-album.c
@@ -150,6 +150,7 @@ gdata_picasaweb_album_class_init (GDataPicasaWebAlbumClass *klass)
 {
 	GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
 	GDataParsableClass *parsable_class = GDATA_PARSABLE_CLASS (klass);
+	GDataEntryClass *entry_class = GDATA_ENTRY_CLASS (klass);
 
 	g_type_class_add_private (klass, sizeof (GDataPicasaWebAlbumPrivate));
 
@@ -162,6 +163,8 @@ gdata_picasaweb_album_class_init (GDataPicasaWebAlbumClass *klass)
 	parsable_class->get_xml = get_xml;
 	parsable_class->get_namespaces = get_namespaces;
 
+	entry_class->kind_term = "http://schemas.google.com/photos/2007#album";;
+
 	/**
 	 * GDataPicasaWebAlbum:album-id
 	 *
diff --git a/gdata/services/picasaweb/gdata-picasaweb-file.c b/gdata/services/picasaweb/gdata-picasaweb-file.c
index db40ed6..487b5cd 100644
--- a/gdata/services/picasaweb/gdata-picasaweb-file.c
+++ b/gdata/services/picasaweb/gdata-picasaweb-file.c
@@ -182,6 +182,7 @@ gdata_picasaweb_file_class_init (GDataPicasaWebFileClass *klass)
 	parsable_class->get_namespaces = get_namespaces;
 
 	entry_class->get_entry_uri = get_entry_uri;
+	entry_class->kind_term = "http://schemas.google.com/photos/2007#photo";;
 
 	/**
 	 * GDataPicasaWebFile:file-id:
diff --git a/gdata/services/picasaweb/gdata-picasaweb-service.c b/gdata/services/picasaweb/gdata-picasaweb-service.c
index 24dffaf..01bdd5c 100644
--- a/gdata/services/picasaweb/gdata-picasaweb-service.c
+++ b/gdata/services/picasaweb/gdata-picasaweb-service.c
@@ -364,17 +364,11 @@ gdata_picasaweb_service_query_files (GDataPicasaWebService *self, GDataPicasaWeb
 static GOutputStream *
 get_file_output_stream (GDataPicasaWebService *self, GDataPicasaWebAlbum *album, GDataPicasaWebFile *file_entry, GFile *file_data, GError **error)
 {
-	GDataCategory *category;
 	GFileInfo *file_info = NULL;
 	const gchar *slug = NULL, *content_type = NULL, *user_id = NULL, *album_id = NULL;
 	GOutputStream *output_stream;
 	gchar *upload_uri;
 
-	/* Add the "photo" kind if the entry is missing it. If it already has the kind category, no duplicate is added. */
-	category = gdata_category_new ("http://schemas.google.com/photos/2007#photo";, "http://schemas.google.com/g/2005#kind";, NULL);
-	gdata_entry_add_category (GDATA_ENTRY (file_entry), category);
-	g_object_unref (category);
-
 	/* PicasaWeb allows you to post to a default Dropbox */
 	album_id = (album != NULL) ? gdata_entry_get_id (GDATA_ENTRY (album)) : "default";
 	user_id = gdata_service_get_username (GDATA_SERVICE (self));
@@ -668,8 +662,6 @@ error:
 GDataPicasaWebAlbum *
 gdata_picasaweb_service_insert_album (GDataPicasaWebService *self, GDataPicasaWebAlbum *album, GCancellable *cancellable, GError **error)
 {
-	GDataCategory *album_kind;
-
 	g_return_val_if_fail (GDATA_IS_PICASAWEB_SERVICE (self), NULL);
 	g_return_val_if_fail (GDATA_IS_PICASAWEB_ALBUM (album), NULL);
 	g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
@@ -687,12 +679,6 @@ gdata_picasaweb_service_insert_album (GDataPicasaWebService *self, GDataPicasaWe
 		return NULL;
 	}
 
-	/* PicasaWeb needs to know that this is an album, so we're adding the category when we insert it to make sure it's there.
-	   gdata_entry_add_category() checks if it already exists for us. */
-	album_kind = gdata_category_new ("http://schemas.google.com/photos/2007#album";, "http://schemas.google.com/g/2005#kind";, NULL);
-	gdata_entry_add_category (GDATA_ENTRY (album), album_kind);
-	g_object_unref (album_kind);
-
 	return GDATA_PICASAWEB_ALBUM (gdata_service_insert_entry (GDATA_SERVICE (self), "http://picasaweb.google.com/data/feed/api/user/default";,
 	                                                          GDATA_ENTRY (album), cancellable, error));
 }
diff --git a/gdata/services/picasaweb/gdata-picasaweb-user.c b/gdata/services/picasaweb/gdata-picasaweb-user.c
index 48e457d..296693e 100644
--- a/gdata/services/picasaweb/gdata-picasaweb-user.c
+++ b/gdata/services/picasaweb/gdata-picasaweb-user.c
@@ -67,6 +67,7 @@ gdata_picasaweb_user_class_init (GDataPicasaWebUserClass *klass)
 {
 	GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
 	GDataParsableClass *parsable_class = GDATA_PARSABLE_CLASS (klass);
+	GDataEntryClass *entry_class = GDATA_ENTRY_CLASS (klass);
 
 	g_type_class_add_private (klass, sizeof (GDataPicasaWebUserPrivate));
 
@@ -76,6 +77,8 @@ gdata_picasaweb_user_class_init (GDataPicasaWebUserClass *klass)
 	parsable_class->parse_xml = parse_xml;
 	parsable_class->get_namespaces = get_namespaces;
 
+	entry_class->kind_term = "http://schemas.google.com/photos/2007#user";;
+
 	/**
 	 * GDataPicasaWebUser:user:
 	 *
diff --git a/gdata/services/youtube/gdata-youtube-service.c b/gdata/services/youtube/gdata-youtube-service.c
index 31e2524..f041033 100644
--- a/gdata/services/youtube/gdata-youtube-service.c
+++ b/gdata/services/youtube/gdata-youtube-service.c
@@ -673,7 +673,6 @@ gdata_youtube_service_upload_video (GDataYouTubeService *self, GDataYouTubeVideo
 {
 	/* TODO: Async variant */
 	GDataYouTubeVideo *new_entry;
-	GDataCategory *category;
 	GOutputStream *output_stream;
 	GInputStream *input_stream;
 	const gchar *slug, *content_type, *response_body;
@@ -699,11 +698,6 @@ gdata_youtube_service_upload_video (GDataYouTubeService *self, GDataYouTubeVideo
 		return NULL;
 	}
 
-	/* Add the "video" kind if the entry is missing it. If it already has the kind category, no duplicate is added. */
-	category = gdata_category_new ("http://gdata.youtube.com/schemas/2007#video";, "http://schemas.google.com/g/2005#kind";, NULL);
-	gdata_entry_add_category (GDATA_ENTRY (video), category);
-	g_object_unref (category);
-
 	file_info = g_file_query_info (video_file, "standard::display-name,standard::content-type", G_FILE_QUERY_INFO_NONE, NULL, error);
 	if (file_info == NULL)
 		return NULL;
diff --git a/gdata/services/youtube/gdata-youtube-video.c b/gdata/services/youtube/gdata-youtube-video.c
index ce81fee..387d969 100644
--- a/gdata/services/youtube/gdata-youtube-video.c
+++ b/gdata/services/youtube/gdata-youtube-video.c
@@ -156,6 +156,7 @@ gdata_youtube_video_class_init (GDataYouTubeVideoClass *klass)
 	parsable_class->get_namespaces = get_namespaces;
 
 	entry_class->get_entry_uri = get_entry_uri;
+	entry_class->kind_term = "http://gdata.youtube.com/schemas/2007#video";;
 
 	/**
 	 * GDataYouTubeVideo:view-count:
diff --git a/gdata/tests/calendar.c b/gdata/tests/calendar.c
index 56f171b..1575418 100644
--- a/gdata/tests/calendar.c
+++ b/gdata/tests/calendar.c
@@ -228,7 +228,6 @@ static void
 test_insert_simple (gconstpointer service)
 {
 	GDataCalendarEvent *event, *new_event;
-	GDataCategory *category;
 	GDataGDWhere *where;
 	GDataGDWho *who;
 	GDataGDWhen *when;
@@ -240,9 +239,6 @@ test_insert_simple (gconstpointer service)
 
 	gdata_entry_set_title (GDATA_ENTRY (event), "Tennis with Beth");
 	gdata_entry_set_content (GDATA_ENTRY (event), "Meet for a quick lesson.");
-	category = gdata_category_new ("http://schemas.google.com/g/2005#event";, "http://schemas.google.com/g/2005#kind";, NULL);
-	gdata_entry_add_category (GDATA_ENTRY (event), category);
-	g_object_unref (category);
 	gdata_calendar_event_set_transparency (event, GDATA_GD_EVENT_TRANSPARENCY_OPAQUE);
 	gdata_calendar_event_set_status (event, GDATA_GD_EVENT_STATUS_CONFIRMED);
 	where = gdata_gd_where_new (NULL, "Rolling Lawn Courts", NULL);
diff --git a/gdata/tests/contacts.c b/gdata/tests/contacts.c
index dc53a1b..1a7ccd0 100644
--- a/gdata/tests/contacts.c
+++ b/gdata/tests/contacts.c
@@ -34,7 +34,7 @@ check_kind (GDataEntry *entry)
 	for (list = gdata_entry_get_categories (entry); list != NULL; list = list->next) {
 		GDataCategory *category = GDATA_CATEGORY (list->data);
 
-		if (strcmp (gdata_category_get_scheme (category), "http://schemas.google.com/g/2005#kind";) == 0) {
+		if (g_strcmp0 (gdata_category_get_scheme (category), "http://schemas.google.com/g/2005#kind";) == 0) {
 			g_assert_cmpstr (gdata_category_get_term (category), ==, "http://schemas.google.com/contact/2008#contact";);
 			has_kind = TRUE;
 		}
diff --git a/gdata/tests/documents.c b/gdata/tests/documents.c
index 41fb89c..0f50ee7 100644
--- a/gdata/tests/documents.c
+++ b/gdata/tests/documents.c
@@ -165,16 +165,12 @@ static void
 test_upload_metadata (gconstpointer service)
 {
 	GDataDocumentsEntry *document, *new_document;
-	GDataCategory *category;
 	GError *error = NULL;
 
 	g_assert (service != NULL);
 
 	document = GDATA_DOCUMENTS_ENTRY (gdata_documents_spreadsheet_new (NULL));
-	category = gdata_category_new ("http://schemas.google.com/docs/2007#spreadsheet";, "http://schemas.google.com/g/2005#kind";, "spreadsheet");
-
 	gdata_entry_set_title (GDATA_ENTRY (document), "myNewSpreadsheet");
-	gdata_entry_add_category (GDATA_ENTRY (document), category);
 
 	/* Insert the document */
 	new_document = gdata_documents_service_upload_document (GDATA_DOCUMENTS_SERVICE (service), GDATA_DOCUMENTS_ENTRY (document), NULL, NULL, NULL, &error);
@@ -191,7 +187,6 @@ test_upload_metadata_file (gconstpointer service)
 {
 	GDataDocumentsEntry *document, *new_document;
 	GFile *document_file;
-	GDataCategory *category;
 	GError *error = NULL;
 
 	g_assert (service != NULL);
@@ -199,9 +194,7 @@ test_upload_metadata_file (gconstpointer service)
 	document_file = g_file_new_for_path (TEST_FILE_DIR "test.odt");
 
 	document = GDATA_DOCUMENTS_ENTRY (gdata_documents_text_new (NULL));
-	category = gdata_category_new ("http://schemas.google.com/docs/2007#document";, "http://schemas.google.com/g/2005#kind";, "document");
 	gdata_entry_set_title (GDATA_ENTRY (document), "upload_metadata_file");
-	gdata_entry_add_category (GDATA_ENTRY (document), category);
 
 	/* Insert the document */
 	new_document = gdata_documents_service_upload_document (GDATA_DOCUMENTS_SERVICE (service), document, document_file, NULL, NULL, &error);
@@ -220,13 +213,11 @@ test_upload_file_get_entry (gconstpointer service)
 	GDataDocumentsEntry *new_document;
 	GDataEntry *new_presentation;
 	GFile *document_file;
-	GDataCategory *category;
 	GError *error = NULL;
 
 	g_assert (service != NULL);
 
 	document_file = g_file_new_for_path (TEST_FILE_DIR "test.ppt");
-	category = gdata_category_new ("http://schemas.google.com/docs/2007#presentation";, "http://schemas.google.com/g/2005#kind";, "presentation");
 
 	/* Insert the document */
 	new_document = gdata_documents_service_upload_document (GDATA_DOCUMENTS_SERVICE (service), NULL, document_file, NULL, NULL, &error);
@@ -251,21 +242,16 @@ test_add_remove_file_from_folder (gconstpointer service)
 	GDataDocumentsEntry *document, *new_document, *new_document2;
 	GDataDocumentsFolder *folder, *new_folder;
 	GFile *document_file;
-	GDataCategory *folder_category, *document_category;
 	GError *error = NULL;
 
 	g_assert (service != NULL);
 
 	folder = gdata_documents_folder_new (NULL);
-	folder_category = gdata_category_new ("http://schemas.google.com/docs/2007#folder";, "http://schemas.google.com/g/2005#kind";, "folder");
 	gdata_entry_set_title (GDATA_ENTRY (folder), "add_remove_from_folder_folder");
-	gdata_entry_add_category (GDATA_ENTRY (folder), folder_category);
 
 	document_file = g_file_new_for_path (TEST_FILE_DIR "test.ppt");
 	document = GDATA_DOCUMENTS_ENTRY (gdata_documents_presentation_new (NULL));
-	document_category = gdata_category_new ("http://schemas.google.com/docs/2007#presentation";, "http://schemas.google.com/g/2005#kind";, "presentation");
 	gdata_entry_set_title (GDATA_ENTRY (document), "add_remove_from_folder_presentation");
-	gdata_entry_add_category (GDATA_ENTRY (document), document_category);
 
 	/* Insert the folder */
 	new_folder = GDATA_DOCUMENTS_FOLDER (gdata_documents_service_upload_document (GDATA_DOCUMENTS_SERVICE (service), GDATA_DOCUMENTS_ENTRY (folder), NULL, NULL, NULL, &error));
@@ -297,7 +283,6 @@ test_add_file_folder_and_move (gconstpointer service)
 	GDataDocumentsEntry *document, *new_document, *new_document2;
 	GDataDocumentsFolder *folder, *new_folder;
 	GFile *document_file;
-	GDataCategory *folder_category, *document_category;
 	GError *error = NULL;
 
 	g_assert (service != NULL);
@@ -305,14 +290,10 @@ test_add_file_folder_and_move (gconstpointer service)
 	document_file = g_file_new_for_path (TEST_FILE_DIR "test.odt");
 
 	folder = gdata_documents_folder_new (NULL);
-	folder_category = gdata_category_new ("http://schemas.google.com/docs/2007#folder";, "http://schemas.google.com/g/2005#kind";, "folder");
 	gdata_entry_set_title (GDATA_ENTRY (folder), "add_file_folder_move_folder");
-	gdata_entry_add_category (GDATA_ENTRY (folder), folder_category);
 
 	document = GDATA_DOCUMENTS_ENTRY (gdata_documents_text_new (NULL));
-	document_category = gdata_category_new ("http://schemas.google.com/docs/2007#document";, "http://schemas.google.com/g/2005#kind";, "document");
 	gdata_entry_set_title (GDATA_ENTRY (document), "add_file_folder_move_text");
-	gdata_entry_add_category (GDATA_ENTRY (document), document_category);
 
 	/* Insert the folder */
 	new_folder = GDATA_DOCUMENTS_FOLDER (gdata_documents_service_upload_document (GDATA_DOCUMENTS_SERVICE (service), GDATA_DOCUMENTS_ENTRY (folder), NULL, NULL, NULL, &error));
@@ -343,7 +324,6 @@ test_upload_file_metadata_in_new_folder (gconstpointer service)
 	GDataDocumentsEntry *document, *new_document;
 	GDataDocumentsFolder *folder, *new_folder;
 	GFile *document_file;
-	GDataCategory *folder_category, *document_category;
 	GError *error = NULL;
 
 	g_assert (service != NULL);
@@ -351,14 +331,10 @@ test_upload_file_metadata_in_new_folder (gconstpointer service)
 	document_file = g_file_new_for_path (TEST_FILE_DIR "test.odt");
 
 	folder = gdata_documents_folder_new (NULL);
-	folder_category = gdata_category_new ("http://schemas.google.com/docs/2007#folder";, "http://schemas.google.com/g/2005#kind";, "folder");
 	gdata_entry_set_title (GDATA_ENTRY (folder), "upload_file_metadata_in_new_folder_folder");
-	gdata_entry_add_category (GDATA_ENTRY (folder), folder_category);
 
 	document = GDATA_DOCUMENTS_ENTRY (gdata_documents_text_new (NULL));
-	document_category = gdata_category_new ("http://schemas.google.com/docs/2007#document";, "http://schemas.google.com/g/2005#kind";, "document");
 	gdata_entry_set_title (GDATA_ENTRY (document), "upload_file_metadata_in_new_folder_text");
-	gdata_entry_add_category (GDATA_ENTRY (document), document_category);
 
 	/* Insert the folder */
 	new_folder = GDATA_DOCUMENTS_FOLDER (gdata_documents_service_upload_document (GDATA_DOCUMENTS_SERVICE (service), GDATA_DOCUMENTS_ENTRY (folder), NULL, NULL, NULL, &error));
@@ -383,15 +359,12 @@ static void
 test_update_metadata (gconstpointer service)
 {
 	GDataDocumentsEntry *document, *new_document, *updated_document;
-	GDataCategory *category;
 	GError *error = NULL;
 
 	g_assert (service != NULL);
 
 	document = GDATA_DOCUMENTS_ENTRY (gdata_documents_text_new (NULL));
-	category = gdata_category_new ("http://schemas.google.com/docs/2007#document";, "http://schemas.google.com/g/2005#kind";, "document");
 	gdata_entry_set_title (GDATA_ENTRY (document), "update_metadata_first_title");
-	gdata_entry_add_category (GDATA_ENTRY (document), category);
 
 	/* Insert the document */
 	new_document = gdata_documents_service_upload_document (GDATA_DOCUMENTS_SERVICE (service), document, NULL, NULL, NULL, &error);
@@ -417,7 +390,6 @@ test_update_metadata_file (gconstpointer service)
 {
 	GDataDocumentsEntry *document, *new_document, *updated_document;
 	GFile *document_file, *updated_document_file;
-	GDataCategory *category;
 	GError *error = NULL;
 
 	g_assert (service != NULL);
@@ -426,9 +398,7 @@ test_update_metadata_file (gconstpointer service)
 	updated_document_file = g_file_new_for_path (TEST_FILE_DIR "test_updated.odt");
 
 	document = GDATA_DOCUMENTS_ENTRY (gdata_documents_text_new (NULL));
-	category = gdata_category_new ("http://schemas.google.com/docs/2007#document";, "http://schemas.google.com/g/2005#kind";, "document");
 	gdata_entry_set_title (GDATA_ENTRY (document), "update_metadata_file_first_title");
-	gdata_entry_add_category (GDATA_ENTRY (document), category);
 
 	/* Insert the documents metadata*/
 	new_document = gdata_documents_service_upload_document (GDATA_DOCUMENTS_SERVICE (service), document, NULL, NULL, NULL, &error);
@@ -555,16 +525,12 @@ test_new_document_with_collaborator (gconstpointer service)
 {
 	GDataDocumentsEntry *document, *new_document;
 	GDataAccessRule *access_rule, *new_access_rule;
-	GDataCategory *category;
 	GError *error = NULL;
 
 	g_assert (service != NULL);
 
 	document = GDATA_DOCUMENTS_ENTRY (gdata_documents_spreadsheet_new (NULL));
-	category = gdata_category_new ("http://schemas.google.com/docs/2007#spreadsheet";, "http://schemas.google.com/g/2005#kind";, "spreadsheet");
-
 	gdata_entry_set_title (GDATA_ENTRY (document), "new_with_collaborator");
-	gdata_entry_add_category (GDATA_ENTRY (document), category);
 
 	/* Insert the document */
 	new_document = gdata_documents_service_upload_document (GDATA_DOCUMENTS_SERVICE (service), GDATA_DOCUMENTS_ENTRY (document), NULL, NULL, NULL, &error);
diff --git a/gdata/tests/picasaweb.c b/gdata/tests/picasaweb.c
index 210201b..aa07f07 100644
--- a/gdata/tests/picasaweb.c
+++ b/gdata/tests/picasaweb.c
@@ -182,6 +182,8 @@ test_upload_async (gconstpointer service)
 						"xmlns:gml='http://www.opengis.net/gml'>"
 						"<title type='text'>Async Photo Entry Title</title>"
 						"<summary type='text'>Async Photo Summary \\(%s\\)</summary>"
+						"<category term='http://schemas.google.com/photos/2007#photo' "
+							"scheme='http://schemas.google.com/g/2005#kind'/>"
 						"<gphoto:position>0</gphoto:position>"
 						"<gphoto:timestamp>([0-9]+)</gphoto:timestamp>"
 						"<gphoto:commentingEnabled>true</gphoto:commentingEnabled>"
@@ -554,6 +556,8 @@ test_upload_simple (gconstpointer service)
 						"xmlns:gml='http://www.opengis.net/gml'>"
 						"<title type='text'>Photo Entry Title</title>"
 						"<summary type='text'>Photo Summary \\(%s\\)</summary>"
+						"<category term='http://schemas.google.com/photos/2007#photo' "
+							"scheme='http://schemas.google.com/g/2005#kind'/>"
 						"<gphoto:position>0</gphoto:position>"
 						"<gphoto:timestamp>([0-9]+)</gphoto:timestamp>"
 						"<gphoto:commentingEnabled>true</gphoto:commentingEnabled>"
@@ -1294,6 +1298,8 @@ test_album_new (gconstpointer service)
 				    "xmlns:georss='http://www.georss.org/georss'>"
 					"<title type='text'></title>"
 					"<id>http://picasaweb.google.com/data/entry/user/libgdata.picasaweb/albumid/5328889949261497249</id>"
+					"<category term='http://schemas.google.com/photos/2007#album' "
+						"scheme='http://schemas.google.com/g/2005#kind'/>"
 					"<gphoto:id>5328889949261497249</gphoto:id>"
 					"<gphoto:access>private</gphoto:access>"
 					"<gphoto:timestamp>([0-9]+)</gphoto:timestamp>"



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