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

Unified Diff: test/FilterEngine.cpp

Issue 29389580: Issue 1397 - FilterEngine::ForceUpdateCheck crashes when passed a 0 std::function (Closed)
Patch Set: Created March 20, 2017, 2:11 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/FilterEngine.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/FilterEngine.cpp
diff --git a/test/FilterEngine.cpp b/test/FilterEngine.cpp
index a49e57c6edfabdeb44366da3fcc6a28f2dc23bec..3754d2fb9249e612d6c8a49791ada8f9c017f267 100644
--- a/test/FilterEngine.cpp
+++ b/test/FilterEngine.cpp
@@ -94,24 +94,6 @@ namespace
}
};
- struct MockUpdateAvailableCallback
- {
- MockUpdateAvailableCallback(int& timesCalled) : timesCalled(timesCalled) {}
-
- void operator()(const std::string&)
- {
- timesCalled++;
- }
-
- private:
- // We currently cannot store timesCalled in the functor, see:
- // https://issues.adblockplus.org/ticket/1378.
- int& timesCalled;
- };
-
- // Workaround for https://issues.adblockplus.org/ticket/1397.
- void NoOpUpdaterCallback(const std::string&) {}
-
class FilterEngineWithFreshFolder : public ::testing::Test
{
protected:
@@ -516,17 +498,39 @@ TEST_F(UpdaterTest, SetRemoveUpdateAvailableCallback)
}";
int timesCalled = 0;
- MockUpdateAvailableCallback mockUpdateAvailableCallback(timesCalled);
-
- filterEngine->SetUpdateAvailableCallback(mockUpdateAvailableCallback);
- filterEngine->ForceUpdateCheck(&NoOpUpdaterCallback);
+ filterEngine->SetUpdateAvailableCallback([&timesCalled](const std::string&)->void
+ {
+ ++timesCalled;
+ });
+ filterEngine->ForceUpdateCheck();
AdblockPlus::Sleep(100);
- ASSERT_EQ(1, timesCalled);
+ EXPECT_EQ(1, timesCalled);
filterEngine->RemoveUpdateAvailableCallback();
- filterEngine->ForceUpdateCheck(&NoOpUpdaterCallback);
+ filterEngine->ForceUpdateCheck();
+ AdblockPlus::Sleep(100);
+ EXPECT_EQ(1, timesCalled);
+}
+
+TEST_F(UpdaterTest, ForceUpdateCheck)
+{
+ mockWebRequest->response.status = 0;
+ mockWebRequest->response.responseStatus = 200;
+ mockWebRequest->response.responseText = "\
+{\
+ \"test\": {\
+ \"version\": \"1.0.2\",\
+ \"url\": \"https://downloads.adblockplus.org/test-1.0.2.tar.gz?update\"\
+ }\
+}";
+
+ int called = 0; // 0 - not called; 1 - once, no error; 2 - error
+ filterEngine->ForceUpdateCheck([&called](const std::string& error)->void
+ {
+ called = error.empty() ? 1 : 2;
+ });
AdblockPlus::Sleep(100);
- ASSERT_EQ(1, timesCalled);
+ EXPECT_EQ(1, called);
}
TEST_F(FilterEngineTest, DocumentWhitelisting)
« no previous file with comments | « src/FilterEngine.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld