Track: Prefetch artist, album, genre and library tags
This makes the code a little bit cleaner, since we don't need to keep doing lookups for each test run. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
50a627412f
commit
39cc10bb3e
|
@ -6,6 +6,14 @@
|
|||
#include <tests/test.h>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
static Artist *artist = NULL;
|
||||
static Album *album = NULL;
|
||||
static Genre *genre = NULL;
|
||||
static Library *library = NULL;
|
||||
const std::string MUSIC_DIR = "/home/Zelda/Music";
|
||||
|
||||
|
||||
static void test_track_tag_default()
|
||||
{
|
||||
Track track;
|
||||
|
@ -29,12 +37,8 @@ static void test_track_tag_default()
|
|||
|
||||
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",
|
||||
MUSIC_DIR + "/Hyrule Symphony/13 - Legend of Zelda Medley.mp3",
|
||||
"Legend of Zelda Medley", 288, 13);
|
||||
|
||||
test_equal(track.album(), album);
|
||||
|
@ -46,7 +50,7 @@ static void test_track_tag_constructor()
|
|||
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.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");
|
||||
|
||||
|
@ -57,24 +61,19 @@ static void test_track_tag_constructor()
|
|||
|
||||
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);
|
||||
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);
|
||||
MUSIC_DIR + "/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);
|
||||
|
@ -103,8 +102,8 @@ static void test_track_tag_functional()
|
|||
|
||||
/* 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);
|
||||
MUSIC_DIR + "/Hyrule Symphony/0 - intro.mp3",
|
||||
"Intro", 56, 0);
|
||||
test_equal(track2.length_str(), (std::string)"0:56");
|
||||
|
||||
test_equal(track1.compare_date(&track1), 0);
|
||||
|
@ -115,6 +114,11 @@ static void test_track_tag_functional()
|
|||
int main(int argc, char **argv)
|
||||
{
|
||||
test :: reset_data_dir();
|
||||
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);
|
||||
|
||||
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);
|
||||
|
|
Loading…
Reference in New Issue