OLD | NEW |
(Empty) | |
| 1 #ifndef MOCKS_H |
| 2 #define MOCKS_H |
| 3 |
| 4 #include <AdblockPlus.h> |
| 5 #include <gtest/gtest.h> |
| 6 |
| 7 class ThrowingErrorCallback : public AdblockPlus::ErrorCallback |
| 8 { |
| 9 public: |
| 10 void operator()(const std::string& message) |
| 11 { |
| 12 throw std::runtime_error("Unexpected error: " + message); |
| 13 } |
| 14 }; |
| 15 |
| 16 class ThrowingFileSystem : public AdblockPlus::FileSystem |
| 17 { |
| 18 std::tr1::shared_ptr<std::istream> Read(const std::string& path) const |
| 19 { |
| 20 throw std::runtime_error("Not implemented"); |
| 21 } |
| 22 |
| 23 void Write(const std::string& path, |
| 24 std::tr1::shared_ptr<std::ostream> content) |
| 25 { |
| 26 throw std::runtime_error("Not implemented"); |
| 27 } |
| 28 |
| 29 void Move(const std::string& fromPath, const std::string& toPath) |
| 30 { |
| 31 throw std::runtime_error("Not implemented"); |
| 32 } |
| 33 |
| 34 void Remove(const std::string& path) |
| 35 { |
| 36 throw std::runtime_error("Not implemented"); |
| 37 } |
| 38 |
| 39 StatResult Stat(const std::string& path) const |
| 40 { |
| 41 throw std::runtime_error("Not implemented"); |
| 42 } |
| 43 }; |
| 44 |
| 45 class ThrowingWebRequest : public AdblockPlus::WebRequest |
| 46 { |
| 47 AdblockPlus::ServerResponse GET(const std::string& url, const AdblockPlus::Hea
derList& requestHeaders) const |
| 48 { |
| 49 throw std::runtime_error("Unexpected GET: " + url); |
| 50 } |
| 51 }; |
| 52 |
| 53 class BaseJsTest : public ::testing::Test |
| 54 { |
| 55 protected: |
| 56 AdblockPlus::JsEnginePtr jsEngine; |
| 57 |
| 58 virtual void SetUp() |
| 59 { |
| 60 jsEngine = AdblockPlus::JsEngine::New(); |
| 61 jsEngine->SetErrorCallback(AdblockPlus::ErrorCallbackPtr(new ThrowingErrorCa
llback)); |
| 62 jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new ThrowingFileSystem)); |
| 63 jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(new ThrowingWebRequest)); |
| 64 } |
| 65 }; |
| 66 |
| 67 #endif |
OLD | NEW |