From 6b32d1f37d7206b3841ccf4b4691cfaa8c824c77 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Fri, 25 Sep 2015 03:57:29 +0200 Subject: [PATCH] fix inconsistency in conception of HierarchyOrientationIndicator while it's still not really clear how we'll use this helper and if we need it at all -- some weeks ago I changed its semantics to be strictly based on the delta to a reference level. Now this means, we could go below level zero, but this doesn't make any sense in the context of navigating a tree. Actually, our test case triggered this situation, which caused the reference level to wrap around, since it is stored in an unsigned variable. Thus I'll add a precondition to keep the level positive, and I'll change the test to comply. --- src/lib/hierarchy-orientation-indicator.hpp | 2 ++ .../hierarchy-orientation-indicator-test.cpp | 29 +++++++------------ 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src/lib/hierarchy-orientation-indicator.hpp b/src/lib/hierarchy-orientation-indicator.hpp index 1ba39e3fc..82e22d1c3 100644 --- a/src/lib/hierarchy-orientation-indicator.hpp +++ b/src/lib/hierarchy-orientation-indicator.hpp @@ -85,6 +85,8 @@ namespace lib { OrientationIndicator& markRefLevel () { + REQUIRE (0 < ptrdiff_t(refLevel_) + offset_); + markRefLevel (refLevel_ + offset_); ENSURE (offset_ == 0); return *this; diff --git a/tests/library/hierarchy-orientation-indicator-test.cpp b/tests/library/hierarchy-orientation-indicator-test.cpp index e242c777c..76cae0cac 100644 --- a/tests/library/hierarchy-orientation-indicator-test.cpp +++ b/tests/library/hierarchy-orientation-indicator-test.cpp @@ -372,17 +372,17 @@ namespace test { OrientationIndicator orient; CHECK (0 == orient); - ++orient; - CHECK (+1 == orient); - ----orient; - CHECK (-1 == orient); + ++++orient; + CHECK (+2 == orient); orient.markRefLevel(); CHECK ( 0 == orient); + --orient; + CHECK (-1 == orient); - orient.markRefLevel (2); + orient.markRefLevel (4); CHECK (-3 == orient); - orient.markRefLevel (2); + orient.markRefLevel (4); CHECK (-3 == orient); orient -= orient; @@ -390,25 +390,16 @@ namespace test { ++orient; CHECK (+1 == orient); - orient.markRefLevel(); - - orient.markRefLevel (4); - orient.markRefLevel (5); - CHECK (-2 == orient); - - orient.markRefLevel (2); - CHECK (+1 == orient); - orient.resetToRef(); - ++orient; - orient.markRefLevel(); // now at level == 3 - CHECK ( 0 == orient); + orient.resetToRef(); // now at level == 4 + orient.markRefLevel (7); + CHECK (-3 == orient); orient += 200; orient -= 190; CHECK (+7 == orient); OrientationIndicator o2(orient); - o2.markRefLevel(12); + o2.markRefLevel(16); CHECK (-2 == o2); CHECK (+7 == orient); }