コード例 #1
0
ファイル: BundleTest.cpp プロジェクト: SeNDA-UAB/aDTNPlus
/**
 * Check the constructor with parameters.
 * The primary block must contain the source and the destination.
 * The bundle must contain a payloadBlock with the payload value.
 */
TEST(BundleTest, FilledConstructor) {
  Bundle b = Bundle("source", "destination", "payload");
  ASSERT_EQ("source", b.getPrimaryBlock()->getSource());
  ASSERT_EQ("destination", b.getPrimaryBlock()->getDestination());
  ASSERT_EQ(static_cast<uint8_t>(2), b.getBlocks().size());
  ASSERT_EQ(static_cast<uint8_t>(CanonicalBlockTypes::PAYLOAD_BLOCK),
            b.getPayloadBlock()->getBlockType());
}
コード例 #2
0
ファイル: BundleTest.cpp プロジェクト: SeNDA-UAB/aDTNPlus
/**
 * Check the raw constructor.
 * Generate a bundle, convert it to raw, and generate a new bundle from that
 * raw.
 * The blocks must be the same.
 */
TEST(BundleTest, RawFunctions) {
  Bundle b = Bundle("Source", "Destination", "This is a payload");
  std::string raw = b.toRaw();
  Bundle b1 = Bundle(raw);
  ASSERT_EQ(b.getPrimaryBlock()->getSource(),
            b1.getPrimaryBlock()->getSource());
  ASSERT_EQ(b.getPrimaryBlock()->getDestination(),
            b1.getPrimaryBlock()->getDestination());
  ASSERT_EQ(b.getBlocks().size(), b1.getBlocks().size());
  ASSERT_EQ(
      std::static_pointer_cast<CanonicalBlock>(b.getBlocks()[1])->getBlockType(),
      std::static_pointer_cast<CanonicalBlock>(b1.getBlocks()[1])->getBlockType());
  std::shared_ptr<CanonicalBlock> PB = std::static_pointer_cast<CanonicalBlock>(
      b.getBlocks()[1]);
  std::shared_ptr<CanonicalBlock> PB1 =
      std::static_pointer_cast<CanonicalBlock>(b1.getBlocks()[1]);
  ASSERT_EQ(std::static_pointer_cast<PayloadBlock>(PB)->getPayload(),
            std::static_pointer_cast<PayloadBlock>(PB1)->getPayload());
}
コード例 #3
0
ファイル: BundleTest.cpp プロジェクト: SeNDA-UAB/aDTNPlus
/**
 * 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());
}