1
0
mirror of https://github.com/wqking/eventpp.git synced 2024-12-27 00:17:02 +08:00

Merge pull request #39 from devbharat/test-setCallbackList

Test setCallbackList
This commit is contained in:
Wang Qi 2022-04-30 07:40:19 +08:00 committed by GitHub
commit 4160f119f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -56,8 +56,9 @@ TEST_CASE("ScopedRemover, CallbackList")
using CL = eventpp::CallbackList<void ()>;
CL callbackList;
using Remover = eventpp::ScopedRemover<CL>;
Remover r4;
std::vector<int> dataList(4);
std::vector<int> dataList(5);
callbackList.append([&dataList]() {
++dataList[0];
@ -78,23 +79,33 @@ TEST_CASE("ScopedRemover, CallbackList")
r3.insert([&dataList]() {
++dataList[3];
}, handle);
{
r4.setCallbackList(callbackList);
r4.append([&dataList]() {
++dataList[4];
});
REQUIRE(dataList == std::vector<int> { 0, 0, 0, 0 });
REQUIRE(dataList == std::vector<int> { 0, 0, 0, 0, 0 });
callbackList();
REQUIRE(dataList == std::vector<int> { 1, 1, 1, 1, 1 });
r4.reset();
}
callbackList();
REQUIRE(dataList == std::vector<int> { 1, 1, 1, 1 });
REQUIRE(dataList == std::vector<int> { 2, 2, 2, 2, 1 });
}
callbackList();
REQUIRE(dataList == std::vector<int> { 2, 2, 2, 1 });
REQUIRE(dataList == std::vector<int> { 3, 3, 3, 2, 1 });
}
callbackList();
REQUIRE(dataList == std::vector<int> { 3, 3, 2, 1 });
REQUIRE(dataList == std::vector<int> { 4, 4, 3, 2, 1 });
}
callbackList();
REQUIRE(dataList == std::vector<int> { 4, 3, 2, 1 });
REQUIRE(dataList == std::vector<int> { 5, 4, 3, 2, 1 });
}
TEST_CASE("ScopedRemover, HeterEventDispatcher")