2015-11-11 09:15:25 -05:00
|
|
|
/*
|
2014-11-08 20:53:08 -05:00
|
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
|
|
*/
|
|
|
|
#include <core/tags/album.h>
|
2015-11-11 09:15:25 -05:00
|
|
|
#include <tests/test.h>
|
2014-11-08 20:53:08 -05:00
|
|
|
|
2015-10-22 08:16:53 -04:00
|
|
|
static void test_verify_empty(struct album *album)
|
2014-11-08 20:53:08 -05:00
|
|
|
{
|
2015-09-23 09:33:55 -04:00
|
|
|
const struct db_ops *album_ops = test_album_ops();
|
2015-10-22 09:58:12 -04:00
|
|
|
test_equal(album->al_name, "");
|
|
|
|
test_equal(album->al_lower, "");
|
|
|
|
test_equal(album->al_year, 0);
|
2015-11-11 07:59:21 -05:00
|
|
|
test_str_equal(album_ops->dbe_key(&album->al_dbe), "0/");
|
2015-10-22 07:58:21 -04:00
|
|
|
}
|
|
|
|
|
2015-10-22 08:16:53 -04:00
|
|
|
static void test_verify_hyrule(struct album *album)
|
2015-10-22 07:58:21 -04:00
|
|
|
{
|
2015-09-23 09:33:55 -04:00
|
|
|
const struct db_ops *album_ops = test_album_ops();
|
2015-10-22 09:58:12 -04:00
|
|
|
test_equal(album->al_name, "Hyrule Symphony");
|
|
|
|
test_equal(album->al_lower, "hyrule symphony");
|
|
|
|
test_equal(album->al_year, 1998);
|
2015-11-11 07:59:21 -05:00
|
|
|
test_str_equal(album_ops->dbe_key(&album->al_dbe), "1998/Hyrule Symphony");
|
2015-10-22 07:58:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_album()
|
|
|
|
{
|
2015-11-02 16:59:55 -05:00
|
|
|
const struct db_ops *album_ops = test_album_ops();
|
|
|
|
struct album *album;
|
2015-11-11 09:15:25 -05:00
|
|
|
struct file f;
|
2014-11-08 20:53:08 -05:00
|
|
|
|
2015-11-11 07:59:21 -05:00
|
|
|
album = ALBUM(album_ops->dbe_alloc("1998/Hyrule Symphony"));
|
2015-10-22 07:58:21 -04:00
|
|
|
test_verify_hyrule(album);
|
2014-11-08 20:53:08 -05:00
|
|
|
|
2016-03-30 11:25:14 -04:00
|
|
|
file_init(&f, "album_tag", 0, 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");
|
2015-11-11 07:59:21 -05:00
|
|
|
album_ops->dbe_write(&f, &album->al_dbe);
|
2015-09-10 09:12:48 -04:00
|
|
|
file_close(&f);
|
2015-11-11 07:59:21 -05:00
|
|
|
album_ops->dbe_free(&album->al_dbe);
|
2014-11-08 20:53:08 -05:00
|
|
|
|
2015-09-10 09:46:33 -04:00
|
|
|
file_open(&f, OPEN_READ);
|
2015-11-11 07:59:21 -05:00
|
|
|
album = ALBUM(album_ops->dbe_read(&f));
|
2015-10-22 07:58:21 -04:00
|
|
|
test_verify_empty(album);
|
2015-11-11 07:59:21 -05:00
|
|
|
album_ops->dbe_free(&album->al_dbe);
|
2015-10-22 07:58:21 -04:00
|
|
|
|
2015-11-11 07:59:21 -05:00
|
|
|
album = ALBUM(album_ops->dbe_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);
|
2015-11-11 07:59:21 -05:00
|
|
|
album_ops->dbe_free(&album->al_dbe);
|
2015-10-22 07:58:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_album_compare()
|
|
|
|
{
|
2015-11-02 16:59:55 -05:00
|
|
|
const struct db_ops *album_ops = test_album_ops();
|
|
|
|
struct album *twilight, *skyward;
|
|
|
|
|
2015-11-11 07:59:21 -05:00
|
|
|
twilight = ALBUM(album_ops->dbe_alloc("2006/Twilight Princess"));
|
|
|
|
skyward = ALBUM(album_ops->dbe_alloc("2011/skyward sword"));
|
2015-10-22 07:58:21 -04:00
|
|
|
|
2015-10-22 09:58:12 -04:00
|
|
|
test_equal(album_compare(twilight, twilight), 0);
|
|
|
|
test_equal(album_compare(twilight, skyward), 1);
|
|
|
|
test_equal(album_compare(skyward, twilight), -1);
|
2014-11-08 20:53:08 -05:00
|
|
|
|
2015-11-16 09:38:31 -05:00
|
|
|
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);
|
|
|
|
|
2015-11-11 07:59:21 -05:00
|
|
|
album_ops->dbe_free(&twilight->al_dbe);
|
|
|
|
album_ops->dbe_free(&skyward->al_dbe);
|
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-11-03 10:39:06 -05:00
|
|
|
const struct db_ops *album_ops = test_album_ops();
|
2015-11-04 12:23:00 -05:00
|
|
|
struct database album_db;
|
2015-10-22 08:16:53 -04:00
|
|
|
struct album *album;
|
2015-09-21 09:02:13 -04:00
|
|
|
|
2015-09-24 11:18:48 -04:00
|
|
|
album_db_init();
|
2015-09-24 11:13:12 -04:00
|
|
|
album = album_find("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
|
|
|
|
2015-11-11 09:15:25 -05:00
|
|
|
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);
|
2014-11-16 14:47:51 -05:00
|
|
|
|
2015-11-03 10:39:06 -05:00
|
|
|
db_init(&album_db, "album.db", false, album_ops);
|
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);
|
2015-09-24 11:18:48 -04:00
|
|
|
album_db_deinit();
|
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
|
|
|
);
|