diff --git a/test/implementations/onblocks/datatreestore/traverseLeaves/DataTreeTest_TraverseLeaves.cpp b/test/implementations/onblocks/datatreestore/traverseLeaves/DataTreeTest_TraverseLeaves.cpp index 2c8cdea3..9d937c27 100644 --- a/test/implementations/onblocks/datatreestore/traverseLeaves/DataTreeTest_TraverseLeaves.cpp +++ b/test/implementations/onblocks/datatreestore/traverseLeaves/DataTreeTest_TraverseLeaves.cpp @@ -20,6 +20,20 @@ MATCHER_P(KeyEq, expected, "node key equals") { class DataTreeTest_TraverseLeaves: public DataTreeTest { public: + void EXPECT_TRAVERSE_LEAF(const Key &key, uint32_t leafIndex) { + EXPECT_CALL(traversor, called(KeyEq(key), leafIndex)).Times(1); + } + + void EXPECT_TRAVERSE_ALL_CHILDREN_OF(const DataInnerNode &node, uint32_t firstLeafIndex) { + for (int i = 0; i < node.numChildren(); ++i) { + EXPECT_TRAVERSE_LEAF(node.getChild(i)->key(), firstLeafIndex+i); + } + } + + void EXPECT_DONT_TRAVERSE_ANY_LEAVES() { + EXPECT_CALL(traversor, called(_, _)).Times(0); + } + void TraverseLeaves(DataNode *root, uint32_t beginIndex, uint32_t endIndex) { root->flush(); auto tree = treeStore.load(root->key()); @@ -32,117 +46,99 @@ public: TEST_F(DataTreeTest_TraverseLeaves, TraverseSingleLeafTree) { auto root = CreateLeaf(); - EXPECT_CALL(traversor, called(KeyEq(root->key()), 0)).Times(1); + EXPECT_TRAVERSE_LEAF(root->key(), 0); TraverseLeaves(root.get(), 0, 1); } TEST_F(DataTreeTest_TraverseLeaves, TraverseNothingInSingleLeafTree1) { auto root = CreateLeaf(); - EXPECT_CALL(traversor, called(_, _)).Times(0); + EXPECT_DONT_TRAVERSE_ANY_LEAVES(); TraverseLeaves(root.get(), 0, 0); } TEST_F(DataTreeTest_TraverseLeaves, TraverseNothingInSingleLeafTree2) { auto root = CreateLeaf(); - EXPECT_CALL(traversor, called(_, _)).Times(0); + EXPECT_DONT_TRAVERSE_ANY_LEAVES(); TraverseLeaves(root.get(), 1, 1); } TEST_F(DataTreeTest_TraverseLeaves, TraverseFirstLeafOfFullTwolevelTree) { auto root = CreateFullTwoLevel(); - auto firstleafkey = root->getChild(0)->key(); - EXPECT_CALL(traversor, called(KeyEq(firstleafkey), 0)).Times(1); + EXPECT_TRAVERSE_LEAF(root->getChild(0)->key(), 0); TraverseLeaves(root.get(), 0, 1); } TEST_F(DataTreeTest_TraverseLeaves, TraverseMiddleLeafOfFullTwolevelTree) { auto root = CreateFullTwoLevel(); - auto leafkey = root->getChild(5)->key(); - EXPECT_CALL(traversor, called(KeyEq(leafkey), 5)).Times(1); + EXPECT_TRAVERSE_LEAF(root->getChild(5)->key(), 5); TraverseLeaves(root.get(), 5, 6); } TEST_F(DataTreeTest_TraverseLeaves, TraverseLastLeafOfFullTwolevelTree) { auto root = CreateFullTwoLevel(); - auto leafkey = root->getChild(DataInnerNode::MAX_STORED_CHILDREN-1)->key(); - EXPECT_CALL(traversor, called(KeyEq(leafkey), DataInnerNode::MAX_STORED_CHILDREN-1)).Times(1); + EXPECT_TRAVERSE_LEAF(root->getChild(DataInnerNode::MAX_STORED_CHILDREN-1)->key(), DataInnerNode::MAX_STORED_CHILDREN-1); TraverseLeaves(root.get(), DataInnerNode::MAX_STORED_CHILDREN-1, DataInnerNode::MAX_STORED_CHILDREN); } TEST_F(DataTreeTest_TraverseLeaves, TraverseNothingInFullTwolevelTree1) { auto root = CreateFullTwoLevel(); - EXPECT_CALL(traversor, called(_, _)).Times(0); + EXPECT_DONT_TRAVERSE_ANY_LEAVES(); TraverseLeaves(root.get(), 0, 0); } TEST_F(DataTreeTest_TraverseLeaves, TraverseNothingInFullTwolevelTree2) { auto root = CreateFullTwoLevel(); - EXPECT_CALL(traversor,called(_, _)).Times(0); + EXPECT_DONT_TRAVERSE_ANY_LEAVES(); TraverseLeaves(root.get(), DataInnerNode::MAX_STORED_CHILDREN, DataInnerNode::MAX_STORED_CHILDREN); } TEST_F(DataTreeTest_TraverseLeaves, TraverseFirstLeafOfThreeLevelMinDataTree) { auto root = CreateThreeLevelMinData(); - auto firstleafkey = LoadInnerNode(root->getChild(0)->key())->getChild(0)->key(); - EXPECT_CALL(traversor, called(KeyEq(firstleafkey), 0)).Times(1); + EXPECT_TRAVERSE_LEAF(LoadInnerNode(root->getChild(0)->key())->getChild(0)->key(), 0); TraverseLeaves(root.get(), 0, 1); } TEST_F(DataTreeTest_TraverseLeaves, TraverseMiddleLeafOfThreeLevelMinDataTree) { auto root = CreateThreeLevelMinData(); - auto leafkey = LoadInnerNode(root->getChild(0)->key())->getChild(5)->key(); - EXPECT_CALL(traversor, called(KeyEq(leafkey), 5)).Times(1); + EXPECT_TRAVERSE_LEAF(LoadInnerNode(root->getChild(0)->key())->getChild(5)->key(), 5); TraverseLeaves(root.get(), 5, 6); } TEST_F(DataTreeTest_TraverseLeaves, TraverseLastLeafOfThreeLevelMinDataTree) { auto root = CreateThreeLevelMinData(); - auto leafkey = LoadInnerNode(root->getChild(1)->key())->getChild(0)->key(); - EXPECT_CALL(traversor, called(KeyEq(leafkey), DataInnerNode::MAX_STORED_CHILDREN)).Times(1); + EXPECT_TRAVERSE_LEAF(LoadInnerNode(root->getChild(1)->key())->getChild(0)->key(), DataInnerNode::MAX_STORED_CHILDREN); TraverseLeaves(root.get(), DataInnerNode::MAX_STORED_CHILDREN, DataInnerNode::MAX_STORED_CHILDREN+1); } TEST_F(DataTreeTest_TraverseLeaves, TraverseAllLeavesOfFullTwolevelTree) { auto root = CreateFullTwoLevel(); - for (int i = 0; i < DataInnerNode::MAX_STORED_CHILDREN; ++i) { - auto leafkey = root->getChild(i)->key(); - EXPECT_CALL(traversor, called(KeyEq(leafkey), i)).Times(1); - } + EXPECT_TRAVERSE_ALL_CHILDREN_OF(*root, 0); TraverseLeaves(root.get(), 0, DataInnerNode::MAX_STORED_CHILDREN); } TEST_F(DataTreeTest_TraverseLeaves, TraverseAllLeavesOfThreelevelMinDataTree) { auto root = CreateThreeLevelMinData(); - auto node = LoadInnerNode(root->getChild(0)->key()); - for (int i = 0; i < DataInnerNode::MAX_STORED_CHILDREN; ++i) { - auto leafkey = node->getChild(i)->key(); - EXPECT_CALL(traversor, called(KeyEq(leafkey), i)).Times(1); - } - Key lastleafkey = LoadInnerNode(root->getChild(1)->key())->getChild(0)->key(); - EXPECT_CALL(traversor, called(KeyEq(lastleafkey), DataInnerNode::MAX_STORED_CHILDREN)).Times(1); + EXPECT_TRAVERSE_ALL_CHILDREN_OF(*LoadInnerNode(root->getChild(0)->key()), 0); + EXPECT_TRAVERSE_LEAF(LoadInnerNode(root->getChild(1)->key())->getChild(0)->key(), DataInnerNode::MAX_STORED_CHILDREN); TraverseLeaves(root.get(), 0, DataInnerNode::MAX_STORED_CHILDREN+1); } TEST_F(DataTreeTest_TraverseLeaves, TraverseFirstChildOfThreelevelMinDataTree) { auto root = CreateThreeLevelMinData(); - auto node = LoadInnerNode(root->getChild(0)->key()); - for (int i = 0; i < DataInnerNode::MAX_STORED_CHILDREN; ++i) { - auto leafkey = node->getChild(i)->key(); - EXPECT_CALL(traversor, called(KeyEq(leafkey), i)).Times(1); - } + EXPECT_TRAVERSE_ALL_CHILDREN_OF(*LoadInnerNode(root->getChild(0)->key()), 0); TraverseLeaves(root.get(), 0, DataInnerNode::MAX_STORED_CHILDREN); } @@ -151,8 +147,7 @@ TEST_F(DataTreeTest_TraverseLeaves, TraverseFirstPartOfThreelevelMinDataTree) { auto root = CreateThreeLevelMinData(); auto node = LoadInnerNode(root->getChild(0)->key()); for (int i = 0; i < 5; ++i) { - auto leafkey = node->getChild(i)->key(); - EXPECT_CALL(traversor, called(KeyEq(leafkey), i)).Times(1); + EXPECT_TRAVERSE_LEAF(node->getChild(i)->key(), i); } TraverseLeaves(root.get(), 0, 5); @@ -162,8 +157,7 @@ TEST_F(DataTreeTest_TraverseLeaves, TraverseInnerPartOfThreelevelMinDataTree) { auto root = CreateThreeLevelMinData(); auto node = LoadInnerNode(root->getChild(0)->key()); for (int i = 5; i < 10; ++i) { - auto leafkey = node->getChild(i)->key(); - EXPECT_CALL(traversor, called(KeyEq(leafkey), i)).Times(1); + EXPECT_TRAVERSE_LEAF(node->getChild(i)->key(), i); } TraverseLeaves(root.get(), 5, 10); @@ -173,11 +167,9 @@ TEST_F(DataTreeTest_TraverseLeaves, TraverseLastPartOfThreelevelMinDataTree) { auto root = CreateThreeLevelMinData(); auto node = LoadInnerNode(root->getChild(0)->key()); for (int i = 5; i < DataInnerNode::MAX_STORED_CHILDREN; ++i) { - auto leafkey = node->getChild(i)->key(); - EXPECT_CALL(traversor, called(KeyEq(leafkey), i)).Times(1); + EXPECT_TRAVERSE_LEAF(node->getChild(i)->key(), i); } - Key lastleafkey = LoadInnerNode(root->getChild(1)->key())->getChild(0)->key(); - EXPECT_CALL(traversor, called(KeyEq(lastleafkey), DataInnerNode::MAX_STORED_CHILDREN)).Times(1); + EXPECT_TRAVERSE_LEAF(LoadInnerNode(root->getChild(1)->key())->getChild(0)->key(), DataInnerNode::MAX_STORED_CHILDREN); TraverseLeaves(root.get(), 5, DataInnerNode::MAX_STORED_CHILDREN+1); }