fe3d7867d1
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
91 lines
1.9 KiB
C++
91 lines
1.9 KiB
C++
/**
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
*/
|
|
#include <core/tags/artist.h>
|
|
#include "../test.h"
|
|
|
|
static void test_verify_empty(struct artist *artist)
|
|
{
|
|
test_equal(artist->ar_name, "");
|
|
test_equal(artist->ar_lower, "");
|
|
test_equal(artist->primary_key(), "");
|
|
}
|
|
|
|
static void test_verify_koji(struct artist *artist)
|
|
{
|
|
test_equal(artist->ar_name, "Koji Kondo");
|
|
test_equal(artist->ar_lower, "koji kondo");
|
|
test_equal(artist->primary_key(), "Koji Kondo");
|
|
}
|
|
|
|
static void test_artist()
|
|
{
|
|
struct artist *artist = new struct artist("Koji Kondo");
|
|
unsigned int i;
|
|
file f;
|
|
|
|
test_verify_koji(artist);
|
|
|
|
file_init(&f, "artist_tag", 0);
|
|
file_open(&f, OPEN_WRITE);
|
|
file_writef(&f, "1 \n1 ");
|
|
artist->write(f);
|
|
file_close(&f);
|
|
delete artist;
|
|
|
|
artist = new struct artist();
|
|
test_verify_empty(artist);
|
|
|
|
file_open(&f, OPEN_READ);
|
|
file_readf(&f, "%u", &i);
|
|
artist->read(f);
|
|
test_verify_empty(artist);
|
|
|
|
file_readf(&f, "%u", &i);
|
|
artist->read(f);
|
|
file_close(&f);
|
|
test_verify_koji(artist);
|
|
delete artist;
|
|
}
|
|
|
|
static void test_artist_compare()
|
|
{
|
|
struct artist *koji = new struct artist("Koji Kondo");
|
|
struct artist *hajime = new struct artist("hajime wakai");
|
|
|
|
test_equal(artist_compare(koji, koji), 0);
|
|
test_equal(artist_compare(koji, hajime), 1);
|
|
test_equal(artist_compare(hajime, koji), -1);
|
|
|
|
delete hajime;
|
|
delete koji;
|
|
}
|
|
|
|
static void test_artist_db()
|
|
{
|
|
database<struct artist> 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);
|
|
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),
|
|
);
|