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

Unified Diff: test/FileSystemJsObject.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/DefaultFileSystem.cpp ('k') | test/Prefs.cpp » ('j') | 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
@@ -20,50 +20,45 @@
#include "../src/Thread.h"
namespace
{
class MockFileSystem : public AdblockPlus::FileSystem
{
public:
bool success;
- std::string contentToRead;
+ IOBuffer contentToRead;
std::string lastWrittenPath;
- std::string lastWrittenContent;
+ IOBuffer lastWrittenContent;
std::string movedFrom;
std::string movedTo;
std::string removedPath;
mutable std::string statPath;
bool statExists;
bool statIsDirectory;
bool statIsFile;
int statLastModified;
MockFileSystem() : success(true)
{
}
- std::shared_ptr<std::istream> Read(const std::string& path) const
+ IOBuffer Read(const std::string& path) const
{
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);
+ return contentToRead;
}
- void Write(const std::string& path, std::istream& data)
+ void Write(const std::string& path, const IOBuffer& data)
{
if (!success)
throw std::runtime_error("Unable to write to " + path);
lastWrittenPath = path;
-
- std::stringstream content;
- content << data.rdbuf();
- lastWrittenContent = content.str();
+ lastWrittenContent = data;
}
void Move(const std::string& fromPath, const std::string& toPath)
{
if (!success)
throw std::runtime_error("Unable to move " + fromPath + " to "
+ toPath);
movedFrom = fromPath;
@@ -120,17 +115,18 @@
mockFileSystem = MockFileSystemPtr(new MockFileSystem);
jsEngine->SetFileSystem(mockFileSystem);
}
};
}
TEST_F(FileSystemJsObjectTest, Read)
{
- mockFileSystem->contentToRead = "foo";
+ mockFileSystem->contentToRead =
+ AdblockPlus::FileSystem::IOBuffer{'f', 'o', 'o'};
std::string content;
std::string error;
ReadFile(jsEngine, content, error);
ASSERT_EQ("foo", content);
ASSERT_EQ("", error);
}
TEST_F(FileSystemJsObjectTest, ReadIllegalArguments)
@@ -149,17 +145,18 @@
ASSERT_EQ("", content);
}
TEST_F(FileSystemJsObjectTest, Write)
{
jsEngine->Evaluate("_fileSystem.write('foo', 'bar', function(e) {error = e})");
AdblockPlus::Sleep(50);
ASSERT_EQ("foo", mockFileSystem->lastWrittenPath);
- ASSERT_EQ("bar", mockFileSystem->lastWrittenContent);
+ ASSERT_EQ((AdblockPlus::FileSystem::IOBuffer{'b', 'a', 'r'}),
+ mockFileSystem->lastWrittenContent);
ASSERT_EQ("", jsEngine->Evaluate("error").AsString());
}
TEST_F(FileSystemJsObjectTest, WriteIllegalArguments)
{
ASSERT_ANY_THROW(jsEngine->Evaluate("_fileSystem.write()"));
ASSERT_ANY_THROW(jsEngine->Evaluate("_fileSystem.write('', '', '')"));
}
« no previous file with comments | « test/DefaultFileSystem.cpp ('k') | test/Prefs.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld