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

Unified Diff: test/BaseJsTest.h

Issue 29731562: Issue 6477 - separate done and error callbacks in IFileSystem::Read (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git@c0a6434596a83383e37678ef3b6ecef00ed6a261
Patch Set: Created March 23, 2018, 10:58 a.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
Index: test/BaseJsTest.h
diff --git a/test/BaseJsTest.h b/test/BaseJsTest.h
index 7762ab22cd10f741d304637a4eb6ebecb8c664d8..8ac8920ba86166d48718234748c6489b85d60440 100644
--- a/test/BaseJsTest.h
+++ b/test/BaseJsTest.h
@@ -108,7 +108,7 @@ public:
class ThrowingFileSystem : public AdblockPlus::IFileSystem
{
public:
- void Read(const std::string& fileName, const ReadCallback& callback) const override
+ void Read(const std::string& fileName, const ReadCallback& callback, const Callback& errorCallback) const override
{
throw std::runtime_error("Not implemented");
}
@@ -160,20 +160,22 @@ public:
{
}
- void Read(const std::string& fileName, const ReadCallback& callback) const override
+ void Read(const std::string& fileName, const ReadCallback& callback, const Callback& errorCallback) const override
{
- scheduler([fileName, callback]
+ scheduler([fileName, callback, errorCallback]
{
sergei 2018/03/23 11:27:19 Strictly speaking, now in accordance with the inte
if (fileName == "patterns.ini")
{
std::string dummyData = "# Adblock Plus preferences\n[Subscription]\nurl=~user~0000";
- callback(IOBuffer(dummyData.cbegin(), dummyData.cend()), "");
+ callback(IOBuffer(dummyData.cbegin(), dummyData.cend()));
}
else if (fileName == "prefs.json")
{
std::string dummyData = "{}";
- callback(IOBuffer(dummyData.cbegin(), dummyData.cend()), "");
+ callback(IOBuffer(dummyData.cbegin(), dummyData.cend()));
}
+ else
+ errorCallback("File not found, " + fileName);
});
}
@@ -213,17 +215,15 @@ class InMemoryFileSystem : public LazyFileSystem
std::map<std::string, IOBuffer> files;
public:
using LazyFileSystem::LazyFileSystem;
- void Read(const std::string& fileName, const ReadCallback& callback) const override
+ void Read(const std::string& fileName, const ReadCallback& callback, const Callback& errorCallback) const override
{
- scheduler([this, fileName, callback]()
+ scheduler([this, fileName, callback, errorCallback]()
{
auto ii_file = files.find(fileName);
- if (ii_file == files.end())
- {
- callback(IOBuffer(), "File not found, " + fileName);
- return;
- }
- callback(IOBuffer(ii_file->second), "");
+ if (ii_file != files.end())
+ callback(IOBuffer(ii_file->second));
+ else
+ errorCallback("File not found, " + fileName);
});
}
« src/FileSystemJsObject.cpp ('K') | « src/JsEngine.cpp ('k') | test/DefaultFileSystem.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld