[grilo-plugins] chromaprint: include tests for this plugin
- From: Victor Toso de Carvalho <victortoso src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [grilo-plugins] chromaprint: include tests for this plugin
- Date: Mon, 30 May 2016 12:05:16 +0000 (UTC)
commit b93248ec56b1f3545f1cbbd0ce18cd0f3b4d20ee
Author: Victor Toso <me victortoso com>
Date: Mon Jul 7 23:07:48 2014 -0300
chromaprint: include tests for this plugin
At this moment, only testing audio metadata from two small music files
attached to the tests
https://bugzilla.gnome.org/show_bug.cgi?id=732879
configure.ac | 1 +
tests/Makefile.am | 5 +
tests/chromaprint/Makefile.am | 34 +++++++
tests/chromaprint/data/sample.flac | Bin 0 -> 196902 bytes
tests/chromaprint/data/sample.ogg | Bin 0 -> 10622 bytes
tests/chromaprint/test_chromaprint_resolve.c | 124 ++++++++++++++++++++++++++
tests/chromaprint/test_chromaprint_utils.c | 62 +++++++++++++
tests/chromaprint/test_chromaprint_utils.h | 35 +++++++
8 files changed, 261 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index a8c51c9..1ddef0e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1368,6 +1368,7 @@ AC_CONFIG_FILES([
src/vimeo/Makefile
src/youtube/Makefile
tests/Makefile
+ tests/chromaprint/Makefile
tests/dleyna/Makefile
tests/dleyna/dbusmock/dleyna-server-mock.service
tests/spotify-cover/Makefile
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 5ed6c85..07eabb7 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -9,6 +9,10 @@ include $(top_srcdir)/gtester.mk
SUBDIRS =
+if CHROMAPRINT_PLUGIN
+SUBDIRS += chromaprint
+endif
+
if DLEYNA_PLUGIN
SUBDIRS += dleyna
endif
@@ -38,6 +42,7 @@ endif
DIST_SUBDIRS = \
dleyna \
games \
+ chromaprint \
spotify-cover \
local-metadata \
lua-factory \
diff --git a/tests/chromaprint/Makefile.am b/tests/chromaprint/Makefile.am
new file mode 100644
index 0000000..a1bf3db
--- /dev/null
+++ b/tests/chromaprint/Makefile.am
@@ -0,0 +1,34 @@
+#
+# Makefile.am
+#
+# Author: Victor Toso <me victortoso com>
+#
+# Copyright (C) 2016 Grilo Project
+
+include $(top_srcdir)/gtester.mk
+
+TEST_PROGS += \
+ test_chromaprint_resolve
+
+test_chromaprint_defines = \
+ -DCHROMAPRINT_PLUGIN_PATH=\""$(abs_top_builddir)/src/chromaprint/.libs/"\" \
+ -DCHROMAPRINT_PLUGIN_TEST_DATA_PATH=\""$(abs_top_srcdir)/tests/chromaprint/data/"\"
+
+test_chromaprint_resolve_SOURCES = \
+ test_chromaprint_resolve.c \
+ test_chromaprint_utils.h test_chromaprint_utils.c
+
+test_chromaprint_resolve_LDADD = \
+ @DEPS_LIBS@
+
+test_chromaprint_resolve_CFLAGS = \
+ @DEPS_CFLAGS@ \
+ $(test_chromaprint_defines)
+
+dist_noinst_DATA = \
+ data/sample.flac \
+ data/sample.ogg
+
+noinst_PROGRAMS = $(TEST_PROGS)
+
+-include $(top_srcdir)/git.mk
diff --git a/tests/chromaprint/data/sample.flac b/tests/chromaprint/data/sample.flac
new file mode 100644
index 0000000..38ce954
Binary files /dev/null and b/tests/chromaprint/data/sample.flac differ
diff --git a/tests/chromaprint/data/sample.ogg b/tests/chromaprint/data/sample.ogg
new file mode 100644
index 0000000..d0c7ad5
Binary files /dev/null and b/tests/chromaprint/data/sample.ogg differ
diff --git a/tests/chromaprint/test_chromaprint_resolve.c b/tests/chromaprint/test_chromaprint_resolve.c
new file mode 100644
index 0000000..499e9ed
--- /dev/null
+++ b/tests/chromaprint/test_chromaprint_resolve.c
@@ -0,0 +1,124 @@
+/*
+ * Copyright (C) 2016 Grilo Project
+ *
+ * Author: Victor Toso <me victortoso 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_chromaprint_utils.h"
+#include <grilo.h>
+
+static void
+get_chromaprint_fingerprint (GrlSource *source,
+ const gchar *url,
+ gint *duration,
+ gchar **fingerprint)
+{
+ GrlMedia *audio;
+ GrlOperationOptions *options;
+ GList *keys;
+ GrlRegistry *registry;
+ GrlKeyID key_fingerprint;
+
+ registry = grl_registry_get_default ();
+
+ key_fingerprint = grl_registry_lookup_metadata_key (registry, "chromaprint");
+ g_assert_cmpint (key_fingerprint, !=, GRL_METADATA_KEY_INVALID);
+
+ audio = grl_media_audio_new ();
+ grl_media_set_url (audio, url);
+
+ keys = grl_metadata_key_list_new (key_fingerprint,
+ GRL_METADATA_KEY_DURATION,
+ GRL_METADATA_KEY_INVALID);
+ options = grl_operation_options_new (NULL);
+ grl_operation_options_set_resolution_flags (options, GRL_RESOLVE_NORMAL);
+
+ grl_source_resolve_sync (source,
+ GRL_MEDIA (audio),
+ keys,
+ options,
+ NULL);
+
+ *duration = grl_media_get_duration (GRL_MEDIA (audio));
+ *fingerprint = g_strdup (grl_data_get_string (GRL_DATA (audio),
+ key_fingerprint));
+ g_list_free (keys);
+ g_object_unref (options);
+ g_object_unref (audio);
+}
+
+static void
+test_fingerprint (void)
+{
+ GrlSource *source;
+ guint i;
+
+ /* FIXME: We should probably check in the tests if tester has decoder
+ * for flac and ogg */
+
+ struct {
+ gchar *url;
+ gint duration;
+ gchar *fingerprint;
+ } audios[] = {
+ { CHROMAPRINT_PLUGIN_TEST_DATA_PATH "sample.flac", 5,
+
"AQAAF1miRNLCKAkafjhUscij5DjFpOgz44N39Mmx-xHyHOfmCNOPZjJOLceP5tA6KRf-473xJMUPRoIDAkqCBEEGCCYAUpYQAQgxSAE" },
+ { CHROMAPRINT_PLUGIN_TEST_DATA_PATH "sample.ogg", 4,
+ "AQAADlQ0JaGihBgpvWicED98hOTxhNCRb7i24RYZNMmEakpY_AGAABTMS0eIAw" }
+ };
+
+ source = test_get_source ();
+ g_assert (source);
+
+ for (i = 0; i < G_N_ELEMENTS (audios); i++) {
+ gchar *fingerprint = NULL;
+ gint duration;
+
+ get_chromaprint_fingerprint (source, audios[i].url, &duration, &fingerprint);
+ g_assert_cmpint (audios[i].duration, ==, duration);
+ g_assert_cmpstr (audios[i].fingerprint, ==, fingerprint);
+ g_clear_pointer (&fingerprint, g_free);
+ }
+}
+
+gint
+main (gint argc, gchar **argv)
+{
+ g_setenv ("GRL_PLUGIN_PATH", CHROMAPRINT_PLUGIN_PATH, TRUE);
+ g_setenv ("GRL_PLUGIN_LIST", CHROMAPRINT_ID, 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_chromaprint ();
+
+ g_test_add_func ("/chromaprint/resolve/fingerprint", test_fingerprint);
+
+ gint result = g_test_run ();
+
+ test_shutdown_chromaprint ();
+
+ grl_deinit ();
+
+ return result;
+}
diff --git a/tests/chromaprint/test_chromaprint_utils.c b/tests/chromaprint/test_chromaprint_utils.c
new file mode 100644
index 0000000..505e0c5
--- /dev/null
+++ b/tests/chromaprint/test_chromaprint_utils.c
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2016 Grilo Project
+ *
+ * Author: Victor Toso <me victortoso 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_chromaprint_utils.h"
+
+GrlSource *source = NULL;
+
+void
+test_setup_chromaprint (void)
+{
+ GrlRegistry *registry;
+ GError *error = NULL;
+
+ registry = grl_registry_get_default ();
+ grl_registry_load_plugin (registry,
+ CHROMAPRINT_PLUGIN_PATH "libgrlchromaprint.so",
+ &error);
+ g_assert_no_error (error);
+ grl_registry_activate_plugin_by_id (registry, CHROMAPRINT_ID, &error);
+ g_assert_no_error (error);
+
+ source = GRL_SOURCE (grl_registry_lookup_source (registry, CHROMAPRINT_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_chromaprint (void)
+{
+ GrlRegistry *registry;
+ GError *error = NULL;
+
+ registry = grl_registry_get_default ();
+ grl_registry_unload_plugin (registry, CHROMAPRINT_ID, &error);
+ g_assert_no_error (error);
+}
diff --git a/tests/chromaprint/test_chromaprint_utils.h b/tests/chromaprint/test_chromaprint_utils.h
new file mode 100644
index 0000000..22cfe7f
--- /dev/null
+++ b/tests/chromaprint/test_chromaprint_utils.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2016 Grilo Project
+ *
+ * Author: Victor Toso <me victortoso 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_CHROMAPRINT_TEST_UTILS_H_
+#define _GRL_CHROMAPRINT_TEST_UTILS_H_
+
+#include <grilo.h>
+
+#define CHROMAPRINT_ID "grl-chromaprint"
+#define TEST_PATH "data/"
+
+void test_setup_chromaprint (void);
+GrlSource* test_get_source (void);
+void test_shutdown_chromaprint (void);
+
+#endif /* _GRL_CHROMAPRINT_TEST_UTILS_H_ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]