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

Delta Between Two Patch Sets: test/JsEngine.cpp

Issue 29417605: Issue 5034 - Part 3: Create plain JsValue instead of JsValuePtr (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Left Patch Set: Added value test for copy ctor Created April 20, 2017, 12:40 p.m.
Right Patch Set: Pass JsEngine by ref Created April 20, 2017, 1:01 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/FilterEngine.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
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 ASSERT_TRUE(value.IsBool()); 58 ASSERT_TRUE(value.IsBool());
59 ASSERT_TRUE(value.AsBool()); 59 ASSERT_TRUE(value.AsBool());
60 60
61 value = jsEngine->NewObject(); 61 value = jsEngine->NewObject();
62 ASSERT_TRUE(value.IsObject()); 62 ASSERT_TRUE(value.IsObject());
63 ASSERT_EQ(0u, value.GetOwnPropertyNames().size()); 63 ASSERT_EQ(0u, value.GetOwnPropertyNames().size());
64 } 64 }
65 65
66 namespace { 66 namespace {
67 67
68 bool IsSame(const AdblockPlus::JsEnginePtr& jsEngine, 68 bool IsSame(AdblockPlus::JsEngine& jsEngine,
sergei 2017/04/20 12:45:08 Can be just `JsEngine&` (without pointer).
hub 2017/04/20 13:01:46 ok
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());
85 85
86 AdblockPlus::JsValue value2(value); 86 AdblockPlus::JsValue value2(value);
87 ASSERT_TRUE(value2.IsString()); 87 ASSERT_TRUE(value2.IsString());
88 ASSERT_EQ("foo", value2.AsString()); 88 ASSERT_EQ("foo", value2.AsString());
89 89
90 ASSERT_TRUE(IsSame(jsEngine, value, value2)); 90 ASSERT_TRUE(IsSame(*jsEngine, value, value2));
sergei 2017/04/20 12:45:08 I think we should rather try to use EXPECT_ when i
hub 2017/04/20 13:01:46 I used ASSERT_ for consistency. EXPECT_ is fine to
91 } 91 }
92 { 92 {
93 auto value = jsEngine->NewValue(12345678901234); 93 auto value = jsEngine->NewValue(12345678901234);
94 ASSERT_TRUE(value.IsNumber()); 94 ASSERT_TRUE(value.IsNumber());
95 ASSERT_EQ(12345678901234, value.AsInt()); 95 ASSERT_EQ(12345678901234, value.AsInt());
96 96
97 AdblockPlus::JsValue value2(value); 97 AdblockPlus::JsValue value2(value);
98 ASSERT_TRUE(value2.IsNumber()); 98 ASSERT_TRUE(value2.IsNumber());
99 ASSERT_EQ(12345678901234, value2.AsInt()); 99 ASSERT_EQ(12345678901234, value2.AsInt());
100 100
101 ASSERT_TRUE(IsSame(jsEngine, value, value2)); 101 ASSERT_TRUE(IsSame(*jsEngine, value, value2));
102 } 102 }
103 { 103 {
104 auto value = jsEngine->NewValue(true); 104 auto value = jsEngine->NewValue(true);
105 ASSERT_TRUE(value.IsBool()); 105 ASSERT_TRUE(value.IsBool());
106 ASSERT_TRUE(value.AsBool()); 106 ASSERT_TRUE(value.AsBool());
107 107
108 AdblockPlus::JsValue value2(value); 108 AdblockPlus::JsValue value2(value);
109 ASSERT_TRUE(value2.IsBool()); 109 ASSERT_TRUE(value2.IsBool());
110 ASSERT_TRUE(value2.AsBool()); 110 ASSERT_TRUE(value2.AsBool());
111 111
112 ASSERT_TRUE(IsSame(jsEngine, value, value2)); 112 ASSERT_TRUE(IsSame(*jsEngine, value, value2));
113 } 113 }
114 { 114 {
115 auto value = jsEngine->NewObject(); 115 auto value = jsEngine->NewObject();
116 ASSERT_TRUE(value.IsObject()); 116 ASSERT_TRUE(value.IsObject());
117 ASSERT_EQ(0u, value.GetOwnPropertyNames().size()); 117 ASSERT_EQ(0u, value.GetOwnPropertyNames().size());
118 118
119 AdblockPlus::JsValue value2(value); 119 AdblockPlus::JsValue value2(value);
120 ASSERT_TRUE(value2.IsObject()); 120 ASSERT_TRUE(value2.IsObject());
121 ASSERT_EQ(0u, value2.GetOwnPropertyNames().size()); 121 ASSERT_EQ(0u, value2.GetOwnPropertyNames().size());
122 122
123 ASSERT_TRUE(IsSame(jsEngine, value, value2)); 123 ASSERT_TRUE(IsSame(*jsEngine, value, value2));
124 } 124 }
125 } 125 }
126 126
127 TEST_F(JsEngineTest, EventCallbacks) 127 TEST_F(JsEngineTest, EventCallbacks)
128 { 128 {
129 bool callbackCalled = false; 129 bool callbackCalled = false;
130 AdblockPlus::JsValueList callbackParams; 130 AdblockPlus::JsValueList callbackParams;
131 auto Callback = [&callbackCalled, & callbackParams]( 131 auto Callback = [&callbackCalled, & callbackParams](
132 const AdblockPlus::JsValueList& params) 132 const AdblockPlus::JsValueList& params)
133 { 133 {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 AdblockPlus::JsValuePtr 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
LEFTRIGHT

Powered by Google App Engine
This is Rietveld