Browse Source

[1971] Add another testcase for untested code detected by lcov

When find() returns COMMONANCESTOR and exits to the right of a
last_compared_node which has a valid down pointer, previousNode() has to
return nodes beginning at at the right-most leaf of subtrees in
last_compared_node->down.
Mukund Sivaraman 13 years ago
parent
commit
94a2da0d06
1 changed files with 22 additions and 0 deletions
  1. 22 0
      src/lib/datasrc/tests/rbtree_unittest.cc

+ 22 - 0
src/lib/datasrc/tests/rbtree_unittest.cc

@@ -511,6 +511,28 @@ TEST_F(RBTreeTest, previousNode) {
     }
     }
 
 
     {
     {
+        SCOPED_TRACE("Start to the right of a parent");
+        // When searching for this, we exit the 'g.h' node to the right
+        // side, so we should go to g.h's children afterwards.
+
+        // 'g.h' is an empty node, so we get a NOTFOUND and not
+        // PARTIALMATCH.
+        EXPECT_EQ(RBTree<int>::NOTFOUND,
+                  rbtree.find(Name("x.h"), &node, node_path));
+        // 'g.h' is the COMMONANCESTOR.
+        EXPECT_EQ(node_path.getLastComparedNode()->getName(), Name("g.h"));
+        EXPECT_EQ(NameComparisonResult::COMMONANCESTOR,
+                  node_path.getLastComparisonResult().getRelation());
+        // find() exits to the right of 'g.h'
+        EXPECT_GT(node_path.getLastComparisonResult().getOrder(), 0);
+        // We then descend into 'i.g.h' and walk all the nodes in the
+        // tree.
+        previousWalk(rbtree, node, node_path, name_count, true);
+        node = NULL;
+        node_path.clear();
+    }
+
+    {
         SCOPED_TRACE("Start inside a wrong node");
         SCOPED_TRACE("Start inside a wrong node");
         // The d.e.f is a single node, but we want only part of it. We
         // The d.e.f is a single node, but we want only part of it. We
         // should start iterating before it.
         // should start iterating before it.