diff --git a/include/etl/private/pvoidvector.h b/include/etl/private/pvoidvector.h index 9786d740..eda3b020 100644 --- a/include/etl/private/pvoidvector.h +++ b/include/etl/private/pvoidvector.h @@ -230,6 +230,7 @@ namespace etl //********************************************************************* reference operator [](size_t i) { + ETL_ASSERT_CHECK_INDEX_OPERATOR(i < size(), ETL_ERROR(vector_out_of_bounds)); return p_buffer[i]; } @@ -240,6 +241,7 @@ namespace etl //********************************************************************* const_reference operator [](size_t i) const { + ETL_ASSERT_CHECK_INDEX_OPERATOR(i < size(), ETL_ERROR(vector_out_of_bounds)); return p_buffer[i]; } @@ -273,6 +275,7 @@ namespace etl //********************************************************************* reference front() { + ETL_ASSERT_CHECK_EXTRA(size() > 0, ETL_ERROR(vector_out_of_bounds)); return p_buffer[0]; } @@ -282,6 +285,7 @@ namespace etl //********************************************************************* const_reference front() const { + ETL_ASSERT_CHECK_EXTRA(size() > 0, ETL_ERROR(vector_out_of_bounds)); return p_buffer[0]; } @@ -291,6 +295,7 @@ namespace etl //********************************************************************* reference back() { + ETL_ASSERT_CHECK_EXTRA(size() > 0, ETL_ERROR(vector_out_of_bounds)); return *(p_end - 1); } @@ -300,6 +305,7 @@ namespace etl //********************************************************************* const_reference back() const { + ETL_ASSERT_CHECK_EXTRA(size() > 0, ETL_ERROR(vector_out_of_bounds)); return *(p_end - 1); } @@ -440,6 +446,7 @@ namespace etl iterator insert(const_iterator position, value_type value) { ETL_ASSERT(size() != CAPACITY, ETL_ERROR(vector_full)); + ETL_ASSERT_CHECK_EXTRA(cbegin() <= position && position <= cend(), ETL_ERROR(vector_out_of_bounds)); iterator position_ = to_iterator(position); @@ -473,6 +480,7 @@ namespace etl iterator emplace(const_iterator position) { ETL_ASSERT(size() != CAPACITY, ETL_ERROR(vector_full)); + ETL_ASSERT_CHECK_EXTRA(cbegin() <= position && position <= cend(), ETL_ERROR(vector_out_of_bounds)); iterator position_ = to_iterator(position); @@ -503,6 +511,7 @@ namespace etl iterator emplace(const_iterator position, value_type value) { ETL_ASSERT(size() != CAPACITY, ETL_ERROR(vector_full)); + ETL_ASSERT_CHECK_EXTRA(cbegin() <= position && position <= cend(), ETL_ERROR(vector_out_of_bounds)); iterator position_ = to_iterator(position); @@ -536,6 +545,7 @@ namespace etl void insert(const_iterator position, size_t n, value_type value) { ETL_ASSERT_OR_RETURN((size() + n) <= CAPACITY, ETL_ERROR(vector_full)); + ETL_ASSERT_CHECK_EXTRA(cbegin() <= position && position <= cend(), ETL_ERROR(vector_out_of_bounds)); iterator position_ = to_iterator(position); @@ -565,6 +575,7 @@ namespace etl iterator position_ = to_iterator(position); ETL_ASSERT_OR_RETURN((size() + count) <= CAPACITY, ETL_ERROR(vector_full)); + ETL_ASSERT_CHECK_EXTRA(cbegin() <= position && position <= cend(), ETL_ERROR(vector_out_of_bounds)); etl::mem_move(position_, p_end, position_ + count); etl::copy(first, last, position_); @@ -588,6 +599,7 @@ namespace etl iterator position_ = to_iterator(position); ETL_ASSERT_OR_RETURN((size() + count) <= CAPACITY, ETL_ERROR(vector_full)); + ETL_ASSERT_CHECK_EXTRA(cbegin() <= position && position <= cend(), ETL_ERROR(vector_out_of_bounds)); etl::mem_move(position_, p_end, position_ + count); etl::mem_move((void**)first, (void**)last, position_); @@ -601,6 +613,8 @@ namespace etl //********************************************************************* iterator erase(iterator i_element) { + ETL_ASSERT_CHECK_EXTRA(cbegin() <= i_element && i_element < cend(), ETL_ERROR(vector_out_of_bounds)); + etl::mem_move(i_element + 1, end(), i_element); --p_end; @@ -614,6 +628,8 @@ namespace etl //********************************************************************* iterator erase(const_iterator i_element) { + ETL_ASSERT_CHECK_EXTRA(cbegin() <= i_element && i_element < cend(), ETL_ERROR(vector_out_of_bounds)); + iterator i_element_ = to_iterator(i_element); etl::mem_move(i_element_ + 1, end(), i_element_); @@ -632,6 +648,8 @@ namespace etl //********************************************************************* iterator erase(const_iterator first, const_iterator last) { + ETL_ASSERT_CHECK_EXTRA(cbegin() <= first && first <= last && last <= cend(), ETL_ERROR(vector_out_of_bounds)); + iterator first_ = to_iterator(first); iterator last_ = to_iterator(last); diff --git a/include/etl/vector.h b/include/etl/vector.h index e85d58f2..c36f9b55 100644 --- a/include/etl/vector.h +++ b/include/etl/vector.h @@ -279,6 +279,7 @@ namespace etl //********************************************************************* reference operator [](size_t i) { + ETL_ASSERT_CHECK_INDEX_OPERATOR(i < size(), ETL_ERROR(vector_out_of_bounds)); return p_buffer[i]; } @@ -289,6 +290,7 @@ namespace etl //********************************************************************* const_reference operator [](size_t i) const { + ETL_ASSERT_CHECK_INDEX_OPERATOR(i < size(), ETL_ERROR(vector_out_of_bounds)); return p_buffer[i]; } @@ -322,6 +324,7 @@ namespace etl //********************************************************************* reference front() { + ETL_ASSERT_CHECK_EXTRA(size() > 0, ETL_ERROR(vector_out_of_bounds)); return *p_buffer; } @@ -331,6 +334,7 @@ namespace etl //********************************************************************* const_reference front() const { + ETL_ASSERT_CHECK_EXTRA(size() > 0, ETL_ERROR(vector_out_of_bounds)); return *p_buffer; } @@ -340,6 +344,7 @@ namespace etl //********************************************************************* reference back() { + ETL_ASSERT_CHECK_EXTRA(size() > 0, ETL_ERROR(vector_out_of_bounds)); return *(p_end - 1); } @@ -349,6 +354,7 @@ namespace etl //********************************************************************* const_reference back() const { + ETL_ASSERT_CHECK_EXTRA(size() > 0, ETL_ERROR(vector_out_of_bounds)); return *(p_end - 1); } @@ -570,6 +576,7 @@ namespace etl iterator insert(const_iterator position, const_reference value) { ETL_ASSERT(size() != CAPACITY, ETL_ERROR(vector_full)); + ETL_ASSERT_CHECK_EXTRA(cbegin() <= position && position <= cend(), ETL_ERROR(vector_out_of_bounds)); iterator position_ = to_iterator(position); @@ -597,6 +604,7 @@ namespace etl iterator insert(const_iterator position, rvalue_reference value) { ETL_ASSERT(size() != CAPACITY, ETL_ERROR(vector_full)); + ETL_ASSERT_CHECK_EXTRA(cbegin() <= position && position <= cend(), ETL_ERROR(vector_out_of_bounds)); iterator position_ = to_iterator(position); @@ -623,6 +631,7 @@ namespace etl iterator emplace(const_iterator position, Args && ... args) { ETL_ASSERT(!full(), ETL_ERROR(vector_full)); + ETL_ASSERT_CHECK_EXTRA(cbegin() <= position && position <= cend(), ETL_ERROR(vector_out_of_bounds)); iterator position_ = to_iterator(position); @@ -650,6 +659,7 @@ namespace etl iterator emplace(const_iterator position, const T1& value1) { ETL_ASSERT(!full(), ETL_ERROR(vector_full)); + ETL_ASSERT_CHECK_EXTRA(cbegin() <= position && position <= cend(), ETL_ERROR(vector_out_of_bounds)); iterator position_ = to_iterator(position); @@ -677,6 +687,7 @@ namespace etl iterator emplace(const_iterator position, const T1& value1, const T2& value2) { ETL_ASSERT(!full(), ETL_ERROR(vector_full)); + ETL_ASSERT_CHECK_EXTRA(cbegin() <= position && position <= cend(), ETL_ERROR(vector_out_of_bounds)); iterator position_ = to_iterator(position); @@ -704,6 +715,7 @@ namespace etl iterator emplace(const_iterator position, const T1& value1, const T2& value2, const T3& value3) { ETL_ASSERT(!full(), ETL_ERROR(vector_full)); + ETL_ASSERT_CHECK_EXTRA(cbegin() <= position && position <= cend(), ETL_ERROR(vector_out_of_bounds)); iterator position_ = to_iterator(position); @@ -731,6 +743,7 @@ namespace etl iterator emplace(const_iterator position, const T1& value1, const T2& value2, const T3& value3, const T4& value4) { ETL_ASSERT(!full(), ETL_ERROR(vector_full)); + ETL_ASSERT_CHECK_EXTRA(cbegin() <= position && position <= cend(), ETL_ERROR(vector_out_of_bounds)); iterator position_ = to_iterator(position); @@ -765,6 +778,7 @@ namespace etl void insert(const_iterator position, size_t n, parameter_t value) { ETL_ASSERT_OR_RETURN((size() + n) <= CAPACITY, ETL_ERROR(vector_full)); + ETL_ASSERT_CHECK_EXTRA(cbegin() <= position && position <= cend(), ETL_ERROR(vector_out_of_bounds)); iterator position_ = to_iterator(position); @@ -804,8 +818,8 @@ namespace etl etl::uninitialized_fill_n(p_end, construct_new_n, value); ETL_ADD_DEBUG_COUNT(construct_new_n); - // Copy new. - etl::fill_n(p_buffer + insert_begin, copy_new_n, value); + // Copy new. + etl::fill_n(p_buffer + insert_begin, copy_new_n, value); p_end += n; } @@ -824,6 +838,7 @@ namespace etl size_t count = etl::distance(first, last); ETL_ASSERT_OR_RETURN((size() + count) <= CAPACITY, ETL_ERROR(vector_full)); + ETL_ASSERT_CHECK_EXTRA(cbegin() <= position && position <= cend(), ETL_ERROR(vector_out_of_bounds)); size_t insert_n = count; size_t insert_begin = etl::distance(cbegin(), position); @@ -874,6 +889,8 @@ namespace etl //********************************************************************* iterator erase(iterator i_element) { + ETL_ASSERT_CHECK_EXTRA(cbegin() <= i_element && i_element < cend(), ETL_ERROR(vector_out_of_bounds)); + etl::move(i_element + 1, end(), i_element); destroy_back(); @@ -887,6 +904,8 @@ namespace etl //********************************************************************* iterator erase(const_iterator i_element) { + ETL_ASSERT_CHECK_EXTRA(cbegin() <= i_element && i_element < cend(), ETL_ERROR(vector_out_of_bounds)); + iterator i_element_ = to_iterator(i_element); etl::move(i_element_ + 1, end(), i_element_); @@ -905,6 +924,8 @@ namespace etl //********************************************************************* iterator erase(const_iterator first, const_iterator last) { + ETL_ASSERT_CHECK_EXTRA(cbegin() <= first && first <= last && last <= cend(), ETL_ERROR(vector_out_of_bounds)); + iterator first_ = to_iterator(first); iterator last_ = to_iterator(last); diff --git a/test/test_vector.cpp b/test/test_vector.cpp index 38c70791..f7df1aaf 100644 --- a/test/test_vector.cpp +++ b/test/test_vector.cpp @@ -276,8 +276,8 @@ namespace Data data(10); const Data constData(10); - CHECK_EQUAL(&data[10], data.end()); - CHECK_EQUAL(&constData[10], constData.end()); + CHECK_EQUAL(data.begin() + data.size(), data.end()); + CHECK_EQUAL(constData.begin() + constData.size(), constData.end()); } //************************************************************************* @@ -459,6 +459,8 @@ namespace { CHECK_EQUAL(data[i], compare_data[i]); } + + CHECK_THROW(data[data.size()], etl::vector_out_of_bounds); } //************************************************************************* @@ -472,6 +474,8 @@ namespace { CHECK_EQUAL(data[i], compare_data[i]); } + + CHECK_THROW(data[data.size()], etl::vector_out_of_bounds); } //************************************************************************* @@ -509,6 +513,9 @@ namespace 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); } //************************************************************************* @@ -518,6 +525,9 @@ namespace 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); } //************************************************************************* @@ -527,6 +537,9 @@ namespace 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); } //************************************************************************* @@ -536,8 +549,10 @@ namespace 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) @@ -778,6 +793,18 @@ namespace } } + //************************************************************************* + 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) { @@ -805,6 +832,18 @@ namespace } } + //************************************************************************* + 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) { @@ -849,6 +888,15 @@ namespace CHECK_TRUE(std::equal(compare_data.begin(), compare_data.end(), data.begin())); } + //************************************************************************* + TEST(test_emplace_out_of_range) + { + etl::vector data; + etl::vector data2; + + CHECK_THROW(data.emplace(data2.end());, etl::vector_out_of_bounds); + } + //************************************************************************* TEST(test_emplace_back_default) { @@ -943,6 +991,17 @@ namespace } } + //************************************************************************* + 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); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { @@ -996,6 +1055,15 @@ namespace } } + //************************************************************************* + 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_range_excess) { @@ -1046,6 +1114,14 @@ namespace 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) { @@ -1071,6 +1147,14 @@ namespace 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) { @@ -1096,6 +1180,15 @@ namespace 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) { diff --git a/test/test_vector_external_buffer.cpp b/test/test_vector_external_buffer.cpp index 773e68ea..a8b0c07b 100644 --- a/test/test_vector_external_buffer.cpp +++ b/test/test_vector_external_buffer.cpp @@ -268,8 +268,8 @@ namespace Data data(10, buffer1, SIZE); const Data constData(10, buffer1, SIZE); - CHECK_EQUAL(&data[10], data.end()); - CHECK_EQUAL(&constData[10], constData.end()); + CHECK_EQUAL(data.begin() + data.size(), data.end()); + CHECK_EQUAL(constData.begin() + constData.size(), constData.end()); } //************************************************************************* @@ -462,6 +462,8 @@ namespace { CHECK_EQUAL(data[i], compare_data[i]); } + + CHECK_THROW(data[data.size()], etl::vector_out_of_bounds); } //************************************************************************* @@ -475,6 +477,8 @@ namespace { CHECK_EQUAL(data[i], compare_data[i]); } + + CHECK_THROW(data[data.size()], etl::vector_out_of_bounds); } //************************************************************************* @@ -512,6 +516,9 @@ namespace Data data(initial_data.begin(), initial_data.end(), buffer1, SIZE); CHECK_EQUAL(compare_data.front(), data.front()); + + Data emptyData(buffer1, SIZE); + CHECK_THROW(emptyData.front(), etl::vector_out_of_bounds); } //************************************************************************* @@ -521,6 +528,9 @@ namespace const Data data(initial_data.begin(), initial_data.end(), buffer1, SIZE); CHECK_EQUAL(compare_data.front(), data.front()); + + const Data emptyData(buffer1, SIZE); + CHECK_THROW(emptyData.front(), etl::vector_out_of_bounds); } //************************************************************************* @@ -530,6 +540,9 @@ namespace Data data(initial_data.begin(), initial_data.end(), buffer1, SIZE); CHECK_EQUAL(compare_data.back(), data.back()); + + Data emptyData(buffer1, SIZE); + CHECK_THROW(emptyData.back(), etl::vector_out_of_bounds); } //************************************************************************* @@ -539,8 +552,10 @@ namespace const Data data(initial_data.begin(), initial_data.end(), buffer1, SIZE); CHECK_EQUAL(compare_data.back(), data.back()); - } + const Data emptyData(buffer1, SIZE); + CHECK_THROW(emptyData.back(), etl::vector_out_of_bounds); + } //************************************************************************* TEST_FIXTURE(SetupFixture, test_data) @@ -781,6 +796,18 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_value_outofbounds) + { + const size_t INITIAL_SIZE = 5; + const int INITIAL_VALUE = 1; + + Data data(buffer1, SIZE); + Data data2(buffer2, SIZE); + 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_array_bounds_push.h" TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) @@ -831,6 +858,16 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_n_value_outofbounds) + { + const int INITIAL_VALUE = 11; + Data data(buffer1, SIZE); + Data data2(buffer2, SIZE); + + CHECK_THROW(data.insert(data2.end(), 1, INITIAL_VALUE);, etl::vector_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { @@ -909,6 +946,14 @@ namespace CHECK_THROW(data.insert(data.begin() + offset, initial_data.begin(), initial_data.end()), etl::vector_full); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_range_out_of_bounds) + { + Data data(buffer1, SIZE); + Data data2(buffer2, SIZE); + + CHECK_THROW(data.insert(data2.end(), insert_data.cbegin(), insert_data.cend());, etl::vector_out_of_bounds); + } //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single) @@ -929,6 +974,14 @@ namespace CHECK(is_equal); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_iterator_outofbounds) + { + Data data(initial_data.begin(), initial_data.end(), buffer1, SIZE); + + CHECK_THROW(data.erase(data.end());, etl::vector_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { @@ -948,6 +1001,15 @@ namespace CHECK(is_equal); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_range_outofbounds) + { + Data data(initial_data.begin(), initial_data.end(), buffer1, SIZE); + Data data2(initial_data.begin(), initial_data.end(), buffer2, SIZE); + + CHECK_THROW(data.erase(data2.begin(), data2.end());, etl::vector_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_clear) { diff --git a/test/test_vector_non_trivial.cpp b/test/test_vector_non_trivial.cpp index 0acb1a22..413ca3cd 100644 --- a/test/test_vector_non_trivial.cpp +++ b/test/test_vector_non_trivial.cpp @@ -364,8 +364,8 @@ namespace DataDC data(10); const DataDC constData(10); - CHECK_EQUAL(&data[10], data.end()); - CHECK_EQUAL(&constData[10], constData.end()); + CHECK_EQUAL(data.begin() + data.size(), data.end()); + CHECK_EQUAL(constData.begin() + constData.size(), constData.end()); } //************************************************************************* @@ -465,6 +465,8 @@ namespace { CHECK_EQUAL(data[i], compare_data[i]); } + + CHECK_THROW(data[data.size()], etl::vector_out_of_bounds); } //************************************************************************* @@ -478,6 +480,8 @@ namespace { CHECK_EQUAL(data[i], compare_data[i]); } + + CHECK_THROW(data[data.size()], etl::vector_out_of_bounds); } //************************************************************************* @@ -515,6 +519,9 @@ namespace DataNDC data(initial_data.begin(), initial_data.end()); CHECK(data.front() == compare_data.front()); + + DataNDC emptyData; + CHECK_THROW(emptyData.front(), etl::vector_out_of_bounds); } //************************************************************************* @@ -524,6 +531,9 @@ namespace const DataNDC data(initial_data.begin(), initial_data.end()); CHECK(data.front() == compare_data.front()); + + const DataNDC emptyData; + CHECK_THROW(emptyData.front(), etl::vector_out_of_bounds); } //************************************************************************* @@ -533,6 +543,9 @@ namespace DataNDC data(initial_data.begin(), initial_data.end()); CHECK(data.back() == compare_data.back()); + + DataNDC emptyData; + CHECK_THROW(emptyData.back(), etl::vector_out_of_bounds); } //************************************************************************* @@ -542,6 +555,9 @@ namespace const DataNDC data(initial_data.begin(), initial_data.end()); CHECK(data.back() == compare_data.back()); + + const DataNDC emptyData; + CHECK_THROW(emptyData.back(), etl::vector_out_of_bounds); } //************************************************************************* @@ -934,6 +950,18 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_value_outofbounds) + { + const size_t INITIAL_SIZE = 5; + const NDC INITIAL_VALUE("1"); + + DataNDC data; + data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE); + DataNDC data2; + CHECK_THROW(data.insert(data2.cbegin(), INITIAL_VALUE), etl::vector_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_emplace_position_value) { @@ -961,6 +989,28 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_emplace_position_value_outofbounds) + { + const size_t INITIAL_SIZE = 5; + const std::string INITIAL_VALUE("1"); + + DataNDC data; + DataNDC 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_out_of_range) + { + DataNDC data; + DataNDC data2; + const std::string INITIAL_VALUE("1"); + + CHECK_THROW(data.emplace(data2.end(), INITIAL_VALUE);, etl::vector_out_of_bounds); + } + //************************************************************************* #include "etl/private/diagnostic_array_bounds_push.h" TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) @@ -1012,6 +1062,16 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_n_value_outofbounds) + { + DataNDC data; + DataNDC data2; + const NDC INITIAL_VALUE("1"); + + CHECK_THROW(data.insert(data2.end(), 1, INITIAL_VALUE);, etl::vector_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { @@ -1091,6 +1151,15 @@ namespace CHECK_THROW(data.insert(data.begin() + offset, initial_data.begin(), initial_data.end()), etl::vector_full); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_range_out_of_bounds) + { + DataNDC data; + DataNDC data2; + + CHECK_THROW(data.insert(data2.end(), insert_data.cbegin(), insert_data.cend());, etl::vector_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single) { @@ -1110,6 +1179,14 @@ namespace CHECK(is_equal); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_iterator_outofbounds) + { + DataNDC data(initial_data.begin(), initial_data.end()); + + CHECK_THROW(data.erase(data.end());, etl::vector_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { @@ -1129,6 +1206,15 @@ namespace CHECK(is_equal); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_range_outofbounds) + { + DataNDC data(initial_data.begin(), initial_data.end()); + DataNDC 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) { diff --git a/test/test_vector_pointer.cpp b/test/test_vector_pointer.cpp index f59c8d29..aa41eac0 100644 --- a/test/test_vector_pointer.cpp +++ b/test/test_vector_pointer.cpp @@ -459,8 +459,8 @@ namespace Data data(10); const Data constData(10); - CHECK_EQUAL(&data[10], data.end()); - CHECK_EQUAL(&constData[10], constData.end()); + CHECK_EQUAL(data.begin() + data.size(), data.end()); + CHECK_EQUAL(constData.begin() + constData.size(), constData.end()); } //************************************************************************* @@ -469,8 +469,8 @@ namespace CData data(10); const CData constData(10); - CHECK_EQUAL(&data[10], data.end()); - CHECK_EQUAL(&constData[10], constData.end()); + CHECK_EQUAL(data.begin() + data.size(), data.end()); + CHECK_EQUAL(constData.begin() + constData.size(), constData.end()); } //************************************************************************* @@ -654,6 +654,8 @@ namespace { CHECK_EQUAL(data[i], compare_data[i]); } + + CHECK_THROW(data[data.size()], etl::vector_out_of_bounds); } //************************************************************************* @@ -667,6 +669,8 @@ namespace { CHECK_EQUAL(data[i], compare_data[i]); } + + CHECK_THROW(data[data.size()], etl::vector_out_of_bounds); } //************************************************************************* @@ -680,6 +684,8 @@ namespace { CHECK_EQUAL(data[i], compare_data[i]); } + + CHECK_THROW(data[data.size()], etl::vector_out_of_bounds); } //************************************************************************* @@ -693,6 +699,8 @@ namespace { CHECK_EQUAL(data[i], compare_data[i]); } + + CHECK_THROW(data[data.size()], etl::vector_out_of_bounds); } //************************************************************************* @@ -758,6 +766,9 @@ namespace 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); } //************************************************************************* @@ -767,6 +778,9 @@ namespace CData data(initial_data.begin(), initial_data.end()); CHECK(data.front() == compare_data.front()); + + CData emptyData; + CHECK_THROW(emptyData.front(), etl::vector_out_of_bounds); } //************************************************************************* @@ -776,6 +790,9 @@ namespace 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); } //************************************************************************* @@ -785,6 +802,9 @@ namespace const CData data(initial_data.begin(), initial_data.end()); CHECK(data.front() == compare_data.front()); + + const CData emptyData; + CHECK_THROW(emptyData.front(), etl::vector_out_of_bounds); } //************************************************************************* @@ -794,6 +814,9 @@ namespace 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); } //************************************************************************* @@ -803,6 +826,9 @@ namespace CData data(initial_data.begin(), initial_data.end()); CHECK(data.back() == compare_data.back()); + + CData emptyData; + CHECK_THROW(emptyData.back(), etl::vector_out_of_bounds); } //************************************************************************* @@ -812,6 +838,9 @@ namespace 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); } //************************************************************************* @@ -821,6 +850,9 @@ namespace const CData data(initial_data.begin(), initial_data.end()); CHECK(data.back() == compare_data.back()); + + const CData emptyData; + CHECK_THROW(emptyData.back(), etl::vector_out_of_bounds); } //************************************************************************* @@ -1200,6 +1232,18 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_value_outofbounds) + { + const size_t INITIAL_SIZE = 5; + 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_const_insert_position_value) { @@ -1225,6 +1269,18 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_insert_position_value_outofbounds) + { + const size_t INITIAL_SIZE = 5; + int INITIAL_VALUE = 1; + + CData data; + CData 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_array_bounds_push.h" TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) @@ -1273,6 +1329,18 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_emplace_position_value_outofbounds) + { + const size_t INITIAL_SIZE = 5; + 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_FIXTURE(SetupFixture, test_insert_position_n_value) { @@ -1296,6 +1364,16 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_n_value_outofbounds) + { + int INITIAL_VALUE = 0; + Data data; + Data data2; + + CHECK_THROW(data.insert(data2.end(), 1, &INITIAL_VALUE);, etl::vector_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_insert_position_n_value) { @@ -1319,6 +1397,16 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_insert_position_n_value_outofbounds) + { + int INITIAL_VALUE = 0; + CData data; + CData data2; + + CHECK_THROW(data.insert(data2.end(), 1, &INITIAL_VALUE);, etl::vector_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { @@ -1394,6 +1482,15 @@ namespace } } + //************************************************************************* + 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) { @@ -1417,6 +1514,14 @@ namespace } } + //************************************************************************* + 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_const_insert_position_range) { @@ -1440,6 +1545,15 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_insert_position_range_out_of_bounds) + { + CData data; + CData data2; + + CHECK_THROW(data.insert(data2.end(), insert_data.cbegin(), insert_data.cend());, etl::vector_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range_excess) { @@ -1506,6 +1620,14 @@ namespace 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_const_erase_single_iterator) { @@ -1522,6 +1644,14 @@ namespace CHECK(is_equal); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_erase_single_iterator_outofbounds) + { + CData data(initial_data.begin(), initial_data.end()); + + CHECK_THROW(data.erase(data.end());, etl::vector_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_erase_single_const_iterator) { @@ -1538,6 +1668,14 @@ namespace CHECK(is_equal); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_erase_single_const_iterator_outofbounds) + { + CData data(initial_data.begin(), initial_data.end()); + + CHECK_THROW(data.erase(data.cend());, etl::vector_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { @@ -1554,6 +1692,15 @@ namespace 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_const_erase_range) { @@ -1569,6 +1716,15 @@ namespace CHECK(is_equal); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_erase_range_outofbounds) + { + CData data(initial_data.begin(), initial_data.end()); + CData 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) { diff --git a/test/test_vector_pointer_external_buffer.cpp b/test/test_vector_pointer_external_buffer.cpp index 975a8d7c..330801d8 100644 --- a/test/test_vector_pointer_external_buffer.cpp +++ b/test/test_vector_pointer_external_buffer.cpp @@ -448,8 +448,8 @@ namespace Data data(10, buffer1, SIZE); const Data constData(10, buffer2, SIZE); - CHECK_EQUAL(&data[10], data.end()); - CHECK_EQUAL(&constData[10], constData.end()); + CHECK_EQUAL(data.begin() + data.size(), data.end()); + CHECK_EQUAL(constData.begin() + constData.size(), constData.end()); } //************************************************************************* @@ -458,8 +458,8 @@ namespace CData data(10, buffer1, SIZE); const CData constData(10, buffer2, SIZE); - CHECK_EQUAL(&data[10], data.end()); - CHECK_EQUAL(&constData[10], constData.end()); + CHECK_EQUAL(data.begin() + data.size(), data.end()); + CHECK_EQUAL(constData.begin() + constData.size(), constData.end()); } //************************************************************************* @@ -645,6 +645,8 @@ namespace { CHECK_EQUAL(data[i], compare_data[i]); } + + CHECK_THROW(data[data.size()], etl::vector_out_of_bounds); } //************************************************************************* @@ -658,6 +660,8 @@ namespace { CHECK_EQUAL(data[i], compare_data[i]); } + + CHECK_THROW(data[data.size()], etl::vector_out_of_bounds); } //************************************************************************* @@ -671,6 +675,8 @@ namespace { CHECK_EQUAL(data[i], compare_data[i]); } + + CHECK_THROW(data[data.size()], etl::vector_out_of_bounds); } //************************************************************************* @@ -684,6 +690,8 @@ namespace { CHECK_EQUAL(data[i], compare_data[i]); } + + CHECK_THROW(data[data.size()], etl::vector_out_of_bounds); } //************************************************************************* @@ -749,6 +757,9 @@ namespace Data data(initial_data.begin(), initial_data.end(), buffer1, SIZE); CHECK(data.front() == compare_data.front()); + + Data emptyData(buffer1, SIZE); + CHECK_THROW(emptyData.front(), etl::vector_out_of_bounds); } //************************************************************************* @@ -758,6 +769,9 @@ namespace CData data(initial_data.begin(), initial_data.end(), buffer1, SIZE); CHECK(data.front() == compare_data.front()); + + CData emptyData(buffer1, SIZE); + CHECK_THROW(emptyData.front(), etl::vector_out_of_bounds); } //************************************************************************* @@ -767,6 +781,9 @@ namespace const Data data(initial_data.begin(), initial_data.end(), buffer1, SIZE); CHECK(data.front() == compare_data.front()); + + const Data emptyData(buffer1, SIZE); + CHECK_THROW(emptyData.front(), etl::vector_out_of_bounds); } //************************************************************************* @@ -776,6 +793,9 @@ namespace const CData data(initial_data.begin(), initial_data.end(), buffer1, SIZE); CHECK(data.front() == compare_data.front()); + + const CData emptyData(buffer1, SIZE); + CHECK_THROW(emptyData.front(), etl::vector_out_of_bounds); } //************************************************************************* @@ -785,6 +805,9 @@ namespace Data data(initial_data.begin(), initial_data.end(), buffer1, SIZE); CHECK(data.back() == compare_data.back()); + + Data emptyData(buffer1, SIZE); + CHECK_THROW(emptyData.back(), etl::vector_out_of_bounds); } //************************************************************************* @@ -794,6 +817,9 @@ namespace CData data(initial_data.begin(), initial_data.end(), buffer1, SIZE); CHECK(data.back() == compare_data.back()); + + CData emptyData(buffer1, SIZE); + CHECK_THROW(emptyData.back(), etl::vector_out_of_bounds); } //************************************************************************* @@ -803,6 +829,9 @@ namespace const Data data(initial_data.begin(), initial_data.end(), buffer1, SIZE); CHECK(data.back() == compare_data.back()); + + const Data emptyData(buffer1, SIZE); + CHECK_THROW(emptyData.back(), etl::vector_out_of_bounds); } //************************************************************************* @@ -812,6 +841,9 @@ namespace const CData data(initial_data.begin(), initial_data.end(), buffer1, SIZE); CHECK(data.back() == compare_data.back()); + + const CData emptyData(buffer1, SIZE); + CHECK_THROW(emptyData.back(), etl::vector_out_of_bounds); } //************************************************************************* @@ -1149,6 +1181,18 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_value_outofbounds) + { + const size_t INITIAL_SIZE = 5UL; + int INITIAL_VALUE = 1; + + Data data(buffer1, SIZE); + Data data2(buffer2, SIZE); + 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_const_insert_position_value) { @@ -1174,6 +1218,18 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_insert_position_value_outofbounds) + { + const size_t INITIAL_SIZE = 5UL; + int INITIAL_VALUE = 1; + + CData data(buffer1, SIZE); + CData data2(buffer2, SIZE); + 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_array_bounds_push.h" TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) @@ -1222,6 +1278,18 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_emplace_position_value_outofbounds) + { + const size_t INITIAL_SIZE = 5UL; + int INITIAL_VALUE = 1; + + Data data(buffer1, SIZE); + Data data2(buffer2, SIZE); + data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE); + CHECK_THROW(data.emplace(data2.cbegin(), &INITIAL_VALUE), etl::vector_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value) { @@ -1245,6 +1313,16 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_n_value_outofbounds) + { + int INITIAL_VALUE = 0; + Data data(buffer1, SIZE); + Data data2(buffer2, SIZE); + + CHECK_THROW(data.insert(data2.end(), 1, &INITIAL_VALUE);, etl::vector_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_insert_position_n_value) { @@ -1268,6 +1346,16 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_insert_position_n_value_outofbounds) + { + int INITIAL_VALUE = 0; + CData data(buffer1, SIZE); + CData data2(buffer2, SIZE); + + CHECK_THROW(data.insert(data2.end(), 1, &INITIAL_VALUE);, etl::vector_out_of_bounds); + } + #include "etl/private/diagnostic_array_bounds_push.h" //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) @@ -1345,6 +1433,15 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_range_out_of_bounds) + { + Data data(buffer1, SIZE); + Data data2(buffer2, SIZE); + + CHECK_THROW(data.insert(data2.end(), insert_data.cbegin(), insert_data.cend());, etl::vector_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_insert_position_range) { @@ -1368,6 +1465,15 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_insert_position_range_out_of_bounds) + { + CData data(buffer1, SIZE); + CData data2(buffer2, SIZE); + + CHECK_THROW(data.insert(data2.end(), insert_data.cbegin(), insert_data.cend());, etl::vector_out_of_bounds); + } + #include "etl/private/diagnostic_array_bounds_push.h" //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range_excess) @@ -1435,6 +1541,14 @@ namespace CHECK(is_equal); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_outofbounds) + { + Data data(initial_data.begin(), initial_data.end(), buffer1, SIZE); + + CHECK_THROW(data.erase(data.end());, etl::vector_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_erase_single) { @@ -1450,6 +1564,14 @@ namespace CHECK(is_equal); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_erase_single_outofbounds) + { + CData data(initial_data.begin(), initial_data.end(), buffer1, SIZE); + + CHECK_THROW(data.erase(data.end());, etl::vector_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { @@ -1465,6 +1587,15 @@ namespace CHECK(is_equal); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_range_outofbounds) + { + Data data(initial_data.begin(), initial_data.end(), buffer1, SIZE); + Data data2(initial_data.begin(), initial_data.end(), buffer2, SIZE); + + CHECK_THROW(data.erase(data2.begin(), data2.end());, etl::vector_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_erase_range) { @@ -1480,6 +1611,15 @@ namespace CHECK(is_equal); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_erase_range_outofbounds) + { + CData data(initial_data.begin(), initial_data.end(), buffer1, SIZE); + CData data2(initial_data.begin(), initial_data.end(), buffer2, SIZE); + + CHECK_THROW(data.erase(data2.begin(), data2.end());, etl::vector_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_clear) {