diff options
author | Sven Gothel <[email protected]> | 2021-10-31 12:01:28 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2021-10-31 12:01:28 +0100 |
commit | 80b91f55090ce0658c87f1fac132641efa1e2605 (patch) | |
tree | e8b8296bb4101600661b584862a5395257bfc8de /test | |
parent | b3d563842dce10992eb25572d906dfb234764150 (diff) |
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
Diffstat (limited to 'test')
-rw-r--r-- | test/test_lfringbuffer01.cpp | 54 | ||||
-rw-r--r-- | test/test_lfringbuffer02.cpp | 53 | ||||
-rw-r--r-- | test/test_lfringbuffer03.cpp | 53 | ||||
-rw-r--r-- | test/test_lfringbuffer11.cpp | 10 | ||||
-rw-r--r-- | test/test_lfringbuffer12.cpp | 10 | ||||
-rw-r--r-- | test/test_lfringbuffer13.cpp | 12 |
6 files changed, 67 insertions, 125 deletions
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<TrivialType, TrivialType, jau::nsize_t> TrivialTypeRingbuffer; +typedef ringbuffer<TrivialType, jau::nsize_t> 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<TrivialType> & source) { - TrivialTypeRingbuffer rb(0xff, source); + TrivialTypeRingbuffer rb(source); REQUIRE_MSG("full "+rb.toString(), rb.isFull()); return rb; } @@ -73,25 +73,6 @@ class TestRingbuffer01 { REQUIRE_MSG("not empty "+rb.toString(), !rb.isEmpty()); for(jau::nsize_t i=0; i<len; i++) { - TrivialType svI = rb.get(); - REQUIRE_MSG("not empty at read #"+std::to_string(i+1)+": "+rb.toString(), svI!=TrivialTypeNullElem); - REQUIRE_MSG("value at read #"+std::to_string(i+1)+": "+rb.toString(), startValue+(IntegralType)i == svI); - } - - REQUIRE_MSG("size "+rb.toString(), preSize-len == rb.size()); - REQUIRE_MSG("free slots after reading "+std::to_string(len)+": "+rb.toString(), rb.freeSlots()>= 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<len; i++) { TrivialType svI; REQUIRE_MSG("ringbuffer get", rb.get(svI)); REQUIRE_MSG("not empty at read #"+std::to_string(i+1)+": "+rb.toString(), svI!=TrivialTypeNullElem); @@ -163,7 +144,9 @@ class TestRingbuffer01 { void moveGetPutImpl(TrivialTypeRingbuffer &rb, jau::nsize_t pos) { REQUIRE_MSG("not empty "+rb.toString(), !rb.isEmpty()); for(jau::nsize_t i=0; i<pos; i++) { - REQUIRE_MSG("moveFull.get "+rb.toString(), (IntegralType)i == rb.get()); + TrivialType svI; + REQUIRE_MSG("moveFull.get "+rb.toString(), rb.get(svI)); + REQUIRE_MSG("moveFull.get "+rb.toString(), (IntegralType)i == svI); REQUIRE_MSG("moveFull.put "+rb.toString(), rb.put( TrivialType( (IntegralType)i ) ) ); } } @@ -172,7 +155,10 @@ class TestRingbuffer01 { REQUIRE_MSG("RB is full "+rb.toString(), !rb.isFull()); for(jau::nsize_t i=0; i<pos; i++) { REQUIRE_MSG("moveEmpty.put "+rb.toString(), rb.put( TrivialType( 600+(IntegralType)i ) ) ); - REQUIRE_MSG("moveEmpty.get "+rb.toString(), 600+(IntegralType)i == rb.get()); + + TrivialType svI; + REQUIRE_MSG("moveEmpty.get "+rb.toString(), rb.get(svI)); + REQUIRE_MSG("moveEmpty.get "+rb.toString(), 600+(IntegralType)i == svI); } } @@ -182,13 +168,11 @@ class TestRingbuffer01 { TrivialTypeRingbuffer rb = createEmpty(11); std::string msg("Ringbuffer: uses_memcpy "+std::to_string(TrivialTypeRingbuffer::uses_memcpy)+ - ", uses_memset "+std::to_string(TrivialTypeRingbuffer::uses_memset)+ ", trivially_copyable "+std::to_string(std::is_trivially_copyable<typename TrivialTypeRingbuffer::value_type>::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<T> using memcpy", TrivialTypeRingbuffer::uses_memcpy); - REQUIRE_MSG("Ringbuffer<T> 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<initialCapacity; i++) { - TrivialType svI = rb.get(); - REQUIRE_MSG("not empty at read #"+std::to_string(i+1)+": "+rb.toString(), svI!=TrivialTypeNullElem); + TrivialType svI;; + REQUIRE_MSG("not empty at read #"+std::to_string(i+1)+": "+rb.toString(), rb.get(svI)); REQUIRE_MSG("value at read #"+std::to_string(i+1)+": "+rb.toString(), IntegralType((0+i)%initialCapacity) == svI); } REQUIRE_MSG("zero size "+rb.toString(), 0 == rb.size()); @@ -489,16 +473,14 @@ class TestRingbuffer01 { REQUIRE_MSG("full "+rb.toString(), rb.isFull()); for(jau::nsize_t i=0; i<initialCapacity; i++) { - TrivialType svI = rb.get(); - // PRINTM("X05["+std::to_string(i)+"]: "+rb.toString()+", svI-null: "+std::to_string(svI==TrivialTypeNullElem)); - REQUIRE_MSG("not empty at read #"+std::to_string(i+1)+": "+rb.toString(), svI!=TrivialTypeNullElem); + TrivialType svI; + REQUIRE_MSG("not empty at read #"+std::to_string(i+1)+": "+rb.toString(), rb.get(svI)); REQUIRE_MSG("value at read #"+std::to_string(i+1)+": "+rb.toString(), IntegralType((pos+i)%initialCapacity) == svI); } for(jau::nsize_t i=0; i<growAmount; i++) { - TrivialType svI = rb.get(); - // PRINTM("X07["+std::to_string(i)+"]: "+rb.toString()+", svI-null: "+std::to_string(svI==TrivialTypeNullElem)); - REQUIRE_MSG("not empty at read #"+std::to_string(i+1)+": "+rb.toString(), svI!=TrivialTypeNullElem); + TrivialType svI; + REQUIRE_MSG("not empty at read #"+std::to_string(i+1)+": "+rb.toString(), rb.get(svI)); REQUIRE_MSG("value at read #"+std::to_string(i+1)+": "+rb.toString(), IntegralType(100+i) == svI); } diff --git a/test/test_lfringbuffer02.cpp b/test/test_lfringbuffer02.cpp index 41b377c..35953e7 100644 --- a/test/test_lfringbuffer02.cpp +++ b/test/test_lfringbuffer02.cpp @@ -59,19 +59,19 @@ class Integer { typedef Integer TrivialType; static const TrivialType TrivialTypeNullElem(-1); -typedef ringbuffer<TrivialType, TrivialType, jau::nsize_t> TrivialTypeRingbuffer; +typedef ringbuffer<TrivialType, jau::nsize_t> TrivialTypeRingbuffer; // Test examples. class TestRingbuffer02 { private: TrivialTypeRingbuffer createEmpty(jau::nsize_t initialCapacity) { - TrivialTypeRingbuffer rb(Integer(-1), initialCapacity); + TrivialTypeRingbuffer rb(initialCapacity); REQUIRE_MSG("empty "+rb.toString(), rb.isEmpty()); return rb; } TrivialTypeRingbuffer createFull(const std::vector<TrivialType> & source) { - TrivialTypeRingbuffer rb(Integer(-1), source); + TrivialTypeRingbuffer rb(source); REQUIRE_MSG("full "+rb.toString(), rb.isFull()); return rb; } @@ -94,25 +94,6 @@ class TestRingbuffer02 { REQUIRE_MSG("not empty "+rb.toString(), !rb.isEmpty()); for(jau::nsize_t i=0; i<len; i++) { - TrivialType svI = rb.get(); - REQUIRE_MSG("not empty at read #"+std::to_string(i+1)+": "+rb.toString(), svI!=TrivialTypeNullElem); - REQUIRE_MSG("value at read #"+std::to_string(i+1)+": "+rb.toString(), startValue+(IntegralType)i == svI.intValue()); - } - - REQUIRE_MSG("size "+rb.toString(), preSize-len == rb.size()); - REQUIRE_MSG("free slots after reading "+std::to_string(len)+": "+rb.toString(), rb.freeSlots()>= 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<len; i++) { TrivialType svI; REQUIRE_MSG("ringbuffer get", rb.get(svI)); REQUIRE_MSG("not empty at read #"+std::to_string(i+1)+": "+rb.toString(), svI!=TrivialTypeNullElem); @@ -184,7 +165,9 @@ class TestRingbuffer02 { void moveGetPutImpl(TrivialTypeRingbuffer &rb, jau::nsize_t pos) { REQUIRE_MSG("not empty "+rb.toString(), !rb.isEmpty()); for(jau::nsize_t i=0; i<pos; i++) { - REQUIRE_MSG("moveFull.get "+rb.toString(), (IntegralType)i == rb.get().intValue()); + TrivialType svI; + REQUIRE_MSG("moveFull.get "+rb.toString(), rb.get(svI)); + REQUIRE_MSG("moveFull.get "+rb.toString(), (IntegralType)i == svI.intValue()); REQUIRE_MSG("moveFull.put "+rb.toString(), rb.put( TrivialType( (IntegralType)i ) ) ); } } @@ -193,7 +176,9 @@ class TestRingbuffer02 { REQUIRE_MSG("RB is full "+rb.toString(), !rb.isFull()); for(jau::nsize_t i=0; i<pos; i++) { REQUIRE_MSG("moveEmpty.put "+rb.toString(), rb.put( TrivialType( 600+(IntegralType)i ) ) ); - REQUIRE_MSG("moveEmpty.get "+rb.toString(), 600+(IntegralType)i == rb.get().intValue()); + TrivialType svI; + REQUIRE_MSG("moveEmpty.get "+rb.toString(), rb.get(svI)); + REQUIRE_MSG("moveEmpty.get "+rb.toString(), 600+(IntegralType)i == svI.intValue()); } } @@ -203,13 +188,11 @@ class TestRingbuffer02 { TrivialTypeRingbuffer rb = createEmpty(11); std::string msg("Ringbuffer: uses_memcpy "+std::to_string(TrivialTypeRingbuffer::uses_memcpy)+ - ", uses_memset "+std::to_string(TrivialTypeRingbuffer::uses_memset)+ ", trivially_copyable "+std::to_string(std::is_trivially_copyable<typename TrivialTypeRingbuffer::value_type>::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<T> using memcpy", TrivialTypeRingbuffer::uses_memcpy); - REQUIRE_MSG("Ringbuffer<T> not using memset", !TrivialTypeRingbuffer::uses_memset); } void test01_FullRead() { @@ -413,7 +396,7 @@ class TestRingbuffer02 { 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()); } @@ -438,7 +421,7 @@ class TestRingbuffer02 { 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()); } @@ -492,8 +475,8 @@ class TestRingbuffer02 { TrivialTypeRingbuffer rb = createFull(source); for(jau::nsize_t i=0; i<initialCapacity; i++) { - TrivialType svI = rb.get(); - REQUIRE_MSG("not empty at read #"+std::to_string(i+1)+": "+rb.toString(), svI!=TrivialTypeNullElem); + TrivialType svI; + REQUIRE_MSG("not empty at read #"+std::to_string(i+1)+": "+rb.toString(), rb.get(svI)); REQUIRE_MSG("value at read #"+std::to_string(i+1)+": "+rb.toString(), IntegralType((0+i)%initialCapacity) == svI.intValue()); } REQUIRE_MSG("zero size "+rb.toString(), 0 == rb.size()); @@ -520,16 +503,14 @@ class TestRingbuffer02 { REQUIRE_MSG("full "+rb.toString(), rb.isFull()); for(jau::nsize_t i=0; i<initialCapacity; i++) { - TrivialType svI = rb.get(); - // PRINTM("X05["+std::to_string(i)+"]: "+rb.toString()+", svI-null: "+std::to_string(svI==TrivialTypeNullElem)); - REQUIRE_MSG("not empty at read #"+std::to_string(i+1)+": "+rb.toString(), svI!=TrivialTypeNullElem); + TrivialType svI; + REQUIRE_MSG("not empty at read #"+std::to_string(i+1)+": "+rb.toString(), rb.get(svI)); REQUIRE_MSG("value at read #"+std::to_string(i+1)+": "+rb.toString(), IntegralType((pos+i)%initialCapacity) == svI.intValue()); } for(jau::nsize_t i=0; i<growAmount; i++) { - TrivialType svI = rb.get(); - // PRINTM("X07["+std::to_string(i)+"]: "+rb.toString()+", svI-null: "+std::to_string(svI==TrivialTypeNullElem)); - REQUIRE_MSG("not empty at read #"+std::to_string(i+1)+": "+rb.toString(), svI!=TrivialTypeNullElem); + TrivialType svI; + REQUIRE_MSG("not empty at read #"+std::to_string(i+1)+": "+rb.toString(), rb.get(svI)); REQUIRE_MSG("value at read #"+std::to_string(i+1)+": "+rb.toString(), IntegralType(100+i) == svI.intValue()); } diff --git a/test/test_lfringbuffer03.cpp b/test/test_lfringbuffer03.cpp index 51819e3..5e6f7bc 100644 --- a/test/test_lfringbuffer03.cpp +++ b/test/test_lfringbuffer03.cpp @@ -58,19 +58,19 @@ class Integer { std::shared_ptr<Integer> NullInteger = nullptr; typedef std::shared_ptr<Integer> SharedType; -typedef ringbuffer<SharedType, std::nullptr_t, jau::nsize_t> SharedTypeRingbuffer; +typedef ringbuffer<SharedType, jau::nsize_t> SharedTypeRingbuffer; // Test examples. class TestRingbuffer03 { private: std::shared_ptr<SharedTypeRingbuffer> createEmpty(jau::nsize_t initialCapacity) { - std::shared_ptr<SharedTypeRingbuffer> rb = std::shared_ptr<SharedTypeRingbuffer>(new SharedTypeRingbuffer(nullptr, initialCapacity)); + std::shared_ptr<SharedTypeRingbuffer> rb = std::shared_ptr<SharedTypeRingbuffer>(new SharedTypeRingbuffer(initialCapacity)); REQUIRE_MSG("empty "+rb->toString(), rb->isEmpty()); return rb; } std::shared_ptr<SharedTypeRingbuffer> createFull(const std::vector<std::shared_ptr<Integer>> & source) { - std::shared_ptr<SharedTypeRingbuffer> rb = std::shared_ptr<SharedTypeRingbuffer>(new SharedTypeRingbuffer(nullptr, source)); + std::shared_ptr<SharedTypeRingbuffer> rb = std::shared_ptr<SharedTypeRingbuffer>(new SharedTypeRingbuffer(source)); REQUIRE_MSG("full "+rb->toString(), rb->isFull()); return rb; } @@ -93,25 +93,6 @@ class TestRingbuffer03 { REQUIRE_MSG("not empty "+rb.toString(), !rb.isEmpty()); for(jau::nsize_t i=0; i<len; i++) { - SharedType svI = rb.get(); - REQUIRE_MSG("not empty at read #"+std::to_string(i+1)+": "+rb.toString(), svI!=nullptr); - REQUIRE_MSG("value at read #"+std::to_string(i+1)+": "+rb.toString(), IntegralType(startValue+i) == svI->intValue()); - } - - REQUIRE_MSG("size "+rb.toString(), preSize-len == rb.size()); - REQUIRE_MSG("free slots after reading "+std::to_string(len)+": "+rb.toString(), rb.freeSlots()>= len); - REQUIRE_MSG("not full "+rb.toString(), !rb.isFull()); - } - void readTestImpl2(SharedTypeRingbuffer &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<len; i++) { SharedType svI; REQUIRE_MSG("ringbuffer get", rb.get(svI)); REQUIRE_MSG("not empty at read #"+std::to_string(i+1)+": "+rb.toString(), svI!=nullptr); @@ -183,7 +164,9 @@ class TestRingbuffer03 { void moveGetPutImpl(SharedTypeRingbuffer &rb, jau::nsize_t pos) { REQUIRE_MSG("not empty "+rb.toString(), !rb.isEmpty()); for(jau::nsize_t i=0; i<pos; i++) { - REQUIRE_MSG("moveFull.get "+rb.toString(), IntegralType(i) == rb.get()->intValue()); + SharedType svI; + REQUIRE_MSG("moveFull.get "+rb.toString(), rb.get(svI)); + REQUIRE_MSG("moveFull.get "+rb.toString(), IntegralType(i) == svI->intValue()); REQUIRE_MSG("moveFull.put "+rb.toString(), rb.put( SharedType( new Integer(i) ) ) ); } } @@ -192,7 +175,9 @@ class TestRingbuffer03 { REQUIRE_MSG("RB is full "+rb.toString(), !rb.isFull()); for(jau::nsize_t i=0; i<pos; i++) { REQUIRE_MSG("moveEmpty.put "+rb.toString(), rb.put( SharedType( new Integer(600+i) ) ) ); - REQUIRE_MSG("moveEmpty.get "+rb.toString(), IntegralType(600+i) == rb.get()->intValue()); + SharedType svI; + REQUIRE_MSG("moveEmpty.get "+rb.toString(), rb.get(svI)); + REQUIRE_MSG("moveEmpty.get "+rb.toString(), IntegralType(600+i) == svI->intValue()); } } @@ -202,13 +187,11 @@ class TestRingbuffer03 { std::shared_ptr<SharedTypeRingbuffer> rb = createEmpty(11); std::string msg("Ringbuffer: uses_memcpy "+std::to_string(SharedTypeRingbuffer::uses_memcpy)+ - ", uses_memset "+std::to_string(SharedTypeRingbuffer::uses_memset)+ ", trivially_copyable "+std::to_string(std::is_trivially_copyable<typename SharedTypeRingbuffer::value_type>::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<shared_ptr<T>> not using memcpy", !SharedTypeRingbuffer::uses_memcpy); - REQUIRE_MSG("Ringbuffer<shared_ptr<T>> not using memset", !SharedTypeRingbuffer::uses_memset); } void test01_FullRead() { @@ -398,7 +381,7 @@ class TestRingbuffer03 { 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()); } @@ -423,7 +406,7 @@ class TestRingbuffer03 { 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()); } @@ -477,8 +460,8 @@ class TestRingbuffer03 { std::shared_ptr<SharedTypeRingbuffer> rb = createFull(source); for(jau::nsize_t i=0; i<initialCapacity; i++) { - SharedType svI = rb->get(); - REQUIRE_MSG("not empty at read #"+std::to_string(i+1)+": "+rb->toString(), svI!=nullptr); + SharedType svI; + REQUIRE_MSG("not empty at read #"+std::to_string(i+1)+": "+rb->toString(), rb->get(svI)); REQUIRE_MSG("value at read #"+std::to_string(i+1)+": "+rb->toString(), IntegralType((0+i)%initialCapacity) == svI->intValue()); } REQUIRE_MSG("zero size "+rb->toString(), 0 == rb->size()); @@ -505,16 +488,14 @@ class TestRingbuffer03 { REQUIRE_MSG("full "+rb->toString(), rb->isFull()); for(jau::nsize_t i=0; i<initialCapacity; i++) { - SharedType svI = rb->get(); - // PRINTM("X05["+std::to_string(i)+"]: "+rb->toString()+", svI-null: "+std::to_string(svI==nullptr)); - REQUIRE_MSG("not empty at read #"+std::to_string(i+1)+": "+rb->toString(), svI!=nullptr); + SharedType svI; + REQUIRE_MSG("not empty at read #"+std::to_string(i+1)+": "+rb->toString(), rb->get(svI)); REQUIRE_MSG("value at read #"+std::to_string(i+1)+": "+rb->toString(), IntegralType((pos+i)%initialCapacity) == svI->intValue()); } for(jau::nsize_t i=0; i<growAmount; i++) { - SharedType svI = rb->get(); - // PRINTM("X07["+std::to_string(i)+"]: "+rb->toString()+", svI-null: "+std::to_string(svI==nullptr)); - REQUIRE_MSG("not empty at read #"+std::to_string(i+1)+": "+rb->toString(), svI!=nullptr); + SharedType svI; + REQUIRE_MSG("not empty at read #"+std::to_string(i+1)+": "+rb->toString(), rb->get(svI)); REQUIRE_MSG("value at read #"+std::to_string(i+1)+": "+rb->toString(), IntegralType(100+i) == svI->intValue()); } diff --git a/test/test_lfringbuffer11.cpp b/test/test_lfringbuffer11.cpp index 2f329ed..c41d602 100644 --- a/test/test_lfringbuffer11.cpp +++ b/test/test_lfringbuffer11.cpp @@ -40,7 +40,7 @@ using namespace jau; typedef uint8_t IntegralType; typedef uint8_t TrivialType; constexpr const TrivialType TrivialTypeNullElem(0xff); -typedef ringbuffer<TrivialType, TrivialType, jau::nsize_t> TrivialTypeRingbuffer; +typedef ringbuffer<TrivialType, jau::nsize_t> TrivialTypeRingbuffer; constexpr static const IntegralType integral_modulus = 254; @@ -49,12 +49,12 @@ class TestRingbuffer11 { 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<TrivialType> & source) { - TrivialTypeRingbuffer rb(0xff, source); + TrivialTypeRingbuffer rb(source); REQUIRE_MSG("full "+rb.toString(), rb.isFull()); return rb; } @@ -74,8 +74,8 @@ class TestRingbuffer11 { // INFO_STR, INFO: Not thread safe yet // INFO_STR(msg+": Created / " + rb->toString()); for(jau::nsize_t i=0; i<len; i++) { - TrivialType svI = rb->getBlocking(); - REQUIRE_MSG("not empty at read #"+std::to_string(i+1)+": "+rb->toString()+", elem "+std::to_string(svI), svI!= TrivialTypeNullElem); + TrivialType svI; + REQUIRE_MSG("not empty at read #"+std::to_string(i+1)+": "+rb->toString()+", elem "+std::to_string(svI), rb->getBlocking(svI)); // INFO_STR("Got "+std::to_string(svI->intValue())+" / " + rb->toString()); } // INFO_STR(msg+": Dies / " + rb->toString()); diff --git a/test/test_lfringbuffer12.cpp b/test/test_lfringbuffer12.cpp index 3ea1637..75a2985 100644 --- a/test/test_lfringbuffer12.cpp +++ b/test/test_lfringbuffer12.cpp @@ -61,19 +61,19 @@ class Integer { typedef Integer TrivialType; static const TrivialType TrivialTypeNullElem(-1); -typedef ringbuffer<TrivialType, TrivialType, jau::nsize_t> TrivialTypeRingbuffer; +typedef ringbuffer<TrivialType, jau::nsize_t> TrivialTypeRingbuffer; // Test examples. class TestRingbuffer12 { private: TrivialTypeRingbuffer createEmpty(jau::nsize_t initialCapacity) { - TrivialTypeRingbuffer rb(Integer(-1), initialCapacity); + TrivialTypeRingbuffer rb(initialCapacity); REQUIRE_MSG("empty "+rb.toString(), rb.isEmpty()); return rb; } TrivialTypeRingbuffer createFull(const std::vector<TrivialType> & source) { - TrivialTypeRingbuffer rb(Integer(-1), source); + TrivialTypeRingbuffer rb(source); REQUIRE_MSG("full "+rb.toString(), rb.isFull()); return rb; } @@ -93,8 +93,8 @@ class TestRingbuffer12 { // INFO_STR, INFO: Not thread safe yet // INFO_STR(msg+": Created / " + rb->toString()); for(jau::nsize_t i=0; i<len; i++) { - TrivialType svI = rb->getBlocking(); - REQUIRE_MSG("not empty at read #"+std::to_string(i+1)+": "+rb->toString(), svI!=TrivialTypeNullElem); + TrivialType svI; + REQUIRE_MSG("not empty at read #"+std::to_string(i+1)+": "+rb->toString(), rb->getBlocking(svI)); // INFO_STR("Got "+std::to_string(svI->intValue())+" / " + rb->toString()); } // INFO_STR(msg+": Dies / " + rb->toString()); diff --git a/test/test_lfringbuffer13.cpp b/test/test_lfringbuffer13.cpp index ba2b994..1588bfc 100644 --- a/test/test_lfringbuffer13.cpp +++ b/test/test_lfringbuffer13.cpp @@ -57,21 +57,19 @@ class Integer { static Integer valueOf(const IntegralType i) { return Integer(i); } }; -std::shared_ptr<Integer> NullInteger = nullptr; - typedef std::shared_ptr<Integer> SharedType; constexpr const std::nullptr_t SharedTypeNullElem = nullptr ; -typedef ringbuffer<SharedType, std::nullptr_t, jau::nsize_t> SharedTypeRingbuffer; +typedef ringbuffer<SharedType, jau::nsize_t> SharedTypeRingbuffer; // Test examples. class TestRingbuffer13 { private: std::shared_ptr<SharedTypeRingbuffer> createEmpty(jau::nsize_t initialCapacity) { - return std::shared_ptr<SharedTypeRingbuffer>(new SharedTypeRingbuffer(nullptr, initialCapacity)); + return std::shared_ptr<SharedTypeRingbuffer>(new SharedTypeRingbuffer(initialCapacity)); } std::shared_ptr<SharedTypeRingbuffer> createFull(const std::vector<std::shared_ptr<Integer>> & source) { - return std::shared_ptr<SharedTypeRingbuffer>(new SharedTypeRingbuffer(nullptr, source)); + return std::shared_ptr<SharedTypeRingbuffer>(new SharedTypeRingbuffer(source)); } std::vector<SharedType> createIntArray(const jau::nsize_t capacity, const IntegralType startValue) { @@ -89,8 +87,8 @@ class TestRingbuffer13 { // INFO_STR, INFO: Not thread safe yet // INFO_STR(msg+": Created / " + rb->toString()); for(jau::nsize_t i=0; i<len; i++) { - SharedType svI = rb->getBlocking(); - REQUIRE_MSG("not empty at read #"+std::to_string(i+1)+": "+rb->toString(), svI!=SharedTypeNullElem); + SharedType svI; + REQUIRE_MSG("not empty at read #"+std::to_string(i+1)+": "+rb->toString(), rb->getBlocking(svI)); // INFO_STR("Got "+std::to_string(svI->intValue())+" / " + rb->toString()); } // INFO_STR(msg+": Dies / " + rb->toString()); |