[libgdata] Bug 597248 — Add gdata_picasaweb_query_new_with_limits



commit d55b48bb650ff31c31f1611a59dec3c5de3b9979
Author: Richard Schwarting <aquarichy gmail com>
Date:   Thu Oct 8 22:34:18 2009 +0100

    Bug 597248 â?? Add gdata_picasaweb_query_new_with_limits

 docs/reference/gdata-sections.txt                |    1 +
 gdata/gdata.symbols                              |    3 +-
 gdata/services/picasaweb/gdata-picasaweb-query.c |   33 ++++++++++++
 gdata/services/picasaweb/gdata-picasaweb-query.h |    1 +
 gdata/tests/picasaweb.c                          |   58 +++++++++++++++++++++-
 5 files changed, 93 insertions(+), 3 deletions(-)
---
diff --git a/docs/reference/gdata-sections.txt b/docs/reference/gdata-sections.txt
index 39b0d9c..9f1b8ab 100644
--- a/docs/reference/gdata-sections.txt
+++ b/docs/reference/gdata-sections.txt
@@ -1202,6 +1202,7 @@ GDATA_TYPE_PICASAWEB_SERVICE
 GDataPicasaWebQuery
 GDataPicasaWebQueryClass
 gdata_picasaweb_query_new
+gdata_picasaweb_query_new_with_limits
 gdata_picasaweb_query_get_visibility
 gdata_picasaweb_query_set_visibility
 gdata_picasaweb_query_get_thumbnail_size
diff --git a/gdata/gdata.symbols b/gdata/gdata.symbols
index 53100c9..c32c42c 100644
--- a/gdata/gdata.symbols
+++ b/gdata/gdata.symbols
@@ -594,8 +594,6 @@ gdata_picasaweb_file_get_make
 gdata_picasaweb_file_get_model
 gdata_picasaweb_file_get_coordinates
 gdata_picasaweb_file_set_coordinates
-gdata_picasaweb_query_get_type
-gdata_picasaweb_query_new
 gdata_picasaweb_service_get_type
 gdata_picasaweb_service_new
 gdata_picasaweb_service_query_all_albums
@@ -604,6 +602,7 @@ gdata_picasaweb_service_query_files
 gdata_picasaweb_service_upload_file
 gdata_picasaweb_query_get_type
 gdata_picasaweb_query_new
+gdata_picasaweb_query_new_with_limits
 gdata_picasaweb_query_get_visibility
 gdata_picasaweb_query_set_visibility
 gdata_picasaweb_query_get_thumbnail_size
diff --git a/gdata/services/picasaweb/gdata-picasaweb-query.c b/gdata/services/picasaweb/gdata-picasaweb-query.c
index 1e4e803..35e1f69 100644
--- a/gdata/services/picasaweb/gdata-picasaweb-query.c
+++ b/gdata/services/picasaweb/gdata-picasaweb-query.c
@@ -311,6 +311,39 @@ gdata_picasaweb_query_new (const gchar *q)
 }
 
 /**
+ * gdata_picasaweb_query_new_with_limits:
+ * @q: a query string
+ * @start_index: the index of the first result to include
+ * @max_results: the maximum number of results to include
+ *
+ * Creates a #GDataPicasaWebQuery with its #GDataQuery:q property set
+ * to @q, returning @max_results starting from the @start_index
+ * result.
+ *
+ * Note that when querying for albums with gdata_picasaweb_service_query_all_albums(), the @q parameter cannot be used.
+ *
+ * This is useful for paging through results, but the result
+ * set between separate queries may change.  So, if you use this to
+ * request the next ten results after a previous query, it may include
+ * some of the previously returned results if their order changed, or
+ * omit ones that would have otherwise been found in a earlier but
+ * larger query.
+ *
+ * Return value: a new #GDataPicasaWebQuery
+ *
+ * Since: 0.6.0
+ **/
+GDataPicasaWebQuery *
+gdata_picasaweb_query_new_with_limits (const gchar *q, gint start_index, gint max_results)
+{
+	return g_object_new (GDATA_TYPE_PICASAWEB_QUERY,
+			     "q", q,
+			     "start-index", start_index,
+			     "max-results", max_results,
+			     NULL);
+}
+
+/**
  * gdata_picasaweb_query_get_visibility:
  * @self: a #GDataPicasaWebQuery
  *
diff --git a/gdata/services/picasaweb/gdata-picasaweb-query.h b/gdata/services/picasaweb/gdata-picasaweb-query.h
index 9e55704..38e7895 100644
--- a/gdata/services/picasaweb/gdata-picasaweb-query.h
+++ b/gdata/services/picasaweb/gdata-picasaweb-query.h
@@ -65,6 +65,7 @@ typedef struct {
 GType gdata_picasaweb_query_get_type (void) G_GNUC_CONST;
 
 GDataPicasaWebQuery *gdata_picasaweb_query_new (const gchar *q) G_GNUC_WARN_UNUSED_RESULT;
+GDataPicasaWebQuery *gdata_picasaweb_query_new_with_limits (const gchar *q, gint start_index, gint max_results) G_GNUC_WARN_UNUSED_RESULT;
 
 GDataPicasaWebVisibility gdata_picasaweb_query_get_visibility (GDataPicasaWebQuery *self);
 void gdata_picasaweb_query_set_visibility (GDataPicasaWebQuery *self, GDataPicasaWebVisibility visibility);
diff --git a/gdata/tests/picasaweb.c b/gdata/tests/picasaweb.c
index 20311b4..c2abfaa 100644
--- a/gdata/tests/picasaweb.c
+++ b/gdata/tests/picasaweb.c
@@ -562,7 +562,7 @@ test_query_all_albums (GDataService *service)
 	GDataPicasaWebAlbum *album;
 
 	/* Test a query with a "q" parameter; it should fail */
