summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMartyn Russell <martyn@lanedo.com>2014-09-10 11:26:11 +0100
committerMartyn Russell <martyn@lanedo.com>2014-10-17 11:23:44 +0100
commitcdc1168b4fadeb2f8bb37c34c2b533eb2837934c (patch)
tree4f0922f9b0ff3c812e5807264c936a934e166873 /tests
parent969517fa94c76e300b4cbaeb8d03e23204907917 (diff)
downloadlibmediaart-cdc1168b4fadeb2f8bb37c34c2b533eb2837934c.tar.gz
cache: Added media_art_remove_async() and _finish()
Part of this API changes makes the media_art_get_{path|file}() APIs not do i/o operations like creating the cache directory. This is now done in media_art_process_new(). https://bugzilla.gnome.org/show_bug.cgi?id=724879
Diffstat (limited to 'tests')
-rw-r--r--tests/mediaarttest.c61
1 files changed, 49 insertions, 12 deletions
diff --git a/tests/mediaarttest.c b/tests/mediaarttest.c
index df34497..22694b6 100644
--- a/tests/mediaarttest.c
+++ b/tests/mediaarttest.c
@@ -23,6 +23,7 @@
#include <stdlib.h>
#include <glib-object.h>
+#include <glib/gstdio.h>
#include <libmediaart/mediaart.h>
@@ -239,11 +240,33 @@ test_mediaart_embedded_mp3 (void)
}
static void
+test_mediaart_remove_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GError *error = NULL;
+ GFile *file = user_data;
+ gboolean success;
+
+ success = media_art_remove_finish (source_object, result, &error);
+ g_assert_no_error (error);
+ g_assert_true (success);
+
+ success = media_art_remove ("Lanedo", NULL, NULL, &error);
+ g_assert_no_error (error);
+ g_assert_true (success);
+
+ g_object_unref (file);
+}
+
+static void
test_mediaart_process_buffer (void)
{
MediaArtProcess *process;
+ GCancellable *cancellable;
GError *error = NULL;
GFile *file = NULL;
+ gchar *dir;
gchar *path;
gchar *out_path = NULL;
gchar *out_uri = NULL;
@@ -253,9 +276,6 @@ test_mediaart_process_buffer (void)
path = g_build_filename (G_DIR_SEPARATOR_S, TOP_SRCDIR, "tests", "cover.png", NULL);
file = g_file_new_for_path (path);
- process = media_art_process_new (&error);
- g_assert_no_error (error);
-
/* Check data is not cached currently */
media_art_get_path ("Lanedo", /* artist / title */
NULL, /* album */
@@ -263,10 +283,18 @@ test_mediaart_process_buffer (void)
path,
&out_path,
&out_uri);
- g_assert (g_file_test (out_path, G_FILE_TEST_EXISTS) == FALSE);
+ g_assert_false (g_file_test (out_path, G_FILE_TEST_EXISTS));
g_free (out_path);
g_free (out_uri);
+ /* Creates media-art cache dir if it doesn't exist ... */
+ process = media_art_process_new (&error);
+ g_assert_no_error (error);
+
+ dir = g_build_filename (g_get_user_cache_dir (), "media-art", NULL);
+ g_assert_true (g_file_test (dir, G_FILE_TEST_EXISTS));
+ g_free (dir);
+
/* Process data */
retval = media_art_process_file (process,
MEDIA_ART_ALBUM,
@@ -303,14 +331,17 @@ test_mediaart_process_buffer (void)
g_free (expected);
/* Remove album art */
- retval = media_art_remove ("Lanedo", "");
- g_assert_true (retval);
-
- retval = media_art_remove ("Lanedo", NULL);
-
- g_object_unref (file);
+ cancellable = g_cancellable_new ();
+ media_art_remove_async ("Lanedo",
+ "",
+ G_PRIORITY_DEFAULT,
+ G_OBJECT (process),
+ cancellable,
+ test_mediaart_remove_cb,
+ file);
+
+ g_object_unref (cancellable);
g_free (path);
-
g_object_unref (process);
}
@@ -381,7 +412,8 @@ main (int argc, char **argv)
{
const gchar *cache_home_originally;
const gchar *test_dir;
- gint success = EXIT_SUCCESS;
+ gchar *dir;
+ gint success;
gint i;
g_test_init (&argc, &argv, NULL);
@@ -420,6 +452,11 @@ main (int argc, char **argv)
success = g_test_run ();
+ /* Clean up */
+ dir = g_build_filename (g_get_user_cache_dir (), "media-art", NULL);
+ g_rmdir (dir);
+ g_free (dir);
+
if (cache_home_originally) {
g_setenv ("XDG_CACHE_HOME", cache_home_originally, TRUE);
} else {