diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-09-30 18:03:17 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-09-30 18:03:17 +0200 |
| commit | 3a0f05541cc619128ee35a75921d7a53e01755ca (patch) | |
| tree | 16f9dbfa43bbe9f5debbdbca043f3a50bb81a149 | |
| parent | fe342f77c1183ee7ef14f909005351dcdef3f162 (diff) | |
| download | kernel-3a0f05541cc619128ee35a75921d7a53e01755ca.tar.xz kernel-3a0f05541cc619128ee35a75921d7a53e01755ca.zip | |
kstd: ring_buffer: add interface type tests
| -rw-r--r-- | libs/kstd/kstd/ring_buffer.tests.cpp | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/libs/kstd/kstd/ring_buffer.tests.cpp b/libs/kstd/kstd/ring_buffer.tests.cpp index bf1ae2a0..f0be78a1 100644 --- a/libs/kstd/kstd/ring_buffer.tests.cpp +++ b/libs/kstd/kstd/ring_buffer.tests.cpp @@ -6,6 +6,88 @@ #include <catch2/matchers/catch_matchers.hpp> #include <catch2/matchers/catch_matchers_exception.hpp> +#include <cstddef> +#include <type_traits> +#include <utility> + +SCENARIO("Ring Buffer interface types", "[kstd][ring_buffer]") +{ + GIVEN("A ring buffer of float") + { + using buffer = kstd::ring_buffer<float, 100>; + + THEN("value_type is 'float'") + { + STATIC_REQUIRE(std::is_same_v<float, buffer::value_type>); + } + + THEN("reference is 'float &'") + { + STATIC_REQUIRE(std::is_same_v<float &, buffer::reference>); + } + + THEN("const_reference is 'float const &'") + { + STATIC_REQUIRE(std::is_same_v<float const &, buffer::const_reference>); + } + + THEN("pointer is 'float *'") + { + STATIC_REQUIRE(std::is_same_v<float *, buffer::pointer>); + } + + THEN("size_type is 'std::size_t'") + { + STATIC_REQUIRE(std::is_same_v<std::size_t, buffer::size_type>); + } + + THEN("const_pointer is 'float const *'") + { + STATIC_REQUIRE(std::is_same_v<float const *, buffer::const_pointer>); + } + + THEN("the return type of at() is 'reference' on a non-const buffer") + { + STATIC_REQUIRE(std::is_same_v<buffer::reference, decltype(std::declval<buffer &>().at(0))>); + } + + THEN("the return type of at() is 'const_reference' on a non-const buffer") + { + STATIC_REQUIRE(std::is_same_v<buffer::const_reference, decltype(std::declval<buffer const &>().at(0))>); + } + + THEN("the return type of operator[] is 'reference' on a non-const buffer") + { + STATIC_REQUIRE(std::is_same_v<buffer::reference, decltype(std::declval<buffer &>()[0])>); + } + + THEN("the return type of operator[] is 'const_reference' on a non-const buffer") + { + STATIC_REQUIRE(std::is_same_v<buffer::const_reference, decltype(std::declval<buffer const &>()[0])>); + } + + THEN("the return type of capacity() is `size_type`") + { + STATIC_REQUIRE(std::is_same_v<buffer::size_type, decltype(std::declval<buffer &>().capacity())>); + } + + THEN("the return type of empty() is `bool`") + { + STATIC_REQUIRE(std::is_same_v<bool, decltype(std::declval<buffer &>().empty())>); + } + + THEN("the return type of size() is `size_type`") + { + STATIC_REQUIRE(std::is_same_v<buffer::size_type, decltype(std::declval<buffer &>().size())>); + } + + THEN("the return type of max_size() is `size_type`") + { + STATIC_REQUIRE(std::is_same_v<buffer::size_type, decltype(std::declval<buffer &>().max_size())>); + } + } +} + SCENARIO("Ring Buffer initialization and construction", "[ring_buffer]") { GIVEN("An empty context") |
