From 496edaf9813440247a1f0a985d07556ce612a905 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 10 Mar 2019 16:05:36 +0000 Subject: [PATCH] Partial implementation --- include/etl/vector.h | 175 +++- support/Release notes.txt | 2 +- test/test_vector_external_buffer.cpp | 1112 ++++++++++++++++++++++++++ test/vs2017/etl.vcxproj | 1 + test/vs2017/etl.vcxproj.filters | 3 + 5 files changed, 1288 insertions(+), 5 deletions(-) create mode 100644 test/test_vector_external_buffer.cpp diff --git a/include/etl/vector.h b/include/etl/vector.h index 577241ce..f791340c 100644 --- a/include/etl/vector.h +++ b/include/etl/vector.h @@ -952,7 +952,25 @@ namespace etl etl::destroy(p_buffer, p_end); ETL_SUBTRACT_DEBUG_COUNT(int32_t(std::distance(p_buffer, p_end))) - p_end = p_buffer; + p_end = p_buffer; + } + + //********************************************************************* + /// Initialise the source vector after a move. + //********************************************************************* + void initialise_source_after_move() + { + ETL_SUBTRACT_DEBUG_COUNT(int32_t(std::distance(p_buffer, p_end))) + + p_end = p_buffer; + } + + //********************************************************************* + /// Initialise the destination vector after a move. + //********************************************************************* + void initialise_destination_after_move() + { + ETL_ADD_DEBUG_COUNT(int32_t(std::distance(p_buffer, p_end))) } //************************************************************************* @@ -962,14 +980,14 @@ namespace etl { uintptr_t length = p_end - p_buffer; p_buffer = p_buffer_; - p_end = p_buffer_ + length; + p_end = p_buffer_ + length; } - private: - pointer p_buffer; ///< Pointer to the start of the buffer. pointer p_end; ///< Pointer to one past the last element in the buffer. + private: + //********************************************************************* /// Create a new element with a default value at the back. //********************************************************************* @@ -1281,6 +1299,155 @@ namespace etl typename etl::aligned_storage::value>::type buffer; }; + //*************************************************************************** + /// A vector implementation that uses a fixed size buffer. + /// The buffer is supplied on construction. + ///\tparam T The element type. + ///\ingroup vector + //*************************************************************************** + template + class vector : public etl::ivector + { + public: + + //************************************************************************* + /// Constructor. + //************************************************************************* + vector(void* buffer, size_t max_size) + : etl::ivector(reinterpret_cast(buffer), max_size) + { + this->initialise(); + } + + //************************************************************************* + /// Constructor, with size. + ///\param initial_size The initial size of the vector. + //************************************************************************* + explicit vector(size_t initial_size, void* buffer, size_t max_size) + : etl::ivector(reinterpret_cast(buffer), max_size) + { + this->initialise(); + this->resize(initial_size); + } + + //************************************************************************* + /// Constructor, from initial size and value. + ///\param initial_size The initial size of the vector. + ///\param value The value to fill the vector with. + //************************************************************************* + vector(size_t initial_size, typename etl::ivector::parameter_t value, void* buffer, size_t max_size) + : etl::ivector(reinterpret_cast(buffer), max_size) + { + this->initialise(); + this->resize(initial_size, value); + } + + //************************************************************************* + /// Constructor, from an iterator range. + ///\tparam TIterator The iterator type. + ///\param first The iterator to the first element. + ///\param last The iterator to the last element + 1. + //************************************************************************* + template + vector(TIterator first, TIterator last, void* buffer, size_t max_size) + : etl::ivector(reinterpret_cast(buffer), max_size) + { + this->assign(first, last); + } + +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) + //************************************************************************* + /// Constructor, from an initializer_list. + //************************************************************************* + vector(std::initializer_list init, void* buffer, size_t max_size) + : etl::ivector(reinterpret_cast(buffer), max_size) + { + this->assign(init.begin(), init.end()); + } +#endif + + //************************************************************************* + /// Copy constructor. + //************************************************************************* + vector(const vector& other, void* buffer, size_t max_size) + : etl::ivector(reinterpret_cast(buffer), max_size) + { + this->assign(other.begin(), other.end()); + } + + //************************************************************************* + /// Assignment operator. + //************************************************************************* + vector& operator = (const vector& rhs) + { + if (&rhs != this) + { + this->assign(rhs.cbegin(), rhs.cend()); + } + + return *this; + } + +#if ETL_CPP11_SUPPORTED + //************************************************************************* + /// Move constructor. + //************************************************************************* + vector(vector&& other, void* buffer, size_t max_size) + : etl::ivector(reinterpret_cast(buffer), max_size) + { + if (this != &other) + { + this->initialise(); + + this->p_buffer = other.p_buffer; + + other.initialise(); + } + } + + //************************************************************************* + /// Move assignment operator. + //************************************************************************* + vector& operator = (vector&& rhs) + { + if (&rhs != this) + { + this->clear(); + this->p_buffer = rhs.p_buffer; + this->p_end = rhs.p_end; + + this->initialise_destination_after_move(); + rhs.initialise_source_after_move(); + } + + return *this; + } +#endif + + //************************************************************************* + /// Destructor. + //************************************************************************* + ~vector() + { + this->clear(); + } + + //************************************************************************* + /// Fix the internal pointers after a low level memory copy. + //************************************************************************* +#ifdef ETL_IVECTOR_REPAIR_ENABLE + virtual +#endif + void repair() + { +//#if ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED +// ETL_ASSERT(std::is_trivially_copyable::value, ETL_ERROR(etl::vector_incompatible_type)); +//#endif +// +// etl::ivector::repair_buffer(this->p_buffer); + } + }; + //*************************************************************************** /// A vector implementation that uses a fixed size buffer. ///\tparam T The element type. diff --git a/support/Release notes.txt b/support/Release notes.txt index b038a690..62f21da1 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,6 +1,6 @@ =============================================================================== 14.14.0 -Fixed string push_back() bug where ther internal terminator was not updated. +Fixed string push_back() bug where the internal terminator was not updated. Basic Conan package added. Added const ref istring constructors. Updated profiles for C++17. diff --git a/test/test_vector_external_buffer.cpp b/test/test_vector_external_buffer.cpp new file mode 100644 index 00000000..19671b63 --- /dev/null +++ b/test/test_vector_external_buffer.cpp @@ -0,0 +1,1112 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2019 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "UnitTest++.h" + +#include +#include +#include +#include + +#include "etl/vector.h" + +namespace +{ + SUITE(test_vector) + { + static const size_t SIZE = 10; + + int buffer[10]; + int buffer2[10]; + + typedef etl::vector Data; + typedef etl::ivector IData; + typedef std::vector 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; + + //************************************************************************* + 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 }; + + 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()); + + std::fill_n(buffer, SIZE, -1); + std::fill_n(buffer2, SIZE, -1); + } + }; + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor) + { + Data data(buffer, SIZE); + + 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()); + } + + //************************************************************************* + TEST(test_iterator_comparison_empty) + { + Data data(buffer, SIZE); + + 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, buffer, 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 compare_data; + compare_data.fill(INITIAL_VALUE); + + Data data(INITIAL_SIZE, INITIAL_VALUE, buffer, SIZE); + + 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, buffer, SIZE), 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(), buffer, SIZE); + + CHECK(data.size() == SIZE); + CHECK(!data.empty()); + } + + //************************************************************************* + TEST(test_constructor_initializer_list) + { + Compare_Data compare_data = { 0, 1, 2, 3 }; + std::initializer_list il = { 0, 1, 2, 3 }; + Data data(il, buffer, SIZE); + + CHECK_EQUAL(compare_data.size(), data.size()); + CHECK(std::equal(compare_data.begin(), compare_data.end(), data.begin())); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_copy_constructor) + { + Data data(initial_data.begin(), initial_data.end(), buffer, SIZE); + Data data2(data, buffer2, SIZE); + CHECK(data2 == data); + + data2[2] = -1; + CHECK(data2 != data); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment) + { + Data data(initial_data.begin(), initial_data.end(), buffer, SIZE); + Data other_data(buffer2, SIZE); + + other_data = data; + + 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(), buffer, SIZE); + // Data data2(buffer2, SIZE); + + // 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); + + // other_data = other_data; + + // 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[10], data.end()); + // CHECK_EQUAL(&constData[10], 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 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_empty) + //{ + // Data data(buffer, SIZE); + // data.resize(data.max_size()); + + // CHECK(data.full()); + // CHECK(!data.empty()); + //} + + ////************************************************************************* + //TEST_FIXTURE(SetupFixture, test_full) + //{ + // Data data(buffer, SIZE); + + // 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 = 0; i < data.size(); ++i) + // { + // CHECK_EQUAL(data[i], compare_data[i]); + // } + //} + + ////************************************************************************* + //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 = 0; i < data.size(); ++i) + // { + // CHECK_EQUAL(data[i], compare_data[i]); + // } + //} + + ////************************************************************************* + //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 = 0; 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 = 0; 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_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()); + //} + + ////************************************************************************* + //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()); + //} + + ////************************************************************************* + //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()); + //} + + ////************************************************************************* + //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()); + //} + + + ////************************************************************************* + //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(buffer, SIZE); + + // 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 compare_data; + // compare_data.fill(INITIAL_VALUE); + + // Data data(buffer, SIZE); + // 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 compare_data; + // compare_data.fill(INITIAL_VALUE); + + // Data data(buffer, SIZE); + + // CHECK_THROW(data.assign(EXCESS_SIZE, INITIAL_VALUE), etl::vector_full); + //} + + ////************************************************************************* + //TEST_FIXTURE(SetupFixture, test_push_back) + //{ + // Compare_Data compare_data; + // Data data(buffer, SIZE); + + // 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(buffer, SIZE); + + // 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(buffer, SIZE); + + // 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_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(buffer, SIZE); + + // 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(buffer, SIZE); + + // 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() + 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); + // } + //} + + ////************************************************************************* + //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.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); + //} + + ////************************************************************************* + //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(buffer, SIZE); + + // 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() + offset, INSERT_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_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.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(buffer, SIZE); + + // 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.begin() + offset, insert_data.begin(), insert_data.end()); + // compare_data.insert(compare_data.begin() + offset, insert_data.begin(), insert_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_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.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.erase(compare_data.begin() + 2); + + // data.erase(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) + //{ + // Compare_Data compare_data(initial_data.begin(), initial_data.end()); + // Data data(initial_data.begin(), initial_data.end()); + + // compare_data.erase(compare_data.begin() + 2, compare_data.begin() + 4); + + // data.erase(data.begin() + 2, data.begin() + 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_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, &data, sizeof(data)); + + // Data& rdata(*reinterpret_cast(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, &data, sizeof(data)); + + // IData& idata(*reinterpret_cast(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 dest(etl::begin(raw), etl::end(raw)); + // etl::vector 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 dest(etl::begin(raw), etl::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); + //} + }; +} diff --git a/test/vs2017/etl.vcxproj b/test/vs2017/etl.vcxproj index d01f21d8..f7b74e0f 100644 --- a/test/vs2017/etl.vcxproj +++ b/test/vs2017/etl.vcxproj @@ -758,6 +758,7 @@ + diff --git a/test/vs2017/etl.vcxproj.filters b/test/vs2017/etl.vcxproj.filters index bb822b22..b800a01d 100644 --- a/test/vs2017/etl.vcxproj.filters +++ b/test/vs2017/etl.vcxproj.filters @@ -1163,6 +1163,9 @@ Source Files + + Source Files +