tests: Build tags/album test with ctest

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2016-03-09 09:38:02 -05:00 committed by Anna Schumaker
parent 8c875acec9
commit 65bbd21669
3 changed files with 65 additions and 57 deletions

View File

@ -5,3 +5,4 @@ function(tag_unit_test name)
endfunction()
tag_unit_test(Artist)
tag_unit_test(Album)

View File

@ -12,7 +12,7 @@ def TagTest(name):
env.UsePackage("taglib_c")
core_objs += [ env.Object("../../../core/tags/artist.c") ]
res += [ TagTest("album") ]
core_objs += [ env.Object("../../../core/tags/album.c") ]
res += [ TagTest("genre") ]
res += [ TagTest("library") ]

View File

@ -8,23 +8,23 @@
static void test_verify_empty(struct album *album)
{
const struct db_ops *album_ops = test_album_ops();
test_equal(album->al_name, "");
test_equal((void *)album->al_tokens[0], NULL);
test_equal((void *)album->al_alts[0], NULL);
test_equal(album->al_year, 0);
test_str_equal(album_ops->dbe_key(&album->al_dbe), "0/");
g_assert_cmpstr(album->al_name, ==, "");
g_assert_null(album->al_tokens[0]);
g_assert_null(album->al_alts[0]);
g_assert_cmpuint(album->al_year, ==, 0);
g_assert_cmpstr_free(album_ops->dbe_key(&album->al_dbe), ==, "0/");
}
static void test_verify_hyrule(struct album *album)
{
const struct db_ops *album_ops = test_album_ops();
test_equal(album->al_name, "Hyrule Symphony");
test_equal(album->al_tokens[0], "hyrule");
test_equal(album->al_tokens[1], "symphony");
test_equal((void *)album->al_tokens[2], NULL);
test_equal((void *)album->al_alts[0], NULL);
test_equal(album->al_year, 1998);
test_str_equal(album_ops->dbe_key(&album->al_dbe), "1998/Hyrule Symphony");
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]);
g_assert_cmpuint(album->al_year, ==, 1998);
g_assert_cmpstr_free(album_ops->dbe_key(&album->al_dbe), ==, "1998/Hyrule Symphony");
}
static void test_album()
@ -37,9 +37,9 @@ static void test_album()
album = ALBUM(album_ops->dbe_alloc("1998/Hyrule Symphony"));
test_verify_hyrule(album);
test_equal(album_match_token(album, "hyrule"), (bool)true);
test_equal(album_match_token(album, "symphony"), (bool)true);
test_equal(album_match_token(album, "skyward"), (bool)false);
g_assert_true( album_match_token(album, "hyrule"));
g_assert_true( album_match_token(album, "symphony"));
g_assert_false(album_match_token(album, "skyward"));
file_init(&f, "album_tag", 0, 0);
file_open(&f, OPEN_WRITE);
@ -67,18 +67,18 @@ static void test_album_compare()
twilight = ALBUM(album_ops->dbe_alloc("2006/Twilight Princess"));
skyward = ALBUM(album_ops->dbe_alloc("2011/skyward sword"));
test_equal(album_compare(twilight, twilight), 0);
test_equal(album_compare(twilight, skyward), 1);
test_equal(album_compare(skyward, twilight), -1);
g_assert_cmpint(album_compare(twilight, twilight), ==, 0);
g_assert_cmpint(album_compare(twilight, skyward), ==, 1);
g_assert_cmpint(album_compare(skyward, twilight), ==, -1);
test_equal(album_compare_year(twilight, twilight), 0);
test_equal(album_compare_year(twilight, skyward), -5);
test_equal(album_compare_year(skyward, twilight), 5);
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);
skyward->al_year = 2006;
test_equal(album_compare_year(twilight, twilight), 0);
test_equal(album_compare_year(twilight, skyward), 1);
test_equal(album_compare_year(skyward, twilight), -1);
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);
album_ops->dbe_free(&twilight->al_dbe);
album_ops->dbe_free(&skyward->al_dbe);
@ -90,18 +90,16 @@ static void test_album_db()
struct database album_db;
struct album *album;
album_db_init();
album = album_find("Hyrule Symphony", 1998);
test_verify_hyrule(album);
test_equal((void *)album_find("Hyrule Symphony", 1998), (void *)album);
test_equal((void *)album_get(0), (void *)album);
test_equal((void *)album_get(1), (void *)NULL);
g_assert(album_find("Hyrule Symphony", 1998) == album);
g_assert(album_get(0) == album);
g_assert_null(album_get(1));
db_init(&album_db, "album.db", false, album_ops);
db_load(&album_db);
test_equal(album_db.db_size, 1);
g_assert_cmpuint(album_db.db_size, ==, 1);
db_deinit(&album_db);
}
@ -113,14 +111,13 @@ static void test_album_artwork()
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%27s Mask.jpg", NULL);
w_path = g_build_filename(cache, "ocarina-test", "0", "Wind Waker.jpg", NULL);
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);
ocarina = album_find("Ocarina of Time", 1998);
majora = album_find("Majora's Mask", 2000);
@ -128,41 +125,51 @@ static void test_album_artwork()
koji = artist_find("Koji Kondo");
ocarina->al_artist = koji;
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);
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));
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_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);
/* Import the original Ocarina of Time album art. */
ocarina_3d = album_find("Ocarina of Time 3D", 2011);
test_equal(album_artwork_exists(ocarina_3d), (bool)false);
g_assert_false(album_artwork_exists(ocarina_3d));
album_artwork_import(ocarina_3d, NULL);
test_equal(album_artwork_exists(ocarina_3d), (bool)false);
g_assert_false(album_artwork_exists(ocarina_3d));
album_artwork_import(ocarina_3d, o_path);
test_equal(album_artwork_exists(ocarina_3d), (bool)true);
g_assert_true(album_artwork_exists(ocarina_3d));
g_free(o_path);
g_free(m_path);
g_free(w_path);
}
int main(int argc, char **argv)
{
int ret;
idle_init();
artist_db_init();
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);
g_test_add_func("/Core/Tags/Album/Artwork", test_album_artwork);
ret = g_test_run();
album_db_deinit();
artist_db_deinit();
idle_deinit();
return ret;
}
DECLARE_UNIT_TESTS(
UNIT_TEST("Album Tag", test_album),
UNIT_TEST("Album Comparison", test_album_compare),
UNIT_TEST("Album Database", test_album_db),
UNIT_TEST("Album Artwork", test_album_artwork),
);