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

Unified Diff: test/BaseJsTest.h

Issue 10260028: Refactor tests, use fixtures and avoid duplication (Closed)
Patch Set: Created April 19, 2013, 4:11 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 | « MSVS/tests.vcxproj.filters ('k') | test/ConsoleJsObject.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/BaseJsTest.h
===================================================================
new file mode 100644
--- /dev/null
+++ b/test/BaseJsTest.h
@@ -0,0 +1,67 @@
+#ifndef MOCKS_H
+#define MOCKS_H
+
+#include <AdblockPlus.h>
+#include <gtest/gtest.h>
+
+class ThrowingErrorCallback : public AdblockPlus::ErrorCallback
+{
+public:
+ void operator()(const std::string& message)
+ {
+ throw std::runtime_error("Unexpected error: " + message);
+ }
+};
+
+class ThrowingFileSystem : public AdblockPlus::FileSystem
+{
+ std::tr1::shared_ptr<std::istream> Read(const std::string& path) const
+ {
+ throw std::runtime_error("Not implemented");
+ }
+
+ void Write(const std::string& path,
+ std::tr1::shared_ptr<std::ostream> content)
+ {
+ throw std::runtime_error("Not implemented");
+ }
+
+ void Move(const std::string& fromPath, const std::string& toPath)
+ {
+ throw std::runtime_error("Not implemented");
+ }
+
+ void Remove(const std::string& path)
+ {
+ throw std::runtime_error("Not implemented");
+ }
+
+ StatResult Stat(const std::string& path) const
+ {
+ throw std::runtime_error("Not implemented");
+ }
+};
+
+class ThrowingWebRequest : public AdblockPlus::WebRequest
+{
+ AdblockPlus::ServerResponse GET(const std::string& url, const AdblockPlus::HeaderList& requestHeaders) const
+ {
+ throw std::runtime_error("Unexpected GET: " + url);
+ }
+};
+
+class BaseJsTest : public ::testing::Test
+{
+protected:
+ AdblockPlus::JsEnginePtr jsEngine;
+
+ virtual void SetUp()
+ {
+ jsEngine = AdblockPlus::JsEngine::New();
+ jsEngine->SetErrorCallback(AdblockPlus::ErrorCallbackPtr(new ThrowingErrorCallback));
+ jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new ThrowingFileSystem));
+ jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(new ThrowingWebRequest));
+ }
+};
+
+#endif
« no previous file with comments | « MSVS/tests.vcxproj.filters ('k') | test/ConsoleJsObject.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld