Commit d8fe4e71 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

Tests: Make IMediaLibrary instance a unique_ptr

parent 93802e24
......@@ -8,25 +8,24 @@
class Albums : public testing::Test
{
public:
static IMediaLibrary* ml;
static std::unique_ptr<IMediaLibrary> ml;
protected:
virtual void SetUp()
{
ml = MediaLibraryFactory::create();
ml.reset( MediaLibraryFactory::create() );
bool res = ml->initialize( "test.db" );
ASSERT_TRUE( res );
}
virtual void TearDown()
{
delete ml;
ml = nullptr;
ml.reset();
unlink("test.db");
}
};
IMediaLibrary* Albums::ml;
std::unique_ptr<IMediaLibrary> Albums::ml;
TEST_F( Albums, Create )
{
......@@ -42,7 +41,6 @@ TEST_F( Albums, Fetch )
auto a = ml->createAlbum( "album" );
// Clear the cache
delete ml;
SetUp();
auto a2 = ml->album( "album" );
......@@ -64,7 +62,6 @@ TEST_F( Albums, AddTrack )
ASSERT_EQ( tracks.size(), 1u );
ASSERT_EQ( tracks[0], track );
delete ml;
SetUp();
a->tracks( tracks );
......@@ -84,7 +81,6 @@ TEST_F( Albums, AssignTrack )
ASSERT_NE( f->albumTrack(), nullptr );
ASSERT_EQ( f->albumTrack(), t );
delete ml;
SetUp();
f = ml->file( "file" );
......@@ -115,7 +111,6 @@ TEST_F( Albums, SetGenre )
t->setGenre( "happy underground post progressive death metal" );
ASSERT_EQ( t->genre(), "happy underground post progressive death metal" );
delete ml;
SetUp();
std::vector<AlbumTrackPtr> tracks;
......@@ -131,7 +126,6 @@ TEST_F( Albums, SetName )
a->setName( "albumname" );
ASSERT_EQ( a->name(), "albumname" );
delete ml;
SetUp();
auto a2 = ml->album( "album" );
......@@ -145,7 +139,6 @@ TEST_F( Albums, SetReleaseDate )
a->setReleaseDate( 1234 );
ASSERT_EQ( a->releaseDate(), 1234 );
delete ml;
SetUp();
auto a2 = ml->album( "album" );
......@@ -159,7 +152,6 @@ TEST_F( Albums, SetShortSummary )
a->setShortSummary( "summary" );
ASSERT_EQ( a->shortSummary(), "summary" );
delete ml;
SetUp();
auto a2 = ml->album( "album" );
......@@ -173,7 +165,6 @@ TEST_F( Albums, SetArtworkUrl )
a->setArtworkUrl( "artwork" );
ASSERT_EQ( a->artworkUrl(), "artwork" );
delete ml;
SetUp();
auto a2 = ml->album( "album" );
......@@ -189,7 +180,6 @@ TEST_F( Albums, FetchAlbumFromTrack )
auto t = a->addTrack( "track 1", 1 );
f->setAlbumTrack( t );
}
delete ml;
SetUp();
auto f = ml->file( "file" );
......
......@@ -6,25 +6,24 @@
class Files : public testing::Test
{
public:
static IMediaLibrary* ml;
static std::unique_ptr<IMediaLibrary> ml;
protected:
virtual void SetUp()
{
ml = MediaLibraryFactory::create();
ml.reset( MediaLibraryFactory::create() );
bool res = ml->initialize( "test.db" );
ASSERT_TRUE( res );
}
virtual void TearDown()
{
delete ml;
ml = nullptr;
ml.reset();
unlink("test.db");
}
};
IMediaLibrary* Files::ml;
std::unique_ptr<IMediaLibrary> Files::ml;
TEST_F( Files, Init )
{
......@@ -55,7 +54,6 @@ TEST_F( Files, Fetch )
ASSERT_EQ( f, f2 );
// Flush cache and fetch from DB
delete ml;
SetUp();
f2 = ml->file( "/dev/null" );
......
......@@ -7,24 +7,24 @@
class Labels : public testing::Test
{
public:
static IMediaLibrary* ml;
static std::unique_ptr<IMediaLibrary> ml;
protected:
virtual void SetUp()
{
ml = MediaLibraryFactory::create();
ml.reset( MediaLibraryFactory::create() );
bool res = ml->initialize( "test.db" );
ASSERT_TRUE( res );
}
virtual void TearDown()
{
delete ml;
ml.reset();
unlink("test.db");
}
};
IMediaLibrary* Labels::ml;
std::unique_ptr<IMediaLibrary> Labels::ml;
TEST_F( Labels, Add )
{
......
......@@ -7,25 +7,24 @@
class Movies : public testing::Test
{
public:
static IMediaLibrary* ml;
static std::unique_ptr<IMediaLibrary> ml;
protected:
virtual void SetUp()
{
ml = MediaLibraryFactory::create();
ml.reset( MediaLibraryFactory::create() );
bool res = ml->initialize( "test.db" );
ASSERT_TRUE( res );
}
virtual void TearDown()
{
delete ml;
ml = nullptr;
ml.reset();
unlink("test.db");
}
};
IMediaLibrary* Movies::ml;
std::unique_ptr<IMediaLibrary> Movies::ml;
TEST_F( Movies, Create )
{
......@@ -41,7 +40,6 @@ TEST_F( Movies, Fetch )
ASSERT_EQ( m, m2 );
delete ml;
SetUp();
m2 = ml->movie( "movie" );
......@@ -56,7 +54,6 @@ TEST_F( Movies, SetReleaseDate )
m->setReleaseDate( 1234 );
ASSERT_EQ( m->releaseDate(), 1234u );
delete ml;
SetUp();
m = ml->movie( "movie" );
......@@ -70,7 +67,6 @@ TEST_F( Movies, SetShortSummary )
m->setShortSummary( "great movie" );
ASSERT_EQ( m->shortSummary(), "great movie" );
delete ml;
SetUp();
m = ml->movie( "movie" );
......@@ -84,7 +80,6 @@ TEST_F( Movies, SetArtworkUrl )
m->setArtworkUrl( "artwork" );
ASSERT_EQ( m->artworkUrl(), "artwork" );
delete ml;
SetUp();
m = ml->movie( "movie" );
......@@ -98,7 +93,6 @@ TEST_F( Movies, SetImdbId )
m->setImdbId( "id" );
ASSERT_EQ( m->imdbId(), "id" );
delete ml;
SetUp();
m = ml->movie( "movie" );
......@@ -114,7 +108,6 @@ TEST_F( Movies, AssignToFile )
f->setMovie( m );
ASSERT_EQ( f->movie(), m );
delete ml;
SetUp();
f = ml->file( "file" );
......@@ -134,7 +127,6 @@ TEST_F( Movies, DestroyMovie )
f = ml->file( "file" );
ASSERT_EQ( f, nullptr );
delete ml;
SetUp();
f = ml->file( "file" );
......
......@@ -8,25 +8,24 @@
class Shows : public testing::Test
{
public:
static IMediaLibrary* ml;
static std::unique_ptr<IMediaLibrary> ml;
protected:
virtual void SetUp()
{
ml = MediaLibraryFactory::create();
ml.reset( MediaLibraryFactory::create() );
bool res = ml->initialize( "test.db" );
ASSERT_TRUE( res );
}
virtual void TearDown()
{
delete ml;
ml = nullptr;
ml.reset();
unlink("test.db");
}
};
IMediaLibrary* Shows::ml;
std::unique_ptr<IMediaLibrary> Shows::ml;
TEST_F( Shows, Create )
{
......@@ -42,7 +41,6 @@ TEST_F( Shows, Fetch )
auto s = ml->createShow( "show" );
// Clear the cache
delete ml;
SetUp();
auto s2 = ml->show( "show" );
......@@ -59,7 +57,6 @@ TEST_F( Shows, SetReleaseDate )
s->setReleaseDate( 1234 );
ASSERT_EQ( s->releaseDate(), 1234 );
delete ml;
SetUp();
auto s2 = ml->show( "show" );
......@@ -73,7 +70,7 @@ TEST_F( Shows, SetShortSummary )
s->setShortSummary( "summary" );
ASSERT_EQ( s->shortSummary(), "summary" );
delete ml;
SetUp();
auto s2 = ml->show( "show" );
......@@ -87,7 +84,6 @@ TEST_F( Shows, SetArtworkUrl )
s->setArtworkUrl( "artwork" );
ASSERT_EQ( s->artworkUrl(), "artwork" );
delete ml;
SetUp();
auto s2 = ml->show( "show" );
......@@ -101,7 +97,6 @@ TEST_F( Shows, SetTvdbId )
s->setTvdbId( "TVDBID" );
ASSERT_EQ( s->tvdbId(), "TVDBID" );
delete ml;
SetUp();
auto s2 = ml->show( "show" );
......@@ -141,7 +136,6 @@ TEST_F( Shows, FetchShowFromEpisode )
ASSERT_NE( s2, nullptr );
ASSERT_EQ( s, s2 );
delete ml;
SetUp();
f = ml->file( "file" );
......@@ -158,7 +152,6 @@ TEST_F( Shows, SetEpisodeArtwork )
ASSERT_TRUE( res );
ASSERT_EQ( e->artworkUrl(), "path-to-snapshot" );
delete ml;
SetUp();
show = ml->show( "show" );
......@@ -175,7 +168,6 @@ TEST_F( Shows, SetEpisodeSeasonNumber )
ASSERT_TRUE( res );
ASSERT_EQ( e->seasonNumber(), 42u );
delete ml;
SetUp();
show = ml->show( "show" );
......@@ -192,7 +184,6 @@ TEST_F( Shows, SetEpisodeSummary )
ASSERT_TRUE( res );
ASSERT_EQ( e->shortSummary(), "Insert spoilers here" );
delete ml;
SetUp();
show = ml->show( "show" );
......@@ -209,7 +200,6 @@ TEST_F( Shows, SetEpisodeTvdbId )
ASSERT_TRUE( res );
ASSERT_EQ( e->tvdbId(), "TVDBID" );
delete ml;
SetUp();
show = ml->show( "show" );
......@@ -232,7 +222,6 @@ TEST_F( Shows, FileSetShowEpisode )
f->setShowEpisode( e );
ASSERT_EQ( f->showEpisode(), e );
delete ml;
SetUp();
f = ml->file( "file" );
......@@ -253,7 +242,6 @@ TEST_F( Shows, DeleteShowEpisode )
f = ml->file( "file" );
ASSERT_EQ( f, nullptr );
delete ml;
SetUp();
f = ml->file( "file" );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment