| 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('', '', '')")); |
| } |