core/tags/album: Add album_artwork_exists() function
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
0d9b7baff6
commit
d79eb2c9b8
|
@ -4,9 +4,20 @@
|
||||||
#include <core/string.h>
|
#include <core/string.h>
|
||||||
#include <core/tags/album.h>
|
#include <core/tags/album.h>
|
||||||
|
|
||||||
|
|
||||||
static struct database album_db;
|
static struct database album_db;
|
||||||
|
|
||||||
|
static inline void __album_init_file(struct album *al, struct cache_file *f)
|
||||||
|
{
|
||||||
|
cache_file_init(f, g_strdup_printf("%d", al->al_year),
|
||||||
|
g_strdup_printf("%s.jpg", al->al_name));
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void __album_deinit_file(struct cache_file *f)
|
||||||
|
{
|
||||||
|
g_free(f->cf_subdir);
|
||||||
|
g_free(f->cf_name);
|
||||||
|
}
|
||||||
|
|
||||||
static gchar *__album_key(const gchar *name, unsigned int year)
|
static gchar *__album_key(const gchar *name, unsigned int year)
|
||||||
{
|
{
|
||||||
return g_strdup_printf("%u/%s", year, name);
|
return g_strdup_printf("%u/%s", year, name);
|
||||||
|
@ -113,6 +124,18 @@ int album_compare_year(struct album *lhs, struct album *rhs)
|
||||||
return lhs->al_year - rhs->al_year;
|
return lhs->al_year - rhs->al_year;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool album_artwork_exists(struct album *album)
|
||||||
|
{
|
||||||
|
struct cache_file file;
|
||||||
|
bool ret;
|
||||||
|
|
||||||
|
__album_init_file(album, &file);
|
||||||
|
ret = cache_file_exists(&file);
|
||||||
|
__album_deinit_file(&file);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_TESTING
|
#ifdef CONFIG_TESTING
|
||||||
const struct db_ops *test_album_ops() { return &album_ops; }
|
const struct db_ops *test_album_ops() { return &album_ops; }
|
||||||
#endif /* CONFIG_TESTING */
|
#endif /* CONFIG_TESTING */
|
||||||
|
|
|
@ -46,6 +46,9 @@ int album_compare(struct album *, struct album *);
|
||||||
/* Called to compare two album tags by year. */
|
/* Called to compare two album tags by year. */
|
||||||
int album_compare_year(struct album *, struct album *);
|
int album_compare_year(struct album *, struct album *);
|
||||||
|
|
||||||
|
/* Called to check if album artwork has been downloaded. */
|
||||||
|
bool album_artwork_exists(struct album *);
|
||||||
|
|
||||||
#ifdef CONFIG_TESTING
|
#ifdef CONFIG_TESTING
|
||||||
const struct db_ops *test_album_ops();
|
const struct db_ops *test_album_ops();
|
||||||
#endif /* CONFIG_TESTING */
|
#endif /* CONFIG_TESTING */
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2014 (c) Anna Schumaker.
|
* Copyright 2014 (c) Anna Schumaker.
|
||||||
*/
|
*/
|
||||||
|
#include <core/idle.h>
|
||||||
#include <core/tags/album.h>
|
#include <core/tags/album.h>
|
||||||
#include <tests/test.h>
|
#include <tests/test.h>
|
||||||
|
|
||||||
|
@ -94,11 +95,25 @@ static void test_album_db()
|
||||||
test_equal(album_db.db_size, 1);
|
test_equal(album_db.db_size, 1);
|
||||||
|
|
||||||
db_deinit(&album_db);
|
db_deinit(&album_db);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_album_artwork()
|
||||||
|
{
|
||||||
|
struct album *album;
|
||||||
|
|
||||||
|
idle_deinit();
|
||||||
|
idle_init();
|
||||||
|
|
||||||
|
album = album_find("Hyrule Symphony", 1998);
|
||||||
|
test_equal(album_artwork_exists(album), (bool)false);
|
||||||
|
|
||||||
album_db_deinit();
|
album_db_deinit();
|
||||||
|
idle_deinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
DECLARE_UNIT_TESTS(
|
DECLARE_UNIT_TESTS(
|
||||||
UNIT_TEST("Album Tag", test_album),
|
UNIT_TEST("Album Tag", test_album),
|
||||||
UNIT_TEST("Album Comparison", test_album_compare),
|
UNIT_TEST("Album Comparison", test_album_compare),
|
||||||
UNIT_TEST("Album Database", test_album_db),
|
UNIT_TEST("Album Database", test_album_db),
|
||||||
|
UNIT_TEST("Album Artwork", test_album_artwork),
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue