2014-11-19 09:08:38 -05:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
|
|
*/
|
|
|
|
#include <core/tags/track.h>
|
|
|
|
#include <tests/test.h>
|
2014-11-27 10:37:46 -05:00
|
|
|
#include <sstream>
|
2014-11-19 09:08:38 -05:00
|
|
|
|
2014-11-28 20:27:08 -05:00
|
|
|
|
|
|
|
static Artist *artist = NULL;
|
|
|
|
static Album *album = NULL;
|
|
|
|
static Genre *genre = NULL;
|
|
|
|
static Library *library = NULL;
|
|
|
|
const std::string MUSIC_DIR = "/home/Zelda/Music";
|
|
|
|
|
|
|
|
|
2014-11-20 08:22:50 -05:00
|
|
|
static void test_track_tag_default()
|
2014-11-19 09:08:38 -05:00
|
|
|
{
|
|
|
|
Track track;
|
|
|
|
|
2014-11-21 08:11:03 -05:00
|
|
|
test_equal(track.album(), (Album *)NULL);
|
2014-11-20 08:41:18 -05:00
|
|
|
test_equal(track.artist(), (Artist *)NULL);
|
2014-11-21 08:25:35 -05:00
|
|
|
test_equal(track.genre(), (Genre *)NULL);
|
2014-11-20 08:16:13 -05:00
|
|
|
test_equal(track.library(), (Library *)NULL);
|
2014-11-19 09:08:38 -05:00
|
|
|
|
|
|
|
test_equal(track.name(), (std::string)"");
|
|
|
|
test_equal(track.lowercase(), (std::string)"");
|
|
|
|
test_equal(track.primary_key(), (std::string)"");
|
2014-11-27 10:37:46 -05:00
|
|
|
test_equal(track.date(), (std::string)"Never");
|
2014-11-26 21:25:39 -05:00
|
|
|
test_equal(track.path(), (std::string)"");
|
2014-11-26 08:55:06 -05:00
|
|
|
test_equal(track.length_str(), (std::string)"0:00");
|
2014-11-19 09:08:38 -05:00
|
|
|
|
2014-11-27 10:37:46 -05:00
|
|
|
test_equal(track.track(), (unsigned)0);
|
|
|
|
test_equal(track.length(), (unsigned)0);
|
|
|
|
test_equal(track.count(), (unsigned)0);
|
2014-11-19 09:08:38 -05:00
|
|
|
}
|
|
|
|
|
2014-11-29 09:56:48 -05:00
|
|
|
static void verify_track_tag(Track *track, unsigned int size)
|
|
|
|
{
|
|
|
|
test_equal(track->album(), album);
|
|
|
|
test_equal(track->artist(), artist);
|
|
|
|
test_equal(track->genre(), genre);
|
|
|
|
test_equal(track->library(), library);
|
|
|
|
|
|
|
|
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)MUSIC_DIR + "/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);
|
|
|
|
test_equal(library->size(), size);
|
|
|
|
}
|
|
|
|
|
2014-11-20 08:22:50 -05:00
|
|
|
static void test_track_tag_constructor()
|
|
|
|
{
|
2014-11-29 09:56:48 -05:00
|
|
|
File f("track_tag", 0);
|
|
|
|
Track a(album, artist, genre, library,
|
2014-11-29 10:17:21 -05:00
|
|
|
"Hyrule Symphony/13 - Legend of Zelda Medley.mp3",
|
2014-11-29 09:56:48 -05:00
|
|
|
"Legend of Zelda Medley", 288, 13);
|
|
|
|
Track b;
|
2014-11-26 08:23:20 -05:00
|
|
|
|
2014-11-29 09:56:48 -05:00
|
|
|
verify_track_tag(&a, 1);
|
|
|
|
|
|
|
|
f.open(OPEN_WRITE);
|
|
|
|
a.write(f);
|
|
|
|
f.close();
|
|
|
|
|
|
|
|
f.open(OPEN_READ);
|
|
|
|
b.read(f);
|
|
|
|
f.close();
|
|
|
|
|
|
|
|
verify_track_tag(&b, 2);
|
2014-11-21 08:36:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_track_tag_destructor()
|
|
|
|
{
|
|
|
|
test_equal(library->size(), (unsigned)0);
|
2014-11-20 08:22:50 -05:00
|
|
|
}
|
|
|
|
|
2014-11-29 10:38:27 -05:00
|
|
|
static void test_track_tag_lookup()
|
|
|
|
{
|
2014-11-29 11:16:21 -05:00
|
|
|
Database<Track> track_db("track.db", false);
|
2014-11-29 10:38:27 -05:00
|
|
|
Track *a, *b;
|
|
|
|
|
|
|
|
a = tags :: add_track(album, artist, genre, library,
|
|
|
|
MUSIC_DIR + "/Hyrule Symphony/13 - Legend of Zelda Medley.mp3",
|
|
|
|
"Legend of Zelda Medley", 288, 13);
|
|
|
|
test_not_equal(a, (Track *)NULL);
|
|
|
|
verify_track_tag(a, 1);
|
|
|
|
|
|
|
|
b = tags :: add_track(album, artist, genre, library,
|
|
|
|
MUSIC_DIR + "/Hyrule Symphony/13 - Legend of Zelda Medley.mp3",
|
|
|
|
"Legend of Zelda Medley", 288, 13);
|
|
|
|
test_equal(b, (Track *)NULL);
|
2014-11-29 11:11:49 -05:00
|
|
|
|
|
|
|
test_equal(tags :: get_track(a->index()), a);
|
|
|
|
test_equal(tags :: get_track(a->index() + 1), (Track *)NULL);
|
2014-11-29 11:16:21 -05:00
|
|
|
|
|
|
|
track_db.load();
|
|
|
|
test_equal(track_db.size(), (unsigned)0);
|
|
|
|
|
|
|
|
tags :: commit_track_db();
|
|
|
|
track_db.load();
|
|
|
|
test_equal(track_db.size(), (unsigned)1);
|
2014-11-29 10:38:27 -05:00
|
|
|
}
|
|
|
|
|
2014-11-26 08:55:06 -05:00
|
|
|
static void test_track_tag_functional()
|
|
|
|
{
|
2014-11-28 20:27:08 -05:00
|
|
|
time_t rawtime = time(NULL);
|
|
|
|
struct tm *now = localtime(&rawtime);
|
2014-11-27 10:37:46 -05:00
|
|
|
std::stringstream ss;
|
2014-11-28 21:18:36 -05:00
|
|
|
Track track1, track2, track3;
|
2014-11-26 08:55:06 -05:00
|
|
|
|
2014-11-28 10:21:35 -05:00
|
|
|
track1 = Track(album, artist, genre, library,
|
2014-11-29 10:17:21 -05:00
|
|
|
"Hyrule Symphony/6 - Kakariko Village.mp3",
|
2014-11-28 20:27:08 -05:00
|
|
|
"Kakariko Village", 186, 6);
|
2014-11-28 10:21:35 -05:00
|
|
|
track1.played();
|
|
|
|
test_equal(track1.length_str(), (std::string)"3:06");
|
|
|
|
test_equal(track1.count(), (unsigned)1);
|
2014-11-27 10:37:46 -05:00
|
|
|
|
|
|
|
|
|
|
|
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);
|
2014-11-28 10:21:35 -05:00
|
|
|
test_equal(track1.date(), ss.str());
|
2014-11-27 10:37:46 -05:00
|
|
|
|
|
|
|
|
|
|
|
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;
|
2014-11-28 10:21:35 -05:00
|
|
|
test_equal(track1.date(), ss.str());
|
2014-11-27 10:37:46 -05:00
|
|
|
|
2014-11-26 08:55:06 -05:00
|
|
|
|
|
|
|
/* Not an actual track on the album, I just needed something < 1 min. */
|
2014-11-28 10:21:35 -05:00
|
|
|
track2 = Track(album, artist, genre, library,
|
2014-11-29 10:17:21 -05:00
|
|
|
"Hyrule Symphony/0 - intro.mp3",
|
2014-11-28 20:27:08 -05:00
|
|
|
"Intro", 56, 0);
|
2014-11-28 10:21:35 -05:00
|
|
|
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);
|
2014-11-26 08:55:06 -05:00
|
|
|
}
|
|
|
|
|
2014-11-19 09:08:38 -05:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2014-11-26 21:25:39 -05:00
|
|
|
test :: reset_data_dir();
|
2014-11-28 20:27:08 -05:00
|
|
|
album = tags :: get_album("Hyrule Symphony", 1998);
|
|
|
|
artist = tags :: get_artist("Koji Kondo");
|
|
|
|
genre = tags :: get_genre("Video Game Music");
|
|
|
|
library = tags :: get_library(MUSIC_DIR);
|
|
|
|
|
2014-11-20 08:22:50 -05:00
|
|
|
run_test("Track Tag Default Constructor Test", test_track_tag_default);
|
|
|
|
run_test("Track Tag Constructor Test", test_track_tag_constructor);
|
2014-11-21 08:36:49 -05:00
|
|
|
run_test("Track Tag Destructor Test", test_track_tag_destructor);
|
2014-11-29 10:38:27 -05:00
|
|
|
run_test("Track Tag Lookup Test", test_track_tag_lookup);
|
2014-11-26 08:55:06 -05:00
|
|
|
run_test("Track Tag Functional Test", test_track_tag_functional);
|
2014-11-19 09:08:38 -05:00
|
|
|
return 0;
|
|
|
|
}
|