1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
/*
* Copyright (C) 2010 Stefan Kost <ensonic@users.sf.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
#undef G_DISABLE_ASSERT
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <locale.h>
#include <glib.h>
#include <grilo.h>
#define CHECK_MESSAGE(domain, error_message) \
(g_strcmp0 (log_domain, domain) == 0 && strstr (message, error_message))
static gboolean
registry_load_error_handler (const gchar *log_domain,
GLogLevelFlags log_level,
const gchar *message,
gpointer user_data)
{
if (CHECK_MESSAGE ("Grilo", "Failed to initialize plugin") ||
CHECK_MESSAGE ("Grilo", "Configuration not provided") ||
CHECK_MESSAGE ("Grilo", "Missing configuration") ||
CHECK_MESSAGE ("Grilo", "Could not open plugin directory") ||
CHECK_MESSAGE ("Grilo", "Error opening directory") ||
CHECK_MESSAGE ("Grilo", "Could not read XML file")) {
return FALSE;
}
return TRUE;
}
typedef struct {
GrlRegistry *registry;
GMainLoop *loop;
} RegistryFixture;
static void
registry_fixture_setup (RegistryFixture *fixture, gconstpointer data)
{
g_test_log_set_fatal_handler (registry_load_error_handler, NULL);
fixture->registry = grl_registry_get_default ();
fixture->loop = g_main_loop_new (NULL, TRUE);
}
static void
registry_fixture_teardown (RegistryFixture *fixture, gconstpointer data)
{
g_main_loop_unref(fixture->loop);
}
static void
registry_init (void)
{
GrlRegistry *registry;
registry = grl_registry_get_default ();
g_assert (registry);
}
static void
registry_load (RegistryFixture *fixture, gconstpointer data)
{
gboolean res;
GError *err = NULL;
res = grl_registry_load_all_plugins (fixture->registry, TRUE, &err);
if (!res) {
g_assert_error (err, GRL_CORE_ERROR, GRL_CORE_ERROR_LOAD_PLUGIN_FAILED);
g_test_skip ("No sources loaded, skipping test");
}
}
static void
registry_unregister (RegistryFixture *fixture, gconstpointer data)
{
GList *sources = NULL;
GList *sources_iter;
int i;
g_test_bug ("627207");
sources = grl_registry_get_sources (fixture->registry, FALSE);
if (sources == NULL) {
g_test_skip ("No sources loaded, skipping test");
return;
}
for (sources_iter = sources, i = 0; sources_iter;
sources_iter = g_list_next (sources_iter), i++) {
GrlSource *source = GRL_SOURCE (sources_iter->data);
grl_registry_unregister_source (fixture->registry, source, NULL);
}
g_list_free (sources);
/* We expect to have loaded sources */
g_assert_cmpint (i, !=, 0);
sources = grl_registry_get_sources (fixture->registry, FALSE);
for (sources_iter = sources, i = 0; sources_iter;
sources_iter = g_list_next (sources_iter), i++)
;
g_list_free (sources);
/* After unregistering the sources, we don't expect any */
g_assert_cmpint (i, ==, 0);
}
int
main (int argc, char **argv)
{
setlocale (LC_ALL, "");
g_test_init (&argc, &argv, NULL);
g_test_bug_base ("http://bugs.gnome.org/%s");
grl_init (&argc, &argv);
/* registry tests */
g_test_add_func ("/registry/init", registry_init);
g_test_add ("/registry/load",
RegistryFixture, NULL,
registry_fixture_setup,
registry_load,
registry_fixture_teardown);
g_test_add ("/registry/unregister",
RegistryFixture, NULL,
registry_fixture_setup,
registry_unregister,
registry_fixture_teardown);
return g_test_run ();
}
|