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

tests: Add a device removal test

parent 8bc2fddf
......@@ -140,6 +140,11 @@ public:
return m_device;
}
void removeDevice()
{
m_device = nullptr;
}
void addFile( const std::string& fileName )
{
m_files.emplace_back( m_path + fileName );
......@@ -259,6 +264,14 @@ struct FileSystemFactory : public factory::IFileSystem
dirs.erase( it );
}
std::shared_ptr<Directory> directory( const std::string& path )
{
auto it = dirs.find( path );
if ( it != end( dirs ) )
return it->second;
return nullptr;
}
virtual std::shared_ptr<fs::IDirectory> createDirectory(const std::string& path) override
{
mock::Directory* res = nullptr;
......
......@@ -23,11 +23,31 @@
#include "Tests.h"
#include "Device.h"
#include "mocks/FileSystem.h"
#include "mocks/DiscovererCbMock.h"
class Devices : public Tests
{
protected:
std::shared_ptr<mock::FileSystemFactory> fsMock;
std::unique_ptr<mock::WaitForDiscoveryComplete> cbMock;
protected:
virtual void SetUp() override
{
fsMock.reset( new mock::FileSystemFactory );
cbMock.reset( new mock::WaitForDiscoveryComplete );
Reload();
}
virtual void Reload()
{
Tests::Reload( fsMock, cbMock.get() );
}
};
// Database/Entity tests
TEST_F( Devices, Create )
{
auto d = ml->addDevice( "dummy", true );
......@@ -59,3 +79,33 @@ TEST_F( Devices, SetPresent )
d = ml->device( "dummy" );
ASSERT_FALSE( d->isPresent() );
}
// Filesystem tests:
TEST_F( Devices, RemoveDisk )
{
cbMock->prepareForWait( 1 );
ml->discover( "." );
bool discovered = cbMock->wait();
ASSERT_TRUE( discovered );
auto files = ml->files();
ASSERT_EQ( 3u, files.size() );
auto file = ml->file( std::string( mock::FileSystemFactory::SubFolder ) + "subfile.mp4" );
ASSERT_NE( nullptr, file );
auto subdir = fsMock->directory( mock::FileSystemFactory::SubFolder );
subdir->removeDevice();
cbMock->prepareForReload();
Reload();
bool reloaded = cbMock->waitForReload();
ASSERT_TRUE( reloaded );
files = ml->files();
ASSERT_EQ( 2u, files.size() );
file = ml->file( std::string( mock::FileSystemFactory::SubFolder ) + "subfile.mp4" );
ASSERT_EQ( nullptr, 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