本文整理汇总了C++中EventBase::loopForever方法的典型用法代码示例。如果您正苦于以下问题:C++ EventBase::loopForever方法的具体用法?C++ EventBase::loopForever怎么用?C++ EventBase::loopForever使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EventBase
的用法示例。
在下文中一共展示了EventBase::loopForever方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cb
TEST(EventBaseTest, RunBeforeLoop) {
EventBase base;
CountedLoopCallback cb(&base, 1, [&](){
base.terminateLoopSoon();
});
base.runBeforeLoop(&cb);
base.loopForever();
ASSERT_EQ(cb.getCount(), 0);
}
示例2:
TEST(EventBaseTest, TryRunningAfterTerminate) {
EventBase eventBase;
CountedLoopCallback c1(&eventBase, 1,
std::bind(&EventBase::terminateLoopSoon, &eventBase));
eventBase.runInLoop(&c1);
eventBase.loopForever();
bool ran = false;
eventBase.runInEventBaseThread([&]() {
ran = true;
});
ASSERT_FALSE(ran);
}
示例3: TestData
TEST(RequestContext, SimpleTest) {
EventBase base;
// There should always be a default context with get()
EXPECT_TRUE(RequestContext::get() != nullptr);
// but not with saveContext()
EXPECT_EQ(RequestContext::saveContext(), nullptr);
RequestContext::create();
EXPECT_NE(RequestContext::saveContext(), nullptr);
RequestContext::create();
EXPECT_NE(RequestContext::saveContext(), nullptr);
EXPECT_EQ(nullptr, RequestContext::get()->getContextData("test"));
RequestContext::get()->setContextData(
"test",
std::unique_ptr<TestData>(new TestData(10)));
base.runInEventBaseThread([&](){
EXPECT_TRUE(RequestContext::get() != nullptr);
auto data = dynamic_cast<TestData*>(
RequestContext::get()->getContextData("test"))->data_;
EXPECT_EQ(10, data);
base.terminateLoopSoon();
});
auto th = std::thread([&](){
base.loopForever();
});
th.join();
EXPECT_TRUE(RequestContext::get() != nullptr);
auto a = dynamic_cast<TestData*>(
RequestContext::get()->getContextData("test"));
auto data = a->data_;
EXPECT_EQ(10, data);
RequestContext::setContext(std::shared_ptr<RequestContext>());
// There should always be a default context
EXPECT_TRUE(nullptr != RequestContext::get());
}