diff --git a/tests/test_circular_q.cpp b/tests/test_circular_q.cpp index fd91503a..5f1a0e57 100644 --- a/tests/test_circular_q.cpp +++ b/tests/test_circular_q.cpp @@ -2,12 +2,14 @@ #include "spdlog/details/circular_q.h" using q_type = spdlog::details::circular_q; + TEST_CASE("test_size", "[circular_q]") { const size_t q_size = 4; q_type q(q_size); REQUIRE(q.size() == 0); REQUIRE(q.empty() == true); + REQUIRE(q.full() == false); for (size_t i = 0; i < q_size; i++) { q.push_back(std::move(i)); @@ -49,7 +51,75 @@ TEST_CASE("test_rolling", "[circular_q]") TEST_CASE("test_empty", "[circular_q]") { - q_type q(0); - q.push_back(1); - REQUIRE(q.empty()); -} \ No newline at end of file + q_type q1(0); + REQUIRE(q1.empty()); + q1.push_back(1); + REQUIRE(q1.empty()); + + q_type q2(1); + REQUIRE(q2.empty()); + q2.push_back(1); + REQUIRE(!q2.empty()); + q2.pop_front(); + REQUIRE(q2.empty()); +} + +TEST_CASE("test_full", "[circular_q]") +{ + q_type q1(0); + REQUIRE(q1.full()); + + q_type q2(2); + REQUIRE(!q2.full()); + + q2.push_back(1); + REQUIRE(!q2.full()); + + q2.push_back(2); + REQUIRE(q2.full()); +} + + +TEST_CASE("test_operator[]", "[circular_q]") +{ + q_type q(2); + q.push_back(100); + q.push_back(200); + REQUIRE(q[0] == 100); + REQUIRE(q[1] == 200); +} + + +TEST_CASE("test_operator=", "[circular_q]") +{ + q_type q1(2); + q1.push_back(100); + q1.push_back(200); + q_type q2 = q1; + REQUIRE(q2.size() == 2); + REQUIRE(q2[0] == 100); + REQUIRE(q2[1] == 200); +} + +TEST_CASE("test_front", "[circular_q]") +{ + q_type q(2); + q.push_back(100); + q.push_back(200); + REQUIRE(q.front() == 100); +} + +TEST_CASE("test_overrun_counter", "[circular_q]") +{ + q_type q(2); + REQUIRE(q.overrun_counter() == 0); + for(size_t i=0; i<10; i++) + { + q.push_back(100); + } + REQUIRE(q.overrun_counter() == 8); +} + + + +