[gom] filter: Add new _fullv constructors
- From: Mathieu Bridon <mbridon src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gom] filter: Add new _fullv constructors
- Date: Fri, 5 Dec 2014 17:17:01 +0000 (UTC)
commit 84d9d22eb487f058e57e660ae5aa5d882dbdecf0
Author: Mathieu Bridon <bochecha daitauha fr>
Date: Thu Nov 27 19:29:36 2014 +0100
filter: Add new _fullv constructors
This is similar to the ones introduced in the previous commit, but the
argument is a NULL-temrinated array of GomFilter, rather than using
variadic functions.
A unit test is also added.
https://bugzilla.gnome.org/show_bug.cgi?id=740872
gom/gom-filter.c | 54 ++++++++++++++++++++++++++++++
gom/gom-filter.h | 2 +
tests/test-gom-find-specific.c | 72 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 128 insertions(+), 0 deletions(-)
---
diff --git a/gom/gom-filter.c b/gom/gom-filter.c
index 87525ed..2fdae8c 100644
--- a/gom/gom-filter.c
+++ b/gom/gom-filter.c
@@ -144,6 +144,30 @@ gom_filter_new_for_subfilters_full (GomFilterMode mode,
return filter;
}
+static GomFilter *
+gom_filter_new_for_subfilters_fullv (GomFilterMode mode,
+ GomFilter **filter_array)
+{
+ GomFilter *filter, *f;
+ guint i;
+
+ filter = g_object_new(GOM_TYPE_FILTER, "mode", mode, NULL);
+ filter->priv->subfilters = g_queue_new();
+
+ i = 0;
+ f = filter_array[i];
+
+ while (f != NULL) {
+ g_return_val_if_fail(GOM_IS_FILTER(f), NULL);
+ g_queue_push_tail(filter->priv->subfilters, g_object_ref(f));
+
+ i += 1;
+ f = filter_array[i];
+ }
+
+ return filter;
+}
+
GomFilter *
gom_filter_new_like (GType resource_type,
const gchar *property_name,
@@ -301,6 +325,21 @@ gom_filter_new_and_full (GomFilter *first,
}
/**
+ * gom_filter_new_and_fullv: (constructor)
+ * @filter_array: (in): A %NULL-terminated array of #GomFilter.
+ *
+ * Creates a new filter that requires that all filters passed as arguments
+ * equate to #TRUE.
+ *
+ * Returns: (transfer full): A #GomFilter.
+ */
+GomFilter *
+gom_filter_new_and_fullv (GomFilter **filter_array)
+{
+ return gom_filter_new_for_subfilters_fullv(GOM_FILTER_AND, filter_array);
+}
+
+/**
* gom_filter_new_or: (constructor)
* @left: (in): A #GomFilter.
* @right: (in): A #GomFilter.
@@ -353,6 +392,21 @@ gom_filter_new_or_full (GomFilter *first,
return filter;
}
+/**
+ * gom_filter_new_or_fullv: (constructor)
+ * @filter_array: (in): A %NULL-terminated array of #GomFilter.
+ *
+ * Creates a new filter that requires either of the filters passed as
+ * arguments equate to #TRUE.
+ *
+ * Returns: (transfer full): A #GomFilter.
+ */
+GomFilter *
+gom_filter_new_or_fullv (GomFilter **filter_array)
+{
+ return gom_filter_new_for_subfilters_fullv(GOM_FILTER_OR, filter_array);
+}
+
gchar *
gom_filter_get_sql (GomFilter *filter,
GHashTable *table_map)
diff --git a/gom/gom-filter.h b/gom/gom-filter.h
index bc51f01..a4fa06e 100644
--- a/gom/gom-filter.h
+++ b/gom/gom-filter.h
@@ -76,10 +76,12 @@ GomFilter *gom_filter_new_or (GomFilter *left,
GomFilter *right);
GomFilter *gom_filter_new_or_full (GomFilter *first,
...);
+GomFilter *gom_filter_new_or_fullv (GomFilter **filter_array);
GomFilter *gom_filter_new_and (GomFilter *left,
GomFilter *right);
GomFilter *gom_filter_new_and_full (GomFilter *first,
...);
+GomFilter *gom_filter_new_and_fullv (GomFilter **filter_array);
GomFilter *gom_filter_new_eq (GType resource_type,
const gchar *property_name,
const GValue *value);
diff --git a/tests/test-gom-find-specific.c b/tests/test-gom-find-specific.c
index 0f2a1dd..36289b3 100644
--- a/tests/test-gom-find-specific.c
+++ b/tests/test-gom-find-specific.c
@@ -451,6 +451,77 @@ find_specific_and_full (void)
free_memory_db(adapter, repository);
}
+/* Same as find_specific, but using the _fullv filter constructors */
+static void
+find_specific_and_fullv (void)
+{
+ GError *error = NULL;
+ GValue value = { 0, };
+ GomFilter **filter_array = g_new(GomFilter *, 4);
+ GomFilter *filter;
+ char *s1, *s2;
+ GomResource *resource;
+ EpisodeResource *eres;
+ GomAdapter *adapter;
+ GomRepository *repository;
+
+ create_memory_db(&adapter, &repository);
+
+ /* Season Number */
+ g_value_init(&value, G_TYPE_INT64);
+ g_value_set_int64(&value, values[0].season_number);
+ filter_array[0] = gom_filter_new_eq(EPISODE_TYPE_RESOURCE,
+ EPISODE_COLUMN_SEASON_NUMBER,
+ &value);
+ g_value_unset(&value);
+
+ /* Episode Number */
+ g_value_init(&value, G_TYPE_INT64);
+ g_value_set_int64(&value, values[0].episode_number);
+ filter_array[1] = gom_filter_new_eq(EPISODE_TYPE_RESOURCE,
+ EPISODE_COLUMN_EPISODE_NUMBER,
+ &value);
+ g_value_unset(&value);
+
+ /* Series ID */
+ g_value_init(&value, G_TYPE_STRING);
+ g_value_set_string(&value, values[0].series_id);
+ filter_array[2] = gom_filter_new_like(EPISODE_TYPE_RESOURCE,
+ EPISODE_COLUMN_SERIES_ID,
+ &value);
+ g_value_unset(&value);
+
+ /* Season Number and Episode Number and Series ID */
+ filter_array[3] = NULL;
+ filter = gom_filter_new_and_fullv(filter_array);
+ g_object_unref(filter_array[0]);
+ g_object_unref(filter_array[1]);
+ g_object_unref(filter_array[2]);
+ g_free(filter_array);
+
+ resource = gom_repository_find_one_sync(repository,
+ EPISODE_TYPE_RESOURCE,
+ filter,
+ &error);
+ g_assert_no_error(error);
+ g_assert(resource);
+ g_object_unref(filter);
+ eres = EPISODE_RESOURCE(resource);
+
+ g_object_get(eres,
+ EPISODE_COLUMN_SERIES_ID, &s1,
+ EPISODE_COLUMN_IMDB_ID, &s2,
+ NULL);
+ g_object_unref(eres);
+
+ g_assert_cmpstr(s1, ==, values[0].series_id);
+ g_assert_cmpstr(s2, ==, values[0].imdb_id);
+ g_free(s1);
+ g_free(s2);
+
+ free_memory_db(adapter, repository);
+}
+
static void
find_glob (void)
{
@@ -505,6 +576,7 @@ main (gint argc, gchar *argv[])
g_test_add_func ("/GomRepository/find-simple", find_simple);
g_test_add_func ("/GomRepository/find-specific", find_specific);
g_test_add_func ("/GomRepository/find-specific-and-full", find_specific_and_full);
+ g_test_add_func ("/GomRepository/find-specific-and-fullv", find_specific_and_fullv);
g_test_add_func ("/GomRepository/find-glob", find_glob);
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]