2 * arch-tag: Indexing (genre/artist/album) tests for the RhythmDB tree database
4 * Copyright (C) 2003 Colin Walters <walters@verbum.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include <libgnome/gnome-i18n.h>
27 #include "rhythmdb-tree.h"
29 #include "rb-thread-helpers.h"
32 verify_entry_metadata (RhythmDB
*db
, RhythmDBEntry
*entry
,
33 const char *name
, const char *album
,
34 const char *artist
, const char *genre
)
38 g_value_init (&val
, G_TYPE_STRING
);
39 rhythmdb_entry_get (db
, entry
, RHYTHMDB_PROP_TITLE
, &val
);
40 g_assert (!strcmp (name
, g_value_get_string (&val
)));
43 g_value_init (&val
, G_TYPE_STRING
);
44 rhythmdb_entry_get (db
, entry
, RHYTHMDB_PROP_ALBUM
, &val
);
45 g_assert (!strcmp (album
, g_value_get_string (&val
)));
48 g_value_init (&val
, G_TYPE_STRING
);
49 rhythmdb_entry_get (db
, entry
, RHYTHMDB_PROP_ARTIST
, &val
);
50 g_assert (!strcmp (artist
, g_value_get_string (&val
)));
53 g_value_init (&val
, G_TYPE_STRING
);
54 rhythmdb_entry_get (db
, entry
, RHYTHMDB_PROP_GENRE
, &val
);
55 g_assert (!strcmp (genre
, g_value_get_string (&val
)));
60 main (int argc
, char **argv
)
66 gtk_init (&argc
, &argv
);
69 rb_thread_helpers_init ();
74 bindtextdomain (GETTEXT_PACKAGE
, GNOMELOCALEDIR
);
75 bind_textdomain_codeset (GETTEXT_PACKAGE
, "UTF-8");
76 textdomain (GETTEXT_PACKAGE
);
81 db
= rhythmdb_tree_new ("test");
84 * TEST 1: Entry creation with album
87 rhythmdb_write_lock (db
);
89 entry
= rhythmdb_entry_new (db
, RHYTHMDB_ENTRY_TYPE_SONG
, "file:///whee.ogg");
91 g_value_init (&val
, G_TYPE_STRING
);
92 g_value_set_static_string (&val
, "Rock");
93 rhythmdb_entry_set (db
, entry
, RHYTHMDB_PROP_GENRE
, &val
);
96 g_value_init (&val
, G_TYPE_STRING
);
97 g_value_set_static_string (&val
, "Nine Inch Nails");
98 rhythmdb_entry_set (db
, entry
, RHYTHMDB_PROP_ARTIST
, &val
);
101 g_value_init (&val
, G_TYPE_STRING
);
102 g_value_set_static_string (&val
, "Pretty Hate Machine");
103 rhythmdb_entry_set (db
, entry
, RHYTHMDB_PROP_ALBUM
, &val
);
104 g_value_unset (&val
);
106 g_value_init (&val
, G_TYPE_STRING
);
107 g_value_set_static_string (&val
, "Sin");
108 rhythmdb_entry_set (db
, entry
, RHYTHMDB_PROP_TITLE
, &val
);
109 g_value_unset (&val
);
111 rhythmdb_write_unlock (db
);
112 g_print ("Test 1: PASS\n");
116 * TEST 2: Read back indexed values
118 g_print ("Test 2\n");
119 rhythmdb_read_lock (db
);
121 verify_entry_metadata (db
, entry
, "Sin", "Pretty Hate Machine",
122 "Nine Inch Nails", "Rock");
124 rhythmdb_read_unlock (db
);
125 g_print ("Test 2: PASS\n");
128 * TEST 3: Changing album
130 g_print ("Test 3\n");
131 rhythmdb_write_lock (db
);
133 g_value_init (&val
, G_TYPE_STRING
);
134 g_value_set_static_string (&val
, "Broken");
135 rhythmdb_entry_set (db
, entry
, RHYTHMDB_PROP_ALBUM
, &val
);
136 g_value_unset (&val
);
137 rhythmdb_write_unlock (db
);
139 rhythmdb_read_lock (db
);
140 verify_entry_metadata (db
, entry
, "Sin", "Broken",
141 "Nine Inch Nails", "Rock");
142 rhythmdb_read_unlock (db
);
144 g_print ("Test 3: PASS\n");
147 * TEST 4: Changing artist
149 g_print ("Test 4\n");
150 rhythmdb_write_lock (db
);
152 g_value_init (&val
, G_TYPE_STRING
);
153 g_value_set_static_string (&val
, "Evanescence");
154 rhythmdb_entry_set (db
, entry
, RHYTHMDB_PROP_ARTIST
, &val
);
155 g_value_unset (&val
);
157 rhythmdb_write_unlock (db
);
159 rhythmdb_read_lock (db
);
160 verify_entry_metadata (db
, entry
, "Sin", "Broken",
161 "Evanescence", "Rock");
162 rhythmdb_read_unlock (db
);
164 g_print ("Test 4: PASS\n");
167 * TEST 5: Changing genre
169 g_print ("Test 5\n");
170 rhythmdb_write_lock (db
);
172 g_value_init (&val
, G_TYPE_STRING
);
173 g_value_set_static_string (&val
, "Techno");
174 rhythmdb_entry_set (db
, entry
, RHYTHMDB_PROP_GENRE
, &val
);
175 g_value_unset (&val
);
177 rhythmdb_write_unlock (db
);
179 rhythmdb_read_lock (db
);
180 verify_entry_metadata (db
, entry
, "Sin", "Broken",
181 "Evanescence", "Techno");
182 rhythmdb_read_unlock (db
);
184 g_print ("Test 5: PASS\n");
189 rhythmdb_shutdown (db
);
190 g_object_unref (G_OBJECT (db
));
191 GDK_THREADS_LEAVE ();