2014-11-08 20:53:08 -05:00
|
|
|
/**
|
|
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
|
|
*/
|
|
|
|
#include <core/tags/album.h>
|
2015-08-27 10:59:43 -04:00
|
|
|
#include "../test.h"
|
2014-11-08 20:53:08 -05:00
|
|
|
|
2015-10-22 07:58:21 -04:00
|
|
|
static void test_verify_empty(Album *album)
|
2014-11-08 20:53:08 -05:00
|
|
|
{
|
2015-10-22 07:58:21 -04:00
|
|
|
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);
|
2015-09-10 10:33:24 -04:00
|
|
|
file f;
|
2014-11-08 20:53:08 -05:00
|
|
|
|
2015-10-22 07:58:21 -04:00
|
|
|
test_verify_hyrule(album);
|
2014-11-08 20:53:08 -05:00
|
|
|
|
2015-09-10 10:33:24 -04:00
|
|
|
file_init(&f, "album_tag", 0);
|
2015-09-10 09:46:33 -04:00
|
|
|
file_open(&f, OPEN_WRITE);
|
2015-10-22 07:58:21 -04:00
|
|
|
file_writef(&f, "0 \n");
|
|
|
|
album->write(f);
|
2015-09-10 09:12:48 -04:00
|
|
|
file_close(&f);
|
2015-10-22 07:58:21 -04:00
|
|
|
delete album;
|
2014-11-08 20:53:08 -05:00
|
|
|
|
2015-10-22 07:58:21 -04:00
|
|
|
album = new Album();
|
|
|
|
test_verify_empty(album);
|
2014-11-08 20:53:08 -05:00
|
|
|
|
2015-09-10 09:46:33 -04:00
|
|
|
file_open(&f, OPEN_READ);
|
2015-10-22 07:58:21 -04:00
|
|
|
album->read(f);
|
|
|
|
test_verify_empty(album);
|
|
|
|
|
|
|
|
album->read(f);
|
2015-09-10 09:12:48 -04:00
|
|
|
file_close(&f);
|
2015-10-22 07:58:21 -04:00
|
|
|
test_verify_hyrule(album);
|
|
|
|
delete album;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2014-11-08 20:53:08 -05:00
|
|
|
|
2015-10-22 07:58:21 -04:00
|
|
|
delete skyward;
|
|
|
|
delete twilight;
|
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-09-21 09:02:13 -04:00
|
|
|
database<Album> album_db;
|
|
|
|
Album *album;
|
|
|
|
|
|
|
|
tags :: init_album_db();
|
|
|
|
album = tags :: get_album("Hyrule Symphony", 1998);
|
2014-11-16 14:47:51 -05:00
|
|
|
|
2015-10-22 07:58:21 -04:00
|
|
|
test_verify_hyrule(album);
|
2014-11-16 14:47:51 -05:00
|
|
|
|
|
|
|
test_equal(tags :: get_album("Hyrule Symphony", 1998), album);
|
|
|
|
test_equal(tags :: get_album(0), album);
|
|
|
|
test_equal(tags :: get_album(1), (Album *)NULL);
|
|
|
|
|
2015-09-21 09:02:13 -04:00
|
|
|
db_init(&album_db, "album.db", false);
|
2015-09-17 08:12:25 -04:00
|
|
|
db_load(&album_db);
|
2015-10-22 07:58:21 -04:00
|
|
|
test_equal(album_db.db_size, 1);
|
|
|
|
|
|
|
|
db_deinit(&album_db);
|
2014-11-16 14:47:51 -05:00
|
|
|
}
|
|
|
|
|
2015-08-27 10:59:43 -04:00
|
|
|
DECLARE_UNIT_TESTS(
|
2015-10-22 07:58:21 -04:00
|
|
|
UNIT_TEST("Album Tag", test_album),
|
|
|
|
UNIT_TEST("Album Comparison", test_album_compare),
|
|
|
|
UNIT_TEST("Album Database", test_album_db),
|
2015-08-27 10:59:43 -04:00
|
|
|
);
|