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

Unified Diff: test/JsEngine.cpp

Issue 10296001: Implement File API (Closed)
Patch Set: Don't pass a blog to _fileSystem.write Created April 12, 2013, 12:10 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
« src/JsEngine.cpp ('K') | « test/FileSystemJsObject.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
}
« src/JsEngine.cpp ('K') | « test/FileSystemJsObject.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld