OLD | NEW |
1 #ifndef MOCKS_H | 1 #ifndef MOCKS_H |
2 #define MOCKS_H | 2 #define MOCKS_H |
3 | 3 |
4 #include <AdblockPlus.h> | 4 #include <AdblockPlus.h> |
5 #include <gtest/gtest.h> | 5 #include <gtest/gtest.h> |
| 6 #include "../src/Thread.h" |
6 | 7 |
7 class ThrowingErrorCallback : public AdblockPlus::ErrorCallback | 8 class ThrowingErrorCallback : public AdblockPlus::ErrorCallback |
8 { | 9 { |
9 public: | 10 public: |
10 void operator()(const std::string& message) | 11 void operator()(const std::string& message) |
11 { | 12 { |
12 throw std::runtime_error("Unexpected error: " + message); | 13 throw std::runtime_error("Unexpected error: " + message); |
13 } | 14 } |
14 }; | 15 }; |
15 | 16 |
(...skipping 27 matching lines...) Expand all Loading... |
43 }; | 44 }; |
44 | 45 |
45 class ThrowingWebRequest : public AdblockPlus::WebRequest | 46 class ThrowingWebRequest : public AdblockPlus::WebRequest |
46 { | 47 { |
47 AdblockPlus::ServerResponse GET(const std::string& url, const AdblockPlus::Hea
derList& requestHeaders) const | 48 AdblockPlus::ServerResponse GET(const std::string& url, const AdblockPlus::Hea
derList& requestHeaders) const |
48 { | 49 { |
49 throw std::runtime_error("Unexpected GET: " + url); | 50 throw std::runtime_error("Unexpected GET: " + url); |
50 } | 51 } |
51 }; | 52 }; |
52 | 53 |
| 54 class LazyFileSystem : public AdblockPlus::FileSystem |
| 55 { |
| 56 std::tr1::shared_ptr<std::istream> Read(const std::string& path) const |
| 57 { |
| 58 while (true) |
| 59 AdblockPlus::Sleep(100000); |
| 60 return std::tr1::shared_ptr<std::istream>(); |
| 61 } |
| 62 |
| 63 void Write(const std::string& path, |
| 64 std::tr1::shared_ptr<std::ostream> content) |
| 65 { |
| 66 while (true) |
| 67 AdblockPlus::Sleep(100000); |
| 68 } |
| 69 |
| 70 void Move(const std::string& fromPath, const std::string& toPath) |
| 71 { |
| 72 while (true) |
| 73 AdblockPlus::Sleep(100000); |
| 74 } |
| 75 |
| 76 void Remove(const std::string& path) |
| 77 { |
| 78 while (true) |
| 79 AdblockPlus::Sleep(100000); |
| 80 } |
| 81 |
| 82 StatResult Stat(const std::string& path) const |
| 83 { |
| 84 while (true) |
| 85 AdblockPlus::Sleep(100000); |
| 86 return StatResult(); |
| 87 } |
| 88 }; |
| 89 |
| 90 class LazyWebRequest : public AdblockPlus::WebRequest |
| 91 { |
| 92 AdblockPlus::ServerResponse GET(const std::string& url, const AdblockPlus::Hea
derList& requestHeaders) const |
| 93 { |
| 94 while (true) |
| 95 AdblockPlus::Sleep(100000); |
| 96 return AdblockPlus::ServerResponse(); |
| 97 } |
| 98 }; |
| 99 |
| 100 |
53 class BaseJsTest : public ::testing::Test | 101 class BaseJsTest : public ::testing::Test |
54 { | 102 { |
55 protected: | 103 protected: |
56 AdblockPlus::JsEnginePtr jsEngine; | 104 AdblockPlus::JsEnginePtr jsEngine; |
57 | 105 |
58 virtual void SetUp() | 106 virtual void SetUp() |
59 { | 107 { |
60 jsEngine = AdblockPlus::JsEngine::New(); | 108 jsEngine = AdblockPlus::JsEngine::New(); |
61 jsEngine->SetErrorCallback(AdblockPlus::ErrorCallbackPtr(new ThrowingErrorCa
llback)); | 109 jsEngine->SetErrorCallback(AdblockPlus::ErrorCallbackPtr(new ThrowingErrorCa
llback)); |
62 jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new ThrowingFileSystem)); | 110 jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new ThrowingFileSystem)); |
63 jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(new ThrowingWebRequest)); | 111 jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(new ThrowingWebRequest)); |
64 } | 112 } |
65 }; | 113 }; |
66 | 114 |
67 #endif | 115 #endif |
OLD | NEW |