4 #include <glib/gi18n.h>
6 #include "test-utils.h"
9 #include "rb-file-helpers.h"
13 #include "rhythmdb-tree.h"
14 #include "rhythmdb-query-model.h"
20 set_true (RhythmDBEntry
*entry
, gboolean
*b
)
28 START_TEST (test_rhythmdb_indexing
)
30 RhythmDBEntry
*entry
= NULL
;
34 entry
= rhythmdb_entry_new (db
, RHYTHMDB_ENTRY_TYPE_SONG
, "file:///whee.ogg");
35 fail_unless (entry
!= NULL
, "failed to create entry");
37 g_value_init (&val
, G_TYPE_STRING
);
38 g_value_set_static_string (&val
, "Rock");
39 rhythmdb_entry_set (db
, entry
, RHYTHMDB_PROP_GENRE
, &val
);
42 g_value_init (&val
, G_TYPE_STRING
);
43 g_value_set_static_string (&val
, "Nine Inch Nails");
44 rhythmdb_entry_set (db
, entry
, RHYTHMDB_PROP_ARTIST
, &val
);
47 g_value_init (&val
, G_TYPE_STRING
);
48 g_value_set_static_string (&val
, "Pretty Hate Machine");
49 rhythmdb_entry_set (db
, entry
, RHYTHMDB_PROP_ALBUM
, &val
);
52 g_value_init (&val
, G_TYPE_STRING
);
53 g_value_set_static_string (&val
, "Sin");
54 rhythmdb_entry_set (db
, entry
, RHYTHMDB_PROP_TITLE
, &val
);
59 /* check the data is recorded correctly */
60 fail_unless (strcmp (rhythmdb_entry_get_string (entry
, RHYTHMDB_PROP_LOCATION
), "file:///whee.ogg") == 0,
61 "LOCATION set incorrectly");
62 fail_unless (strcmp (rhythmdb_entry_get_string (entry
, RHYTHMDB_PROP_GENRE
), "Rock") == 0,
63 "GENRE set incorrectly");
64 fail_unless (strcmp (rhythmdb_entry_get_string (entry
, RHYTHMDB_PROP_ARTIST
), "Nine Inch Nails") == 0,
65 "ARTIST set incorrectly");
66 fail_unless (strcmp (rhythmdb_entry_get_string (entry
, RHYTHMDB_PROP_ALBUM
), "Pretty Hate Machine") == 0,
67 "ALBUM set incorrectly");
68 fail_unless (strcmp (rhythmdb_entry_get_string (entry
, RHYTHMDB_PROP_TITLE
), "Sin") == 0,
69 "TITLE set incorrectly");
71 /* check changing album */
72 g_value_init (&val
, G_TYPE_STRING
);
73 g_value_set_static_string (&val
, "Broken");
74 rhythmdb_entry_set (db
, entry
, RHYTHMDB_PROP_ALBUM
, &val
);
78 fail_unless (strcmp (rhythmdb_entry_get_string (entry
, RHYTHMDB_PROP_LOCATION
), "file:///whee.ogg") == 0,
79 "LOCATION set incorrectly");
80 fail_unless (strcmp (rhythmdb_entry_get_string (entry
, RHYTHMDB_PROP_GENRE
), "Rock") == 0,
81 "GENRE set incorrectly");
82 fail_unless (strcmp (rhythmdb_entry_get_string (entry
, RHYTHMDB_PROP_ARTIST
), "Nine Inch Nails") == 0,
83 "ARTIST set incorrectly");
84 fail_unless (strcmp (rhythmdb_entry_get_string (entry
, RHYTHMDB_PROP_ALBUM
), "Broken") == 0,
85 "ALBUM set incorrectly");
86 fail_unless (strcmp (rhythmdb_entry_get_string (entry
, RHYTHMDB_PROP_TITLE
), "Sin") == 0,
87 "TITLE set incorrectly");
89 /* check changing artist */
90 g_value_init (&val
, G_TYPE_STRING
);
91 g_value_set_static_string (&val
, "Evanescence");
92 rhythmdb_entry_set (db
, entry
, RHYTHMDB_PROP_ARTIST
, &val
);
96 fail_unless (strcmp (rhythmdb_entry_get_string (entry
, RHYTHMDB_PROP_LOCATION
), "file:///whee.ogg") == 0,
97 "LOCATION set incorrectly");
98 fail_unless (strcmp (rhythmdb_entry_get_string (entry
, RHYTHMDB_PROP_GENRE
), "Rock") == 0,
99 "GENRE set incorrectly");
100 fail_unless (strcmp (rhythmdb_entry_get_string (entry
, RHYTHMDB_PROP_ARTIST
), "Evanescence") == 0,
101 "ARTIST set incorrectly");
102 fail_unless (strcmp (rhythmdb_entry_get_string (entry
, RHYTHMDB_PROP_ALBUM
), "Broken") == 0,
103 "ALBUM set incorrectly");
104 fail_unless (strcmp (rhythmdb_entry_get_string (entry
, RHYTHMDB_PROP_TITLE
), "Sin") == 0,
105 "TITLE set incorrectly");
108 rhythmdb_entry_delete (db
, entry
);
112 rhythmdb_entry_foreach (db
, (GFunc
)set_true
, &b
);
113 fail_unless (b
== FALSE
, "entry not deleted");
117 START_TEST (test_rhythmdb_multiple
)
119 RhythmDBEntry
*entry1
, *entry2
, *entry3
;
121 /* add multiple entries */
122 entry1
= rhythmdb_entry_new (db
, RHYTHMDB_ENTRY_TYPE_SONG
, "file:///foo.mp3");
123 rhythmdb_commit (db
);
124 fail_unless (entry1
!= NULL
, "failed to create entry");
125 fail_unless (rhythmdb_entry_lookup_by_location (db
, "file:///foo.mp3") == entry1
, "entry missing");
127 entry2
= rhythmdb_entry_new (db
, RHYTHMDB_ENTRY_TYPE_SONG
, "file:///bar.mp3");
128 rhythmdb_commit (db
);
129 fail_unless (entry2
!= NULL
, "failed to create entry");
130 fail_unless (rhythmdb_entry_lookup_by_location (db
, "file:///bar.mp3") == entry2
, "entry missing");
132 entry3
= rhythmdb_entry_new (db
, RHYTHMDB_ENTRY_TYPE_SONG
, "file:///baz.mp3");
133 rhythmdb_commit (db
);
134 fail_unless (entry3
!= NULL
, "failed to create entry");
135 fail_unless (rhythmdb_entry_lookup_by_location (db
, "file:///baz.mp3") == entry3
, "entry missing");
137 /* check they're still there */
138 fail_unless (rhythmdb_entry_lookup_by_location (db
, "file:///foo.mp3") == entry1
, "entry missing");
139 fail_unless (rhythmdb_entry_lookup_by_location (db
, "file:///bar.mp3") == entry2
, "entry missing");
140 fail_unless (rhythmdb_entry_lookup_by_location (db
, "file:///baz.mp3") == entry3
, "entry missing");
142 /* remove the middle one and check again */
143 rhythmdb_entry_delete (db
, entry2
);
144 rhythmdb_commit (db
);
146 fail_unless (rhythmdb_entry_lookup_by_location (db
, "file:///foo.mp3") == entry1
, "entry missing");
147 fail_unless (rhythmdb_entry_lookup_by_location (db
, "file:///bar.mp3") == NULL
, "entry not deleted");
148 fail_unless (rhythmdb_entry_lookup_by_location (db
, "file:///baz.mp3") == entry3
, "entry missing");
151 rhythmdb_entry_delete (db
, entry1
);
152 rhythmdb_entry_delete (db
, entry3
);
153 rhythmdb_commit (db
);
155 fail_unless (rhythmdb_entry_lookup_by_location (db
, "file:///foo.mp3") == NULL
, "entry not deleted");
156 fail_unless (rhythmdb_entry_lookup_by_location (db
, "file:///bar.mp3") == NULL
, "entry not deleted");
157 fail_unless (rhythmdb_entry_lookup_by_location (db
, "file:///baz.mp3") == NULL
, "entry not deleted");
161 START_TEST (test_rhythmdb_mirroring
)
164 RhythmDBEntry
*entry
;
167 entry
= rhythmdb_entry_new (db
, RHYTHMDB_ENTRY_TYPE_SONG
, "file:///foo.mp3");
168 fail_unless (entry
!= NULL
, "failed to create entry");
170 /* check the last-played date is mirrored */
171 g_value_init (&val
, G_TYPE_ULONG
);
172 g_value_set_ulong (&val
, 1354285);
173 rhythmdb_entry_set (db
, entry
, RHYTHMDB_PROP_LAST_PLAYED
, &val
);
174 g_value_unset (&val
);
175 rhythmdb_commit (db
);
177 str
= rhythmdb_entry_get_string (entry
, RHYTHMDB_PROP_LAST_PLAYED_STR
);
178 fail_unless (str
&& (strlen (str
) > 0), "date not converted to string");
180 /* check folded and sort-key varients */
181 g_value_init (&val
, G_TYPE_STRING
);
182 g_value_set_static_string (&val
, "FOO");
183 rhythmdb_entry_set (db
, entry
, RHYTHMDB_PROP_TITLE
, &val
);
184 g_value_unset (&val
);
185 rhythmdb_commit (db
);
187 str
= rhythmdb_entry_get_string (entry
, RHYTHMDB_PROP_TITLE_SORT_KEY
);
188 fail_unless (str
&& (strlen (str
) > 0), "sort-key not generated");
189 str
= rhythmdb_entry_get_string (entry
, RHYTHMDB_PROP_TITLE_FOLDED
);
190 fail_unless (str
&& (strcmp (str
, "foo") == 0), "folded variant not generated");
192 g_value_init (&val
, G_TYPE_STRING
);
193 g_value_set_static_string (&val
, "BAR");
194 rhythmdb_entry_set (db
, entry
, RHYTHMDB_PROP_TITLE
, &val
);
195 g_value_unset (&val
);
196 rhythmdb_commit (db
);
198 str
= rhythmdb_entry_get_string (entry
, RHYTHMDB_PROP_TITLE_SORT_KEY
);
199 fail_unless (str
&& (strlen (str
) > 0), "sort-key not generated");
200 str
= rhythmdb_entry_get_string (entry
, RHYTHMDB_PROP_TITLE_FOLDED
);
201 fail_unless (str
&& (strcmp (str
, "bar") == 0), "folded variant not generated");
207 START_TEST (test_rhythmdb_deserialisation1
)
209 RhythmDBQueryModel
*model
;
212 g_object_set (G_OBJECT (db
), "name", "deserialization-test1.xml", NULL
);
213 set_waiting_signal (G_OBJECT (db
), "load-complete");
217 model
= rhythmdb_query_model_new_empty (db
);
218 g_object_set (G_OBJECT (model
), "show-hidden", TRUE
, NULL
);
219 set_waiting_signal (G_OBJECT (model
), "complete");
220 rhythmdb_do_full_query (db
, RHYTHMDB_QUERY_RESULTS (model
),
222 RHYTHMDB_QUERY_PROP_EQUALS
,
223 RHYTHMDB_PROP_TYPE
, RHYTHMDB_ENTRY_TYPE_SONG
,
226 fail_unless (gtk_tree_model_iter_n_children (GTK_TREE_MODEL (model
), NULL
) == 0, "deserialisation incorrect");
227 g_object_unref (model
);
231 START_TEST (test_rhythmdb_deserialisation2
)
233 RhythmDBQueryModel
*model
;
235 /* single entry db */
236 g_object_set (G_OBJECT (db
), "name", "deserialization-test2.xml", NULL
);
237 set_waiting_signal (G_OBJECT (db
), "load-complete");
241 model
= rhythmdb_query_model_new_empty (db
);
242 g_object_set (G_OBJECT (model
), "show-hidden", TRUE
, NULL
);
243 set_waiting_signal (G_OBJECT (model
), "complete");
244 rhythmdb_do_full_query (db
, RHYTHMDB_QUERY_RESULTS (model
),
245 RHYTHMDB_QUERY_PROP_EQUALS
,
246 RHYTHMDB_PROP_TYPE
, RHYTHMDB_ENTRY_TYPE_SONG
,
249 /* FIXME: this fails for some reason
250 fail_unless (gtk_tree_model_iter_n_children (GTK_TREE_MODEL (model), NULL) == 1, "deserialisation incorrect");*/
251 g_object_unref (model
);
253 /* TODO: check values */
257 START_TEST (test_rhythmdb_deserialisation3
)
259 RhythmDBQueryModel
*model
;
261 /* two entries of different types db */
262 g_object_set (G_OBJECT (db
), "name", "deserialization-test3.xml", NULL
);
263 set_waiting_signal (G_OBJECT (db
), "load-complete");
267 model
= rhythmdb_query_model_new_empty (db
);
268 g_object_set (G_OBJECT (model
), "show-hidden", TRUE
, NULL
);
269 set_waiting_signal (G_OBJECT (model
), "complete");
270 rhythmdb_do_full_query (db
, RHYTHMDB_QUERY_RESULTS (model
),
272 RHYTHMDB_QUERY_PROP_EQUALS
,
273 RHYTHMDB_PROP_TYPE
, RHYTHMDB_ENTRY_TYPE_SONG
,
276 /* FIXME: this fails for some reason
277 fail_unless (gtk_tree_model_iter_n_children (GTK_TREE_MODEL (model), NULL) == 1, "deserialisation incorrect");*/
278 g_object_unref (model
);
280 /* TODO: check values */
286 rhythmdb_suite (void)
288 Suite
*s
= suite_create ("rhythmdb");
289 TCase
*tc_chain
= tcase_create ("rhythmdb-core");
290 TCase
*tc_bugs
= tcase_create ("rhythmdb-bugs");
292 suite_add_tcase (s
, tc_chain
);
293 tcase_add_checked_fixture (tc_chain
, test_rhythmdb_setup
, test_rhythmdb_shutdown
);
294 suite_add_tcase (s
, tc_bugs
);
295 tcase_add_checked_fixture (tc_bugs
, test_rhythmdb_setup
, test_rhythmdb_shutdown
);
297 /* test core functionality */
298 /*tcase_add_test (tc_chain, test_refstring);*/
299 tcase_add_test (tc_chain
, test_rhythmdb_indexing
);
300 tcase_add_test (tc_chain
, test_rhythmdb_multiple
);
301 tcase_add_test (tc_chain
, test_rhythmdb_mirroring
);
302 /*tcase_add_test (tc_chain, test_rhythmdb_signals);*/
303 /*tcase_add_test (tc_chain, test_rhythmdb_query);*/
304 tcase_add_test (tc_chain
, test_rhythmdb_deserialisation1
);
305 tcase_add_test (tc_chain
, test_rhythmdb_deserialisation2
);
306 tcase_add_test (tc_chain
, test_rhythmdb_deserialisation3
);
307 /*tcase_add_test (tc_chain, test_rhythmdb_serialisation);*/
309 /* tests for breakable bug fixes */
315 main (int argc
, char **argv
)
322 rb_profile_start ("rhythmbox test suite");
324 g_thread_init (NULL
);
327 gtk_init (&argc
, &argv
);
329 rb_debug_init (TRUE
);
330 rb_refstring_system_init ();
331 rb_file_helpers_init ();
334 GDK_THREADS_ENTER ();
337 s
= rhythmdb_suite ();
338 sr
= srunner_create (s
);
339 srunner_run_all (sr
, CK_NORMAL
);
340 ret
= srunner_ntests_failed (sr
);
344 rb_file_helpers_shutdown ();
345 rb_refstring_system_shutdown ();
346 gnome_vfs_shutdown ();
348 rb_profile_end ("rhythmbox test suite");