diff --git a/tests/unit/hal/CMakeLists.txt b/tests/unit/hal/CMakeLists.txt index 792d600..ce3c840 100644 --- a/tests/unit/hal/CMakeLists.txt +++ b/tests/unit/hal/CMakeLists.txt @@ -1 +1 @@ -# +add_subdirectory(circular_buffer) diff --git a/tests/unit/hal/circular_buffer/CMakeLists.txt b/tests/unit/hal/circular_buffer/CMakeLists.txt new file mode 100644 index 0000000..728d78c --- /dev/null +++ b/tests/unit/hal/circular_buffer/CMakeLists.txt @@ -0,0 +1,8 @@ +# define the test executable +add_executable(circular_buffer_tests test_circular_buffer.cpp) + +# define required search paths +target_include_directories(circular_buffer_tests PUBLIC ${CMAKE_SOURCE_DIR}/src/hal) + +# tell build system about the test case +add_catch_test(circular_buffer_tests) diff --git a/tests/unit/hal/circular_buffer/test_circular_buffer.cpp b/tests/unit/hal/circular_buffer/test_circular_buffer.cpp new file mode 100644 index 0000000..287ba3e --- /dev/null +++ b/tests/unit/hal/circular_buffer/test_circular_buffer.cpp @@ -0,0 +1,27 @@ +#include "catch2/catch.hpp" +#include "circular_buffer.h" + +using Catch::Matchers::Equals; + +TEST_CASE("circular_buffer::basic", "[circular_buffer]") { + + using CB = CircularBuffer; + + CB cb; + + // at the beginning the buffer is empty + REQUIRE(cb.empty()); + + // since its capacity was defined as 32, at least one element must be successfully inserted + CHECK(cb.push(1)); + + // is the element there? + REQUIRE(!cb.empty()); + CHECK(cb.front() == 1); + + // remove the element + uint8_t b = 0; + CHECK(cb.pop(b)); + CHECK(b == 1); + CHECK(cb.empty()); +}