| Index: test/FileSystemJsObject.cpp |
| =================================================================== |
| --- a/test/FileSystemJsObject.cpp |
| +++ b/test/FileSystemJsObject.cpp |
| @@ -45,62 +45,141 @@ |
| { |
| if (!success) |
| throw std::runtime_error("Unable to read " + path); |
| std::stringstream* const stream = new std::stringstream; |
| *stream << contentToRead; |
| return std::shared_ptr<std::istream>(stream); |
| } |
| + void Read(const std::string& path, |
| + const ReadCallback& callback) const |
| + { |
| + try |
| + { |
| + auto result = Read(path); |
| + callback(result); |
| + } |
| + catch (...) |
| + { |
| + } |
| + } |
| + |
| void Write(const std::string& path, std::istream& data) |
| { |
| if (!success) |
| throw std::runtime_error("Unable to write to " + path); |
| lastWrittenPath = path; |
| std::stringstream content; |
| content << data.rdbuf(); |
| lastWrittenContent = content.str(); |
| } |
| + void Write(const std::string& path, |
| + std::istream& data, |
| + const Callback& callback) |
| + { |
| + try |
| + { |
| + Write(path, data); |
| + callback(); |
| + } |
| + catch (...) |
| + { |
| + } |
| + } |
| + |
| void Move(const std::string& fromPath, const std::string& toPath) |
| { |
| if (!success) |
| throw std::runtime_error("Unable to move " + fromPath + " to " |
| + toPath); |
| movedFrom = fromPath; |
| movedTo = toPath; |
| } |
| + void Move(const std::string& fromPath, |
| + const std::string& toPath, |
| + const Callback& callback) |
| + { |
| + try |
| + { |
| + Move(fromPath, toPath); |
| + callback(); |
| + } |
| + catch (...) |
| + { |
| + } |
| + } |
| + |
| void Remove(const std::string& path) |
| { |
| if (!success) |
| throw std::runtime_error("Unable to remove " + path); |
| removedPath = path; |
| } |
| + void Remove(const std::string& path, const Callback& callback) |
| + { |
| + try |
| + { |
| + Remove(path); |
| + callback(); |
| + } |
| + catch (...) |
| + { |
| + } |
| + } |
| + |
| StatResult Stat(const std::string& path) const |
| { |
| if (!success) |
| throw std::runtime_error("Unable to stat " + path); |
| statPath = path; |
| StatResult result; |
| result.exists = statExists; |
| result.isDirectory = statIsDirectory; |
| result.isFile = statIsFile; |
| result.lastModified = statLastModified; |
| return result; |
| } |
| + void Stat(const std::string& path, |
| + const StatCallback& callback) const |
| + { |
| + try |
| + { |
| + auto result = Stat(path); |
| + callback(result); |
| + } |
| + catch (...) |
| + { |
| + } |
| + } |
| + |
| std::string Resolve(const std::string& path) const |
| { |
| if (!success) |
| throw std::runtime_error("Unable to stat " + path); |
| return path; |
| } |
| + |
| + void Resolve(const std::string& path, |
| + const ResolveCallback& callback) const |
| + { |
| + try |
| + { |
| + auto result = Resolve(path); |
| + callback(result); |
| + } |
| + catch (...) |
| + { |
| + } |
| + } |
| }; |
| void ReadFile(AdblockPlus::JsEnginePtr jsEngine, std::string& content, |
| std::string& error) |
| { |
| jsEngine->Evaluate("_fileSystem.read('', function(r) {result = r})"); |
| AdblockPlus::Sleep(50); |
| content = jsEngine->Evaluate("result.content").AsString(); |