60 lines
1.8 KiB
C++
60 lines
1.8 KiB
C++
/**
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
*/
|
|
#include <core/tags/album.h>
|
|
#include "../test.h"
|
|
|
|
static void test_album_tag()
|
|
{
|
|
Album album("Hyrule Symphony", 1998);
|
|
file f;
|
|
|
|
test_equal(album.name(), (std::string)"Hyrule Symphony");
|
|
test_equal(album.lowercase(), (std::string)"hyrule symphony");
|
|
test_equal(album.year(), (unsigned int)1998);
|
|
test_equal(album.primary_key(), (std::string)"1998/Hyrule Symphony");
|
|
|
|
file_init(&f, "album_tag", 0);
|
|
file_open(&f, OPEN_WRITE);
|
|
album.write(f);
|
|
file_close(&f);
|
|
|
|
album = Album();
|
|
test_equal(album.name(), (std::string)"");
|
|
test_equal(album.lowercase(), (std::string)"");
|
|
test_equal(album.year(), (unsigned int)0);
|
|
test_equal(album.primary_key(), (std::string)"0/");
|
|
|
|
file_open(&f, OPEN_READ);
|
|
album.read(f);
|
|
file_close(&f);
|
|
|
|
test_equal(album.name(), (std::string)"Hyrule Symphony");
|
|
test_equal(album.lowercase(), (std::string)"hyrule symphony");
|
|
test_equal(album.year(), (unsigned int)1998);
|
|
test_equal(album.primary_key(), (std::string)"1998/Hyrule Symphony");
|
|
}
|
|
|
|
static void test_album_tag_lookup()
|
|
{
|
|
Database<Album> album_db("album.db", false);
|
|
Album *album = tags :: get_album("Hyrule Symphony", 1998);
|
|
|
|
test_equal(album->name(), (std::string)"Hyrule Symphony");
|
|
test_equal(album->lowercase(), (std::string)"hyrule symphony");
|
|
test_equal(album->year(), (unsigned int)1998);
|
|
test_equal(album->primary_key(), (std::string)"1998/Hyrule Symphony");
|
|
|
|
test_equal(tags :: get_album("Hyrule Symphony", 1998), album);
|
|
test_equal(tags :: get_album(0), album);
|
|
test_equal(tags :: get_album(1), (Album *)NULL);
|
|
|
|
album_db.load();
|
|
test_equal(album_db.size(), (unsigned)1);
|
|
}
|
|
|
|
DECLARE_UNIT_TESTS(
|
|
UNIT_TEST("Album Tag", test_album_tag),
|
|
UNIT_TEST("Album Tag Lookup", test_album_tag_lookup),
|
|
);
|