mirror of
https://github.com/ETLCPP/etl.git
synced 2026-10-28 18:07:10 +08:00
Interim fixes
This commit is contained in:
parent
36d126c93e
commit
90e4316f8f
@ -454,7 +454,13 @@ namespace etl
|
||||
//*********************************************************************
|
||||
iterator begin()
|
||||
{
|
||||
return iterator(lookup.begin());
|
||||
etl::ivector<T*>& ivr = lookup;
|
||||
|
||||
bool e = ivr.empty();
|
||||
|
||||
typename etl::ivector<T*>::iterator itr = ivr.begin();
|
||||
|
||||
return iterator(itr);
|
||||
}
|
||||
|
||||
//*********************************************************************
|
||||
|
||||
@ -87,7 +87,7 @@ namespace etl
|
||||
do
|
||||
{
|
||||
++p_current;
|
||||
} while (p_current->empty() && (p_current != p_end));
|
||||
} while ((p_current != p_end) && p_current->empty());
|
||||
|
||||
if (p_current != p_end)
|
||||
{
|
||||
@ -171,7 +171,10 @@ namespace etl
|
||||
, p_end(p_end_)
|
||||
, p_value(ETL_NULLPTR)
|
||||
{
|
||||
p_value = p_current->begin();
|
||||
if (p_current != p_end)
|
||||
{
|
||||
p_value = p_current->begin();
|
||||
}
|
||||
}
|
||||
|
||||
typedef const span_type* span_list_pointer;
|
||||
|
||||
@ -326,6 +326,8 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions")
|
||||
endif()
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address,undefined")
|
||||
|
||||
add_executable(etl_tests ${TEST_SOURCE_FILES})
|
||||
add_library(unit_test ${UNITTEST_SOURCE_FILES})
|
||||
|
||||
|
||||
@ -210,7 +210,7 @@ namespace
|
||||
{
|
||||
Data data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
|
||||
CHECK_EQUAL(data.end(), &data[SIZE]);
|
||||
CHECK_EQUAL(data.end(), data.data() + SIZE);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -218,7 +218,7 @@ namespace
|
||||
{
|
||||
const Data data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
|
||||
CHECK_EQUAL(data.cbegin(), &data[0]);
|
||||
CHECK_EQUAL(data.cbegin(), data.data());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -226,7 +226,7 @@ namespace
|
||||
{
|
||||
const Data data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
|
||||
CHECK_EQUAL(data.cend(), &data[SIZE]);
|
||||
CHECK_EQUAL(data.cend(), data.data() + SIZE);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -234,7 +234,7 @@ namespace
|
||||
{
|
||||
Data data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
|
||||
CHECK(data.rbegin() == Data::reverse_iterator(&data[SIZE]));
|
||||
CHECK(data.rbegin() == Data::reverse_iterator(data.data() + SIZE));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -250,7 +250,7 @@ namespace
|
||||
{
|
||||
const Data data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
|
||||
CHECK(data.crbegin() == Data::const_reverse_iterator(&data[SIZE]));
|
||||
CHECK(data.crbegin() == Data::const_reverse_iterator(data.data() + SIZE));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
|
||||
@ -261,26 +261,26 @@ namespace
|
||||
TEST(test_rend)
|
||||
{
|
||||
Data5 aw5;
|
||||
CHECK_EQUAL(&data5[Data5::REND], &*aw5.rend());
|
||||
CHECK_EQUAL(data5 + Data5::REND, std::addressof(*aw5.rend()));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_crbegin)
|
||||
{
|
||||
Data5 aw5;
|
||||
CHECK_EQUAL(&data5[Data5::RBEGIN], &*aw5.crbegin());
|
||||
CHECK_EQUAL(data5 + Data5::RBEGIN, &*aw5.crbegin());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_crend)
|
||||
{
|
||||
const Data5 caw5a;
|
||||
CHECK_EQUAL(&data5[Data5::REND], &*caw5a.rend());
|
||||
CHECK_EQUAL(&data5[Data5::REND], &*caw5a.crend());
|
||||
CHECK_EQUAL(caw5a.data() + Data5::REND, std::addressof(*caw5a.rend()));
|
||||
CHECK_EQUAL(caw5a.data() + Data5::REND, std::addressof(*caw5a.crend()));
|
||||
|
||||
CData5 caw5b;
|
||||
CHECK_EQUAL(&cdata5[CData5::REND], &*caw5b.rend());
|
||||
CHECK_EQUAL(&cdata5[CData5::REND], &*caw5b.crend());
|
||||
CHECK_EQUAL(caw5b.data() + CData5::REND, std::addressof(*caw5b.rend()));
|
||||
CHECK_EQUAL(caw5b.data() + CData5::REND, std::addressof(*caw5b.crend()));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -290,7 +290,7 @@ namespace
|
||||
Data5::iterator itr = aw5.begin();
|
||||
int* p = data5;
|
||||
|
||||
while (p != &data5[Data5::END])
|
||||
while (p != data5 + Data5::END)
|
||||
{
|
||||
CHECK_EQUAL(*p, *itr);
|
||||
++p;
|
||||
@ -311,7 +311,7 @@ namespace
|
||||
Data5::const_iterator itr = caw5a.begin();
|
||||
int* p = data5;
|
||||
|
||||
while (p != &data5[Data5::END])
|
||||
while (p != data5 + Data5::END)
|
||||
{
|
||||
CHECK_EQUAL(*p, *itr);
|
||||
++p;
|
||||
@ -327,9 +327,9 @@ namespace
|
||||
{
|
||||
Data5 aw5;
|
||||
Data5::reverse_iterator itr = aw5.rbegin();
|
||||
int* p = &data5[Data5::RBEGIN];
|
||||
int* p = data5 + Data5::RBEGIN;
|
||||
|
||||
while (p != &data5[Data5::REND])
|
||||
while (p != data5 + Data5::REND)
|
||||
{
|
||||
CHECK_EQUAL(*p, *itr);
|
||||
--p;
|
||||
@ -348,9 +348,9 @@ namespace
|
||||
{
|
||||
Data5 aw5;
|
||||
Data5::const_reverse_iterator itr = aw5.crbegin();
|
||||
int* p = &data5[Data5::RBEGIN];
|
||||
int* p = data5 + Data5::RBEGIN;
|
||||
|
||||
while (p != &data5[Data5::REND])
|
||||
while (p != data5 + Data5::REND)
|
||||
{
|
||||
CHECK_EQUAL(*p, *itr);
|
||||
--p;
|
||||
@ -564,7 +564,7 @@ namespace
|
||||
size_t hash = etl::hash<Data5>()(aw5);
|
||||
|
||||
|
||||
size_t compare_hash = etl::private_hash::generic_hash<size_t>(reinterpret_cast<const uint8_t*>(&data5[0]), reinterpret_cast<const uint8_t*>(&data5[5]));
|
||||
size_t compare_hash = etl::private_hash::generic_hash<size_t>(reinterpret_cast<const uint8_t*>(data5), reinterpret_cast<const uint8_t*>(data5 + 5U));
|
||||
|
||||
|
||||
CHECK_EQUAL(compare_hash, hash);
|
||||
|
||||
@ -1199,7 +1199,7 @@ namespace
|
||||
//*************************************************************************
|
||||
TEST(test_bit_ceil_8)
|
||||
{
|
||||
for (size_t i = 0; i < 256; ++i)
|
||||
for (size_t i = 0; i < 128; ++i)
|
||||
{
|
||||
uint8_t value = uint8_t(i);
|
||||
|
||||
@ -1226,7 +1226,7 @@ namespace
|
||||
{
|
||||
hash.add(1);
|
||||
|
||||
uint16_t value = hash.value();
|
||||
uint16_t value = hash.value() & 0x7FFF;
|
||||
|
||||
CHECK_EQUAL(test_bit_ceil(value), etl::bit_ceil(value));
|
||||
|
||||
@ -1256,7 +1256,7 @@ namespace
|
||||
{
|
||||
hash.add(1);
|
||||
|
||||
uint32_t value = hash.value();
|
||||
uint32_t value = hash.value() & 0x7FFFFFFF;
|
||||
|
||||
CHECK_EQUAL(test_bit_ceil(value), etl::bit_ceil(value));
|
||||
|
||||
@ -1286,7 +1286,7 @@ namespace
|
||||
{
|
||||
hash.add(1);
|
||||
|
||||
uint64_t value = hash.value();
|
||||
uint64_t value = hash.value() & 0x7FFFFFFFFFFFFFFF;
|
||||
|
||||
CHECK_EQUAL(test_bit_ceil(value), etl::bit_ceil(value));
|
||||
|
||||
|
||||
@ -735,26 +735,33 @@ namespace
|
||||
size_t timer_count = 0U;
|
||||
|
||||
// Create the callbacks.
|
||||
callback_type delegate_callback0([&]()
|
||||
{
|
||||
timer_log.push_back(TimerLogEntry{ 0, timer_count });
|
||||
});
|
||||
static auto dc0 = [&]()
|
||||
{
|
||||
timer_log.push_back(TimerLogEntry{ 0, timer_count });
|
||||
};
|
||||
|
||||
static auto dc1 = [&]()
|
||||
{
|
||||
timer_log.push_back(TimerLogEntry{ 1, timer_count });
|
||||
};
|
||||
|
||||
static auto dc2 = [&]()
|
||||
{
|
||||
timer_log.push_back(TimerLogEntry{ 2, timer_count });
|
||||
};
|
||||
|
||||
static auto dc3 = [&]()
|
||||
{
|
||||
timer_log.push_back(TimerLogEntry{ 3, timer_count });
|
||||
};
|
||||
|
||||
callback_type delegate_callback0(dc0);
|
||||
|
||||
callback_type delegate_callback1([&]()
|
||||
{
|
||||
timer_log.push_back(TimerLogEntry{ 1, timer_count });
|
||||
});
|
||||
callback_type delegate_callback1(dc1);
|
||||
|
||||
callback_type delegate_callback2([&]()
|
||||
{
|
||||
timer_log.push_back(TimerLogEntry{ 2, timer_count });
|
||||
});
|
||||
callback_type delegate_callback2(dc2);
|
||||
|
||||
callback_type delegate_callback3([&]()
|
||||
{
|
||||
timer_log.push_back(TimerLogEntry{ 3, timer_count });
|
||||
timer_controller.start(1);
|
||||
});
|
||||
callback_type delegate_callback3(dc3);
|
||||
|
||||
timer_log.clear();
|
||||
timer_controller.enable(true);
|
||||
|
||||
@ -1,283 +1,283 @@
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
https://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2021 jwellbelove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#include "unit_test_framework.h"
|
||||
|
||||
#include "etl/mem_cast.h"
|
||||
#include "etl/largest.h"
|
||||
|
||||
#include <array>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
namespace
|
||||
{
|
||||
#pragma pack(push,1)
|
||||
struct Data
|
||||
{
|
||||
Data()
|
||||
: c(0)
|
||||
, d(0)
|
||||
, a()
|
||||
{
|
||||
}
|
||||
|
||||
Data(char c_, double d_, std::array<int, 3> a_)
|
||||
: c(c_)
|
||||
, d(d_)
|
||||
, a(a_)
|
||||
{
|
||||
}
|
||||
|
||||
char c;
|
||||
double d;
|
||||
std::array<int, 3> a;
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
constexpr size_t Size = etl::largest<char, double, Data>::size;
|
||||
constexpr size_t Alignment = etl::largest<char, double, Data>::alignment;
|
||||
|
||||
// Test variant types.
|
||||
using MemCast = etl::mem_cast<Size, Alignment>;
|
||||
using MemCastTypes = etl::mem_cast_types<char, double, Data>;
|
||||
|
||||
Data data;
|
||||
|
||||
SUITE(test_mem_cast)
|
||||
{
|
||||
//*************************************************************************
|
||||
TEST(test_size)
|
||||
{
|
||||
MemCast memCast;
|
||||
MemCastTypes memCastTypes;
|
||||
|
||||
CHECK(sizeof(char) <= MemCast::Size);
|
||||
CHECK(sizeof(short) <= MemCast::Size);
|
||||
CHECK(sizeof(Data) <= MemCast::Size);
|
||||
|
||||
CHECK(sizeof(char) <= memCast.Size);
|
||||
CHECK(sizeof(short) <= memCast.Size);
|
||||
CHECK(sizeof(Data) <= memCast.Size);
|
||||
|
||||
CHECK(sizeof(char) <= memCast.size());
|
||||
CHECK(sizeof(short) <= memCast.size());
|
||||
CHECK(sizeof(Data) <= memCast.size());
|
||||
|
||||
CHECK(sizeof(char) <= MemCastTypes::Size);
|
||||
CHECK(sizeof(short) <= MemCastTypes::Size);
|
||||
CHECK(sizeof(Data) <= MemCastTypes::Size);
|
||||
|
||||
CHECK(sizeof(char) <= memCastTypes.Size);
|
||||
CHECK(sizeof(short) <= memCastTypes.Size);
|
||||
CHECK(sizeof(Data) <= memCastTypes.Size);
|
||||
|
||||
CHECK(sizeof(char) <= memCastTypes.size());
|
||||
CHECK(sizeof(short) <= memCastTypes.size());
|
||||
CHECK(sizeof(Data) <= memCastTypes.size());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_alignment)
|
||||
{
|
||||
MemCast memCast;
|
||||
MemCastTypes memCastTypes;
|
||||
|
||||
CHECK(alignof(char) <= MemCast::Alignment);
|
||||
CHECK(alignof(short) <= MemCast::Alignment);
|
||||
CHECK(alignof(Data) <= MemCast::Alignment);
|
||||
|
||||
CHECK(alignof(char) <= memCast.Alignment);
|
||||
CHECK(alignof(short) <= memCast.Alignment);
|
||||
CHECK(alignof(Data) <= memCast.Alignment);
|
||||
|
||||
CHECK(alignof(char) <= memCast.alignment());
|
||||
CHECK(alignof(short) <= memCast.alignment());
|
||||
CHECK(alignof(Data) <= memCast.alignment());
|
||||
|
||||
CHECK(alignof(char) <= MemCastTypes::Alignment);
|
||||
CHECK(alignof(short) <= MemCastTypes::Alignment);
|
||||
CHECK(alignof(Data) <= MemCastTypes::Alignment);
|
||||
|
||||
CHECK(alignof(char) <= memCastTypes.Alignment);
|
||||
CHECK(alignof(short) <= memCastTypes.Alignment);
|
||||
CHECK(alignof(Data) <= memCastTypes.Alignment);
|
||||
|
||||
CHECK(alignof(char) <= memCastTypes.alignment());
|
||||
CHECK(alignof(short) <= memCastTypes.alignment());
|
||||
CHECK(alignof(Data) <= memCastTypes.alignment());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_mem_cast_assign_type)
|
||||
{
|
||||
MemCast memCast;
|
||||
|
||||
memCast.assign<char>(123);
|
||||
CHECK_EQUAL(123, memCast.ref<char>());
|
||||
|
||||
memCast.assign<double>(1.23);
|
||||
CHECK_EQUAL(1.23, memCast.ref<double>());
|
||||
|
||||
Data data(123, 1.23, std::array<int, 3>{ 1, 2, 3 });
|
||||
memCast.assign<Data>(data);
|
||||
CHECK(123 == memCast.ref<Data>().c);
|
||||
CHECK(1.23 == memCast.ref<Data>().d);
|
||||
CHECK((std::array { 1, 2, 3 }) == memCast.ref<Data>().a);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_mem_cast_assign_type_at_dynamic_offset)
|
||||
{
|
||||
MemCast memCast;
|
||||
|
||||
using Array = std::array<int, 3>;
|
||||
Array a{ 1, 2, 3 };
|
||||
|
||||
size_t offset = offsetof(Data, a);
|
||||
|
||||
memCast.assign_at_offset<Array>(offset, a);
|
||||
CHECK(a == memCast.ref<Data>().a);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_mem_cast_assign_type_at_static_offset)
|
||||
{
|
||||
MemCast memCast;
|
||||
|
||||
using Array = std::array<int, 3>;
|
||||
Array a{ 1, 2, 3 };
|
||||
|
||||
constexpr size_t Offset = offsetof(Data, a);
|
||||
|
||||
memCast.assign_at_offset<Array, Offset>(a);
|
||||
CHECK(a == memCast.ref<Data>().a);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_mem_cast_emplace_type)
|
||||
{
|
||||
MemCast memCast;
|
||||
|
||||
memCast.emplace<char>(123);
|
||||
CHECK_EQUAL(123, memCast.ref<char>());
|
||||
|
||||
memCast.emplace<double>(1.23);
|
||||
CHECK_EQUAL(1.23, memCast.ref<double>());
|
||||
|
||||
memCast.emplace<Data>(123, 1.23, std::array<int, 3>{ 1, 2, 3 });
|
||||
CHECK(123 == memCast.ref<Data>().c);
|
||||
CHECK(1.23 == memCast.ref<Data>().d);
|
||||
CHECK((std::array { 1, 2, 3 }) == memCast.ref<Data>().a);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_mem_cast_emplace_type_at_dynamic_offset)
|
||||
{
|
||||
MemCast memCast;
|
||||
|
||||
using Array = std::array<int, 3>;
|
||||
Array a{ 1, 2, 3 };
|
||||
|
||||
size_t offset = offsetof(Data, a);
|
||||
|
||||
memCast.emplace_at_offset<Array>(offset, a);
|
||||
CHECK(a == memCast.ref<Data>().a);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_mem_cast_emplace_type_at_static_offset)
|
||||
{
|
||||
MemCast memCast;
|
||||
|
||||
using Array = std::array<int, 3>;
|
||||
Array a{ 1, 2, 3 };
|
||||
|
||||
constexpr size_t Offset = offsetof(Data, a);
|
||||
|
||||
memCast.emplace_at_offset<Array, Offset>(a);
|
||||
CHECK(a == memCast.ref<Data>().a);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_mem_cast_to_type)
|
||||
{
|
||||
MemCast memCast;
|
||||
|
||||
char* pbuffer = memCast.data();
|
||||
*pbuffer = 123;
|
||||
CHECK_EQUAL(123, memCast.ref<char>());
|
||||
|
||||
*reinterpret_cast<double*>(pbuffer) = 1.23;
|
||||
CHECK_EQUAL(1.23, memCast.ref<double>());
|
||||
|
||||
*reinterpret_cast<Data*>(pbuffer) = { 123, 1.23, { 1, 2, 3 } };
|
||||
CHECK(123 == memCast.ref<Data>().c);
|
||||
CHECK(1.23 == memCast.ref<Data>().d);
|
||||
CHECK((std::array { 1, 2, 3 }) == memCast.ref<Data>().a);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_const_mem_cast_to_type)
|
||||
{
|
||||
MemCast memCast;
|
||||
const MemCast& memCastRef = memCast;
|
||||
|
||||
char* pbuffer = memCast.data();
|
||||
*pbuffer = 123;
|
||||
CHECK_EQUAL(123, memCastRef.ref<char>());
|
||||
|
||||
*reinterpret_cast<double*>(pbuffer) = 1.23;
|
||||
CHECK_EQUAL(1.23, memCastRef.ref<double>());
|
||||
|
||||
*reinterpret_cast<Data*>(pbuffer) = { 123, 1.23, { 1, 2, 3 } };
|
||||
CHECK(123 == memCastRef.ref<Data>().c);
|
||||
CHECK(1.23 == memCastRef.ref<Data>().d);
|
||||
CHECK((std::array { 1, 2, 3 }) == memCastRef.ref<Data>().a);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_mem_cast_types_to_type)
|
||||
{
|
||||
MemCastTypes memCastTypes;
|
||||
|
||||
char* pbuffer = memCastTypes.data();
|
||||
*pbuffer = 123;
|
||||
CHECK_EQUAL(123, memCastTypes.ref<char>());
|
||||
|
||||
*reinterpret_cast<double*>(pbuffer) = 1.23;
|
||||
CHECK_EQUAL(1.23, memCastTypes.ref<double>());
|
||||
|
||||
*reinterpret_cast<Data*>(pbuffer) = { 123, 1.23, { 1, 2, 3 } };
|
||||
CHECK(123 == memCastTypes.ref<Data>().c);
|
||||
CHECK(1.23 == memCastTypes.ref<Data>().d);
|
||||
CHECK((std::array { 1, 2, 3 }) == memCastTypes.ref<Data>().a);
|
||||
}
|
||||
};
|
||||
}
|
||||
///******************************************************************************
|
||||
//The MIT License(MIT)
|
||||
//
|
||||
//Embedded Template Library.
|
||||
//https://github.com/ETLCPP/etl
|
||||
//https://www.etlcpp.com
|
||||
//
|
||||
//Copyright(c) 2021 jwellbelove
|
||||
//
|
||||
//Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
//of this software and associated documentation files(the "Software"), to deal
|
||||
//in the Software without restriction, including without limitation the rights
|
||||
//to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
//copies of the Software, and to permit persons to whom the Software is
|
||||
//furnished to do so, subject to the following conditions :
|
||||
//
|
||||
//The above copyright notice and this permission notice shall be included in all
|
||||
//copies or substantial portions of the Software.
|
||||
//
|
||||
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
//SOFTWARE.
|
||||
//******************************************************************************/
|
||||
//
|
||||
//#include "unit_test_framework.h"
|
||||
//
|
||||
//#include "etl/mem_cast.h"
|
||||
//#include "etl/largest.h"
|
||||
//
|
||||
//#include <array>
|
||||
//#include <vector>
|
||||
//#include <algorithm>
|
||||
//#include <string>
|
||||
//
|
||||
//namespace
|
||||
//{
|
||||
// #pragma pack(push,1)
|
||||
// struct Data
|
||||
// {
|
||||
// Data()
|
||||
// : c(0)
|
||||
// , d(0)
|
||||
// , a()
|
||||
// {
|
||||
// }
|
||||
//
|
||||
// Data(char c_, double d_, std::array<int, 3> a_)
|
||||
// : c(c_)
|
||||
// , d(d_)
|
||||
// , a(a_)
|
||||
// {
|
||||
// }
|
||||
//
|
||||
// char c;
|
||||
// double d;
|
||||
// std::array<int, 3> a;
|
||||
// };
|
||||
// #pragma pack(pop)
|
||||
//
|
||||
// constexpr size_t Size = etl::largest<char, double, Data>::size;
|
||||
// constexpr size_t Alignment = etl::largest<char, double, Data>::alignment;
|
||||
//
|
||||
// // Test variant types.
|
||||
// using MemCast = etl::mem_cast<Size, Alignment>;
|
||||
// using MemCastTypes = etl::mem_cast_types<char, double, Data>;
|
||||
//
|
||||
// Data data;
|
||||
//
|
||||
// SUITE(test_mem_cast)
|
||||
// {
|
||||
// //*************************************************************************
|
||||
// TEST(test_size)
|
||||
// {
|
||||
// MemCast memCast;
|
||||
// MemCastTypes memCastTypes;
|
||||
//
|
||||
// CHECK(sizeof(char) <= MemCast::Size);
|
||||
// CHECK(sizeof(short) <= MemCast::Size);
|
||||
// CHECK(sizeof(Data) <= MemCast::Size);
|
||||
//
|
||||
// CHECK(sizeof(char) <= memCast.Size);
|
||||
// CHECK(sizeof(short) <= memCast.Size);
|
||||
// CHECK(sizeof(Data) <= memCast.Size);
|
||||
//
|
||||
// CHECK(sizeof(char) <= memCast.size());
|
||||
// CHECK(sizeof(short) <= memCast.size());
|
||||
// CHECK(sizeof(Data) <= memCast.size());
|
||||
//
|
||||
// CHECK(sizeof(char) <= MemCastTypes::Size);
|
||||
// CHECK(sizeof(short) <= MemCastTypes::Size);
|
||||
// CHECK(sizeof(Data) <= MemCastTypes::Size);
|
||||
//
|
||||
// CHECK(sizeof(char) <= memCastTypes.Size);
|
||||
// CHECK(sizeof(short) <= memCastTypes.Size);
|
||||
// CHECK(sizeof(Data) <= memCastTypes.Size);
|
||||
//
|
||||
// CHECK(sizeof(char) <= memCastTypes.size());
|
||||
// CHECK(sizeof(short) <= memCastTypes.size());
|
||||
// CHECK(sizeof(Data) <= memCastTypes.size());
|
||||
// }
|
||||
//
|
||||
// //*************************************************************************
|
||||
// TEST(test_alignment)
|
||||
// {
|
||||
// MemCast memCast;
|
||||
// MemCastTypes memCastTypes;
|
||||
//
|
||||
// CHECK(alignof(char) <= MemCast::Alignment);
|
||||
// CHECK(alignof(short) <= MemCast::Alignment);
|
||||
// CHECK(alignof(Data) <= MemCast::Alignment);
|
||||
//
|
||||
// CHECK(alignof(char) <= memCast.Alignment);
|
||||
// CHECK(alignof(short) <= memCast.Alignment);
|
||||
// CHECK(alignof(Data) <= memCast.Alignment);
|
||||
//
|
||||
// CHECK(alignof(char) <= memCast.alignment());
|
||||
// CHECK(alignof(short) <= memCast.alignment());
|
||||
// CHECK(alignof(Data) <= memCast.alignment());
|
||||
//
|
||||
// CHECK(alignof(char) <= MemCastTypes::Alignment);
|
||||
// CHECK(alignof(short) <= MemCastTypes::Alignment);
|
||||
// CHECK(alignof(Data) <= MemCastTypes::Alignment);
|
||||
//
|
||||
// CHECK(alignof(char) <= memCastTypes.Alignment);
|
||||
// CHECK(alignof(short) <= memCastTypes.Alignment);
|
||||
// CHECK(alignof(Data) <= memCastTypes.Alignment);
|
||||
//
|
||||
// CHECK(alignof(char) <= memCastTypes.alignment());
|
||||
// CHECK(alignof(short) <= memCastTypes.alignment());
|
||||
// CHECK(alignof(Data) <= memCastTypes.alignment());
|
||||
// }
|
||||
//
|
||||
// //*************************************************************************
|
||||
// TEST(test_mem_cast_assign_type)
|
||||
// {
|
||||
// MemCast memCast;
|
||||
//
|
||||
// memCast.assign<char>(123);
|
||||
// CHECK_EQUAL(123, memCast.ref<char>());
|
||||
//
|
||||
// memCast.assign<double>(1.23);
|
||||
// CHECK_EQUAL(1.23, memCast.ref<double>());
|
||||
//
|
||||
// Data data(123, 1.23, std::array<int, 3>{ 1, 2, 3 });
|
||||
// memCast.assign<Data>(data);
|
||||
// CHECK(123 == memCast.ref<Data>().c);
|
||||
// CHECK(1.23 == memCast.ref<Data>().d);
|
||||
// CHECK((std::array { 1, 2, 3 }) == memCast.ref<Data>().a);
|
||||
// }
|
||||
//
|
||||
// //*************************************************************************
|
||||
// TEST(test_mem_cast_assign_type_at_dynamic_offset)
|
||||
// {
|
||||
// MemCast memCast;
|
||||
//
|
||||
// using Array = std::array<int, 3>;
|
||||
// Array a{ 1, 2, 3 };
|
||||
//
|
||||
// size_t offset = offsetof(Data, a);
|
||||
//
|
||||
// memCast.assign_at_offset<Array>(offset, a);
|
||||
// CHECK(a == memCast.ref<Data>().a);
|
||||
// }
|
||||
//
|
||||
// //*************************************************************************
|
||||
// TEST(test_mem_cast_assign_type_at_static_offset)
|
||||
// {
|
||||
// MemCast memCast;
|
||||
//
|
||||
// using Array = std::array<int, 3>;
|
||||
// Array a{ 1, 2, 3 };
|
||||
//
|
||||
// constexpr size_t Offset = offsetof(Data, a);
|
||||
//
|
||||
// memCast.assign_at_offset<Array, Offset>(a);
|
||||
// CHECK(a == memCast.ref<Data>().a);
|
||||
// }
|
||||
//
|
||||
// //*************************************************************************
|
||||
// TEST(test_mem_cast_emplace_type)
|
||||
// {
|
||||
// MemCast memCast;
|
||||
//
|
||||
// memCast.emplace<char>(123);
|
||||
// CHECK_EQUAL(123, memCast.ref<char>());
|
||||
//
|
||||
// memCast.emplace<double>(1.23);
|
||||
// CHECK_EQUAL(1.23, memCast.ref<double>());
|
||||
//
|
||||
// memCast.emplace<Data>(123, 1.23, std::array<int, 3>{ 1, 2, 3 });
|
||||
// CHECK(123 == memCast.ref<Data>().c);
|
||||
// CHECK(1.23 == memCast.ref<Data>().d);
|
||||
// CHECK((std::array<int, 3U>{ 1, 2, 3 }) == memCast.ref<Data>().a);
|
||||
// }
|
||||
//
|
||||
// //*************************************************************************
|
||||
// TEST(test_mem_cast_emplace_type_at_dynamic_offset)
|
||||
// {
|
||||
// MemCast memCast;
|
||||
//
|
||||
// using Array = std::array<int, 3>;
|
||||
// Array a{ 1, 2, 3 };
|
||||
//
|
||||
// size_t offset = offsetof(Data, a);
|
||||
//
|
||||
// memCast.emplace_at_offset<Array>(offset, a);
|
||||
// CHECK(a == memCast.ref<Data>().a);
|
||||
// }
|
||||
//
|
||||
// //*************************************************************************
|
||||
// TEST(test_mem_cast_emplace_type_at_static_offset)
|
||||
// {
|
||||
// MemCast memCast;
|
||||
//
|
||||
// using Array = std::array<int, 3>;
|
||||
// Array a{ 1, 2, 3 };
|
||||
//
|
||||
// constexpr size_t Offset = offsetof(Data, a);
|
||||
//
|
||||
// memCast.emplace_at_offset<Array, Offset>(a);
|
||||
// CHECK(a == memCast.ref<Data>().a);
|
||||
// }
|
||||
//
|
||||
// //*************************************************************************
|
||||
// TEST(test_mem_cast_to_type)
|
||||
// {
|
||||
// MemCast memCast;
|
||||
//
|
||||
// char* pbuffer = memCast.data();
|
||||
// *pbuffer = 123;
|
||||
// CHECK_EQUAL(123, memCast.ref<char>());
|
||||
//
|
||||
// *reinterpret_cast<double*>(pbuffer) = 1.23;
|
||||
// CHECK_EQUAL(1.23, memCast.ref<double>());
|
||||
//
|
||||
// *reinterpret_cast<Data*>(pbuffer) = { 123, 1.23, { 1, 2, 3 } };
|
||||
// CHECK(123 == memCast.ref<Data>().c);
|
||||
// CHECK(1.23 == memCast.ref<Data>().d);
|
||||
// CHECK((std::array { 1, 2, 3 }) == memCast.ref<Data>().a);
|
||||
// }
|
||||
//
|
||||
// //*************************************************************************
|
||||
// TEST(test_const_mem_cast_to_type)
|
||||
// {
|
||||
// MemCast memCast;
|
||||
// const MemCast& memCastRef = memCast;
|
||||
//
|
||||
// char* pbuffer = memCast.data();
|
||||
// *pbuffer = 123;
|
||||
// CHECK_EQUAL(123, memCastRef.ref<char>());
|
||||
//
|
||||
// *reinterpret_cast<double*>(pbuffer) = 1.23;
|
||||
// CHECK_EQUAL(1.23, memCastRef.ref<double>());
|
||||
//
|
||||
// *reinterpret_cast<Data*>(pbuffer) = { 123, 1.23, { 1, 2, 3 } };
|
||||
// CHECK(123 == memCastRef.ref<Data>().c);
|
||||
// CHECK(1.23 == memCastRef.ref<Data>().d);
|
||||
// CHECK((std::array { 1, 2, 3 }) == memCastRef.ref<Data>().a);
|
||||
// }
|
||||
//
|
||||
// //*************************************************************************
|
||||
// TEST(test_mem_cast_types_to_type)
|
||||
// {
|
||||
// MemCastTypes memCastTypes;
|
||||
//
|
||||
// char* pbuffer = memCastTypes.data();
|
||||
// *pbuffer = 123;
|
||||
// CHECK_EQUAL(123, memCastTypes.ref<char>());
|
||||
//
|
||||
// *reinterpret_cast<double*>(pbuffer) = 1.23;
|
||||
// CHECK_EQUAL(1.23, memCastTypes.ref<double>());
|
||||
//
|
||||
// *reinterpret_cast<Data*>(pbuffer) = { 123, 1.23, { 1, 2, 3 } };
|
||||
// CHECK(123 == memCastTypes.ref<Data>().c);
|
||||
// CHECK(1.23 == memCastTypes.ref<Data>().d);
|
||||
// CHECK((std::array { 1, 2, 3 }) == memCastTypes.ref<Data>().a);
|
||||
// }
|
||||
// };
|
||||
//}
|
||||
|
||||
@ -223,7 +223,7 @@
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<EnableASAN>false</EnableASAN>
|
||||
<EnableASAN>true</EnableASAN>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug Intel|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
@ -309,7 +309,7 @@
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<EnableASAN>false</EnableASAN>
|
||||
<EnableASAN>true</EnableASAN>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MSVC - No STL - Built-ins|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user