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

Return vectors by value

parent f05e350c
......@@ -17,7 +17,7 @@ class IAlbum
virtual bool setShortSummary( const std::string& summary ) = 0;
virtual const std::string& artworkUrl() const = 0;
virtual bool setArtworkUrl( const std::string& artworkUrl ) = 0;
virtual bool tracks( std::vector<std::shared_ptr<IAlbumTrack>>& tracks ) const = 0;
virtual std::vector<std::shared_ptr<IAlbumTrack>> tracks() const = 0;
virtual AlbumTrackPtr addTrack( const std::string& title, unsigned int trackId ) = 0;
virtual bool destroy() = 0;
};
......
......@@ -18,7 +18,7 @@ class IAlbumTrack
virtual std::shared_ptr<IAlbum> album() = 0;
virtual const std::string& artist() const = 0;
virtual bool setArtist( const std::string& artist ) = 0;
virtual bool files( std::vector<FilePtr>& files ) = 0;
virtual std::vector<FilePtr> files() = 0;
/**
* @brief destroy Deletes the album track and the file(s) associated
*/
......
......@@ -38,10 +38,10 @@ class IFile
virtual std::vector<std::shared_ptr<ILabel> > labels() = 0;
virtual bool addVideoTrack( const std::string& codec, unsigned int width,
unsigned int height, float fps ) = 0;
virtual bool videoTracks( std::vector<VideoTrackPtr>& tracks ) = 0;
virtual std::vector<VideoTrackPtr> videoTracks() = 0;
virtual bool addAudioTrack( const std::string& codec, unsigned int bitrate,
unsigned int sampleRate, unsigned int nbChannels ) = 0;
virtual bool audioTracks( std::vector<AudioTrackPtr>& tracks ) = 0;
virtual std::vector<AudioTrackPtr> audioTracks() = 0;
/// Returns wether the file has been added as a stand alone file (true), or as
/// part of a folder (false)
virtual bool isStandAlone() = 0;
......
......@@ -13,7 +13,7 @@ class ILabel
virtual unsigned int id() const = 0;
virtual const std::string& name() = 0;
virtual bool files( std::vector<FilePtr>& files ) = 0;
virtual std::vector<FilePtr> files() = 0;
};
#endif // ILABEL_H
......@@ -43,7 +43,7 @@ class IMediaLibrary
virtual LabelPtr createLabel( const std::string& label ) = 0;
virtual bool deleteLabel( const std::string& label ) = 0;
virtual bool deleteLabel( LabelPtr label ) = 0;
virtual bool files( std::vector<FilePtr>& res ) = 0;
virtual std::vector<FilePtr> files() = 0;
virtual AlbumPtr album( const std::string& title ) = 0;
virtual AlbumPtr createAlbum( const std::string& title ) = 0;
virtual ShowPtr show( const std::string& name ) = 0;
......
......@@ -18,7 +18,7 @@ class IMovie
virtual const std::string& imdbId() const = 0;
virtual bool setImdbId( const std::string& id ) = 0;
virtual bool destroy() = 0;
virtual bool files( std::vector<FilePtr>& files ) = 0;
virtual std::vector<FilePtr> files() = 0;
};
#endif // IMOVIE_H
......@@ -18,7 +18,7 @@ class IShow
virtual const std::string& tvdbId() = 0;
virtual bool setTvdbId( const std::string& id ) = 0;
virtual ShowEpisodePtr addEpisode( const std::string& title, unsigned int episodeNumber ) = 0;
virtual bool episodes( std::vector<ShowEpisodePtr>& episodes ) = 0;
virtual std::vector<ShowEpisodePtr> episodes() = 0;
virtual bool destroy() = 0;
};
......
......@@ -23,7 +23,7 @@ class IShowEpisode
virtual const std::string& tvdbId() const = 0;
virtual bool setTvdbId( const std::string& tvdbId ) = 0;
virtual std::shared_ptr<IShow> show() = 0;
virtual bool files( std::vector<FilePtr>& files ) = 0;
virtual std::vector<FilePtr> files() = 0;
/**
* @brief destroy Deletes the album track and the file(s) associated
*/
......
......@@ -86,11 +86,11 @@ time_t Album::lastSyncDate() const
return m_lastSyncDate;
}
bool Album::tracks( std::vector<std::shared_ptr<IAlbumTrack> >& tracks ) const
std::vector<std::shared_ptr<IAlbumTrack>> Album::tracks() const
{
static const std::string req = "SELECT * FROM " + policy::AlbumTrackTable::Name
+ " WHERE album_id = ?";
return SqliteTools::fetchAll<AlbumTrack>( m_dbConnection, req, tracks, m_id );
return SqliteTools::fetchAll<AlbumTrack, IAlbumTrack>( m_dbConnection, req, m_id );
}
AlbumTrackPtr Album::addTrack( const std::string& title, unsigned int trackNb )
......@@ -100,9 +100,7 @@ AlbumTrackPtr Album::addTrack( const std::string& title, unsigned int trackNb )
bool Album::destroy()
{
std::vector<AlbumTrackPtr> ts;
if ( tracks( ts ) == false )
return false;
auto ts = tracks();
//FIXME: Have a single request to fetch all files at once, instead of having one per track
for ( auto& t : ts )
{
......
......@@ -38,7 +38,7 @@ class Album : public IAlbum, public Cache<Album, IAlbum, policy::AlbumTable>
virtual const std::string& artworkUrl() const;
virtual bool setArtworkUrl( const std::string& artworkUrl );
virtual time_t lastSyncDate() const;
virtual bool tracks( std::vector<std::shared_ptr<IAlbumTrack>>& tracks ) const;
virtual std::vector<std::shared_ptr<IAlbumTrack> > tracks() const;
virtual AlbumTrackPtr addTrack( const std::string& title, unsigned int trackNb );
virtual bool destroy();
......
......@@ -95,9 +95,7 @@ std::shared_ptr<IAlbum> AlbumTrack::album()
bool AlbumTrack::destroy()
{
// Manually remove Files from cache, and let foreign key handling delete them from the DB
std::vector<FilePtr> fs;
if ( files( fs ) == false )
return false;
auto fs = files();
if ( fs.size() == 0 )
std::cerr << "No files found for AlbumTrack " << m_id << std::endl;
for ( auto& f : fs )
......@@ -124,9 +122,9 @@ bool AlbumTrack::setArtist(const std::string& artist)
return true;
}
bool AlbumTrack::files(std::vector<FilePtr>& files)
std::vector<FilePtr> AlbumTrack::files()
{
static const std::string req = "SELECT * FROM " + policy::FileTable::Name
+ " WHERE album_track_id = ? ";
return SqliteTools::fetchAll<File>( m_dbConnection, req, files, m_id );
return SqliteTools::fetchAll<File, IFile>( m_dbConnection, req, m_id );
}
......@@ -38,7 +38,7 @@ class AlbumTrack : public IAlbumTrack, public Cache<AlbumTrack, IAlbumTrack, pol
virtual bool destroy();
virtual const std::string& artist() const;
virtual bool setArtist( const std::string& artist );
virtual bool files( std::vector<FilePtr>& files );
virtual std::vector<FilePtr> files();
static bool createTable( DBConnection dbConnection );
static AlbumTrackPtr create( DBConnection dbConnection, unsigned int albumId,
......
......@@ -72,10 +72,10 @@ class Cache
* @param res A reference to the result vector. All existing elements will
* be discarded.
*/
static bool fetchAll( DBConnection dbConnectionWeak, std::vector<std::shared_ptr<INTF> >& res )
static std::vector<std::shared_ptr<INTF>> fetchAll( DBConnection dbConnectionWeak )
{
static const std::string req = "SELECT * FROM " + TABLEPOLICY::Name;
return SqliteTools::fetchAll<IMPL, INTF>( dbConnectionWeak, req.c_str(), res );
return SqliteTools::fetchAll<IMPL, INTF>( dbConnectionWeak, req.c_str() );
}
static std::shared_ptr<IMPL> load( std::shared_ptr<sqlite3> dbConnection, sqlite3_stmt* stmt )
......
......@@ -115,12 +115,10 @@ bool File::setShowEpisode(ShowEpisodePtr showEpisode)
std::vector<std::shared_ptr<ILabel> > File::labels()
{
std::vector<std::shared_ptr<ILabel> > labels;
static const std::string req = "SELECT l.* FROM " + policy::LabelTable::Name + " l "
"LEFT JOIN LabelFileRelation lfr ON lfr.id_label = l.id_label "
"WHERE lfr.id_file = ?";
SqliteTools::fetchAll<Label>( m_dbConnection, req, labels, m_id );
return labels;
return SqliteTools::fetchAll<Label, ILabel>( m_dbConnection, req, m_id );
}
int File::playCount() const
......@@ -167,12 +165,12 @@ bool File::addVideoTrack(const std::string& codec, unsigned int width, unsigned
return SqliteTools::executeRequest( m_dbConnection, req, track->id(), m_id );
}
bool File::videoTracks(std::vector<VideoTrackPtr>& tracks)
std::vector<VideoTrackPtr> File::videoTracks()
{
static const std::string req = "SELECT t.* FROM " + policy::VideoTrackTable::Name +
" t LEFT JOIN VideoTrackFileRelation vtfr ON vtfr.id_track = t.id_track"
" WHERE vtfr.id_file = ?";
return SqliteTools::fetchAll<VideoTrack>( m_dbConnection, req, tracks, m_id );
return SqliteTools::fetchAll<VideoTrack, IVideoTrack>( m_dbConnection, req, m_id );
}
bool File::addAudioTrack( const std::string& codec, unsigned int bitrate,
......@@ -190,12 +188,12 @@ bool File::addAudioTrack( const std::string& codec, unsigned int bitrate,
return SqliteTools::executeRequest( m_dbConnection, req, track->id(), m_id );
}
bool File::audioTracks( std::vector<AudioTrackPtr>& tracks )
std::vector<AudioTrackPtr> File::audioTracks()
{
static const std::string req = "SELECT t.* FROM " + policy::AudioTrackTable::Name +
" t LEFT JOIN AudioTrackFileRelation atfr ON atfr.id_track = t.id_track"
" WHERE atfr.id_file = ?";
return SqliteTools::fetchAll<AudioTrack>( m_dbConnection, req, tracks, m_id );
return SqliteTools::fetchAll<AudioTrack, IAudioTrack>( m_dbConnection, req, m_id );
}
bool File::isStandAlone()
......
......@@ -60,9 +60,9 @@ class File : public IFile, public Cache<File, IFile, policy::FileTable, policy::
virtual bool setMovie( MoviePtr movie );
virtual bool addVideoTrack( const std::string& codec, unsigned int width,
unsigned int height, float fps );
virtual bool videoTracks( std::vector<VideoTrackPtr>& tracks );
virtual std::vector<VideoTrackPtr> videoTracks();
virtual bool addAudioTrack(const std::string& codec, unsigned int bitrate , unsigned int sampleRate, unsigned int nbChannels);
virtual bool audioTracks( std::vector<AudioTrackPtr>& tracks );
virtual std::vector<AudioTrackPtr> audioTracks();
virtual bool isStandAlone() override;
virtual bool isReady() const;
......
......@@ -56,7 +56,5 @@ std::vector<FilePtr> Folder::files()
{
static const std::string req = "SELECT f.* FROM " + policy::FileTable::Name +
" WHERE f.id_folder = ?";
auto res = std::vector<FilePtr>{};
SqliteTools::fetchAll<File>( m_dbConection, req, res, m_id );
return res;
return SqliteTools::fetchAll<File, IFile>( m_dbConection, req, m_id );
}
......@@ -33,12 +33,12 @@ const std::string& Label::name()
return m_name;
}
bool Label::files( std::vector<FilePtr>& files )
std::vector<FilePtr> Label::files()
{
static const std::string req = "SELECT f.* FROM " + policy::FileTable::Name + " f "
"LEFT JOIN LabelFileRelation lfr ON lfr.id_file = f.id_file "
"WHERE lfr.id_label = ?";
return SqliteTools::fetchAll<File>( m_dbConnection, req, files, m_id );
return SqliteTools::fetchAll<File, IFile>( m_dbConnection, req, m_id );
}
LabelPtr Label::create(DBConnection dbConnection, const std::string& name )
......
......@@ -39,7 +39,7 @@ class Label : public ILabel, public Cache<Label, ILabel, policy::LabelTable, pol
public:
virtual unsigned int id() const;
virtual const std::string& name();
virtual bool files( std::vector<FilePtr>& files );
virtual std::vector<FilePtr> files();
static LabelPtr create( DBConnection dbConnection, const std::string& name );
static bool createTable( DBConnection dbConnection );
......
......@@ -60,9 +60,9 @@ bool MediaLibrary::initialize(const std::string& dbPath)
}
bool MediaLibrary::files( std::vector<FilePtr>& res )
std::vector<FilePtr> MediaLibrary::files()
{
return File::fetchAll( m_dbConnection, res );
return File::fetchAll( m_dbConnection );
}
FilePtr MediaLibrary::file( const std::string& path )
......
......@@ -14,7 +14,7 @@ class MediaLibrary : public IMediaLibrary
~MediaLibrary();
virtual bool initialize( const std::string& dbPath );
virtual bool files( std::vector<FilePtr>& res );
virtual std::vector<FilePtr> files();
virtual FilePtr file( const std::string& path );
virtual FilePtr addFile( const std::string& path );
virtual FolderPtr addFolder( const std::string& path ) override;
......
......@@ -97,9 +97,7 @@ bool Movie::setImdbId( const std::string& imdbId )
bool Movie::destroy()
{
std::vector<FilePtr> fs;
if ( files( fs ) == false )
return false;
auto fs = files();
for ( auto& f : fs )
{
File::discard( std::static_pointer_cast<File>( f ) );
......@@ -107,11 +105,11 @@ bool Movie::destroy()
return _Cache::destroy( m_dbConnection, this );
}
bool Movie::files( std::vector<FilePtr>& files )
std::vector<FilePtr> Movie::files()
{
static const std::string req = "SELECT * FROM " + policy::FileTable::Name
+ " WHERE movie_id = ?";
return SqliteTools::fetchAll<File>( m_dbConnection, req, files, m_id );
return SqliteTools::fetchAll<File, IFile>( m_dbConnection, req, m_id );
}
bool Movie::createTable( DBConnection dbConnection )
......
......@@ -34,7 +34,7 @@ class Movie : public IMovie, public Cache<Movie, IMovie, policy::MovieTable>
virtual const std::string& imdbId() const;
virtual bool setImdbId(const std::string& imdbId);
virtual bool destroy();
virtual bool files( std::vector<FilePtr>& files );
virtual std::vector<FilePtr> files();
static bool createTable( DBConnection dbConnection );
static MoviePtr create( DBConnection dbConnection, const std::string& title );
......
......@@ -106,18 +106,16 @@ ShowEpisodePtr Show::addEpisode(const std::string& title, unsigned int episodeNu
return ShowEpisode::create( m_dbConnection, title, episodeNumber, m_id );
}
bool Show::episodes( std::vector<ShowEpisodePtr>& episodes )
std::vector<ShowEpisodePtr> Show::episodes()
{
static const std::string req = "SELECT * FROM " + policy::ShowEpisodeTable::Name
+ " WHERE show_id = ?";
return SqliteTools::fetchAll<ShowEpisode>( m_dbConnection, req, episodes, m_id );
return SqliteTools::fetchAll<ShowEpisode, IShowEpisode>( m_dbConnection, req, m_id );
}
bool Show::destroy()
{
std::vector<ShowEpisodePtr> eps;
if ( episodes( eps ) == false )
return false;
auto eps = episodes();
//FIXME: This is suboptimal. Each episode::destroy() will fire a SQL request of its own
for ( auto& t : eps )
{
......
......@@ -37,7 +37,7 @@ class Show : public IShow, public Cache<Show, IShow, policy::ShowTable>
virtual const std::string& tvdbId();
virtual bool setTvdbId( const std::string& summary );
virtual ShowEpisodePtr addEpisode( const std::string& title, unsigned int episodeNumber );
virtual bool episodes( std::vector<ShowEpisodePtr>& episodes );
virtual std::vector<ShowEpisodePtr> episodes();
virtual bool destroy();
static bool createTable( DBConnection dbConnection );
......
......@@ -119,18 +119,16 @@ std::shared_ptr<IShow> ShowEpisode::show()
return m_show;
}
bool ShowEpisode::files( std::vector<FilePtr>& files )
std::vector<FilePtr> ShowEpisode::files()
{
static const std::string req = "SELECT * FROM " + policy::FileTable::Name
+ " WHERE show_episode_id = ?";
return SqliteTools::fetchAll<File>( m_dbConnection, req, files, m_id );
return SqliteTools::fetchAll<File, IFile>( m_dbConnection, req, m_id );
}
bool ShowEpisode::destroy()
{
std::vector<FilePtr> fs;
if ( files( fs ) == false )
return false;
auto fs = files();
for ( auto& f : fs )
File::discard( std::static_pointer_cast<File>( f ) );
return _Cache::destroy( m_dbConnection, this );
......
......@@ -40,7 +40,7 @@ class ShowEpisode : public IShowEpisode, public Cache<ShowEpisode, IShowEpisode,
virtual const std::string& tvdbId() const;
virtual bool setTvdbId( const std::string& tvdbId );
virtual std::shared_ptr<IShow> show();
virtual bool files( std::vector<FilePtr>& files );
virtual std::vector<FilePtr> files();
virtual bool destroy();
static bool createTable( DBConnection dbConnection );
......
......@@ -74,16 +74,16 @@ class SqliteTools
* be discarded.
*/
template <typename IMPL, typename INTF, typename... Args>
static bool fetchAll( DBConnection dbConnectionWeak, const std::string& req, std::vector<std::shared_ptr<INTF> >& results, const Args&... args )
static std::vector<std::shared_ptr<INTF> > fetchAll( DBConnection dbConnectionWeak, const std::string& req, const Args&... args )
{
auto dbConnection = dbConnectionWeak.lock();
if ( dbConnection == nullptr )
return false;
throw std::runtime_error("Invalid SQlite connection");
results.clear();
std::vector<std::shared_ptr<INTF>> results;
auto stmt = prepareRequest( dbConnection, req, args...);
if ( stmt == nullptr )
return false;
throw std::runtime_error("Failed to execute SQlite request");
int res = sqlite3_step( stmt.get() );
while ( res == SQLITE_ROW )
{
......@@ -91,7 +91,7 @@ class SqliteTools
results.push_back( row );
res = sqlite3_step( stmt.get() );
}
return true;
return results;
}
template <typename T, typename... Args>
......
......@@ -57,15 +57,14 @@ TEST_F( Albums, AddTrack )
auto track = a->addTrack( "track", 10 );
ASSERT_NE( track, nullptr );
std::vector<AlbumTrackPtr> tracks;
bool res = a->tracks( tracks );
ASSERT_TRUE( res );
auto tracks = a->tracks();
ASSERT_EQ( tracks.size(), 1u );
ASSERT_EQ( tracks[0], track );
SetUp();
a->tracks( tracks );
a = ml->album( "albumtag" );
tracks = a->tracks();
ASSERT_EQ( tracks.size(), 1u );
ASSERT_EQ( tracks[0]->title(), track->title() );
}
......@@ -114,9 +113,8 @@ TEST_F( Albums, SetGenre )
SetUp();
std::vector<AlbumTrackPtr> tracks;
a = ml->album( "album" );
a->tracks( tracks );
auto tracks = a->tracks();
auto t2 = tracks[0];
ASSERT_EQ( t->genre(), t2->genre() );
}
......@@ -171,8 +169,7 @@ TEST_F( Albums, SetArtist )
SetUp();
auto a2 = ml->album( "album" );
std::vector<AlbumTrackPtr> tracks;
a2->tracks( tracks );
auto tracks = a2->tracks();
auto t2 = tracks[0];
ASSERT_EQ( t->artist(), t2->artist() );
}
......
......@@ -38,9 +38,7 @@ TEST_F( AudioTracks, FetchTracks )
f->addAudioTrack( "PCM", 44100, 128, 2 );
f->addAudioTrack( "WMA", 48000, 128, 2 );
std::vector<AudioTrackPtr> ts;
bool res = f->audioTracks( ts );
ASSERT_TRUE( res );
auto ts = f->audioTracks();
ASSERT_EQ( ts.size(), 2u );
}
......@@ -52,11 +50,9 @@ TEST_F( AudioTracks, CheckUnique )
auto f2 = ml->addFile( "file2" );
f2->addAudioTrack( "PCM", 44100, 128, 2 );
std::vector<AudioTrackPtr> ts;
f->audioTracks( ts );
auto ts = f->audioTracks();
std::vector<AudioTrackPtr> ts2;
f2->audioTracks( ts2 );
auto ts2 = f2->audioTracks();
ASSERT_EQ( ts.size(), 1u );
ASSERT_EQ( ts2.size(), 1u );
......
......@@ -40,9 +40,7 @@ TEST_F( Files, Create )
ASSERT_EQ( f->showEpisode(), nullptr );
ASSERT_TRUE( f->isStandAlone() );
std::vector<std::shared_ptr<IFile>> files;
bool success = ml->files( files );
ASSERT_TRUE( success );
auto files = ml->files();
ASSERT_EQ( files.size(), 1u );
ASSERT_EQ( files[0]->mrl(), f->mrl() );
}
......
......@@ -28,45 +28,36 @@ std::unique_ptr<IMediaLibrary> Folders::ml;
TEST_F( Folders, Add )
{
auto f = ml->addFolder( "." );
auto files = std::vector<FilePtr>{};
bool res = ml->files( files );
ml->addFolder( "." );
auto files = ml->files();
ASSERT_TRUE( res );
ASSERT_EQ( files.size(), 2u );
ASSERT_FALSE( files[0]->isStandAlone() );
}
TEST_F( Folders, Delete )
{
auto f = ml->addFolder( "." );
auto files = std::vector<FilePtr>{};
bool res = ml->files( files );
auto files = ml->files();
ASSERT_TRUE( res );
ASSERT_EQ( files.size(), 2u );
ml->deleteFolder( f );
res = ml->files( files );
ASSERT_TRUE( res );
files = ml->files();
ASSERT_EQ( files.size(), 0u );
}
TEST_F( Folders, Load )
{
auto f = ml->addFolder( "." );
auto files = std::vector<FilePtr>{};
bool res = ml->files( files );
auto files = ml->files();
ASSERT_TRUE( res );
ASSERT_EQ( files.size(), 2u );
SetUp();
res = ml->files( files );
ASSERT_TRUE( res );
files = ml->files();
ASSERT_EQ( files.size(), 2u );
ASSERT_FALSE( files[0]->isStandAlone() );
ASSERT_FALSE( files[1]->isStandAlone() );
......@@ -77,8 +68,6 @@ TEST_F( Folders, InvalidPath )
auto f = ml->addFolder( "/invalid/path" );
ASSERT_EQ( f, nullptr );
auto files = std::vector<FilePtr>{};
bool res = ml->files( files );
ASSERT_TRUE( res );
auto files = ml->files();
ASSERT_EQ( files.size(), 0u );
}
......@@ -104,13 +104,8 @@ TEST_F( Labels, Files )
f2->addLabel( l2 );
f3->addLabel( l1 );
std::vector<FilePtr> label1Files;
std::vector<FilePtr> label2Files;
bool res = l1->files( label1Files );
ASSERT_TRUE( res );
res = l2->files( label2Files );
ASSERT_TRUE( res );
auto label1Files = l1->files();
auto label2Files = l2->files();
ASSERT_EQ( label1Files.size(), 2u );
ASSERT_EQ( label2Files.size(), 1u );
......
......@@ -117,9 +117,7 @@ TEST_F( Shows, AddEpisode )
ASSERT_EQ( e->show(), show );
ASSERT_EQ( e->name(), "episode 1" );
std::vector<ShowEpisodePtr> episodes;
bool res = show->episodes( episodes );
ASSERT_TRUE( res );
auto episodes = show->episodes();
ASSERT_EQ( episodes.size(), 1u );
ASSERT_EQ( episodes[0], e );
}
......@@ -155,8 +153,7 @@ TEST_F( Shows, SetEpisodeArtwork )
SetUp();
show = ml->show( "show" );
std::vector<ShowEpisodePtr> episodes;
show->episodes( episodes );
auto episodes = show->episodes();
ASSERT_EQ( episodes[0]->artworkUrl(), e->artworkUrl() );
}
......@@ -171,8 +168,7 @@ TEST_F( Shows, SetEpisodeSeasonNumber )
SetUp();
show = ml->show( "show" );
std::vector<ShowEpisodePtr> episodes;
show->episodes( episodes );
auto episodes = show->episodes();
ASSERT_EQ( episodes[0]->seasonNumber(), e->seasonNumber() );
}
......@@ -187,8 +183,7 @@ TEST_F( Shows, SetEpisodeSummary )
SetUp();
show = ml->show( "show" );
std::vector<ShowEpisodePtr> episodes;
show->episodes( episodes );
auto episodes = show->episodes();
ASSERT_EQ( episodes[0]->shortSummary(), e->shortSummary() );
}
......@@ -203,8 +198,7 @@ TEST_F( Shows, SetEpisodeTvdbId )
SetUp();
show = ml->show( "show" );
std::vector<ShowEpisodePtr> episodes;
show->episodes( episodes );
auto episodes = show->episodes();
ASSERT_EQ( episodes[0]->tvdbId(), e->tvdbId() );
}
......
......@@ -84,17 +84,15 @@ TEST_F( VLCMetadataServices, ParseAudio )
std::unique_lock<std::mutex> lock( cb->mutex );
auto file = ml->addFile( "mr-zebra.mp3" );
ml->parse( file, cb.get() );
std::vector<AudioTrackPtr> tracks;
bool res = cb->waitCond.wait_for( lock, std::chrono::seconds( 5 ), [&]{
return cb->failed == true || ( file->audioTracks( tracks ) == true && tracks.size() > 0 );
return cb->failed == true || ( file->audioTracks().size() > 0 );
} );
ASSERT_TRUE( res );
ASSERT_FALSE( cb->failed );
SetUp();
file = ml->file( "mr-zebra.mp3" );
res = file->audioTracks( tracks );
ASSERT_TRUE( res );
auto tracks = file->audioTracks();
ASSERT_EQ( tracks.size(), 1u );
auto track = tracks[0];
ASSERT_EQ( track->codec(), "mpga" );
......@@ -136,9 +134,8 @@ TEST_F( VLCMetadataServices, ParseVideo )
std::unique_lock<std::mutex> lock( cb->mutex );
auto file = ml->addFile( "mrmssmith.mp4" );
ml->parse( file, cb.get() );
std::vector<VideoTrackPtr> tracks;
bool res = cb->waitCond.wait_for( lock, std::chrono::seconds( 5 ), [&tracks, file]{
return cb->failed == true || (file->videoTracks(tracks) != false && tracks.size() != 0);
bool res = cb->waitCond.wait_for( lock, std::chrono::seconds( 5 ), [file]{
return cb->failed == true || (file->videoTracks().size() != 0);
} );
ASSERT_TRUE( res );
......@@ -148,16 +145,14 @@ TEST_F( VLCMetadataServices, ParseVideo )
ASSERT_EQ( file->showEpisode(), nullptr );
res = file->videoTracks( tracks );
auto tracks = file->videoTracks();
ASSERT_EQ( tracks.size(), 1u );
ASSERT_EQ( tracks[0]->codec(), "h264" );
ASSERT_EQ( tracks[0]->width(), 320u );
ASSERT_EQ( tracks[0]->height(), 176u );
ASSERT_EQ( tracks[0]->fps(), 25 );
std::vector<AudioTrackPtr> audioTracks;
res = file->audioTracks( audioTracks );
ASSERT_TRUE( res );
auto audioTracks = file->audioTracks();
ASSERT_EQ( audioTracks.size(), 1u );
ASSERT_EQ( audioTracks[0]->codec(), "mp4a" );
ASSERT_EQ( audioTracks[0]->sampleRate(), 44100u );
......
......@@ -38,9 +38,7 @@ TEST_F( VideoTracks, FetchTracks )
f->addVideoTrack( "H264", 1920, 1080, 29.97 );
f->addVideoTrack( "VP80", 640, 480, 29.97 );
std::vector<VideoTrackPtr> ts;
bool res = f->videoTracks( ts );
ASSERT_TRUE( res );
auto ts = f->videoTracks();
ASSERT_EQ( ts.size(), 2u );
}
......@@ -52,11 +50,8 @@ TEST_F( VideoTracks, CheckUnique )
auto f2 = ml->addFile( "file2" );
f2->addVideoTrack( "H264", 1920, 1080, 29.97 );
std::vector<VideoTrackPtr> ts;
f->videoTracks( ts );
std::vector<VideoTrackPtr> ts2;
f2->videoTracks( ts2 );
auto ts = f->videoTracks();
auto ts2 = f2->videoTracks();
ASSERT_EQ( ts.size(), 1u );
ASSERT_EQ( ts2.size(), 1u );
......