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

Add a mock::NoopCallback to implement all IMediaLibraryCb methods

This will ease up future modifications of this interface
parent a90b2e2e
......@@ -26,59 +26,26 @@
#include <condition_variable>
#include "IMediaLibrary.h"
#include "mocks/NoopCallback.h"
namespace mock
{
class WaitForDiscoveryComplete : public IMediaLibraryCb
class WaitForDiscoveryComplete : public mock::NoopCallback
{
public:
virtual void onMediaAdded( MediaPtr ) override
{
}
virtual void onMediaUpdated( MediaPtr ) override
{
}
virtual void onMediaDeleted( std::vector<int64_t> ) override
{
}
virtual void onArtistAdded( ArtistPtr ) override
{
}
virtual void onAlbumAdded( AlbumPtr ) override
{
}
virtual void onTrackAdded( MediaPtr, AlbumTrackPtr ) override
{
}
virtual void onDiscoveryStarted( const std::string& ) override
{
}
virtual void onDiscoveryCompleted( const std::string& ) override
{
if ( --m_nbDiscoveryToWait == 0 )
m_cond.notify_all();
}
virtual void onReloadStarted( const std::string& ) override
{
}
virtual void onReloadCompleted( const std::string& ) override
{
if ( --m_nbReloadExpected == 0 )
m_reloadCond.notify_all();
}
virtual void onParsingStatsUpdated( uint32_t ) override {}
bool wait()
{
std::unique_lock<std::mutex> lock( m_mutex );
......
/*****************************************************************************
* Media Library
*****************************************************************************
* Copyright (C) 2015 Hugo Beauzée-Luyssen, Videolabs
*
* Authors: Hugo Beauzée-Luyssen<hugo@beauzee.fr>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#pragma once
#include "IMediaLibrary.h"
namespace mock
{
class NoopCallback : public IMediaLibraryCb
{
virtual void onMediaAdded(MediaPtr) override {}
virtual void onMediaUpdated(MediaPtr) override {}
virtual void onMediaDeleted( std::vector<int64_t> ) override {}
virtual void onDiscoveryStarted(const std::string&) override {}
virtual void onDiscoveryCompleted(const std::string&) override {}
virtual void onReloadStarted( const std::string& ) override {}
virtual void onReloadCompleted( const std::string& ) override {}
virtual void onArtistAdded( ArtistPtr ) override {}
virtual void onAlbumAdded( AlbumPtr ) override {}
virtual void onTrackAdded( MediaPtr, AlbumTrackPtr ) override {}
virtual void onParsingStatsUpdated( uint32_t ) override {}
};
}
......@@ -36,25 +36,16 @@
#include "IAudioTrack.h"
#include "IVideoTrack.h"
#include "IGenre.h"
#include "mocks/NoopCallback.h"
class MockCallback : public IMediaLibraryCb
class MockCallback : public mock::NoopCallback
{
public:
MockCallback();
bool waitForParsingComplete();
private:
virtual void onMediaAdded(MediaPtr) override {}
virtual void onMediaUpdated(MediaPtr) override {}
virtual void onMediaDeleted( std::vector<int64_t> ) override {}
virtual void onDiscoveryStarted(const std::string&) override {}
virtual void onDiscoveryCompleted(const std::string&) override;
virtual void onReloadStarted( const std::string& ) override {}
virtual void onReloadCompleted( const std::string& ) override {}
virtual void onArtistAdded( ArtistPtr ) override {}
virtual void onAlbumAdded( AlbumPtr ) override {}
virtual void onTrackAdded( MediaPtr, AlbumTrackPtr ) override {}
virtual void onParsingStatsUpdated(uint32_t percent) override;
std::condition_variable m_parsingCompleteVar;
......
......@@ -23,29 +23,19 @@
#include "Tests.h"
#include "Media.h"
#include "File.h"
#include "mocks/NoopCallback.h"
class MockCallback : public IMediaLibraryCb
class MockCallback : public mock::NoopCallback
{
public:
MockCallback() : m_nbMedia( 0 ) {}
private:
virtual void onMediaAdded(MediaPtr) override {}
virtual void onMediaUpdated(MediaPtr) override {}
virtual void onMediaDeleted( std::vector<int64_t> batch ) override
{
std::lock_guard<std::mutex> lock( m_lock );
m_nbMedia = batch.size();
m_cond.notify_all();
}
virtual void onDiscoveryStarted(const std::string&) override {}
virtual void onDiscoveryCompleted(const std::string&) override {}
virtual void onReloadStarted( const std::string& ) override {}
virtual void onReloadCompleted( const std::string& ) override {}
virtual void onArtistAdded( ArtistPtr ) override {}
virtual void onAlbumAdded( AlbumPtr ) override {}
virtual void onTrackAdded( MediaPtr, AlbumTrackPtr ) override {}
virtual void onParsingStatsUpdated( uint32_t ) override {}
public:
std::unique_lock<std::mutex> prepareWait()
{
......
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