diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-10-02 15:47:50 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-10-02 15:47:50 +0200 |
| commit | bf59e881f3d4069d01e1dfad7c2cd8db54975763 (patch) | |
| tree | 74de9088dee8f04c5d398585f3a0d4cec01c4e2b | |
| parent | da509fa854178842433739dc03f862ab9d5a4682 (diff) | |
| download | kernel-bf59e881f3d4069d01e1dfad7c2cd8db54975763.tar.xz kernel-bf59e881f3d4069d01e1dfad7c2cd8db54975763.zip | |
kstd: ring_buffer: add more iterator tests
| -rw-r--r-- | libs/kstd/kstd/ring_buffer.tests.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/libs/kstd/kstd/ring_buffer.tests.cpp b/libs/kstd/kstd/ring_buffer.tests.cpp index 12a88e8f..99dbe3eb 100644 --- a/libs/kstd/kstd/ring_buffer.tests.cpp +++ b/libs/kstd/kstd/ring_buffer.tests.cpp @@ -1047,6 +1047,70 @@ SCENARIO("Ring Buffer iterators", "[kstd][ring_buffer]") REQUIRE(it == buffer.crend()); } + + THEN("a const_iterator can be constructed from an iterator") + { + auto it = decltype(buffer)::const_iterator{buffer.begin()}; + + AND_THEN("the const_iterator points to the same element as the original iterator") + { + REQUIRE(*it == *buffer.begin()); + } + } + + THEN("two iterators constructed from begin() and cbegin() compare equal") + { + auto it = buffer.begin(); + auto cit = buffer.cbegin(); + + REQUIRE(it == cit); + } + + THEN("an iterator to the second element compares greater than begin()") + { + REQUIRE(++buffer.begin() > buffer.begin()); + } + + THEN("an iterator to the second element compares less than the iterator to the third element") + { + REQUIRE(++buffer.begin() < std::next(buffer.begin(), 2)); + } + + THEN("the adding 1 to the iterator returned by begin() yields an iterator to the second element") + { + REQUIRE((buffer.begin() + 1) == ++buffer.begin()); + REQUIRE((1 + buffer.begin()) == ++buffer.begin()); + } + + THEN("subtracting 1 from the iterator returned by the second element yields an iterator to the first element") + { + REQUIRE(((buffer.begin() + 1) - 1) == buffer.begin()); + } + + THEN("postfix incrementing the iterator returned by begin() yields an iterator to the first element") + { + REQUIRE(buffer.begin()++ == buffer.begin()); + } + + THEN("postfix decrementing the iterator one after begin() yields an iterator to the first element") + { + REQUIRE((buffer.begin() + 1)-- == (buffer.begin() + 1)); + } + + THEN("accessing an element by subscripting the iterator yields the correct element") + { + auto it = buffer.begin(); + REQUIRE(std::addressof(it[0]) == std::addressof(buffer.at(0))); + REQUIRE(std::addressof(it[1]) == std::addressof(buffer.at(1))); + REQUIRE(std::addressof(it[2]) == std::addressof(buffer.at(2))); + } + + THEN("access to an element via member-of-pointer yields the correct element") + { + auto it = buffer.begin(); + REQUIRE(it.operator->() == std::addressof(buffer.at(0))); + } + WHEN("working through a const reference") { auto const & ref = buffer; |
