diff --git a/core/tags/album.c b/core/tags/album.c index 6250aee7..6b453202 100644 --- a/core/tags/album.c +++ b/core/tags/album.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -163,12 +164,13 @@ static bool __album_fetch_artwork(struct album *album) return true; } -static gchar *__album_key(struct artist *artist, const gchar *name, - unsigned int year) +static gchar *__album_key(struct artist *artist, struct genre *genre, + const gchar *name, unsigned int year) { - if (!artist) + if (!artist || !genre) return g_strdup_printf("%u/%s", year, name); - return g_strdup_printf("%u/%u/%s", artist_index(artist), year, name); + return g_strdup_printf("%u/%u/%u/%s", artist_index(artist), + genre_index(genre), year, name); } static struct album *__album_alloc(gchar *name, unsigned int year) @@ -208,8 +210,8 @@ static void album_free(struct db_entry *dbe) static gchar *album_key(struct db_entry *dbe) { - return __album_key(ALBUM(dbe)->al_artist, ALBUM(dbe)->al_name, - ALBUM(dbe)->al_year); + return __album_key(ALBUM(dbe)->al_artist, ALBUM(dbe)->al_genre, + ALBUM(dbe)->al_name, ALBUM(dbe)->al_year); } static struct db_entry *album_read(struct file *file) @@ -254,7 +256,7 @@ void album_db_deinit() struct album *album_find(const gchar *name, unsigned int year) { - gchar *key = __album_key(NULL, name, year); + gchar *key = __album_key(NULL, NULL, name, year); struct album *album = ALBUM(db_find(&album_db, key)); g_free(key); return album; diff --git a/tests/core/tags/.gitignore b/tests/core/tags/.gitignore index 45d5f601..6d3fcd62 100644 --- a/tests/core/tags/.gitignore +++ b/tests/core/tags/.gitignore @@ -1,5 +1,5 @@ artist -album genre +album library track diff --git a/tests/core/tags/CMakeLists.txt b/tests/core/tags/CMakeLists.txt index bcf499ff..6ea399fc 100644 --- a/tests/core/tags/CMakeLists.txt +++ b/tests/core/tags/CMakeLists.txt @@ -5,7 +5,7 @@ function(tag_unit_test name) endfunction() tag_unit_test(Artist) -tag_unit_test(Album) tag_unit_test(Genre) +tag_unit_test(Album) tag_unit_test(Library) tag_unit_test(Track) diff --git a/tests/core/tags/album.c b/tests/core/tags/album.c index 5c6b57ee..7cd6bbce 100644 --- a/tests/core/tags/album.c +++ b/tests/core/tags/album.c @@ -3,6 +3,7 @@ */ #include #include +#include #include static void test_verify_empty(struct album *album) @@ -29,7 +30,7 @@ static void test_verify_hyrule(struct album *album) key = album_ops->dbe_key(&album->al_dbe); if (album->al_artist) - g_assert_cmpstr_free(key, ==, "0/1998/Hyrule Symphony"); + g_assert_cmpstr_free(key, ==, "0/0/1998/Hyrule Symphony"); else g_assert_cmpstr_free(key, ==, "1998/Hyrule Symphony"); } @@ -39,14 +40,18 @@ static void test_album() const struct db_ops *album_ops = test_album_ops(); struct album *album; struct artist *koji; + struct genre *genre; struct file f; idle_init(); koji = artist_find("Koji Kondo"); + genre = genre_find("Video Game Music"); + album = ALBUM(album_ops->dbe_alloc("1998/Hyrule Symphony")); test_verify_hyrule(album); album->al_artist = koji; + album->al_genre = genre; test_verify_hyrule(album); g_assert_true( album_match_token(album, "hyrule")); g_assert_true( album_match_token(album, "symphony")); @@ -173,6 +178,7 @@ int main(int argc, char **argv) idle_init(); artist_db_init(); + genre_db_init(); album_db_init(); g_test_init(&argc, &argv, NULL); g_test_add_func("/Core/Tags/Album", test_album);