[grilo-plugins] tests: Add tests for tmdb plug-in



commit 2c2b5ea365408ef907b4f2639a8ba73a8fa57d41
Author: Jens Georg <jensg openismus com>
Date:   Tue Nov 13 10:32:05 2012 +0100

    tests: Add tests for tmdb plug-in
    
    With some changes by Murray Cumming to update this patch to
    the latest grilo API, split it into separate files so we can
    set GRL_NET_MOCKED before calling grl_init(), and to
    dist the test data files.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=688245

 test/.gitignore                        |    5 +
 test/Makefile.am                       |   56 +++++++++++--
 test/test_tmdb_fast_resolution.c       |  118 +++++++++++++++++++++++++
 test/test_tmdb_full_resolution.c       |  151 ++++++++++++++++++++++++++++++++
 test/test_tmdb_missing_configuration.c |   84 ++++++++++++++++++
 test/test_tmdb_preconditions.c         |  107 ++++++++++++++++++++++
 test/test_tmdb_utils.c                 |   72 +++++++++++++++
 test/test_tmdb_utils.h                 |   33 +++++++
 8 files changed, 620 insertions(+), 6 deletions(-)
---
diff --git a/test/.gitignore b/test/.gitignore
index 9daeafb..0df9d07 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -1 +1,6 @@
 test
+test_local_metadata
+test_tmdb_preconditions
+test_tmdb_missing_configuration
+test_tmdb_fast_resolution
+test_tmdb_full_resolution
diff --git a/test/Makefile.am b/test/Makefile.am
index a68fe61..9710fb8 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -7,7 +7,11 @@
 
 INCLUDES = @DEPS_CFLAGS@
 
-noinst_PROGRAMS = test_local_metadata test_tmdb
+noinst_PROGRAMS = test_local_metadata \
+	test_tmdb_preconditions \
+	test_tmdb_missing_configuration \
+	test_tmdb_fast_resolution \
+	test_tmdb_full_resolution
 #noinst_PROGRAMS += test
 
 #test_SOURCES =	\
@@ -32,14 +36,54 @@ test_local_metadata_CFLAGS = \
 	@GTHREAD_CFLAGS@ \
 	@GIO_CFLAGS@
 
-test_tmdb_SOURCES = \
-	test_tmdb.c
+# Let the .c source code know about this path,
+# even when sourcedir!=builddir, such as during make distcheck:
+test_tmdb_defines = -DGRILO_PLUGINS_TESTS_TMDB_DATA_PATH=\""$(abs_top_srcdir)/test/test_data/tmdb/"\"
 
-test_tmdb_LDADD = \
+test_tmdb_preconditions_SOURCES = \
+	test_tmdb_preconditions.c \
+	test_tmdb_utils.h test_tmdb_utils.c
+test_tmdb_preconditions_LDADD = \
 	@DEPS_LIBS@
+test_tmdb_preconditions_CFLAGS = \
+	-DPREFIX=$(prefix) $(test_tmdb_defines)
 
-test_tmdb_CFLAGS = \
-	-DPREFIX=$(prefix)
+test_tmdb_missing_configuration_SOURCES = \
+	test_tmdb_missing_configuration.c \
+	test_tmdb_utils.h test_tmdb_utils.c
+test_tmdb_missing_configuration_LDADD = \
+	@DEPS_LIBS@
+test_tmdb_missing_configuration_CFLAGS = \
+	-DPREFIX=$(prefix) $(test_tmdb_defines)
+
+test_tmdb_fast_resolution_SOURCES = \
+	test_tmdb_fast_resolution.c \
+	test_tmdb_utils.h test_tmdb_utils.c
+test_tmdb_fast_resolution_LDADD = \
+	@DEPS_LIBS@
+test_tmdb_fast_resolution_CFLAGS = \
+	-DPREFIX=$(prefix) $(test_tmdb_defines)
+
+test_tmdb_full_resolution_SOURCES = \
+	test_tmdb_full_resolution.c \
+	test_tmdb_utils.h test_tmdb_utils.c
+test_tmdb_full_resolution_LDADD = \
+	@DEPS_LIBS@
+test_tmdb_full_resolution_CFLAGS = \
+	-DPREFIX=$(prefix) $(test_tmdb_defines)
+
+# Distribute the tests data:
+dist_noinst_DATA = \
+	test_data/tmdb/casts.txt \
+	test_data/tmdb/configuration.txt \
+	test_data/tmdb/details.txt \
+	test_data/tmdb/empty-data.ini \
+	test_data/tmdb/images.txt \
+	test_data/tmdb/keywords.txt \
+	test_data/tmdb/no-details.ini \
+	test_data/tmdb/releases.txt \
+	test_data/tmdb/search.txt \
+	test_data/tmdb/sherlock.ini
 
 MAINTAINERCLEANFILES =	\
 	*.in		\
