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

Side by Side Diff: test/JsEngine.cpp

Issue 29417624: Issue 5034 - Part 4: JsEngine::Evaluate() return a JsValue (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Rebased on top of part 3 Created April 20, 2017, 12:41 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/GlobalJsObject.cpp ('k') | test/JsValue.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 11 matching lines...) Expand all
22 namespace 22 namespace
23 { 23 {
24 class JsEngineTest : public BaseJsTest 24 class JsEngineTest : public BaseJsTest
25 { 25 {
26 }; 26 };
27 } 27 }
28 28
29 TEST_F(JsEngineTest, Evaluate) 29 TEST_F(JsEngineTest, Evaluate)
30 { 30 {
31 jsEngine->Evaluate("function hello() { return 'Hello'; }"); 31 jsEngine->Evaluate("function hello() { return 'Hello'; }");
32 AdblockPlus::JsValuePtr result = jsEngine->Evaluate("hello()"); 32 auto result = jsEngine->Evaluate("hello()");
33 ASSERT_TRUE(result->IsString()); 33 ASSERT_TRUE(result.IsString());
34 ASSERT_EQ("Hello", result->AsString()); 34 ASSERT_EQ("Hello", result.AsString());
35 } 35 }
36 36
37 TEST_F(JsEngineTest, RuntimeExceptionIsThrown) 37 TEST_F(JsEngineTest, RuntimeExceptionIsThrown)
38 { 38 {
39 ASSERT_THROW(jsEngine->Evaluate("doesnotexist()"), std::runtime_error); 39 ASSERT_THROW(jsEngine->Evaluate("doesnotexist()"), std::runtime_error);
40 } 40 }
41 41
42 TEST_F(JsEngineTest, CompileTimeExceptionIsThrown) 42 TEST_F(JsEngineTest, CompileTimeExceptionIsThrown)
43 { 43 {
44 ASSERT_THROW(jsEngine->Evaluate("'foo'bar'"), std::runtime_error); 44 ASSERT_THROW(jsEngine->Evaluate("'foo'bar'"), std::runtime_error);
(...skipping 19 matching lines...) Expand all
64 } 64 }
65 65
66 namespace { 66 namespace {
67 67
68 bool IsSame(const AdblockPlus::JsEnginePtr& jsEngine, 68 bool IsSame(const AdblockPlus::JsEnginePtr& jsEngine,
69 const AdblockPlus::JsValue& v1, const AdblockPlus::JsValue& v2) 69 const AdblockPlus::JsValue& v1, const AdblockPlus::JsValue& v2)
70 { 70 {
71 AdblockPlus::JsValueList params; 71 AdblockPlus::JsValueList params;
72 params.push_back(v1); 72 params.push_back(v1);
73 params.push_back(v2); 73 params.push_back(v2);
74 return jsEngine->Evaluate("f = function(a, b) { return a == b };")->Call(par ams).AsBool(); 74 return jsEngine->Evaluate("f = function(a, b) { return a == b };").Call(para ms).AsBool();
75 } 75 }
76 76
77 } 77 }
78 78
79 TEST_F(JsEngineTest, ValueCopy) 79 TEST_F(JsEngineTest, ValueCopy)
80 { 80 {
81 { 81 {
82 auto value = jsEngine->NewValue("foo"); 82 auto value = jsEngine->NewValue("foo");
83 ASSERT_TRUE(value.IsString()); 83 ASSERT_TRUE(value.IsString());
84 ASSERT_EQ("foo", value.AsString()); 84 ASSERT_EQ("foo", value.AsString());
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 ASSERT_ANY_THROW(jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr())); 182 ASSERT_ANY_THROW(jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr()));
183 AdblockPlus::WebRequestPtr webRequest(new AdblockPlus::DefaultWebRequest()); 183 AdblockPlus::WebRequestPtr webRequest(new AdblockPlus::DefaultWebRequest());
184 jsEngine->SetWebRequest(webRequest); 184 jsEngine->SetWebRequest(webRequest);
185 ASSERT_EQ(webRequest, jsEngine->GetWebRequest()); 185 ASSERT_EQ(webRequest, jsEngine->GetWebRequest());
186 } 186 }
187 187
188 TEST(NewJsEngineTest, GlobalPropertyTest) 188 TEST(NewJsEngineTest, GlobalPropertyTest)
189 { 189 {
190 AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New()); 190 AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New());
191 jsEngine->SetGlobalProperty("foo", jsEngine->NewValue("bar")); 191 jsEngine->SetGlobalProperty("foo", jsEngine->NewValue("bar"));
192 AdblockPlus::JsValuePtr foo = jsEngine->Evaluate("foo"); 192 auto foo = jsEngine->Evaluate("foo");
193 ASSERT_TRUE(foo->IsString()); 193 ASSERT_TRUE(foo.IsString());
194 ASSERT_EQ(foo->AsString(), "bar"); 194 ASSERT_EQ(foo.AsString(), "bar");
195 } 195 }
196 196
OLDNEW
« 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