~snaggen/rhythmbox/bpm

« back to all changes in this revision

Viewing changes to tests/test-rhythmdb-tree-deserialization.c

  • Committer: James Livingston
  • Author(s): James Livingston
  • Date: 2006-06-02 13:46:16 UTC
  • Revision ID: git-v1:3a79c0fb2234303984ff8bf896d7067dca65f740
+ macros/check.m4: add support for using check for unit tests, the .m4

2006-06-02  James Livingston  <doclivingston@gmail.com>

        * configure.ac:
        + macros/check.m4: add support for using check for unit tests, the .m4
        files is so autogen can run without check being installed

        * tests/Makefile.am:
        + tests/test-rhythmdb.c: update the tests to new rhythmdb API, port
        some of the old tests, and add some new ones. Currently
        deserialisation tests 2 and 3 fail, for reasons I haven't figured out
        yet (the query doesn't return any entries).

        - tests/deserialization-test1.xml:
        - tests/deserialization-test2.xml:
        - tests/deserialization-test3.xml:
        - tests/test-rhythmdb-indexing.c:
        - tests/test-rhythmdb-simple.c:
        - tests/test-rhythmdb-tree-deserialization.c: remove old tests that
        have been ported

        - tests/test-cd.c:
        - tests/test-cmdline.c: remove obsolete tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* 
2
 
 *  arch-tag: De-serialization tests for the RhythmDB tree database
3
 
 *
4
 
 *  Copyright (C) 2003 Colin Walters <walters@verbum.org>
5
 
 *
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.
10
 
 *
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.
15
 
 *
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.
19
 
 */
20
 
 
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"
30
 
 
31
 
static void
32
 
completed_cb (RhythmDBQueryModel *model, gboolean *complete)
33
 
{
34
 
        rb_debug ("query complete");
35
 
        *complete = TRUE;
36
 
}
37
 
 
38
 
static void
39
 
wait_for_model_completion (RhythmDBQueryModel *model)
40
 
{
41
 
        gboolean complete = FALSE;
42
 
        GTimeVal timeout;
43
 
        g_signal_connect (G_OBJECT (model), "complete",
44
 
                          G_CALLBACK (completed_cb), &complete);
45
 
 
46
 
        while (!complete) {
47
 
                g_get_current_time (&timeout);
48
 
                g_time_val_add (&timeout, G_USEC_PER_SEC);
49
 
 
50
 
                rb_debug ("polling model for changes");
51
 
                rhythmdb_query_model_sync (model, &timeout);
52
 
        }
53
 
}
54
 
 
55
 
int
56
 
main (int argc, char **argv)
57
 
{
58
 
        RhythmDB *db;
59
 
        GtkTreeModel *main_model;
60
 
        GtkTreeIter iter;
61
 
 
62
 
        gtk_init (&argc, &argv);
63
 
        g_thread_init (NULL);
64
 
        gdk_threads_init ();
65
 
        rb_thread_helpers_init ();
66
 
        rb_debug_init (TRUE);
67
 
 
68
 
        GDK_THREADS_ENTER ();
69
 
 
70
 
        /**
71
 
         *  TEST 1: Load with no entries
72
 
         */
73
 
        g_print ("Test 1\n");
74
 
 
75
 
        db = rhythmdb_tree_new ("deserialization-test1.xml");
76
 
 
77
 
        rhythmdb_load (db);
78
 
        rhythmdb_load_join (db);
79
 
 
80
 
        rhythmdb_read_lock (db);
81
 
 
82
 
 
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));
90
 
 
91
 
        rhythmdb_read_unlock (db);
92
 
 
93
 
        g_object_unref (G_OBJECT (main_model));
94
 
        rhythmdb_shutdown (db);
95
 
        g_object_unref (G_OBJECT (db));
96
 
 
97
 
        g_print ("Test 1: PASS\n");
98
 
 
99
 
        /**
100
 
         *  TEST 2: Load with 1 entry
101
 
         */
102
 
        g_print ("Test 2\n");
103
 
 
104
 
        db = rhythmdb_tree_new ("deserialization-test2.xml");
105
 
 
106
 
        rhythmdb_load (db);
107
 
        rhythmdb_load_join (db);
108
 
 
109
 
        rhythmdb_read_lock (db);
110
 
 
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));
120
 
 
121
 
        g_object_unref (G_OBJECT (main_model));
122
 
        rhythmdb_shutdown (db);
123
 
        g_object_unref (G_OBJECT (db));
124
 
 
125
 
        g_print ("Test 2: PASS\n");
126
 
 
127
 
        /**
128
 
         *  TEST 3: Load with 2 entres, of different types
129
 
         */
130
 
        g_print ("Test 3\n");
131
 
 
132
 
        db = rhythmdb_tree_new ("deserialization-test3.xml");
133
 
 
134
 
        rhythmdb_load (db);
135
 
 
136
 
        rhythmdb_shutdown (db);
137
 
        g_object_unref (G_OBJECT (db));
138
 
 
139
 
        g_print ("Test 3: PASS\n");
140
 
 
141
 
 
142
 
        /**
143
 
         * THE END
144
 
         */
145
 
        GDK_THREADS_LEAVE ();
146
 
        
147
 
        exit (0);
148
 
}