| Index: test/JsEngine.cpp |
| =================================================================== |
| --- a/test/JsEngine.cpp |
| +++ b/test/JsEngine.cpp |
| @@ -3,7 +3,30 @@ |
| #include <gtest/gtest.h> |
| #include <sstream> |
| -class ThrowingFileReader : public AdblockPlus::FileReader |
| +class BaseFileSystem : public AdblockPlus::FileSystem |
| +{ |
| + void Write(const std::string& path, const std::string& content) |
| + { |
| + throw std::runtime_error("Write is not implemented"); |
| + } |
| + |
| + void Move(const std::string& fromPath, const std::string& toPath) |
| + { |
| + throw std::runtime_error("Move is not implemented"); |
| + } |
| + |
| + void Remove(const std::string& path) |
| + { |
| + throw std::runtime_error("Remove is not implemented"); |
| + } |
| + |
| + StatResult Stat(const std::string& path) const |
| + { |
| + throw std::runtime_error("Stat is not implemented"); |
| + } |
| +}; |
| + |
| +class ThrowingFileSystem : public BaseFileSystem |
| { |
| public: |
| std::auto_ptr<std::istream> Read(const std::string& path) const |
| @@ -21,7 +44,7 @@ |
| } |
| }; |
| -class StubFileReader : public AdblockPlus::FileReader |
| +class StubFileSystem : public BaseFileSystem |
| { |
| public: |
| std::auto_ptr<std::istream> Read(const std::string& path) const |
| @@ -32,7 +55,7 @@ |
| } |
| }; |
| -class BadFileReader : public AdblockPlus::FileReader |
| +class BadFileSystem : public BaseFileSystem |
| { |
| public: |
| std::auto_ptr<std::istream> Read(const std::string& path) const |
| @@ -45,9 +68,9 @@ |
| TEST(JsEngineTest, EvaluateAndCall) |
| { |
| - ThrowingFileReader fileReader; |
| + ThrowingFileSystem fileSystem; |
| ThrowingErrorCallback errorCallback; |
| - AdblockPlus::JsEngine jsEngine(&fileReader, 0, &errorCallback); |
| + AdblockPlus::JsEngine jsEngine(&fileSystem, 0, &errorCallback); |
| const std::string source = "function hello() { return 'Hello'; }"; |
| jsEngine.Evaluate(source); |
| const std::string result = jsEngine.Evaluate("hello()"); |
| @@ -56,9 +79,9 @@ |
| TEST(JsEngineTest, LoadAndCall) |
| { |
| - StubFileReader fileReader; |
| + StubFileSystem fileSystem; |
| ThrowingErrorCallback errorCallback; |
| - AdblockPlus::JsEngine jsEngine(&fileReader, 0, &errorCallback); |
| + AdblockPlus::JsEngine jsEngine(&fileSystem, 0, &errorCallback); |
| jsEngine.Load("hello.js"); |
| const std::string result = jsEngine.Evaluate("hello()"); |
| ASSERT_EQ("Hello", result); |
| @@ -66,24 +89,24 @@ |
| TEST(JsEngineTest, LoadBadStreamFails) |
| { |
| - BadFileReader fileReader; |
| + BadFileSystem fileSystem; |
| ThrowingErrorCallback errorCallback; |
| - AdblockPlus::JsEngine jsEngine(&fileReader, 0, &errorCallback); |
| + AdblockPlus::JsEngine jsEngine(&fileSystem, 0, &errorCallback); |
| ASSERT_ANY_THROW(jsEngine.Load("hello.js")); |
| } |
| TEST(JsEngineTest, RuntimeExceptionIsThrown) |
| { |
| - ThrowingFileReader fileReader; |
| + ThrowingFileSystem fileSystem; |
| ThrowingErrorCallback errorCallback; |
| - AdblockPlus::JsEngine jsEngine(&fileReader, 0, &errorCallback); |
| + AdblockPlus::JsEngine jsEngine(&fileSystem, 0, &errorCallback); |
| ASSERT_THROW(jsEngine.Evaluate("doesnotexist()"), AdblockPlus::JsError); |
| } |
| TEST(JsEngineTest, CompileTimeExceptionIsThrown) |
| { |
| - ThrowingFileReader fileReader; |
| + ThrowingFileSystem fileSystem; |
| ThrowingErrorCallback errorCallback; |
| - AdblockPlus::JsEngine jsEngine(&fileReader, 0, &errorCallback); |
| + AdblockPlus::JsEngine jsEngine(&fileSystem, 0, &errorCallback); |
| ASSERT_THROW(jsEngine.Evaluate("'foo'bar'"), AdblockPlus::JsError); |
| } |