2006-05-16 James Livingston <doclivingston@gmail.com>
[rhythmbox.git] / tests / test-rhythmdb-tree-deserialization.c
blobb0d6904e442e2759da15d930277a3080b18e503f
1 /*
2 * arch-tag: De-serialization 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.
21 #include <glib.h>
22 #include <gtk/gtk.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <libxml/tree.h>
26 #include "rhythmdb-query-model.h"
27 #include "rhythmdb-tree.h"
28 #include "rb-debug.h"
29 #include "rb-thread-helpers.h"
31 static void
32 completed_cb (RhythmDBQueryModel *model, gboolean *complete)
34 rb_debug ("query complete");
35 *complete = TRUE;
38 static void
39 wait_for_model_completion (RhythmDBQueryModel *model)
41 gboolean complete = FALSE;
42 GTimeVal timeout;
43 g_signal_connect (G_OBJECT (model), "complete",
44 G_CALLBACK (completed_cb), &complete);
46 while (!complete) {
47 g_get_current_time (&timeout);
48 g_time_val_add (&timeout, G_USEC_PER_SEC);
50 rb_debug ("polling model for changes");
51 rhythmdb_query_model_sync (model, &timeout);
55 int
56 main (int argc, char **argv)
58 RhythmDB *db;
59 GtkTreeModel *main_model;
60 GtkTreeIter iter;
62 gtk_init (&argc, &argv);
63 g_thread_init (NULL);
64 gdk_threads_init ();
65 rb_thread_helpers_init ();
66 rb_debug_init (TRUE);
68 GDK_THREADS_ENTER ();
70 /**
71 * TEST 1: Load with no entries
73 g_print ("Test 1\n");
75 db = rhythmdb_tree_new ("deserialization-test1.xml");
77 rhythmdb_load (db);
78 rhythmdb_load_join (db);
80 rhythmdb_read_lock (db);
83 main_model = GTK_TREE_MODEL (rhythmdb_query_model_new_empty (db));
84 rhythmdb_do_full_query (db, main_model,
85 RHYTHMDB_QUERY_PROP_EQUALS,
86 RHYTHMDB_PROP_TYPE, RHYTHMDB_ENTRY_TYPE_SONG,
87 RHYTHMDB_QUERY_END);
88 wait_for_model_completion (RHYTHMDB_QUERY_MODEL (main_model));
89 g_assert (!gtk_tree_model_get_iter_first (main_model, &iter));
91 rhythmdb_read_unlock (db);
93 g_object_unref (G_OBJECT (main_model));
94 rhythmdb_shutdown (db);
95 g_object_unref (G_OBJECT (db));
97 g_print ("Test 1: PASS\n");
99 /**
100 * TEST 2: Load with 1 entry
102 g_print ("Test 2\n");
104 db = rhythmdb_tree_new ("deserialization-test2.xml");
106 rhythmdb_load (db);
107 rhythmdb_load_join (db);
109 rhythmdb_read_lock (db);
111 main_model = GTK_TREE_MODEL (rhythmdb_query_model_new_empty (db));
112 rhythmdb_do_full_query (db, main_model,
113 RHYTHMDB_QUERY_PROP_EQUALS,
114 RHYTHMDB_PROP_TYPE, RHYTHMDB_ENTRY_TYPE_SONG,
115 RHYTHMDB_QUERY_END);
116 wait_for_model_completion (RHYTHMDB_QUERY_MODEL (main_model));
117 g_assert (gtk_tree_model_get_iter_first (main_model, &iter));
118 /* We should only have one entry. */
119 g_assert (!gtk_tree_model_iter_next (main_model, &iter));
121 g_object_unref (G_OBJECT (main_model));
122 rhythmdb_shutdown (db);
123 g_object_unref (G_OBJECT (db));
125 g_print ("Test 2: PASS\n");
128 * TEST 3: Load with 2 entres, of different types
130 g_print ("Test 3\n");
132 db = rhythmdb_tree_new ("deserialization-test3.xml");
134 rhythmdb_load (db);
136 rhythmdb_shutdown (db);
137 g_object_unref (G_OBJECT (db));
139 g_print ("Test 3: PASS\n");
143 * THE END
145 GDK_THREADS_LEAVE ();
147 exit (0);