From 80b91f55090ce0658c87f1fac132641efa1e2605 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sun, 31 Oct 2021 12:01:28 +0100 Subject: ringbuffer API change: Drop whole `NullValue` *angle*, simplifying; Drop `use_memset` non-type template param use `use_memcpy` - ringbuffer API change: Drop whole `NullValue` *angle*, simplifying - Drop `Value_type [get|peek]*()`, use `bool [get|peek]*(Value_type&)` instead - Use `bool` return to determine success and `Value_type` reference as storage. - Drop `NullValue_type` template type param and `NullValue_type` ctor argument. - Simplifies and unifies single and multi get and put, as well as testing (motivation). - ringbuffer: Drop `use_memset` non-type template param, simply use `use_memcpy` having same semantics of *TriviallyCopyable* - favor ::memcpy over ::memmove if applicable don't confuse with our `use_memmove` semantics :) - Use proper 'void*' cast to lose const'ness, drop non-required 'void*' cast for source (memmove) - Use global namespace ::memmove and ::explicit_bzero --- test/test_lfringbuffer01.cpp | 54 +++++++++++++++----------------------------- 1 file changed, 18 insertions(+), 36 deletions(-) (limited to 'test/test_lfringbuffer01.cpp') diff --git a/test/test_lfringbuffer01.cpp b/test/test_lfringbuffer01.cpp index 998251a..68aeaf2 100644 --- a/test/test_lfringbuffer01.cpp +++ b/test/test_lfringbuffer01.cpp @@ -38,19 +38,19 @@ using namespace jau; typedef uint8_t IntegralType; typedef uint8_t TrivialType; constexpr const TrivialType TrivialTypeNullElem(0xff); -typedef ringbuffer TrivialTypeRingbuffer; +typedef ringbuffer TrivialTypeRingbuffer; // Test examples. class TestRingbuffer01 { private: TrivialTypeRingbuffer createEmpty(jau::nsize_t initialCapacity) { - TrivialTypeRingbuffer rb(0xff, initialCapacity); + TrivialTypeRingbuffer rb(initialCapacity); REQUIRE_MSG("empty "+rb.toString(), rb.isEmpty()); return rb; } TrivialTypeRingbuffer createFull(const std::vector & source) { - TrivialTypeRingbuffer rb(0xff, source); + TrivialTypeRingbuffer rb(source); REQUIRE_MSG("full "+rb.toString(), rb.isFull()); return rb; } @@ -72,25 +72,6 @@ class TestRingbuffer01 { REQUIRE_MSG("size at read "+std::to_string(len)+" elems: "+rb.toString(), preSize >= len); REQUIRE_MSG("not empty "+rb.toString(), !rb.isEmpty()); - for(jau::nsize_t i=0; i= len); - REQUIRE_MSG("not full "+rb.toString(), !rb.isFull()); - } - void readTestImpl2(TrivialTypeRingbuffer &rb, bool clearRef, jau::nsize_t capacity, jau::nsize_t len, IntegralType startValue) { - (void) clearRef; - - jau::nsize_t preSize = rb.size(); - REQUIRE_MSG("capacity "+rb.toString(), capacity == rb.capacity()); - REQUIRE_MSG("capacity at read "+std::to_string(len)+" elems: "+rb.toString(), capacity >= len); - REQUIRE_MSG("size at read "+std::to_string(len)+" elems: "+rb.toString(), preSize >= len); - REQUIRE_MSG("not empty "+rb.toString(), !rb.isEmpty()); - for(jau::nsize_t i=0; i::value)+ ", size "+std::to_string(sizeof(rb))+" bytes"); fprintf(stderr, "%s\n", msg.c_str()); fprintf(stderr, "%s\n", rb.get_info().c_str()); REQUIRE_MSG("Ringbuffer using memcpy", TrivialTypeRingbuffer::uses_memcpy); - REQUIRE_MSG("Ringbuffer uses memset", TrivialTypeRingbuffer::uses_memset); } void test01_FullRead() { @@ -382,7 +366,7 @@ class TestRingbuffer01 { INFO_STR("test04_FullReadReset: Post Reset w/ source / " + rb.toString()); REQUIRE_MSG("full "+rb.toString(), rb.isFull()); - readTestImpl2(rb, false, capacity, capacity, 0); + readTestImpl(rb, false, capacity, capacity, 0); INFO_STR("test04_FullReadReset: Post Read / " + rb.toString()); REQUIRE_MSG("empty "+rb.toString(), rb.isEmpty()); } @@ -407,7 +391,7 @@ class TestRingbuffer01 { writeTestImpl(rb, capacity, capacity, 0); REQUIRE_MSG("full "+rb.toString(), rb.isFull()); - readTestImpl2(rb, false, capacity, capacity, 0); + readTestImpl(rb, false, capacity, capacity, 0); REQUIRE_MSG("empty "+rb.toString(), rb.isEmpty()); } @@ -461,8 +445,8 @@ class TestRingbuffer01 { TrivialTypeRingbuffer rb = createFull(source); for(jau::nsize_t i=0; i