本文整理汇总了C++中TimeInterval::IsZero方法的典型用法代码示例。如果您正苦于以下问题:C++ TimeInterval::IsZero方法的具体用法?C++ TimeInterval::IsZero怎么用?C++ TimeInterval::IsZero使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TimeInterval
的用法示例。
在下文中一共展示了TimeInterval::IsZero方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testSingleTimeouts
/*
* Check RegisterSingleTimeout works.
*/
void TimeoutManagerTest::testSingleTimeouts() {
MockClock clock;
TimeoutManager timeout_manager(&m_map, &clock);
OLA_ASSERT_FALSE(timeout_manager.EventsPending());
TimeInterval timeout_interval(1, 0);
timeout_id id1 = timeout_manager.RegisterSingleTimeout(
timeout_interval,
NewSingleCallback(this, &TimeoutManagerTest::HandleEvent, 1u));
OLA_ASSERT_NE(id1, ola::thread::INVALID_TIMEOUT);
TimeStamp last_checked_time;
clock.AdvanceTime(0, 1); // Small offset to work around timer precision
clock.CurrentTime(&last_checked_time);
TimeInterval next = timeout_manager.ExecuteTimeouts(&last_checked_time);
OLA_ASSERT_EQ(0u, GetEventCounter(1));
OLA_ASSERT_LT(next, timeout_interval);
clock.AdvanceTime(0, 500000);
clock.CurrentTime(&last_checked_time);
next = timeout_manager.ExecuteTimeouts(&last_checked_time);
OLA_ASSERT_EQ(0u, GetEventCounter(1));
OLA_ASSERT_LT(next, TimeInterval(0, 500000));
clock.AdvanceTime(0, 500000);
clock.CurrentTime(&last_checked_time);
next = timeout_manager.ExecuteTimeouts(&last_checked_time);
OLA_ASSERT_TRUE(next.IsZero());
OLA_ASSERT_EQ(1u, GetEventCounter(1));
OLA_ASSERT_FALSE(timeout_manager.EventsPending());
// now add another timeout and then remove it
timeout_id id2 = timeout_manager.RegisterSingleTimeout(
timeout_interval,
NewSingleCallback(this, &TimeoutManagerTest::HandleEvent, 2u));
OLA_ASSERT_NE(id2, ola::thread::INVALID_TIMEOUT);
OLA_ASSERT_TRUE(timeout_manager.EventsPending());
OLA_ASSERT_EQ(0u, GetEventCounter(2));
timeout_manager.CancelTimeout(id2);
clock.AdvanceTime(1, 0);
clock.CurrentTime(&last_checked_time);
next = timeout_manager.ExecuteTimeouts(&last_checked_time);
OLA_ASSERT_FALSE(timeout_manager.EventsPending());
OLA_ASSERT_EQ(0u, GetEventCounter(2));
}
示例2: testRepeatingTimeouts
/*
* Check RegisterRepeatingTimeout works.
*/
void TimeoutManagerTest::testRepeatingTimeouts() {
MockClock clock;
TimeoutManager timeout_manager(&m_map, &clock);
OLA_ASSERT_FALSE(timeout_manager.EventsPending());
TimeInterval timeout_interval(1, 0);
timeout_id id1 = timeout_manager.RegisterRepeatingTimeout(
timeout_interval,
NewCallback(this, &TimeoutManagerTest::HandleRepeatingEvent, 1u));
OLA_ASSERT_NE(id1, ola::thread::INVALID_TIMEOUT);
TimeStamp last_checked_time;
clock.AdvanceTime(0, 1); // Small offset to work around timer precision
clock.CurrentTime(&last_checked_time);
TimeInterval next = timeout_manager.ExecuteTimeouts(&last_checked_time);
OLA_ASSERT_EQ(0u, GetEventCounter(1));
OLA_ASSERT_LT(next, timeout_interval);
clock.AdvanceTime(0, 500000);
clock.CurrentTime(&last_checked_time);
next = timeout_manager.ExecuteTimeouts(&last_checked_time);
OLA_ASSERT_EQ(0u, GetEventCounter(1));
OLA_ASSERT_LT(next, TimeInterval(0, 500000));
clock.AdvanceTime(0, 500000);
clock.CurrentTime(&last_checked_time);
next = timeout_manager.ExecuteTimeouts(&last_checked_time);
OLA_ASSERT_LTE(next, timeout_interval);
OLA_ASSERT_EQ(1u, GetEventCounter(1));
OLA_ASSERT_TRUE(timeout_manager.EventsPending());
// fire the event again
clock.AdvanceTime(1, 0);
clock.CurrentTime(&last_checked_time);
next = timeout_manager.ExecuteTimeouts(&last_checked_time);
OLA_ASSERT_LTE(next, timeout_interval);
OLA_ASSERT_EQ(2u, GetEventCounter(1));
// cancel the event
timeout_manager.CancelTimeout(id1);
clock.AdvanceTime(1, 0);
clock.CurrentTime(&last_checked_time);
next = timeout_manager.ExecuteTimeouts(&last_checked_time);
OLA_ASSERT_TRUE(next.IsZero());
OLA_ASSERT_EQ(2u, GetEventCounter(1));
}