[grilo-plugins] lastfm-albumart: Add tests
- From: Juan A. Suarez Romero <jasuarez src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [grilo-plugins] lastfm-albumart: Add tests
- Date: Thu, 31 Jul 2014 19:15:45 +0000 (UTC)
commit 7192e4fd4702da009c7b247797443850a2427721
Author: Juan A. Suarez Romero <jasuarez igalia com>
Date: Thu Jul 31 19:13:37 2014 +0000
lastfm-albumart: Add tests
configure.ac | 1 +
src/lastfm-albumart/Makefile.am | 9 +
tests/Makefile.am | 5 +
tests/lastfm-albumart/Makefile.am | 40 +++
tests/lastfm-albumart/data/network-data.ini | 11 +
.../data/resolve-good-found-default.data | 14 +
tests/lastfm-albumart/data/resolve-good-found.data | 82 +++++
tests/lastfm-albumart/test_lastfm_albumart.c | 332 ++++++++++++++++++++
8 files changed, 494 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index adc1efb..0b9e35c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1413,6 +1413,7 @@ AC_CONFIG_FILES([
tests/bliptv/Makefile
tests/dleyna/Makefile
tests/dleyna/dbusmock/dleyna-server-mock.service
+ tests/lastfm-albumart/Makefile
tests/local-metadata/Makefile
tests/thetvdb/Makefile
tests/tmdb/Makefile
diff --git a/src/lastfm-albumart/Makefile.am b/src/lastfm-albumart/Makefile.am
index 603b518..29a347b 100644
--- a/src/lastfm-albumart/Makefile.am
+++ b/src/lastfm-albumart/Makefile.am
@@ -28,6 +28,15 @@ extdir = $(GRL_PLUGINS_DIR)
lastfmalbumartxmldir = $(GRL_PLUGINS_DIR)
lastfmalbumartxml_DATA = $(LASTFM_ALBUMART_PLUGIN_ID).xml
+# This lets us test the plugin without installing it,
+# because grilo expects the .so and .xml files to be in
+# the same directory:
+copy-xml-to-libs-dir: libgrllastfm-albumart.la
+ cp -f $(srcdir)/$(lastfmalbumartxml_DATA) $(builddir)/.libs/
+
+all-local: copy-xml-to-libs-dir
+
+
EXTRA_DIST = $(lastfmalbumartxml_DATA)
MAINTAINERCLEANFILES = \
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 647a531..8230b5d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -21,6 +21,10 @@ if DLEYNA_PLUGIN
SUBDIRS += dleyna
endif
+if LASTFM_ALBUMART_PLUGIN
+SUBDIRS += lastfm-albumart
+endif
+
if LOCALMETADATA_PLUGIN
SUBDIRS += local-metadata
endif
@@ -41,6 +45,7 @@ DIST_SUBDIRS = \
apple-trailers \
bliptv \
dleyna \
+ lastfm-albumart\
local-metadata \
tmdb \
thetvdb \
diff --git a/tests/lastfm-albumart/Makefile.am b/tests/lastfm-albumart/Makefile.am
new file mode 100644
index 0000000..6bb19f7
--- /dev/null
+++ b/tests/lastfm-albumart/Makefile.am
@@ -0,0 +1,40 @@
+#
+# Makefile.am
+#
+# Author: Juan A. Suarez Romero <jasuarez igalia com>
+#
+# Copyright (C) 2014 Igalia S.L.
+
+include $(top_srcdir)/gtester.mk
+
+INCLUDES = @DEPS_CFLAGS@
+
+TEST_PROGS += \
+ test_lastfm_albumart
+
+test_lastfm_albumart_defines = \
+ -DLASTFM_ALBUMART_PLUGIN_PATH=\""$(abs_top_builddir)/src/lastfm-albumart/.libs/"\" \
+ -DLASTFM_ALBUMART_DATA_PATH=\""$(abs_top_srcdir)/tests/lastfm-albumart/data/"\"
+
+test_lastfm_albumart_SOURCES = \
+ test_lastfm_albumart.c
+
+test_lastfm_albumart_LDADD = \
+ @DEPS_LIBS@
+
+test_lastfm_albumart_CFLAGS = \
+ $(test_lastfm_albumart_defines)
+
+# Distribute the tests data:
+dist_noinst_DATA = \
+ data/network-data.ini \
+ data/resolve-good-found.data \
+ data/resolve-good-found-default.data
+
+noinst_PROGRAMS = $(TEST_PROGS)
+
+MAINTAINERCLEANFILES = \
+ *.in \
+ *~
+
+DISTCLEANFILES = $(MAINTAINERCLEANFILES)
diff --git a/tests/lastfm-albumart/data/network-data.ini b/tests/lastfm-albumart/data/network-data.ini
new file mode 100644
index 0000000..7ac986c
--- /dev/null
+++ b/tests/lastfm-albumart/data/network-data.ini
@@ -0,0 +1,11 @@
+[default]
+version=1
+
+[http://ws.audioscrobbler.com/1.0/album/madonna/frozen/info.xml]
+data=resolve-good-found.data
+
+[http://ws.audioscrobbler.com/1.0/album/madonna/frocen/info.xml]
+data=resolve-good-found-default.data
+
+[http://ws.audioscrobbler.com/1.0/album/madonna/unknown/info.xml]
+data=
diff --git a/tests/lastfm-albumart/data/resolve-good-found-default.data
b/tests/lastfm-albumart/data/resolve-good-found-default.data
new file mode 100644
index 0000000..943005d
--- /dev/null
+++ b/tests/lastfm-albumart/data/resolve-good-found-default.data
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<album artist="Madonna" title="Frocen">
+ <reach>1</reach>
+ <url>http://www.last.fm/music/Madonna/Frocen</url>
+ <releasedate> </releasedate>
+ <coverart>
+ <small>http://cdn.last.fm/flatness/catalogue/noimage/2/default_album_medium.png</small>
+ <medium>http://cdn.last.fm/flatness/catalogue/noimage/2/default_album_medium.png</medium>
+ <large>http://cdn.last.fm/flatness/catalogue/noimage/2/default_album_medium.png</large>
+ </coverart>
+ <mbid></mbid>
+ <tracks>
+ </tracks>
+</album>
\ No newline at end of file
diff --git a/tests/lastfm-albumart/data/resolve-good-found.data
b/tests/lastfm-albumart/data/resolve-good-found.data
new file mode 100644
index 0000000..c00ed82
--- /dev/null
+++ b/tests/lastfm-albumart/data/resolve-good-found.data
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<album artist="Madonna" title="Frozen">
+ <reach>20831</reach>
+ <url>http://www.last.fm/music/Madonna/Frozen</url>
+ <releasedate> 17 Mar 1998, 00:00</releasedate>
+ <coverart>
+ <small>http://userserve-ak.last.fm/serve/34s/76737256.png</small>
+ <medium>http://userserve-ak.last.fm/serve/64s/76737256.png</medium>
+ <large>http://userserve-ak.last.fm/serve/126/76737256.png</large>
+ </coverart>
+ <mbid>e911cad9-dc8f-4134-8438-c392b9cf1a58</mbid>
+ <tracks>
+ <track title="Frozen">
+ <reach>388796</reach>
+ <url>http://www.last.fm/music/Madonna/_/Frozen</url>
+ </track>
+ <track title="Don't Cry for Me Argentina">
+ <reach>55360</reach>
+ <url>http://www.last.fm/music/Madonna/_/Don%27t+Cry+for+Me+Argentina</url>
+ </track>
+ <track title="Like a Prayer">
+ <reach>487462</reach>
+ <url>http://www.last.fm/music/Madonna/_/Like+a+Prayer</url>
+ </track>
+ <track title="You'll See">
+ <reach>68196</reach>
+ <url>http://www.last.fm/music/Madonna/_/You%27ll+See</url>
+ </track>
+ <track title="Deeper and Deeper">
+ <reach>61639</reach>
+ <url>http://www.last.fm/music/Madonna/_/Deeper+and+Deeper</url>
+ </track>
+ <track title="La Isla Bonita">
+ <reach>321802</reach>
+ <url>http://www.last.fm/music/Madonna/_/La+Isla+Bonita</url>
+ </track>
+ <track title="Take A Bonita">
+ <reach>6</reach>
+ <url>http://www.last.fm/music/Madonna/_/Take+A+Bonita</url>
+ </track>
+ <track title="Holyday">
+ <reach>283</reach>
+ <url>http://www.last.fm/music/+noredirect/Madonna/_/Holyday</url>
+ </track>
+ <track title="Crazy for You">
+ <reach>167426</reach>
+ <url>http://www.last.fm/music/Madonna/_/Crazy+for+You</url>
+ </track>
+ <track title="Material Girl">
+ <reach>358192</reach>
+ <url>http://www.last.fm/music/Madonna/_/Material+Girl</url>
+ </track>
+ <track title="Causing a Commotion">
+ <reach>12784</reach>
+ <url>http://www.last.fm/music/Madonna/_/Causing+a+Commotion</url>
+ </track>
+ <track title="You Must Love Me">
+ <reach>27327</reach>
+ <url>http://www.last.fm/music/Madonna/_/You+Must+Love+Me</url>
+ </track>
+ <track title="Papa Don't Preach">
+ <reach>269903</reach>
+ <url>http://www.last.fm/music/Madonna/_/Papa+Don%27t+Preach</url>
+ </track>
+ <track title="Into The Groode">
+ <reach>1</reach>
+ <url>http://www.last.fm/music/Madonna/_/Into+The+Groode</url>
+ </track>
+ <track title="Open Your Heart">
+ <reach>169657</reach>
+ <url>http://www.last.fm/music/Madonna/_/Open+Your+Heart</url>
+ </track>
+ <track title="Live to Tell">
+ <reach>157781</reach>
+ <url>http://www.last.fm/music/Madonna/_/Live+to+Tell</url>
+ </track>
+ <track title="True Blue">
+ <reach>62135</reach>
+ <url>http://www.last.fm/music/Madonna/_/True+Blue</url>
+ </track>
+ </tracks>
+</album>
\ No newline at end of file
diff --git a/tests/lastfm-albumart/test_lastfm_albumart.c b/tests/lastfm-albumart/test_lastfm_albumart.c
new file mode 100644
index 0000000..c4831c1
--- /dev/null
+++ b/tests/lastfm-albumart/test_lastfm_albumart.c
@@ -0,0 +1,332 @@
+/*
+ * Copyright (C) 2014 Igalia S.L.
+ *
+ * Author: Juan A. Suarez Romero <jasuarez igalia 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>
+
+#define LASTFM_ALBUMART_ID "grl-lastfm-albumart"
+
+static GrlMedia *
+build_media_audio (const gchar *artist,
+ const gchar *album)
+{
+ GrlMedia *media;
+
+ media = grl_media_audio_new ();
+ grl_media_audio_set_artist (GRL_MEDIA_AUDIO (media), artist);
+ grl_media_audio_set_album (GRL_MEDIA_AUDIO (media), album);
+
+ return media;
+}
+
+static void
+test_setup (void)
+{
+ GError *error = NULL;
+ GrlRegistry *registry;
+
+ registry = grl_registry_get_default ();
+ grl_registry_load_all_plugins (registry, &error);
+ g_assert_no_error (error);
+}
+
+static void
+test_may_resolve_good (void)
+{
+ GList *missing_keys = NULL;
+ GrlMedia *media;
+ GrlRegistry *registry;
+ GrlSource *source;
+ gboolean can_resolve;
+
+ registry = grl_registry_get_default ();
+ source = grl_registry_lookup_source (registry, LASTFM_ALBUMART_ID);
+ g_assert (source);
+
+ media = build_media_audio ("My Artist", "My Album");
+
+ can_resolve = grl_source_may_resolve (source, media, GRL_METADATA_KEY_THUMBNAIL, &missing_keys);
+
+ g_assert (can_resolve);
+ g_assert (!missing_keys);
+
+ g_object_unref (media);
+}
+
+static void
+test_may_resolve_wrong_key (void)
+{
+ GList *missing_keys = NULL;
+ GrlMedia *media;
+ GrlRegistry *registry;
+ GrlSource *source;
+ gboolean can_resolve;
+
+ registry = grl_registry_get_default ();
+ source = grl_registry_lookup_source (registry, LASTFM_ALBUMART_ID);
+ g_assert (source);
+
+ media = build_media_audio ("My Artist", "My Album");
+
+ can_resolve = grl_source_may_resolve (source, media, GRL_METADATA_KEY_TITLE, &missing_keys);
+
+ g_assert (!can_resolve);
+ g_assert (!missing_keys);
+
+ g_object_unref (media);
+}
+
+static void
+test_may_resolve_missing_key (void)
+{
+ GList *missing_keys = NULL;
+ GrlMedia *media;
+ GrlRegistry *registry;
+ GrlSource *source;
+ gboolean can_resolve;
+
+ registry = grl_registry_get_default ();
+ source = grl_registry_lookup_source (registry, LASTFM_ALBUMART_ID);
+ g_assert (source);
+
+ media = build_media_audio ("My Artist", NULL);
+
+ can_resolve = grl_source_may_resolve (source, media, GRL_METADATA_KEY_THUMBNAIL, &missing_keys);
+
+ g_assert (!can_resolve);
+ g_assert_cmpint (g_list_length (missing_keys), ==, 1);
+ g_assert (GRLPOINTER_TO_KEYID (missing_keys->data) == GRL_METADATA_KEY_ALBUM);
+
+ g_object_unref (media);
+}
+
+static void
+test_may_resolve_missing_media (void)
+{
+ GList *missing_keys = NULL;
+ GrlRegistry *registry;
+ GrlSource *source;
+ gboolean can_resolve;
+
+ registry = grl_registry_get_default ();
+ source = grl_registry_lookup_source (registry, LASTFM_ALBUMART_ID);
+ g_assert (source);
+
+ can_resolve = grl_source_may_resolve (source, NULL, GRL_METADATA_KEY_THUMBNAIL, &missing_keys);
+
+ g_assert (!can_resolve);
+ g_assert_cmpint (g_list_length (missing_keys), ==, 2);
+ g_assert (GRLPOINTER_TO_KEYID (missing_keys->data) == GRL_METADATA_KEY_ARTIST ||
+ GRLPOINTER_TO_KEYID (missing_keys->data) == GRL_METADATA_KEY_ALBUM);
+ g_assert (GRLPOINTER_TO_KEYID (missing_keys->next->data) == GRL_METADATA_KEY_ARTIST ||
+ GRLPOINTER_TO_KEYID (missing_keys->next->data) == GRL_METADATA_KEY_ALBUM);
+ g_assert (GRLPOINTER_TO_KEYID (missing_keys->data) != GRLPOINTER_TO_KEYID (missing_keys->next->data));
+}
+
+static void
+test_resolve_good_found (void)
+{
+ GError *error = NULL;
+ GList *keys;
+ GrlMedia *media;
+ GrlOperationOptions *options;
+ GrlRegistry *registry;
+ GrlSource *source;
+ guint expected_n_thumbnails;
+
+ registry = grl_registry_get_default ();
+ source = grl_registry_lookup_source (registry, LASTFM_ALBUMART_ID);
+ g_assert (source);
+
+ media = build_media_audio ("madonna", "frozen");
+
+ keys = grl_metadata_key_list_new (GRL_METADATA_KEY_THUMBNAIL, NULL);
+
+ options = grl_operation_options_new (NULL);
+ grl_operation_options_set_flags (options, GRL_RESOLVE_FULL);
+
+ grl_source_resolve_sync (source, media, keys, options, &error);
+
+ g_assert_no_error (error);
+
+ /* We should get 5 thumbnails */
+ expected_n_thumbnails = grl_data_length (GRL_DATA (media), GRL_METADATA_KEY_THUMBNAIL);
+ g_assert_cmpuint (expected_n_thumbnails, ==, 5);
+ g_assert_cmpstr (grl_media_get_thumbnail_nth (media, 0),
+ ==,
+ "http://userserve-ak.last.fm/serve/500/76737256.png");
+ g_assert_cmpstr (grl_media_get_thumbnail_nth (media, 1),
+ ==,
+ "http://userserve-ak.last.fm/serve/252/76737256.png");
+ g_assert_cmpstr (grl_media_get_thumbnail_nth (media, 2),
+ ==,
+ "http://userserve-ak.last.fm/serve/126/76737256.png");
+ g_assert_cmpstr (grl_media_get_thumbnail_nth (media, 3),
+ ==,
+ "http://userserve-ak.last.fm/serve/64s/76737256.png");
+ g_assert_cmpstr (grl_media_get_thumbnail_nth (media, 4),
+ ==,
+ "http://userserve-ak.last.fm/serve/34s/76737256.png");
+
+ g_list_free (keys);
+ g_object_unref (options);
+ g_object_unref (media);
+}
+
+static void
+test_resolve_good_found_default (void)
+{
+ GError *error = NULL;
+ GList *keys;
+ GrlMedia *media;
+ GrlOperationOptions *options;
+ GrlRegistry *registry;
+ GrlSource *source;
+ guint expected_n_thumbnails;
+
+ registry = grl_registry_get_default ();
+ source = grl_registry_lookup_source (registry, LASTFM_ALBUMART_ID);
+ g_assert (source);
+
+ media = build_media_audio ("madonna", "frocen");
+
+ keys = grl_metadata_key_list_new (GRL_METADATA_KEY_THUMBNAIL, NULL);
+
+ options = grl_operation_options_new (NULL);
+ grl_operation_options_set_flags (options, GRL_RESOLVE_FULL);
+
+ grl_source_resolve_sync (source, media, keys, options, &error);
+
+ g_assert_no_error (error);
+
+ /* We should get 0 thumbnails */
+ expected_n_thumbnails = grl_data_length (GRL_DATA (media), GRL_METADATA_KEY_THUMBNAIL);
+ g_assert_cmpuint (expected_n_thumbnails, ==, 0);
+ g_assert (!grl_media_get_thumbnail (media));
+
+ g_list_free (keys);
+ g_object_unref (options);
+ g_object_unref (media);
+}
+
+static void
+test_resolve_good_not_found (void)
+{
+ GError *error = NULL;
+ GList *keys;
+ GrlMedia *media;
+ GrlOperationOptions *options;
+ GrlRegistry *registry;
+ GrlSource *source;
+ guint expected_n_thumbnails;
+
+ registry = grl_registry_get_default ();
+ source = grl_registry_lookup_source (registry, LASTFM_ALBUMART_ID);
+ g_assert (source);
+
+ media = build_media_audio ("madonna", "unknown");
+
+ keys = grl_metadata_key_list_new (GRL_METADATA_KEY_THUMBNAIL, NULL);
+
+ options = grl_operation_options_new (NULL);
+ grl_operation_options_set_flags (options, GRL_RESOLVE_FULL);
+
+ grl_source_resolve_sync (source, media, keys, options, &error);
+
+ g_assert_no_error (error);
+
+ /* We should get 0 thumbnails */
+ expected_n_thumbnails = grl_data_length (GRL_DATA (media), GRL_METADATA_KEY_THUMBNAIL);
+ g_assert_cmpuint (expected_n_thumbnails, ==, 0);
+ g_assert (!grl_media_get_thumbnail (media));
+
+ g_list_free (keys);
+ g_object_unref (options);
+ g_object_unref (media);
+}
+
+static void
+test_resolve_missing_key (void)
+{
+ GError *error = NULL;
+ GList *keys;
+ GrlMedia *media;
+ GrlOperationOptions *options;
+ GrlRegistry *registry;
+ GrlSource *source;
+ guint expected_n_thumbnails;
+
+ registry = grl_registry_get_default ();
+ source = grl_registry_lookup_source (registry, LASTFM_ALBUMART_ID);
+ g_assert (source);
+
+ media = build_media_audio ("madonna", NULL);
+
+ keys = grl_metadata_key_list_new (GRL_METADATA_KEY_THUMBNAIL, NULL);
+
+ options = grl_operation_options_new (NULL);
+ grl_operation_options_set_flags (options, GRL_RESOLVE_FULL);
+
+ grl_source_resolve_sync (source, media, keys, options, &error);
+
+ g_assert_no_error (error);
+
+ /* We should get 0 thumbnails */
+ expected_n_thumbnails = grl_data_length (GRL_DATA (media), GRL_METADATA_KEY_THUMBNAIL);
+ g_assert_cmpuint (expected_n_thumbnails, ==, 0);
+ g_assert (!grl_media_get_thumbnail (media));
+
+ g_list_free (keys);
+ g_object_unref (options);
+ g_object_unref (media);
+}
+
+int
+main(int argc, char **argv)
+{
+ g_setenv ("GRL_PLUGIN_PATH", LASTFM_ALBUMART_PLUGIN_PATH, TRUE);
+ g_setenv ("GRL_PLUGIN_LIST", LASTFM_ALBUMART_ID, TRUE);
+ g_setenv ("GRL_NET_MOCKED", LASTFM_ALBUMART_DATA_PATH "network-data.ini", TRUE);
+
+ grl_init (&argc, &argv);
+ g_test_init (&argc, &argv, NULL);
+
+#if !GLIB_CHECK_VERSION(2,32,0)
+ g_thread_init (NULL);
+#endif
+
+ test_setup ();
+
+ g_test_add_func ("/lastfm-albumart/may-resolve/good", test_may_resolve_good);
+ g_test_add_func ("/lastfm-albumart/may-resolve/wrong-key", test_may_resolve_wrong_key);
+ g_test_add_func ("/lastfm-albumart/may-resolve/missing-key", test_may_resolve_missing_key);
+ g_test_add_func ("/lastfm-albumart/may-resolve/missing-media", test_may_resolve_missing_media);
+ g_test_add_func ("/lastfm-albumart/resolve/good-found", test_resolve_good_found);
+ g_test_add_func ("/lastfm-albumart/resolve/good-found-default", test_resolve_good_found_default);
+ g_test_add_func ("/lastfm-albumart/resolve/good-not-found", test_resolve_good_not_found);
+ g_test_add_func ("/lastfm-albumart/resolve/missing-key", test_resolve_missing_key);
+
+ gint result = g_test_run ();
+
+ grl_deinit ();
+
+ return result;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]