/** * 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()); }
/** * Check that a bundle id is correctly generated. * Bundle id format: * <Source><CreationTimestamp><TimestampSeqNumber> */ TEST(BundleTest, BundleId) { Bundle b = Bundle("Source", "Destination", "This is a payload"); std::stringstream ss; ss << b.getPrimaryBlock()->getSource() << "_" << b.getPrimaryBlock()->getCreationTimestamp() << "_" << b.getPrimaryBlock()->getCreationTimestampSeqNumber(); ASSERT_EQ(ss.str(), b.getId()); }
/** * 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()); }