Write a test case that we reject invalid magic numbers

This commit is contained in:
Sebastian Messmer 2014-12-09 18:56:45 +01:00
parent ec65b31c8e
commit 48cc8eeff0

View File

@ -61,3 +61,14 @@ TEST_F(DataNodeTest, InnerNodeIsRecognizedAfterStoreAndLoad) {
EXPECT_IS_PTR_TYPE(DataInnerNode, loaded_node.get()); EXPECT_IS_PTR_TYPE(DataInnerNode, loaded_node.get());
} }
TEST_F(DataNodeTest, DataNodeCrashesOnLoadIfMagicNumberIsWrong) {
auto block = blockStore->create(BlobStoreOnBlocks::BLOCKSIZE);
string key = block.key;
DataNode::NodeHeader* header = (DataNode::NodeHeader*)block.block->data();
header->magicNumber = 0xFF; // this is an invalid magic number
EXPECT_ANY_THROW(
DataNode::load(std::move(block.block))
);
}