core/tags/album: Rewrite unit test
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
45207ebd2e
commit
75d4bd2af3
|
@ -4,38 +4,63 @@
|
|||
#include <core/tags/album.h>
|
||||
#include "../test.h"
|
||||
|
||||
static void test_album_tag()
|
||||
static void test_verify_empty(Album *album)
|
||||
{
|
||||
Album album("Hyrule Symphony", 1998);
|
||||
test_equal(album->name(), "");
|
||||
test_equal(album->lowercase(), "");
|
||||
test_equal(album->year(), 0);
|
||||
test_equal(album->primary_key(), "0/");
|
||||
}
|
||||
|
||||
static void test_verify_hyrule(Album *album)
|
||||
{
|
||||
test_equal(album->name(), "Hyrule Symphony");
|
||||
test_equal(album->lowercase(), "hyrule symphony");
|
||||
test_equal(album->year(), 1998);
|
||||
test_equal(album->primary_key(), "1998/Hyrule Symphony");
|
||||
}
|
||||
|
||||
static void test_album()
|
||||
{
|
||||
Album *album = new Album("Hyrule Symphony", 1998);
|
||||
file f;
|
||||
|
||||
test_equal(album.name(), (std::string)"Hyrule Symphony");
|
||||
test_equal(album.lowercase(), (std::string)"hyrule symphony");
|
||||
test_equal(album.year(), (unsigned int)1998);
|
||||
test_equal(album.primary_key(), (std::string)"1998/Hyrule Symphony");
|
||||
test_verify_hyrule(album);
|
||||
|
||||
file_init(&f, "album_tag", 0);
|
||||
file_open(&f, OPEN_WRITE);
|
||||
album.write(f);
|
||||
file_writef(&f, "0 \n");
|
||||
album->write(f);
|
||||
file_close(&f);
|
||||
delete album;
|
||||
|
||||
album = Album();
|
||||
test_equal(album.name(), (std::string)"");
|
||||
test_equal(album.lowercase(), (std::string)"");
|
||||
test_equal(album.year(), (unsigned int)0);
|
||||
test_equal(album.primary_key(), (std::string)"0/");
|
||||
album = new Album();
|
||||
test_verify_empty(album);
|
||||
|
||||
file_open(&f, OPEN_READ);
|
||||
album.read(f);
|
||||
file_close(&f);
|
||||
album->read(f);
|
||||
test_verify_empty(album);
|
||||
|
||||
test_equal(album.name(), (std::string)"Hyrule Symphony");
|
||||
test_equal(album.lowercase(), (std::string)"hyrule symphony");
|
||||
test_equal(album.year(), (unsigned int)1998);
|
||||
test_equal(album.primary_key(), (std::string)"1998/Hyrule Symphony");
|
||||
album->read(f);
|
||||
file_close(&f);
|
||||
test_verify_hyrule(album);
|
||||
delete album;
|
||||
}
|
||||
|
||||
static void test_album_tag_lookup()
|
||||
static void test_album_compare()
|
||||
{
|
||||
Album *twilight = new Album("Twilight Princess", 2006);
|
||||
Album *skyward = new Album("skyward sword", 2011);
|
||||
|
||||
test_equal(twilight->compare(twilight), 0);
|
||||
test_equal(twilight->compare(skyward), 1);
|
||||
test_equal(skyward->compare(twilight), -1);
|
||||
|
||||
delete skyward;
|
||||
delete twilight;
|
||||
}
|
||||
|
||||
static void test_album_db()
|
||||
{
|
||||
database<Album> album_db;
|
||||
Album *album;
|
||||
|
@ -43,10 +68,7 @@ static void test_album_tag_lookup()
|
|||
tags :: init_album_db();
|
||||
album = tags :: get_album("Hyrule Symphony", 1998);
|
||||
|
||||
test_equal(album->name(), (std::string)"Hyrule Symphony");
|
||||
test_equal(album->lowercase(), (std::string)"hyrule symphony");
|
||||
test_equal(album->year(), (unsigned int)1998);
|
||||
test_equal(album->primary_key(), (std::string)"1998/Hyrule Symphony");
|
||||
test_verify_hyrule(album);
|
||||
|
||||
test_equal(tags :: get_album("Hyrule Symphony", 1998), album);
|
||||
test_equal(tags :: get_album(0), album);
|
||||
|
@ -54,10 +76,13 @@ static void test_album_tag_lookup()
|
|||
|
||||
db_init(&album_db, "album.db", false);
|
||||
db_load(&album_db);
|
||||
test_equal(album_db.db_size, (unsigned)1);
|
||||
test_equal(album_db.db_size, 1);
|
||||
|
||||
db_deinit(&album_db);
|
||||
}
|
||||
|
||||
DECLARE_UNIT_TESTS(
|
||||
UNIT_TEST("Album Tag", test_album_tag),
|
||||
UNIT_TEST("Album Tag Lookup", test_album_tag_lookup),
|
||||
UNIT_TEST("Album Tag", test_album),
|
||||
UNIT_TEST("Album Comparison", test_album_compare),
|
||||
UNIT_TEST("Album Database", test_album_db),
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue