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


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

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


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

示例1:

TEST_F(DecoratorTest, VerifyDecoratorAwareness) {
  auto filter = [](const Decoration<0>& zero, const Decoration<1>& one) {};

  // Create a packet while the factory has no subscribers:
  AutoRequired<AutoPacketFactory> factory;
  auto packet1 = factory->NewPacket();

  // Verify subscription-free status:
  ASSERT_FALSE(packet1->HasSubscribers<Decoration<0>>()) << "Subscription exists where one should not have existed";

  // Create another packet where a subscriber exists:
  *factory += filter;
  auto packet2 = factory->NewPacket();

  // Verify the first packet still does not have subscriptions:
  ASSERT_THROW(packet1->GetSatisfaction<decltype(filter)>(), autowiring_error) << "Subscription was incorrectly, retroactively added to a packet";
  ASSERT_FALSE(packet1->HasSubscribers<Decoration<0>>()) << "Subscription was incorrectly, retroactively added to a packet";
  ASSERT_EQ(0UL, packet1->GetDecorationTypeCount()) << "Subscription was incorrectly, retroactively added to a packet";
  ASSERT_FALSE(packet1->HasSubscribers<Decoration<0>>()) << "Subscription was incorrectly, retroactively added to a packet";

  // Verify the second one does:
  ASSERT_NO_THROW(packet2->GetSatisfaction<decltype(filter)>()) << "Packet lacked an expected subscription";
  ASSERT_EQ(2UL, packet2->GetDecorationTypeCount()) << "Incorrect count of expected decorations";
  ASSERT_TRUE(packet2->HasSubscribers<Decoration<0>>()) << "Packet lacked an expected subscription";
}
开发者ID:c-zheng,项目名称:autowiring,代码行数:25,代码来源:DecoratorTest.cpp

示例2: AutoCurrentContext

TEST_F(AutoPacketFactoryTest, CanRemoveAddedLambda) {
  AutoCurrentContext()->Initiate();
  AutoRequired<AutoPacketFactory> factory;

  auto desc = *factory += [](int&){};
  auto packet1 = factory->NewPacket();
  *factory -= desc;
  auto packet2 = factory->NewPacket();

  ASSERT_TRUE(packet1->Has<int>()) << "First packet did not posess expected decoration";
  ASSERT_FALSE(packet2->Has<int>()) << "Decoration present even after all filters were removed from a factory";
}
开发者ID:,项目名称:,代码行数:12,代码来源:

示例3:

TEST_F(DecoratorTest, VerifySimplePacketDecoration) {
  AutoRequired<AutoPacketFactory> factory;

  // Create the packet we will be persisting:
  auto packet = factory->NewPacket();

  // Add a few decorations on this packet:
  auto& knownDec0 = packet->Decorate(Decoration<0>());
  auto& knownDec1 = packet->Decorate(Decoration<1>());
  auto& knownDec2 = packet->Decorate(Decoration<2>());

  // Verify we can get these packets back--might throw exceptions here!
  auto& dec0 = packet->Get<Decoration<0>>();
  auto& dec1 = packet->Get<Decoration<1>>();
  auto& dec2 = packet->Get<Decoration<2>>();

  // Verify identities:
  EXPECT_EQ(&knownDec0, &dec0) << "Decoration 0 returned at an incorrect location";
  EXPECT_EQ(&knownDec1, &dec1) << "Decoration 1 returned at an incorrect location";
  EXPECT_EQ(&knownDec2, &dec2) << "Decoration 2 returned at an incorrect location";

  // Verify content correctness:
  EXPECT_EQ(0, dec0.i) << "Decoration 0 incorrectly persisted";
  EXPECT_EQ(1, dec1.i) << "Decoration 1 incorrectly persisted";
  EXPECT_EQ(2, dec2.i) << "Decoration 2 incorrectly persisted";
}
开发者ID:jdiego,项目名称:autowiring,代码行数:26,代码来源:DecoratorTest.cpp