-	query = GDATA_PICASAWEB_QUERY (gdata_picasaweb_query_new ("foobar"));
+	query = GDATA_QUERY (gdata_picasaweb_query_new ("foobar"));
 	album_feed = gdata_picasaweb_service_query_all_albums (GDATA_PICASAWEB_SERVICE (service), query, NULL, NULL, NULL, NULL, &error);
 	g_assert_error (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_BAD_QUERY_PARAMETER);
 	g_assert (album_feed == NULL);
@@ -589,6 +589,61 @@ test_query_all_albums (GDataService *service)
 }
 
 static void
+test_query_new_with_limits (GDataService *service)
+{
+	GDataQuery *query;
+	GDataFeed *album_feed_1, *album_feed_2;
+	GError *error;
+	GList *albums_1, *albums_2;
+
+	error = NULL;
+
+	/* Test a query with a "q" parameter; it should fail */
+	query = GDATA_QUERY (gdata_picasaweb_query_new_with_limits ("foobar", 1, 1));
+	album_feed_1 = gdata_picasaweb_service_query_all_albums (GDATA_PICASAWEB_SERVICE (service), query, NULL, NULL, NULL, NULL, &error);
+	g_assert_error (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_BAD_QUERY_PARAMETER);
+	g_assert (album_feed_1 == NULL);
+	g_clear_error (&error);
+	g_object_unref (query);
+
+	/* Test that two queries starting at different indices don't return the same content */
+	query = GDATA_QUERY (gdata_picasaweb_query_new_with_limits (NULL, 1, 1));
+	album_feed_1 = gdata_picasaweb_service_query_all_albums (GDATA_PICASAWEB_SERVICE (service), query, NULL, NULL, NULL, NULL, &error);
+	g_assert_no_error (error);
+	g_assert (GDATA_IS_FEED (album_feed_1));
+	albums_1 = gdata_feed_get_entries (album_feed_1);
+	g_object_unref (query);
+
+	query = GDATA_QUERY (gdata_picasaweb_query_new_with_limits (NULL, 2, 1));
+	album_feed_2 = gdata_picasaweb_service_query_all_albums (GDATA_PICASAWEB_SERVICE (service), query, NULL, NULL, NULL, NULL, &error);
+	g_assert_no_error (error);
+	g_assert (GDATA_IS_FEED (album_feed_2));
+	albums_2 = gdata_feed_get_entries (album_feed_2);
+	g_object_unref (query);
+
+	g_assert_cmpint (g_list_length (albums_1), ==, 1);
+	g_assert_cmpint (g_list_length (albums_2), ==, 1);
+	g_assert (GDATA_IS_ENTRY (albums_1->data));
+	g_assert (GDATA_IS_ENTRY (albums_2->data));
+	g_assert_cmpstr (gdata_entry_get_title (GDATA_ENTRY (albums_1->data)), !=, gdata_entry_get_title (GDATA_ENTRY (albums_2->data)));
+
+	g_object_unref (album_feed_1);
+	g_object_unref (album_feed_2);
+
+	/* Test that we get at most as many results as we requested */
+	query = GDATA_QUERY (gdata_picasaweb_query_new_with_limits (NULL, 1, 3));
+	album_feed_1 = gdata_picasaweb_service_query_all_albums (GDATA_PICASAWEB_SERVICE (service), query, NULL, NULL, NULL, NULL, &error);
+	g_assert_no_error (error);
+	g_assert (GDATA_IS_FEED (album_feed_1));
+	albums_1 = gdata_feed_get_entries (album_feed_1);
+	g_object_unref (query);
+
+	g_assert_cmpint (g_list_length (albums_1), ==, 3);
+
+	g_object_unref (album_feed_1);
+}
+
+static void
 test_query_all_albums_async_cb (GDataService *service, GAsyncResult *async_result, GMainLoop *main_loop)
 {
 	GDataFeed *feed;
@@ -641,6 +696,7 @@ main (int argc, char *argv[])
 	g_test_add_data_func ("/picasaweb/query/all_albums", service, test_query_all_albums);
 	if (g_test_thorough () == TRUE)
 		g_test_add_data_func ("/picasaweb/query/all_albums_async", service, test_query_all_albums_async);
+	g_test_add_data_func ("/picasaweb/query/new_with_limits", service, test_query_new_with_limits);
 	g_test_add_data_func ("/picasaweb/query/album_feed", service, test_album_feed);
 	g_test_add_data_func ("/picasaweb/query/album_feed_entry", service, test_album_feed_entry);
 	g_test_add_data_func ("/picasaweb/query/album", service, test_album);



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