2015-11-11 09:15:25 -05:00
|
|
|
/*
|
2014-11-08 20:53:08 -05:00
|
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
|
|
*/
|
2016-04-30 08:51:34 -04:00
|
|
|
#include <core/idle.h>
|
2014-11-08 20:53:08 -05:00
|
|
|
#include <core/tags/album.h>
|
2016-08-12 10:10:00 -04:00
|
|
|
#include <core/tags/genre.h>
|
2015-11-11 09:15:25 -05:00
|
|
|
#include <tests/test.h>
|
2014-11-08 20:53:08 -05:00
|
|
|
|
2015-10-22 08:16:53 -04:00
|
|
|
static void test_verify_empty(struct album *album)
|
2014-11-08 20:53:08 -05:00
|
|
|
{
|
2015-09-23 09:33:55 -04:00
|
|
|
const struct db_ops *album_ops = test_album_ops();
|
2016-03-09 09:38:02 -05:00
|
|
|
g_assert_cmpstr(album->al_name, ==, "");
|
|
|
|
g_assert_null(album->al_tokens[0]);
|
|
|
|
g_assert_null(album->al_alts[0]);
|
2016-08-12 11:14:51 -04:00
|
|
|
g_assert(album->al_artist == artist_get(0));
|
|
|
|
g_assert(album->al_genre == genre_get(0));
|
2016-03-09 09:38:02 -05:00
|
|
|
g_assert_cmpuint(album->al_year, ==, 0);
|
2016-08-12 11:14:51 -04:00
|
|
|
g_assert_cmpstr_free(album_ops->dbe_key(&album->al_dbe), ==, "0/0/0/");
|
2015-10-22 07:58:21 -04:00
|
|
|
}
|
|
|
|
|
2016-08-12 09:10:57 -04:00
|
|
|
static void test_verify_hyrule(struct album *album, struct artist *artist,
|
|
|
|
struct genre *genre)
|
2015-10-22 07:58:21 -04:00
|
|
|
{
|
2015-09-23 09:33:55 -04:00
|
|
|
const struct db_ops *album_ops = test_album_ops();
|
2016-08-12 08:13:20 -04:00
|
|
|
gchar *key;
|
|
|
|
|
2016-03-09 09:38:02 -05:00
|
|
|
g_assert_cmpstr(album->al_name, ==, "Hyrule Symphony");
|
|
|
|
g_assert_cmpstr(album->al_tokens[0], ==, "hyrule");
|
|
|
|
g_assert_cmpstr(album->al_tokens[1], ==, "symphony");
|
|
|
|
g_assert_null(album->al_tokens[2]);
|
|
|
|
g_assert_null(album->al_alts[0]);
|
2016-08-12 09:10:57 -04:00
|
|
|
g_assert(album->al_artist == artist);
|
|
|
|
g_assert(album->al_genre == genre);
|
2016-03-09 09:38:02 -05:00
|
|
|
g_assert_cmpuint(album->al_year, ==, 1998);
|
2016-08-12 08:13:20 -04:00
|
|
|
|
|
|
|
key = album_ops->dbe_key(&album->al_dbe);
|
2016-08-12 09:10:57 -04:00
|
|
|
if (artist && genre)
|
2016-08-12 10:10:00 -04:00
|
|
|
g_assert_cmpstr_free(key, ==, "0/0/1998/Hyrule Symphony");
|
2016-08-12 08:13:20 -04:00
|
|
|
else
|
|
|
|
g_assert_cmpstr_free(key, ==, "1998/Hyrule Symphony");
|
2015-10-22 07:58:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_album()
|
|
|
|
{
|
2015-11-02 16:59:55 -05:00
|
|
|
const struct db_ops *album_ops = test_album_ops();
|
|
|
|
struct album *album;
|
2016-08-12 08:13:20 -04:00
|
|
|
struct artist *koji;
|
2016-08-12 10:10:00 -04:00
|
|
|
struct genre *genre;
|
2018-02-16 15:50:46 -05:00
|
|
|
struct file f = FILE_INIT_DATA("", "album_tag", 1);
|
2014-11-08 20:53:08 -05:00
|
|
|
|
2016-09-24 09:57:51 -04:00
|
|
|
idle_init(IDLE_SYNC);
|
2016-04-30 10:56:18 -04:00
|
|
|
|
2016-08-12 08:13:20 -04:00
|
|
|
koji = artist_find("Koji Kondo");
|
2016-08-12 10:10:00 -04:00
|
|
|
genre = genre_find("Video Game Music");
|
2016-09-12 15:27:02 -04:00
|
|
|
album = ALBUM(album_ops->dbe_alloc("0/0/1998/Hyrule Symphony", 0));
|
2016-08-12 09:10:57 -04:00
|
|
|
test_verify_hyrule(album, koji, genre);
|
2016-03-09 09:38:02 -05:00
|
|
|
g_assert_true( album_match_token(album, "hyrule"));
|
|
|
|
g_assert_true( album_match_token(album, "symphony"));
|
|
|
|
g_assert_false(album_match_token(album, "skyward"));
|
2014-11-08 20:53:08 -05:00
|
|
|
|
2018-02-20 15:38:28 -05:00
|
|
|
file_open(&f, OPEN_WRITE);
|
2018-02-21 08:19:19 -05:00
|
|
|
file_writef(&f, "0 0 0 \n");
|
2015-11-11 07:59:21 -05:00
|
|
|
album_ops->dbe_write(&f, &album->al_dbe);
|
2018-02-20 09:53:53 -05:00
|
|
|
file_close(&f);
|
2015-11-11 07:59:21 -05:00
|
|
|
album_ops->dbe_free(&album->al_dbe);
|
2014-11-08 20:53:08 -05:00
|
|
|
|
2018-02-20 14:26:47 -05:00
|
|
|
file_open(&f, OPEN_READ);
|
2016-09-12 15:27:02 -04:00
|
|
|
album = ALBUM(album_ops->dbe_read(&f, 0));
|
2015-10-22 07:58:21 -04:00
|
|
|
test_verify_empty(album);
|
2015-11-11 07:59:21 -05:00
|
|
|
album_ops->dbe_free(&album->al_dbe);
|
2015-10-22 07:58:21 -04:00
|
|
|
|
2016-09-12 15:27:02 -04:00
|
|
|
album = ALBUM(album_ops->dbe_read(&f, 0));
|
2018-02-20 09:53:53 -05:00
|
|
|
file_close(&f);
|
2016-08-12 11:14:51 -04:00
|
|
|
test_verify_hyrule(album, koji, genre);
|
2015-11-11 07:59:21 -05:00
|
|
|
album_ops->dbe_free(&album->al_dbe);
|
2015-10-22 07:58:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_album_compare()
|
|
|
|
{
|
2015-11-02 16:59:55 -05:00
|
|
|
const struct db_ops *album_ops = test_album_ops();
|
|
|
|
struct album *twilight, *skyward;
|
|
|
|
|
2016-09-12 15:27:02 -04:00
|
|
|
twilight = ALBUM(album_ops->dbe_alloc("2006/Twilight Princess", 0));
|
|
|
|
skyward = ALBUM(album_ops->dbe_alloc("2011/skyward sword", 0));
|
2015-10-22 07:58:21 -04:00
|
|
|
|
2016-03-09 09:38:02 -05:00
|
|
|
g_assert_cmpint(album_compare(twilight, twilight), ==, 0);
|
|
|
|
g_assert_cmpint(album_compare(twilight, skyward), ==, 1);
|
|
|
|
g_assert_cmpint(album_compare(skyward, twilight), ==, -1);
|
2014-11-08 20:53:08 -05:00
|
|
|
|
2016-03-09 09:38:02 -05:00
|
|
|
g_assert_cmpint(album_compare_year(twilight, twilight), ==, 0);
|
|
|
|
g_assert_cmpint(album_compare_year(twilight, skyward), ==, -5);
|
|
|
|
g_assert_cmpint(album_compare_year(skyward, twilight), ==, 5);
|
2015-11-16 09:38:31 -05:00
|
|
|
|
|
|
|
skyward->al_year = 2006;
|
2016-03-09 09:38:02 -05:00
|
|
|
g_assert_cmpint(album_compare_year(twilight, twilight), ==, 0);
|
|
|
|
g_assert_cmpint(album_compare_year(twilight, skyward), ==, 1);
|
|
|
|
g_assert_cmpint(album_compare_year(skyward, twilight), ==, -1);
|
2015-11-16 09:38:31 -05:00
|
|
|
|
2015-11-11 07:59:21 -05:00
|
|
|
album_ops->dbe_free(&twilight->al_dbe);
|
|
|
|
album_ops->dbe_free(&skyward->al_dbe);
|
2014-11-08 20:53:08 -05:00
|
|
|
}
|
|
|
|
|
2015-10-22 07:58:21 -04:00
|
|
|
static void test_album_db()
|
2014-11-16 14:47:51 -05:00
|
|
|
{
|
2015-11-03 10:39:06 -05:00
|
|
|
const struct db_ops *album_ops = test_album_ops();
|
2015-11-04 12:23:00 -05:00
|
|
|
struct database album_db;
|
2016-08-12 09:10:57 -04:00
|
|
|
struct artist *koji;
|
|
|
|
struct genre *genre;
|
2015-10-22 08:16:53 -04:00
|
|
|
struct album *album;
|
2015-09-21 09:02:13 -04:00
|
|
|
|
2016-08-12 09:10:57 -04:00
|
|
|
koji = artist_find("Koji Kondo");
|
|
|
|
genre = genre_find("Video Game Music");
|
|
|
|
album = album_find(koji, genre, "Hyrule Symphony", 1998);
|
|
|
|
test_verify_hyrule(album, koji, genre);
|
|
|
|
g_assert(album_find(koji, genre, "Hyrule Symphony", 1998) == album);
|
2016-08-12 11:14:51 -04:00
|
|
|
g_assert(album_get(0) == album);
|
|
|
|
g_assert_null(album_get(1));
|
2016-08-12 09:10:57 -04:00
|
|
|
|
2016-08-17 14:17:52 -04:00
|
|
|
db_init(&album_db, "album.db", false, album_ops, 0);
|
2015-09-17 08:12:25 -04:00
|
|
|
db_load(&album_db);
|
2016-08-12 11:14:51 -04:00
|
|
|
g_assert_cmpuint(album_db.db_size, ==, 1);
|
2015-10-22 07:58:21 -04:00
|
|
|
|
|
|
|
db_deinit(&album_db);
|
2016-04-30 08:51:34 -04:00
|
|
|
}
|
|
|
|
|
2016-09-28 10:08:12 -04:00
|
|
|
#ifdef CONFIG_TESTING_ARTWORK
|
2016-04-30 08:51:34 -04:00
|
|
|
static void test_album_artwork()
|
|
|
|
{
|
2016-07-12 14:36:40 -04:00
|
|
|
struct album *ocarina, *majora, *wind, *ocarina_3d;
|
2016-04-30 12:54:42 -04:00
|
|
|
gchar *o_path, *m_path, *w_path;
|
2016-04-30 10:56:18 -04:00
|
|
|
struct artist *koji;
|
2016-08-12 11:14:51 -04:00
|
|
|
struct genre *genre;
|
2016-04-30 12:54:42 -04:00
|
|
|
const gchar *cache;
|
2016-04-30 08:51:34 -04:00
|
|
|
|
|
|
|
idle_deinit();
|
2016-09-24 09:57:51 -04:00
|
|
|
idle_init(IDLE_ASYNC);
|
2016-04-30 08:51:34 -04:00
|
|
|
|
2016-04-30 12:54:42 -04:00
|
|
|
cache = g_get_user_cache_dir();
|
2016-03-09 09:38:02 -05:00
|
|
|
o_path = g_build_filename(cache, "ocarina-test", "core", "tags", "album", "1998", "Ocarina of Time.jpg", NULL);
|
|
|
|
m_path = g_build_filename(cache, "ocarina-test", "core", "tags", "album", "2000", "Majora%27s Mask.jpg", NULL);
|
|
|
|
w_path = g_build_filename(cache, "ocarina-test", "core", "tags", "album", "0", "Wind Waker.jpg", NULL);
|
2016-04-30 12:54:42 -04:00
|
|
|
|
2016-04-30 10:56:18 -04:00
|
|
|
koji = artist_find("Koji Kondo");
|
2016-08-12 11:14:51 -04:00
|
|
|
genre = genre_find("Video Game Music");
|
|
|
|
ocarina = album_find(koji, genre, "Ocarina of Time", 1998);
|
|
|
|
majora = album_find(koji, genre, "Majora's Mask", 2000);
|
|
|
|
wind = album_find(koji, genre, "Wind Waker", 0);
|
2016-04-30 10:56:18 -04:00
|
|
|
ocarina->al_artist = koji;
|
|
|
|
|
2016-03-09 09:38:02 -05:00
|
|
|
g_assert_false(album_artwork_exists(ocarina));
|
|
|
|
g_assert_false(album_artwork_exists(majora));
|
|
|
|
g_assert_false(album_artwork_exists(wind));
|
|
|
|
g_assert_null(album_artwork_path(ocarina));
|
|
|
|
g_assert_null(album_artwork_path(majora));
|
|
|
|
g_assert_null(album_artwork_path(wind));
|
2016-04-30 10:56:18 -04:00
|
|
|
|
|
|
|
while (idle_run_task()) {}
|
|
|
|
|
2016-03-09 09:38:02 -05:00
|
|
|
g_assert_true(album_artwork_exists(ocarina));
|
|
|
|
g_assert_true(album_artwork_exists(majora));
|
|
|
|
g_assert_true(album_artwork_exists(wind));
|
|
|
|
g_assert_cmpstr_free(album_artwork_path(ocarina), ==, o_path);
|
|
|
|
g_assert_cmpstr_free(album_artwork_path(majora), ==, m_path);
|
|
|
|
g_assert_cmpstr_free(album_artwork_path(wind), ==, w_path);
|
2016-04-30 08:51:34 -04:00
|
|
|
|
2016-07-12 14:36:40 -04:00
|
|
|
/* Import the original Ocarina of Time album art. */
|
2016-08-12 11:14:51 -04:00
|
|
|
ocarina_3d = album_find(koji, genre, "Ocarina of Time 3D", 2011);
|
2016-03-09 09:38:02 -05:00
|
|
|
g_assert_false(album_artwork_exists(ocarina_3d));
|
2016-07-12 14:36:40 -04:00
|
|
|
album_artwork_import(ocarina_3d, NULL);
|
2016-03-09 09:38:02 -05:00
|
|
|
g_assert_false(album_artwork_exists(ocarina_3d));
|
2016-07-12 14:36:40 -04:00
|
|
|
album_artwork_import(ocarina_3d, o_path);
|
2016-03-09 09:38:02 -05:00
|
|
|
g_assert_true(album_artwork_exists(ocarina_3d));
|
2016-07-12 14:36:40 -04:00
|
|
|
|
2016-04-30 12:54:42 -04:00
|
|
|
g_free(o_path);
|
|
|
|
g_free(m_path);
|
|
|
|
g_free(w_path);
|
2016-03-09 09:38:02 -05:00
|
|
|
}
|
2016-09-28 10:08:12 -04:00
|
|
|
#endif /* CONFIG_TESTING_ARTWORK */
|
2016-03-09 09:38:02 -05:00
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2016-09-24 09:57:51 -04:00
|
|
|
idle_init(IDLE_SYNC);
|
2016-03-09 09:38:02 -05:00
|
|
|
artist_db_init();
|
2016-08-12 10:10:00 -04:00
|
|
|
genre_db_init();
|
2016-03-09 09:38:02 -05:00
|
|
|
album_db_init();
|
|
|
|
g_test_init(&argc, &argv, NULL);
|
|
|
|
g_test_add_func("/Core/Tags/Album", test_album);
|
|
|
|
g_test_add_func("/Core/Tags/Album/Comparison", test_album_compare);
|
|
|
|
g_test_add_func("/Core/Tags/Album/Database", test_album_db);
|
2016-09-28 10:08:12 -04:00
|
|
|
#ifdef CONFIG_TESTING_ARTWORK
|
2016-03-09 09:38:02 -05:00
|
|
|
g_test_add_func("/Core/Tags/Album/Artwork", test_album_artwork);
|
2016-09-28 10:08:12 -04:00
|
|
|
#endif /* CONFIG_TESTING_ARTWORK */
|
2016-03-09 09:38:02 -05:00
|
|
|
ret = g_test_run();
|
|
|
|
|
2015-09-24 11:18:48 -04:00
|
|
|
album_db_deinit();
|
2016-09-28 16:53:20 -04:00
|
|
|
genre_db_deinit();
|
2016-04-30 10:56:18 -04:00
|
|
|
artist_db_deinit();
|
2016-04-30 08:51:34 -04:00
|
|
|
idle_deinit();
|
2016-03-09 09:38:02 -05:00
|
|
|
return ret;
|
2014-11-16 14:47:51 -05:00
|
|
|
}
|