ocarina/tests/core/tags/artist.cpp

97 lines
2.4 KiB
C++
Raw Normal View History

/**
* Copyright 2014 (c) Anna Schumaker.
*/
#include <core/tags/artist.h>
#include "../test.h"
static void test_verify_empty(struct artist *artist)
{
const struct db_ops *artist_ops = test_artist_ops();
test_equal(artist->ar_name, "");
test_equal(artist->ar_lower, "");
test_str_equal(artist_ops->dbe_key(artist), "");
}
static void test_verify_koji(struct artist *artist)
{
const struct db_ops *artist_ops = test_artist_ops();
test_equal(artist->ar_name, "Koji Kondo");
test_equal(artist->ar_lower, "koji kondo");
test_str_equal(artist_ops->dbe_key(artist), "Koji Kondo");
}
static void test_artist()
{
const struct db_ops *artist_ops = test_artist_ops();
struct artist *artist;
unsigned int i;
file f;
artist = (struct artist *)artist_ops->dbe_alloc("Koji Kondo");
test_verify_koji(artist);
file_init(&f, "artist_tag", 0);
file_open(&f, OPEN_WRITE);
file_writef(&f, "1 \n1 ");
artist_ops->dbe_write(&f, artist);
file_close(&f);
artist_ops->dbe_free(artist);
file_open(&f, OPEN_READ);
file_readf(&f, "%u", &i);
artist = (struct artist *)artist_ops->dbe_read(&f);
test_verify_empty(artist);
artist_ops->dbe_free(artist);
file_readf(&f, "%u", &i);
artist = (struct artist *)artist_ops->dbe_read(&f);
file_close(&f);
test_verify_koji(artist);
artist_ops->dbe_free(artist);
}
static void test_artist_compare()
{
const struct db_ops *artist_ops = test_artist_ops();
struct artist *koji, *hajime;
koji = (struct artist *)artist_ops->dbe_alloc("Koji Kondo");
hajime = (struct artist *)artist_ops->dbe_alloc("hajime wakai");
test_equal(artist_compare(koji, koji), 0);
test_equal(artist_compare(koji, hajime), 1);
test_equal(artist_compare(hajime, koji), -1);
artist_ops->dbe_free(koji);
artist_ops->dbe_free(hajime);
}
static void test_artist_db()
{
const struct db_ops *artist_ops = test_artist_ops();
struct database artist_db;
struct artist *artist;
artist_db_init();
artist = artist_find("Koji Kondo");
test_verify_koji(artist);
test_equal(artist_find("Koji Kondo"), artist);
test_equal(artist_get(0), artist);
test_equal(artist_get(1), (struct artist *)NULL);
db_init(&artist_db, "artist.db", false, artist_ops);
db_load(&artist_db);
test_equal(artist_db.db_size, 1);
db_deinit(&artist_db);
artist_db_deinit();
}
DECLARE_UNIT_TESTS(
UNIT_TEST("Artist Tag", test_artist),
UNIT_TEST("Artist Comparison", test_artist_compare),
UNIT_TEST("Artist Database", test_artist_db),
);