Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: test/FileSystemJsObject.cpp

Issue 29449592: Issue 5183 - Provide async interface for FileSystem (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Created May 26, 2017, 12:43 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« include/AdblockPlus/FileSystem.h ('K') | « test/BaseJsTest.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
« include/AdblockPlus/FileSystem.h ('K') | « test/BaseJsTest.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld