[tracker/media-art-enhancements] tests/libtracker-extract: Add initial tracker-media-art test
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/media-art-enhancements] tests/libtracker-extract: Add initial tracker-media-art test
- Date: Mon, 13 Feb 2012 20:45:09 +0000 (UTC)
commit afe10076aa1773bfaf23a409315fe4fb97dccf6f
Author: Sam Thursfield <sam thursfield codethink co uk>
Date: Tue Sep 27 17:46:43 2011 +0100
tests/libtracker-extract: Add initial tracker-media-art test
tests/libtracker-extract/.gitignore | 1 +
tests/libtracker-extract/Makefile.am | 3 +
tests/libtracker-extract/tracker-media-art-test.c | 258 +++++++++++++++++++++
3 files changed, 262 insertions(+), 0 deletions(-)
---
diff --git a/tests/libtracker-extract/.gitignore b/tests/libtracker-extract/.gitignore
index d3fbec9..e8c9653 100644
--- a/tests/libtracker-extract/.gitignore
+++ b/tests/libtracker-extract/.gitignore
@@ -1,4 +1,5 @@
tracker-encoding
+tracker-media-art
tracker-test-utils
tracker-test-xmp
tracker-exif-test
diff --git a/tests/libtracker-extract/Makefile.am b/tests/libtracker-extract/Makefile.am
index 57cde15..6df0ef5 100644
--- a/tests/libtracker-extract/Makefile.am
+++ b/tests/libtracker-extract/Makefile.am
@@ -3,6 +3,7 @@ include $(top_srcdir)/Makefile.decl
noinst_PROGRAMS = $(TEST_PROGS)
TEST_PROGS += \
+ tracker-media-art \
tracker-test-utils \
tracker-test-xmp \
tracker-extract-info-test \
@@ -41,6 +42,8 @@ LDADD = \
tracker_encoding_SOURCES = tracker-encoding-test.c
+tracker_media_art_SOURCES = tracker-media-art-test.c
+
tracker_test_utils_SOURCES = tracker-test-utils.c
tracker_test_xmp_SOURCES = tracker-test-xmp.c
diff --git a/tests/libtracker-extract/tracker-media-art-test.c b/tests/libtracker-extract/tracker-media-art-test.c
new file mode 100644
index 0000000..792d904
--- /dev/null
+++ b/tests/libtracker-extract/tracker-media-art-test.c
@@ -0,0 +1,258 @@
+/*
+ * Copyright (C) 2011, Nokia <ivan frade nokia com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * Author: Sam Thursfield <sam thursfield codethink co uk>
+ */
+
+#include "config.h"
+
+#include <time.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <glib-object.h>
+
+#include <libtracker-extract/tracker-extract.h>
+
+#include <tracker-test-helpers.h>
+
+typedef struct {
+ const gchar *media_file;
+ const gchar *type;
+ const gchar *artist;
+ const gchar *title;
+ const gchar *expected_result;
+ const gchar *tree[];
+} ExternalMediaArtTestCase;
+
+/* Build a fake directory tree inside /tmp for the media art finder to
+ * look through
+ */
+static void
+set_up_directory_tree (const ExternalMediaArtTestCase *test,
+ const gchar *root_dir_path)
+{
+ const gchar * const *tree_item;
+ GError *error = NULL;
+
+ for (tree_item = test->tree; *tree_item != NULL; tree_item ++) {
+ gchar *file_path;
+ GFile *file, *dir;
+ GFileOutputStream *file_stream;
+
+ file_path = g_build_filename (root_dir_path, *tree_item, NULL);
+ file = g_file_new_for_path (file_path);
+
+ dir = g_file_get_parent (file);
+ if (!g_file_query_exists (dir, NULL)) {
+ g_file_make_directory_with_parents (dir, NULL, &error);
+ }
+
+ file_stream = g_file_create (file, G_FILE_CREATE_NONE, NULL, &error);
+ g_output_stream_write (G_OUTPUT_STREAM (file_stream), "test\n", 5, NULL, &error);
+
+ g_assert_no_error (error);
+
+ g_object_unref (file_stream);
+ g_object_unref (dir);
+ g_object_unref (file);
+ g_free (file_path);
+ }
+}
+
+static void
+rm_tree (GFile *dir)
+{
+ GFileEnumerator *e;
+ GFileInfo *file_info;
+ GFile *file;
+ GError *error = NULL;
+
+ e = g_file_enumerate_children (dir,
+ "standard::*",
+ G_FILE_QUERY_INFO_NONE,
+ NULL,
+ &error);
+
+ while ((file_info = g_file_enumerator_next_file (e, NULL, &error))) {
+ file = g_file_get_child (dir, g_file_info_get_name (file_info));
+ if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_DIRECTORY) {
+ rm_tree (file);
+ } else {
+ g_file_delete (file, NULL, &error);
+ }
+
+ g_assert_no_error (error);
+
+ g_object_unref (file);
+ g_object_unref (file_info);
+ }
+
+ g_object_unref (e);
+
+ g_file_delete (dir, NULL, &error);
+
+ g_assert_no_error (error);
+}
+
+static void
+run_external_media_art_test (const ExternalMediaArtTestCase *test)
+{
+ gchar *root_dir_path;
+ GFile *root_dir;
+ gchar *media_file_path;
+ gchar *media_file_uri;
+ gchar *art_file_path;
+ GError *error = NULL;
+
+ root_dir_path = tempnam (NULL, "test-");
+ root_dir = g_file_new_for_path (root_dir_path);
+
+ /* Construct test directory */
+ set_up_directory_tree (test, root_dir_path);
+
+ media_file_path = g_build_filename (root_dir_path, test->media_file, NULL);
+ media_file_uri = g_filename_to_uri (media_file_path, NULL, &error);
+
+ g_assert_no_error (error);
+
+ /* Choose a file likely to be the media art */
+ art_file_path = tracker_find_external_media_art_for_file (media_file_uri,
+ test->artist,
+ test->title,
+ test->type);
+
+ /* Check result */
+ if (test->expected_result == NULL) {
+ if (art_file_path != NULL) {
+ g_error ("assertion failed: expected no art file, got %s",
+ art_file_path);
+ }
+ } else {
+ gchar *expected_path;
+
+ expected_path = g_build_filename (root_dir_path, test->expected_result, NULL);
+
+ if (g_ascii_strcasecmp (expected_path, art_file_path)) {
+ g_error ("assertion failed: expected art file %s, got %s",
+ test->expected_result, art_file_path);
+ }
+
+ g_free (expected_path);
+ }
+
+ g_free (art_file_path);
+ g_free (media_file_path);
+ g_free (media_file_uri);
+
+ rm_tree (root_dir);
+
+ g_object_unref (root_dir);
+ g_free (root_dir_path);
+}
+
+static void
+test_album_heuristic (void)
+{
+ static const ExternalMediaArtTestCase basic = {
+ "Track 1.mp3", "album", "Test Artist", "Track 1",
+ "folder.jpg",
+ {
+ "folder.jpg",
+ "Track 1.mp3",
+ "Track 2.mp3",
+ "Track 3.mp3",
+ NULL
+ }
+ };
+
+ static const ExternalMediaArtTestCase missing = {
+ "Track 1.mp3", "album", "Test Artist", "Track 1",
+ NULL, /* No result expected */
+ {
+ "folder.mp3",
+ "Track 1.mp3",
+ "Track 2.mp3",
+ "Track 3.mp3",
+ NULL
+ }
+ };
+
+ run_external_media_art_test (&basic);
+ run_external_media_art_test (&missing);
+}
+
+static void
+test_video_heuristic (void)
+{
+ static const ExternalMediaArtTestCase basic = {
+ "Episode 1 [SP WS].avi", "video", NULL, "Episode 1",
+ "My DVD.jpeg",
+ {
+ "My DVD.jpeg",
+ "Episode 1 [SP WS].srt",
+ "Episode 1 [SP WS].avi",
+ NULL
+ }
+ };
+
+ static const ExternalMediaArtTestCase negative_1 = {
+ "myfilm/myfilm.avi", "video", NULL, "myfilm",
+ NULL, /* No result expected */
+ {
+ "photo1.jpg",
+ "myfilm/myfilm.avi",
+ "yourfilm/yourfilm.avi",
+ NULL
+ }
+ };
+
+ static const ExternalMediaArtTestCase negative_2 = {
+ "random film.avi", "video", NULL, "random film",
+ NULL, /* No result expected */
+ {
+ "random picture.jpg",
+ "random film.avi",
+ "document.txt",
+ "photo of a dog.jpg",
+ NULL
+ }
+ };
+
+ run_external_media_art_test (&basic);
+ run_external_media_art_test (&negative_1);
+ run_external_media_art_test (&negative_2);
+}
+
+int
+main (int argc, char **argv)
+{
+ gint result;
+
+ g_type_init ();
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add_func ("/libtracker-extract/tracker-media-art/album-heuristic",
+ test_album_heuristic);
+ g_test_add_func ("/libtracker-extract/tracker-media-art/video-heuristic",
+ test_video_heuristic);
+
+ result = g_test_run ();
+
+ return result;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]