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

Unified Diff: test/JsEngine.cpp

Issue 10213003: Make JsEngine::Evaluate() return a wrapper for v8::Value to accessdifferent variable types easily (Closed)
Patch Set: Addressed review comments Created April 17, 2013, 7:56 a.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 | « test/GlobalJsObject.cpp ('k') | test/JsValue.cpp » ('j') | 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
@@ -65,28 +65,30 @@ public:
};
TEST(JsEngineTest, EvaluateAndCall)
{
ThrowingErrorCallback errorCallback;
AdblockPlus::JsEngine jsEngine(0, 0, &errorCallback);
const std::string source = "function hello() { return 'Hello'; }";
jsEngine.Evaluate(source);
- const std::string result = jsEngine.Evaluate("hello()");
- ASSERT_EQ("Hello", result);
+ 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(&fileSystem, 0, &errorCallback);
jsEngine.Load("hello.js");
- const std::string result = jsEngine.Evaluate("hello()");
- ASSERT_EQ("Hello", result);
+ 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(&fileSystem, 0, &errorCallback);
ASSERT_ANY_THROW(jsEngine.Load("hello.js"));
@@ -100,8 +102,27 @@ TEST(JsEngineTest, RuntimeExceptionIsThr
}
TEST(JsEngineTest, CompileTimeExceptionIsThrown)
{
ThrowingErrorCallback errorCallback;
AdblockPlus::JsEngine jsEngine(0, 0, &errorCallback);
ASSERT_THROW(jsEngine.Evaluate("'foo'bar'"), AdblockPlus::JsError);
}
+
+TEST(JsEngineTest, ValueCreation)
+{
+ ThrowingErrorCallback errorCallback;
+ AdblockPlus::JsEngine jsEngine(0, 0, &errorCallback);
+ AdblockPlus::JsValuePtr value;
+
+ value = jsEngine.NewValue("foo");
+ ASSERT_TRUE(value->IsString());
+ ASSERT_EQ("foo", value->AsString());
+
+ value = jsEngine.NewValue(12);
+ ASSERT_TRUE(value->IsNumber());
+ ASSERT_EQ(12, value->AsInt());
+
+ value = jsEngine.NewValue(true);
+ ASSERT_TRUE(value->IsBool());
+ ASSERT_TRUE(value->AsBool());
+}
« no previous file with comments | « test/GlobalJsObject.cpp ('k') | test/JsValue.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld