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.
25
#include <libxml/tree.h>
26
#include "rhythmdb-query-model.h"
27
#include "rhythmdb-tree.h"
29
#include "rb-thread-helpers.h"
32
completed_cb (RhythmDBQueryModel *model, gboolean *complete)
34
rb_debug ("query complete");
39
wait_for_model_completion (RhythmDBQueryModel *model)
41
gboolean complete = FALSE;
43
g_signal_connect (G_OBJECT (model), "complete",
44
G_CALLBACK (completed_cb), &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);
56
main (int argc, char **argv)
59
GtkTreeModel *main_model;
62
gtk_init (&argc, &argv);
65
rb_thread_helpers_init ();
71
* TEST 1: Load with no entries
75
db = rhythmdb_tree_new ("deserialization-test1.xml");
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,
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");
100
* TEST 2: Load with 1 entry
102
g_print ("Test 2\n");
104
db = rhythmdb_tree_new ("deserialization-test2.xml");
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,
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");
136
rhythmdb_shutdown (db);
137
g_object_unref (G_OBJECT (db));
139
g_print ("Test 3: PASS\n");
145
GDK_THREADS_LEAVE ();