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); }