core/tags/album: Add album_artwork_path() function
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
940d2d1dc2
commit
d0dddeacdb
|
@ -245,6 +245,19 @@ bool album_artwork_exists(struct album *album)
|
|||
return ret;
|
||||
}
|
||||
|
||||
gchar *album_artwork_path(struct album *album)
|
||||
{
|
||||
struct cache_file file;
|
||||
gchar *ret = NULL;
|
||||
|
||||
__album_init_file(album, &file);
|
||||
if (cache_file_exists(&file))
|
||||
ret = cache_file_path(&file);
|
||||
__album_deinit_file(&file);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_TESTING
|
||||
const struct db_ops *test_album_ops() { return &album_ops; }
|
||||
#endif /* CONFIG_TESTING */
|
||||
|
|
|
@ -49,6 +49,12 @@ int album_compare_year(struct album *, struct album *);
|
|||
/* Called to check if album artwork has been downloaded. */
|
||||
bool album_artwork_exists(struct album *);
|
||||
|
||||
/*
|
||||
* Called to find the path to an album's artwork.
|
||||
* This function returns a new string that MUST be freed with g_free().
|
||||
*/
|
||||
gchar *album_artwork_path(struct album *);
|
||||
|
||||
#ifdef CONFIG_TESTING
|
||||
const struct db_ops *test_album_ops();
|
||||
#endif /* CONFIG_TESTING */
|
||||
|
|
|
@ -102,12 +102,19 @@ static void test_album_db()
|
|||
static void test_album_artwork()
|
||||
{
|
||||
struct album *ocarina, *majora, *wind;
|
||||
gchar *o_path, *m_path, *w_path;
|
||||
struct artist *koji;
|
||||
const gchar *cache;
|
||||
|
||||
artist_db_init();
|
||||
idle_deinit();
|
||||
idle_init();
|
||||
|
||||
cache = g_get_user_cache_dir();
|
||||
o_path = g_build_filename(cache, "ocarina-test", "1998", "Ocarina of Time.jpg", NULL);
|
||||
m_path = g_build_filename(cache, "ocarina-test", "2000", "Majora's Mask.jpg", NULL);
|
||||
w_path = g_build_filename(cache, "ocarina-test", "0", "Wind Waker.jpg", NULL);
|
||||
|
||||
ocarina = album_find("Ocarina of Time", 1998);
|
||||
majora = album_find("Majora's Mask", 2000);
|
||||
wind = album_find("Wind Waker", 0);
|
||||
|
@ -117,13 +124,22 @@ static void test_album_artwork()
|
|||
test_equal(album_artwork_exists(ocarina), (bool)false);
|
||||
test_equal(album_artwork_exists(majora), (bool)false);
|
||||
test_equal(album_artwork_exists(wind), (bool)false);
|
||||
test_equal((void *)album_artwork_path(ocarina), NULL);
|
||||
test_equal((void *)album_artwork_path(majora), NULL);
|
||||
test_equal((void *)album_artwork_path(wind), NULL);
|
||||
|
||||
while (idle_run_task()) {}
|
||||
|
||||
test_equal(album_artwork_exists(ocarina), (bool)true);
|
||||
test_equal(album_artwork_exists(majora), (bool)true);
|
||||
test_equal(album_artwork_exists(wind), (bool)true);
|
||||
test_str_equal(album_artwork_path(ocarina), o_path);
|
||||
test_str_equal(album_artwork_path(majora), m_path);
|
||||
test_str_equal(album_artwork_path(wind), w_path);
|
||||
|
||||
g_free(o_path);
|
||||
g_free(m_path);
|
||||
g_free(w_path);
|
||||
album_db_deinit();
|
||||
artist_db_deinit();
|
||||
idle_deinit();
|
||||
|
|
Loading…
Reference in New Issue