diff --git a/test/test_tmdb_fast_resolution.c b/test/test_tmdb_fast_resolution.c
new file mode 100644
index 0000000..55803df
--- /dev/null
+++ b/test/test_tmdb_fast_resolution.c
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2012 Openismus GmbH
+ *
+ * Author: Jens Georg <jensg openismus com>
+ *
+ * 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
+ *
+ */
+
+#include <grilo.h>
+#include "test_tmdb_utils.h"
+#include <math.h>
+#include <float.h>
+
+#define TMDB_PLUGIN_ID "grl-tmdb"
+
+/** Compare the floats.
+ * A simple == will fail on values that are effectively the same,
+ * due to rounding issues.
+ */
+static gboolean compare_floats(gfloat a, gfloat b)
+{
+   return fabs(a - b) < DBL_EPSILON;
+}
+
+static void
+test (void)
+{
+  GrlKeyID backdrop, original_title, posters;
+  GrlRegistry *registry;
+  GDateTime *date, *orig;
+  GrlOperationOptions *options = NULL;
+  GrlMedia *media = NULL;
+  GError *error = NULL;
+
+  test_setup_tmdb ();
+
+  registry = grl_registry_get_default ();
+  backdrop = grl_registry_lookup_metadata_key (registry, "tmdb-backdrop");
+  g_assert_cmpint (backdrop, !=, GRL_METADATA_KEY_INVALID);
+  original_title = GRL_METADATA_KEY_ORIGINAL_TITLE;
+  posters = grl_registry_lookup_metadata_key (registry, "tmdb-poster");
+  g_assert_cmpint (posters, !=, GRL_METADATA_KEY_INVALID);
+
+  options = grl_operation_options_new (NULL);
+  g_assert (options != NULL);
+  grl_operation_options_set_flags (options, GRL_RESOLVE_FAST_ONLY);
+
+  media = grl_media_video_new ();
+  g_assert (media != NULL);
+  grl_media_set_title (media, "TMDBTestTitle");
+
+  GrlSource *source = test_get_source();
+  g_assert (source);
+  grl_source_resolve_sync (source,
+                           media,
+                           grl_source_supported_keys (source),
+                           options,
+                           &error);
+
+  /* Fast resolution must not result in an error if the details are missing */
+  g_assert (error == NULL);
+
+  /* Check if we have everything we need */
+  g_assert (compare_floats (grl_media_get_rating (media), 3.8f));
+  g_assert_cmpstr (grl_data_get_string (GRL_DATA (media), original_title), ==,
+                   "Sherlock Holmes");
+  /* There's only one poster/backdrop in the search result */
+  g_assert_cmpstr (grl_data_get_string (GRL_DATA (media), backdrop), ==,
+                   "http://cf2.imgobject.com/t/p/original/uM414ugc1B910bTvGEIzsucfMMC.jpg";);
+
+  g_assert_cmpstr (grl_data_get_string (GRL_DATA (media), posters), ==,
+                   "http://cf2.imgobject.com/t/p/original/22ngurXbLqab7Sko6aTSdwOCe5W.jpg";);
+  orig = g_date_time_new_utc (2009, 12, 25, 0, 0, 0.0);
+  date = grl_media_get_publication_date (media);
+  g_assert_cmpint (g_date_time_compare (orig, date), ==, 0);
+  g_date_time_unref (orig);
+
+  g_object_unref (media);
+  media = NULL;
+
+  g_object_unref (options);
+  options = NULL;
+
+  test_shutdown_tmdb ();
+}
+
+
+int
+main(int argc, char **argv)
+{
+  g_setenv ("GRL_PLUGIN_LIST", TMDB_PLUGIN_ID, TRUE);
+
+  /* We must set this before calling grl_init.
+   * See https://bugzilla.gnome.org/show_bug.cgi?id=685967#c17
+   */
+  g_setenv ("GRL_NET_MOCKED", GRILO_PLUGINS_TESTS_TMDB_DATA_PATH "no-details.ini", TRUE);
+
+  grl_init (&argc, &argv);
+#if !GLIB_CHECK_VERSION(2,32,0)
+  g_thread_init (NULL);
+#endif
+
+  test ();
+}
diff --git a/test/test_tmdb_full_resolution.c b/test/test_tmdb_full_resolution.c
new file mode 100644
index 0000000..be9c404
--- /dev/null
+++ b/test/test_tmdb_full_resolution.c
@@ -0,0 +1,151 @@
+/*
+ * Copyright (C) 2012 Openismus GmbH
+ *
+ * Author: Jens Georg <jensg openismus com>
+ *
+ * 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
+ *
+ */
+
+#include <grilo.h>
+#include "test_tmdb_utils.h"
+#include <math.h>
+#include <float.h>
+
+#define TMDB_PLUGIN_ID "grl-tmdb"
+
+/** Compare the floats.
+ * A simple == will fail on values that are effectively the same,
+ * due to rounding issues.
+ */
+static gboolean compare_floats(gfloat a, gfloat b)
+{
+   return fabs(a - b) < DBL_EPSILON;
+}
+
+#define DESCRIPTION \
+"In a dynamic new portrayal of Arthur Conan Doyleâs most famous characters, âSherlock Holmesâ sends Holmes and his stalwart partner Watson on their latest challenge. Revealing fighting skills as lethal as his legendary intellect, Holmes will battle as never before to bring down a new nemesis and unravel a deadly plot that could destroy England."
+
+static void
+test (void)
+{
+  GError *error = NULL;
+  GrlRegistry *registry;
+  GrlKeyID backdrop, posters, imdb_id, keywords, performer, producer;
+  GrlKeyID director, original_title;
+  GrlOperationOptions *options = NULL;
+  GrlMedia *media = NULL;
+  GDateTime *date, *orig;
+
+  test_setup_tmdb ();
+
+  registry = grl_registry_get_default ();
+  backdrop = grl_registry_lookup_metadata_key (registry, "tmdb-backdrop");
+  g_assert_cmpint (backdrop, !=, GRL_METADATA_KEY_INVALID);
+  posters = grl_registry_lookup_metadata_key (registry, "tmdb-poster");
+  g_assert_cmpint (posters, !=, GRL_METADATA_KEY_INVALID);
+  imdb_id = grl_registry_lookup_metadata_key (registry, "tmdb-imdb-id");
+  g_assert_cmpint (imdb_id, !=, GRL_METADATA_KEY_INVALID);
+  keywords = GRL_METADATA_KEY_KEYWORD;
+  performer = GRL_METADATA_KEY_PERFORMER;
+  producer = GRL_METADATA_KEY_PRODUCER;
+  director = GRL_METADATA_KEY_DIRECTOR;
+  original_title = GRL_METADATA_KEY_ORIGINAL_TITLE;
+
+  media = grl_media_video_new ();
+  g_assert (media != NULL);
+  grl_media_set_title (media, "Sherlock Holmes");
+
+  GrlSource *source = test_get_source();
+  g_assert (source);
+  options = grl_operation_options_new (NULL);
+  g_assert (options != NULL);
+  grl_source_resolve_sync (source,
+                           media,
+                           grl_source_supported_keys (source),
+                           options,
+                           &error);
+  g_assert (error == NULL);
+
+  /* Check if we got everything we need for the fast resolution */
+  g_assert (compare_floats (grl_media_get_rating (media), 3.8f));
+  g_assert_cmpstr (grl_data_get_string (GRL_DATA (media), original_title), ==,
+                   "Sherlock Holmes");
+  /* There's only one poster/backdrop in the search result */
+  g_assert_cmpstr (grl_data_get_string (GRL_DATA (media), backdrop), ==,
+                   "http://cf2.imgobject.com/t/p/original/uM414ugc1B910bTvGEIzsucfMMC.jpg";);
+
+  g_assert_cmpstr (grl_data_get_string (GRL_DATA (media), posters), ==,
+                   "http://cf2.imgobject.com/t/p/original/22ngurXbLqab7Sko6aTSdwOCe5W.jpg";);
+  orig = g_date_time_new_utc (2009, 12, 25, 0, 0, 0.0);
+  date = grl_media_get_publication_date (media);
+  g_assert_cmpint (g_date_time_compare (orig, date), ==, 0);
+  g_date_time_unref (orig);
+
+  /* And now the slow properties */
+  g_assert_cmpstr (grl_media_get_site (media), ==,
+                   "http://sherlock-holmes-movie.warnerbros.com/";);
+  g_assert_cmpint (grl_data_length (GRL_DATA (media), GRL_METADATA_KEY_GENRE), ==, 6);
+  g_assert_cmpint (grl_data_length (GRL_DATA (media), GRL_METADATA_KEY_STUDIO), ==, 3);
+
+  g_assert_cmpstr (grl_media_get_description (media), ==, DESCRIPTION);
+
+  /* TODO: See https://bugzilla.gnome.org/show_bug.cgi?id=679686#c13
+  g_assert_cmpstr (grl_media_get_certificate (media), ==, "PG-13");
+  */
+
+  g_assert_cmpstr (grl_data_get_string (GRL_DATA (media), imdb_id), ==, "tt0988045");
+  g_assert_cmpint (grl_data_length (GRL_DATA (media), keywords), ==, 15);
+
+  g_assert_cmpint (grl_data_length (GRL_DATA (media), performer), ==, 10);
+
+  g_assert_cmpint (grl_data_length (GRL_DATA (media), producer), ==, 9);
+
+  g_assert_cmpint (grl_data_length (GRL_DATA (media), director), ==, 1);
+  g_assert_cmpstr (grl_data_get_string (GRL_DATA (media), director), ==, "Guy Ritchie");
+
+  /* TODO: See https://bugzilla.gnome.org/show_bug.cgi?id=679686#c13
+  g_assert_cmpstr (grl_data_get_string (GRL_DATA (media), age_certs), ==,
+                   "GB:12A;NL:12;BG:C;HU:16;DE:12;DK:15;US:PG-13");
+  */
+
+  g_object_unref (media);
+  media = NULL;
+
+  g_object_unref (options);
+  options = NULL;
+
+  test_shutdown_tmdb ();
+}
+
+
+int
+main(int argc, char **argv)
+{
+  g_setenv ("GRL_PLUGIN_LIST", TMDB_PLUGIN_ID, TRUE);
+
+  /* We must set this before calling grl_init.
+   * See https://bugzilla.gnome.org/show_bug.cgi?id=685967#c17
+   */
+  g_setenv ("GRL_NET_MOCKED", GRILO_PLUGINS_TESTS_TMDB_DATA_PATH "sherlock.ini", TRUE);
+
+  grl_init (&argc, &argv);
+#if !GLIB_CHECK_VERSION(2,32,0)
+  g_thread_init (NULL);
+#endif
+
+  test ();
+}
diff --git a/test/test_tmdb_missing_configuration.c b/test/test_tmdb_missing_configuration.c
new file mode 100644
index 0000000..fee49ca
--- /dev/null
+++ b/test/test_tmdb_missing_configuration.c
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2012 Openismus GmbH
+ *
+ * Author: Jens Georg <jensg openismus com>
+ *
+ * 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
+ *
+ */
+
+#include <grilo.h>
+#include "test_tmdb_utils.h"
+#include <math.h>
+#include <float.h>
+
+#define TMDB_PLUGIN_ID "grl-tmdb"
+
+static void
+test (void)
+{
+  GrlMedia *media = NULL;
+  GrlOperationOptions *options = NULL;
+  GError *error = NULL;
+
+  test_setup_tmdb ();
+
+  /* Doesn't matter. We just need to get it to resolve */
+  media = grl_media_video_new ();
+  g_assert (media != NULL);
+  grl_media_set_title (media, "Non-Empty");
+
+  GrlSource *source = test_get_source();
+  g_assert (source);
+  options = grl_operation_options_new (NULL);
+  g_assert (options != NULL);
+  grl_source_resolve_sync (source,
+                           media,
+                           grl_source_supported_keys (source),
+                           options,
+                           &error);
+
+  /* Check that the plugin didn't even try to resolve data, otherwise the mock
+   * file would have resulted in an error */
+  g_assert (error != NULL);
+
+  g_object_unref (media);
+  media = NULL;
+
+  g_object_unref (options);
+  options = NULL;
+
+  test_shutdown_tmdb ();
+}
+
+
+int
+main(int argc, char **argv)
+{
+  g_setenv ("GRL_PLUGIN_LIST", TMDB_PLUGIN_ID, TRUE);
+
+  /* We must set this before calling grl_init.
+   * See https://bugzilla.gnome.org/show_bug.cgi?id=685967#c17
+   */
+  g_setenv ("GRL_NET_MOCKED", GRILO_PLUGINS_TESTS_TMDB_DATA_PATH "empty-data.ini", TRUE);
+
+  grl_init (&argc, &argv);
+#if !GLIB_CHECK_VERSION(2,32,0)
+  g_thread_init (NULL);
+#endif
+
+  test ();
+}
diff --git a/test/test_tmdb_preconditions.c b/test/test_tmdb_preconditions.c
new file mode 100644
index 0000000..e869da9
--- /dev/null
+++ b/test/test_tmdb_preconditions.c
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2012 Openismus GmbH
+ *
+ * Author: Jens Georg <jensg openismus com>
+ *
+ * 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
+ *
+ */
+
+#include <grilo.h>
+#include "test_tmdb_utils.h"
+#include <math.h>
+#include <float.h>
+
+#define TMDB_PLUGIN_ID "grl-tmdb"
+
+static void
+test (void)
+{
+  GrlMedia *local_media = NULL;
+  GrlMedia *media = NULL;
+  GError *error = NULL;
+  GrlOperationOptions *options = NULL;
+
+  test_setup_tmdb ();
+
+  local_media = grl_media_audio_new ();
+
+  GrlSource *source = test_get_source();
+  g_assert (source);
+  options = grl_operation_options_new (NULL);
+  g_assert (options != NULL);
+  grl_source_resolve_sync (source,
+                           local_media,
+                           grl_source_supported_keys (source),
+                           options,
+                           &error);
+
+  /* Check that the plugin didn't even try to resolve data, otherwise the mock
+   * file would have resulted in an error */
+  g_assert (error == NULL);
+
+  g_object_unref (local_media);
+
+  local_media = grl_media_image_new ();
+
+  grl_source_resolve_sync (source,
+                           local_media,
+                           grl_source_supported_keys (source),
+                           options,
+                           &error);
+
+  /* Check that the plugin didn't even try to resolve data, otherwise the
+   * empty mock file would have resulted in an error */
+  g_assert (error == NULL);
+  g_object_unref (local_media);
+
+  /* Check the same for title-less video */
+  media = grl_media_video_new ();
+  g_assert (media != NULL);
+  grl_source_resolve_sync (source,
+                           media,
+                           grl_source_supported_keys (source),
+                           options,
+                           &error);
+  g_assert (error == NULL);
+
+  g_object_unref (media);
+  media = NULL;
+
+  g_object_unref (options);
+  options = NULL;
+
+  test_shutdown_tmdb ();
+}
+
+
+int
+main(int argc, char **argv)
+{
+  g_setenv ("GRL_PLUGIN_LIST", TMDB_PLUGIN_ID, TRUE);
+
+  /* We must set this before calling grl_init.
+   * See https://bugzilla.gnome.org/show_bug.cgi?id=685967#c17
+   */
+  g_setenv ("GRL_NET_MOCKED", GRILO_PLUGINS_TESTS_TMDB_DATA_PATH "empty-data.ini", TRUE);
+
+  grl_init (&argc, &argv);
+#if !GLIB_CHECK_VERSION(2,32,0)
+  g_thread_init (NULL);
+#endif
+
+  test ();
+}
diff --git a/test/test_tmdb_utils.c b/test/test_tmdb_utils.c
new file mode 100644
index 0000000..0918c35
--- /dev/null
+++ b/test/test_tmdb_utils.c
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2012 Openismus GmbH
+ *
+ * Author: Jens Georg <jensg openismus com>
+ *
+ * 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
+ *
+ */
+
+#include "test_tmdb_utils.h"
+#include <math.h>
+#include <float.h>
+
+#define TMDB_PLUGIN_ID "grl-tmdb"
+#define TEST_PATH "test_data/tmdb/"
+
+GrlSource *source = NULL;
+
+void
+test_setup_tmdb (void)
+{
+  GrlConfig *config;
+  GrlRegistry *registry;
+  GError *error = NULL;
+
+  config = grl_config_new (TMDB_PLUGIN_ID, NULL);
+  /* It does not matter what we set this to. It just needs to be non-empty because we're
+   * going to fake the network responses. */
+  grl_config_set_api_key (config, "TMDB_TEST_API_KEY");
+
+  registry = grl_registry_get_default ();
+  grl_registry_add_config (registry, config, &error);
+  g_assert (error == NULL);
+
+  grl_registry_load_plugin_by_id (registry, TMDB_PLUGIN_ID, &error);
+  g_assert (error == NULL);
+
+  source = GRL_SOURCE (grl_registry_lookup_source (registry, TMDB_PLUGIN_ID));
+  g_assert (source != NULL);
+
+  g_assert (grl_source_supported_operations (source) & GRL_OP_RESOLVE);
+}
+
+GrlSource* test_get_source (void)
+{
+  return source;
+}
+
+void
+test_shutdown_tmdb (void)
+{
+  GrlRegistry *registry;
+  GError *error = NULL;
+
+  registry = grl_registry_get_default ();
+  grl_registry_unload_plugin (registry, TMDB_PLUGIN_ID, &error);
+  g_assert (error == NULL);
+}
+
diff --git a/test/test_tmdb_utils.h b/test/test_tmdb_utils.h
new file mode 100644
index 0000000..c7dca95
--- /dev/null
+++ b/test/test_tmdb_utils.h
@@ -0,0 +1,33 @@
+
+/*
+ * Copyright (C) 2012 Openismus GmbH
+ *
+ * Author: Jens Georg <jensg openismus com>
+ *
+ * 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
+ *
+ */
+
+#ifndef _GRL_TMDB_TEST_UTILS_H_
+#define _GRL_TMDB_TEST_UTILS_H_
+
+#include <grilo.h>
+
+void test_setup_tmdb (void);
+GrlSource* test_get_source (void);
+void test_shutdown_tmdb (void);
+
+#endif /* _GRL_TMDB_TEST_UTILS_H_ */



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