diff options
author | Sven Gothel <[email protected]> | 2021-01-09 14:08:56 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2021-01-09 14:08:56 +0100 |
commit | 31d870deff87502ddf1b0bdf57ed8494b31d94a4 (patch) | |
tree | d40448e02228ef26452f0806ad49093e3eb86498 /test | |
parent | 0074f03ec69b0a1004f68f3106bacab77c0268e8 (diff) |
test_cow_darray_01.cpp: Repurpose test: Initializer List and all darray operational modes: use_memmove=[false, true /* forced */], ..
Diffstat (limited to 'test')
-rw-r--r-- | test/test_cow_darray_01.cpp | 633 |
1 files changed, 334 insertions, 299 deletions
diff --git a/test/test_cow_darray_01.cpp b/test/test_cow_darray_01.cpp index 1ae6fb8..a1bb2be 100644 --- a/test/test_cow_darray_01.cpp +++ b/test/test_cow_darray_01.cpp @@ -35,6 +35,8 @@ #include "test_datatype01.hpp" +#include "test_datatype02.hpp" + #include <jau/basic_algos.hpp> #include <jau/basic_types.hpp> #include <jau/darray.hpp> @@ -49,341 +51,374 @@ */ using namespace jau; -static uint8_t start_addr_b[] = {0x20, 0x26, 0x2A, 0x01, 0x20, 0x10}; -static Addr48Bit start_addr(start_addr_b); - -typedef std::vector<DataType01, counting_allocator<DataType01>> std_vector_DataType01; -typedef jau::darray<DataType01, counting_callocator<DataType01>> jau_darray_DataType01; -typedef jau::cow_vector<DataType01, counting_allocator<DataType01>> jau_cow_vector_DataType01; -typedef jau::cow_darray<DataType01, counting_callocator<DataType01>> jau_cow_darray_DataType01; - -JAU_TYPENAME_CUE_ALL(std_vector_DataType01) -JAU_TYPENAME_CUE_ALL(jau_darray_DataType01) -JAU_TYPENAME_CUE_ALL(jau_cow_vector_DataType01) -JAU_TYPENAME_CUE_ALL(jau_cow_darray_DataType01) - -template<class T> -DataType01 * findDataSet01_idx(T& data, DataType01 const & elem) noexcept { - const size_t size = data.size(); - for (size_t i = 0; i < size; i++) { - DataType01 & e = data[i]; - if ( elem == e ) { - return &e; - } - } - return nullptr; -} - -template<class T> -static void test_00_list_idx(T& data, const bool show) { - Addr48Bit a0(start_addr); - const std::size_t size = data.size(); - for (std::size_t i = 0; i < size && a0.next(); ++i) { - const DataType01 & e = data[i]; - e.nop(); - if( show ) { - printf("data[%zu]: %s\n", i, e.toString().c_str()); - } - REQUIRE(e.address == a0); - } -} -template<class T> -static int test_00_list_itr(T& data, const bool show) { - Addr48Bit a0(start_addr); - int some_number = 0, i=0; // add some validated work, avoiding any 'optimization away' - jau::for_each_const(data, [&some_number, &a0, &i, show](const DataType01 & e) { - some_number += e.nop(); - if( show ) { - printf("data[%d]: %s\n", i, e.toString().c_str()); - } - REQUIRE( a0.next() ); - REQUIRE(e.address == a0); +/**********************************************************************************************************************************************/ +/**********************************************************************************************************************************************/ +/**********************************************************************************************************************************************/ +/**********************************************************************************************************************************************/ +/**********************************************************************************************************************************************/ + +TEST_CASE( "JAU DArray Test 01 - jau::darray initializer list", "[datatype][jau][darray]" ) { + int i = 0; + jau::for_each(GATT_SERVICES.begin(), GATT_SERVICES.end(), [&i](const GattServiceCharacteristic* ml){ + (void)ml; + // printf("XX: %s\n\n", ml->toString().c_str()); ++i; - } ); - REQUIRE(some_number > 0); - return some_number; + }); + REQUIRE(3 == i); } -template<class T> -static void test_00_seq_find_idx(T& data) { - Addr48Bit a0(start_addr); - const std::size_t size = data.size(); - std::size_t fi = 0, i=0; - - for(; i<size && a0.next(); i++) { - DataType01 elem(a0, static_cast<uint8_t>(1)); - DataType01 *found = findDataSet01_idx(data, elem); - if( nullptr != found ) { - fi++; - found->nop(); - } +/**********************************************************************************************************************************************/ +/**********************************************************************************************************************************************/ +/**********************************************************************************************************************************************/ +/**********************************************************************************************************************************************/ +/**********************************************************************************************************************************************/ + +template<class Payload> +using SharedPayloadListMemMove = jau::darray<std::shared_ptr<Payload>, jau::callocator<std::shared_ptr<Payload>>, jau::nsize_t, true /* use_memmove */, true /* use_realloc */>; +// JAU_TYPENAME_CUE_ALL(SharedPayloadListMemMove) + +template<class Payload> +using SharedPayloadListDefault = jau::darray<std::shared_ptr<Payload>>; +// JAU_TYPENAME_CUE_ALL(SharedPayloadListDefault) + +template<class Payload> +struct NamedSharedPayloadListDefault { + int name; + SharedPayloadListDefault<Payload> payload; + + std::string toString() const noexcept { + std::string res = "NSPL-Default-"+std::to_string(name)+"[sz"+std::to_string(payload.size())+": "; + int i=0; + jau::for_each(payload.cbegin(), payload.cend(), [&](const std::shared_ptr<Payload>& e) { + if(0<i) { + res += ", "; + } + res += "["+jau::to_string(e)+"]"; + ++i; + } ); + res += "]"; + return res; } - REQUIRE(fi == i); -} -template<class T> -static void test_00_seq_find_itr(T& data) { - Addr48Bit a0(start_addr); - const std::size_t size = data.size(); - std::size_t fi = 0, i=0; - - for(; i<size && a0.next(); i++) { - DataType01 elem(a0, static_cast<uint8_t>(1)); - const DataType01 *found = jau::find_const(data, elem); - if( nullptr != found ) { - fi++; - found->nop(); - } +}; +// JAU_TYPENAME_CUE_ALL(NamedSharedPayloadListDefault) + +template<class Payload> +struct NamedSharedPayloadListMemMove { + int name; + SharedPayloadListMemMove<Payload> payload; + + std::string toString() const noexcept { + std::string res = "NSPL-MemMove-"+std::to_string(name)+"[sz"+std::to_string(payload.size())+": "; + int i=0; + jau::for_each(payload.cbegin(), payload.cend(), [&](const std::shared_ptr<Payload>& e) { + if(0<i) { + res += ", "; + } + res += "["+jau::to_string(e)+"]"; + ++i; + } ); + res += "]"; + return res; + } +}; +// JAU_TYPENAME_CUE_ALL(NamedSharedPayloadListMemMove) + +template<class Payload> +using PayloadListMemMove = jau::darray<Payload, jau::callocator<Payload>, jau::nsize_t, true /* use_memmove */, true /* use_realloc */>; +// JAU_TYPENAME_CUE_ALL(PayloadListMemMove) + +template<class Payload> +using PayloadListDefault = jau::darray<Payload>; +// JAU_TYPENAME_CUE_ALL(PayloadListDefault) + +template<class Payload> +struct NamedPayloadListDefault { + int name; + PayloadListDefault<Payload> payload; + + std::string toString() const noexcept { + std::string res = "NPL-Default-"+std::to_string(name)+"[sz"+std::to_string(payload.size())+": "; + int i=0; + jau::for_each(payload.cbegin(), payload.cend(), [&](const typename PayloadListDefault<Payload>::value_type & e) { + if(0<i) { + res += ", "; + } + res += "["+jau::to_string(e)+"]"; + ++i; + } ); + res += "]"; + return res; + } +}; +// JAU_TYPENAME_CUE_ALL(NamedPayloadListDefault) + +template<class Payload> +struct NamedPayloadListMemMove { + int name; + PayloadListMemMove<Payload> payload; + + std::string toString() const noexcept { + std::string res = "NPL-MemMove-"+std::to_string(name)+"[sz"+std::to_string(payload.size())+": "; + int i=0; + jau::for_each(payload.cbegin(), payload.cend(), [&](const Payload& e) { + if(0<i) { + res += ", "; + } + res += "["+jau::to_string(e)+"]"; + ++i; + } ); + res += "]"; + return res; + } +}; +// JAU_TYPENAME_CUE_ALL(NamedPayloadListMemMove) + +template<class Payload> +static NamedSharedPayloadListDefault<Payload> makeNamedSharedPayloadListDefault(int name) { + SharedPayloadListDefault<Payload> data; + int i=0; + for(i=0; i<2; i++) { + std::shared_ptr<Payload> sp(std::make_shared<Payload>( name+i )); // copy-elision + make_shared in-place + data.push_back( sp ); + } + for(i=2; i<4; i++) { + std::shared_ptr<Payload> sp(new Payload( name+i )); // double malloc: 1 Payload, 2 shared_ptr + data.push_back( std::move( sp ) ); // move the less efficient into } - REQUIRE(fi == i); + return NamedSharedPayloadListDefault<Payload>{name, data}; } - -template<class T> -static void test_00_seq_fill(T& data, const std::size_t size) { - Addr48Bit a0(start_addr); - std::size_t i=0; - - for(; i<size && a0.next(); i++) { - data.emplace_back( a0, static_cast<uint8_t>(1) ); +template<class Payload> +static NamedSharedPayloadListMemMove<Payload> makeNamedSharedPayloadListMemMove(int name) { + SharedPayloadListMemMove<Payload> data; + int i=0; + for(i=0; i<2; i++) { + std::shared_ptr<Payload> sp(std::make_shared<Payload>( name+i )); // copy-elision + make_shared in-place + data.push_back( sp ); } - if( i != data.size() ) { - test_00_list_itr(data, true); - printf("a0 %s\n", a0.toString().c_str()); - printf("Size %zu, expected %zu, iter %zu\n", static_cast<std::size_t>(data.size()), size, i); + for(i=2; i<4; i++) { + std::shared_ptr<Payload> sp(new Payload( name+i )); // double malloc: 1 Payload, 2 shared_ptr + data.push_back( std::move( sp ) ); // move the less efficient into } - REQUIRE(i == data.size()); + return NamedSharedPayloadListMemMove<Payload>{name, data}; } - -template<class T> -static void test_00_seq_fill_unique_idx(T& data, const std::size_t size) { - Addr48Bit a0(start_addr); - std::size_t i=0, fi=0; - - for(; i<size && a0.next(); i++) { - DataType01 elem(a0, static_cast<uint8_t>(1)); - DataType01* exist = findDataSet01_idx(data, elem); - if( nullptr == exist ) { - data.push_back( std::move(elem) ); - fi++; - } else { - printf("Not unique #%zu: %s == %s (%d)\n", i, elem.toString().c_str(), exist->toString().c_str(), (elem == *exist)); - } +template<class Payload> +static NamedPayloadListDefault<Payload> makeNamedPayloadListDefault(int name) { + PayloadListDefault<Payload> data; + int i=0; + for(i=0; i<2; i++) { + Payload sp( name+i ); // copy-elision + data.push_back( sp ); } - if( fi != size ) { - test_00_list_idx(data, true); - printf("a0 %s\n", a0.toString().c_str()); - printf("Size %zu, expected %zu, iter %zu\n", static_cast<std::size_t>(data.size()), size, i); + for(i=2; i<4; i++) { + Payload sp( name+i ); + data.push_back( std::move( sp ) ); // move the less efficient into } - REQUIRE(i == data.size()); - REQUIRE(fi == size); + return NamedPayloadListDefault<Payload>{name, data}; } -template<class T> -static void test_00_seq_fill_unique_itr(T& data, const std::size_t size) { - Addr48Bit a0(start_addr); - std::size_t i=0, fi=0; - - for(; i<size && a0.next(); i++) { - DataType01 elem(a0, static_cast<uint8_t>(1)); - const DataType01* exist = jau::find_const(data, elem); - if( nullptr == exist ) { - data.push_back( std::move(elem) ); - fi++; - } else { - printf("Not unique #%zu: %s == %s (%d)\n", i, elem.toString().c_str(), exist->toString().c_str(), (elem == *exist)); - } +template<class Payload> +static NamedPayloadListMemMove<Payload> makeNamedPayloadListMemMove(int name) { + PayloadListMemMove<Payload> data; + int i=0; + for(i=0; i<2; i++) { + Payload sp( name+i ); // copy-elision + data.push_back( sp ); } - if( fi != size ) { - test_00_list_itr(data, true); - printf("a0 %s\n", a0.toString().c_str()); - printf("Size %zu, expected %zu, iter %zu\n", static_cast<std::size_t>(data.size()), size, i); + for(i=2; i<4; i++) { + Payload sp( name+i ); + data.push_back( std::move( sp ) ); // move the less efficient into } - REQUIRE(i == data.size()); - REQUIRE(fi == size); + return NamedPayloadListMemMove<Payload>{name, data}; } -/**************************************************************************************** - ****************************************************************************************/ +JAU_TYPENAME_CUE_ALL(std::shared_ptr<Addr48Bit>) +JAU_TYPENAME_CUE_ALL(jau::darray<Addr48Bit>) +JAU_TYPENAME_CUE_ALL(jau::darray<std::shared_ptr<Addr48Bit>>) -template<class T> -static bool test_01_seq_fill_list_idx(const std::string& type_id, const std::size_t size0, const std::size_t reserve0) { - (void)type_id; +JAU_TYPENAME_CUE_ALL(std::shared_ptr<DataType01>) +JAU_TYPENAME_CUE_ALL(jau::darray<DataType01>) +JAU_TYPENAME_CUE_ALL(jau::darray<std::shared_ptr<DataType01>>) - T data; - REQUIRE(0 == data.get_allocator().memory_usage); - REQUIRE(data.size() == 0); - REQUIRE(data.capacity() == 0); +#define CHECK_TRAITS 0 - if( 0 < reserve0 ) { - data.reserve(reserve0); - REQUIRE(data.size() == 0); - REQUIRE(0 != data.get_allocator().memory_usage); - REQUIRE(data.capacity() == reserve0); +template<class Payload> +static void testDArrayValueType(const std::string& type_id) { + { + // jau::type_cue<Payload>::print(type_id, jau::TypeTraitGroup::ALL); + // jau::type_cue<std::shared_ptr<Payload>>::print("std::shared_ptr<"+type_id+">", jau::TypeTraitGroup::ALL); } - - test_00_seq_fill(data, size0); - REQUIRE(0 != data.get_allocator().memory_usage); - REQUIRE(data.size() == size0); - - test_00_list_idx(data, false); - REQUIRE(0 != data.get_allocator().memory_usage); - REQUIRE(data.size() == size0); - - data.clear(); - REQUIRE(data.size() == 0); - // REQUIRE(0 == data.get_allocator().memory_usage); - return data.size() == 0; -} -template<class T> -static bool test_01_seq_fill_list_itr(const std::string& type_id, const std::size_t size0, const std::size_t reserve0) { - (void)type_id; - - T data; - REQUIRE(0 == data.get_allocator().memory_usage); - REQUIRE(data.size() == 0); - REQUIRE(data.capacity() == 0); - - if( 0 < reserve0 ) { - data.reserve(reserve0); - REQUIRE(data.size() == 0); - REQUIRE(0 != data.get_allocator().memory_usage); - REQUIRE(data.capacity() == reserve0); + { + printf("PayloadListDefault, value_type %s uses_memcpy %d, %s is_trivially_copyable %d\n", + type_id.c_str(), PayloadListDefault<Payload>::uses_memmove, + type_id.c_str(), std::is_trivially_copyable<Payload>::value); + printf("PayloadListDefault, value_type %s uses_realloc %d, is_base_of jau::callocator %d\n", + type_id.c_str(), PayloadListDefault<Payload>::uses_realloc, + std::is_base_of<jau::callocator<Payload>, jau::callocator<Payload>>::value); + +#if CHECK_TRAITS + CHECK( true == std::is_base_of<jau::callocator<Payload>, jau::callocator<Payload>>::value); + CHECK( true == PayloadListDefault<Payload>::uses_realloc); + CHECK( true == std::is_trivially_copyable<Payload>::value); + CHECK( true == PayloadListDefault<Payload>::uses_memmove); +#endif + + NamedPayloadListDefault<Payload> data = makeNamedPayloadListDefault<Payload>(1); + + NamedPayloadListDefault<Payload> data2 = data; + data2.payload.erase(data2.payload.cbegin()); + + NamedPayloadListDefault<Payload> data3(data); + data3.payload.erase(data3.payload.begin(), data3.payload.cbegin()+data3.payload.size()/2); + + NamedPayloadListDefault<Payload> data8 = makeNamedPayloadListDefault<Payload>(8); + data8.payload.insert(data8.payload.begin(), data.payload.cbegin(), data.payload.cend()); + + printf("COPY-0: %s\n\n", data.toString().c_str()); + printf("COPY-1: %s\n\n", data2.toString().c_str()); + printf("COPY-2: %s\n\n", data3.toString().c_str()); + printf("COPY+2: %s\n\n", data8.toString().c_str()); } - - test_00_seq_fill(data, size0); - REQUIRE(0 != data.get_allocator().memory_usage); - REQUIRE(data.size() == size0); - - test_00_list_itr(data, false); - REQUIRE(0 != data.get_allocator().memory_usage); - REQUIRE(data.size() == size0); - - data.clear(); - REQUIRE(data.size() == 0); - // REQUIRE(0 == data.get_allocator().memory_usage); - return data.size() == 0; -} - -template<class T> -static bool test_02_seq_fillunique_find_idx(const std::string& type_id, const std::size_t size0, const std::size_t reserve0) { - (void)type_id; - - T data; - REQUIRE(0 == data.get_allocator().memory_usage); - REQUIRE(data.size() == 0); - REQUIRE(data.capacity() == 0); - - if( 0 < reserve0 ) { - data.reserve(reserve0); - REQUIRE(data.size() == 0); - REQUIRE(0 != data.get_allocator().memory_usage); - REQUIRE(data.capacity() == reserve0); + { + printf("PayloadListMemMove, value_type %s uses_memcpy %d, %s is_trivially_copyable %d\n", + type_id.c_str(), PayloadListMemMove<Payload>::uses_memmove, + type_id.c_str(), std::is_trivially_copyable<Payload>::value); + printf("PayloadListMemMove, value_type %s uses_realloc %d, is_base_of jau::callocator %d\n", + type_id.c_str(), PayloadListMemMove<Payload>::uses_realloc, + std::is_base_of<jau::callocator<Payload>, jau::callocator<Payload>>::value); + +#if CHECK_TRAITS + CHECK( true == std::is_base_of<jau::callocator<Payload>, jau::callocator<Payload>>::value); + CHECK( true == PayloadListMemMove<Payload>::uses_realloc); + CHECK( true == std::is_trivially_copyable<Payload>::value); + CHECK( true == PayloadListMemMove<Payload>::uses_memmove); +#endif + + NamedPayloadListMemMove<Payload> data = makeNamedPayloadListMemMove<Payload>(1); + + NamedPayloadListMemMove<Payload> data2 = data; + data2.payload.erase(data2.payload.cbegin()); + + NamedPayloadListMemMove<Payload> data3(data); + data3.payload.erase(data3.payload.begin(), data3.payload.cbegin()+data3.payload.size()/2); + + NamedPayloadListMemMove<Payload> data8 = makeNamedPayloadListMemMove<Payload>(8); + data8.payload.insert(data8.payload.begin(), data.payload.cbegin(), data.payload.cend()); + + printf("COPY-0: %s\n\n", data.toString().c_str()); + printf("COPY-1: %s\n\n", data2.toString().c_str()); + printf("COPY-2: %s\n\n", data3.toString().c_str()); + printf("COPY+2: %s\n\n", data8.toString().c_str()); } - - test_00_seq_fill_unique_idx(data, size0); - REQUIRE(0 != data.get_allocator().memory_usage); - REQUIRE(data.size() == size0); - - test_00_seq_find_idx(data); - REQUIRE(0 != data.get_allocator().memory_usage); - REQUIRE(data.size() == size0); - - data.clear(); - REQUIRE(data.size() == 0); - // REQUIRE(0 == data.get_allocator().memory_usage); - return data.size() == 0; -} -template<class T> -static bool test_02_seq_fillunique_find_itr(const std::string& type_id, const std::size_t size0, const std::size_t reserve0) { - (void)type_id; - - T data; - REQUIRE(0 == data.get_allocator().memory_usage); - REQUIRE(data.size() == 0); - REQUIRE(data.capacity() == 0); - - if( 0 < reserve0 ) { - data.reserve(reserve0); - REQUIRE(data.size() == 0); - REQUIRE(0 != data.get_allocator().memory_usage); - REQUIRE(data.capacity() == reserve0); + { + printf("SharedPayloadListDefault, value_type std::shared_ptr<%s> uses_memcpy %d, std::shared_ptr<%s> is_trivially_copyable = %d\n", + type_id.c_str(), SharedPayloadListDefault<Payload>::uses_memmove, + type_id.c_str(), std::is_trivially_copyable<std::shared_ptr<Payload>>::value); + printf("SharedPayloadListDefault, value_type std::shared_ptr<%s> uses_realloc %d, is_base_of jau::callocator %d\n", + type_id.c_str(), SharedPayloadListDefault<Payload>::uses_realloc, + std::is_base_of<jau::callocator<std::shared_ptr<Payload>>, jau::callocator<std::shared_ptr<Payload>>>::value); + +#if CHECK_TRAITS + CHECK( true == std::is_base_of<jau::callocator<std::shared_ptr<Payload>>, jau::callocator<std::shared_ptr<Payload>>>::value); + CHECK( true == SharedPayloadListDefault<Payload>::uses_realloc); + CHECK( true == std::is_trivially_copyable<std::shared_ptr<Payload>>::value); + CHECK( true == SharedPayloadListDefault<Payload>::uses_memmove); +#endif + + NamedSharedPayloadListDefault<Payload> data = makeNamedSharedPayloadListDefault<Payload>(1); + + NamedSharedPayloadListDefault<Payload> data2 = data; + data2.payload.erase(data2.payload.cbegin()); + + NamedSharedPayloadListDefault<Payload> data3(data); + data3.payload.erase(data3.payload.begin(), data3.payload.cbegin()+data3.payload.size()/2); + + NamedSharedPayloadListDefault<Payload> data8 = makeNamedSharedPayloadListDefault<Payload>(8); + data8.payload.insert(data8.payload.begin(), data.payload.cbegin(), data.payload.cend()); + + printf("COPY-0: %s\n\n", data.toString().c_str()); + printf("COPY-1: %s\n\n", data2.toString().c_str()); + printf("COPY-2: %s\n\n", data3.toString().c_str()); + printf("COPY+2: %s\n\n", data8.toString().c_str()); + } + { + printf("SharedPayloadListMemMove, value_type std::shared_ptr<%s> uses_memcpy %d, std::shared_ptr<%s> is_trivially_copyable = %d\n", + type_id.c_str(), SharedPayloadListMemMove<Payload>::uses_memmove, + type_id.c_str(), std::is_trivially_copyable<std::shared_ptr<Payload>>::value); + printf("SharedPayloadListMemMove, value_type std::shared_ptr<%s> uses_realloc %d, is_base_of jau::callocator %d\n", + type_id.c_str(), SharedPayloadListMemMove<Payload>::uses_realloc, + std::is_base_of<jau::callocator<std::shared_ptr<Payload>>, jau::callocator<std::shared_ptr<Payload>>>::value); + +#if CHECK_TRAITS + CHECK( true == std::is_base_of<jau::callocator<std::shared_ptr<Payload>>, jau::callocator<std::shared_ptr<Payload>>>::value); + CHECK( true == SharedPayloadListMemMove<Payload>::uses_realloc); + CHECK( true == std::is_trivially_copyable<std::shared_ptr<Payload>>::value); + CHECK( true == SharedPayloadListMemMove<Payload>::uses_memmove); +#endif + + NamedSharedPayloadListMemMove<Payload> data = makeNamedSharedPayloadListMemMove<Payload>(1); + + NamedSharedPayloadListMemMove<Payload> data2 = data; + data2.payload.erase(data2.payload.cbegin()); + + NamedSharedPayloadListMemMove<Payload> data3(data); + data3.payload.erase(data3.payload.begin(), data3.payload.cbegin()+data3.payload.size()/2); + + NamedSharedPayloadListMemMove<Payload> data8 = makeNamedSharedPayloadListMemMove<Payload>(8); + data8.payload.insert(data8.payload.begin(), data.payload.cbegin(), data.payload.cend()); + + printf("COPY-0: %s\n\n", data.toString().c_str()); + printf("COPY-1: %s\n\n", data2.toString().c_str()); + printf("COPY-2: %s\n\n", data3.toString().c_str()); + printf("COPY+2: %s\n\n", data8.toString().c_str()); } - - test_00_seq_fill_unique_itr(data, size0); - REQUIRE(0 != data.get_allocator().memory_usage); - REQUIRE(data.size() == size0); - - test_00_seq_find_itr(data); - REQUIRE(0 != data.get_allocator().memory_usage); - REQUIRE(data.size() == size0); - - data.clear(); - REQUIRE(data.size() == 0); - // REQUIRE(0 == data.get_allocator().memory_usage); - return data.size() == 0; -} - -/**************************************************************************************** - ****************************************************************************************/ - -TEST_CASE( "STD Vector Test 01 - Fill Sequential and List", "[datatype][std][vector]" ) { - test_01_seq_fill_list_idx< std::vector<DataType01, counting_allocator<DataType01>> >("stdvec_fillseq_empty__", 100, 0); - test_01_seq_fill_list_idx< std::vector<DataType01, counting_allocator<DataType01>> >("stdvec_fillseq_reserve", 100, 100); - - test_01_seq_fill_list_itr< std::vector<DataType01, counting_allocator<DataType01>> >("stdvec_fillseq_empty__", 100, 0); - test_01_seq_fill_list_itr< std::vector<DataType01, counting_allocator<DataType01>> >("stdvec_fillseq_reserve", 100, 100); } -TEST_CASE( "STD Vector Test 02 - Fill Unique and Find-Each", "[datatype][std][vector]" ) { - test_02_seq_fillunique_find_idx< std::vector<DataType01, counting_allocator<DataType01>> >("stdvec_filluni_empty__", 100, 0); - test_02_seq_fillunique_find_idx< std::vector<DataType01, counting_allocator<DataType01>> >("stdvec_filluni_reserve", 100, 100); - - test_02_seq_fillunique_find_itr< std::vector<DataType01, counting_allocator<DataType01>> >("stdvec_filluni_empty__", 100, 0); - test_02_seq_fillunique_find_itr< std::vector<DataType01, counting_allocator<DataType01>> >("stdvec_filluni_reserve", 100, 100); +static GattServiceCharacteristic returnGattSrvcChar(int i) { + return *GATT_SERVICES[i]; } -TEST_CASE( "JAU COW_Vector Test 11 - Fill Sequential and List", "[datatype][jau][cow_vector]" ) { - // test_01_seq_fill_list_idx< jau::cow_vector<DataType01, counting_allocator<DataType01>> >("cowstdvec_fillseq_empty__", 100, 0); - // test_01_seq_fill_list_idx< jau::cow_vector<DataType01, counting_allocator<DataType01>> >("cowstdvec_fillseq_reserve", 100, 100); +static void testDArrayGattServiceCharacteristic() { + typedef jau::darray<GattCharacteristicSpec> GattCharacteristicSpecList; - test_01_seq_fill_list_itr< jau::cow_vector<DataType01, counting_allocator<DataType01>> >("cowstdvec_fillseq_empty__", 100, 0); - test_01_seq_fill_list_itr< jau::cow_vector<DataType01, counting_allocator<DataType01>> >("cowstdvec_fillseq_reserve", 100, 100); -} + printf("GattCharacteristicSpecList, value_type GattCharacteristicSpec: uses_memcpy %d, is_trivially_copyable = %d\n", + GattCharacteristicSpecList::uses_memmove, + std::is_trivially_copyable<GattCharacteristicSpec>::value); + printf("GattCharacteristicSpecList, value_type GattCharacteristicSpec: uses_realloc = %d, is_base_of jau::callocator %d\n", + GattCharacteristicSpecList::uses_realloc, + std::is_base_of<jau::callocator<GattCharacteristicSpec>, jau::callocator<GattCharacteristicSpec>>::value); + // jau::type_cue<GattCharacteristicSpec>::print("GattCharacteristicSpec", jau::TypeTraitGroup::ALL); -TEST_CASE( "JAU COW_Vector Test 12 - Fill Unique and Find-Each", "[datatype][jau][cow_vector]" ) { - // test_02_seq_fillunique_find_idx< jau::cow_vector<DataType01, counting_allocator<DataType01>> >("cowstdvec_filluni_empty__", 100, 0); - // test_02_seq_fillunique_find_idx< jau::cow_vector<DataType01, counting_allocator<DataType01>> >("cowstdvec_filluni_reserve", 100, 100); +#if CHECK_TRAITS + CHECK( true == std::is_base_of<jau::callocator<GattCharacteristicSpec>, jau::callocator<GattCharacteristicSpec>>::value); + CHECK( true == GattCharacteristicSpecList::uses_realloc); - test_02_seq_fillunique_find_itr< jau::cow_vector<DataType01, counting_allocator<DataType01>> >("cowstdvec_filluni_empty__", 100, 0); - test_02_seq_fillunique_find_itr< jau::cow_vector<DataType01, counting_allocator<DataType01>> >("cowstdvec_filluni_reserve", 100, 100); -} + CHECK( true == GattCharacteristicSpecList::uses_memmove); + CHECK( true == std::is_trivially_copyable<GattCharacteristicSpec>::value); +#endif -TEST_CASE( "JAU DArray Test 21 - Fill Sequential and List", "[datatype][jau][darray]" ) { - test_01_seq_fill_list_idx< jau::darray<DataType01, counting_callocator<DataType01>> >("darray_fillseq_empty__", 100, 0); - test_01_seq_fill_list_idx< jau::darray<DataType01, counting_callocator<DataType01>> >("darray_fillseq_reserve", 100, 100); + GattServiceCharacteristic gatt2 = returnGattSrvcChar(1); + gatt2.characteristics.erase(gatt2.characteristics.cbegin()); - test_01_seq_fill_list_itr< jau::darray<DataType01, counting_callocator<DataType01>> >("darray_fillseq_empty__", 100, 0); - test_01_seq_fill_list_itr< jau::darray<DataType01, counting_callocator<DataType01>> >("darray_fillseq_reserve", 100, 100); -} + GattServiceCharacteristic gatt2b = gatt2; + gatt2b.characteristics.erase(gatt2b.characteristics.cbegin()); -TEST_CASE( "JAU DArray Test 22 - Fill Unique and Find-Each", "[datatype][jau][darray]" ) { - test_02_seq_fillunique_find_idx< jau::darray<DataType01, counting_callocator<DataType01>> >("darray_filluni_empty__", 100, 0); - test_02_seq_fillunique_find_idx< jau::darray<DataType01, counting_callocator<DataType01>> >("darray_filluni_reserve", 100, 100); + GattServiceCharacteristic gatt2c(gatt2); + gatt2c.characteristics.erase(gatt2c.characteristics.cbegin()); - test_02_seq_fillunique_find_itr< jau::darray<DataType01, counting_callocator<DataType01>> >("darray_filluni_empty__", 100, 0); - test_02_seq_fillunique_find_itr< jau::darray<DataType01, counting_callocator<DataType01>> >("darray_filluni_reserve", 100, 100); + printf("COPY0-1: %s\n\n", gatt2.toString().c_str()); + printf("COPY1-2: %s\n\n", gatt2b.toString().c_str()); + printf("COPY2-3: %s\n\n", gatt2c.toString().c_str()); } -TEST_CASE( "JAU COW_DArray Test 31 - Fill Sequential and List", "[datatype][jau][cow_darray]" ) { - // test_01_seq_fill_list_idx< jau::cow_darray<DataType01, counting_callocator<DataType01>> >("cowdarray_fillseq_empty__", 100, 0); - // test_01_seq_fill_list_idx< jau::cow_darray<DataType01, counting_callocator<DataType01>> >("cowdarray_fillseq_reserve", 100, 100); - - test_01_seq_fill_list_itr< jau::cow_darray<DataType01, counting_callocator<DataType01>> >("cowdarray_fillseq_empty__", 100, 0); - test_01_seq_fill_list_itr< jau::cow_darray<DataType01, counting_callocator<DataType01>> >("cowdarray_fillseq_reserve", 100, 100); +TEST_CASE( "JAU DArray Test 02 - jau::darray value_type behavior (type traits)", "[datatype][jau][darray]" ) { + testDArrayValueType<uint64_t>("uint64_t"); + testDArrayValueType<Addr48Bit>("Addr48Bit"); + testDArrayValueType<DataType01>("DataType01"); + testDArrayGattServiceCharacteristic(); } -TEST_CASE( "JAU COW_DArray Test 32 - Fill Unique and Find-Each", "[datatype][jau][cow_darray]" ) { - // test_02_seq_fillunique_find_idx< jau::cow_darray<DataType01, counting_callocator<DataType01>> >("cowdarray_filluni_empty__", 100, 0); - // test_02_seq_fillunique_find_idx< jau::cow_darray<DataType01, counting_callocator<DataType01>> >("cowdarray_filluni_reserve", 100, 100); +/**********************************************************************************************************************************************/ +/**********************************************************************************************************************************************/ +/**********************************************************************************************************************************************/ +/**********************************************************************************************************************************************/ +/**********************************************************************************************************************************************/ - test_02_seq_fillunique_find_itr< jau::cow_darray<DataType01, counting_callocator<DataType01>> >("cowdarray_filluni_empty__", 100, 0); - test_02_seq_fillunique_find_itr< jau::cow_darray<DataType01, counting_callocator<DataType01>> >("cowdarray_filluni_reserve", 100, 100); -} |