30 #define CATCH_CONFIG_MAIN
31 #include <catch2/catch_amalgamated.hpp>
67 std::shared_ptr<SharedTypeRingbuffer> createEmpty(
jau::nsize_t initialCapacity) {
68 std::shared_ptr<SharedTypeRingbuffer> rb = std::shared_ptr<SharedTypeRingbuffer>(
new SharedTypeRingbuffer(
nullptr, initialCapacity));
72 std::shared_ptr<SharedTypeRingbuffer> createFull(
const std::vector<std::shared_ptr<Integer>> & source) {
73 std::shared_ptr<SharedTypeRingbuffer> rb = std::shared_ptr<SharedTypeRingbuffer>(
new SharedTypeRingbuffer(
nullptr, source));
79 std::vector<SharedType> array(capacity);
135 std::vector<SharedType> array(len);
202 std::shared_ptr<SharedTypeRingbuffer> rb = createEmpty(11);
206 ", trivially_copyable "+
std::to_string(std::is_trivially_copyable<typename SharedTypeRingbuffer::value_type>::value)+
208 fprintf(stderr,
"%s", msg.c_str());
215 std::vector<SharedType> source = createIntArray(capacity, 0);
216 std::shared_ptr<SharedTypeRingbuffer> rb = createFull(source);
221 readTestImpl(*rb,
true, capacity, capacity, 0);
228 std::shared_ptr<SharedTypeRingbuffer> rb = createEmpty(capacity);
229 INFO( std::string(
"test02_EmptyWrite: Created / ") + rb->
toString().c_str());
233 writeTestImpl(*rb, capacity, capacity, 0);
234 INFO( std::string(
"test02_EmptyWrite: PostWrite / ") + rb->
toString().c_str());
238 readTestImpl(*rb,
true, capacity, capacity, 0);
239 INFO( std::string(
"test02_EmptyWrite: PostRead / ") + rb->
toString().c_str());
246 std::shared_ptr<SharedTypeRingbuffer> rb = createEmpty(capacity);
247 INFO( std::string(
"test03_EmptyWriteRange: Created / ") + rb->
toString().c_str());
255 std::vector<SharedType> new_data = createIntArray(capacity, 0);
256 writeRangeTestImpl(*rb, capacity, new_data);
258 INFO( std::string(
"test03_EmptyWriteRange: PostWrite / ") + rb->
toString().c_str());
262 readRangeTestImpl(*rb,
true, capacity, capacity, 0);
263 INFO( std::string(
"test03_EmptyWriteRange: PostRead / ") + rb->
toString().c_str());
268 std::shared_ptr<SharedTypeRingbuffer> rb = createEmpty(capacity);
269 INFO( std::string(
"test03_EmptyWriteRange: Created / ") + rb->
toString().c_str());
284 std::vector<SharedType> new_data = createIntArray(capacity, 0);
285 writeRangeTestImpl(*rb, capacity, new_data);
287 INFO( std::string(
"test03_EmptyWriteRange: PostWrite / ") + rb->
toString().c_str());
291 readRangeTestImpl(*rb,
true, capacity, capacity, 0);
292 INFO( std::string(
"test03_EmptyWriteRange: PostRead / ") + rb->
toString().c_str());
297 std::shared_ptr<SharedTypeRingbuffer> rb = createEmpty(capacity);
298 INFO( std::string(
"test03_EmptyWriteRange: Created / ") + rb->
toString().c_str());
318 std::vector<SharedType> new_data = createIntArray(capacity-2, 0);
319 writeRangeTestImpl(*rb, capacity, new_data);
322 INFO( std::string(
"test03_EmptyWriteRange: PostWrite / ") + rb->
toString().c_str());
330 readRangeTestImpl(*rb,
true, capacity, capacity-2, 0);
332 INFO( std::string(
"test03_EmptyWriteRange: PostRead / ") + rb->
toString().c_str());
338 std::shared_ptr<SharedTypeRingbuffer> rb = createEmpty(capacity);
339 INFO( std::string(
"test03_EmptyWriteRange: Created / ") + rb->
toString().c_str());
349 for(
int i=0; i<11; i++) { rb->
put(dummy); }
355 for(
int i=0; i<2; i++) { rb->
put(dummy); }
361 std::vector<SharedType> new_data = createIntArray(capacity-3, 0);
362 writeRangeTestImpl(*rb, capacity, new_data);
365 INFO( std::string(
"test03_EmptyWriteRange: PostWrite / ") + rb->
toString().c_str());
373 readRangeTestImpl(*rb,
true, capacity, capacity-3, 0);
375 INFO( std::string(
"test03_EmptyWriteRange: PostRead / ") + rb->
toString().c_str());
383 std::vector<SharedType> source = createIntArray(capacity, 0);
384 std::shared_ptr<SharedTypeRingbuffer> rb = createFull(source);
392 readTestImpl(*rb,
false, capacity, capacity, 0);
400 readTestImpl2(*rb,
false, capacity, capacity, 0);
407 std::shared_ptr<SharedTypeRingbuffer> rb = createEmpty(capacity);
413 writeTestImpl(*rb, capacity, capacity, 0);
416 readTestImpl(*rb,
false, capacity, capacity, 0);
422 writeTestImpl(*rb, capacity, capacity, 0);
425 readTestImpl2(*rb,
false, capacity, capacity, 0);
431 std::vector<SharedType> source = createIntArray(capacity, 0);
432 std::shared_ptr<SharedTypeRingbuffer> rb = createFull(source);
438 readTestImpl(*rb,
false, capacity, 5, 0);
445 readTestImpl(*rb,
false, capacity, capacity, 0);
451 std::vector<SharedType> source = createIntArray(capacity, 0);
452 std::shared_ptr<SharedTypeRingbuffer> rb = createFull(source);
458 moveGetPutImpl(*rb, 5);
459 readTestImpl(*rb,
false, capacity, 5, 5);
466 readTestImpl(*rb,
false, capacity, capacity, 0);
474 jau::nsize_t grownCapacity = initialCapacity+growAmount;
475 std::vector<SharedType> source = createIntArray(initialCapacity, 0);
476 std::shared_ptr<SharedTypeRingbuffer> rb = createFull(source);
488 moveGetPutImpl(*rb, pos);
529 test_GrowFullImpl(11, 0);
532 test_GrowFullImpl(11, 0+1);
535 test_GrowFullImpl(11, 0+2);
538 test_GrowFullImpl(11, 0+3);
541 test_GrowFullImpl(11, 11-1);
544 test_GrowFullImpl(11, 11-1-1);
547 test_GrowFullImpl(11, 11-1-2);
550 test_GrowFullImpl(11, 11-1-3);