ocarina/tests/core/tags/album.c

105 lines
2.8 KiB
C

/*
* Copyright 2014 (c) Anna Schumaker.
*/
#include <core/tags/album.h>
#include <tests/test.h>
static void test_verify_empty(struct album *album)
{
const struct db_ops *album_ops = test_album_ops();
test_equal(album->al_name, "");
test_equal(album->al_lower, "");
test_equal(album->al_year, 0);
test_str_equal(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_lower, "hyrule symphony");
test_equal(album->al_year, 1998);
test_str_equal(album_ops->dbe_key(&album->al_dbe), "1998/Hyrule Symphony");
}
static void test_album()
{
const struct db_ops *album_ops = test_album_ops();
struct album *album;
struct file f;
album = ALBUM(album_ops->dbe_alloc("1998/Hyrule Symphony"));
test_verify_hyrule(album);
file_init(&f, "album_tag", 0, 0);
file_open(&f, OPEN_WRITE);
file_writef(&f, "0 \n");
album_ops->dbe_write(&f, &album->al_dbe);
file_close(&f);
album_ops->dbe_free(&album->al_dbe);
file_open(&f, OPEN_READ);
album = ALBUM(album_ops->dbe_read(&f));
test_verify_empty(album);
album_ops->dbe_free(&album->al_dbe);
album = ALBUM(album_ops->dbe_read(&f));
file_close(&f);
test_verify_hyrule(album);
album_ops->dbe_free(&album->al_dbe);
}
static void test_album_compare()
{
const struct db_ops *album_ops = test_album_ops();
struct album *twilight, *skyward;
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);
test_equal(album_compare_year(twilight, twilight), 0);
test_equal(album_compare_year(twilight, skyward), -5);
test_equal(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);
album_ops->dbe_free(&twilight->al_dbe);
album_ops->dbe_free(&skyward->al_dbe);
}
static void test_album_db()
{
const struct db_ops *album_ops = test_album_ops();
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);
db_init(&album_db, "album.db", false, album_ops);
db_load(&album_db);
test_equal(album_db.db_size, 1);
db_deinit(&album_db);
album_db_deinit();
}
DECLARE_UNIT_TESTS(
UNIT_TEST("Album Tag", test_album),
UNIT_TEST("Album Comparison", test_album_compare),
UNIT_TEST("Album Database", test_album_db),
);