示例4: IssuesPacketWaitsThenQuits

 IssuesPacketWaitsThenQuits(void) {
   // Note:  Don't do this in practice.  This only works because we only inject this type
   // into a context that's already running; normally, creating a packet from our ctor can
   // cause an exception if we are being injected before Initiate is called.
   AutoRequired<AutoPacketFactory> factory;
   m_packet = factory->NewPacket();
 }
开发者ID:,项目名称:,代码行数:7,代码来源:

示例5:

TEST_F(AutoPacketFactoryTest, AddSubscriberTest) {
  AutoCurrentContext ctxt;
  AutoRequired<AutoPacketFactory> factory;
  ctxt->Initiate();

  bool first_called = false;
  bool second_called = false;

  factory->AddSubscriber(AutoFilterDescriptor([&first_called](int) {first_called = true; }));
  {
    std::vector<AutoFilterDescriptor> descs;
    factory->AppendAutoFiltersTo(descs);
    ASSERT_EQ(1UL, descs.size()) << "Expected exactly one AutoFilters after call to AddSubscriber";
  }

  *factory += [&second_called] (int v) {
    second_called = true;
    ASSERT_EQ(101, v) << "Decoration value mismatch";
  };
  {
    std::vector<AutoFilterDescriptor> descs;
    factory->AppendAutoFiltersTo(descs);
    ASSERT_EQ(2UL, descs.size()) << "Expected exactly two AutoFilters on this packet";
  }

  auto packet = factory->NewPacket();

  ASSERT_FALSE(first_called) << "Normal subscriber called too early";
  ASSERT_FALSE(second_called) << "Subscriber added with operator+= called too early";

  packet->DecorateImmediate(int(101));

  ASSERT_TRUE(first_called) << "Normal subscriber never called";
  ASSERT_TRUE(second_called) << "Subscriber added with operator+= never called";
}
开发者ID:,项目名称:,代码行数:35,代码来源:

示例6: pshr

TEST_F(AutoPacketFactoryTest, AutoPacketFactoryCycle) {
  AutoCurrentContext()->Initiate();

  std::weak_ptr<CoreContext> ctxtWeak;
  std::weak_ptr<HoldsAutoPacketFactoryReference> hapfrWeak;
  std::shared_ptr<AutoPacket> packet;

  {
    // Create a context, fill it up, kick it off:
    AutoCreateContext ctxt;
    CurrentContextPusher pshr(ctxt);
    AutoRequired<HoldsAutoPacketFactoryReference> hapfr(ctxt);
    ctxt->Initiate();

    // A weak pointer is used to detect object destruction
    ctxtWeak = ctxt;
    hapfrWeak = hapfr;

    // Trivial validation-of-reciept:
    AutoRequired<AutoPacketFactory> factory;
    {
      auto trivial = factory->NewPacket();
      trivial->Decorate((int) 54);
      ASSERT_EQ(54, hapfr->m_value) << "A simple packet was not received as expected by an AutoFilter";
    }

    // Create a packet which will force in a back-reference:
    packet = factory->NewPacket();

    // Terminate the context:
    ctxt->SignalShutdown();

    // Verify that we can still decorate the packet and also that the packet is delivered to the factory:
    packet->Decorate((int) 55);

    // Relock, verify the value was received by the hapfr:
    ASSERT_EQ(55, hapfr->m_value) << "AutoFilter did not receive a packet as expected";
  }

  // The context cannot go out of socpe until all packets in the context are out of scope
  ASSERT_FALSE(ctxtWeak.expired()) << "Context went out of scope before all packets were finished being processed";

  // Now we can release the packet and verify that everything gets cleaned up:
  packet.reset();
  ASSERT_TRUE(ctxtWeak.expired()) << "AutoPacketFactory incorrectly held a cyclic reference even after the context was shut down";
  ASSERT_TRUE(hapfrWeak.expired()) << "The last packet from a factory was released; this should have resulted in teardown, but it did not";
}
开发者ID:,项目名称:,代码行数:47,代码来源:


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