udapted vi.po
[rhythmbox.git] / tests / test-rhythmdb-tree-serialization.c
blob717673fb592817a653e62577453a411f61059cac
1 /*
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.
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-tree.h"
27 #include "rb-debug.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)
34 RhythmDBEntry *entry;
35 GValue val = {0, };
37 entry = rhythmdb_entry_new (db, RHYTHMDB_ENTRY_TYPE_SONG, "file:///yay.ogg");
38 g_assert (entry);
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);
42 g_value_unset (&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);
47 g_value_unset (&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);
52 g_value_unset (&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);
57 g_value_unset (&val);
59 return entry;
62 static void
63 assert_xml_file_has_entry (const char *entry)
65 xmlDocPtr doc;
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) {
75 xmlNodePtr sub_child;
77 if (child->type != XML_ELEMENT_NODE)
78 continue;
80 for (sub_child = child->children; sub_child; sub_child = sub_child->next) {
81 if (sub_child->type != XML_ELEMENT_NODE)
82 continue;
84 if (!strcmp (sub_child->name, "title")) {
85 if (!strcmp (sub_child->children->content,
86 entry))
87 goto out;
92 g_assert_not_reached ();
93 out:
94 xmlFreeDoc (doc);
98 int
99 main (int argc, char **argv)
101 RhythmDB *db;
102 RhythmDBEntry *entry;
103 xmlDocPtr doc;
105 gtk_init (&argc, &argv);
106 g_thread_init (NULL);
107 gdk_threads_init ();
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);
121 rhythmdb_save (db);
123 doc = xmlParseFile ("test.xml");
124 g_assert (doc != NULL);
125 xmlFreeDoc (doc);
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");
138 rhythmdb_save (db);
140 assert_xml_file_has_entry ("Sin");
142 rhythmdb_write_unlock (db);
145 * THE END
147 rhythmdb_shutdown (db);
148 g_object_unref (G_OBJECT (db));
149 GDK_THREADS_LEAVE ();
151 exit (0);