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


C++ Bundle::addBlock方法代码示例

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


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

示例1: CanonicalBlock

/**
 * Check the raw functions when a canonical block is added.
 * Generate a bundle, add a valid canonical block, convert all to raw.
 * Create a new bundle from that raw, check that all the blocks are correct.
 */
TEST(BundleTest, ConstructorWithCanonical) {
  Bundle b = Bundle("Source", "Destination", "This is a payload");
  std::stringstream ss;
  // Block Type
  ss << static_cast<uint8_t>(2) << SDNV::encode(std::bitset<7>().to_ulong());
  std::string data = std::to_string(rand() + 1);
  ss << SDNV::encode(data.size()) << data;
  std::shared_ptr<CanonicalBlock> cb = std::shared_ptr<CanonicalBlock>(
      new CanonicalBlock(ss.str()));
  ASSERT_EQ(ss.str(), cb->toRaw());
  b.addBlock(cb);
  ASSERT_EQ(static_cast<uint8_t>(3), b.getBlocks().size());
  std::string raw = b.toRaw();
  Bundle b1 = Bundle(raw);
  ASSERT_EQ(b.getBlocks().size(), b1.getBlocks().size());
  std::shared_ptr<CanonicalBlock> cb1 =
      std::static_pointer_cast<CanonicalBlock>(b1.getBlocks()[2]);
  ASSERT_EQ(cb->toRaw(), cb1->toRaw());
  ASSERT_EQ(cb->getBlockType(), cb1->getBlockType());
}
开发者ID:SeNDA-UAB,项目名称:aDTNPlus,代码行数:25,代码来源:BundleTest.cpp

示例2: FrameworkExtension

TEST(BundleTest, GetFrameworkExtension) {
  Bundle b = Bundle("Source", "Destination", "This is a payload");

  uint8_t fwkId = 1;
  std::map<uint8_t, std::shared_ptr<FrameworkExtension>> extensions;
  nlohmann::json state = {"source", "me"};

  uint8_t fwkExtId = 2;
  std::string code = "code";
  std::shared_ptr<FrameworkExtension> ext =
  std::shared_ptr<FrameworkExtension>(
      new FrameworkExtension(fwkExtId, code));

  extensions.insert(std::pair<uint8_t, std::shared_ptr<FrameworkExtension>>
                    (fwkExtId, ext));
  std::shared_ptr<FrameworkMEB> fmeb =
      std::shared_ptr<FrameworkMEB>(new FrameworkMEB(fwkId, extensions, state));
  b.addBlock(fmeb);

  std::shared_ptr<FrameworkExtension> fe = b.getFwkExt(fwkId, fwkExtId);
  ASSERT_EQ(fe->getCodeLength(), static_cast<uint16_t>(code.length()));
  ASSERT_EQ(fe->getFwkExtId(), fwkExtId);
  ASSERT_EQ(fe->getSwSrcCode(), code);

  Bundle b2 = Bundle("Source", "Destination", "This is a payload");

  ASSERT_THROW(b2.getFwkExt(fwkId, fwkExtId), FrameworkNotFoundException);

  b2.addBlock(fmeb);
  uint8_t fwkId2 = 3;
  uint8_t fwkExtId2 = 4;

  ASSERT_THROW(b2.getFwkExt(fwkId, fwkExtId2), FrameworkNotFoundException);
  ASSERT_THROW(b2.getFwkExt(fwkId2, fwkExtId), FrameworkNotFoundException);
  ASSERT_THROW(b2.getFwkExt(fwkId2, fwkExtId2), FrameworkNotFoundException);
}
开发者ID:SeNDA-UAB,项目名称:aDTNPlus,代码行数:36,代码来源:BundleTest.cpp

示例3: PayloadBlock

/**
 * Check an exception throw when a second payload is inserted.
 */
TEST(BundleTest, ConstructorWithTwoPayload) {
  Bundle b = Bundle("Source", "Destination", "This is a payload");
  std::shared_ptr<CanonicalBlock> payload = std::shared_ptr<CanonicalBlock>(
      new PayloadBlock("This is a new payload", false));
  ASSERT_THROW(b.addBlock(payload), BundleException);
}
开发者ID:SeNDA-UAB,项目名称:aDTNPlus,代码行数:9,代码来源:BundleTest.cpp


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