Track: Add a test for the Track destructor

We want to make sure that the _library size is decremented whenever a
track is removed or destroyed.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2014-11-21 08:36:49 -05:00
parent 2dfa9bf168
commit 91f6f54b4e
3 changed files with 14 additions and 7 deletions

View File

@ -29,12 +29,6 @@ Track :: Track(const std::string &f, Library *library)
library->inc_size();
}
Track :: ~Track()
{
if (_library)
_library->dec_size();
}
const std::string Track :: primary_key() const
{
return path();

View File

@ -17,6 +17,12 @@ Track :: Track(Album *album, Artist *artist, Genre *genre, Library *library)
_library->inc_size();
}
Track :: ~Track()
{
if (_library)
_library->dec_size();
}
Album *Track :: album() { return _album; }
Artist *Track :: artist() { return _artist; }
Genre *Track :: genre() { return _genre; }

View File

@ -42,12 +42,19 @@ static void test_track_tag_constructor()
test_equal(track.artist(), artist);
test_equal(track.genre(), genre);
test_equal(track.library(), library);
test_equal(track.library()->size(), (unsigned)1);
test_equal(library->size(), (unsigned)1);
}
static void test_track_tag_destructor()
{
Library *library = tags :: get_library("/home/Zelda/Music");
test_equal(library->size(), (unsigned)0);
}
int main(int argc, char **argv)
{
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);
return 0;
}