2 * arch-tag: 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-tree.h"
28 #include "rb-thread-helpers.h"
30 static RhythmDBEntry
*
31 create_entry (RhythmDB
*db
, const char *name
, const char *album
,
32 const char *artist
, const char *genre
)
37 entry
= rhythmdb_entry_new (db
, RHYTHMDB_ENTRY_TYPE_SONG
, "file:///yay.ogg");
39 g_value_init (&val
, G_TYPE_STRING
);
40 g_value_set_static_string (&val
, genre
);
41 rhythmdb_entry_set (db
, entry
, RHYTHMDB_PROP_GENRE
, &val
);
44 g_value_init (&val
, G_TYPE_STRING
);
45 g_value_set_static_string (&val
, artist
);
46 rhythmdb_entry_set (db
, entry
, RHYTHMDB_PROP_ARTIST
, &val
);
49 g_value_init (&val
, G_TYPE_STRING
);
50 g_value_set_static_string (&val
, album
);
51 rhythmdb_entry_set (db
, entry
, RHYTHMDB_PROP_ALBUM
, &val
);
54 g_value_init (&val
, G_TYPE_STRING
);
55 g_value_set_static_string (&val
, name
);
56 rhythmdb_entry_set (db
, entry
, RHYTHMDB_PROP_TITLE
, &val
);
63 assert_xml_file_has_entry (const char *entry
)
66 xmlNodePtr root
, child
;
68 doc
= xmlParseFile ("test.xml");
69 g_assert (doc
!= NULL
);
71 root
= xmlDocGetRootElement (doc
);
73 child
= root
->children
;
74 for (; child
!= NULL
; child
= child
->next
) {
77 if (child
->type
!= XML_ELEMENT_NODE
)
80 for (sub_child
= child
->children
; sub_child
; sub_child
= sub_child
->next
) {
81 if (sub_child
->type
!= XML_ELEMENT_NODE
)
84 if (!strcmp (sub_child
->name
, "title")) {
85 if (!strcmp (sub_child
->children
->content
,
92 g_assert_not_reached ();
99 main (int argc
, char **argv
)
102 RhythmDBEntry
*entry
;
105 gtk_init (&argc
, &argv
);
106 g_thread_init (NULL
);
108 rb_thread_helpers_init ();
109 rb_debug_init (TRUE
);
111 GDK_THREADS_ENTER ();
113 db
= rhythmdb_tree_new ("test.xml");
116 * TEST 1: Save with no entries
118 g_print ("Test 1\n");
119 rhythmdb_read_lock (db
);
123 doc
= xmlParseFile ("test.xml");
124 g_assert (doc
!= NULL
);
127 rhythmdb_read_unlock (db
);
128 g_print ("Test 1: PASS\n");
131 * TEST 2: Save with a single entry
133 g_print ("Test 1\n");
134 rhythmdb_write_lock (db
);
136 entry
= create_entry (db
, "Sin", "Pretty Hate Machine", "Nine Inch Nails", "Rock");
140 assert_xml_file_has_entry ("Sin");
142 rhythmdb_write_unlock (db
);
147 rhythmdb_shutdown (db
);
148 g_object_unref (G_OBJECT (db
));
149 GDK_THREADS_LEAVE ();