BIND 10 trac1803, updated. 6abb27b31deb6c5bbbe18a97bb7e0a719ee9a9ce [1903] Minor fix to the exception text
BIND 10 source code commits
bind10-changes at lists.isc.org
Mon May 7 09:11:42 UTC 2012
The branch, trac1803 has been updated
via 6abb27b31deb6c5bbbe18a97bb7e0a719ee9a9ce (commit)
via db211a922da7f6d72575cbb7112f6013babd4291 (commit)
from 768f28b23d6309f9916f4273222f8c187ba29faf (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 6abb27b31deb6c5bbbe18a97bb7e0a719ee9a9ce
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Mon May 7 11:11:09 2012 +0200
[1903] Minor fix to the exception text
It talked about the other method.
commit db211a922da7f6d72575cbb7112f6013babd4291
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Mon May 7 11:10:13 2012 +0200
[1903] More tests for previousNode
This time, we check it can start iterating if we search for something
that is not in the tree.
-----------------------------------------------------------------------
Summary of changes:
src/lib/datasrc/rbtree.h | 3 +-
src/lib/datasrc/tests/rbtree_unittest.cc | 123 ++++++++++++++++++++++++++---
2 files changed, 112 insertions(+), 14 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/datasrc/rbtree.h b/src/lib/datasrc/rbtree.h
index fe25bee..5e17ee6 100644
--- a/src/lib/datasrc/rbtree.h
+++ b/src/lib/datasrc/rbtree.h
@@ -1159,7 +1159,8 @@ template <typename T>
const RBNode<T>*
RBTree<T>::previousNode(RBTreeNodeChain<T>& node_path) const {
if (node_path.isEmpty()) {
- isc_throw(isc::BadValue, "RBTree::nextNode is given an empty chain");
+ isc_throw(isc::BadValue,
+ "RBTree::previousNode is given an empty chain");
}
const RBNode<T>* node(node_path.top());
diff --git a/src/lib/datasrc/tests/rbtree_unittest.cc b/src/lib/datasrc/tests/rbtree_unittest.cc
index 27f0d9a..1d5f3c2 100644
--- a/src/lib/datasrc/tests/rbtree_unittest.cc
+++ b/src/lib/datasrc/tests/rbtree_unittest.cc
@@ -367,8 +367,14 @@ TEST_F(RBTreeTest, nextNode) {
// Just walk until the beginning of the tree and check it is OK
void
previousWalk(RBTree<int>& rbtree, const RBNode<int>* node,
- RBTreeNodeChain<int>& node_path, size_t position)
+ RBTreeNodeChain<int>& node_path, size_t position, bool skipFirst)
{
+ if (skipFirst) {
+ // If the first is not found, this is supposed to be NULL and we skip
+ // it in our checks.
+ EXPECT_EQ(static_cast<void*>(NULL), node);
+ node = rbtree.previousNode(node_path);
+ }
for (size_t i(position); i > 0; --i) {
EXPECT_NE(static_cast<void*>(NULL), node);
EXPECT_EQ(Name(names[i - 1]), node_path.getAbsoluteName());
@@ -397,21 +403,112 @@ previousWalk(RBTree<int>& rbtree, const RBNode<int>* node,
TEST_F(RBTreeTest, previousNode) {
// First, iterate the whole tree from the end to the beginning.
RBTreeNodeChain<int> node_path;
+ EXPECT_THROW(rbtree.previousNode(node_path), isc::BadValue) <<
+ "Throw before a search was done on the path";
const RBNode<int>* node(NULL);
- EXPECT_EQ(RBTree<int>::EXACTMATCH,
- rbtree.find<void*>(Name(names[name_count - 1]), &node, node_path,
- NULL, NULL));
- previousWalk(rbtree, node, node_path, name_count);
- node_path.clear();
+ {
+ SCOPED_TRACE("Iterate through");
+ EXPECT_EQ(RBTree<int>::EXACTMATCH,
+ rbtree.find<void*>(Name(names[name_count - 1]), &node,
+ node_path, NULL, NULL));
+ previousWalk(rbtree, node, node_path, name_count, false);
+ node = NULL;
+ node_path.clear();
+ }
- // Now, start somewhere in the middle, but within the real node.
- EXPECT_EQ(RBTree<int>::EXACTMATCH,
- rbtree.find<void*>(Name(names[4]), &node, node_path,
- NULL, NULL));
- previousWalk(rbtree, node, node_path, 5);
- node_path.clear();
+ {
+ SCOPED_TRACE("Iterate from the middle");
+ // Now, start somewhere in the middle, but within the real node.
+ EXPECT_EQ(RBTree<int>::EXACTMATCH,
+ rbtree.find<void*>(Name(names[4]), &node, node_path,
+ NULL, NULL));
+ previousWalk(rbtree, node, node_path, 5, false);
+ node = NULL;
+ node_path.clear();
+ }
- // TODO: The tests where we start in between of the nodes somewhere
+ {
+ SCOPED_TRACE("Start at the first");
+ // If we start at the lowest (which is "a"), we get to the beginning
+ // right away.
+ EXPECT_EQ(RBTree<int>::EXACTMATCH,
+ rbtree.find<void*>(Name(names[0]), &node, node_path, NULL,
+ NULL));
+ EXPECT_NE(static_cast<void*>(NULL), node);
+ EXPECT_EQ(NULL, rbtree.previousNode(node_path));
+ node = NULL;
+ node_path.clear();
+ }
+
+ {
+ SCOPED_TRACE("Start before the first");
+ // If we start before the lowest (0 < a), we should not get a node nor
+ EXPECT_EQ(RBTree<int>::NOTFOUND,
+ rbtree.find<void*>(Name("0"), &node, node_path, NULL, NULL));
+ EXPECT_EQ(NULL, node);
+ EXPECT_EQ(NULL, rbtree.previousNode(node_path));
+ node = NULL;
+ node_path.clear();
+ }
+
+ {
+ SCOPED_TRACE("Start after the last");
+ EXPECT_EQ(RBTree<int>::NOTFOUND,
+ rbtree.find<void*>(Name("z"), &node, node_path, NULL, NULL));
+ previousWalk(rbtree, node, node_path, name_count, true);
+ node = NULL;
+ node_path.clear();
+ }
+
+ {
+ SCOPED_TRACE("Start to the right of a leaf");
+ // When searching for this, we exit the 'x' node to the right side,
+ // so we should go x afterwards.
+ EXPECT_EQ(RBTree<int>::PARTIALMATCH,
+ rbtree.find<void*>(Name("xy.d.e.f"), &node, node_path,
+ NULL, NULL));
+ previousWalk(rbtree, node, node_path, 5, true);
+ node = NULL;
+ node_path.clear();
+ }
+
+ {
+ SCOPED_TRACE("Start to the left of a leaf");
+ // This is similar to the previous, but we exit the 'z' leaf to the
+ // left side, so should not visit z at all then.
+ EXPECT_EQ(RBTree<int>::PARTIALMATCH,
+ rbtree.find<void*>(Name("yz.d.e.f"), &node, node_path,
+ NULL, NULL));
+ previousWalk(rbtree, node, node_path, 9, true);
+ node = NULL;
+ node_path.clear();
+ }
+
+ {
+ SCOPED_TRACE("Start inside a wrong node");
+ // The d.e.f is a single node, but we want only part of it. We
+ // should start iterating before it.
+ EXPECT_EQ(RBTree<int>::NOTFOUND,
+ rbtree.find<void*>(Name("e.f"), &node, node_path,
+ NULL, NULL));
+ previousWalk(rbtree, node, node_path, 3, true);
+ node = NULL;
+ node_path.clear();
+ }
+
+ {
+ SCOPED_TRACE("Lookup in empty tree");
+ // Just check it doesn't crash, etc.
+ RBTree<int> empty_tree;
+ EXPECT_EQ(RBTree<int>::NOTFOUND,
+ empty_tree.find<void*>(Name("x"), &node, node_path,
+ NULL, NULL));
+ EXPECT_EQ(static_cast<void*>(NULL), node);
+ EXPECT_EQ(static_cast<void*>(NULL),
+ empty_tree.previousNode(node_path));
+ node = NULL;
+ node_path.clear();
+ }
}
TEST_F(RBTreeTest, nextNodeError) {
More information about the bind10-changes
mailing list