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

Unified Diff: test/Prefs.cpp

Issue 29481704: Noissue - Use buffer for FileSystem IO (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Nit addressed Created July 7, 2017, 12:50 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
« no previous file with comments | « test/FileSystemJsObject.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/Prefs.cpp
===================================================================
--- a/test/Prefs.cpp
+++ b/test/Prefs.cpp
@@ -24,34 +24,30 @@
namespace
{
typedef std::shared_ptr<AdblockPlus::FilterEngine> FilterEnginePtr;
class TestFileSystem : public LazyFileSystem
{
public:
- std::string prefsContents;
+ IOBuffer prefsContents;
- std::shared_ptr<std::istream> Read(const std::string& path) const
+ IOBuffer Read(const std::string& path) const
{
if (path == "prefs.json" && !prefsContents.empty())
- return std::shared_ptr<std::istream>(new std::istringstream(prefsContents));
+ return prefsContents;
return LazyFileSystem::Read(path);
}
- void Write(const std::string& path, std::istream& content)
+ void Write(const std::string& path, const IOBuffer& content)
{
if (path == "prefs.json")
- {
- std::stringstream ss;
- ss << content.rdbuf();
- prefsContents = ss.str();
- }
+ prefsContents = content;
else
LazyFileSystem::Write(path, content);
}
StatResult Stat(const std::string& path) const
{
if (path == "prefs.json")
{
@@ -139,25 +135,29 @@
ASSERT_EQ("filters.ini", filterEngine->GetPref("patternsfile").AsString());
ASSERT_EQ(48, filterEngine->GetPref("patternsbackupinterval").AsInt());
ASSERT_FALSE(filterEngine->GetPref("subscriptions_autoupdate").AsBool());
}
}
TEST_F(PrefsTest, UnknownPrefs)
{
- fileSystem->prefsContents = "{\"foobar\":2, \"patternsbackupinterval\": 12}";
+ using IOBuffer = AdblockPlus::FileSystem::IOBuffer;
+ std::string content = "{\"foobar\":2, \"patternsbackupinterval\": 12}";
+ fileSystem->prefsContents = IOBuffer(content.cbegin(), content.cend());
auto filterEngine = CreateFilterEngine();
ASSERT_TRUE(filterEngine->GetPref("foobar").IsUndefined());
ASSERT_EQ(12, filterEngine->GetPref("patternsbackupinterval").AsInt());
}
TEST_F(PrefsTest, SyntaxFailure)
{
- fileSystem->prefsContents = "{\"patternsbackupinterval\": 6, \"foo\"}";
+ using IOBuffer = AdblockPlus::FileSystem::IOBuffer;
+ std::string content = "{\"patternsbackupinterval\": 6, \"foo\"}";
+ fileSystem->prefsContents = IOBuffer(content.cbegin(), content.cend());
auto filterEngine = CreateFilterEngine();
ASSERT_EQ(24, filterEngine->GetPref("patternsbackupinterval").AsInt());
}
TEST_F(PrefsTest, PreconfiguredPrefsPreconfigured)
{
AdblockPlus::FilterEngine::Prefs preconfiguredPrefs;
« no previous file with comments | « test/FileSystemJsObject.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld