Index: test/JsEngine.cpp |
=================================================================== |
--- a/test/JsEngine.cpp |
+++ b/test/JsEngine.cpp |
@@ -104,33 +104,44 @@ |
TEST(NewJsEngineTest, CallbackGetSet) |
{ |
- AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New()); |
+ auto jsEngine = AdblockPlus::JsEngine::New(); |
ASSERT_TRUE(jsEngine->GetLogSystem()); |
ASSERT_ANY_THROW(jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr())); |
- AdblockPlus::LogSystemPtr logSystem(new AdblockPlus::DefaultLogSystem()); |
+ auto logSystem(std::make_shared<AdblockPlus::DefaultLogSystem>()); |
jsEngine->SetLogSystem(logSystem); |
ASSERT_EQ(logSystem, jsEngine->GetLogSystem()); |
ASSERT_TRUE(jsEngine->GetFileSystem()); |
ASSERT_ANY_THROW(jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr())); |
- AdblockPlus::FileSystemPtr fileSystem(new AdblockPlus::DefaultFileSystem()); |
+ auto fileSystem(std::make_shared<AdblockPlus::DefaultFileSystem>()); |
jsEngine->SetFileSystem(fileSystem); |
ASSERT_EQ(fileSystem, jsEngine->GetFileSystem()); |
ASSERT_TRUE(jsEngine->GetWebRequest()); |
ASSERT_ANY_THROW(jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr())); |
- AdblockPlus::WebRequestPtr webRequest(new AdblockPlus::DefaultWebRequest()); |
+ auto webRequest(std::make_shared<AdblockPlus::DefaultWebRequest>()); |
jsEngine->SetWebRequest(webRequest); |
ASSERT_EQ(webRequest, jsEngine->GetWebRequest()); |
+ |
+ ASSERT_EQ(1, jsEngine.use_count()); |
+ jsEngine.reset(); |
} |
TEST(NewJsEngineTest, GlobalPropertyTest) |
{ |
- AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New()); |
+ auto jsEngine = AdblockPlus::JsEngine::New(); |
jsEngine->SetGlobalProperty("foo", jsEngine->NewValue("bar")); |
- AdblockPlus::JsValuePtr foo = jsEngine->Evaluate("foo"); |
- ASSERT_TRUE(foo->IsString()); |
- ASSERT_EQ(foo->AsString(), "bar"); |
+ /* |
+ * Use a separate scope for JsValue variable to ensure its destruction |
+ * before we check the use count of the engine. |
+ */ |
+ { |
+ auto foo = jsEngine->Evaluate("foo"); |
+ ASSERT_TRUE(foo->IsString()); |
+ ASSERT_EQ(foo->AsString(), "bar"); |
+ } |
+ ASSERT_EQ(1, jsEngine.use_count()); |
+ jsEngine.reset(); |
} |