90 lines
2.0 KiB
C++
90 lines
2.0 KiB
C++
/**
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
*/
|
|
#include <core/tags/album.h>
|
|
#include "../test.h"
|
|
|
|
static void test_verify_empty(struct album *album)
|
|
{
|
|
test_equal(album->name(), "");
|
|
test_equal(album->lowercase(), "");
|
|
test_equal(album->year(), 0);
|
|
test_equal(album->primary_key(), "0/");
|
|
}
|
|
|
|
static void test_verify_hyrule(struct 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()
|
|
{
|
|
struct album *album = new struct album("Hyrule Symphony", 1998);
|
|
file f;
|
|
|
|
test_verify_hyrule(album);
|
|
|
|
file_init(&f, "album_tag", 0);
|
|
file_open(&f, OPEN_WRITE);
|
|
file_writef(&f, "0 \n");
|
|
album->write(f);
|
|
file_close(&f);
|
|
delete album;
|
|
|
|
album = new struct album();
|
|
test_verify_empty(album);
|
|
|
|
file_open(&f, OPEN_READ);
|
|
album->read(f);
|
|
test_verify_empty(album);
|
|
|
|
album->read(f);
|
|
file_close(&f);
|
|
test_verify_hyrule(album);
|
|
delete album;
|
|
}
|
|
|
|
static void test_album_compare()
|
|
{
|
|
struct album *twilight = new struct album("Twilight Princess", 2006);
|
|
struct album *skyward = new struct 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<struct album> album_db;
|
|
struct album *album;
|
|
|
|
album_db_init();
|
|
album = album_find("Hyrule Symphony", 1998);
|
|
|
|
test_verify_hyrule(album);
|
|
|
|
test_equal(album_find("Hyrule Symphony", 1998), album);
|
|
test_equal(album_get(0), album);
|
|
test_equal(album_get(1), (struct album *)NULL);
|
|
|
|
db_init(&album_db, "album.db", false);
|
|
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),
|
|
);
|