Add testcases to DataLeafNodeTest

This commit is contained in:
Sebastian Messmer 2014-12-13 17:58:11 +01:00
parent 059629cd8a
commit 517ed6929d
3 changed files with 18 additions and 5 deletions

View File

@ -34,14 +34,14 @@ unique_ptr<DataNode> DataNodeStore::load(unique_ptr<Block> block, const Key &key
} }
} }
unique_ptr<DataNode> DataNodeStore::createNewInnerNode(const DataNode &first_child) { unique_ptr<DataInnerNode> DataNodeStore::createNewInnerNode(const DataNode &first_child) {
auto block = _blockstore->create(DataNodeView::BLOCKSIZE_BYTES); auto block = _blockstore->create(DataNodeView::BLOCKSIZE_BYTES);
auto newNode = make_unique<DataInnerNode>(std::move(block.block), block.key, this); auto newNode = make_unique<DataInnerNode>(std::move(block.block), block.key, this);
newNode->InitializeNewNode(first_child); newNode->InitializeNewNode(first_child);
return std::move(newNode); return std::move(newNode);
} }
unique_ptr<DataNode> DataNodeStore::createNewLeafNode() { unique_ptr<DataLeafNode> DataNodeStore::createNewLeafNode() {
auto block = _blockstore->create(DataNodeView::BLOCKSIZE_BYTES); auto block = _blockstore->create(DataNodeView::BLOCKSIZE_BYTES);
auto newNode = make_unique<DataLeafNode>(std::move(block.block), block.key, this); auto newNode = make_unique<DataLeafNode>(std::move(block.block), block.key, this);
newNode->InitializeNewNode(); newNode->InitializeNewNode();

View File

@ -14,6 +14,8 @@ class Key;
namespace blobstore { namespace blobstore {
namespace onblocks { namespace onblocks {
class DataNode; class DataNode;
class DataLeafNode;
class DataInnerNode;
class DataNodeStore { class DataNodeStore {
public: public:
@ -25,8 +27,8 @@ public:
std::unique_ptr<DataNode> load(const blockstore::Key &key); std::unique_ptr<DataNode> load(const blockstore::Key &key);
std::unique_ptr<const DataNode> load(const blockstore::Key &key) const; std::unique_ptr<const DataNode> load(const blockstore::Key &key) const;
std::unique_ptr<DataNode> createNewLeafNode(); std::unique_ptr<DataLeafNode> createNewLeafNode();
std::unique_ptr<DataNode> createNewInnerNode(const DataNode &first_child); std::unique_ptr<DataInnerNode> createNewInnerNode(const DataNode &first_child);
private: private:
std::unique_ptr<DataNode> load(std::unique_ptr<blockstore::Block> block, const blockstore::Key &key); std::unique_ptr<DataNode> load(std::unique_ptr<blockstore::Block> block, const blockstore::Key &key);

View File

@ -70,9 +70,20 @@ public:
unique_ptr<BlockStore> _blockStore; unique_ptr<BlockStore> _blockStore;
BlockStore *blockStore; BlockStore *blockStore;
unique_ptr<DataNodeStore> nodeStore; unique_ptr<DataNodeStore> nodeStore;
unique_ptr<DataNode> leaf; unique_ptr<DataLeafNode> leaf;
}; };
TEST_F(DataLeafNodeTest, InitializesCorrectly) {
leaf->InitializeNewNode();
EXPECT_EQ(0u, leaf->numBytesInThisNode());
}
TEST_F(DataLeafNodeTest, ReinitializesCorrectly) {
leaf->resize(5);
leaf->InitializeNewNode();
EXPECT_EQ(0u, leaf->numBytesInThisNode());
}
TEST_F(DataLeafNodeTest, ReadWrittenDataImmediately) { TEST_F(DataLeafNodeTest, ReadWrittenDataImmediately) {
leaf->resize(randomData.size()); leaf->resize(randomData.size());
leaf->write(0, randomData.size(), randomData); leaf->write(0, randomData.size(), randomData);