Index: test/UpdateCheck.cpp |
=================================================================== |
--- a/test/UpdateCheck.cpp |
+++ b/test/UpdateCheck.cpp |
@@ -18,6 +18,7 @@ |
#include <functional> |
#include "BaseJsTest.h" |
+#include "../src/JsEngineTransition.h" |
namespace |
{ |
@@ -46,10 +47,30 @@ |
class UpdateCheckTest : public ::testing::Test |
{ |
+ void Construct() |
+ { |
+ jsEngine = CreateJsEngine(appInfo); |
+ jsEngine->SetLogSystem(std::make_shared<LazyLogSystem>()); |
+ jsEngine->SetFileSystem(std::make_shared<LazyFileSystem>()); |
+ jsEngine->SetWebRequest(webRequest); |
+ jsEngine->SetEventCallback("updateAvailable", |
+ std::bind(&UpdateCheckTest::EventCallback, this, std::placeholders::_1)); |
+ |
+ filterEngine = std::make_shared<AdblockPlus::FilterEngine>(jsEngine); |
+ } |
+ |
+ void Destroy() |
+ { |
+ webRequest->Cancel(); |
+ filterEngine.reset(); |
+ ToInternal(jsEngine)->WaitForQuietScheduler(); |
+ jsEngine.reset(); |
+ ASSERT_EQ(0, jsEngine.use_count()); |
+ } |
+ |
protected: |
AdblockPlus::AppInfo appInfo; |
- TestWebRequest* webRequest; |
- AdblockPlus::WebRequestPtr webRequestPtr; |
+ std::shared_ptr<TestWebRequest> webRequest; |
AdblockPlus::JsEnginePtr jsEngine; |
FilterEnginePtr filterEngine; |
@@ -60,29 +81,22 @@ |
void SetUp() |
{ |
- webRequest = new TestWebRequest(); |
- webRequestPtr.reset(webRequest); |
- |
+ webRequest = std::make_shared<TestWebRequest>(); |
eventCallbackCalled = false; |
updateCallbackCalled = false; |
- Reset(); |
+ Construct(); |
} |
void TearDown() |
{ |
- webRequest->Cancel(); |
+ Destroy(); |
+ webRequest.reset(); |
} |
void Reset() |
{ |
- jsEngine = CreateJsEngine(appInfo); |
- jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr(new LazyLogSystem)); |
- jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new LazyFileSystem)); |
- jsEngine->SetWebRequest(webRequestPtr); |
- jsEngine->SetEventCallback("updateAvailable", |
- std::bind(&UpdateCheckTest::EventCallback, this, std::placeholders::_1)); |
- |
- filterEngine.reset(new AdblockPlus::FilterEngine(jsEngine)); |
+ Destroy(); |
+ Construct(); |
} |
void ForceUpdateCheck() |