Index: test/FilterEngine.cpp |
=================================================================== |
--- a/test/FilterEngine.cpp |
+++ b/test/FilterEngine.cpp |
@@ -72,17 +72,17 @@ |
class FilterEngineWithFreshFolder : public ::testing::Test |
{ |
protected: |
FileSystemPtr fileSystem; |
std::weak_ptr<JsEngine> weakJsEngine; |
void SetUp() override |
{ |
- fileSystem.reset(new DefaultFileSystem()); |
+ fileSystem = CreateDefaultFileSystem(); |
// Since there is neither in memory FS nor functionality to work with |
// directories use the hack: manually clean the directory. |
removeFileIfExists("patterns.ini"); |
removeFileIfExists("prefs.json"); |
} |
JsEnginePtr createJsEngine(const AppInfo& appInfo = AppInfo()) |
{ |
JsEngineCreationParameters jsEngineParams; |
@@ -104,19 +104,33 @@ |
void removeFileIfExists(const std::string& path) |
{ |
// Hack: allow IO to finish currently running operations, in particular |
// writing into files. Otherwise we get "Permission denied". |
auto safeRemove = [this, &path]()->bool |
{ |
try |
{ |
- if (fileSystem->Stat(path).exists) |
- fileSystem->Remove(path); |
- return true; |
+ Sync sync; |
+ auto fs = fileSystem; |
+ fileSystem->Stat(path, |
+ [fs, &path, &sync](const IFileSystem::StatResult& stats, const std::string& error) |
+ { |
+ if (error.empty() && stats.exists) |
+ { |
+ fs->Remove(path, [&sync](const std::string& error) |
+ { |
+ sync.Set(error); |
+ }); |
+ } |
+ else |
+ sync.Set(error); |
+ }); |
+ sync.Wait(); |
+ return sync.GetError().empty(); |
} |
catch (...) |
{ |
return false; |
} |
}; |
int i = 5; |
while ((i-- > 0 && weakJsEngine.lock()) || !safeRemove()) |
@@ -580,19 +594,21 @@ |
std::this_thread::sleep_for(std::chrono::milliseconds(200)); |
filterEngine->SetFilterChangeCallback([×Called](const std::string&, AdblockPlus::JsValue&&) |
{ |
timesCalled++; |
}); |
filterEngine->GetFilter("foo").AddToList(); |
EXPECT_EQ(1, timesCalled); |
+ // we want to actually check the call count didn't change. |
+ int previousTimesCalled = timesCalled; |
sergei
2017/06/16 15:05:56
But its value is still one. Could you move it into
hub
2017/06/16 21:52:56
I'll just keep the comment.
|
filterEngine->RemoveFilterChangeCallback(); |
filterEngine->GetFilter("foo").RemoveFromList(); |
- EXPECT_EQ(1, timesCalled); |
+ EXPECT_EQ(previousTimesCalled, timesCalled); |
} |
TEST_F(FilterEngineTest, DocumentWhitelisting) |
{ |
filterEngine->GetFilter("@@||example.org^$document").AddToList(); |
filterEngine->GetFilter("@@||example.com^$document,domain=example.de").AddToList(); |
ASSERT_TRUE(filterEngine->IsDocumentWhitelisted( |