当前位置: 首页>>代码示例>>C++>>正文


C++ TimeInterval::IsZero方法代码示例

本文整理汇总了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));
}
开发者ID:DanielAeolusLaude,项目名称:ola,代码行数:53,代码来源:TimeoutManagerTest.cpp

示例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));
}
开发者ID:DanielAeolusLaude,项目名称:ola,代码行数:52,代码来源:TimeoutManagerTest.cpp


注:本文中的TimeInterval::IsZero方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。