forked from IronsDu/brynet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_timer.cpp
More file actions
37 lines (33 loc) · 1.02 KB
/
test_timer.cpp
File metadata and controls
37 lines (33 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#include "catch.hpp"
#include <memory>
#include <brynet/timer/Timer.h>
#include <chrono>
TEST_CASE("Timer are computed", "[timer]") {
auto timerMgr = std::make_shared<brynet::timer::TimerMgr>();
int upvalue = 0;
auto timer = timerMgr->addTimer(std::chrono::seconds(1), [&upvalue]() {
upvalue++;
});
timer = timerMgr->addTimer(std::chrono::seconds(1), [&upvalue]() {
upvalue++;
});
auto leftTime = timerMgr->nearLeftTime();
REQUIRE_FALSE(leftTime > std::chrono::seconds(1));
REQUIRE(timerMgr->isEmpty() == false);
while (!timerMgr->isEmpty())
{
timerMgr->schedule();
}
REQUIRE(upvalue == 2);
timer = timerMgr->addTimer(std::chrono::seconds(1), [&upvalue]() {
upvalue++;
});
timer.lock()->cancel();
REQUIRE(timerMgr->isEmpty() == false);
while (!timerMgr->isEmpty())
{
timerMgr->schedule();
}
REQUIRE(upvalue == 2);
}