Track: Clean up test for reads and writes

I want to test basic reading and writing before running the functional
test, since the functional test will eventually trigger database
commits.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2014-11-29 09:56:48 -05:00
parent 2578cdadfe
commit cfef5c07a0
1 changed files with 34 additions and 43 deletions

View File

@ -35,28 +35,45 @@ static void test_track_tag_default()
test_equal(track.count(), (unsigned)0);
}
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);
}
static void test_track_tag_constructor()
{
Track track(album, artist, genre, library,
MUSIC_DIR + "/Hyrule Symphony/13 - Legend of Zelda Medley.mp3",
"Legend of Zelda Medley", 288, 13);
File f("track_tag", 0);
Track a(album, artist, genre, library,
MUSIC_DIR + "/Hyrule Symphony/13 - Legend of Zelda Medley.mp3",
"Legend of Zelda Medley", 288, 13);
Track b;
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);
verify_track_tag(&a, 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)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");
f.open(OPEN_WRITE);
a.write(f);
f.close();
test_equal(track.track(), (unsigned)13);
test_equal(track.length(), (unsigned)288);
test_equal(track.count(), (unsigned)0);
f.open(OPEN_READ);
b.read(f);
f.close();
verify_track_tag(&b, 2);
}
static void test_track_tag_destructor()
@ -66,7 +83,6 @@ static void test_track_tag_destructor()
static void test_track_tag_functional()
{
File f("track_tag", 0);
time_t rawtime = time(NULL);
struct tm *now = localtime(&rawtime);
std::stringstream ss;
@ -110,31 +126,6 @@ static void test_track_tag_functional()
test_equal(track1.compare_date(&track1), 0);
test_equal(track1.compare_date(&track2), 2014);
test_equal(track2.compare_date(&track1), -2014);
f.open(OPEN_WRITE);
track1.write(f);
f.close();
f.open(OPEN_READ);
track3.read(f);
f.close();
test_equal(track1.album(), track3.album());
test_equal(track1.artist(), track3.artist());
test_equal(track1.genre(), track3.genre());
test_equal(track1.library(), track3.library());
test_equal(track1.name(), track3.name());
test_equal(track1.lowercase(), track3.lowercase());
test_equal(track1.primary_key(), track3.primary_key());
test_equal(track1.date(), track3.date());
test_equal(track1.path(), track3.path());
test_equal(track1.length_str(), track3.length_str());
test_equal(track1.track(), track3.track());
test_equal(track1.length(), track3.length());
test_equal(track1.count(), track3.count());
}
int main(int argc, char **argv)