[gom] sorting: Add an async method
- From: Mathieu Bridon <mbridon src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gom] sorting: Add an async method
- Date: Wed, 8 Jul 2015 13:32:26 +0000 (UTC)
commit f6b9b84dc9be1d23dc09c62ae537fa2fa91cbb52
Author: Mathieu Bridon <bochecha daitauha fr>
Date: Sat Jun 27 17:54:12 2015 +0200
sorting: Add an async method
https://bugzilla.gnome.org/show_bug.cgi?id=730581
gom/gom-repository.c | 18 ++++++++-
gom/gom-repository.h | 6 +++
tests/test-gom-sorting.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 124 insertions(+), 1 deletions(-)
---
diff --git a/gom/gom-repository.c b/gom/gom-repository.c
index ae396ae..ca0cf89 100644
--- a/gom/gom-repository.c
+++ b/gom/gom-repository.c
@@ -627,6 +627,18 @@ gom_repository_find_async (GomRepository *repository,
GAsyncReadyCallback callback,
gpointer user_data)
{
+ gom_repository_find_sorted_async(repository, resource_type, filter, NULL,
+ callback, user_data);
+}
+
+void
+gom_repository_find_sorted_async (GomRepository *repository,
+ GType resource_type,
+ GomFilter *filter,
+ GomSorting *sorting,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
GomRepositoryPrivate *priv;
GSimpleAsyncResult *simple;
@@ -634,18 +646,22 @@ gom_repository_find_async (GomRepository *repository,
g_return_if_fail(g_type_is_a(resource_type, GOM_TYPE_RESOURCE));
g_return_if_fail(resource_type != GOM_TYPE_RESOURCE);
g_return_if_fail(!filter || GOM_IS_FILTER(filter));
+ g_return_if_fail(!sorting || GOM_IS_SORTING(sorting));
g_return_if_fail(callback != NULL);
priv = repository->priv;
simple = g_simple_async_result_new(G_OBJECT(repository), callback, user_data,
- gom_repository_find_async);
+ gom_repository_find_sorted_async);
g_object_set_data(G_OBJECT(simple), "resource-type",
GINT_TO_POINTER(resource_type));
g_object_set_data_full(G_OBJECT(simple), "filter",
filter ? g_object_ref(filter) : NULL,
filter ? g_object_unref : NULL);
+ g_object_set_data_full(G_OBJECT(simple), "sorting",
+ sorting ? g_object_ref(sorting) : NULL,
+ sorting ? g_object_unref : NULL);
gom_adapter_queue_read(priv->adapter, gom_repository_find_cb, simple);
}
diff --git a/gom/gom-repository.h b/gom/gom-repository.h
index 113cccd..a7cf98a 100644
--- a/gom/gom-repository.h
+++ b/gom/gom-repository.h
@@ -117,6 +117,12 @@ void gom_repository_find_async (GomRepository *reposi
GomFilter *filter,
GAsyncReadyCallback callback,
gpointer user_data);
+void gom_repository_find_sorted_async (GomRepository *repository,
+ GType resource_type,
+ GomFilter *filter,
+ GomSorting *sorting,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
GomResourceGroup *gom_repository_find_finish (GomRepository *repository,
GAsyncResult *result,
GError **error);
diff --git a/tests/test-gom-sorting.c b/tests/test-gom-sorting.c
index 2b8eb19..1e2ce3c 100644
--- a/tests/test-gom-sorting.c
+++ b/tests/test-gom-sorting.c
@@ -440,6 +440,105 @@ find_order_by_complex (void)
free_memory_db(adapter, repository);
}
+static void
+find_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GomAdapter *adapter;
+ GomRepository *repository;
+ GomResourceGroup *group;
+ GError *error = NULL;
+ EpisodeResource *eres;
+ guint count;
+ gchar *id;
+ guint8 season, episode;
+
+ repository = GOM_REPOSITORY(object);
+
+ group = gom_repository_find_finish(repository, result, &error);
+ g_assert_no_error(error);
+
+ count = gom_resource_group_get_count(group);
+ g_assert_cmpuint(count, ==, 4);
+
+ gom_resource_group_fetch_sync(group, 0, count, &error);
+ g_assert_no_error(error);
+
+ eres = EPISODE_RESOURCE(gom_resource_group_get_index(group, 0));
+ g_assert(eres);
+ g_object_get(eres, "series-id", &id, "season-number", &season,
+ "episode-number", &episode, NULL);
+ g_assert_cmpstr(id, ==, "84947");
+ g_assert_cmpuint(season, ==, 5);
+ g_assert_cmpuint(episode, ==, 1);
+ g_object_unref(eres);
+
+ eres = EPISODE_RESOURCE(gom_resource_group_get_index(group, 1));
+ g_assert(eres);
+ g_object_get(eres, "series-id", &id, "season-number", &season,
+ "episode-number", &episode, NULL);
+ g_assert_cmpstr(id, ==, "84947");
+ g_assert_cmpuint(season, ==, 5);
+ g_assert_cmpuint(episode, ==, 2);
+ g_object_unref(eres);
+
+ eres = EPISODE_RESOURCE(gom_resource_group_get_index(group, 2));
+ g_assert(eres);
+ g_object_get(eres, "series-id", &id, "season-number", &season,
+ "episode-number", &episode, NULL);
+ g_assert_cmpstr(id, ==, "84947");
+ g_assert_cmpuint(season, ==, 4);
+ g_assert_cmpuint(episode, ==, 1);
+ g_object_unref(eres);
+
+ eres = EPISODE_RESOURCE(gom_resource_group_get_index(group, 3));
+ g_assert(eres);
+ g_object_get(eres, "series-id", &id, "season-number", &season,
+ "episode-number", &episode, NULL);
+ g_assert_cmpstr(id, ==, "84947");
+ g_assert_cmpuint(season, ==, 4);
+ g_assert_cmpuint(episode, ==, 2);
+ g_object_unref(eres);
+
+ adapter = gom_repository_get_adapter(repository);
+ free_memory_db(adapter, repository);
+
+ g_main_loop_quit(gMainLoop);
+}
+
+static void
+find_order_by_complex_async (void)
+{
+ GomAdapter *adapter;
+ GomRepository *repository;
+ GomFilter *filter;
+ GomSorting *sorting;
+ GValue value = { 0, };
+
+ create_memory_db(&adapter, &repository);
+
+ /* Select only the episode for a single show */
+ g_value_init(&value, G_TYPE_STRING);
+ g_value_set_string(&value, "84947");
+ filter = gom_filter_new_eq(EPISODE_TYPE_RESOURCE, "series-id", &value);
+ g_value_unset(&value);
+
+ /* Order by season, then by episode */
+ sorting = gom_sorting_new(EPISODE_TYPE_RESOURCE, "season-number",
+ GOM_SORTING_DESCENDING,
+ EPISODE_TYPE_RESOURCE, "episode-number",
+ GOM_SORTING_ASCENDING,
+ NULL);
+
+ gom_repository_find_sorted_async(repository, EPISODE_TYPE_RESOURCE,
+ filter, sorting, find_cb, NULL);
+ g_object_unref(filter);
+ g_object_unref(sorting);
+
+ g_main_loop_run(gMainLoop);
+}
+
gint
main (gint argc, gchar *argv[])
{
@@ -448,6 +547,8 @@ main (gint argc, gchar *argv[])
g_test_add_func("/GomRepository/find-order-by-desc", find_order_by_desc);
g_test_add_func("/GomRepository/find-order-by-complex",
find_order_by_complex);
+ g_test_add_func("/GomRepository/find-order-by-complex-async",
+ find_order_by_complex_async);
gMainLoop = g_main_loop_new(NULL, FALSE);
return g_test_run();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]