[gom] tests: Ensure filter priority
- From: Mathieu Bridon <mbridon src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gom] tests: Ensure filter priority
- Date: Mon, 8 Dec 2014 18:18:58 +0000 (UTC)
commit 991dcc20db650611853529c2d9c7dc49700b248b
Author: Mathieu Bridon <bochecha daitauha fr>
Date: Mon Dec 8 18:51:09 2014 +0100
tests: Ensure filter priority
This runs 2 queries with the same filters, but "grouped" in 2 different
ways, to ensure that we respect filtering priorities (i.e parentheses).
https://bugzilla.gnome.org/show_bug.cgi?id=740701
tests/test-gom-find-specific.c | 71 ++++++++++++++++++++++++++++++++++++++++
1 files changed, 71 insertions(+), 0 deletions(-)
---
diff --git a/tests/test-gom-find-specific.c b/tests/test-gom-find-specific.c
index 24b68b8..6bf006e 100644
--- a/tests/test-gom-find-specific.c
+++ b/tests/test-gom-find-specific.c
@@ -527,6 +527,76 @@ find_specific_and_fullv (void)
free_memory_db(adapter, repository);
}
+/* Ensure we respect filter priorities */
+static void
+find_specific_ensure_priorities (void)
+{
+ GomAdapter *adapter;
+ GomRepository *repository;
+ GomFilter *filter1, *filter2, *filter3, *filter4, *filter5;
+ GomResourceGroup *group;
+ GValue value = { 0, };
+ GError *error = NULL;
+ guint count;
+
+ create_memory_db(&adapter, &repository);
+
+ g_value_init(&value, G_TYPE_INT64);
+ g_value_set_int64(&value, 4);
+ filter1 = gom_filter_new_eq(EPISODE_TYPE_RESOURCE,
+ EPISODE_COLUMN_SEASON_NUMBER, &value);
+ g_value_unset(&value);
+
+ g_value_init(&value, G_TYPE_INT64);
+ g_value_set_int64(&value, 1);
+ filter2 = gom_filter_new_eq(EPISODE_TYPE_RESOURCE,
+ EPISODE_COLUMN_EPISODE_NUMBER, &value);
+ g_value_unset(&value);
+
+ g_value_init(&value, G_TYPE_INT64);
+ g_value_set_int64(&value, 2);
+ filter3 = gom_filter_new_eq(EPISODE_TYPE_RESOURCE,
+ EPISODE_COLUMN_EPISODE_NUMBER, &value);
+ g_value_unset(&value);
+
+ /* Search for:
+ * ( season-number=4 AND episode-number=1 ) OR episode-number=2
+ */
+ filter4 = gom_filter_new_and_full(filter1, filter2, NULL);
+ filter5 = gom_filter_new_or_full(filter4, filter3, NULL);
+
+ group = gom_repository_find_sync(repository, EPISODE_TYPE_RESOURCE,
+ filter5, &error);
+ g_assert_no_error(error);
+
+ count = gom_resource_group_get_count(group);
+ g_assert_cmpuint(count, ==, 3);
+
+ g_object_unref(filter4);
+ g_object_unref(filter5);
+
+ /* Now search for:
+ * season-number=4 AND ( episode-number=1 OR episode-number=2 )
+ */
+ filter4 = gom_filter_new_or_full(filter2, filter3, NULL);
+ filter5 = gom_filter_new_and_full(filter1, filter4, NULL);
+
+ group = gom_repository_find_sync(repository, EPISODE_TYPE_RESOURCE,
+ filter5, &error);
+ g_assert_no_error(error);
+
+ count = gom_resource_group_get_count(group);
+ g_assert_cmpuint(count, ==, 2);
+
+ g_object_unref(filter1);
+ g_object_unref(filter2);
+ g_object_unref(filter3);
+ g_object_unref(filter4);
+ g_object_unref(filter5);
+
+ free_memory_db(adapter, repository);
+}
+
static void
find_glob (void)
{
@@ -582,6 +652,7 @@ main (gint argc, gchar *argv[])
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-specific-ensure-priorities", find_specific_ensure_priorities);
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]