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: Created April 19, 2017, 6:18 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
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 10 matching lines...) Expand all
21 namespace 21 namespace
22 { 22 {
23 class JsEngineTest : public BaseJsTest 23 class JsEngineTest : public BaseJsTest
24 { 24 {
25 }; 25 };
26 } 26 }
27 27
28 TEST_F(JsEngineTest, Evaluate) 28 TEST_F(JsEngineTest, Evaluate)
29 { 29 {
30 jsEngine->Evaluate("function hello() { return 'Hello'; }"); 30 jsEngine->Evaluate("function hello() { return 'Hello'; }");
31 AdblockPlus::JsValuePtr result = jsEngine->Evaluate("hello()"); 31 auto result = jsEngine->Evaluate("hello()");
32 ASSERT_TRUE(result->IsString()); 32 ASSERT_TRUE(result.IsString());
33 ASSERT_EQ("Hello", result->AsString()); 33 ASSERT_EQ("Hello", result.AsString());
34 } 34 }
35 35
36 TEST_F(JsEngineTest, RuntimeExceptionIsThrown) 36 TEST_F(JsEngineTest, RuntimeExceptionIsThrown)
37 { 37 {
38 ASSERT_THROW(jsEngine->Evaluate("doesnotexist()"), std::runtime_error); 38 ASSERT_THROW(jsEngine->Evaluate("doesnotexist()"), std::runtime_error);
39 } 39 }
40 40
41 TEST_F(JsEngineTest, CompileTimeExceptionIsThrown) 41 TEST_F(JsEngineTest, CompileTimeExceptionIsThrown)
42 { 42 {
43 ASSERT_THROW(jsEngine->Evaluate("'foo'bar'"), std::runtime_error); 43 ASSERT_THROW(jsEngine->Evaluate("'foo'bar'"), std::runtime_error);
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 ASSERT_ANY_THROW(jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr())); 160 ASSERT_ANY_THROW(jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr()));
161 AdblockPlus::WebRequestPtr webRequest(new AdblockPlus::DefaultWebRequest()); 161 AdblockPlus::WebRequestPtr webRequest(new AdblockPlus::DefaultWebRequest());
162 jsEngine->SetWebRequest(webRequest); 162 jsEngine->SetWebRequest(webRequest);
163 ASSERT_EQ(webRequest, jsEngine->GetWebRequest()); 163 ASSERT_EQ(webRequest, jsEngine->GetWebRequest());
164 } 164 }
165 165
166 TEST(NewJsEngineTest, GlobalPropertyTest) 166 TEST(NewJsEngineTest, GlobalPropertyTest)
167 { 167 {
168 AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New()); 168 AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New());
169 jsEngine->SetGlobalProperty("foo", jsEngine->NewValue("bar")); 169 jsEngine->SetGlobalProperty("foo", jsEngine->NewValue("bar"));
170 AdblockPlus::JsValuePtr foo = jsEngine->Evaluate("foo"); 170 auto foo = jsEngine->Evaluate("foo");
171 ASSERT_TRUE(foo->IsString()); 171 ASSERT_TRUE(foo.IsString());
172 ASSERT_EQ(foo->AsString(), "bar"); 172 ASSERT_EQ(foo.AsString(), "bar");
173 } 173 }
174 174
OLDNEW
« include/AdblockPlus/JsValue.h ('K') | « test/GlobalJsObject.cpp ('k') | test/JsValue.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld