4 #include "test-utils.h"
5 #include "rhythmdb-query-model.h"
8 #include "rb-file-helpers.h"
11 START_TEST (test_rhythmdb_db_queries
)
13 RhythmDBEntry
*entry
= NULL
;
19 entry
= rhythmdb_entry_new (db
, RHYTHMDB_ENTRY_TYPE_SONG
, "file:///whee.ogg");
20 fail_unless (entry
!= NULL
, "failed to create entry");
22 g_value_init (&val
, G_TYPE_STRING
);
23 g_value_set_static_string (&val
, "Rock");
24 rhythmdb_entry_set (db
, entry
, RHYTHMDB_PROP_GENRE
, &val
);
27 g_value_init (&val
, G_TYPE_STRING
);
28 g_value_set_static_string (&val
, "Nine Inch Nails");
29 rhythmdb_entry_set (db
, entry
, RHYTHMDB_PROP_ARTIST
, &val
);
32 g_value_init (&val
, G_TYPE_STRING
);
33 g_value_set_static_string (&val
, "Pretty Hate Machine");
34 rhythmdb_entry_set (db
, entry
, RHYTHMDB_PROP_ALBUM
, &val
);
37 g_value_init (&val
, G_TYPE_STRING
);
38 g_value_set_static_string (&val
, "Sin");
39 rhythmdb_entry_set (db
, entry
, RHYTHMDB_PROP_TITLE
, &val
);
44 /* basic queries and conjunctions */
45 query
= rhythmdb_query_parse (db
,
46 RHYTHMDB_QUERY_PROP_EQUALS
, RHYTHMDB_PROP_TYPE
, RHYTHMDB_ENTRY_TYPE_SONG
,
47 RHYTHMDB_QUERY_PROP_EQUALS
, RHYTHMDB_PROP_TITLE
, "Sin",
49 fail_unless (rhythmdb_evaluate_query (db
, query
, entry
), "query evaluated incorrectly");
50 rhythmdb_query_free (query
);
54 query
= rhythmdb_query_parse (db
,
55 RHYTHMDB_QUERY_PROP_LIKE
, RHYTHMDB_PROP_ARTIST
, "Nine Inch",
57 fail_unless (rhythmdb_evaluate_query (db
, query
, entry
), "query evaluated incorrectly");
58 rhythmdb_query_free (query
);
62 query
= rhythmdb_query_parse (db
,
63 RHYTHMDB_QUERY_PROP_LIKE
, RHYTHMDB_PROP_ALBUM
, "Load",
65 fail_if (rhythmdb_evaluate_query (db
, query
, entry
), "query evaluated incorrectly");
66 rhythmdb_query_free (query
);
70 query
= rhythmdb_query_parse (db
,
71 RHYTHMDB_QUERY_PROP_LIKE
, RHYTHMDB_PROP_SEARCH_MATCH
, "Pretty Nine",
73 rhythmdb_query_preprocess (db
, query
);
74 fail_unless (rhythmdb_evaluate_query (db
, query
, entry
), "query evaluated incorrectly");
75 rhythmdb_query_free (query
);
80 query
= rhythmdb_query_parse (db
,
81 RHYTHMDB_QUERY_PROP_LIKE
, RHYTHMDB_PROP_TITLE
, "Sin",
82 RHYTHMDB_QUERY_DISJUNCTION
,
83 RHYTHMDB_QUERY_PROP_LIKE
, RHYTHMDB_PROP_TITLE
, "Son",
85 fail_unless (rhythmdb_evaluate_query (db
, query
, entry
), "query evaluated incorrectly");
86 rhythmdb_query_free (query
);
90 query
= rhythmdb_query_parse (db
,
91 RHYTHMDB_QUERY_PROP_LIKE
, RHYTHMDB_PROP_TITLE
, "Sun",
92 RHYTHMDB_QUERY_DISJUNCTION
,
93 RHYTHMDB_QUERY_PROP_LIKE
, RHYTHMDB_PROP_TITLE
, "Sin",
95 fail_unless (rhythmdb_evaluate_query (db
, query
, entry
), "query evaluated incorrectly");
96 rhythmdb_query_free (query
);
100 query
= rhythmdb_query_parse (db
,
101 RHYTHMDB_QUERY_PROP_LIKE
, RHYTHMDB_PROP_TITLE
, "Sun",
102 RHYTHMDB_QUERY_DISJUNCTION
,
103 RHYTHMDB_QUERY_PROP_LIKE
, RHYTHMDB_PROP_TITLE
, "Son",
105 fail_if (rhythmdb_evaluate_query (db
, query
, entry
), "query evaluated incorrectly");
106 rhythmdb_query_free (query
);
108 /* TODO: subqueries */
110 rhythmdb_entry_delete (db
, entry
);
116 /* this tests that chained query models, where the base shows hidden entries
117 * forwards visibility changes correctly. This is basically what static playlists do */
118 START_TEST (test_hidden_chain_filter
)
120 RhythmDBQueryModel
*base_model
;
121 RhythmDBQueryModel
*filter_model
;
122 RhythmDBQuery
*query
;
123 RhythmDBEntry
*entry
;
130 base_model
= rhythmdb_query_model_new_empty (db
);
131 g_object_set (base_model
, "show-hidden", TRUE
, NULL
);
133 filter_model
= rhythmdb_query_model_new_empty (db
);
134 g_object_set (filter_model
, "base-model", base_model
, NULL
);
135 query
= g_ptr_array_new ();
136 g_object_set (filter_model
, "query", query
, NULL
);
137 rhythmdb_query_free (query
);
139 entry
= rhythmdb_entry_new (db
, RHYTHMDB_ENTRY_TYPE_SONG
, "file:///whee.ogg");
140 rhythmdb_commit (db
);
142 g_value_init (&val
, G_TYPE_BOOLEAN
);
145 /* add entry to base, should be in both */
146 rhythmdb_query_model_add_entry (base_model
, entry
, -1);
147 fail_unless (rhythmdb_query_model_entry_to_iter (base_model
, entry
, &iter
));
148 fail_unless (rhythmdb_query_model_entry_to_iter (filter_model
, entry
, &iter
));
152 /* hide entry, should be in base and not filtered */
153 g_value_set_boolean (&val
, TRUE
);
154 set_waiting_signal (G_OBJECT (db
), "entry-changed");
155 rhythmdb_entry_set (db
, entry
, RHYTHMDB_PROP_HIDDEN
, &val
);
156 rhythmdb_commit (db
);
159 fail_unless (rhythmdb_query_model_entry_to_iter (base_model
, entry
, &iter
));
160 fail_if (rhythmdb_query_model_entry_to_iter (filter_model
, entry
, &iter
));
164 /* show entry again, should be in both */
165 g_value_set_boolean (&val
, FALSE
);
166 set_waiting_signal (G_OBJECT (db
), "entry-changed");
167 rhythmdb_entry_set (db
, entry
, RHYTHMDB_PROP_HIDDEN
, &val
);
168 rhythmdb_commit (db
);
171 fail_unless (rhythmdb_query_model_entry_to_iter (base_model
, entry
, &iter
));
172 fail_unless (rhythmdb_query_model_entry_to_iter (filter_model
, entry
, &iter
));
177 rhythmdb_entry_delete (db
, entry
);
178 g_object_unref (base_model
);
179 g_object_unref (filter_model
);
180 g_value_unset (&val
);
187 rhythmdb_query_model_suite (void)
189 Suite
*s
= suite_create ("rhythmdb-query-model");
190 TCase
*tc_chain
= tcase_create ("rhythmdb-query-model-core");
191 TCase
*tc_bugs
= tcase_create ("rhythmdb-query-model-bugs");
193 suite_add_tcase (s
, tc_chain
);
194 tcase_add_checked_fixture (tc_chain
, test_rhythmdb_setup
, test_rhythmdb_shutdown
);
195 suite_add_tcase (s
, tc_bugs
);
196 tcase_add_checked_fixture (tc_bugs
, test_rhythmdb_setup
, test_rhythmdb_shutdown
);
198 /* test core functionality */
199 tcase_add_test (tc_chain
, test_rhythmdb_db_queries
);
201 /* tests for breakable bug fixes */
202 tcase_add_test (tc_bugs
, test_hidden_chain_filter
);
208 main (int argc
, char **argv
)
215 rb_profile_start ("rhythmdb-query-model test suite");
217 g_thread_init (NULL
);
220 gtk_init (&argc
, &argv
);
222 rb_debug_init (TRUE
);
223 rb_refstring_system_init ();
224 rb_file_helpers_init ();
227 GDK_THREADS_ENTER ();
230 s
= rhythmdb_query_model_suite ();
231 sr
= srunner_create (s
);
232 srunner_run_all (sr
, CK_NORMAL
);
233 ret
= srunner_ntests_failed (sr
);
237 rb_file_helpers_shutdown ();
238 rb_refstring_system_shutdown ();
239 gnome_vfs_shutdown ();
241 rb_profile_end ("rhythmdb-query-model test suite");