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


C++ AutoRequired::Clear方法代码示例

本文整理汇总了C++中AutoRequired::Clear方法的典型用法代码示例。如果您正苦于以下问题:C++ AutoRequired::Clear方法的具体用法?C++ AutoRequired::Clear怎么用?C++ AutoRequired::Clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AutoRequired的用法示例。


在下文中一共展示了AutoRequired::Clear方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: pusher

TEST_F(ContextCreatorTest, ClearAndTeardown) {
  // Create a context and verify it gets evicted from the context creator:

  std::weak_ptr<CoreContext> ctxtWeak;

  {
    AutoCreateContext mainContext;
    CurrentContextPusher pusher(mainContext);

    AutoRequired<Creator> creator;
    std::shared_ptr<CoreContext> ctxt;

    // Make a sub-context
    ctxt = creator->CreateContext(0).first;

    // Obtain a weak pointer, in order to ensure proper teardown:
    ctxtWeak = ctxt;

    //Call clear on the creator.
    creator->Clear(true);

    //Make another one!
    ctxt = creator->CreateContext(1).first;
    //Let the creator go out of scope
  }

  // Context must be destroyed as a precondition of the subsequent assertion
  ASSERT_TRUE(ctxtWeak.expired()) << "Expected the context to be destroyed";

  // Verify that our creator is now empty:
 // ASSERT_EQ(0UL, creator->GetSize()) << "Context creator is non-empty after all created contexts were destroyed";
}
开发者ID:c-zheng,项目名称:autowiring,代码行数:32,代码来源:ContextCreatorTest.cpp

示例2:

TEST_F(ContextCreatorTest, VoidKeyType) {
  AutoRequired<VoidCreator> vc;

  {
    std::shared_ptr<CoreContext> ctxt = vc->CreateContext();
    ASSERT_EQ(1UL, vc->GetSize()) << "Requested that a context be created, but the void creator did not have any members";

    ASSERT_EQ(1UL, vc->GetSize()) << "A created context was apparently destroyed after firing bolts";
    ASSERT_EQ(0UL, vc->m_totalDestroyed) << "The void creator received a NotifyContextDestroyed call unexpectedly early";

    vc->Clear(true);

    //Make another one to check about collisions
    std::shared_ptr<CoreContext> ctxt2 = vc->CreateContext();
    ASSERT_EQ(1UL, vc->GetSize()) << "Second void context creation failed!";
  }

  ASSERT_EQ(0UL, vc->GetSize()) << "A void context creator was not correctly updated when its dependent context went out of scope";
  ASSERT_EQ(2UL, vc->m_totalDestroyed) << "The void creator did not receive the expected number of NotifyContextDestroyed calls";
}
开发者ID:c-zheng,项目名称:autowiring,代码行数:20,代码来源:ContextCreatorTest.cpp


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