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

tests: Fix unmounting device behavior

parent 0bd3b314
......@@ -69,6 +69,51 @@ struct FileSystemFactory : public factory::IFileSystem
return dev;
}
std::shared_ptr<Device> removeDevice( const std::string& uuid )
{
auto it = std::find_if( begin( devices ), end( devices ), [uuid]( const std::shared_ptr<Device>& d ) {
return d->uuid() == uuid;
} );
if ( it == end( devices ) )
return nullptr;
auto ret = *it;
devices.erase( it );
// Now flag the mountpoint as belonging to its containing device, since it's now
// just a regular folder
auto d = device( ret->mountpoint() );
d->invalidateMountpoint( ret->mountpoint() );
return ret;
}
void unmountDevice( const std::string& uuid )
{
auto it = std::find_if( begin( devices ), end( devices ), [uuid]( const std::shared_ptr<Device>& d ) {
return d->uuid() == uuid;
} );
if ( it == end( devices ) )
return;
auto d = *it;
d->setPresent( false );
auto mountpointDevice = device( d->mountpoint() );
mountpointDevice->invalidateMountpoint( d->mountpoint() );
}
void remountDevice( const std::string& uuid )
{
auto it = std::find_if( begin( devices ), end( devices ), [uuid]( const std::shared_ptr<Device>& d ) {
return d->uuid() == uuid;
} );
if ( it == end( devices ) )
return;
auto d = *it;
// Look for the containing device before marking the actual device back as present.
// otherwise, we will get the device mountpoint itself, instead of the device that contains
// the mountpoint
auto mountpointDevice = device( d->mountpoint() );
d->setPresent( true );
mountpointDevice->setMountpointRoot( d->mountpoint(), d->root() );
}
void addDevice( std::shared_ptr<Device> dev )
{
auto d = device( dev->mountpoint() );
......@@ -154,22 +199,6 @@ struct FileSystemFactory : public factory::IFileSystem
return ret;
}
std::shared_ptr<Device> removeDevice( const std::string& uuid )
{
auto it = std::find_if( begin( devices ), end( devices ), [uuid]( const std::shared_ptr<Device>& d ) {
return d->uuid() == uuid;
} );
if ( it == end( devices ) )
return nullptr;
auto ret = *it;
devices.erase( it );
// Now flag the mountpoint as belonging to its containing device, since it's now
// just a regular folder
auto d = device( ret->mountpoint() );
d->invalidateMountpoint( ret->mountpoint() );
return ret;
}
std::vector<std::shared_ptr<Device>> devices;
};
......
......@@ -44,7 +44,7 @@ const std::string&Directory::path() const
return m_path;
}
const std::vector<std::shared_ptr<fs::IFile> >&Directory::files() const
const std::vector<std::shared_ptr<fs::IFile>>& Directory::files() const
{
m_filePathes.clear();
for ( auto& f : m_files )
......@@ -52,7 +52,7 @@ const std::vector<std::shared_ptr<fs::IFile> >&Directory::files() const
return m_filePathes;
}
const std::vector<std::shared_ptr<fs::IDirectory> >&Directory::dirs() const
const std::vector<std::shared_ptr<fs::IDirectory>>& Directory::dirs() const
{
m_dirPathes.clear();
for ( const auto& d : m_dirs )
......
......@@ -146,8 +146,7 @@ TEST_F( DeviceFs, UnmountDisk )
auto media = ml->media( RemovableDeviceMountpoint + "removablefile.mp3" );
ASSERT_NE( nullptr, media );
auto device = std::static_pointer_cast<mock::Device>( fsMock->createDevice( RemovableDeviceUuid ) );
device->setPresent( false );
fsMock->unmountDevice( RemovableDeviceUuid );
cbMock->prepareForReload();
Reload();
......
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