diff options
Diffstat (limited to 'tests/mediaarttest.c')
-rw-r--r-- | tests/mediaarttest.c | 157 |
1 files changed, 119 insertions, 38 deletions
diff --git a/tests/mediaarttest.c b/tests/mediaarttest.c index 3690335..09cc1ae 100644 --- a/tests/mediaarttest.c +++ b/tests/mediaarttest.c @@ -76,9 +76,17 @@ struct { }; static void -test_mediaart_init (void) +test_mediaart_new (void) { - g_assert_true (media_art_init ()); + MediaArtProcess *process; + GError *error = NULL; + + /* Test: creation of object */ + process = media_art_process_new (&error); + g_assert_no_error (error); + g_assert (process != NULL); + + g_object_unref (process); } static void @@ -97,11 +105,6 @@ test_mediaart_stripping (void) } static void -test_mediaart_stripping_null (void) -{ -} - -static void test_mediaart_stripping_failures_subprocess (void) { g_assert (!media_art_strip_invalid_entities (NULL)); @@ -150,8 +153,6 @@ test_mediaart_location (void) g_free (local_uri); } g_print ("(%d test cases) ", i); - - } static void @@ -160,8 +161,13 @@ test_mediaart_location_null (void) gchar *path = NULL, *local_uri = NULL; /* NULL parameters */ - media_art_get_path (NULL, NULL, "album", "file:///a/b/c.mp3", &path, &local_uri); - g_assert (!path && !local_uri); + media_art_get_path (NULL, "some-title", "album", "file:///a/b/c.mp3", &path, &local_uri); + g_assert (path != NULL); + g_assert (local_uri != NULL); + + media_art_get_path ("some-artist", NULL, "album", "file:///a/b/c.mp3", &path, &local_uri); + g_assert (path != NULL); + g_assert (local_uri != NULL); } static void @@ -192,35 +198,41 @@ test_mediaart_location_path (void) static void test_mediaart_embedded_mp3 (void) { + MediaArtProcess *process; GError *error = NULL; GFile *file = NULL; gchar *dir, *path; gboolean retval; - /* FIXME: Handle 'buffer' AND 'file/path', is broken currently */ - dir = g_get_current_dir (); path = g_build_filename (G_DIR_SEPARATOR_S, dir, "543249_King-Kilo---Radium.mp3", NULL); file = g_file_new_for_path (path); g_free (path); - retval = media_art_process_file (NULL, - 0, - "audio/mp3", /* mime */ + process = media_art_process_new (&error); + g_assert_no_error (error); + + retval = media_art_process_file (process, MEDIA_ART_ALBUM, + MEDIA_ART_PROCESS_FLAGS_FORCE, + file, "King Kilo", /* artist */ - "Lanedo", /* title */ - file); + "Radium", /* title */ + &error); + g_assert_no_error (error); g_assert_true (retval); g_object_unref (file); g_free (dir); + + g_object_unref (process); } static void -test_mediaart_png (void) +test_mediaart_process_buffer (void) { + MediaArtProcess *process; GError *error = NULL; GFile *file = NULL; gchar *dir, *path; @@ -230,14 +242,17 @@ test_mediaart_png (void) gboolean retval; dir = g_get_current_dir (); - path = g_build_filename (G_DIR_SEPARATOR_S, dir, "LanedoIconHKS43-64².png", NULL); + path = g_build_filename (G_DIR_SEPARATOR_S, dir, "cover.png", NULL); file = g_file_new_for_path (path); g_free (dir); + 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 */ - NULL, /* prefix */ + NULL, /* album */ + NULL, /* prefix */ path, &out_path, &out_uri); @@ -246,20 +261,20 @@ test_mediaart_png (void) g_free (out_uri); /* Process data */ - retval = media_art_process_file (NULL, - 0, - "image/png", /* mime */ + retval = media_art_process_file (process, MEDIA_ART_ALBUM, - NULL, /* album */ - "Lanedo", /* title */ - file); - + MEDIA_ART_PROCESS_FLAGS_NONE, + file, + NULL, /* album */ + "Lanedo", /* title */ + &error); + g_assert_no_error (error); g_assert_true (retval); /* Check cache exists */ media_art_get_path ("Lanedo", /* artist / title */ - NULL, /* album */ - NULL, /* prefix */ + NULL, /* album */ + NULL, /* prefix */ path, &out_path, &out_uri); @@ -274,7 +289,7 @@ test_mediaart_png (void) /* FIXME: Why does this next test fail - i.e. file does not * exist if we've processed it? */ - /* g_assert (g_file_test (out_path, G_FILE_TEST_EXISTS) == TRUE); */ + g_assert (g_file_test (out_path, G_FILE_TEST_EXISTS) == TRUE); g_free (out_path); g_free (out_uri); @@ -288,6 +303,70 @@ test_mediaart_png (void) g_object_unref (file); g_free (path); + + g_object_unref (process); +} + +static void +test_mediaart_process_failures (void) +{ + MediaArtProcess *process; + GError *error = NULL; + + g_test_trap_subprocess ("/mediaart/process_failures/subprocess", 0, 0 /*G_TEST_SUBPROCESS_INHERIT_STDOUT | G_TEST_SUBPROCESS_INHERIT_STDERR*/); + g_test_trap_assert_failed (); + g_test_trap_assert_stderr ("*assertion 'uri != NULL' failed*"); + + process = media_art_process_new (&error); + g_assert_no_error (error); + + /* Test: invalid file */ + g_assert (!media_art_process_uri (process, + MEDIA_ART_ALBUM, + MEDIA_ART_PROCESS_FLAGS_NONE, + "file:///invalid/path.png", + "Foo", /* album */ + "Bar", /* title */ + &error)); + + g_assert_error (error, g_io_error_quark(), G_IO_ERROR_NOT_FOUND); + g_clear_error (&error); + + /* Test: Invalid mime type */ + /* g_assert (!media_art_process_uri (process, */ + /* "file:///invalid/path.png", */ + /* NULL, */ + /* 0, */ + /* "image/png", /\* mime *\/ */ + /* MEDIA_ART_ALBUM, */ + /* "Foo", /\* album *\/ */ + /* "Bar", /\* title *\/ */ + /* &error)); */ + + /* g_message ("code:%d, domain:%d, error:'%s'\n", error->code, error->domain, error->message); */ + + g_object_unref (process); +} + +static void +test_mediaart_process_failures_subprocess (void) +{ + MediaArtProcess *process; + GError *error = NULL; + + process = media_art_process_new (&error); + g_assert_no_error (error); + + g_assert (!media_art_process_uri (process, + MEDIA_ART_ALBUM, + MEDIA_ART_PROCESS_FLAGS_NONE, + NULL, + "Foo", /* album */ + "Bar", /* title */ + &error)); + g_assert_no_error (error); + + g_object_unref (process); } int @@ -297,8 +376,8 @@ main (int argc, char **argv) g_test_init (&argc, &argv, NULL); - g_test_add_func ("/mediaart/init", - test_mediaart_init); + g_test_add_func ("/mediaart/new", + test_mediaart_new); g_test_add_func ("/mediaart/stripping", test_mediaart_stripping); g_test_add_func ("/mediaart/stripping_failures", @@ -313,12 +392,14 @@ main (int argc, char **argv) test_mediaart_location_path); g_test_add_func ("/mediaart/embedded_mp3", test_mediaart_embedded_mp3); - g_test_add_func ("/mediaart/png", - test_mediaart_png); + g_test_add_func ("/mediaart/process_buffer", + test_mediaart_process_buffer); + g_test_add_func ("/mediaart/process_failures", + test_mediaart_process_failures); + g_test_add_func ("/mediaart/process_failures/subprocess", + test_mediaart_process_failures_subprocess); success = g_test_run (); - media_art_shutdown (); - return success; } |