124 lines
4.0 KiB
C++
124 lines
4.0 KiB
C++
/**
|
|
* @file
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
*/
|
|
#include <core/tags/track.h>
|
|
#include <tests/test.h>
|
|
#include <sstream>
|
|
|
|
static void test_track_tag_default()
|
|
{
|
|
Track track;
|
|
|
|
test_equal(track.album(), (Album *)NULL);
|
|
test_equal(track.artist(), (Artist *)NULL);
|
|
test_equal(track.genre(), (Genre *)NULL);
|
|
test_equal(track.library(), (Library *)NULL);
|
|
|
|
test_equal(track.name(), (std::string)"");
|
|
test_equal(track.lowercase(), (std::string)"");
|
|
test_equal(track.primary_key(), (std::string)"");
|
|
test_equal(track.date(), (std::string)"Never");
|
|
test_equal(track.path(), (std::string)"");
|
|
test_equal(track.length_str(), (std::string)"0:00");
|
|
|
|
test_equal(track.track(), (unsigned)0);
|
|
test_equal(track.length(), (unsigned)0);
|
|
test_equal(track.count(), (unsigned)0);
|
|
}
|
|
|
|
static void test_track_tag_constructor()
|
|
{
|
|
Album *album = tags :: get_album("Hyrule Symphony", 1998);
|
|
Artist *artist = tags :: get_artist("Koji Kondo");
|
|
Genre *genre = tags :: get_genre("Video Game Music");
|
|
Library *library = tags :: get_library("/home/Zelda/Music");
|
|
Track track(album, artist, genre, library,
|
|
"/home/Zelda/Music/Hyrule Symphony/13 - Legend of Zelda Medley.mp3",
|
|
"Legend of Zelda Medley", 288, 13);
|
|
|
|
test_equal(track.album(), album);
|
|
test_equal(track.artist(), artist);
|
|
test_equal(track.genre(), genre);
|
|
test_equal(track.library(), library);
|
|
test_equal(library->size(), (unsigned)1);
|
|
|
|
test_equal(track.name(), (std::string)"Legend of Zelda Medley");
|
|
test_equal(track.lowercase(), (std::string)"legend of zelda medley");
|
|
test_equal(track.date(), (std::string)"Never");
|
|
test_equal(track.path(), (std::string)"/home/Zelda/Music/Hyrule Symphony/13 - Legend of Zelda Medley.mp3");
|
|
test_equal(track.length_str(), (std::string)"4:48");
|
|
test_equal(track.primary_key(), (std::string)"0/Hyrule Symphony/13 - Legend of Zelda Medley.mp3");
|
|
|
|
test_equal(track.track(), (unsigned)13);
|
|
test_equal(track.length(), (unsigned)288);
|
|
test_equal(track.count(), (unsigned)0);
|
|
}
|
|
|
|
static void test_track_tag_destructor()
|
|
{
|
|
Library *library = tags :: get_library("/home/Zelda/Music");
|
|
test_equal(library->size(), (unsigned)0);
|
|
}
|
|
|
|
static void test_track_tag_functional()
|
|
{
|
|
Album *album = tags :: get_album("Hyrule Symphony", 1998);
|
|
Artist *artist = tags :: get_artist("Koji Kondo");
|
|
Genre *genre = tags :: get_genre("Video Game Music");
|
|
Library *library = tags :: get_library("/home/Zelda/Music");
|
|
time_t rawtime = time(NULL);
|
|
struct tm *now = localtime(&rawtime);
|
|
std::stringstream ss;
|
|
Track track1, track2;
|
|
|
|
track1 = Track(album, artist, genre, library,
|
|
"/home/Zelda/Music/Hyrule Symphony/6 - Kakariko Village.mp3",
|
|
"Kakariko Village", 186, 6);
|
|
track1.played();
|
|
test_equal(track1.length_str(), (std::string)"3:06");
|
|
test_equal(track1.count(), (unsigned)1);
|
|
|
|
|
|
std::setlocale(LC_TIME, "C");
|
|
if ((now->tm_mon + 1) < 10)
|
|
ss << "0";
|
|
ss << (now->tm_mon + 1) << "/";
|
|
if (now->tm_mday < 10)
|
|
ss << "0";
|
|
ss << now->tm_mday << "/" << (now->tm_year % 100);
|
|
test_equal(track1.date(), ss.str());
|
|
|
|
|
|
std::setlocale(LC_TIME, "en_US");
|
|
ss.str("");
|
|
if ((now->tm_mon + 1) < 10)
|
|
ss << "0";
|
|
ss << (now->tm_mon + 1) << "/";
|
|
if (now->tm_mday < 10)
|
|
ss << "0";
|
|
ss << now->tm_mday << "/" << now->tm_year + 1900;
|
|
test_equal(track1.date(), ss.str());
|
|
|
|
|
|
/* Not an actual track on the album, I just needed something < 1 min. */
|
|
track2 = Track(album, artist, genre, library,
|
|
"/home/Zelda/Music/Hyrule Symphony/0 - intro.mp3",
|
|
"Intro", 56, 0);
|
|
test_equal(track2.length_str(), (std::string)"0:56");
|
|
|
|
test_equal(track1.compare_date(&track1), 0);
|
|
test_equal(track1.compare_date(&track2), 2014);
|
|
test_equal(track2.compare_date(&track1), -2014);
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
test :: reset_data_dir();
|
|
run_test("Track Tag Default Constructor Test", test_track_tag_default);
|
|
run_test("Track Tag Constructor Test", test_track_tag_constructor);
|
|
run_test("Track Tag Destructor Test", test_track_tag_destructor);
|
|
run_test("Track Tag Functional Test", test_track_tag_functional);
|
|
return 0;
|
|
}
|