etl/test/test_vector_member_function_pointer.cpp
John Wellbelove afa17c5042 Squashed commit of the following:
commit c5dc331004b4d9611ab996935bedada203676c71
Author: John Wellbelove <john.wellbelove@etlcpp.com>
Date:   Sat Jul 11 12:32:20 2026 +0100

    Updated release notes

commit 4bf6ed6ce8d79857658d763e368ee56617542b2c
Author: vcoselev <145198867+vcoselev@users.noreply.github.com>
Date:   Sat Jul 11 12:05:39 2026 +0100

    Fix for 1405: etl::exchange doesn't work with unique_ptr (#1477)

    * Separate bit order and endianness in bit_stream.h (#1495)

    * Factor out ranges tests from test_algorithm.cpp to test_algorithm_ranges.cpp (#1497)

    * Fix exchange to use forwarding reference (U&&) and move

    - etl::exchange was using the copy constructor. Changed for etl::move.
    - The assignment to the new object is now done with forward.
    - Added a test with unique_ptr.

    ---------

    Co-authored-by: Roland Reichwein <Roland.Reichwein@bmw.de>
    Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com>

commit 2ed9019df04d470530c41c1f27d35adc30b9a32d
Author: Moritz Pflanzer <moritz@pflanzer.eu>
Date:   Fri Jul 10 11:42:32 2026 +0200

    Update operator[] docs for map class (#1499)

    * Separate bit order and endianness in bit_stream.h (#1495)

    * Update operator[] docs for map class

    No const variant is implemented for the operator[].

    ---------

    Co-authored-by: Roland Reichwein <Roland.Reichwein@bmw.de>

commit 423e18d96dc645f1c733cb0d8ae6b675b9eb7e83
Author: Roland Reichwein <Roland.Reichwein@bmw.de>
Date:   Fri Jul 10 11:14:08 2026 +0200

    Factor out ranges tests from test_algorithm.cpp to test_algorithm_ranges.cpp (#1497)

commit 338bfdbb1f4df3c5c08a68a9038f13b8dae1c28b
Author: John Wellbelove <jwellbelove@users.noreply.github.com>
Date:   Fri Jul 10 10:12:04 2026 +0100

    Add coverage report to docs (#1498)

    * Updated release notes

    * Added link to coverage report

    ---------

    Co-authored-by: John Wellbelove <john.wellbelove@etlcpp.com>

commit 269025424f4c6f61cebac090f4df82985fb3b239
Merge: c004cc9d faa4c15b
Author: John Wellbelove <john.wellbelove@etlcpp.com>
Date:   Thu Jul 9 14:18:32 2026 +0100

    Merge branch 'development' of https://github.com/ETLCPP/etl into development

commit c004cc9d508efcf398630758a47aae95b37a7eb8
Author: John Wellbelove <john.wellbelove@etlcpp.com>
Date:   Thu Jul 9 10:06:17 2026 +0100

    Updated release notes

commit faa4c15b49c8ad15475c83ae23e00f5a46f803ca
Author: John Wellbelove <john.wellbelove@etlcpp.com>
Date:   Thu Jul 9 10:06:17 2026 +0100

    Updated release notes

commit 1523e63e35a15cfd1fa72d230a3c79efa7b9c3e0
Author: Roland Reichwein <Roland.Reichwein@bmw.de>
Date:   Wed Jul 8 20:48:33 2026 +0200

    Support non-assignable alternatives in variant (#1496)

commit 878a0ba5a28f6b0dcae9f472a6a6a1f107de0a74
Author: John Wellbelove <john.wellbelove@etlcpp.com>
Date:   Wed Jul 8 11:07:01 2026 +0100

    Updated version and release notes

commit 5287fe4b3b9f58330881d2a62abf6ce8e1159b8d
Author: John Wellbelove <jwellbelove@users.noreply.github.com>
Date:   Wed Jul 8 09:06:50 2026 +0100

    Allow etl::vector to store pointers to functions and member functions (#1492)

    * Refactored vector.h

    Deleted ivectorpointer.h

    * Minor changes

    * Fixed code incompatible with C++03

    * Clang-format changes

    * Removed redundant double-qualified name

    * Fixed is_is_object_pointer_v to is_object_pointer_v

    * Added new test files to meson.build

    * Added overflow checks to vector_ext copy and move constructors and assignments

    Added assert throw tests.

    * Added diagnostic pushes to eliminate GCC warning false positives

    * Changed the GCC C++23 Github action to use GCC14

    * Applied clang-format

    * Added guard to pop_heap

    * Added guard to adjust_heap

    * Attempt to fix GCC diagnostic

    * Attempt to fix GCC diagnostic

    Re-enable ranges algorithm tests

    * Attempt to fix GCC diagnostic

    Re-enable ranges algorithm tests

    * clang-format

    * Attempt to fix GCC diagnostic

    Re-enable ranges algorithm tests

    * Attempt to fix GCC diagnostic

    Re-enable ranges algorithm tests

    * Attempt to fix GCC diagnostic

    Re-enable ranges algorithm tests

    * Missing newline at end of file

    * Attempt to fix GCC diagnostic

    Re-enable ranges algorithm tests

    * Attempt to fix GCC diagnostic

    Re-enable ranges algorithm tests

    * Attempt to fix GCC diagnostic

    Re-enable ranges algorithm tests

    * Attempt to fix GCC diagnostic

    Re-enable ranges algorithm tests

    * Attempt to fix GCC diagnostic

    * clang-format

    * Changed gcc --version to gcc-14 --version

    ---------

    Co-authored-by: John Wellbelove <john.wellbelove@etlcpp.com>
    Co-authored-by: Roland Reichwein <Roland.Reichwein@bmw.de>

commit 40dddd7f9601985ae7350e60a404af9028bc9fe9
Author: Roland Reichwein <Roland.Reichwein@bmw.de>
Date:   Tue Jul 7 23:41:17 2026 +0200

    Add optional etl_profile label_flag for Bazel profile injection (#1491)

    Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com>

commit 84fca4cd62f72c382c062376ca934803116a20d5
Author: Roland Reichwein <Roland.Reichwein@bmw.de>
Date:   Tue Jul 7 21:45:47 2026 +0200

    Add missing memory functions, according the standard (#1490)

    Adding:

    - etl::align
    - etl::assume_aligned
    - etl::is_sufficiently_aligned
    - etl::launder
    - etl::pointer_traits
    - etl::start_lifetime_as

    Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com>

commit dca6653b3759b2cdc79307fec7425589feea478d
Author: Roland Reichwein <Roland.Reichwein@bmw.de>
Date:   Tue Jul 7 21:00:09 2026 +0200

    Add missing interfaces to etl::chrono (#1489)

    Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com>

commit c52b2ac7b1f675e6b1d34052239423b7f3634033
Author: Roland Reichwein <Roland.Reichwein@bmw.de>
Date:   Tue Jul 7 18:06:05 2026 +0200

    Fix etl::mem_cast cross-size copy constructor and assignment (#1488)

    The templated cross-size copy constructor and assignment operator were
    broken in two ways:

    - They accessed other.buffer / rhs.buffer, which is private in a
      different mem_cast instantiation, so the cross-size overloads failed
      to compile whenever they were actually instantiated.
    - They copied Size_ (the destination size) bytes from a source buffer
      that is only Other_Size bytes large, reading past the end of the
      source when the destination was larger.

    Use the public data() accessor and copy Other_Size bytes. The existing
    static_assert(Size >= Other_Size) guarantees the destination is big
    enough.

    Add test_mem_cast_copy_and_assign_from_smaller regression test.

    Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com>

commit 165674cb23dda1fd4f7e5a1182f49554a796bfe8
Author: Roland Reichwein <Roland.Reichwein@bmw.de>
Date:   Tue Jul 7 16:41:50 2026 +0200

    Fix etl::pearson::reset() not resetting the first-byte flag (#1487)

    reset() cleared the hash array but left the `first` flag false, so a
    calculator reused after reset() took the XOR update path on its next
    add() instead of the initialisation path. This produced an incorrect
    hash for any pearson object that was reset and reused.

    Reset `first` to true in reset() so a reset calculator behaves like a
    freshly constructed one.

    Add test_pearson_reset regression test.

    Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com>

commit 032ec4cc80f1c0f1baa0383bdbc5f9239b68f268
Author: Roland Reichwein <Roland.Reichwein@bmw.de>
Date:   Tue Jul 7 13:40:04 2026 +0200

    Fix etl::bitset single-element from_string shift on empty string (#1486)

    The single-element from_string overloads (char, wchar_t, char16_t,
    char32_t) computed element_type(1) << (string_length - 1U) before the
    copy loop. For an empty string, or when active_bits is 0, string_length
    is 0, so the shift count underflows to SIZE_MAX. Shifting by more than
    the element width is undefined behaviour, which also breaks constexpr
    evaluation.

    Guard the mask with a zero-length check so the shift is only performed
    when string_length > 0. The multi-element from_string overloads were
    already safe.

    Add test_construct_from_empty_string regression test.

    Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com>

commit 98cb365d4c28e7b72f8547b734a03a4068acd3f5
Author: Roland Reichwein <Roland.Reichwein@bmw.de>
Date:   Tue Jul 7 12:32:56 2026 +0200

    Fix etl::histogram copy/move not preserving start_index (#1485)

    The run-time-offset specialization of etl::histogram stores a start_index
    member used to map keys to bins (accumulator[key - start_index]). Its copy
    constructor, move constructor, copy assignment, and move assignment copied
    only the accumulator and left start_index uninitialized, so a copied or
    moved histogram indexed the wrong bin in operator[]/add(), causing
    out-of-bounds access (undefined behavior).

    All four special member functions now also copy start_index. The
    compile-time-offset specialization is unaffected, as its start index is a
    template constant rather than a data member.

    Add regression tests covering copy/move construction and assignment.

    Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com>

commit 5cd2f28cd54e4019f7be126bcf7394a6a8318eb9
Author: Drew Rife <darife@jlg.com>
Date:   Tue Jul 7 03:14:48 2026 -0400

    Refactor variant::emplace to perfect forward args instead of copy/move construct (#1494)

    * refactor: emplace logic to use do_emplace for in-place construction with forwarded arguments #1493

    * Add test for variant_variadic

    ---------

    Co-authored-by: Roland Reichwein <Roland.Reichwein@bmw.de>

commit a47c0aae81b886259918961d5fcee20faa06fdd0
Author: Roland Reichwein <Roland.Reichwein@bmw.de>
Date:   Mon Jul 6 17:32:26 2026 +0200

    Fix etl::message_timer firing following timers early on unregister (#1484)

    active_list.remove(id, has_expired) adjusts the next timer's delta only
    when has_expired is false. When unregistering an active, non-expired timer,
    unregister_timer() incorrectly passed true, skipping that adjustment, so
    every timer after the removed one in the active list fired early by the
    removed timer's delta.

    Pass false instead, matching the etl::callback_timer family. tick() still
    passes true, since the timer has genuinely expired there. The bug affected
    all four variants: message_timer, message_timer_interrupt,
    message_timer_atomic and message_timer_locked. Existing tests missed it
    because they only ever unregistered the tail timer, where the delta
    adjustment is a no-op.

    Add a regression test that unregisters a non-tail active timer and checks
    the following timer still fires at its original absolute time.
2026-07-11 13:02:42 +01:00

1331 lines
44 KiB
C++

/******************************************************************************
The MIT License(MIT)
Embedded Template Library.
https://github.com/ETLCPP/etl
https://www.etlcpp.com
Copyright(c) 2026 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_member_function_pointer)
{
static const size_t SIZE = 10;
struct Functions
{
size_t f0(size_t a)
{
return 0 * a;
}
size_t f1(size_t a)
{
return 1 * a;
}
size_t f2(size_t a)
{
return 2 * a;
}
size_t f3(size_t a)
{
return 3 * a;
}
size_t f4(size_t a)
{
return 4 * a;
}
size_t f5(size_t a)
{
return 5 * a;
}
size_t f6(size_t a)
{
return 6 * a;
}
size_t f7(size_t a)
{
return 7 * a;
}
size_t f8(size_t a)
{
return 8 * a;
}
size_t f9(size_t a)
{
return 9 * a;
}
size_t f10(size_t a)
{
return 10 * a;
}
size_t f11(size_t a)
{
return 11 * a;
}
size_t f12(size_t a)
{
return 12 * a;
}
};
Functions functions;
using MFPtr = size_t (Functions::*)(size_t);
using Data = etl::vector<MFPtr, SIZE>;
using IData = etl::ivector<MFPtr>;
using Compare_Data = std::vector<MFPtr>;
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 swap_data;
Compare_Data swap_other_data;
//*************************************************************************
struct SetupFixture
{
SetupFixture()
{
MFPtr n[] = {&Functions::f0, &Functions::f1, &Functions::f2, &Functions::f3, &Functions::f4,
&Functions::f5, &Functions::f6, &Functions::f7, &Functions::f8, &Functions::f9};
MFPtr n_insert[] = {&Functions::f10, &Functions::f11, &Functions::f12};
MFPtr n_less[] = {&Functions::f0, &Functions::f1, &Functions::f2, &Functions::f3, &Functions::f3,
&Functions::f5, &Functions::f6, &Functions::f7, &Functions::f8, &Functions::f9};
MFPtr n_greater[] = {&Functions::f0, &Functions::f1, &Functions::f2, &Functions::f4, &Functions::f4,
&Functions::f5, &Functions::f6, &Functions::f7, &Functions::f8, &Functions::f9};
MFPtr n_swap[] = {&Functions::f0, &Functions::f1, &Functions::f2, &Functions::f3, &Functions::f4, &Functions::f5};
MFPtr n_swap_other[] = {&Functions::f6, &Functions::f7, &Functions::f8, &Functions::f9};
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());
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);
}
#if ETL_USING_CPP17 && ETL_HAS_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED)
//*************************************************************************
TEST(test_cpp17_deduced_constructor)
{
etl::vector data{&Functions::f0, &Functions::f1, &Functions::f2, &Functions::f3, &Functions::f4,
&Functions::f5, &Functions::f6, &Functions::f7, &Functions::f8, &Functions::f9};
etl::vector<MFPtr, 10U> check = {&Functions::f0, &Functions::f1, &Functions::f2, &Functions::f3, &Functions::f4,
&Functions::f5, &Functions::f6, &Functions::f7, &Functions::f8, &Functions::f9};
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;
MFPtr Initial_Value = &Functions::f0;
std::array<MFPtr, 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());
CHECK(std::equal(compare_data.begin(), compare_data.end(), data.begin()));
}
#if ETL_HAS_INITIALIZER_LIST
//*************************************************************************
TEST(test_constructor_initializer_list)
{
MFPtr a = &Functions::f0;
MFPtr b = &Functions::f1;
MFPtr c = &Functions::f2;
MFPtr d = &Functions::f3;
Compare_Data compare_data = {a, b, c, d};
Data data = {a, b, c, d};
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] = nullptr;
CHECK(data2 != data);
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_move_constructor)
{
Data data(initial_data.begin(), initial_data.end());
Data data2(std::move(data));
CHECK_EQUAL(0U, data.size());
CHECK_EQUAL(initial_data.size(), data2.size());
CHECK_EQUAL(initial_data.size(), data2.size());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_assignment)
{
Data data(initial_data.begin(), initial_data.end());
Data other_data;
other_data = data;
CHECK_EQUAL(initial_data.size(), data.size());
CHECK_EQUAL(initial_data.size(), other_data.size());
bool is_equal = std::equal(data.begin(), data.end(), other_data.begin());
CHECK(is_equal);
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_assignment_from_pointer_range)
{
Data data(initial_data.data(), initial_data.data() + initial_data.size());
Data other_data;
other_data = data;
CHECK_EQUAL(initial_data.size(), data.size());
CHECK_EQUAL(initial_data.size(), other_data.size());
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(MFPtr(0));
other_data = std::move(data);
CHECK_EQUAL(0U, data.size());
CHECK_EQUAL(initial_data.size(), other_data.size());
bool is_equal = std::equal(data.begin(), data.end(), other_data.begin());
CHECK(is_equal);
}
//*************************************************************************
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;
MFPtr Initial_Value = &Functions::f0;
Data data(Initial_Size, Initial_Value);
data.resize(NEW_SIZE, Initial_Value);
std::array<MFPtr, NEW_SIZE> compare_data;
compare_data.fill(Initial_Value);
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;
MFPtr Initial_Value = &Functions::f0;
Data data(Initial_Size);
data.resize(NEW_SIZE, Initial_Value);
CHECK_EQUAL(data.size(), NEW_SIZE);
}
//*************************************************************************
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_TRUE(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_TRUE(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_TRUE(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_TRUE(data.at(i) == compare_data.at(i));
}
CHECK_THROW(data.at(data.size()), etl::vector_out_of_bounds);
}
//*************************************************************************
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);
}
//*************************************************************************
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);
}
//*************************************************************************
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());
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;
MFPtr Initial_Value = &Functions::f0;
std::array<MFPtr, Initial_Size> compare_data;
compare_data.fill(Initial_Value);
Data data;
data.assign(Initial_Size, Initial_Value);
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;
MFPtr Initial_Value = &Functions::f0;
std::array<MFPtr, 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;
MFPtr fptr = &Functions::f0;
for (size_t i = 0UL; i < SIZE; ++i)
{
compare_data.push_back(fptr);
}
for (size_t i = 0UL; i < SIZE; ++i)
{
data.push_back(fptr);
}
bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin());
CHECK(is_equal);
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_push_back_excess)
{
Data data;
MFPtr fptr = &Functions::f0;
for (size_t i = 0UL; i < SIZE; ++i)
{
data.push_back(fptr);
}
CHECK_THROW(data.push_back(fptr), etl::vector_full);
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_emplace_back)
{
Compare_Data compare_data;
Data data;
MFPtr fptr = &Functions::f0;
for (size_t i = 0UL; i < SIZE; ++i)
{
compare_data.emplace_back(fptr);
}
for (size_t i = 0UL; i < SIZE; ++i)
{
data.emplace_back(fptr);
}
bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin());
CHECK(is_equal);
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_emplace_back_return)
{
Data data;
MFPtr fptr1 = &Functions::f0;
MFPtr fptr2 = &Functions::f1;
data.emplace_back(fptr1);
CHECK_TRUE(fptr2 == data.emplace_back(fptr2));
}
//*************************************************************************
TEST(test_emplace_default)
{
static MFPtr initial = &Functions::f0;
// First fill with Initial values.
etl::vector<MFPtr, SIZE> data;
data.resize(SIZE, initial);
data.clear();
// Then emplace Default values.
for (size_t i = 0; i < SIZE; ++i)
{
data.emplace(data.begin());
}
// Compare with an array of default values.
std::array<MFPtr, SIZE> compare_data;
compare_data.fill(nullptr);
CHECK_TRUE(std::equal(compare_data.begin(), compare_data.end(), data.begin()));
}
//*************************************************************************
TEST(test_emplace_back_default)
{
static MFPtr initial = &Functions::f0;
// First fill with initial values.
etl::vector<MFPtr, SIZE> data;
data.resize(SIZE, 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<MFPtr, SIZE> compare_data;
compare_data.fill(nullptr);
CHECK_TRUE(std::equal(compare_data.begin(), compare_data.end(), data.begin()));
}
//*************************************************************************
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();
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;
MFPtr Initial_Value = &Functions::f0;
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.begin() + offset, Initial_Value);
compare_data.insert(compare_data.begin() + static_cast<ptrdiff_t>(offset), Initial_Value);
CHECK_EQUAL(compare_data.size(), data.size());
bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin());
CHECK(is_equal);
}
}
//*************************************************************************
#include "etl/private/diagnostic_uninitialized_push.h"
TEST_FIXTURE(SetupFixture, test_insert_position_value_outofbounds)
{
const size_t Initial_Size = 5;
MFPtr Initial_Value = &Functions::f0;
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);
}
#include "etl/private/diagnostic_pop.h"
//*************************************************************************
#include "etl/private/diagnostic_array_bounds_push.h"
TEST_FIXTURE(SetupFixture, test_insert_position_value_excess)
{
const size_t Initial_Size = SIZE;
MFPtr Initial_Value = &Functions::f0;
Data data(Initial_Size, Initial_Value);
size_t offset = 2;
CHECK_THROW(data.insert(data.begin() + offset, Initial_Value), etl::vector_full);
offset = 0;
CHECK_THROW(data.insert(data.begin() + offset, Initial_Value), etl::vector_full);
offset = data.size();
CHECK_THROW(data.insert(data.begin() + offset, Initial_Value), etl::vector_full);
}
#include "etl/private/diagnostic_pop.h"
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_emplace_position_value)
{
const size_t Initial_Size = 5;
MFPtr Initial_Value = &Functions::f0;
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.begin() + offset, Initial_Value);
compare_data.emplace(compare_data.begin() + static_cast<ptrdiff_t>(offset), Initial_Value);
CHECK_EQUAL(compare_data.size(), data.size());
bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin());
CHECK(is_equal);
}
}
//*************************************************************************
#include "etl/private/diagnostic_uninitialized_push.h"
TEST_FIXTURE(SetupFixture, test_emplace_position_value_outofbounds)
{
const size_t Initial_Size = 5;
MFPtr Initial_Value = &Functions::f0;
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);
}
#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;
MFPtr Initial_Value = &Functions::f0;
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.begin() + offset, INSERT_SIZE, Initial_Value);
compare_data.insert(compare_data.begin() + static_cast<ptrdiff_t>(offset), INSERT_SIZE, Initial_Value);
bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin());
CHECK(is_equal);
}
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_insert_position_n_value_outofbounds)
{
MFPtr Initial_Value = &Functions::f0;
Data data;
Data data2;
CHECK_THROW(data.insert(data2.end(), 1, Initial_Value);, etl::vector_out_of_bounds);
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess)
{
const size_t Initial_Size = SIZE;
const size_t INSERT_SIZE = 4;
MFPtr Initial_Value = &Functions::f0;
Data data(Initial_Size, Initial_Value);
size_t offset = 0;
CHECK_THROW(data.insert(data.begin() + offset, INSERT_SIZE, Initial_Value), etl::vector_full);
offset = 2;
CHECK_THROW(data.insert(data.begin() + offset, INSERT_SIZE, Initial_Value), etl::vector_full);
offset = 4;
CHECK_THROW(data.insert(data.begin() + offset, INSERT_SIZE, Initial_Value), etl::vector_full);
offset = data.size();
CHECK_THROW(data.insert(data.begin() + 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.assign(initial_data.begin(), initial_data.begin() + Initial_Size);
compare_data.assign(initial_data.begin(), initial_data.begin() + Initial_Size);
data.insert(data.begin() + offset, insert_data.begin(), insert_data.end());
compare_data.insert(compare_data.begin() + static_cast<ptrdiff_t>(offset), insert_data.begin(), insert_data.end());
bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin());
CHECK(is_equal);
}
}
//*************************************************************************
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);
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_insert_position_pointer_range)
{
const size_t Initial_Size = 5;
for (size_t offset = 0; offset <= Initial_Size; ++offset)
{
Compare_Data compare_data;
Data data;
data.assign(initial_data.data(), initial_data.data() + Initial_Size);
compare_data.assign(initial_data.begin(), initial_data.begin() + Initial_Size);
data.insert(data.data() + offset, insert_data.data(), insert_data.data() + insert_data.size());
compare_data.insert(compare_data.begin() + static_cast<ptrdiff_t>(offset), insert_data.begin(), insert_data.end());
bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin());
CHECK(is_equal);
}
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_insert_position_pointer_range_out_of_bounds)
{
Data data;
CHECK_THROW(data.insert(data.data() + data.size() + 1, insert_data.data(), insert_data.data() + insert_data.size());
, etl::vector_out_of_bounds);
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_insert_position_range_excess)
{
const size_t Initial_Size = 5;
MFPtr Initial_Value = &Functions::f0;
Data data(Initial_Size, Initial_Value);
size_t offset = 0;
CHECK_THROW(data.insert(data.begin() + offset, initial_data.begin(), initial_data.end()), etl::vector_full);
offset = 2;
CHECK_THROW(data.insert(data.begin() + offset, initial_data.begin(), initial_data.end()), etl::vector_full);
offset = 4;
CHECK_THROW(data.insert(data.begin() + offset, initial_data.begin(), initial_data.end()), etl::vector_full);
offset = data.size();
CHECK_THROW(data.insert(data.begin() + offset, initial_data.begin(), initial_data.end()), etl::vector_full);
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_erase_single)
{
Compare_Data compare_data(initial_data.begin(), initial_data.end());
Data data(initial_data.begin(), initial_data.end());
Compare_Data::iterator citr = compare_data.erase(compare_data.begin() + 2);
Data::iterator ditr = data.erase(data.begin() + 2);
CHECK(*citr == *ditr);
bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin());
CHECK(is_equal);
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_erase_single_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_range)
{
Compare_Data compare_data(initial_data.begin(), initial_data.end());
Data data(initial_data.begin(), initial_data.end());
Compare_Data::iterator citr = compare_data.erase(compare_data.cbegin() + 2, compare_data.cbegin() + 4);
Data::iterator ditr = data.erase(data.cbegin() + 2, data.cbegin() + 4);
CHECK(*citr == *ditr);
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_const_ivector_of_pointer_to_pointer)
{
MFPtr i1 = &Functions::f0;
etl::vector<MFPtr, 10> consttest;
consttest.push_back(i1);
const etl::ivector<MFPtr>& ct = consttest;
MFPtr i2 = ct[0];
CHECK(i1 == i2);
}
//*************************************************************************
#if ETL_HAS_INITIALIZER_LIST
TEST(test_make_vector)
{
MFPtr values[] = {&Functions::f0, &Functions::f1, &Functions::f2, &Functions::f3, &Functions::f4,
&Functions::f5, &Functions::f6, &Functions::f7, &Functions::f8, &Functions::f9};
auto data = etl::make_vector(values[0], values[1], values[2], values[3], values[4], values[5], values[6], values[7], values[8], values[9]);
CHECK_TRUE(&Functions::f0 == data[0]);
CHECK_TRUE(&Functions::f1 == data[1]);
CHECK_TRUE(&Functions::f2 == data[2]);
CHECK_TRUE(&Functions::f3 == data[3]);
CHECK_TRUE(&Functions::f4 == data[4]);
CHECK_TRUE(&Functions::f5 == data[5]);
CHECK_TRUE(&Functions::f6 == data[6]);
CHECK_TRUE(&Functions::f7 == data[7]);
CHECK_TRUE(&Functions::f8 == data[8]);
CHECK_TRUE(&Functions::f9 == data[9]);
}
#endif
//*************************************************************************
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<MFPtr, 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<MFPtr, 4> etl_data(4);
etl::vector<MFPtr, 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<MFPtr, 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);
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_functions_can_be_called)
{
Data data(initial_data.begin(), initial_data.end());
for (size_t i = 0; i < data.size(); ++i)
{
MFPtr mfptr = data[i];
CHECK_TRUE(i * i == (functions.*mfptr)(i));
}
}
}
} // namespace