2006-01-11 Francisco Javier F. Serrador <serrador@cvs.gnome.org>
[rhythmbox.git] / tests / test-rhythmdb-indexing.c
blobc44d95eeeab6bb7bd7c94c1427c133f91f93e2b7
1 /*
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include "config.h"
22 #include <glib.h>
23 #include <gtk/gtk.h>
24 #include <libgnome/gnome-i18n.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include "rhythmdb-tree.h"
28 #include "rb-debug.h"
29 #include "rb-thread-helpers.h"
31 static void
32 verify_entry_metadata (RhythmDB *db, RhythmDBEntry *entry,
33 const char *name, const char *album,
34 const char *artist, const char *genre)
36 GValue val = {0, };
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)));
41 g_value_unset (&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)));
46 g_value_unset (&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)));
51 g_value_unset (&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)));
56 g_value_unset (&val);
59 int
60 main (int argc, char **argv)
62 RhythmDB *db;
63 RhythmDBEntry *entry;
64 GValue val = {0, };
66 gtk_init (&argc, &argv);
67 g_thread_init (NULL);
68 gdk_threads_init ();
69 rb_thread_helpers_init ();
70 rb_debug_init (TRUE);
72 #ifdef ENABLE_NLS
73 /* initialize i18n */
74 bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
75 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
76 textdomain (GETTEXT_PACKAGE);
77 #endif
79 GDK_THREADS_ENTER ();
81 db = rhythmdb_tree_new ("test");
83 /**
84 * TEST 1: Entry creation with album
86 g_print ("Test 1\n");
87 rhythmdb_write_lock (db);
89 entry = rhythmdb_entry_new (db, RHYTHMDB_ENTRY_TYPE_SONG, "file:///whee.ogg");
90 g_assert (entry);
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);
94 g_value_unset (&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);
99 g_value_unset (&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");
187 * THE END
189 rhythmdb_shutdown (db);
190 g_object_unref (G_OBJECT (db));
191 GDK_THREADS_LEAVE ();
193 exit (0);