mirror of
https://github.com/ETLCPP/etl.git
synced 2026-10-28 18:07:10 +08:00
* Fixed make_array rejecting const-qualified lvalues of the element type make_array forwarded each argument as T (the element type) rather than as its own deduced type. etl::forward<T> accepts only a non-const T& or a T&&, and a T&& cannot bind to a reference-related const lvalue, so any call passing a const-qualified lvalue of type T failed to compile: static const char c = 42; etl::make_array<char>(c, c); // error: would lose const qualifier Arguments of *other* types slipped through via temporary materialisation, which is why the existing conversion and move tests never caught it. Forward each argument as its own deduced type and convert explicitly with static_cast<T>. The explicit conversion is required rather than plain forwarding: function parameters are not constant expressions, so narrowing initialisers such as make_array<char>(0, 1) - which the old code accepted and the tests cover - would otherwise be rejected by the braced initialiser list. Adds regression tests for const/non-const lvalues of the element type and for constexpr evaluation. Verified with clang 22 (C++14/17/20) and GCC 14 (C++11/20); existing conversion and move-only patterns still compile. * Fixed make_deque rejecting const-qualified lvalues of the element type make_deque had the same defect fixed for make_array in the previous commit: it forwarded each argument as T (the element type) rather than as its own deduced type. etl::forward<T> accepts only a non-const T& or a T&&, and a T&& cannot bind to a reference-related const lvalue, so any call passing a const-qualified lvalue of type T failed to compile: static const char c = 42; etl::make_deque<char>(c, c); // error: would lose const qualifier An audit of all other make_xxx container factories found no further instances - they forward each argument as its own deduced pack type, which is the correct idiom. Forward each argument as its own deduced type and convert explicitly with static_cast<T>. The explicit conversion keeps narrowing initialisers such as make_deque<char>(0, 1) - which the old code accepted and test_make_deque covers - working, which plain forwarding into the braced initialiser list would reject. Adds a regression test for const/non-const lvalues of the element type. No constexpr test, unlike make_array: etl::deque is not a literal type, so make_deque cannot be evaluated at compile time. Verified with clang 22 (C++14/17/20); the new test fails to compile before the fix and passes after, and all 101 deque tests pass. * Added narrowing-conversion regression tests for make_array and make_deque Review feedback on the make_deque fix: the const-lvalue regression test only passes arguments that already have the element type, so nothing exercises the static_cast<T> conversion that keeps narrowing initialisers working. If the implementation regressed to plain forwarding into the braced initialiser list, narrowing calls such as make_deque<char>(0, 1) would fail to compile. make_array already covered narrowing from int literals via test_make_array, but neither container covered conversion from const-qualified lvalues of a different type (const int narrowed to char), which combines both dimensions of the fix. Adds a matching test to each container covering int literals plus const/non-const int lvalues, all narrowed to char. Verified with clang 22 (C++17): 102 deque and 53 array tests pass. * Added const-lvalue regression tests for the remaining make_xxx factories Review feedback on the make_array/make_deque fixes asked whether the same defect - rejecting const-qualified lvalue arguments by forwarding each argument as the element type rather than as its own deduced type - exists in the other make_xxx container factories. The audit found that it does not: the other factories forward each argument as its own deduced pack type. These tests pin that down explicitly for every remaining factory, mirroring the make_array and make_deque regression tests: - make_vector, make_forward_list, make_indirect_vector (element type deduced via common_type): const/non-const char lvalues, element type checked. - make_set, make_multiset, make_flat_set, make_flat_multiset, make_unordered_set, make_unordered_multiset: const/non-const lvalues of the key type. - make_map, make_multimap, make_flat_map, make_flat_multimap, make_unordered_map, make_unordered_multimap: const/non-const lvalues of the pair type. make_reference_flat_* are excluded: they cannot currently be instantiated at all (no initializer_list constructor exists in the reference containers), which is reported separately. Verified with clang 22 (C++17): all 15 test suites pass (996 tests). * Added make_forward_list parity tests matching the make_list fixes Checked whether the make_list defect - taking its argument pack by value, costing an extra move per lvalue argument - also applies to make_forward_list. It does not: make_forward_list already takes its pack by forwarding reference, as make_vector does. No header change is needed. Adds the two tests that accompanied the make_list fix so that forward_list has the same coverage and the same regression detector: - test_make_forward_list_common_type_from_mixed_types, confirming the element type deduction through common_type. - test_make_forward_list_argument_copy_and_move_counts, an instrumented type counting copy/move constructions. This is the test that fails if the pack ever regresses to by-value (one extra move per lvalue argument). The exact move counts are C++17-only, as before C++17 the non-guaranteed return elision may add a move per element. Verified with clang 22 (C++17): all 67 forward_list tests pass. --------- Co-authored-by: Roland Reichwein <Roland.Reichwein@bmw.de>
1755 lines
56 KiB
C++
1755 lines
56 KiB
C++
/******************************************************************************
|
|
The MIT License(MIT)
|
|
|
|
Embedded Template Library.
|
|
https://github.com/ETLCPP/etl
|
|
https://www.etlcpp.com
|
|
|
|
Copyright(c) 2014 John Wellbelove
|
|
|
|
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 <algorithm>
|
|
#include <array>
|
|
#include <cstring>
|
|
#include <vector>
|
|
|
|
#include "etl/vector.h"
|
|
|
|
namespace
|
|
{
|
|
SUITE(test_vector)
|
|
{
|
|
static const size_t SIZE = 10;
|
|
|
|
typedef etl::vector<int, SIZE> Data;
|
|
typedef etl::ivector<int> IData;
|
|
typedef std::vector<int> Compare_Data;
|
|
|
|
Compare_Data initial_data;
|
|
Compare_Data less_data;
|
|
Compare_Data greater_data;
|
|
Compare_Data shorter_data;
|
|
Compare_Data different_data;
|
|
Compare_Data insert_data;
|
|
Compare_Data blank_data;
|
|
Compare_Data swap_data;
|
|
Compare_Data swap_other_data;
|
|
|
|
//*************************************************************************
|
|
struct SetupFixture
|
|
{
|
|
SetupFixture()
|
|
{
|
|
int n[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
|
|
int n_insert[] = {11, 12, 13};
|
|
int n_less[] = {0, 1, 2, 3, 3, 5, 6, 7, 8, 9};
|
|
int n_greater[] = {0, 1, 2, 4, 4, 5, 6, 7, 8, 9};
|
|
int n_blank[] = {99, 99, 99, 99, 99, 99, 99, 99, 99, 99};
|
|
int n_swap[] = {0, 1, 2, 3, 4, 5};
|
|
int n_swap_other[] = {6, 7, 8, 9};
|
|
|
|
initial_data.assign(std::begin(n), std::end(n));
|
|
insert_data.assign(std::begin(n_insert), std::end(n_insert));
|
|
less_data.assign(std::begin(n_less), std::end(n_less));
|
|
greater_data.assign(std::begin(n_greater), std::end(n_greater));
|
|
shorter_data.assign(std::begin(n_greater), std::end(n_greater) - 1);
|
|
different_data.assign(initial_data.rbegin(), initial_data.rend());
|
|
blank_data.assign(std::begin(n_blank), std::end(n_blank));
|
|
swap_data.assign(std::begin(n_swap), std::end(n_swap));
|
|
swap_other_data.assign(std::begin(n_swap_other), std::end(n_swap_other));
|
|
}
|
|
};
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_default_constructor)
|
|
{
|
|
Data data;
|
|
|
|
CHECK_EQUAL(data.size(), size_t(0));
|
|
CHECK(data.empty());
|
|
CHECK_EQUAL(data.capacity(), SIZE);
|
|
CHECK_EQUAL(data.max_size(), SIZE);
|
|
CHECK(data.begin() == data.end());
|
|
}
|
|
|
|
#if ETL_USING_CPP17 && ETL_HAS_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED)
|
|
//*************************************************************************
|
|
TEST(test_cpp17_deduced_constructor)
|
|
{
|
|
etl::vector data{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
|
|
etl::vector<int, 10U> check = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
|
|
|
|
CHECK(!data.empty());
|
|
CHECK(data.full());
|
|
CHECK(data.begin() != data.end());
|
|
CHECK_EQUAL(0U, data.available());
|
|
CHECK_EQUAL(10U, data.capacity());
|
|
CHECK_EQUAL(10U, data.size());
|
|
CHECK_EQUAL(10U, data.max_size());
|
|
CHECK(data == check);
|
|
}
|
|
#endif
|
|
|
|
//*************************************************************************
|
|
TEST(test_iterator_comparison_empty)
|
|
{
|
|
Data data;
|
|
|
|
CHECK(data.begin() == data.end());
|
|
CHECK(data.cbegin() == data.cend());
|
|
CHECK(data.rbegin() == data.rend());
|
|
CHECK(data.crbegin() == data.crend());
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_constructor_size)
|
|
{
|
|
const size_t INITIAL_SIZE = 5;
|
|
Data data(INITIAL_SIZE);
|
|
|
|
CHECK(data.size() == INITIAL_SIZE);
|
|
CHECK(!data.empty());
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_constructor_size_value)
|
|
{
|
|
const size_t INITIAL_SIZE = 5;
|
|
const int INITIAL_VALUE = 1;
|
|
|
|
std::array<int, INITIAL_SIZE> compare_data;
|
|
compare_data.fill(INITIAL_VALUE);
|
|
|
|
Data data(INITIAL_SIZE, INITIAL_VALUE);
|
|
|
|
CHECK(data.size() == INITIAL_SIZE);
|
|
CHECK(!data.empty());
|
|
|
|
bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_constructor_size_excess)
|
|
{
|
|
CHECK_THROW(Data data(SIZE + 1), etl::vector_full);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_constructor_range)
|
|
{
|
|
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
|
|
|
Data data(compare_data.begin(), compare_data.end());
|
|
|
|
CHECK(data.size() == SIZE);
|
|
CHECK(!data.empty());
|
|
}
|
|
|
|
#if ETL_HAS_INITIALIZER_LIST
|
|
//*************************************************************************
|
|
TEST(test_constructor_initializer_list)
|
|
{
|
|
Compare_Data compare_data = {0, 1, 2, 3};
|
|
Data data = {0, 1, 2, 3};
|
|
|
|
CHECK_EQUAL(compare_data.size(), data.size());
|
|
CHECK(std::equal(compare_data.begin(), compare_data.end(), data.begin()));
|
|
}
|
|
#endif
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_copy_constructor)
|
|
{
|
|
Data data(initial_data.begin(), initial_data.end());
|
|
Data data2(data);
|
|
CHECK(data2 == data);
|
|
|
|
data2[2] = -1;
|
|
CHECK(data2 != data);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_move_constructor)
|
|
{
|
|
Data data(initial_data.begin(), initial_data.end());
|
|
Data data2(std::move(data));
|
|
CHECK(data.size() == 0);
|
|
CHECK(data2.size() == initial_data.size());
|
|
CHECK(data2 != data);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_assignment)
|
|
{
|
|
Data data(initial_data.begin(), initial_data.end());
|
|
Data other_data;
|
|
|
|
other_data = data;
|
|
|
|
bool is_equal = std::equal(data.begin(), data.end(), other_data.begin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_move_assignment)
|
|
{
|
|
Data data(initial_data.begin(), initial_data.end());
|
|
Data other_data;
|
|
other_data.push_back(1);
|
|
|
|
other_data = std::move(data);
|
|
|
|
CHECK(data.size() == 0);
|
|
CHECK(other_data.size() == initial_data.size());
|
|
CHECK(data != other_data);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_assignment_iterface)
|
|
{
|
|
Data data1(initial_data.begin(), initial_data.end());
|
|
Data data2;
|
|
|
|
IData& idata1 = data1;
|
|
IData& idata2 = data2;
|
|
|
|
idata2 = idata1;
|
|
|
|
bool is_equal = std::equal(data1.begin(), data1.end(), data2.begin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_self_assignment)
|
|
{
|
|
Data data(initial_data.begin(), initial_data.end());
|
|
Data other_data(data);
|
|
|
|
#include "etl/private/diagnostic_self_assign_overloaded_push.h"
|
|
other_data = other_data;
|
|
#include "etl/private/diagnostic_pop.h"
|
|
|
|
bool is_equal = std::equal(data.begin(), data.end(), other_data.begin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_begin)
|
|
{
|
|
Data data(10);
|
|
const Data constData(10);
|
|
|
|
CHECK_EQUAL(&data[0], data.begin());
|
|
CHECK_EQUAL(&constData[0], constData.begin());
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_end)
|
|
{
|
|
Data data(10);
|
|
const Data constData(10);
|
|
|
|
CHECK_EQUAL(data.begin() + data.size(), data.end());
|
|
CHECK_EQUAL(constData.begin() + constData.size(), constData.end());
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_resize_up)
|
|
{
|
|
const size_t INITIAL_SIZE = 5;
|
|
const size_t NEW_SIZE = 8;
|
|
|
|
Data data(INITIAL_SIZE);
|
|
data.resize(NEW_SIZE);
|
|
|
|
CHECK_EQUAL(data.size(), NEW_SIZE);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_resize_up_value)
|
|
{
|
|
const size_t INITIAL_SIZE = 5;
|
|
const size_t NEW_SIZE = 8;
|
|
const int INITIAL_VALUE = 1;
|
|
|
|
Data data(INITIAL_SIZE, INITIAL_VALUE);
|
|
data.resize(NEW_SIZE, INITIAL_VALUE);
|
|
|
|
std::array<int, NEW_SIZE> compare_data;
|
|
compare_data.fill(INITIAL_VALUE);
|
|
|
|
CHECK_EQUAL(compare_data.size(), data.size());
|
|
|
|
bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_resize_excess)
|
|
{
|
|
const size_t INITIAL_SIZE = 5;
|
|
const size_t NEW_SIZE = SIZE + 1;
|
|
|
|
Data data(INITIAL_SIZE);
|
|
|
|
CHECK_THROW(data.resize(NEW_SIZE), etl::vector_full);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_resize_down)
|
|
{
|
|
const size_t INITIAL_SIZE = 5;
|
|
const size_t NEW_SIZE = 2;
|
|
|
|
Data data(INITIAL_SIZE);
|
|
data.resize(NEW_SIZE);
|
|
|
|
CHECK_EQUAL(data.size(), NEW_SIZE);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_resize_down_value)
|
|
{
|
|
const size_t INITIAL_SIZE = 5;
|
|
const size_t NEW_SIZE = 2;
|
|
const int INITIAL_VALUE = 1;
|
|
|
|
Data data(INITIAL_SIZE);
|
|
data.resize(NEW_SIZE, INITIAL_VALUE);
|
|
|
|
CHECK_EQUAL(data.size(), NEW_SIZE);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up)
|
|
{
|
|
const size_t INITIAL_SIZE = 5;
|
|
const size_t NEW_SIZE = 8;
|
|
|
|
Data data(INITIAL_SIZE);
|
|
|
|
int* pbegin = &data.front();
|
|
int* pend = &data.back() + 1;
|
|
int* pmax = pbegin + data.max_size();
|
|
|
|
constexpr int Pattern = 0x12345678UL;
|
|
|
|
// Fill free space with a pattern.
|
|
std::fill(pend, pmax, Pattern);
|
|
|
|
data.uninitialized_resize(NEW_SIZE);
|
|
|
|
for (int* p = pbegin; p != pend; ++p)
|
|
{
|
|
CHECK_EQUAL(*p, 0);
|
|
}
|
|
|
|
for (int* p = pend; p != pmax; ++p)
|
|
{
|
|
CHECK_EQUAL(*p, Pattern);
|
|
}
|
|
|
|
CHECK_EQUAL(data.size(), NEW_SIZE);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up_excess)
|
|
{
|
|
const size_t INITIAL_SIZE = 5;
|
|
const size_t NEW_SIZE = SIZE + 1;
|
|
|
|
Data data(INITIAL_SIZE);
|
|
|
|
CHECK_THROW(data.uninitialized_resize(NEW_SIZE), etl::vector_full);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_uninitialized_resize_down)
|
|
{
|
|
const size_t INITIAL_SIZE = 5;
|
|
const size_t NEW_SIZE = 2;
|
|
|
|
Data data(INITIAL_SIZE);
|
|
|
|
int* pbegin = &data.front();
|
|
int* pend = &data.back() + 1;
|
|
int* pmax = pbegin + data.max_size();
|
|
|
|
constexpr int Pattern = 0x12345678UL;
|
|
|
|
// Fill free space with a pattern.
|
|
std::fill(pend, pmax, Pattern);
|
|
|
|
data.uninitialized_resize(NEW_SIZE);
|
|
|
|
pend = &data.back() + 1;
|
|
|
|
for (int* p = pbegin; p < pend; ++p)
|
|
{
|
|
CHECK_EQUAL(*p, 0);
|
|
}
|
|
|
|
CHECK_EQUAL(data.size(), NEW_SIZE);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_reserve)
|
|
{
|
|
Data data;
|
|
|
|
CHECK_NO_THROW(data.reserve(data.max_size()));
|
|
CHECK_THROW(data.reserve(data.max_size() + 1), etl::vector_out_of_bounds);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_empty)
|
|
{
|
|
Data data;
|
|
data.resize(data.max_size());
|
|
|
|
CHECK(data.full());
|
|
CHECK(!data.empty());
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_full)
|
|
{
|
|
Data data;
|
|
|
|
CHECK(!data.full());
|
|
CHECK(data.empty());
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_index)
|
|
{
|
|
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
|
|
|
Data data(compare_data.begin(), compare_data.end());
|
|
|
|
for (size_t i = 0UL; i < data.size(); ++i)
|
|
{
|
|
CHECK_EQUAL(data[i], compare_data[i]);
|
|
}
|
|
|
|
CHECK_THROW(data[data.size()], etl::vector_out_of_bounds);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_index_const)
|
|
{
|
|
const Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
|
|
|
const Data data(compare_data.begin(), compare_data.end());
|
|
|
|
for (size_t i = 0UL; i < data.size(); ++i)
|
|
{
|
|
CHECK_EQUAL(data[i], compare_data[i]);
|
|
}
|
|
|
|
CHECK_THROW(data[data.size()], etl::vector_out_of_bounds);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_at)
|
|
{
|
|
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
|
Data data(initial_data.begin(), initial_data.end());
|
|
|
|
for (size_t i = 0UL; i < data.size(); ++i)
|
|
{
|
|
CHECK_EQUAL(data.at(i), compare_data.at(i));
|
|
}
|
|
|
|
CHECK_THROW(data.at(data.size()), etl::vector_out_of_bounds);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_at_const)
|
|
{
|
|
const Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
|
const Data data(initial_data.begin(), initial_data.end());
|
|
|
|
for (size_t i = 0UL; i < data.size(); ++i)
|
|
{
|
|
CHECK_EQUAL(data.at(i), compare_data.at(i));
|
|
}
|
|
|
|
CHECK_THROW(data.at(data.size()), etl::vector_out_of_bounds);
|
|
}
|
|
|
|
//*************************************************************************
|
|
#include "etl/private/diagnostic_uninitialized_push.h"
|
|
TEST_FIXTURE(SetupFixture, test_front)
|
|
{
|
|
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
|
Data data(initial_data.begin(), initial_data.end());
|
|
|
|
CHECK(data.front() == compare_data.front());
|
|
|
|
Data emptyData;
|
|
CHECK_THROW(emptyData.front(), etl::vector_out_of_bounds);
|
|
}
|
|
#include "etl/private/diagnostic_pop.h"
|
|
|
|
//*************************************************************************
|
|
#include "etl/private/diagnostic_uninitialized_push.h"
|
|
TEST_FIXTURE(SetupFixture, test_front_const)
|
|
{
|
|
const Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
|
const Data data(initial_data.begin(), initial_data.end());
|
|
|
|
CHECK(data.front() == compare_data.front());
|
|
|
|
const Data emptyData;
|
|
CHECK_THROW(emptyData.front(), etl::vector_out_of_bounds);
|
|
}
|
|
#include "etl/private/diagnostic_pop.h"
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_back)
|
|
{
|
|
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
|
Data data(initial_data.begin(), initial_data.end());
|
|
|
|
CHECK(data.back() == compare_data.back());
|
|
|
|
Data emptyData;
|
|
CHECK_THROW(emptyData.back(), etl::vector_out_of_bounds);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_back_const)
|
|
{
|
|
const Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
|
const Data data(initial_data.begin(), initial_data.end());
|
|
|
|
CHECK(data.back() == compare_data.back());
|
|
|
|
const Data emptyData;
|
|
CHECK_THROW(emptyData.back(), etl::vector_out_of_bounds);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_data)
|
|
{
|
|
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
|
|
|
Data data(compare_data.begin(), compare_data.end());
|
|
|
|
bool is_equal = std::equal(data.data(), data.data() + data.size(), compare_data.begin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_data_const)
|
|
{
|
|
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
|
|
|
const Data data(compare_data.begin(), compare_data.end());
|
|
|
|
bool is_equal = std::equal(data.data(), data.data() + data.size(), compare_data.begin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_assign_range)
|
|
{
|
|
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
|
|
|
Data data;
|
|
|
|
data.assign(compare_data.begin(), compare_data.end());
|
|
|
|
CHECK_EQUAL(compare_data.size(), data.size());
|
|
|
|
bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_assign_size_value)
|
|
{
|
|
const size_t INITIAL_SIZE = 5;
|
|
const int INITIAL_VALUE = 1;
|
|
std::array<int, INITIAL_SIZE> compare_data;
|
|
compare_data.fill(INITIAL_VALUE);
|
|
|
|
Data data;
|
|
data.assign(INITIAL_SIZE, INITIAL_VALUE);
|
|
|
|
CHECK_EQUAL(compare_data.size(), data.size());
|
|
|
|
bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_assign_size_value_excess)
|
|
{
|
|
const size_t INITIAL_SIZE = SIZE;
|
|
const size_t EXCESS_SIZE = SIZE + 1;
|
|
const int INITIAL_VALUE = 1;
|
|
std::array<int, INITIAL_SIZE> compare_data;
|
|
compare_data.fill(INITIAL_VALUE);
|
|
|
|
Data data;
|
|
|
|
CHECK_THROW(data.assign(EXCESS_SIZE, INITIAL_VALUE), etl::vector_full);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_push_back)
|
|
{
|
|
Compare_Data compare_data;
|
|
Data data;
|
|
|
|
for (int i = 0; i < int(SIZE); ++i)
|
|
{
|
|
compare_data.push_back(i);
|
|
}
|
|
|
|
for (int i = 0; i < int(SIZE); ++i)
|
|
{
|
|
data.push_back(i);
|
|
}
|
|
|
|
CHECK_EQUAL(compare_data.size(), data.size());
|
|
|
|
bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_push_back_literal)
|
|
{
|
|
Compare_Data compare_data;
|
|
Data data;
|
|
|
|
compare_data.push_back(1);
|
|
compare_data.push_back(2);
|
|
compare_data.push_back(3);
|
|
compare_data.push_back(4);
|
|
|
|
data.push_back(1);
|
|
data.push_back(2);
|
|
data.push_back(3);
|
|
data.push_back(4);
|
|
|
|
CHECK_EQUAL(compare_data.size(), data.size());
|
|
|
|
bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_push_back_excess)
|
|
{
|
|
Data data;
|
|
|
|
for (int i = 0; i < int(SIZE); ++i)
|
|
{
|
|
data.push_back(i);
|
|
}
|
|
|
|
CHECK_THROW(data.push_back(SIZE), etl::vector_full);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_emplace_back)
|
|
{
|
|
Compare_Data compare_data;
|
|
Data data;
|
|
|
|
for (int i = 0; i < int(SIZE); ++i)
|
|
{
|
|
compare_data.emplace_back(i);
|
|
}
|
|
|
|
for (int i = 0; i < int(SIZE); ++i)
|
|
{
|
|
data.emplace_back(i);
|
|
}
|
|
|
|
CHECK_EQUAL(compare_data.size(), data.size());
|
|
|
|
bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_emplace_back_return)
|
|
{
|
|
Data data;
|
|
|
|
data.emplace_back(24);
|
|
auto back = data.emplace_back(42);
|
|
CHECK_EQUAL(back, data.back());
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_pop_back)
|
|
{
|
|
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
|
Data data(initial_data.begin(), initial_data.end());
|
|
|
|
compare_data.pop_back();
|
|
compare_data.pop_back();
|
|
|
|
data.pop_back();
|
|
data.pop_back();
|
|
|
|
CHECK_EQUAL(compare_data.size(), data.size());
|
|
|
|
bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_pop_back_exception)
|
|
{
|
|
Data data;
|
|
|
|
data.resize(2);
|
|
|
|
data.pop_back();
|
|
data.pop_back();
|
|
|
|
CHECK_THROW(data.pop_back(), etl::vector_empty);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_insert_position_value)
|
|
{
|
|
const size_t INITIAL_SIZE = 5;
|
|
const int INITIAL_VALUE = 1;
|
|
|
|
for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset)
|
|
{
|
|
Compare_Data compare_data;
|
|
Data data;
|
|
|
|
data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE);
|
|
compare_data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE);
|
|
|
|
data.insert(data.cbegin() + offset, INITIAL_VALUE);
|
|
compare_data.insert(compare_data.cbegin() + static_cast<ptrdiff_t>(offset), INITIAL_VALUE);
|
|
|
|
CHECK_EQUAL(compare_data.size(), data.size());
|
|
|
|
bool is_equal = std::equal(data.cbegin(), data.cend(), compare_data.cbegin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_insert_position_value_outofbounds)
|
|
{
|
|
const size_t INITIAL_SIZE = 5;
|
|
const int INITIAL_VALUE = 1;
|
|
|
|
Data data;
|
|
Data data2;
|
|
data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE);
|
|
CHECK_THROW(data.insert(data2.cbegin(), INITIAL_VALUE), etl::vector_out_of_bounds);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_emplace_position_value)
|
|
{
|
|
const size_t INITIAL_SIZE = 5;
|
|
const int INITIAL_VALUE = 1;
|
|
|
|
for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset)
|
|
{
|
|
Compare_Data compare_data;
|
|
Data data;
|
|
|
|
data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE);
|
|
compare_data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE);
|
|
|
|
data.emplace(data.cbegin() + offset, INITIAL_VALUE);
|
|
compare_data.emplace(compare_data.cbegin() + static_cast<ptrdiff_t>(offset), INITIAL_VALUE);
|
|
|
|
CHECK_EQUAL(compare_data.size(), data.size());
|
|
|
|
bool is_equal = std::equal(data.cbegin(), data.cend(), compare_data.cbegin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_emplace_position_value_outofbounds)
|
|
{
|
|
const size_t INITIAL_SIZE = 5;
|
|
const int INITIAL_VALUE = 1;
|
|
|
|
Data data;
|
|
Data data2;
|
|
data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE);
|
|
CHECK_THROW(data.emplace(data2.cbegin(), INITIAL_VALUE), etl::vector_out_of_bounds);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST(test_emplace_default)
|
|
{
|
|
const int Initial = 1;
|
|
const int Default = 2;
|
|
|
|
struct S
|
|
{
|
|
S()
|
|
: value(Default)
|
|
{
|
|
}
|
|
|
|
S(int v)
|
|
: value(v)
|
|
{
|
|
}
|
|
|
|
bool operator==(const S& rhs) const
|
|
{
|
|
return value == rhs.value;
|
|
}
|
|
|
|
int value;
|
|
};
|
|
|
|
// First fill with Initial values.
|
|
etl::vector<S, SIZE> data;
|
|
data.resize(SIZE, S(Initial));
|
|
data.clear();
|
|
|
|
// Then emplace Default values.
|
|
for (size_t i = 0; i < SIZE; ++i)
|
|
{
|
|
data.emplace(data.end());
|
|
}
|
|
|
|
// Compare with an array of default values.
|
|
std::array<S, SIZE> compare_data;
|
|
compare_data.fill(S());
|
|
|
|
CHECK_TRUE(std::equal(compare_data.begin(), compare_data.end(), data.begin()));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST(test_emplace_out_of_range)
|
|
{
|
|
etl::vector<int, SIZE> data;
|
|
etl::vector<int, SIZE> data2;
|
|
|
|
CHECK_THROW(data.emplace(data2.end());, etl::vector_out_of_bounds);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST(test_emplace_back_default)
|
|
{
|
|
const int Initial = 1;
|
|
const int Default = 2;
|
|
|
|
struct S
|
|
{
|
|
S()
|
|
: value(Default)
|
|
{
|
|
}
|
|
|
|
S(int v)
|
|
: value(v)
|
|
{
|
|
}
|
|
|
|
bool operator==(const S& rhs) const
|
|
{
|
|
return value == rhs.value;
|
|
}
|
|
|
|
int value;
|
|
};
|
|
|
|
// First fill with Initial values.
|
|
etl::vector<S, SIZE> data;
|
|
data.resize(SIZE, S(Initial));
|
|
data.clear();
|
|
|
|
// Then emplace Default values.
|
|
for (size_t i = 0; i < SIZE; ++i)
|
|
{
|
|
data.emplace_back();
|
|
}
|
|
|
|
// Compare with an array of default values.
|
|
std::array<S, SIZE> compare_data;
|
|
compare_data.fill(S());
|
|
|
|
CHECK_TRUE(std::equal(compare_data.begin(), compare_data.end(), data.begin()));
|
|
}
|
|
|
|
//*************************************************************************
|
|
#include "etl/private/diagnostic_array_bounds_push.h"
|
|
TEST_FIXTURE(SetupFixture, test_insert_position_value_excess)
|
|
{
|
|
const size_t INITIAL_SIZE = SIZE;
|
|
const int INITIAL_VALUE = 1;
|
|
|
|
Data data(INITIAL_SIZE, INITIAL_VALUE);
|
|
|
|
size_t offset = 2;
|
|
|
|
CHECK_THROW(data.insert(data.cbegin() + offset, INITIAL_VALUE), etl::vector_full);
|
|
|
|
offset = 0;
|
|
|
|
CHECK_THROW(data.insert(data.cbegin() + offset, INITIAL_VALUE), etl::vector_full);
|
|
|
|
offset = data.size();
|
|
|
|
CHECK_THROW(data.insert(data.cbegin() + offset, INITIAL_VALUE), etl::vector_full);
|
|
}
|
|
#include "etl/private/diagnostic_pop.h"
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_insert_position_n_value)
|
|
{
|
|
const size_t INITIAL_SIZE = 5;
|
|
const size_t INSERT_SIZE = 3;
|
|
const int INITIAL_VALUE = 11;
|
|
|
|
for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset)
|
|
{
|
|
Compare_Data compare_data;
|
|
Data data;
|
|
|
|
data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE);
|
|
compare_data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE);
|
|
data.insert(data.cbegin() + offset, INSERT_SIZE, INITIAL_VALUE);
|
|
compare_data.insert(compare_data.cbegin() + static_cast<ptrdiff_t>(offset), INSERT_SIZE, INITIAL_VALUE);
|
|
|
|
CHECK_EQUAL(compare_data.size(), data.size());
|
|
|
|
bool is_equal = std::equal(data.cbegin(), data.cend(), compare_data.cbegin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
}
|
|
|
|
//*************************************************************************
|
|
#include "etl/private/diagnostic_uninitialized_push.h"
|
|
TEST_FIXTURE(SetupFixture, test_insert_position_n_value_outofbounds)
|
|
{
|
|
const int INITIAL_VALUE = 0;
|
|
|
|
Data data;
|
|
Data data2;
|
|
|
|
CHECK_THROW(data.insert(data2.end(), 1, INITIAL_VALUE);, etl::vector_out_of_bounds);
|
|
}
|
|
#include "etl/private/diagnostic_pop.h"
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess)
|
|
{
|
|
const size_t INITIAL_SIZE = SIZE;
|
|
const size_t INSERT_SIZE = 4;
|
|
const int INITIAL_VALUE = 1;
|
|
|
|
Data data(INITIAL_SIZE, INITIAL_VALUE);
|
|
|
|
size_t offset = 0;
|
|
|
|
CHECK_THROW(data.insert(data.cbegin() + offset, INSERT_SIZE, INITIAL_VALUE), etl::vector_full);
|
|
|
|
offset = 2;
|
|
|
|
CHECK_THROW(data.insert(data.cbegin() + offset, INSERT_SIZE, INITIAL_VALUE), etl::vector_full);
|
|
|
|
offset = 4;
|
|
|
|
CHECK_THROW(data.insert(data.cbegin() + offset, INSERT_SIZE, INITIAL_VALUE), etl::vector_full);
|
|
|
|
offset = data.size();
|
|
|
|
CHECK_THROW(data.insert(data.cbegin() + offset, INSERT_SIZE, INITIAL_VALUE), etl::vector_full);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_insert_position_range)
|
|
{
|
|
const size_t INITIAL_SIZE = 5;
|
|
|
|
for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset)
|
|
{
|
|
Compare_Data compare_data;
|
|
Data data;
|
|
|
|
data.resize(SIZE, -1);
|
|
|
|
data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE);
|
|
compare_data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE);
|
|
data.insert(data.cbegin() + offset, insert_data.cbegin(), insert_data.cend());
|
|
compare_data.insert(compare_data.cbegin() + static_cast<ptrdiff_t>(offset), insert_data.cbegin(), insert_data.cend());
|
|
|
|
CHECK_EQUAL(compare_data.size(), data.size());
|
|
|
|
bool is_equal = std::equal(data.cbegin(), data.cend(), compare_data.cbegin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
}
|
|
|
|
//*************************************************************************
|
|
#include "etl/private/diagnostic_uninitialized_push.h"
|
|
TEST_FIXTURE(SetupFixture, test_insert_position_range_out_of_bounds)
|
|
{
|
|
Data data;
|
|
Data data2;
|
|
|
|
CHECK_THROW(data.insert(data2.end(), insert_data.cbegin(), insert_data.cend());, etl::vector_out_of_bounds);
|
|
}
|
|
#include "etl/private/diagnostic_pop.h"
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_insert_position_range_excess)
|
|
{
|
|
const size_t INITIAL_SIZE = 5;
|
|
const int INITIAL_VALUE = 1;
|
|
|
|
Data data(INITIAL_SIZE, INITIAL_VALUE);
|
|
|
|
size_t offset = 0;
|
|
|
|
CHECK_THROW(data.insert(data.cbegin() + offset, initial_data.cbegin(), initial_data.cend()), etl::vector_full);
|
|
|
|
offset = 2;
|
|
|
|
CHECK_THROW(data.insert(data.cbegin() + offset, initial_data.cbegin(), initial_data.cend()), etl::vector_full);
|
|
|
|
offset = 4;
|
|
|
|
CHECK_THROW(data.insert(data.cbegin() + offset, initial_data.cbegin(), initial_data.cend()), etl::vector_full);
|
|
|
|
offset = data.size();
|
|
|
|
CHECK_THROW(data.insert(data.cbegin() + offset, initial_data.cbegin(), initial_data.cend()), etl::vector_full);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_erase_single_iterator)
|
|
{
|
|
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
|
Data data(initial_data.begin(), initial_data.end());
|
|
|
|
Compare_Data::iterator const_cdi = compare_data.begin() + 2U;
|
|
#include "etl/private/diagnostic_null_dereference_push.h"
|
|
int compare_value = compare_data[3];
|
|
#include "etl/private/diagnostic_pop.h"
|
|
Compare_Data::iterator cdi = compare_data.erase(const_cdi);
|
|
CHECK_EQUAL(compare_value, *cdi);
|
|
|
|
Data::iterator const_di = data.begin() + 2U;
|
|
int data_value = data[3];
|
|
Data::iterator di = data.erase(const_di);
|
|
CHECK_EQUAL(data_value, *di);
|
|
|
|
CHECK_EQUAL(compare_data.size(), data.size());
|
|
|
|
bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_erase_single_iterator_outofbounds)
|
|
{
|
|
Data data(initial_data.begin(), initial_data.end());
|
|
|
|
CHECK_THROW(data.erase(data.end());, etl::vector_out_of_bounds);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator)
|
|
{
|
|
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
|
Data data(initial_data.begin(), initial_data.end());
|
|
|
|
Compare_Data::const_iterator const_cdi = compare_data.cbegin() + 2U;
|
|
#include "etl/private/diagnostic_null_dereference_push.h"
|
|
int compare_value = compare_data[3];
|
|
#include "etl/private/diagnostic_pop.h"
|
|
Compare_Data::iterator cdi = compare_data.erase(const_cdi);
|
|
CHECK_EQUAL(compare_value, *cdi);
|
|
|
|
Data::const_iterator const_di = data.cbegin() + 2U;
|
|
int data_value = data[3];
|
|
Data::iterator di = data.erase(const_di);
|
|
CHECK_EQUAL(data_value, *di);
|
|
|
|
CHECK_EQUAL(compare_data.size(), data.size());
|
|
|
|
bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator_outofbounds)
|
|
{
|
|
Data data(initial_data.begin(), initial_data.end());
|
|
|
|
CHECK_THROW(data.erase(data.cend());, etl::vector_out_of_bounds);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_erase_range)
|
|
{
|
|
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
|
Data data(initial_data.begin(), initial_data.end());
|
|
|
|
Compare_Data::iterator cdi = compare_data.erase(compare_data.begin() + 2, compare_data.begin() + 4);
|
|
|
|
Data::iterator di = data.erase(data.begin() + 2, data.begin() + 4);
|
|
|
|
CHECK(cdi == compare_data.begin() + 2);
|
|
CHECK(di == data.begin() + 2);
|
|
|
|
CHECK_EQUAL(compare_data.size(), data.size());
|
|
|
|
bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_erase_range_outofbounds)
|
|
{
|
|
Data data(initial_data.begin(), initial_data.end());
|
|
Data data2(initial_data.begin(), initial_data.end());
|
|
|
|
CHECK_THROW(data.erase(data2.begin(), data2.end());, etl::vector_out_of_bounds);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_clear)
|
|
{
|
|
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
|
|
|
Data data(compare_data.begin(), compare_data.end());
|
|
data.clear();
|
|
|
|
CHECK_EQUAL(data.size(), size_t(0));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_iterator)
|
|
{
|
|
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
|
|
|
Data data(compare_data.begin(), compare_data.end());
|
|
|
|
bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_const_iterator)
|
|
{
|
|
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
|
|
|
Data data(compare_data.begin(), compare_data.end());
|
|
|
|
bool is_equal = std::equal(data.cbegin(), data.cend(), compare_data.cbegin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_reverse_iterator)
|
|
{
|
|
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
|
|
|
Data data(compare_data.begin(), compare_data.end());
|
|
|
|
bool is_equal = std::equal(data.rbegin(), data.rend(), compare_data.rbegin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_const_reverse_iterator)
|
|
{
|
|
const Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
|
|
|
const Data data(compare_data.begin(), compare_data.end());
|
|
|
|
bool is_equal = std::equal(data.crbegin(), data.crend(), compare_data.crbegin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_const_reverse_iterator2)
|
|
{
|
|
const Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
|
|
|
const Data data(compare_data.begin(), compare_data.end());
|
|
|
|
bool is_equal = std::equal(data.rbegin(), data.rend(), compare_data.rbegin());
|
|
|
|
CHECK(is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_equal)
|
|
{
|
|
const Data initial1(initial_data.begin(), initial_data.end());
|
|
const Data initial2(initial_data.begin(), initial_data.end());
|
|
|
|
CHECK(initial1 == initial2);
|
|
|
|
const Data different(different_data.begin(), different_data.end());
|
|
|
|
CHECK(!(initial1 == different));
|
|
|
|
const Data shorter(shorter_data.begin(), shorter_data.end());
|
|
|
|
CHECK(!(shorter == initial1));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_not_equal)
|
|
{
|
|
const Data initial1(initial_data.begin(), initial_data.end());
|
|
const Data initial2(initial_data.begin(), initial_data.end());
|
|
|
|
CHECK(!(initial1 != initial2));
|
|
|
|
const Data different(different_data.begin(), different_data.end());
|
|
|
|
CHECK(initial1 != different);
|
|
|
|
const Data shorter(shorter_data.begin(), shorter_data.end());
|
|
|
|
CHECK(shorter != initial1);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_less_than)
|
|
{
|
|
const Data less(less_data.begin(), less_data.end());
|
|
const Data initial(initial_data.begin(), initial_data.end());
|
|
|
|
CHECK((less < initial) == (less_data < initial_data));
|
|
|
|
const Data greater(greater_data.begin(), greater_data.end());
|
|
|
|
CHECK((greater < initial) == (greater_data < initial_data));
|
|
|
|
const Data shorter(shorter_data.begin(), shorter_data.end());
|
|
|
|
CHECK((shorter < initial) == (shorter_data < initial_data));
|
|
CHECK((initial < shorter) == (initial_data < shorter_data));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_less_than_or_equal)
|
|
{
|
|
const Data less(less_data.begin(), less_data.end());
|
|
const Data initial(initial_data.begin(), initial_data.end());
|
|
|
|
CHECK((less <= initial) == (less_data <= initial_data));
|
|
|
|
const Data greater(greater_data.begin(), greater_data.end());
|
|
|
|
CHECK((greater <= initial) == (greater_data <= initial_data));
|
|
|
|
const Data shorter(shorter_data.begin(), shorter_data.end());
|
|
|
|
CHECK((shorter <= initial) == (shorter_data <= initial_data));
|
|
CHECK((initial <= shorter) == (initial_data <= shorter_data));
|
|
|
|
const Data initial2(initial_data.begin(), initial_data.end());
|
|
CHECK((initial <= initial2) == (initial_data <= initial_data));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_greater_than)
|
|
{
|
|
const Data less(less_data.begin(), less_data.end());
|
|
const Data initial(initial_data.begin(), initial_data.end());
|
|
|
|
CHECK((less > initial) == (less_data > initial_data));
|
|
|
|
const Data greater(greater_data.begin(), greater_data.end());
|
|
|
|
CHECK((greater > initial) == (greater_data > initial_data));
|
|
|
|
const Data shorter(shorter_data.begin(), shorter_data.end());
|
|
|
|
CHECK((shorter > initial) == (shorter_data > initial_data));
|
|
CHECK((initial > shorter) == (initial_data > shorter_data));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_greater_than_or_equal)
|
|
{
|
|
const Data less(less_data.begin(), less_data.end());
|
|
const Data initial(initial_data.begin(), initial_data.end());
|
|
|
|
CHECK((less >= initial) == (less_data >= initial_data));
|
|
|
|
const Data greater(greater_data.begin(), greater_data.end());
|
|
|
|
CHECK((greater >= initial) == (greater_data >= initial_data));
|
|
|
|
const Data shorter(shorter_data.begin(), shorter_data.end());
|
|
|
|
CHECK((shorter >= initial) == (shorter_data >= initial_data));
|
|
CHECK((initial >= shorter) == (initial_data > shorter_data));
|
|
|
|
const Data initial2(initial_data.begin(), initial_data.end());
|
|
CHECK((initial >= initial2) == (initial_data >= initial_data));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_memcpy_repair)
|
|
{
|
|
Data data(initial_data.begin(), initial_data.end());
|
|
|
|
char buffer[sizeof(Data)];
|
|
|
|
memcpy(&buffer, (const void*)&data, sizeof(data));
|
|
|
|
Data& rdata(*reinterpret_cast<Data*>(buffer));
|
|
rdata.repair();
|
|
|
|
// Check that the memcpy'd vector is the same.
|
|
CHECK_EQUAL(data.size(), rdata.size());
|
|
CHECK(!rdata.empty());
|
|
CHECK(rdata.full());
|
|
|
|
bool is_equal = std::equal(rdata.begin(), rdata.end(), data.begin());
|
|
|
|
CHECK(is_equal);
|
|
|
|
// Modify the original and check that the memcpy'd vector is not the same.
|
|
std::reverse(data.begin(), data.end());
|
|
|
|
is_equal = std::equal(rdata.begin(), rdata.end(), data.begin());
|
|
|
|
CHECK(!is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_memcpy_repair_virtual)
|
|
{
|
|
Data data(initial_data.begin(), initial_data.end());
|
|
|
|
char buffer[sizeof(Data)];
|
|
|
|
memcpy(&buffer, (const void*)&data, sizeof(data));
|
|
|
|
IData& idata(*reinterpret_cast<Data*>(buffer));
|
|
idata.repair();
|
|
|
|
// Check that the memcpy'd vector is the same.
|
|
CHECK_EQUAL(data.size(), idata.size());
|
|
CHECK(!idata.empty());
|
|
CHECK(idata.full());
|
|
|
|
bool is_equal = std::equal(idata.begin(), idata.end(), data.begin());
|
|
|
|
CHECK(is_equal);
|
|
|
|
// Modify the original and check that the memcpy'd vector is not the same.
|
|
std::reverse(data.begin(), data.end());
|
|
|
|
is_equal = std::equal(idata.begin(), idata.end(), data.begin());
|
|
|
|
CHECK(!is_equal);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST(test_insert_bug)
|
|
{
|
|
struct S
|
|
{
|
|
virtual ~S() {}
|
|
|
|
S(int i_)
|
|
: i(i_)
|
|
{
|
|
}
|
|
|
|
int i;
|
|
};
|
|
|
|
const S raw[6] = {1, 2, 3, 4, 5, 6};
|
|
|
|
etl::vector<S, 10> dest(ETL_OR_STD11::begin(raw), ETL_OR_STD11::end(raw));
|
|
etl::vector<S, 10> src((size_t)2, S(8));
|
|
|
|
dest.insert(dest.begin(), src.begin(), src.end());
|
|
|
|
CHECK(dest.size() == 8);
|
|
CHECK_EQUAL(src[0].i, dest[0].i);
|
|
CHECK_EQUAL(src[1].i, dest[1].i);
|
|
CHECK_EQUAL(raw[0].i, dest[2].i);
|
|
CHECK_EQUAL(raw[1].i, dest[3].i);
|
|
CHECK_EQUAL(raw[2].i, dest[4].i);
|
|
CHECK_EQUAL(raw[3].i, dest[5].i);
|
|
CHECK_EQUAL(raw[4].i, dest[6].i);
|
|
CHECK_EQUAL(raw[5].i, dest[7].i);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST(test_insert_n_bug)
|
|
{
|
|
struct S
|
|
{
|
|
virtual ~S() {}
|
|
|
|
S(int i_)
|
|
: i(i_)
|
|
{
|
|
}
|
|
|
|
int i;
|
|
};
|
|
|
|
const S raw[6] = {1, 2, 3, 4, 5, 6};
|
|
|
|
etl::vector<S, 10> dest(ETL_OR_STD11::begin(raw), ETL_OR_STD11::end(raw));
|
|
|
|
dest.insert(dest.begin(), 2, S(8));
|
|
|
|
CHECK(dest.size() == 8);
|
|
CHECK_EQUAL(8, dest[0].i);
|
|
CHECK_EQUAL(8, dest[1].i);
|
|
CHECK_EQUAL(raw[0].i, dest[2].i);
|
|
CHECK_EQUAL(raw[1].i, dest[3].i);
|
|
CHECK_EQUAL(raw[2].i, dest[4].i);
|
|
CHECK_EQUAL(raw[3].i, dest[5].i);
|
|
CHECK_EQUAL(raw[4].i, dest[6].i);
|
|
CHECK_EQUAL(raw[5].i, dest[7].i);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST(test_two_parameter_constructor_same_type_not_iterator)
|
|
{
|
|
// No compilation error.
|
|
etl::vector<int, 10> v(5, 5);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST(test_two_parameter_assign_same_type_not_iterator)
|
|
{
|
|
// No compilation error.
|
|
etl::vector<int, 10> v;
|
|
v.assign(5, 5);
|
|
}
|
|
|
|
//*************************************************************************
|
|
#include "etl/private/diagnostic_uninitialized_push.h"
|
|
TEST(test_three_parameter_insert_same_type_not_iterator)
|
|
{
|
|
// No compilation error.
|
|
etl::vector<int, 10> v;
|
|
v.insert(v.end(), 5, 5);
|
|
}
|
|
#include "etl/private/diagnostic_pop.h"
|
|
|
|
//*************************************************************************
|
|
TEST(remove)
|
|
{
|
|
const int raw[10] = {1, 8, 2, 7, 7, 7, 4, 5, 10, 9};
|
|
etl::vector<int, 10> data(ETL_OR_STD11::begin(raw), ETL_OR_STD11::end(raw));
|
|
std::array<int, 7> expected = {1, 8, 2, 4, 5, 10, 9};
|
|
|
|
etl::erase(data, 7);
|
|
|
|
CHECK_EQUAL(expected.size(), data.size());
|
|
|
|
bool is_same = std::equal(expected.begin(), expected.end(), data.begin());
|
|
CHECK(is_same);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST(remove_if)
|
|
{
|
|
const int raw[10] = {1, 8, 2, 7, 7, 7, 4, 5, 10, 9};
|
|
etl::vector<int, 10> data(ETL_OR_STD11::begin(raw), ETL_OR_STD11::end(raw));
|
|
std::array<int, 4> expected = {1, 2, 4, 5};
|
|
|
|
etl::erase_if(data, [](int value) { return value >= 7; });
|
|
|
|
bool is_same = std::equal(expected.begin(), expected.end(), data.begin());
|
|
CHECK(is_same);
|
|
}
|
|
|
|
//*************************************************************************
|
|
#if ETL_HAS_INITIALIZER_LIST
|
|
TEST(test_make_vector)
|
|
{
|
|
auto data = etl::make_vector<char>(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
|
|
|
|
using Type = typename std::remove_reference<decltype(data[0])>::type;
|
|
CHECK((std::is_same<int, Type>::value));
|
|
|
|
CHECK_EQUAL(0, data[0]);
|
|
CHECK_EQUAL(1, data[1]);
|
|
CHECK_EQUAL(2, data[2]);
|
|
CHECK_EQUAL(3, data[3]);
|
|
CHECK_EQUAL(4, data[4]);
|
|
CHECK_EQUAL(5, data[5]);
|
|
CHECK_EQUAL(6, data[6]);
|
|
CHECK_EQUAL(7, data[7]);
|
|
CHECK_EQUAL(8, data[8]);
|
|
CHECK_EQUAL(9, data[9]);
|
|
}
|
|
#endif
|
|
|
|
//*************************************************************************
|
|
#if ETL_HAS_INITIALIZER_LIST
|
|
TEST(test_make_vector_issue_931_two_pairs)
|
|
{
|
|
auto data3 = etl::make_vector(etl::make_pair(1, 2), etl::make_pair(3, 4), etl::make_pair(5, 6));
|
|
CHECK_EQUAL(1, data3[0].first);
|
|
CHECK_EQUAL(2, data3[0].second);
|
|
CHECK_EQUAL(3, data3[1].first);
|
|
CHECK_EQUAL(4, data3[1].second);
|
|
CHECK_EQUAL(5, data3[2].first);
|
|
CHECK_EQUAL(6, data3[2].second);
|
|
|
|
auto data2 = etl::make_vector(etl::make_pair(1, 2), etl::make_pair(3, 4));
|
|
CHECK_EQUAL(1, data3[0].first);
|
|
CHECK_EQUAL(2, data3[0].second);
|
|
CHECK_EQUAL(3, data3[1].first);
|
|
CHECK_EQUAL(4, data3[1].second);
|
|
}
|
|
#endif
|
|
|
|
//*************************************************************************
|
|
#if ETL_HAS_INITIALIZER_LIST
|
|
// Arguments that are const-qualified lvalues must be accepted and must not
|
|
// affect the deduced element type. Guards against the defect fixed for
|
|
// make_array and make_deque, which forwarded each argument as the element
|
|
// type rather than as its own deduced type and so rejected const lvalues.
|
|
TEST(test_make_vector_from_const_lvalues_of_element_type)
|
|
{
|
|
static const char static_const_lvalue = 42;
|
|
const char local_const_lvalue = 43;
|
|
char mutable_lvalue = 44;
|
|
|
|
auto data = etl::make_vector(static_const_lvalue, local_const_lvalue, mutable_lvalue);
|
|
|
|
using Type = typename std::remove_reference<decltype(data[0])>::type;
|
|
CHECK((std::is_same<char, Type>::value));
|
|
|
|
CHECK_EQUAL(42, data[0]);
|
|
CHECK_EQUAL(43, data[1]);
|
|
CHECK_EQUAL(44, data[2]);
|
|
}
|
|
#endif
|
|
|
|
//*************************************************************************
|
|
TEST(test_fill)
|
|
{
|
|
etl::vector<int, 10> data(initial_data.begin(), initial_data.end());
|
|
|
|
data.fill(99);
|
|
|
|
CHECK(std::equal(blank_data.begin(), blank_data.end(), data.begin()));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_swap_same_capacity)
|
|
{
|
|
Data etl_data(swap_data.begin(), swap_data.end());
|
|
Data etl_data2(swap_other_data.begin(), swap_other_data.end());
|
|
|
|
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
|
CHECK(etl_data.size() == swap_data.size());
|
|
CHECK(etl_data.max_size() == SIZE);
|
|
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
|
CHECK(etl_data2.size() == swap_other_data.size());
|
|
CHECK(etl_data2.max_size() == SIZE);
|
|
|
|
etl_data.swap(etl_data2);
|
|
|
|
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data2.begin()));
|
|
CHECK(etl_data2.size() == swap_data.size());
|
|
CHECK(etl_data2.max_size() == SIZE);
|
|
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data.begin()));
|
|
CHECK(etl_data.size() == swap_other_data.size());
|
|
CHECK(etl_data.max_size() == SIZE);
|
|
|
|
etl_data.swap(etl_data2);
|
|
|
|
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
|
CHECK(etl_data.size() == swap_data.size());
|
|
CHECK(etl_data.max_size() == SIZE);
|
|
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
|
CHECK(etl_data2.size() == swap_other_data.size());
|
|
CHECK(etl_data2.max_size() == SIZE);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_swap_different_capacity)
|
|
{
|
|
const size_t other_size = 6;
|
|
Data etl_data(swap_data.begin(), swap_data.end());
|
|
etl::vector<int, other_size> etl_data2(swap_other_data.begin(), swap_other_data.end());
|
|
|
|
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
|
CHECK(etl_data.size() == swap_data.size());
|
|
CHECK(etl_data.max_size() == SIZE);
|
|
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
|
CHECK(etl_data2.size() == swap_other_data.size());
|
|
CHECK(etl_data2.max_size() == other_size);
|
|
|
|
etl_data.swap(etl_data2);
|
|
|
|
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data2.begin()));
|
|
CHECK(etl_data2.size() == swap_data.size());
|
|
CHECK(etl_data2.max_size() == other_size);
|
|
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data.begin()));
|
|
CHECK(etl_data.size() == swap_other_data.size());
|
|
CHECK(etl_data.max_size() == SIZE);
|
|
|
|
etl_data.swap(etl_data2);
|
|
|
|
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
|
CHECK(etl_data.size() == swap_data.size());
|
|
CHECK(etl_data.max_size() == SIZE);
|
|
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
|
CHECK(etl_data2.size() == swap_other_data.size());
|
|
CHECK(etl_data2.max_size() == other_size);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST(test_swap_insufficient_capacity)
|
|
{
|
|
etl::vector<int, 4> etl_data(4);
|
|
etl::vector<int, 6> etl_data2(6);
|
|
|
|
CHECK_THROW(etl_data.swap(etl_data2), etl::vector_full);
|
|
CHECK_THROW(etl_data2.swap(etl_data), etl::vector_full);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST_FIXTURE(SetupFixture, test_etl_swap_different_capacity)
|
|
{
|
|
const size_t other_size = 6;
|
|
Data etl_data(swap_data.begin(), swap_data.end());
|
|
etl::vector<int, other_size> etl_data2(swap_other_data.begin(), swap_other_data.end());
|
|
|
|
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
|
CHECK(etl_data.size() == swap_data.size());
|
|
CHECK(etl_data.max_size() == SIZE);
|
|
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
|
CHECK(etl_data2.size() == swap_other_data.size());
|
|
CHECK(etl_data2.max_size() == other_size);
|
|
|
|
etl::swap(etl_data, etl_data2);
|
|
|
|
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data2.begin()));
|
|
CHECK(etl_data2.size() == swap_data.size());
|
|
CHECK(etl_data2.max_size() == other_size);
|
|
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data.begin()));
|
|
CHECK(etl_data.size() == swap_other_data.size());
|
|
CHECK(etl_data.max_size() == SIZE);
|
|
|
|
etl::swap(etl_data, etl_data2);
|
|
|
|
CHECK(std::equal(swap_data.begin(), swap_data.end(), etl_data.begin()));
|
|
CHECK(etl_data.size() == swap_data.size());
|
|
CHECK(etl_data.max_size() == SIZE);
|
|
CHECK(std::equal(swap_other_data.begin(), swap_other_data.end(), etl_data2.begin()));
|
|
CHECK(etl_data2.size() == swap_other_data.size());
|
|
CHECK(etl_data2.max_size() == other_size);
|
|
}
|
|
|
|
//*************************************************************************
|
|
template <typename TContainer, typename TIterator, typename = void>
|
|
struct is_assign_callable : std::false_type
|
|
{
|
|
};
|
|
|
|
template <typename TContainer, typename TIterator>
|
|
struct is_assign_callable<TContainer, TIterator,
|
|
etl::void_t<decltype(std::declval<TContainer&>().assign(std::declval<TIterator>(), std::declval<TIterator>()))>>
|
|
: std::true_type
|
|
{
|
|
};
|
|
|
|
template <typename TContainer, typename TIterator1, typename TIterator2, typename = void>
|
|
struct is_insert_callable : std::false_type
|
|
{
|
|
};
|
|
|
|
template <typename TContainer, typename TIterator1, typename TIterator2>
|
|
struct is_insert_callable<
|
|
TContainer, TIterator1, TIterator2,
|
|
etl::void_t<decltype(std::declval<TContainer&>().insert(std::declval<TIterator1>(), std::declval<TIterator2>(), std::declval<TIterator2>()))>>
|
|
: std::true_type
|
|
{
|
|
};
|
|
TEST_FIXTURE(SetupFixture, test_issue_1464_etl_vector_insert_allows_inserting_an_incompatible_type)
|
|
{
|
|
struct SomeStruct
|
|
{
|
|
int foo;
|
|
};
|
|
|
|
using ContainerType = etl::vector<SomeStruct*, 4>;
|
|
using Iterator1Type = etl::vector<SomeStruct*, 4>::iterator;
|
|
using Iterator2Type = etl::vector<SomeStruct, 4>::const_iterator;
|
|
|
|
constexpr bool can_assign = is_assign_callable<ContainerType, Iterator2Type>::value;
|
|
CHECK_FALSE(can_assign);
|
|
|
|
constexpr bool can_insert = is_insert_callable<ContainerType, Iterator1Type, Iterator2Type>::value;
|
|
CHECK_FALSE(can_insert);
|
|
}
|
|
}
|
|
} // namespace
|