Commit e455e0da authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

unittests: Remove calls to Media::setType

parent 6ea36b0a
......@@ -207,10 +207,9 @@ class MediaLibrary : public IMediaLibrary, public IDeviceListerCb
bool onDeviceChanged( fs::IFileSystemFactory& fsFactory, Device& device );
bool createThumbnailFolder( const std::string& thumbnailPath ) const;
MediaPtr addExternalMedia( const std::string& mrl, IMedia::Type type );
protected:
virtual void addLocalFsFactory();
MediaPtr addExternalMedia( const std::string& mrl, IMedia::Type type );
// Mark IDeviceListerCb callbacks as private. They must be invoked through the interface.
private:
......
......@@ -62,23 +62,24 @@ std::shared_ptr<Folder> MediaLibraryTester::folder( const std::string& mrl )
return nullptr;
}
std::shared_ptr<Media> MediaLibraryTester::addFile( const std::string& path )
std::shared_ptr<Media> MediaLibraryTester::addFile( const std::string& path, IMedia::Type type )
{
return addFile( std::make_shared<mock::NoopFile>( path ),
dummyFolder, dummyDirectory );
dummyFolder, dummyDirectory, type );
}
std::shared_ptr<Media> MediaLibraryTester::addFile( std::shared_ptr<fs::IFile> file )
std::shared_ptr<Media> MediaLibraryTester::addFile( std::shared_ptr<fs::IFile> file, IMedia::Type type )
{
return addFile( std::move( file ), dummyFolder, dummyDirectory );
return addFile( std::move( file ), dummyFolder, dummyDirectory, type );
}
std::shared_ptr<Media> MediaLibraryTester::addFile( std::shared_ptr<fs::IFile> fileFs,
std::shared_ptr<Folder> parentFolder,
std::shared_ptr<fs::IDirectory> parentFolderFs )
std::shared_ptr<fs::IDirectory> parentFolderFs,
IMedia::Type type )
{
LOG_INFO( "Adding ", fileFs->mrl() );
auto mptr = Media::create( this, IMedia::Type::Unknown,
auto mptr = Media::create( this, type,
utils::file::stripExtension( fileFs->name() ) );
if ( mptr == nullptr )
{
......@@ -189,7 +190,7 @@ void MediaLibraryTester::addDiscoveredFile(std::shared_ptr<fs::IFile> fileFs,
std::shared_ptr<fs::IDirectory> parentFolderFs,
std::pair<std::shared_ptr<Playlist>, unsigned int>)
{
addFile( fileFs, parentFolder, parentFolderFs );
addFile( fileFs, parentFolder, parentFolderFs, IMedia::Type::Unknown );
}
sqlite::Connection* MediaLibraryTester::getDbConn()
......@@ -205,9 +206,9 @@ void MediaLibraryTester::populateFsFactories()
{
}
MediaPtr MediaLibraryTester::addMedia( const std::string& mrl )
MediaPtr MediaLibraryTester::addMedia( const std::string& mrl, IMedia::Type type )
{
return addExternalMedia( mrl );
return addExternalMedia( mrl, type );
}
void MediaLibraryTester::deleteMedia( int64_t mediaId )
......@@ -234,3 +235,9 @@ void MediaLibraryTester::outdateAllExternalMedia()
"WHERE type = ? OR type = ?";
sqlite::Tools::executeUpdate( getConn(), req, IMedia::Type::External, IMedia::Type::Stream );
}
void MediaLibraryTester::setMediaType(int64_t mediaId, IMedia::Type type)
{
std::string req = "UPDATE " + Media::Table::Name + " SET type = ? WHERE id_media = ?";
sqlite::Tools::executeUpdate( getConn(), req, type, mediaId );
}
......@@ -59,12 +59,13 @@ public:
void deleteTrack( int64_t trackId );
std::shared_ptr<AlbumTrack> albumTrack( int64_t id );
// Use to run tests that fiddles with file properties (modification dates, size...)
std::shared_ptr<Media> addFile( std::shared_ptr<fs::IFile> file);
std::shared_ptr<Media> addFile(std::shared_ptr<fs::IFile> file, IMedia::Type type);
// Used when we need an actual file instead of an external media
std::shared_ptr<Media> addFile( const std::string& path );
std::shared_ptr<Media> addFile(const std::string& path , IMedia::Type type);
std::shared_ptr<Media> addFile( std::shared_ptr<fs::IFile> fileFs,
std::shared_ptr<Folder> parentFolder,
std::shared_ptr<fs::IDirectory> parentFolderFs );
std::shared_ptr<fs::IDirectory> parentFolderFs,
IMedia::Type type );
virtual void addLocalFsFactory() override;
std::shared_ptr<Device> device( const std::string& uuid );
std::vector<const char*> getSupportedExtensions() const;
......@@ -75,11 +76,12 @@ public:
sqlite::Connection* getDbConn();
virtual void startThumbnailer();
virtual void populateFsFactories();
MediaPtr addMedia( const std::string& mrl );
MediaPtr addMedia( const std::string& mrl, IMedia::Type type = IMedia::Type::External );
void deleteMedia( int64_t mediaId );
void outdateAllDevices();
void setMediaInsertionDate( int64_t mediaId, time_t t );
void outdateAllExternalMedia();
void setMediaType( int64_t mediaId, IMedia::Type type );
private:
std::shared_ptr<fs::IDirectory> dummyDirectory;
......
......@@ -64,7 +64,7 @@ TEST_F( Albums, Fetch )
TEST_F( Albums, AddTrack )
{
auto a = ml->createAlbum( "albumtag" );
auto f = std::static_pointer_cast<Media>( ml->addMedia( "track.mp3" ) );
auto f = std::static_pointer_cast<Media>( ml->addMedia( "track.mp3", IMedia::Type::Audio ) );
auto track = a->addTrack( f, 10, 0, 0, nullptr );
f->save();
ASSERT_NE( track, nullptr );
......@@ -611,21 +611,18 @@ TEST_F( Albums, SearchTracks )
{
auto alb = ml->createAlbum( "Mustelidae" );
auto m1 = std::static_pointer_cast<Media>( ml->addMedia( "track1.mp3" ) );
auto m1 = std::static_pointer_cast<Media>( ml->addMedia( "track1.mp3", IMedia::Type::Audio ) );
m1->setTitleBuffered( "otter otter run run" );
m1->setType( IMedia::Type::Audio );
alb->addTrack( m1, 1, 1, 0, nullptr );
m1->save();
auto m2 = std::static_pointer_cast<Media>( ml->addMedia( "track2.mp3" ) );
auto m2 = std::static_pointer_cast<Media>( ml->addMedia( "track2.mp3", IMedia::Type::Audio ) );
m2->setTitleBuffered( "weasel weasel" );
m2->setType( IMedia::Type::Audio );
alb->addTrack( m2, 1, 1, 0, nullptr );
m2->save();
auto m3 = std::static_pointer_cast<Media>( ml->addMedia( "random media.aac" ) );
auto m3 = std::static_pointer_cast<Media>( ml->addMedia( "random media.aac", IMedia::Type::Audio ) );
m3->setTitleBuffered( "otters are cute but not on this album" );
m3->setType( IMedia::Type::Audio );
m3->save();
auto allMedia = ml->searchMedia( "otter", nullptr )->all();
......
......@@ -577,17 +577,15 @@ TEST_F( Artists, SearchTracks )
{
auto artist1 = ml->createArtist( "artist" );
auto album1 = ml->createAlbum( "album" );
auto m1 = std::static_pointer_cast<Media>( ml->addMedia( "track1.mp3" ) );
auto m1 = std::static_pointer_cast<Media>( ml->addMedia( "track1.mp3", Media::Type::Audio ) );
m1->setTitleBuffered( "sea otter" );
m1->setType( Media::Type::Audio );
auto track1 = album1->addTrack( m1, 1, 0, artist1->id(), nullptr );
m1->save();
auto artist2 = ml->createArtist( "artist2" );
auto album2 = ml->createAlbum( "album2" );
auto m2 = std::static_pointer_cast<Media>( ml->addMedia( "track2.mp3" ) );
auto m2 = std::static_pointer_cast<Media>( ml->addMedia( "track2.mp3", IMedia::Type::Audio ) );
m2->setTitleBuffered( "sea cucumber" );
m2->setType( IMedia::Type::Audio );
album2->addTrack( m2, 1, 0, artist2->id(), nullptr );
m2->save();
......
......@@ -37,7 +37,7 @@ protected:
virtual void SetUp() override
{
Tests::SetUp();
m = ml->addFile( "media.mkv" );
m = ml->addFile( "media.mkv", IMedia::Type::Unknown );
auto files = m->files();
ASSERT_EQ( 1u, files.size() );
f = std::static_pointer_cast<File>( files[0] );
......
......@@ -282,13 +282,11 @@ TEST_F( Genres, SearchTracks )
{
auto a = ml->createAlbum( "album" );
auto m = std::static_pointer_cast<Media>( ml->addMedia( "Hell's Kitchen.mp3" ) );
m->setType( IMedia::Type::Audio );
auto m = std::static_pointer_cast<Media>( ml->addMedia( "Hell's Kitchen.mp3", IMedia::Type::Audio ) );
auto t = a->addTrack( m, 1, 1, 0, g.get() );
m->save();
auto m2 = std::static_pointer_cast<Media>( ml->addMedia( "Different genre Hell's Kitchen.mp3" ) );
m2->setType( IMedia::Type::Audio );
auto m2 = std::static_pointer_cast<Media>( ml->addMedia( "Different genre Hell's Kitchen.mp3", IMedia::Type::Audio ) );
auto t2 = a->addTrack( m2, 1, 1, 0, nullptr );
m2->save();
......@@ -304,20 +302,17 @@ TEST_F( Genres, SearchAlbums )
{
auto a1 = ml->createAlbum( "an album" );
auto m = std::static_pointer_cast<Media>( ml->addMedia( "track1.mp3" ) );
m->setType( IMedia::Type::Audio );
auto m = std::static_pointer_cast<Media>( ml->addMedia( "track1.mp3", IMedia::Type::Audio ) );
auto t = a1->addTrack( m, 1, 1, 0, g.get() );
m->save();
auto a2 = ml->createAlbum( "another album" );
auto m2 = std::static_pointer_cast<Media>( ml->addMedia( "Different genre Hell's Kitchen.mp3" ) );
m2->setType( IMedia::Type::Audio );
auto m2 = std::static_pointer_cast<Media>( ml->addMedia( "Different genre Hell's Kitchen.mp3", IMedia::Type::Audio ) );
auto t2 = a2->addTrack( m2, 1, 1, 0, nullptr );
m2->save();
auto a3 = ml->createAlbum( "another album" );
auto m3 = std::static_pointer_cast<Media>( ml->addMedia( "track3.mp3" ) );
m3->setType( IMedia::Type::Audio );
auto m3 = std::static_pointer_cast<Media>( ml->addMedia( "track3.mp3", IMedia::Type::Audio ) );
auto t3 = a3->addTrack( m3, 1, 1, 0, g.get() );
m3->save();
......
......@@ -49,7 +49,7 @@ TEST_F( Medias, Init )
TEST_F( Medias, Create )
{
auto m = ml->addFile( "media.avi" );
auto m = ml->addFile( "media.avi", IMedia::Type::Video );
ASSERT_NE( m, nullptr );
ASSERT_EQ( m->playCount(), 0 );
......@@ -160,8 +160,7 @@ TEST_F( Medias, Search )
for ( auto i = 1u; i <= 10u; ++i )
{
auto m = std::static_pointer_cast<Media>(
ml->addMedia( "track " + std::to_string( i ) + ".mp3" ) );
m->setType( IMedia::Type::Video );
ml->addMedia( "track " + std::to_string( i ) + ".mp3", IMedia::Type::Video ) );
m->save();
}
auto media = ml->searchMedia( "tra", nullptr )->all();
......@@ -182,14 +181,12 @@ TEST_F( Medias, SearchAndSort )
for ( auto i = 1u; i <= 3u; ++i )
{
auto m = std::static_pointer_cast<Media>(
ml->addMedia( "track " + std::to_string( i ) + ".mp3" ) );
m->setType( IMedia::Type::Audio );
ml->addMedia( "track " + std::to_string( i ) + ".mp3", IMedia::Type::Audio ) );
m->setDuration( 3 - i );
m->save();
}
auto m = std::static_pointer_cast<Media>( ml->addMedia( "this pattern doesn't match.mp3" ) );
m->setType( IMedia::Type::Audio );
m->save();
auto m = std::static_pointer_cast<Media>( ml->addMedia(
"this pattern doesn't match.mp3", IMedia::Type::Audio ) );
auto media = ml->searchMedia( "tra", nullptr )->all();
ASSERT_EQ( 3u, media.size() );
......@@ -207,9 +204,7 @@ TEST_F( Medias, SearchAndSort )
TEST_F( Medias, SearchAfterEdit )
{
auto m = std::static_pointer_cast<Media>( ml->addMedia( "media.mp3" ) );
m->setType( IMedia::Type::Audio );
m->save();
auto m = std::static_pointer_cast<Media>( ml->addMedia( "media.mp3", IMedia::Type::Audio ) );
auto media = ml->searchMedia( "media", nullptr )->all();
ASSERT_EQ( 1u, media.size() );
......@@ -226,9 +221,7 @@ TEST_F( Medias, SearchAfterEdit )
TEST_F( Medias, SearchAfterDelete )
{
auto m = std::static_pointer_cast<Media>( ml->addMedia( "media.mp3" ) );
m->setType( IMedia::Type::Audio );
m->save();
auto m = std::static_pointer_cast<Media>( ml->addMedia( "media.mp3", IMedia::Type::Audio ) );
auto media = ml->searchMedia( "media", nullptr )->all();
ASSERT_EQ( 1u, media.size() );
......@@ -242,9 +235,7 @@ TEST_F( Medias, SearchAfterDelete )
TEST_F( Medias, SearchByLabel )
{
auto m = std::static_pointer_cast<Media>( ml->addMedia( "media.mkv" ) );
m->setType( IMedia::Type::Video );
m->save();
auto m = std::static_pointer_cast<Media>( ml->addMedia( "media.mkv", IMedia::Type::Video ) );
auto media = ml->searchMedia( "otter", nullptr )->all();
ASSERT_EQ( 0u, media.size() );
......@@ -293,9 +284,9 @@ TEST_F( Medias, SearchTracks )
auto a = ml->createAlbum( "album" );
for ( auto i = 1u; i <= 10u; ++i )
{
auto m = std::static_pointer_cast<Media>( ml->addMedia( "track " + std::to_string( i ) + ".mp3" ) );
auto m = std::static_pointer_cast<Media>( ml->addMedia( "track " +
std::to_string( i ) + ".mp3", IMedia::Type::Audio ) );
a->addTrack( m, i, 1, 0, 0 );
m->setType( IMedia::Type::Audio );
m->save();
}
auto tracks = ml->searchMedia( "tra", nullptr )->all();
......@@ -313,9 +304,7 @@ TEST_F( Medias, SearchTracks )
TEST_F( Medias, Favorite )
{
auto m = std::static_pointer_cast<Media>( ml->addMedia( "media.mkv" ) );
m->setType( IMedia::Type::Video );
m->save();
auto m = std::static_pointer_cast<Media>( ml->addMedia( "media.mkv", IMedia::Type::Video ) );
ASSERT_FALSE( m->isFavorite() );
m->setFavorite( true );
......@@ -407,19 +396,16 @@ TEST_F( Medias, SetReleaseDate )
TEST_F( Medias, SortByAlpha )
{
auto m1 = std::static_pointer_cast<Media>( ml->addMedia( "media1.mp3" ) );
auto m1 = std::static_pointer_cast<Media>( ml->addMedia( "media1.mp3", Media::Type::Audio ) );
m1->setTitleBuffered( "Abcd" );
m1->setType( Media::Type::Audio );
m1->save();
auto m2 = std::static_pointer_cast<Media>( ml->addMedia( "media2.mp3" ) );
auto m2 = std::static_pointer_cast<Media>( ml->addMedia( "media2.mp3", Media::Type::Audio ) );
m2->setTitleBuffered( "Zyxw" );
m2->setType( Media::Type::Audio );
m2->save();
auto m3 = std::static_pointer_cast<Media>( ml->addMedia( "media3.mp3" ) );
auto m3 = std::static_pointer_cast<Media>( ml->addMedia( "media3.mp3", Media::Type::Audio) );
m3->setTitleBuffered( "afterA-beforeZ" );
m3->setType( Media::Type::Audio );
m3->save();
QueryParameters params { SortingCriteria::Alpha, false };
......@@ -441,15 +427,11 @@ TEST_F( Medias, SortByLastModifDate )
{
auto file1 = std::make_shared<mock::NoopFile>( "media.mkv" );
file1->setLastModificationDate( 666 );
auto m1 = ml->addFile( file1 );
m1->setType( Media::Type::Video );
m1->save();
auto m1 = ml->addFile( file1, Media::Type::Video );
auto file2 = std::make_shared<mock::NoopFile>( "media2.mkv" );
file2->setLastModificationDate( 111 );
auto m2 = ml->addFile( file2 );
m2->setType( Media::Type::Video );
m2->save();
auto m2 = ml->addFile( file2, Media::Type::Video );
QueryParameters params { SortingCriteria::LastModificationDate, false };
auto media = ml->videoFiles( &params )->all();
......@@ -468,15 +450,11 @@ TEST_F( Medias, SortByFileSize )
{
auto file1 = std::make_shared<mock::NoopFile>( "media.mkv" );
file1->setSize( 666 );
auto m1 = ml->addFile( file1 );
m1->setType( Media::Type::Video );
m1->save();
auto m1 = ml->addFile( file1, Media::Type::Video );
auto file2 = std::make_shared<mock::NoopFile>( "media2.mkv" );
file2->setSize( 111 );
auto m2 = ml->addFile( file2 );
m2->setType( Media::Type::Video );
m2->save();
auto m2 = ml->addFile( file2, Media::Type::Video );
QueryParameters params { SortingCriteria::FileSize, false };
auto media = ml->videoFiles( &params )->all();
......@@ -493,15 +471,11 @@ TEST_F( Medias, SortByFileSize )
TEST_F( Medias, SortByFilename )
{
auto m1 = std::static_pointer_cast<Media>( ml->addMedia( "zzzzz.mp3" ) );
m1->setType( Media::Type::Video );
auto m1 = std::static_pointer_cast<Media>( ml->addMedia( "zzzzz.mp3", Media::Type::Video ) );
m1->setTitle( "aaaaa" );
m1->save();
auto m2 = std::static_pointer_cast<Media>( ml->addMedia( "aaaaa.mp3" ) );
m2->setType( Media::Type::Video );
auto m2 = std::static_pointer_cast<Media>( ml->addMedia( "aaaaa.mp3", Media::Type::Video ) );
m2->setTitle( "zzzzz" );
m2->save();
QueryParameters params { SortingCriteria::Filename, false };
auto media = ml->videoFiles( &params )->all();
......@@ -653,9 +627,8 @@ TEST_F( Medias, Pagination )
{
for ( auto i = 1u; i <= 9u; ++i )
{
auto m = std::static_pointer_cast<Media>( ml->addMedia( "track " + std::to_string( i ) + ".mp3" ) );
m->setType( IMedia::Type::Video );
m->save();
auto m = std::static_pointer_cast<Media>( ml->addMedia( "track " +
std::to_string( i ) + ".mp3", IMedia::Type::Video ) );
}
auto allMedia = ml->videoFiles( nullptr )->all();
......@@ -676,17 +649,9 @@ TEST_F( Medias, Pagination )
TEST_F( Medias, SortFilename )
{
auto m1 = std::static_pointer_cast<Media>( ml->addMedia( "AAAAB.mp3" ) );
m1->setType( IMedia::Type::Audio );
m1->save();
auto m2 = std::static_pointer_cast<Media>( ml->addMedia( "aaaaa.mp3" ) );
m2->setType( IMedia::Type::Audio );
m2->save();
auto m3 = std::static_pointer_cast<Media>( ml->addMedia( "BbBbB.mp3" ) );
m3->setType( IMedia::Type::Audio );
m3->save();
auto m1 = std::static_pointer_cast<Media>( ml->addMedia( "AAAAB.mp3", IMedia::Type::Audio ) );
auto m2 = std::static_pointer_cast<Media>( ml->addMedia( "aaaaa.mp3", IMedia::Type::Audio ) );
auto m3 = std::static_pointer_cast<Media>( ml->addMedia( "BbBbB.mp3", IMedia::Type::Audio ) );
QueryParameters params { SortingCriteria::Filename, false };
auto media = ml->audioFiles( &params )->all();
......@@ -719,10 +684,8 @@ TEST_F( Medias, SearchExternal )
auto media = ml->searchMedia( "otter", nullptr )->all();
ASSERT_EQ( 0u, media.size() );
m1->setType( IMedia::Type::Video );
m1->save();
m2->setType( IMedia::Type::Video );
m2->save();
ml->setMediaType( m1->id(), IMedia::Type::Video );
ml->setMediaType( m2->id(), IMedia::Type::Video );
media = ml->searchMedia( "otter", nullptr )->all();
ASSERT_EQ( 2u, media.size() );
......
......@@ -335,20 +335,17 @@ TEST_F( Playlists, AddDuplicate )
TEST_F( Playlists, SearchMedia )
{
auto m1 = std::static_pointer_cast<Media>( ml->addMedia( "m1.mp3" ) );
auto m1 = std::static_pointer_cast<Media>( ml->addMedia( "m1.mp3", IMedia::Type::Audio ) );
m1->setTitleBuffered( "otter" );
m1->setType( IMedia::Type::Audio );
m1->save();
auto m2 = std::static_pointer_cast<Media>( ml->addMedia( "m2.mp3" ) );
auto m2 = std::static_pointer_cast<Media>( ml->addMedia( "m2.mp3", IMedia::Type::Audio ) );
// Won't match since it's not on the beginning of a word
m2->setTitleBuffered( "ENOOTTER" );
m2->setType( IMedia::Type::Audio );
m2->save();
auto m3 = std::static_pointer_cast<Media>( ml->addMedia( "m3.mp3" ) );
auto m3 = std::static_pointer_cast<Media>( ml->addMedia( "m3.mp3", IMedia::Type::Audio ) );
m3->setTitleBuffered( "otter otter otter" );
m3->setType( IMedia::Type::Audio );
m3->save();
pl->append( *m1 );
......
......@@ -316,14 +316,13 @@ TEST_F( Shows, SearchEpisodes )
auto show1 = ml->createShow( "Show1" );
auto show2 = ml->createShow( "show2" );
auto m1 = std::static_pointer_cast<Media>( ml->addMedia( "episode.mkv" ) );
auto m1 = std::static_pointer_cast<Media>( ml->addMedia( "episode.mkv", IMedia::Type::Video ) );
m1->setTitleBuffered( "cute otters" );
m1->setType( IMedia::Type::Video );
// will save the media in db
auto ep1 = show1->addEpisode( *m1, 1 );
auto m2 = std::static_pointer_cast<Media>( ml->addMedia( "other episode.mkv" ) );
auto m2 = std::static_pointer_cast<Media>( ml->addMedia( "other episode.mkv", IMedia::Type::Video ) );
m2->setTitleBuffered( "fluffy otters" );
m2->setType( IMedia::Type::Video );
auto ep2 = show2->addEpisode( *m2, 1 );
auto episodes = ml->searchVideo( "otters", nullptr )->all();
......
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