[libgdata] [documents] Test case fixes
- From: Philip Withnall <pwithnall src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [libgdata] [documents] Test case fixes
- Date: Thu, 6 Aug 2009 21:10:38 +0000 (UTC)
commit c6a02abf76fd6c29b2eac61c107c8f4101af11c4
Author: Philip Withnall <philip tecnocode co uk>
Date: Thu Aug 6 22:09:16 2009 +0100
[documents] Test case fixes
Use the correct HTTP method when updating documents, check more strictly for
missing XML responses, use the Google-provided URI for removing documents from
folders, and don't try to parse a response to the same request which doesn't
exist.
gdata/gdata-parsable.c | 4 +-
gdata/gdata-service.c | 1 -
gdata/gdata-upload-stream.c | 9 +++-
gdata/gdata-upload-stream.h | 2 +-
gdata/services/documents/gdata-documents-service.c | 51 +++++---------------
5 files changed, 23 insertions(+), 44 deletions(-)
---
diff --git a/gdata/gdata-parsable.c b/gdata/gdata-parsable.c
index ae232a8..e274304 100644
--- a/gdata/gdata-parsable.c
+++ b/gdata/gdata-parsable.c
@@ -149,7 +149,7 @@ _gdata_parsable_new_from_xml (GType parsable_type, const gchar *xml, gint length
xmlNode *node;
g_return_val_if_fail (g_type_is_a (parsable_type, GDATA_TYPE_PARSABLE) == TRUE, FALSE);
- g_return_val_if_fail (xml != NULL, NULL);
+ g_return_val_if_fail (xml != NULL && *xml != '\0', NULL);
g_return_val_if_fail (length >= -1, NULL);
if (length == -1)
@@ -162,7 +162,7 @@ _gdata_parsable_new_from_xml (GType parsable_type, const gchar *xml, gint length
g_set_error (error, GDATA_PARSER_ERROR, GDATA_PARSER_ERROR_PARSING_STRING,
/* Translators: the parameter is an error message */
_("Error parsing XML: %s"),
- xml_error->message);
+ (xml_error != NULL) ? xml_error->message : NULL);
return NULL;
}
diff --git a/gdata/gdata-service.c b/gdata/gdata-service.c
index 4c3b8a8..1994487 100644
--- a/gdata/gdata-service.c
+++ b/gdata/gdata-service.c
@@ -331,7 +331,6 @@ static void
real_parse_error_response (GDataService *self, GDataServiceError error_type, guint status, const gchar *reason_phrase, const gchar *response_body,
gint length, GError **error)
{
- g_message ("*** parse_error_response: %u, %s, %s, %i", status, reason_phrase, response_body, length);
/* See: http://code.google.com/apis/gdata/docs/2.0/reference.html#HTTPStatusCodes */
switch (status) {
case 400:
diff --git a/gdata/gdata-upload-stream.c b/gdata/gdata-upload-stream.c
index c83a86f..e6abb5d 100644
--- a/gdata/gdata-upload-stream.c
+++ b/gdata/gdata-upload-stream.c
@@ -540,6 +540,7 @@ create_network_thread (GDataUploadStream *self, GError **error)
/**
* gdata_upload_stream_new:
* @service: a #GDataService
+ * @method: the HTTP method to use
* @upload_uri: the URI to upload
* @entry: the entry to upload as metadata, or %NULL
* @slug: the file's slug (filename)
@@ -547,6 +548,9 @@ create_network_thread (GDataUploadStream *self, GError **error)
*
* Creates a new #GDataUploadStream, allowing a file to be uploaded from a GData service using standard #GOutputStream API.
*
+ * The HTTP method to use should be specified in @method, and will typically be either %SOUP_METHOD_POST or %SOUP_METHOD_PUT, according to the server
+ * and the @upload_uri.
+ *
* If @entry is specified, it will be attached to the upload as the entry to which the file being uploaded belongs. Otherwise, just the file
* written to the stream will be uploaded, and given a default entry as determined by the server.
*
@@ -564,7 +568,8 @@ create_network_thread (GDataUploadStream *self, GError **error)
* Since: 0.5.0
**/
GOutputStream *
-gdata_upload_stream_new (GDataService *service, const gchar *upload_uri, GDataEntry *entry, const gchar *slug, const gchar *content_type)
+gdata_upload_stream_new (GDataService *service, const gchar *method, const gchar *upload_uri, GDataEntry *entry,
+ const gchar *slug, const gchar *content_type)
{
GDataServiceClass *klass;
GDataUploadStream *upload_stream;
@@ -577,7 +582,7 @@ gdata_upload_stream_new (GDataService *service, const gchar *upload_uri, GDataEn
g_return_val_if_fail (content_type != NULL, NULL);
/* Build the message */
- message = soup_message_new (SOUP_METHOD_POST, upload_uri);
+ message = soup_message_new (method, upload_uri);
/* Make sure the headers are set */
klass = GDATA_SERVICE_GET_CLASS (service);
diff --git a/gdata/gdata-upload-stream.h b/gdata/gdata-upload-stream.h
index d15dae6..6683f69 100644
--- a/gdata/gdata-upload-stream.h
+++ b/gdata/gdata-upload-stream.h
@@ -64,7 +64,7 @@ typedef struct {
GType gdata_upload_stream_get_type (void) G_GNUC_CONST;
-GOutputStream *gdata_upload_stream_new (GDataService *service, const gchar *upload_uri, GDataEntry *entry,
+GOutputStream *gdata_upload_stream_new (GDataService *service, const gchar *method, const gchar *upload_uri, GDataEntry *entry,
const gchar *slug, const gchar *content_type) G_GNUC_WARN_UNUSED_RESULT;
const gchar *gdata_upload_stream_get_response (GDataUploadStream *self, gssize *length);
diff --git a/gdata/services/documents/gdata-documents-service.c b/gdata/services/documents/gdata-documents-service.c
index 85cc7ba..c670ce2 100644
--- a/gdata/services/documents/gdata-documents-service.c
+++ b/gdata/services/documents/gdata-documents-service.c
@@ -59,7 +59,7 @@ static void gdata_documents_service_get_property (GObject *object, guint propert
static void notify_authenticated_cb (GObject *service, GParamSpec *pspec, GObject *self);
static void notify_proxy_uri_cb (GObject *service, GParamSpec *pspec, GObject *self);
GDataDocumentsEntry *upload_update_document (GDataDocumentsService *self, GDataDocumentsEntry *document, GFile *document_file,
- const gchar *upload_uri, GCancellable *cancellable, GError **error);
+ const gchar *method, const gchar *upload_uri, GCancellable *cancellable, GError **error);
struct _GDataDocumentsServicePrivate {
GDataService *spreadsheet_service;
@@ -327,8 +327,8 @@ notify_proxy_uri_cb (GObject *service, GParamSpec *pspec, GObject *self)
}
GDataDocumentsEntry *
-upload_update_document (GDataDocumentsService *self, GDataDocumentsEntry *document, GFile *document_file, const gchar *upload_uri,
- GCancellable *cancellable, GError **error)
+upload_update_document (GDataDocumentsService *self, GDataDocumentsEntry *document, GFile *document_file, const gchar *method,
+ const gchar *upload_uri, GCancellable *cancellable, GError **error)
{
GDataDocumentsEntry *new_entry;
GOutputStream *output_stream;
@@ -386,7 +386,7 @@ upload_update_document (GDataDocumentsService *self, GDataDocumentsEntry *docume
}
/* We need streaming file I/O: GDataUploadStream */
- output_stream = gdata_upload_stream_new (GDATA_SERVICE (self), upload_uri, GDATA_ENTRY (document), slug, content_type);
+ output_stream = gdata_upload_stream_new (GDATA_SERVICE (self), method, upload_uri, GDATA_ENTRY (document), slug, content_type);
if (file_info != NULL)
g_object_unref (file_info);
@@ -484,7 +484,7 @@ gdata_documents_service_upload_document (GDataDocumentsService *self, GDataDocum
new_document = GDATA_DOCUMENTS_ENTRY (gdata_service_insert_entry (GDATA_SERVICE (self), upload_uri, GDATA_ENTRY (document),
cancellable, error));
} else {
- new_document = upload_update_document (self, document, document_file, upload_uri, cancellable, error);
+ new_document = upload_update_document (self, document, document_file, SOUP_METHOD_POST, upload_uri, cancellable, error);
}
g_free (upload_uri);
@@ -534,7 +534,7 @@ gdata_documents_service_update_document (GDataDocumentsService *self, GDataDocum
update_link = gdata_entry_look_up_link (GDATA_ENTRY (document), GDATA_LINK_EDIT_MEDIA);
g_assert (update_link != NULL);
- return upload_update_document (self, document, document_file, gdata_link_get_uri (update_link), cancellable, error);
+ return upload_update_document (self, document, document_file, SOUP_METHOD_PUT, gdata_link_get_uri (update_link), cancellable, error);
}
/**
@@ -656,11 +656,10 @@ gdata_documents_service_remove_document_from_folder (GDataDocumentsService *self
GCancellable *cancellable, GError **error)
{
GDataServiceClass *klass;
- gchar *uri;
const gchar *document_id, *folder_id;
SoupMessage *message;
- GDataDocumentsEntry *new_document;
guint status;
+ GDataLink *link;
g_return_val_if_fail (GDATA_IS_DOCUMENTS_SERVICE (self), NULL);
g_return_val_if_fail (GDATA_IS_DOCUMENTS_ENTRY (document), NULL);
@@ -673,23 +672,9 @@ gdata_documents_service_remove_document_from_folder (GDataDocumentsService *self
return NULL;
}
- /* Get the document ID */
- folder_id = gdata_documents_entry_get_document_id (GDATA_DOCUMENTS_ENTRY (folder));
- document_id = gdata_documents_entry_get_document_id (GDATA_DOCUMENTS_ENTRY (document));
- g_assert (folder_id != NULL);
- g_assert (document_id != NULL);
-
- if (GDATA_IS_DOCUMENTS_PRESENTATION (document))
- uri = g_strdup_printf ("http://docs.google.com/feeds/folders/private/full/folder%%3A%s/presentation%%3A%s", folder_id, document_id);
- else if (GDATA_IS_DOCUMENTS_SPREADSHEET (document))
- uri = g_strdup_printf ("http://docs.google.com/feeds/folders/private/full/folder%%3A%s/spreadsheet%%3A%s", folder_id, document_id);
- else if (GDATA_IS_DOCUMENTS_TEXT (document))
- uri = g_strdup_printf ("http://docs.google.com/feeds/folders/private/full/folder%%3A%s/document%%3A%s", folder_id, document_id);
- else
- g_assert_not_reached ();
-
- message = soup_message_new (SOUP_METHOD_DELETE, uri);
- g_free (uri);
+ /* Build the message */
+ link = gdata_entry_look_up_link (GDATA_ENTRY (document), GDATA_LINK_EDIT);
+ message = soup_message_new (SOUP_METHOD_DELETE, gdata_link_get_uri (link));
/* Make sure subclasses set their headers */
klass = GDATA_SERVICE_GET_CLASS (self);
@@ -698,12 +683,6 @@ gdata_documents_service_remove_document_from_folder (GDataDocumentsService *self
soup_message_headers_append (message->request_headers, "If-Match", gdata_entry_get_etag (GDATA_ENTRY (document)));
- /* Check for cancellation */
- if (g_cancellable_set_error_if_cancelled (cancellable, error) == TRUE) {
- g_object_unref (message);
- return NULL;
- }
-
/* Send the message */
status = _gdata_service_send_message (GDATA_SERVICE (self), message, error);
if (status == SOUP_STATUS_NONE) {
@@ -726,15 +705,11 @@ gdata_documents_service_remove_document_from_folder (GDataDocumentsService *self
return NULL;
}
- /* Build the updated entry */
- g_assert (message->response_body->data != NULL);
-
- /* Parse the XML; and update the document*/
- new_document = GDATA_DOCUMENTS_ENTRY (gdata_parsable_new_from_xml (G_OBJECT_TYPE (document), message->response_body->data,
- message->response_body->length, error));
g_object_unref (message);
- return new_document;
+ /* Remove evidence of the folder from the entry and return it (since Google's servers don't return an updated entry for this query) */
+
+ return g_object_ref (document);
}
GDataService *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]