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

tests: fs: Ensure mock match the behavior of the actual code

parent ccc73318
......@@ -164,7 +164,7 @@ struct FileSystemFactory : public factory::IFileSystem
{
auto d = device( mrl );
if ( d == nullptr )
return nullptr;
return std::make_shared<Directory>( "", nullptr );
return d->directory( mrl );
}
......
......@@ -106,7 +106,7 @@ std::shared_ptr<File> Device::file(const std::string& filePath )
std::shared_ptr<Directory> Device::directory(const std::string& path)
{
if ( m_root == nullptr || m_present == false )
return nullptr;
return std::make_shared<Directory>( "", nullptr );
const auto relPath = relativePath( path );
if ( relPath.empty() == true )
return m_root;
......
......@@ -25,6 +25,7 @@
#endif
#include <cassert>
#include <system_error>
#include "MockDirectory.h"
#include "MockFile.h"
......@@ -50,6 +51,9 @@ const std::string& Directory::mrl() const
const std::vector<std::shared_ptr<fs::IFile>>& Directory::files() const
{
// Assume no device means a wrong path
if ( m_device.lock() == nullptr )
throw std::system_error( ENOENT, std::generic_category(), "Failed to open mock directory" );
m_filePathes.clear();
for ( auto& f : m_files )
m_filePathes.push_back( f.second );
......@@ -58,6 +62,8 @@ const std::vector<std::shared_ptr<fs::IFile>>& Directory::files() const
const std::vector<std::shared_ptr<fs::IDirectory>>& Directory::dirs() const
{
if ( m_device.lock() == nullptr )
throw std::system_error( ENOENT, std::generic_category(), "Failed to open mock directory" );
m_dirPathes.clear();
for ( const auto& d : m_dirs )
m_dirPathes.push_back( d.second );
......@@ -146,7 +152,7 @@ std::shared_ptr<Directory> Directory::directory(const std::string& path)
{
auto it = m_dirs.find( subFolder );
if ( it == end( m_dirs ) )
return nullptr;
return std::make_shared<Directory>( "", nullptr );
return it->second;
}
else
......
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