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

Tests: sample: Request a thumbnail to be generated before checking its presence

parent 9ae0d60d
......@@ -51,6 +51,25 @@ bool MockCallback::waitForParsingComplete()
});
}
void MockCallback::prepareWaitForThumbnail( MediaPtr media )
{
m_thumbnailMutex.lock();
m_thumbnailDone = false;
m_thumbnailSuccess = false;
m_thumbnailTarget = std::move( media );
}
bool MockCallback::waitForThumbnail()
{
std::unique_lock<compat::Mutex> lock( m_thumbnailMutex, std::adopt_lock );
if ( m_thumbnailCond.wait_for( lock, std::chrono::seconds{ 5 }, [this]() {
return m_thumbnailDone;
}) == false )
return false;
m_thumbnailMutex.unlock();
return m_thumbnailSuccess;
}
void MockCallback::onDiscoveryCompleted(const std::string& entryPoint )
{
if ( entryPoint.empty() == true )
......@@ -71,6 +90,17 @@ void MockCallback::onParsingStatsUpdated(uint32_t percent)
}
}
void MockCallback::onMediaThumbnailReady( MediaPtr media, bool success )
{
std::unique_lock<compat::Mutex> lock( m_thumbnailMutex );
if ( m_thumbnailTarget == nullptr || media->id() != m_thumbnailTarget->id() )
return;
m_thumbnailDone = true;
m_thumbnailSuccess = success;
m_thumbnailCond.notify_all();
}
MockResumeCallback::MockResumeCallback()
{
m_discoveryMutex.lock();
......@@ -282,6 +312,13 @@ void Tests::checkMedias(const rapidjson::Value& expectedMedias)
if ( expectedMedia.HasMember( "snapshotExpected" ) == true )
{
auto snapshotExpected = expectedMedia["snapshotExpected"].GetBool();
if ( snapshotExpected && media->thumbnail().empty() == true )
{
m_cb->prepareWaitForThumbnail( media );
m_ml->requestThumbnail( media );
auto res = m_cb->waitForThumbnail();
ASSERT_TRUE( res );
}
ASSERT_EQ( !snapshotExpected, media->thumbnail().empty() );
}
}
......
......@@ -46,12 +46,20 @@ public:
virtual bool waitForParsingComplete();
virtual bool waitForDiscoveryComplete() { return true; }
virtual void reinit() {}
void prepareWaitForThumbnail( MediaPtr media );
bool waitForThumbnail();
protected:
virtual void onDiscoveryCompleted( const std::string& ) override;
virtual void onParsingStatsUpdated(uint32_t percent) override;
virtual void onMediaThumbnailReady( MediaPtr media, bool success );
compat::ConditionVariable m_parsingCompleteVar;
compat::Mutex m_parsingMutex;
compat::Mutex m_thumbnailMutex;
compat::ConditionVariable m_thumbnailCond;
MediaPtr m_thumbnailTarget;
bool m_thumbnailDone;
bool m_thumbnailSuccess;
bool m_done;
bool m_discoveryCompleted;
};
......
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