Index: test/JsEngine.cpp |
=================================================================== |
--- a/test/JsEngine.cpp |
+++ b/test/JsEngine.cpp |
@@ -61,64 +61,62 @@ public: |
std::tr1::shared_ptr<std::ostream> content) |
{ |
throw std::runtime_error("No writing"); |
} |
}; |
TEST(JsEngineTest, EvaluateAndCall) |
{ |
- ThrowingErrorCallback errorCallback; |
- AdblockPlus::JsEngine jsEngine(AdblockPlus::AppInfo(), 0, 0, &errorCallback); |
+ AdblockPlus::JsEngine jsEngine; |
+ jsEngine.SetErrorCallback(AdblockPlus::ErrorCallbackPtr(new ThrowingErrorCallback())); |
const std::string source = "function hello() { return 'Hello'; }"; |
jsEngine.Evaluate(source); |
AdblockPlus::JsValuePtr result = jsEngine.Evaluate("hello()"); |
ASSERT_TRUE(result->IsString()); |
ASSERT_EQ("Hello", result->AsString()); |
} |
TEST(JsEngineTest, LoadAndCall) |
{ |
- StubFileSystem fileSystem; |
- ThrowingErrorCallback errorCallback; |
- AdblockPlus::JsEngine jsEngine(AdblockPlus::AppInfo(), &fileSystem, 0, |
- &errorCallback); |
+ AdblockPlus::JsEngine jsEngine; |
+ jsEngine.SetErrorCallback(AdblockPlus::ErrorCallbackPtr(new ThrowingErrorCallback())); |
+ jsEngine.SetFileSystem(AdblockPlus::FileSystemPtr(new StubFileSystem())); |
jsEngine.Load("hello.js"); |
AdblockPlus::JsValuePtr result = jsEngine.Evaluate("hello()"); |
ASSERT_TRUE(result->IsString()); |
ASSERT_EQ("Hello", result->AsString()); |
} |
TEST(JsEngineTest, LoadBadStreamFails) |
{ |
- BadFileSystem fileSystem; |
- ThrowingErrorCallback errorCallback; |
- AdblockPlus::JsEngine jsEngine(AdblockPlus::AppInfo(), &fileSystem, 0, |
- &errorCallback); |
+ AdblockPlus::JsEngine jsEngine; |
+ jsEngine.SetErrorCallback(AdblockPlus::ErrorCallbackPtr(new ThrowingErrorCallback())); |
+ jsEngine.SetFileSystem(AdblockPlus::FileSystemPtr(new BadFileSystem())); |
ASSERT_ANY_THROW(jsEngine.Load("hello.js")); |
} |
TEST(JsEngineTest, RuntimeExceptionIsThrown) |
{ |
- ThrowingErrorCallback errorCallback; |
- AdblockPlus::JsEngine jsEngine(AdblockPlus::AppInfo(), 0, 0, &errorCallback); |
+ AdblockPlus::JsEngine jsEngine; |
+ jsEngine.SetErrorCallback(AdblockPlus::ErrorCallbackPtr(new ThrowingErrorCallback())); |
ASSERT_THROW(jsEngine.Evaluate("doesnotexist()"), AdblockPlus::JsError); |
} |
TEST(JsEngineTest, CompileTimeExceptionIsThrown) |
{ |
- ThrowingErrorCallback errorCallback; |
- AdblockPlus::JsEngine jsEngine(AdblockPlus::AppInfo(), 0, 0, &errorCallback); |
+ AdblockPlus::JsEngine jsEngine; |
+ jsEngine.SetErrorCallback(AdblockPlus::ErrorCallbackPtr(new ThrowingErrorCallback())); |
ASSERT_THROW(jsEngine.Evaluate("'foo'bar'"), AdblockPlus::JsError); |
} |
TEST(JsEngineTest, ValueCreation) |
{ |
- ThrowingErrorCallback errorCallback; |
- AdblockPlus::JsEngine jsEngine(AdblockPlus::AppInfo(), 0, 0, &errorCallback); |
+ AdblockPlus::JsEngine jsEngine; |
+ jsEngine.SetErrorCallback(AdblockPlus::ErrorCallbackPtr(new ThrowingErrorCallback())); |
AdblockPlus::JsValuePtr value; |
value = jsEngine.NewValue("foo"); |
ASSERT_TRUE(value->IsString()); |
ASSERT_EQ("foo", value->AsString()); |
value = jsEngine.NewValue(12); |
ASSERT_TRUE(value->IsNumber()); |