[PATCH 6/7] core: Moved tests infrastructure to /tests



---
 Makefile.am                          |    2 +-
 configure.ac                         |    5 +-
 src/Makefile.am                      |    2 -
 src/tests/.gitignore                 |    1 -
 src/tests/Makefile.am                |   74 ----------------
 src/tests/constants.py               |   50 -----------
 src/tests/registry.c                 |  150 --------------------------------
 src/tests/test_metadata_source.py    |   99 ---------------------
 src/tests/test_plugin.py             |   77 ----------------
 src/tests/test_registry.py           |  158 ----------------------------------
 src/tests/testrunner.py              |   27 ------
 src/tests/util.py.in                 |    9 --
 tests/Makefile.am                    |   60 +++++++++++++
 tests/python/Makefile.am             |   16 ++++
 tests/python/constants.py            |   50 +++++++++++
 tests/python/test_metadata_source.py |   99 +++++++++++++++++++++
 tests/python/test_plugin.py          |   77 ++++++++++++++++
 tests/python/test_registry.py        |  158 ++++++++++++++++++++++++++++++++++
 tests/python/testrunner.py           |   27 ++++++
 tests/python/util.py.in              |    9 ++
 tests/registry.c                     |  149 ++++++++++++++++++++++++++++++++
 21 files changed, 649 insertions(+), 650 deletions(-)
 delete mode 100644 src/tests/.gitignore
 delete mode 100644 src/tests/Makefile.am
 delete mode 100644 src/tests/constants.py
 delete mode 100644 src/tests/registry.c
 delete mode 100644 src/tests/test_metadata_source.py
 delete mode 100644 src/tests/test_plugin.py
 delete mode 100644 src/tests/test_registry.py
 delete mode 100755 src/tests/testrunner.py
 delete mode 100644 src/tests/util.py.in
 create mode 100644 tests/Makefile.am
 create mode 100644 tests/python/Makefile.am
 create mode 100644 tests/python/constants.py
 create mode 100644 tests/python/test_metadata_source.py
 create mode 100644 tests/python/test_plugin.py
 create mode 100644 tests/python/test_registry.py
 create mode 100755 tests/python/testrunner.py
 create mode 100644 tests/python/util.py.in
 create mode 100644 tests/registry.c

diff --git a/Makefile.am b/Makefile.am
index 5cfd858..8ce9435 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -7,7 +7,7 @@
 
 ACLOCAL_AMFLAGS = -I m4
 
-SUBDIRS = src bindings tools
+SUBDIRS = src bindings tools tests
 
 if ENABLE_GTK_DOC
 SUBDIRS += doc
diff --git a/configure.ac b/configure.ac
index 7878f37..0dfa6f7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -200,8 +200,9 @@ AC_CONFIG_FILES([
   grilo-uninstalled.pc
   grilo-0.1.pc
   src/Makefile
-  src/tests/Makefile
-  src/tests/util.py
+  tests/Makefile
+  tests/python/Makefile
+  tests/python/util.py
   tools/Makefile
   tools/grilo-test-ui/Makefile
   tools/grilo-inspect/Makefile
diff --git a/src/Makefile.am b/src/Makefile.am
index 1708025..51442c8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -7,8 +7,6 @@
 
 INCLUDES = -DGRL_PLUGINS_CONF_DIR=\""$(GRL_PLUGINS_CONF_DIR)"\"
 
-SUBDIRS = . tests
-
 lib_LTLIBRARIES = lib GRL_NAME@.la
 
 lib GRL_NAME@_la_CFLAGS =	\
diff --git a/src/tests/.gitignore b/src/tests/.gitignore
deleted file mode 100644
index 14bc599..0000000
--- a/src/tests/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-registry
diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am
deleted file mode 100644
index e3c0be7..0000000
--- a/src/tests/Makefile.am
+++ /dev/null
@@ -1,74 +0,0 @@
-# things to test
-
-noinst_PROGRAMS = $(TEST_PROGS)
-
-AM_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/src/data $(DEPS_CFLAGS)
-progs_ldadd = $(top_builddir)/src/lib GRL_NAME@.la $(DEPS_LIBS)
-
-TEST_PROGS       = registry
-registry_SOURCES = registry.c
-registry_LDADD = $(progs_ldadd)
-
-### testing rules (from glib)
-
-GTESTER = gtester
-
-# test: run all tests in cwd and subdirs
-c_test:	${TEST_PROGS}
-	@test -z "${TEST_PROGS}" || ${GTESTER} --verbose ${TEST_PROGS}
-	@ for subdir in $(SUBDIRS) . ; do \
-	    test "$$subdir" = "." -o "$$subdir" = "po" || \
-	    ( cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $@ ) || exit $? ; \
-	  done
-
-python_test: testrunner.py
-if HAVE_INTROSPECTION
-	PYTHONPATH=$(top_builddir):$(top_builddir)/src/tests$${PYTHONPATH:+:$$PYTHONPATH} $(PYTHON) $(srcdir)/testrunner.py
-endif
-
-if HAVE_INTROSPECTION
-EXTRA_DIST = \
-	runtests.py \
-	test_registry.py
-endif
-
-# test-report: run tests in subdirs and generate report
-# perf-report: run tests in subdirs with -m perf and generate report
-# full-report: like test-report: with -m perf and -m slow
-test-report perf-report full-report:	${TEST_PROGS}
-	@test -z "${TEST_PROGS}" || { \
-	  case $@ in \
-	  test-report) test_options="-k";; \
-	  perf-report) test_options="-k -m=perf";; \
-	  full-report) test_options="-k -m=perf -m=slow";; \
-	  esac ; \
-	  if test -z "$$GTESTER_LOGDIR" ; then	\
-	    ${GTESTER} --verbose $$test_options -o test-report.xml ${TEST_PROGS} ; \
-	  elif test -n "${TEST_PROGS}" ; then \
-	    ${GTESTER} --verbose $$test_options -o `mktemp "$$GTESTER_LOGDIR/log-XXXXXX"` ${TEST_PROGS} ; \
-	  fi ; \
-	}
-	@ ignore_logdir=true ; \
-	  if test -z "$$GTESTER_LOGDIR" ; then \
-	    GTESTER_LOGDIR=`mktemp -d "\`pwd\`/.testlogs-XXXXXX"`; export GTESTER_LOGDIR ; \
-	    ignore_logdir=false ; \
-	  fi ; \
-	  for subdir in $(SUBDIRS) . ; do \
-	    test "$$subdir" = "." -o "$$subdir" = "po" || \
-	    ( cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $@ ) || exit $? ; \
-	  done ; \
-	  $$ignore_logdir || { \
-	    echo '<?xml version="1.0"?>' > $  xml ; \
-	    echo '<report-collection>'  >> $  xml ; \
-	    for lf in `ls -L "$$GTESTER_LOGDIR"/.` ; do \
-	      sed '1,1s/^<?xml\b[^>?]*?>//' <"$$GTESTER_LOGDIR"/"$$lf" >> $  xml ; \
-	    done ; \
-	    echo >> $  xml ; \
-	    echo '</report-collection>' >> $  xml ; \
-	    rm -rf "$$GTESTER_LOGDIR"/ ; \
-	    ${GTESTER_REPORT} --version 2>/dev/null 1>&2 ; test "$$?" != 0 || ${GTESTER_REPORT} $  xml >$  html ; \
-	  }
-.PHONY: test test-report perf-report full-report
-# run make test as part of make check
-check-local: c_test python_test
-
diff --git a/src/tests/constants.py b/src/tests/constants.py
deleted file mode 100644
index e8e2690..0000000
--- a/src/tests/constants.py
+++ /dev/null
@@ -1,50 +0,0 @@
-KEY_NONEXISTING = 'nonexisting-key'
-KEY_ALBUM = 'album'
-KEY_ARTIST = 'artist'
-KEY_AUTHOR = 'author'
-KEY_BITRATE = 'bitrate'
-KEY_CERTIFICATE = 'certificate'
-KEY_CHILDCOUNT = 'childcount'
-KEY_DATE = 'date'
-KEY_DESCRIPTION = 'description'
-KEY_DURATION = 'duration'
-KEY_EXTERNAL_PLAYER = 'external-player'
-KEY_EXTERNAL_URL = 'external-url'
-KEY_FRAMERATE = 'framerate'
-KEY_GENRE = 'genre'
-KEY_HEIGHT = 'height'
-KEY_ID = 'id'
-KEY_LAST_PLAYED = 'last-played'
-KEY_LAST_POSITION = 'last-position'
-KEY_LICENSE = 'license'
-KEY_LYRICS = 'lyrics'
-KEY_MIME = 'mime'
-KEY_PLAY_COUNT = 'play-count'
-KEY_RATING = 'rating'
-KEY_SITE = 'site'
-KEY_SOURCE = 'source'
-KEY_STUDIO = 'studio'
-KEY_THUMBNAIL = 'thumbnail'
-KEY_TITLE = 'title'
-KEY_URL = 'url'
-KEY_WIDTH = 'width'
-
-REGISTERED_KEYS = [KEY_ALBUM, KEY_ARTIST, KEY_AUTHOR, KEY_BITRATE,
-                   KEY_CERTIFICATE, KEY_CHILDCOUNT, KEY_DATE,
-                   KEY_DESCRIPTION, KEY_DURATION, KEY_EXTERNAL_PLAYER,
-                   KEY_EXTERNAL_URL, KEY_FRAMERATE, KEY_GENRE, KEY_HEIGHT,
-                   KEY_ID, KEY_LAST_PLAYED, KEY_LAST_POSITION, KEY_LICENSE,
-                   KEY_LYRICS, KEY_MIME, KEY_PLAY_COUNT, KEY_RATING,
-                   KEY_SITE, KEY_SOURCE, KEY_STUDIO, KEY_THUMBNAIL,
-                   KEY_TITLE, KEY_URL, KEY_WIDTH]
-
-SUPPORTED_OPS = []
-try:
-    from gi.repository import Grl
-    SUPPORTED_OPS = [Grl.SupportedOps.NONE, Grl.SupportedOps.METADATA,
-                     Grl.SupportedOps.RESOLVE, Grl.SupportedOps.BROWSE,
-                     Grl.SupportedOps.SEARCH, Grl.SupportedOps.QUERY,
-                     Grl.SupportedOps.STORE, Grl.SupportedOps.STORE_PARENT,
-                     Grl.SupportedOps.REMOVE, Grl.SupportedOps.SET_METADATA]
-except:
-    pass
diff --git a/src/tests/registry.c b/src/tests/registry.c
deleted file mode 100644
index 0306cde..0000000
--- a/src/tests/registry.c
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- * 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 <glib.h>
-
-#include <grilo.h>
-
-#define CHECK_MESSAGE(domain, error_message) \
-  (g_strcmp0 (log_domain, domain) == 0 && strstr (message, error_message))
-
-#if GLIB_CHECK_VERSION(2,22,0)
-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", "Could not read XML file")) {
-    return FALSE;
-  }
-
-  return TRUE;
-}
-#endif
-
-typedef struct {
-  GrlPluginRegistry *registry;
-  GMainLoop *loop;
-} RegistryFixture;
-
-static void
-registry_fixture_setup (RegistryFixture *fixture, gconstpointer data)
-{
-#if GLIB_CHECK_VERSION(2,22,0)
-  g_test_log_set_fatal_handler (registry_load_error_handler, NULL);
-#endif
-
-  fixture->registry = grl_plugin_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)
-{
-  GrlPluginRegistry *registry;
-
-  registry = grl_plugin_registry_get_default ();
-  g_assert (registry);
-}
-
-static void
-registry_load (RegistryFixture *fixture, gconstpointer data)
-{
-  gboolean res;
-
-  res = grl_plugin_registry_load_all (fixture->registry);
-  g_assert_cmpint (res, ==, TRUE);
-}
-
-static void
-registry_unregister (RegistryFixture *fixture, gconstpointer data)
-{
-  GList *sources = NULL;
-  GList *sources_iter;
-  int i;
-
-  g_test_bug ("627207");
-
-  sources = grl_plugin_registry_get_sources (fixture->registry, FALSE);
-
-  for (sources_iter = sources, i = 0; sources_iter;
-      sources_iter = g_list_next (sources_iter), i++) {
-    GrlMediaPlugin *source = GRL_MEDIA_PLUGIN (sources_iter->data);
-
-    grl_plugin_registry_unregister_source (fixture->registry, source);
-  }
-  g_list_free (sources);
-
-  /* We expect to have loaded sources */
-  g_assert_cmpint (i, !=, 0);
-
-  sources = grl_plugin_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)
-{
-  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 ();
-}
-
diff --git a/src/tests/test_metadata_source.py b/src/tests/test_metadata_source.py
deleted file mode 100644
index 92482e7..0000000
--- a/src/tests/test_metadata_source.py
+++ /dev/null
@@ -1,99 +0,0 @@
-import unittest
-import logging
-import constants
-
-try:
-    from gi.repository import Grl
-except:
-    logging.warning("Unable to import Grilo's introspection bindings")
-
-class TestMetadataSource(unittest.TestCase):
-
-    MEDIA = Grl.Media()
-    METADATA_FLAGS = Grl.MetadataResolutionFlags(Grl.MetadataResolutionFlags.FULL |
-                                                 Grl.MetadataResolutionFlags.IDLE_RELAY)
-
-    def setUp(self):
-        Grl.init([])
-        self.registry = Grl.PluginRegistry.get_default()
-        self.registry.load_all()
-        ops = Grl.SupportedOps(Grl.SupportedOps.RESOLVE |
-                               Grl.SupportedOps.SET_METADATA)
-        sources = self.registry.get_sources_by_operations(ops, False)
-        if sources:
-            self.metadata_source = sources[0]
-
-    def tearDown(self):
-        self.metadata_source = None
-        for source in self.registry.get_sources(False):
-            self.registry.unload(source.get_id())
-            self.registry.unregister_source(source)
-
-    def test_supported_ops(self):
-        ops = self.metadata_source.supported_operations()
-        self.assertTrue(ops)
-
-    def test_supported_keys(self):
-        keys = self.metadata_source.supported_keys()
-        self.assertTrue(keys)
-
-    def test_slow_keys(self):
-        keys = self.metadata_source.slow_keys()
-
-    def test_filter_supported(self):
-        keys = self.metadata_source.filter_supported([], True)
-
-    def test_filter_slow(self):
-        keys = self.metadata_source.filter_slow([], True)
-
-    def test_filter_writable(self):
-        keys = self.metadata_source.filter_writable([], True)
-
-    def test_key_depends(self):
-        key_id = self.registry.lookup_metadata_key(constants.KEY_ID)
-        keys = self.metadata_source.key_depends(key_id)
-        self.assertTrue(keys is not None)
-
-    def test_writable_keys(self):
-        keys = self.metadata_source.writable_keys()
-        self.assertTrue(keys is not None)
-
-    def test_resolve(self):
-        self.metadata_source.resolve([], self.MEDIA, self.METADATA_FLAGS,
-                                     self.resolve_cb, None)
-
-    def resolve_cb(self, *args):
-        pass
-
-    def test_resolve_sync(self):
-        try:
-            self.metadata_source.resolve_sync([], self.MEDIA, self.METADATA_FLAGS)
-        except Exception, ex:
-            self.fail(ex)
-
-    def test_set_metadata(self):
-        self.metadata_source.set_metadata(self.MEDIA, [], self.METADATA_FLAGS,
-                                          self.metadata_cb, None)
-
-    def metadata_cb(self, *args):
-        pass
-
-    def test_set_metadata_sync(self):
-        try:
-            self.metadata_source.set_metadata_sync(self.MEDIA,
-                                                   self.registry.get_metadata_keys(),
-                                                   self.METADATA_FLAGS)
-        except Exception, ex:
-            self.fail(ex)
-
-    def test_get_id(self):
-        id = self.metadata_source.get_id()
-        self.assertTrue(id)
-
-    def test_get_name(self):
-        name = self.metadata_source.get_name()
-        self.assertTrue(name)
-
-    def test_get_description(self):
-        description = self.metadata_source.get_description()
-        self.assertTrue(description)
diff --git a/src/tests/test_plugin.py b/src/tests/test_plugin.py
deleted file mode 100644
index 1af54cb..0000000
--- a/src/tests/test_plugin.py
+++ /dev/null
@@ -1,77 +0,0 @@
-import unittest
-import logging
-
-try:
-    from gi.repository import Grl
-except:
-    logging.warning("Unable to import Grilo's introspection bindings")
-    exit()
-
-class TestMediaPlugin(unittest.TestCase):
-
-    NONEXISTING_KEY = 'nonexisting_key'
-
-    def setUp(self):
-        Grl.init([])
-        self.registry = Grl.PluginRegistry.get_default()
-        self.registry.load_all()
-        sources = self.registry.get_sources(False)
-        if sources:
-            self.plugin = sources[0]
-
-    def tearDown(self):
-        self.plugin = None
-        for source in self.registry.get_sources(False):
-            self.registry.unload(source.get_id())
-            self.registry.unregister_source(source)
-
-    def test_get_name(self):
-        name = self.plugin.get_name()
-        self.assertTrue(name)
-
-    def test_get_description(self):
-        description = self.plugin.get_name()
-        self.assertTrue(description)
-
-    def test_get_version(self):
-        version = self.plugin.get_version()
-        self.assertTrue(version)
-
-    def test_get_license(self):
-        license = self.plugin.get_license()
-        self.assertTrue(license)
-
-    def test_get_author(self):
-        author = self.plugin.get_author()
-        self.assertTrue(author)
-
-    def test_get_site(self):
-        site = self.plugin.get_site()
-        self.assertTrue(site)
-
-    def test_get_id(self):
-        id = self.plugin.get_id()
-        self.assertTrue(id)
-
-    def test_get_filename(self):
-        filename = self.plugin.get_filename()
-        self.assertTrue(filename)
-
-    def test_get_rank(self):
-        rank = self.plugin.get_rank()
-        self.assertTrue(rank is not None)
-
-    def test_get_info_keys(self):
-        info_keys = self.plugin.get_info_keys()
-        self.assertTrue(info_keys)
-
-    def test_get_info_existing_key(self):
-        keys = self.plugin.get_info_keys()
-        if keys:
-            existing_key = keys[0]
-            info = self.plugin.get_info(existing_key)
-            self.assertTrue(info)
-
-    def test_get_info_nonexisting_key(self):
-        info = self.plugin.get_info(self.NONEXISTING_KEY)
-        self.assertFalse(info)
diff --git a/src/tests/test_registry.py b/src/tests/test_registry.py
deleted file mode 100644
index b7b85c1..0000000
--- a/src/tests/test_registry.py
+++ /dev/null
@@ -1,158 +0,0 @@
-import unittest
-import os
-import util
-import tempfile
-import logging
-import constants
-
-try:
-    from gi.repository import Grl
-except:
-    logging.warning("Unable to import Grilo's introspection bindings")
-    exit()
-
-class TestPluginRegistry(unittest.TestCase):
-
-    EXISTING_LIBRARY_PATH = None
-
-    NONEXISTING_LIBRARY_PATH = 'NONEXISTING_LIBRARY.so'
-
-    INVALID_LIBRARY_PATH = os.path.join(util.PREFIX,
-                                        util.GRL_LIB_NAME)
-
-    NONEXISTING_SOURCE = 'NON_EXISTING_SOURCE'
-
-    def setUp(self):
-        Grl.init([])
-        self.registry = Grl.PluginRegistry.get_default()
-        plugin_dir = os.listdir(util.GRL_PLUGIN_PATH)
-        if plugin_dir:
-            self.EXISTING_LIBRARY_PATH = os.path.join(util.GRL_PLUGIN_PATH,
-                                                      plugin_dir[0])
-
-    def tearDown(self):
-        for source in self.registry.get_sources(False):
-            self.registry.unload(source.get_id())
-            self.registry.unregister_source(source)
-
-    def test_get_default_not_null(self):
-        registry = Grl.PluginRegistry.get_default()
-        self.assertTrue(registry)
-
-    def test_get_default_singleton(self):
-        registry1 = Grl.PluginRegistry.get_default()
-        registry2 = Grl.PluginRegistry.get_default()
-        self.assertEquals(registry1, registry2)
-
-    def test_add_directory(self):
-        pass
-
-    def test_load_existing(self):
-        if not self.registry.load(self.EXISTING_LIBRARY_PATH):
-            self.fail()
-
-    def test_load_unexisting(self):
-        if self.registry.load(self.NONEXISTING_LIBRARY_PATH):
-            self.fail()
-
-    def test_load_invalid(self):
-        if self.registry.load(self.INVALID_LIBRARY_PATH):
-            self.fail()
-
-    def test_load_directory_nonexisting(self):
-        if self.registry.load_directory(''):
-            self.fail()
-
-    def test_load_directory_existing(self):
-        if not self.registry.load_directory(os.getcwd()):
-            self.fail()
-
-    def test_unload(self):
-        pass
-
-    def test_load_all(self):
-        self.assertTrue(self.registry.load_all())
-
-    def test_register_source(self):
-        pass
-
-    def test_unregister_source(self):
-        self.registry.load_all()
-        sources = self.registry.get_sources(False)
-        for source in sources:
-            self.registry.unregister_source(source)
-        sources = self.registry.get_sources(False)
-        self.assertEqual(len(sources), 0)
-
-    def test_lookup_source(self):
-        self.registry.load_all()
-        sources = self.registry.get_sources(False)
-
-        if sources:
-            expected = sources[0]
-            search_id = expected.get_id()
-            found = self.registry.lookup_source(search_id)
-
-            self.assertEqual(expected, found)
-
-    def test_lookup_source_nonexisting(self):
-        self.registry.load_all()
-        found = self.registry.lookup_source(self.NONEXISTING_SOURCE)
-        self.assertFalse(found)
-
-    def test_get_sources(self):
-        sources = self.registry.get_sources(False)
-        self.assertEqual(len(sources), 0)
-
-        self.registry.load_all()
-        sources = self.registry.get_sources(False)
-        self.assertNotEqual(len(sources), 0)
-
-    def test_get_sources_ordering(self):
-        self.registry.load_all()
-        ordered_sources = self.registry.get_sources(True)
-        unordered_sources = self.registry.get_sources(False)
-
-        unordered_sources.sort(key=Grl.MediaPlugin.get_rank)
-        self.assertEquals(ordered_sources, unordered_sources)
-
-    def test_get_sources_by_operations_supported_ops(self):
-        self.registry.load_all()
-        for op in constants.SUPPORTED_OPS:
-            if op != Grl.SupportedOps.NONE:
-                sources = self.registry.get_sources_by_operations(op, False)
-                if sources:
-                    supported_operations = sources[0].supported_operations()
-                    self.assertTrue(supported_operations & op)
-
-    def test_register_metadata_key(self):
-        pass
-
-    def test_lookup_metadata_key_existing_key(self):
-        existing_key = self.registry.lookup_metadata_key(constants.KEY_ID)
-        self.assertTrue(existing_key)
-
-    def test_lookup_metadata_key_nonexisting_key(self):
-        nonexisting_key = self.registry.lookup_metadata_key(constants.KEY_NONEXISTING)
-        self.assertTrue(nonexisting_key is None)
-
-    def test_lookup_metadata_key_singleton(self):
-        a_key = self.registry.lookup_metadata_key(constants.KEY_ID)
-        another_key = self.registry.lookup_metadata_key(constants.KEY_ID)
-        self.assertEquals(a_key, another_key)
-
-    def test_get_metadata_keys_contains(self):
-        registered_key = self.registry.lookup_metadata_key(constants.KEY_ARTIST)
-        metadata_keys = self.registry.get_metadata_keys()
-        self.assertTrue(registered_key in metadata_keys)
-
-    def test_get_metadata_keys_all_keys(self):
-        registered_keys = []
-        for k in constants.REGISTERED_KEYS:
-            registered_keys.append(self.registry.lookup_metadata_key(k))
-
-        metadata_keys = self.registry.get_metadata_keys()
-        self.assertEquals(registered_keys.sort(), metadata_keys.sort())
-
-    def test_add_config(self):
-        pass
diff --git a/src/tests/testrunner.py b/src/tests/testrunner.py
deleted file mode 100755
index e3b090a..0000000
--- a/src/tests/testrunner.py
+++ /dev/null
@@ -1,27 +0,0 @@
-#!/usr/bin/env python
-
-import unittest
-import glob
-import sys
-
-test_loader = unittest.defaultTestLoader
-
-names = []
-args = sys.argv[1:]
-
-if args:
-    for item in args:
-        names.append(item[:-3])
-else:
-    for filename in glob.iglob("test_*.py"):
-        names.append(filename[:-3])
-
-test_suites = []
-print names
-for name in names:
-    test_suites.append(test_loader.loadTestsFromName(name))
-
-runner = unittest.TextTestRunner(verbosity=2)
-
-for suite in test_suites:
-    runner.run(suite)
diff --git a/src/tests/util.py.in b/src/tests/util.py.in
deleted file mode 100644
index 365c349..0000000
--- a/src/tests/util.py.in
+++ /dev/null
@@ -1,9 +0,0 @@
-import os
-
-GRL_PLUGIN_PATH_VAR = 'GRL_PLUGIN_PATH'
-GRL_PLUGIN_PATH_DEFAULT = '''@GRL_PLUGINS_DIR@'''
-GRL_PLUGIN_PATH = os.getenv(GRL_PLUGIN_PATH_VAR,
-                            GRL_PLUGIN_PATH_DEFAULT)
-
-PREFIX = '''@libdir@'''
-GRL_LIB_NAME = '''lib GRL_NAME@.la'''
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644
index 0000000..22e96ae
--- /dev/null
+++ b/tests/Makefile.am
@@ -0,0 +1,60 @@
+# things to test
+
+SUBDIRS = . python
+
+noinst_PROGRAMS = $(TEST_PROGS)
+
+AM_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/src/data $(DEPS_CFLAGS)
+progs_ldadd = $(top_builddir)/src/lib GRL_NAME@.la $(DEPS_LIBS)
+
+TEST_PROGS       = registry
+registry_SOURCES = registry.c
+registry_LDADD = $(progs_ldadd)
+
+### testing rules (from glib)
+
+GTESTER = gtester
+
+# test: run all tests in cwd and subdirs
+test:	${TEST_PROGS}
+	@test -z "${TEST_PROGS}" || ${GTESTER} --verbose ${TEST_PROGS}
+
+# test-report: run tests in subdirs and generate report
+# perf-report: run tests in subdirs with -m perf and generate report
+# full-report: like test-report: with -m perf and -m slow
+test-report perf-report full-report:	${TEST_PROGS}
+	@test -z "${TEST_PROGS}" || { \
+	  case $@ in \
+	  test-report) test_options="-k";; \
+	  perf-report) test_options="-k -m=perf";; \
+	  full-report) test_options="-k -m=perf -m=slow";; \
+	  esac ; \
+	  if test -z "$$GTESTER_LOGDIR" ; then	\
+	    ${GTESTER} --verbose $$test_options -o test-report.xml ${TEST_PROGS} ; \
+	  elif test -n "${TEST_PROGS}" ; then \
+	    ${GTESTER} --verbose $$test_options -o `mktemp "$$GTESTER_LOGDIR/log-XXXXXX"` ${TEST_PROGS} ; \
+	  fi ; \
+	}
+	@ ignore_logdir=true ; \
+	  if test -z "$$GTESTER_LOGDIR" ; then \
+	    GTESTER_LOGDIR=`mktemp -d "\`pwd\`/.testlogs-XXXXXX"`; export GTESTER_LOGDIR ; \
+	    ignore_logdir=false ; \
+	  fi ; \
+	  for subdir in $(SUBDIRS) . ; do \
+	    test "$$subdir" = "." -o "$$subdir" = "po" || \
+	    ( cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $@ ) || exit $? ; \
+	  done ; \
+	  $$ignore_logdir || { \
+	    echo '<?xml version="1.0"?>' > $  xml ; \
+	    echo '<report-collection>'  >> $  xml ; \
+	    for lf in `ls -L "$$GTESTER_LOGDIR"/.` ; do \
+	      sed '1,1s/^<?xml\b[^>?]*?>//' <"$$GTESTER_LOGDIR"/"$$lf" >> $  xml ; \
+	    done ; \
+	    echo >> $  xml ; \
+	    echo '</report-collection>' >> $  xml ; \
+	    rm -rf "$$GTESTER_LOGDIR"/ ; \
+	    ${GTESTER_REPORT} --version 2>/dev/null 1>&2 ; test "$$?" != 0 || ${GTESTER_REPORT} $  xml >$  html ; \
+	  }
+.PHONY: test test-report perf-report full-report
+# run make test as part of make check
+check-local: test
diff --git a/tests/python/Makefile.am b/tests/python/Makefile.am
new file mode 100644
index 0000000..935cf04
--- /dev/null
+++ b/tests/python/Makefile.am
@@ -0,0 +1,16 @@
+test: testrunner.py
+if HAVE_INTROSPECTION
+	PYTHONPATH=$(top_builddir):$(top_builddir)/tests$${PYTHONPATH:+:$$PYTHONPATH} $(PYTHON) $(srcdir)/testrunner.py
+endif
+
+if HAVE_INTROSPECTION
+EXTRA_DIST = \
+	testrunner.py \
+	test_registry.py \
+	test_plugin.py \
+	test_metadata_source.py
+endif
+
+.PHONY: test
+# run make test as part of make check
+check-local: test
diff --git a/tests/python/constants.py b/tests/python/constants.py
new file mode 100644
index 0000000..e8e2690
--- /dev/null
+++ b/tests/python/constants.py
@@ -0,0 +1,50 @@
+KEY_NONEXISTING = 'nonexisting-key'
+KEY_ALBUM = 'album'
+KEY_ARTIST = 'artist'
+KEY_AUTHOR = 'author'
+KEY_BITRATE = 'bitrate'
+KEY_CERTIFICATE = 'certificate'
+KEY_CHILDCOUNT = 'childcount'
+KEY_DATE = 'date'
+KEY_DESCRIPTION = 'description'
+KEY_DURATION = 'duration'
+KEY_EXTERNAL_PLAYER = 'external-player'
+KEY_EXTERNAL_URL = 'external-url'
+KEY_FRAMERATE = 'framerate'
+KEY_GENRE = 'genre'
+KEY_HEIGHT = 'height'
+KEY_ID = 'id'
+KEY_LAST_PLAYED = 'last-played'
+KEY_LAST_POSITION = 'last-position'
+KEY_LICENSE = 'license'
+KEY_LYRICS = 'lyrics'
+KEY_MIME = 'mime'
+KEY_PLAY_COUNT = 'play-count'
+KEY_RATING = 'rating'
+KEY_SITE = 'site'
+KEY_SOURCE = 'source'
+KEY_STUDIO = 'studio'
+KEY_THUMBNAIL = 'thumbnail'
+KEY_TITLE = 'title'
+KEY_URL = 'url'
+KEY_WIDTH = 'width'
+
+REGISTERED_KEYS = [KEY_ALBUM, KEY_ARTIST, KEY_AUTHOR, KEY_BITRATE,
+                   KEY_CERTIFICATE, KEY_CHILDCOUNT, KEY_DATE,
+                   KEY_DESCRIPTION, KEY_DURATION, KEY_EXTERNAL_PLAYER,
+                   KEY_EXTERNAL_URL, KEY_FRAMERATE, KEY_GENRE, KEY_HEIGHT,
+                   KEY_ID, KEY_LAST_PLAYED, KEY_LAST_POSITION, KEY_LICENSE,
+                   KEY_LYRICS, KEY_MIME, KEY_PLAY_COUNT, KEY_RATING,
+                   KEY_SITE, KEY_SOURCE, KEY_STUDIO, KEY_THUMBNAIL,
+                   KEY_TITLE, KEY_URL, KEY_WIDTH]
+
+SUPPORTED_OPS = []
+try:
+    from gi.repository import Grl
+    SUPPORTED_OPS = [Grl.SupportedOps.NONE, Grl.SupportedOps.METADATA,
+                     Grl.SupportedOps.RESOLVE, Grl.SupportedOps.BROWSE,
+                     Grl.SupportedOps.SEARCH, Grl.SupportedOps.QUERY,
+                     Grl.SupportedOps.STORE, Grl.SupportedOps.STORE_PARENT,
+                     Grl.SupportedOps.REMOVE, Grl.SupportedOps.SET_METADATA]
+except:
+    pass
diff --git a/tests/python/test_metadata_source.py b/tests/python/test_metadata_source.py
new file mode 100644
index 0000000..92482e7
--- /dev/null
+++ b/tests/python/test_metadata_source.py
@@ -0,0 +1,99 @@
+import unittest
+import logging
+import constants
+
+try:
+    from gi.repository import Grl
+except:
+    logging.warning("Unable to import Grilo's introspection bindings")
+
+class TestMetadataSource(unittest.TestCase):
+
+    MEDIA = Grl.Media()
+    METADATA_FLAGS = Grl.MetadataResolutionFlags(Grl.MetadataResolutionFlags.FULL |
+                                                 Grl.MetadataResolutionFlags.IDLE_RELAY)
+
+    def setUp(self):
+        Grl.init([])
+        self.registry = Grl.PluginRegistry.get_default()
+        self.registry.load_all()
+        ops = Grl.SupportedOps(Grl.SupportedOps.RESOLVE |
+                               Grl.SupportedOps.SET_METADATA)
+        sources = self.registry.get_sources_by_operations(ops, False)
+        if sources:
+            self.metadata_source = sources[0]
+
+    def tearDown(self):
+        self.metadata_source = None
+        for source in self.registry.get_sources(False):
+            self.registry.unload(source.get_id())
+            self.registry.unregister_source(source)
+
+    def test_supported_ops(self):
+        ops = self.metadata_source.supported_operations()
+        self.assertTrue(ops)
+
+    def test_supported_keys(self):
+        keys = self.metadata_source.supported_keys()
+        self.assertTrue(keys)
+
+    def test_slow_keys(self):
+        keys = self.metadata_source.slow_keys()
+
+    def test_filter_supported(self):
+        keys = self.metadata_source.filter_supported([], True)
+
+    def test_filter_slow(self):
+        keys = self.metadata_source.filter_slow([], True)
+
+    def test_filter_writable(self):
+        keys = self.metadata_source.filter_writable([], True)
+
+    def test_key_depends(self):
+        key_id = self.registry.lookup_metadata_key(constants.KEY_ID)
+        keys = self.metadata_source.key_depends(key_id)
+        self.assertTrue(keys is not None)
+
+    def test_writable_keys(self):
+        keys = self.metadata_source.writable_keys()
+        self.assertTrue(keys is not None)
+
+    def test_resolve(self):
+        self.metadata_source.resolve([], self.MEDIA, self.METADATA_FLAGS,
+                                     self.resolve_cb, None)
+
+    def resolve_cb(self, *args):
+        pass
+
+    def test_resolve_sync(self):
+        try:
+            self.metadata_source.resolve_sync([], self.MEDIA, self.METADATA_FLAGS)
+        except Exception, ex:
+            self.fail(ex)
+
+    def test_set_metadata(self):
+        self.metadata_source.set_metadata(self.MEDIA, [], self.METADATA_FLAGS,
+                                          self.metadata_cb, None)
+
+    def metadata_cb(self, *args):
+        pass
+
+    def test_set_metadata_sync(self):
+        try:
+            self.metadata_source.set_metadata_sync(self.MEDIA,
+                                                   self.registry.get_metadata_keys(),
+                                                   self.METADATA_FLAGS)
+        except Exception, ex:
+            self.fail(ex)
+
+    def test_get_id(self):
+        id = self.metadata_source.get_id()
+        self.assertTrue(id)
+
+    def test_get_name(self):
+        name = self.metadata_source.get_name()
+        self.assertTrue(name)
+
+    def test_get_description(self):
+        description = self.metadata_source.get_description()
+        self.assertTrue(description)
diff --git a/tests/python/test_plugin.py b/tests/python/test_plugin.py
new file mode 100644
index 0000000..1af54cb
--- /dev/null
+++ b/tests/python/test_plugin.py
@@ -0,0 +1,77 @@
+import unittest
+import logging
+
+try:
+    from gi.repository import Grl
+except:
+    logging.warning("Unable to import Grilo's introspection bindings")
+    exit()
+
+class TestMediaPlugin(unittest.TestCase):
+
+    NONEXISTING_KEY = 'nonexisting_key'
+
+    def setUp(self):
+        Grl.init([])
+        self.registry = Grl.PluginRegistry.get_default()
+        self.registry.load_all()
+        sources = self.registry.get_sources(False)
+        if sources:
+            self.plugin = sources[0]
+
+    def tearDown(self):
+        self.plugin = None
+        for source in self.registry.get_sources(False):
+            self.registry.unload(source.get_id())
+            self.registry.unregister_source(source)
+
+    def test_get_name(self):
+        name = self.plugin.get_name()
+        self.assertTrue(name)
+
+    def test_get_description(self):
+        description = self.plugin.get_name()
+        self.assertTrue(description)
+
+    def test_get_version(self):
+        version = self.plugin.get_version()
+        self.assertTrue(version)
+
+    def test_get_license(self):
+        license = self.plugin.get_license()
+        self.assertTrue(license)
+
+    def test_get_author(self):
+        author = self.plugin.get_author()
+        self.assertTrue(author)
+
+    def test_get_site(self):
+        site = self.plugin.get_site()
+        self.assertTrue(site)
+
+    def test_get_id(self):
+        id = self.plugin.get_id()
+        self.assertTrue(id)
+
+    def test_get_filename(self):
+        filename = self.plugin.get_filename()
+        self.assertTrue(filename)
+
+    def test_get_rank(self):
+        rank = self.plugin.get_rank()
+        self.assertTrue(rank is not None)
+
+    def test_get_info_keys(self):
+        info_keys = self.plugin.get_info_keys()
+        self.assertTrue(info_keys)
+
+    def test_get_info_existing_key(self):
+        keys = self.plugin.get_info_keys()
+        if keys:
+            existing_key = keys[0]
+            info = self.plugin.get_info(existing_key)
+            self.assertTrue(info)
+
+    def test_get_info_nonexisting_key(self):
+        info = self.plugin.get_info(self.NONEXISTING_KEY)
+        self.assertFalse(info)
diff --git a/tests/python/test_registry.py b/tests/python/test_registry.py
new file mode 100644
index 0000000..b7b85c1
--- /dev/null
+++ b/tests/python/test_registry.py
@@ -0,0 +1,158 @@
+import unittest
+import os
+import util
+import tempfile
+import logging
+import constants
+
+try:
+    from gi.repository import Grl
+except:
+    logging.warning("Unable to import Grilo's introspection bindings")
+    exit()
+
+class TestPluginRegistry(unittest.TestCase):
+
+    EXISTING_LIBRARY_PATH = None
+
+    NONEXISTING_LIBRARY_PATH = 'NONEXISTING_LIBRARY.so'
+
+    INVALID_LIBRARY_PATH = os.path.join(util.PREFIX,
+                                        util.GRL_LIB_NAME)
+
+    NONEXISTING_SOURCE = 'NON_EXISTING_SOURCE'
+
+    def setUp(self):
+        Grl.init([])
+        self.registry = Grl.PluginRegistry.get_default()
+        plugin_dir = os.listdir(util.GRL_PLUGIN_PATH)
+        if plugin_dir:
+            self.EXISTING_LIBRARY_PATH = os.path.join(util.GRL_PLUGIN_PATH,
+                                                      plugin_dir[0])
+
+    def tearDown(self):
+        for source in self.registry.get_sources(False):
+            self.registry.unload(source.get_id())
+            self.registry.unregister_source(source)
+
+    def test_get_default_not_null(self):
+        registry = Grl.PluginRegistry.get_default()
+        self.assertTrue(registry)
+
+    def test_get_default_singleton(self):
+        registry1 = Grl.PluginRegistry.get_default()
+        registry2 = Grl.PluginRegistry.get_default()
+        self.assertEquals(registry1, registry2)
+
+    def test_add_directory(self):
+        pass
+
+    def test_load_existing(self):
+        if not self.registry.load(self.EXISTING_LIBRARY_PATH):
+            self.fail()
+
+    def test_load_unexisting(self):
+        if self.registry.load(self.NONEXISTING_LIBRARY_PATH):
+            self.fail()
+
+    def test_load_invalid(self):
+        if self.registry.load(self.INVALID_LIBRARY_PATH):
+            self.fail()
+
+    def test_load_directory_nonexisting(self):
+        if self.registry.load_directory(''):
+            self.fail()
+
+    def test_load_directory_existing(self):
+        if not self.registry.load_directory(os.getcwd()):
+            self.fail()
+
+    def test_unload(self):
+        pass
+
+    def test_load_all(self):
+        self.assertTrue(self.registry.load_all())
+
+    def test_register_source(self):
+        pass
+
+    def test_unregister_source(self):
+        self.registry.load_all()
+        sources = self.registry.get_sources(False)
+        for source in sources:
+            self.registry.unregister_source(source)
+        sources = self.registry.get_sources(False)
+        self.assertEqual(len(sources), 0)
+
+    def test_lookup_source(self):
+        self.registry.load_all()
+        sources = self.registry.get_sources(False)
+
+        if sources:
+            expected = sources[0]
+            search_id = expected.get_id()
+            found = self.registry.lookup_source(search_id)
+
+            self.assertEqual(expected, found)
+
+    def test_lookup_source_nonexisting(self):
+        self.registry.load_all()
+        found = self.registry.lookup_source(self.NONEXISTING_SOURCE)
+        self.assertFalse(found)
+
+    def test_get_sources(self):
+        sources = self.registry.get_sources(False)
+        self.assertEqual(len(sources), 0)
+
+        self.registry.load_all()
+        sources = self.registry.get_sources(False)
+        self.assertNotEqual(len(sources), 0)
+
+    def test_get_sources_ordering(self):
+        self.registry.load_all()
+        ordered_sources = self.registry.get_sources(True)
+        unordered_sources = self.registry.get_sources(False)
+
+        unordered_sources.sort(key=Grl.MediaPlugin.get_rank)
+        self.assertEquals(ordered_sources, unordered_sources)
+
+    def test_get_sources_by_operations_supported_ops(self):
+        self.registry.load_all()
+        for op in constants.SUPPORTED_OPS:
+            if op != Grl.SupportedOps.NONE:
+                sources = self.registry.get_sources_by_operations(op, False)
+                if sources:
+                    supported_operations = sources[0].supported_operations()
+                    self.assertTrue(supported_operations & op)
+
+    def test_register_metadata_key(self):
+        pass
+
+    def test_lookup_metadata_key_existing_key(self):
+        existing_key = self.registry.lookup_metadata_key(constants.KEY_ID)
+        self.assertTrue(existing_key)
+
+    def test_lookup_metadata_key_nonexisting_key(self):
+        nonexisting_key = self.registry.lookup_metadata_key(constants.KEY_NONEXISTING)
+        self.assertTrue(nonexisting_key is None)
+
+    def test_lookup_metadata_key_singleton(self):
+        a_key = self.registry.lookup_metadata_key(constants.KEY_ID)
+        another_key = self.registry.lookup_metadata_key(constants.KEY_ID)
+        self.assertEquals(a_key, another_key)
+
+    def test_get_metadata_keys_contains(self):
+        registered_key = self.registry.lookup_metadata_key(constants.KEY_ARTIST)
+        metadata_keys = self.registry.get_metadata_keys()
+        self.assertTrue(registered_key in metadata_keys)
+
+    def test_get_metadata_keys_all_keys(self):
+        registered_keys = []
+        for k in constants.REGISTERED_KEYS:
+            registered_keys.append(self.registry.lookup_metadata_key(k))
+
+        metadata_keys = self.registry.get_metadata_keys()
+        self.assertEquals(registered_keys.sort(), metadata_keys.sort())
+
+    def test_add_config(self):
+        pass
diff --git a/tests/python/testrunner.py b/tests/python/testrunner.py
new file mode 100755
index 0000000..e3b090a
--- /dev/null
+++ b/tests/python/testrunner.py
@@ -0,0 +1,27 @@
+#!/usr/bin/env python
+
+import unittest
+import glob
+import sys
+
+test_loader = unittest.defaultTestLoader
+
+names = []
+args = sys.argv[1:]
+
+if args:
+    for item in args:
+        names.append(item[:-3])
+else:
+    for filename in glob.iglob("test_*.py"):
+        names.append(filename[:-3])
+
+test_suites = []
+print names
+for name in names:
+    test_suites.append(test_loader.loadTestsFromName(name))
+
+runner = unittest.TextTestRunner(verbosity=2)
+
+for suite in test_suites:
+    runner.run(suite)
diff --git a/tests/python/util.py.in b/tests/python/util.py.in
new file mode 100644
index 0000000..365c349
--- /dev/null
+++ b/tests/python/util.py.in
@@ -0,0 +1,9 @@
+import os
+
+GRL_PLUGIN_PATH_VAR = 'GRL_PLUGIN_PATH'
+GRL_PLUGIN_PATH_DEFAULT = '''@GRL_PLUGINS_DIR@'''
+GRL_PLUGIN_PATH = os.getenv(GRL_PLUGIN_PATH_VAR,
+                            GRL_PLUGIN_PATH_DEFAULT)
+
+PREFIX = '''@libdir@'''
+GRL_LIB_NAME = '''lib GRL_NAME@.la'''
diff --git a/tests/registry.c b/tests/registry.c
new file mode 100644
index 0000000..08e95e8
--- /dev/null
+++ b/tests/registry.c
@@ -0,0 +1,149 @@
+/*
+ * 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 <glib.h>
+
+#include <grilo.h>
+
+#define CHECK_MESSAGE(domain, error_message) \
+  (g_strcmp0 (log_domain, domain) == 0 && strstr (message, error_message))
+
+#if GLIB_CHECK_VERSION(2,22,0)
+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", "Could not read XML file")) {
+    return FALSE;
+  }
+
+  return TRUE;
+}
+#endif
+
+typedef struct {
+  GrlPluginRegistry *registry;
+  GMainLoop *loop;
+} RegistryFixture;
+
+static void
+registry_fixture_setup (RegistryFixture *fixture, gconstpointer data)
+{
+#if GLIB_CHECK_VERSION(2,22,0)
+  g_test_log_set_fatal_handler (registry_load_error_handler, NULL);
+#endif
+
+  fixture->registry = grl_plugin_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)
+{
+  GrlPluginRegistry *registry;
+
+  registry = grl_plugin_registry_get_default ();
+  g_assert (registry);
+}
+
+static void
+registry_load (RegistryFixture *fixture, gconstpointer data)
+{
+  gboolean res;
+
+  res = grl_plugin_registry_load_all (fixture->registry);
+  g_assert_cmpint (res, ==, TRUE);
+}
+
+static void
+registry_unregister (RegistryFixture *fixture, gconstpointer data)
+{
+  GList *sources = NULL;
+  GList *sources_iter;
+  int i;
+
+  g_test_bug ("627207");
+
+  sources = grl_plugin_registry_get_sources (fixture->registry, FALSE);
+
+  for (sources_iter = sources, i = 0; sources_iter;
+      sources_iter = g_list_next (sources_iter), i++) {
+    GrlMediaPlugin *source = GRL_MEDIA_PLUGIN (sources_iter->data);
+
+    grl_plugin_registry_unregister_source (fixture->registry, source);
+  }
+  g_list_free (sources);
+
+  /* We expect to have loaded sources */
+  g_assert_cmpint (i, !=, 0);
+
+  sources = grl_plugin_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)
+{
+  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 ();
+}
-- 
1.7.0.4



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]