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

Delta Between Two Patch Sets: test/JsEngine.cpp

Issue 29417624: Issue 5034 - Part 4: JsEngine::Evaluate() return a JsValue (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Left Patch Set: Created April 19, 2017, 6:18 p.m.
Right Patch Set: Rebased again Created April 20, 2017, 1:02 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « test/GlobalJsObject.cpp ('k') | test/JsValue.cpp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #include <stdexcept> 18 #include <stdexcept>
19 #include "BaseJsTest.h" 19 #include "BaseJsTest.h"
20 #include "../src/JsContext.h"
20 21
21 namespace 22 namespace
22 { 23 {
23 class JsEngineTest : public BaseJsTest 24 class JsEngineTest : public BaseJsTest
24 { 25 {
25 }; 26 };
26 } 27 }
27 28
28 TEST_F(JsEngineTest, Evaluate) 29 TEST_F(JsEngineTest, Evaluate)
29 { 30 {
(...skipping 25 matching lines...) Expand all
55 56
56 value = jsEngine->NewValue(true); 57 value = jsEngine->NewValue(true);
57 ASSERT_TRUE(value.IsBool()); 58 ASSERT_TRUE(value.IsBool());
58 ASSERT_TRUE(value.AsBool()); 59 ASSERT_TRUE(value.AsBool());
59 60
60 value = jsEngine->NewObject(); 61 value = jsEngine->NewObject();
61 ASSERT_TRUE(value.IsObject()); 62 ASSERT_TRUE(value.IsObject());
62 ASSERT_EQ(0u, value.GetOwnPropertyNames().size()); 63 ASSERT_EQ(0u, value.GetOwnPropertyNames().size());
63 } 64 }
64 65
66 namespace {
67
68 bool IsSame(AdblockPlus::JsEngine& jsEngine,
69 const AdblockPlus::JsValue& v1, const AdblockPlus::JsValue& v2)
70 {
71 AdblockPlus::JsValueList params;
72 params.push_back(v1);
73 params.push_back(v2);
74 return jsEngine.Evaluate("f = function(a, b) { return a == b };").Call(param s).AsBool();
75 }
76
77 }
78
65 TEST_F(JsEngineTest, ValueCopy) 79 TEST_F(JsEngineTest, ValueCopy)
66 { 80 {
67 { 81 {
68 auto value = jsEngine->NewValue("foo"); 82 auto value = jsEngine->NewValue("foo");
69 ASSERT_TRUE(value.IsString()); 83 ASSERT_TRUE(value.IsString());
70 ASSERT_EQ("foo", value.AsString()); 84 ASSERT_EQ("foo", value.AsString());
71 85
72 AdblockPlus::JsValue value2(value); 86 AdblockPlus::JsValue value2(value);
73 ASSERT_TRUE(value2.IsString()); 87 ASSERT_TRUE(value2.IsString());
74 ASSERT_EQ("foo", value2.AsString()); 88 ASSERT_EQ("foo", value2.AsString());
89
90 ASSERT_TRUE(IsSame(*jsEngine, value, value2));
75 } 91 }
76 { 92 {
77 auto value = jsEngine->NewValue(12345678901234); 93 auto value = jsEngine->NewValue(12345678901234);
78 ASSERT_TRUE(value.IsNumber()); 94 ASSERT_TRUE(value.IsNumber());
79 ASSERT_EQ(12345678901234, value.AsInt()); 95 ASSERT_EQ(12345678901234, value.AsInt());
80 96
81 AdblockPlus::JsValue value2(value); 97 AdblockPlus::JsValue value2(value);
82 ASSERT_TRUE(value2.IsNumber()); 98 ASSERT_TRUE(value2.IsNumber());
83 ASSERT_EQ(12345678901234, value2.AsInt()); 99 ASSERT_EQ(12345678901234, value2.AsInt());
100
101 ASSERT_TRUE(IsSame(*jsEngine, value, value2));
84 } 102 }
85 { 103 {
86 auto value = jsEngine->NewValue(true); 104 auto value = jsEngine->NewValue(true);
87 ASSERT_TRUE(value.IsBool()); 105 ASSERT_TRUE(value.IsBool());
88 ASSERT_TRUE(value.AsBool()); 106 ASSERT_TRUE(value.AsBool());
89 107
90 AdblockPlus::JsValue value2(value); 108 AdblockPlus::JsValue value2(value);
91 ASSERT_TRUE(value2.IsBool()); 109 ASSERT_TRUE(value2.IsBool());
92 ASSERT_TRUE(value2.AsBool()); 110 ASSERT_TRUE(value2.AsBool());
111
112 ASSERT_TRUE(IsSame(*jsEngine, value, value2));
93 } 113 }
94 { 114 {
95 auto value = jsEngine->NewObject(); 115 auto value = jsEngine->NewObject();
96 ASSERT_TRUE(value.IsObject()); 116 ASSERT_TRUE(value.IsObject());
97 ASSERT_EQ(0u, value.GetOwnPropertyNames().size()); 117 ASSERT_EQ(0u, value.GetOwnPropertyNames().size());
98 118
99 AdblockPlus::JsValue value2(value); 119 AdblockPlus::JsValue value2(value);
100 ASSERT_TRUE(value2.IsObject()); 120 ASSERT_TRUE(value2.IsObject());
101 ASSERT_EQ(0u, value2.GetOwnPropertyNames().size()); 121 ASSERT_EQ(0u, value2.GetOwnPropertyNames().size());
122
123 ASSERT_TRUE(IsSame(*jsEngine, value, value2));
102 } 124 }
103 } 125 }
104 126
105 TEST_F(JsEngineTest, EventCallbacks) 127 TEST_F(JsEngineTest, EventCallbacks)
106 { 128 {
107 bool callbackCalled = false; 129 bool callbackCalled = false;
108 AdblockPlus::JsValueList callbackParams; 130 AdblockPlus::JsValueList callbackParams;
109 auto Callback = [&callbackCalled, & callbackParams]( 131 auto Callback = [&callbackCalled, & callbackParams](
110 const AdblockPlus::JsValueList& params) 132 const AdblockPlus::JsValueList& params)
111 { 133 {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 187
166 TEST(NewJsEngineTest, GlobalPropertyTest) 188 TEST(NewJsEngineTest, GlobalPropertyTest)
167 { 189 {
168 AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New()); 190 AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New());
169 jsEngine->SetGlobalProperty("foo", jsEngine->NewValue("bar")); 191 jsEngine->SetGlobalProperty("foo", jsEngine->NewValue("bar"));
170 auto foo = jsEngine->Evaluate("foo"); 192 auto foo = jsEngine->Evaluate("foo");
171 ASSERT_TRUE(foo.IsString()); 193 ASSERT_TRUE(foo.IsString());
172 ASSERT_EQ(foo.AsString(), "bar"); 194 ASSERT_EQ(foo.AsString(), "bar");
173 } 195 }
174 196
LEFTRIGHT

Powered by Google App Engine
This is Rietveld