diff --git a/include/etl/basic_string.h b/include/etl/basic_string.h index 462faec1..4d8157cf 100644 --- a/include/etl/basic_string.h +++ b/include/etl/basic_string.h @@ -560,6 +560,7 @@ namespace etl //********************************************************************* reference operator [](size_type i) { + ETL_ASSERT_CHECK_INDEX_OPERATOR(i < size(), ETL_ERROR(string_out_of_bounds)); return p_buffer[i]; } @@ -570,6 +571,7 @@ namespace etl //********************************************************************* const_reference operator [](size_type i) const { + ETL_ASSERT_CHECK_INDEX_OPERATOR(i < size(), ETL_ERROR(string_out_of_bounds)); return p_buffer[i]; } @@ -603,6 +605,7 @@ namespace etl //********************************************************************* reference front() { + ETL_ASSERT_CHECK_EXTRA(size() > 0, ETL_ERROR(string_out_of_bounds)); return p_buffer[0]; } @@ -612,6 +615,7 @@ namespace etl //********************************************************************* const_reference front() const { + ETL_ASSERT_CHECK_EXTRA(size() > 0, ETL_ERROR(string_out_of_bounds)); return p_buffer[0]; } @@ -621,7 +625,8 @@ namespace etl //********************************************************************* reference back() { - return p_buffer[current_size - 1]; + ETL_ASSERT_CHECK_EXTRA(size() > 0, ETL_ERROR(string_out_of_bounds)); + return p_buffer[size() - 1]; } //********************************************************************* @@ -630,7 +635,8 @@ namespace etl //********************************************************************* const_reference back() const { - return p_buffer[current_size - 1]; + ETL_ASSERT_CHECK_EXTRA(size() > 0, ETL_ERROR(string_out_of_bounds)); + return p_buffer[size() - 1]; } //********************************************************************* @@ -932,6 +938,8 @@ namespace etl //********************************************************************* iterator insert(const_iterator position, T value) { + ETL_ASSERT_CHECK_EXTRA(cbegin() <= position && position <= cend(), ETL_ERROR(string_out_of_bounds)); + // Quick hack, as iterators are pointers. iterator insert_position = to_iterator(position); @@ -984,6 +992,8 @@ namespace etl //********************************************************************* iterator insert(const_iterator position, size_type n, T value) { + ETL_ASSERT_CHECK_EXTRA(cbegin() <= position && position <= cend(), ETL_ERROR(string_out_of_bounds)); + iterator position_ = to_iterator(position); if (n == 0) @@ -1071,6 +1081,9 @@ namespace etl template iterator insert(const_iterator position, TIterator first, TIterator last) { + ETL_ASSERT_CHECK_EXTRA(cbegin() <= position && position <= cend(), ETL_ERROR(string_out_of_bounds)); + ETL_ASSERT_CHECK_EXTRA(first <= last, ETL_ERROR(string_iterator)); + iterator position_ = to_iterator(position); if (first == last) @@ -1307,6 +1320,8 @@ namespace etl //********************************************************************* etl::ibasic_string& erase(size_type position, size_type length_ = npos) { + ETL_ASSERT_CHECK_EXTRA(position <= size(), ETL_ERROR(string_out_of_bounds)); + // Limit the length. length_ = etl::min(length_, size() - position); @@ -1322,6 +1337,8 @@ namespace etl //********************************************************************* iterator erase(iterator i_element) { + ETL_ASSERT_CHECK_EXTRA(cbegin() <= i_element && i_element < cend(), ETL_ERROR(string_out_of_bounds)); + etl::mem_move(i_element + 1, end(), i_element); p_buffer[--current_size] = 0; @@ -1335,6 +1352,8 @@ namespace etl //********************************************************************* iterator erase(const_iterator i_element) { + ETL_ASSERT_CHECK_EXTRA(cbegin() <= i_element && i_element < cend(), ETL_ERROR(string_out_of_bounds)); + iterator i_element_(to_iterator(i_element)); etl::mem_move(i_element + 1, end(), i_element_); @@ -1353,6 +1372,8 @@ namespace etl //********************************************************************* iterator erase(const_iterator first, const_iterator last) { + ETL_ASSERT_CHECK_EXTRA(cbegin() <= first && first <= last && last <= cend(), ETL_ERROR(string_out_of_bounds)); + iterator first_ = to_iterator(first); iterator last_ = to_iterator(last); diff --git a/test/test_string_char.cpp b/test/test_string_char.cpp index 7ee55e32..6cf70b28 100644 --- a/test/test_string_char.cpp +++ b/test/test_string_char.cpp @@ -614,8 +614,8 @@ namespace Text text(initial_text.c_str()); const Text constText(initial_text.c_str()); - CHECK_EQUAL(&text[initial_text.size()], text.end()); - CHECK_EQUAL(&constText[initial_text.size()], constText.end()); + CHECK_EQUAL(text.begin() + text.size(), text.end()); + CHECK_EQUAL(constText.begin() + constText.size(), constText.end()); } //************************************************************************* @@ -910,6 +910,8 @@ namespace } CHECK_FALSE(text.is_truncated()); + + CHECK_THROW(text[text.size()], etl::string_out_of_bounds); } //************************************************************************* @@ -924,6 +926,8 @@ namespace } CHECK_FALSE(text.is_truncated()); + + CHECK_THROW(text[text.size()], etl::string_out_of_bounds); } //************************************************************************* @@ -964,6 +968,9 @@ namespace CHECK(text.front() == compare_text.front()); CHECK_FALSE(text.is_truncated()); + + Text emptyText; + CHECK_THROW(emptyText.front(), etl::string_out_of_bounds); } //************************************************************************* @@ -974,6 +981,9 @@ namespace CHECK(text.front() == compare_text.front()); CHECK_FALSE(text.is_truncated()); + + const Text emptyText; + CHECK_THROW(emptyText.front(), etl::string_out_of_bounds); } //************************************************************************* @@ -984,6 +994,9 @@ namespace CHECK(text.back() == compare_text.back()); CHECK_FALSE(text.is_truncated()); + + Text emptyText; + CHECK_THROW(emptyText.back(), etl::string_out_of_bounds); } //************************************************************************* @@ -994,6 +1007,9 @@ namespace CHECK(text.back() == compare_text.back()); CHECK_FALSE(text.is_truncated()); + + const Text emptyText; + CHECK_THROW(emptyText.back(), etl::string_out_of_bounds); } //************************************************************************* @@ -1327,6 +1343,20 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_value_outofbounds) + { + const size_t INITIAL_SIZE = 5; + const value_t INITIAL_VALUE = STR('A'); + + Text text; + text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); + + Text text2; + + CHECK_THROW(text.insert(text2.cbegin(), INITIAL_VALUE), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { @@ -1402,6 +1432,21 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_n_value_outofbounds) + { + const size_t INITIAL_SIZE = 5UL; + const size_t INSERT_SIZE = 3UL; + const value_t INITIAL_VALUE = STR('A'); + + Text text; + text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); + + Text text2; + + CHECK_THROW(text.insert(text2.cbegin(), INSERT_SIZE, INITIAL_VALUE), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { @@ -1501,6 +1546,30 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_range_outofbounds) + { + const size_t INITIAL_SIZE = 5UL; + + Text text; + text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); + + Text text2; + + CHECK_THROW(text.insert(text2.cbegin(), insert_text.cbegin(), insert_text.cend()), etl::string_out_of_bounds); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_range_swapped_iterators) + { + const size_t INITIAL_SIZE = 5UL; + + Text text; + text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); + + CHECK_THROW(text.insert(text.cbegin(), insert_text.cend(), insert_text.cbegin()), etl::string_iterator); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range_excess) { @@ -3266,6 +3335,23 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_outofbounds) + { + Text text(initial_text.c_str()); + + CHECK_THROW(text.erase(text.end()), etl::string_out_of_bounds); + CHECK_THROW(text.erase(text.cend()), etl::string_out_of_bounds); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_position_outofbounds) + { + Text text(initial_text.c_str()); + + CHECK_THROW(text.erase(text.size() + 1), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { @@ -3283,6 +3369,15 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_range_outofbounds) + { + Text text(initial_text.c_str()); + Text text2(initial_text.c_str()); + + CHECK_THROW(text.erase(text2.begin(), text2.end()), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_clear) { @@ -5043,7 +5138,7 @@ namespace // Test with actual string type. Text text(STR("ABCDEFHIJKL")); size_t hash = etl::hash()(text); - size_t compare_hash = etl::private_hash::generic_hash(reinterpret_cast(&text[0]), reinterpret_cast(&text[text.size()])); + size_t compare_hash = etl::private_hash::generic_hash(reinterpret_cast(text.data()), reinterpret_cast(text.data_end())); CHECK_EQUAL(compare_hash, hash); // Test with interface string type. @@ -5305,7 +5400,7 @@ namespace for (size_t i = text.size(); i < text.max_size(); ++i) { - CHECK_EQUAL(0, text[i]); + CHECK_EQUAL(0, text.data()[i]); } } @@ -5323,7 +5418,7 @@ namespace for (size_t i = text.size(); i < text.max_size(); ++i) { - CHECK_EQUAL(0, text[i]); + CHECK_EQUAL(0, text.data()[i]); } } diff --git a/test/test_string_char_external_buffer.cpp b/test/test_string_char_external_buffer.cpp index 7346042b..e644f578 100644 --- a/test/test_string_char_external_buffer.cpp +++ b/test/test_string_char_external_buffer.cpp @@ -767,8 +767,8 @@ namespace TextBuffer buffer2{0}; const Text constText(initial_text.c_str(), buffer2.data(), buffer2.size()); - CHECK_EQUAL(&text[initial_text.size()], text.end()); - CHECK_EQUAL(&constText[initial_text.size()], constText.end()); + CHECK_EQUAL(text.begin() + text.size(), text.end()); + CHECK_EQUAL(constText.begin() + constText.size(), constText.end()); } //************************************************************************* @@ -1069,6 +1069,8 @@ namespace } CHECK_FALSE(text.is_truncated()); + + CHECK_THROW(text[text.size()], etl::string_out_of_bounds); } //************************************************************************* @@ -1085,6 +1087,8 @@ namespace } CHECK_FALSE(text.is_truncated()); + + CHECK_THROW(text[text.size()], etl::string_out_of_bounds); } //************************************************************************* @@ -1133,6 +1137,10 @@ namespace CHECK(text.front() == compare_text.front()); CHECK_FALSE(text.is_truncated()); + + TextBuffer buffer2{0}; + Text emptyText(buffer2.data(), buffer2.size()); + CHECK_THROW(emptyText.front(), etl::string_out_of_bounds); } //************************************************************************* @@ -1145,6 +1153,10 @@ namespace CHECK(text.front() == compare_text.front()); CHECK_FALSE(text.is_truncated()); + + TextBuffer buffer2{0}; + const Text emptyText(buffer2.data(), buffer2.size()); + CHECK_THROW(emptyText.front(), etl::string_out_of_bounds); } //************************************************************************* @@ -1157,6 +1169,10 @@ namespace CHECK(text.back() == compare_text.back()); CHECK_FALSE(text.is_truncated()); + + TextBuffer buffer2{0}; + Text emptyText(buffer2.data(), buffer2.size()); + CHECK_THROW(emptyText.back(), etl::string_out_of_bounds); } //************************************************************************* @@ -1169,6 +1185,10 @@ namespace CHECK(text.back() == compare_text.back()); CHECK_FALSE(text.is_truncated()); + + TextBuffer buffer2{0}; + const Text emptyText(buffer2.data(), buffer2.size()); + CHECK_THROW(emptyText.back(), etl::string_out_of_bounds); } //************************************************************************* @@ -1531,6 +1551,22 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_value_outofbounds) + { + const size_t INITIAL_SIZE = 5; + const value_t INITIAL_VALUE = STR('A'); + + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); + + TextBuffer buffer2{0}; + Text text2(buffer2.data(), buffer2.size()); + + CHECK_THROW(text.insert(text2.cbegin(), INITIAL_VALUE), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { @@ -1608,6 +1644,23 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_n_value_outofbounds) + { + const size_t INITIAL_SIZE = 5UL; + const size_t INSERT_SIZE = 3UL; + const value_t INITIAL_VALUE = STR('A'); + + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); + + TextBuffer buffer2{0}; + Text text2(buffer2.data(), buffer2.size()); + + CHECK_THROW(text.insert(text2.cbegin(), INSERT_SIZE, INITIAL_VALUE), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { @@ -1709,6 +1762,33 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_range_outofbounds) + { + const size_t INITIAL_SIZE = 5UL; + + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); + + TextBuffer buffer2{0}; + Text text2(buffer2.data(), buffer2.size()); + + CHECK_THROW(text.insert(text2.cbegin(), insert_text.cbegin(), insert_text.cend()), etl::string_out_of_bounds); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_range_swapped_iterators) + { + const size_t INITIAL_SIZE = 5UL; + + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); + + CHECK_THROW(text.insert(text.cbegin(), insert_text.cend(), insert_text.cbegin()), etl::string_iterator); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range_excess) { @@ -3442,6 +3522,25 @@ namespace CHECK_FALSE(text.is_truncated()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_outofbounds) + { + TextBuffer buffer{0}; + Text text(initial_text.c_str(), buffer.data(), buffer.size()); + + CHECK_THROW(text.erase(text.end()), etl::string_out_of_bounds); + CHECK_THROW(text.erase(text.cend()), etl::string_out_of_bounds); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_position_outofbounds) + { + TextBuffer buffer{0}; + Text text(initial_text.c_str(), buffer.data(), buffer.size()); + + CHECK_THROW(text.erase(text.size() + 1), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { @@ -3459,6 +3558,17 @@ namespace CHECK_FALSE(text.is_truncated()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_range_outofbounds) + { + TextBuffer buffer{0}; + Text text(initial_text.c_str(), buffer.data(), buffer.size()); + TextBuffer buffer2{0}; + Text text2(initial_text.c_str(), buffer2.data(), buffer2.size()); + + CHECK_THROW(text.erase(text2.begin(), text2.end()), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_clear) { @@ -5302,7 +5412,7 @@ namespace TextBuffer buffer{0}; Text text(STR("ABCDEFHIJKL"), buffer.data(), buffer.size()); size_t hash = etl::hash()(text); - size_t compare_hash = etl::private_hash::generic_hash(reinterpret_cast(&text[0]), reinterpret_cast(&text[text.size()])); + size_t compare_hash = etl::private_hash::generic_hash(reinterpret_cast(text.data()), reinterpret_cast(text.data_end())); CHECK_EQUAL(compare_hash, hash); // Test with interface string type. @@ -5589,7 +5699,7 @@ namespace for (size_t i = text.size(); i < text.max_size(); ++i) { - CHECK_EQUAL(0, text[i]); + CHECK_EQUAL(0, text.data()[i]); } } @@ -5609,7 +5719,7 @@ namespace for (size_t i = text.size(); i < text.max_size(); ++i) { - CHECK_EQUAL(0, text[i]); + CHECK_EQUAL(0, text.data()[i]); } } diff --git a/test/test_string_u16.cpp b/test/test_string_u16.cpp index 6662a82c..a569d269 100644 --- a/test/test_string_u16.cpp +++ b/test/test_string_u16.cpp @@ -658,8 +658,8 @@ namespace Text text(initial_text.c_str()); const Text constText(initial_text.c_str()); - CHECK_EQUAL(&text[initial_text.size()], text.end()); - CHECK_EQUAL(&constText[initial_text.size()], constText.end()); + CHECK_EQUAL(text.begin() + text.size(), text.end()); + CHECK_EQUAL(constText.begin() + constText.size(), constText.end()); } //************************************************************************* @@ -954,6 +954,8 @@ namespace } CHECK_FALSE(text.is_truncated()); + + CHECK_THROW(text[text.size()], etl::string_out_of_bounds); } //************************************************************************* @@ -968,6 +970,8 @@ namespace } CHECK_FALSE(text.is_truncated()); + + CHECK_THROW(text[text.size()], etl::string_out_of_bounds); } //************************************************************************* @@ -1008,6 +1012,9 @@ namespace CHECK(text.front() == compare_text.front()); CHECK_FALSE(text.is_truncated()); + + Text emptyText; + CHECK_THROW(emptyText.front(), etl::string_out_of_bounds); } //************************************************************************* @@ -1018,6 +1025,9 @@ namespace CHECK(text.front() == compare_text.front()); CHECK_FALSE(text.is_truncated()); + + const Text emptyText; + CHECK_THROW(emptyText.front(), etl::string_out_of_bounds); } //************************************************************************* @@ -1028,6 +1038,9 @@ namespace CHECK(text.back() == compare_text.back()); CHECK_FALSE(text.is_truncated()); + + Text emptyText; + CHECK_THROW(emptyText.back(), etl::string_out_of_bounds); } //************************************************************************* @@ -1038,6 +1051,9 @@ namespace CHECK(text.back() == compare_text.back()); CHECK_FALSE(text.is_truncated()); + + const Text emptyText; + CHECK_THROW(emptyText.back(), etl::string_out_of_bounds); } //************************************************************************* @@ -1399,6 +1415,20 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_value_outofbounds) + { + const size_t INITIAL_SIZE = 5; + const value_t INITIAL_VALUE = STR('A'); + + Text text; + text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); + + Text text2; + + CHECK_THROW(text.insert(text2.cbegin(), INITIAL_VALUE), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { @@ -1474,6 +1504,21 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_n_value_outofbounds) + { + const size_t INITIAL_SIZE = 5UL; + const size_t INSERT_SIZE = 3UL; + const value_t INITIAL_VALUE = STR('A'); + + Text text; + text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); + + Text text2; + + CHECK_THROW(text.insert(text2.cbegin(), INSERT_SIZE, INITIAL_VALUE), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { @@ -1573,6 +1618,30 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_range_outofbounds) + { + const size_t INITIAL_SIZE = 5UL; + + Text text; + text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); + + Text text2; + + CHECK_THROW(text.insert(text2.cbegin(), insert_text.cbegin(), insert_text.cend()), etl::string_out_of_bounds); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_range_swapped_iterators) + { + const size_t INITIAL_SIZE = 5UL; + + Text text; + text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); + + CHECK_THROW(text.insert(text.cbegin(), insert_text.cend(), insert_text.cbegin()), etl::string_iterator); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range_excess) { @@ -3338,6 +3407,23 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_outofbounds) + { + Text text(initial_text.c_str()); + + CHECK_THROW(text.erase(text.end()), etl::string_out_of_bounds); + CHECK_THROW(text.erase(text.cend()), etl::string_out_of_bounds); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_position_outofbounds) + { + Text text(initial_text.c_str()); + + CHECK_THROW(text.erase(text.size() + 1), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { @@ -3355,6 +3441,15 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_range_outofbounds) + { + Text text(initial_text.c_str()); + Text text2(initial_text.c_str()); + + CHECK_THROW(text.erase(text2.begin(), text2.end()), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_clear) { @@ -5115,7 +5210,7 @@ namespace // Test with actual string type. Text text(STR("ABCDEFHIJKL")); size_t hash = etl::hash()(text); - size_t compare_hash = etl::private_hash::generic_hash(reinterpret_cast(&text[0]), reinterpret_cast(&text[text.size()])); + size_t compare_hash = etl::private_hash::generic_hash(reinterpret_cast(text.data()), reinterpret_cast(text.data_end())); CHECK_EQUAL(compare_hash, hash); // Test with interface string type. @@ -5377,7 +5472,7 @@ namespace for (size_t i = text.size(); i < text.max_size(); ++i) { - CHECK_EQUAL(0, text[i]); + CHECK_EQUAL(0, text.data()[i]); } } @@ -5395,7 +5490,7 @@ namespace for (size_t i = text.size(); i < text.max_size(); ++i) { - CHECK_EQUAL(0, text[i]); + CHECK_EQUAL(0, text.data()[i]); } } diff --git a/test/test_string_u16_external_buffer.cpp b/test/test_string_u16_external_buffer.cpp index a7a3279c..41e60750 100644 --- a/test/test_string_u16_external_buffer.cpp +++ b/test/test_string_u16_external_buffer.cpp @@ -836,8 +836,8 @@ namespace TextBuffer buffer2{0}; const Text constText(initial_text.c_str(), buffer2.data(), buffer2.size()); - CHECK_EQUAL(&text[initial_text.size()], text.end()); - CHECK_EQUAL(&constText[initial_text.size()], constText.end()); + CHECK_EQUAL(text.begin() + text.size(), text.end()); + CHECK_EQUAL(constText.begin() + constText.size(), constText.end()); } //************************************************************************* @@ -1138,6 +1138,8 @@ namespace } CHECK_FALSE(text.is_truncated()); + + CHECK_THROW(text[text.size()], etl::string_out_of_bounds); } //************************************************************************* @@ -1154,6 +1156,8 @@ namespace } CHECK_FALSE(text.is_truncated()); + + CHECK_THROW(text[text.size()], etl::string_out_of_bounds); } //************************************************************************* @@ -1202,6 +1206,10 @@ namespace CHECK(text.front() == compare_text.front()); CHECK_FALSE(text.is_truncated()); + + TextBuffer buffer2{0}; + Text emptyText(buffer2.data(), buffer2.size()); + CHECK_THROW(emptyText.front(), etl::string_out_of_bounds); } //************************************************************************* @@ -1214,6 +1222,10 @@ namespace CHECK(text.front() == compare_text.front()); CHECK_FALSE(text.is_truncated()); + + TextBuffer buffer2{0}; + const Text emptyText(buffer2.data(), buffer2.size()); + CHECK_THROW(emptyText.front(), etl::string_out_of_bounds); } //************************************************************************* @@ -1226,6 +1238,10 @@ namespace CHECK(text.back() == compare_text.back()); CHECK_FALSE(text.is_truncated()); + + TextBuffer buffer2{0}; + Text emptyText(buffer2.data(), buffer2.size()); + CHECK_THROW(emptyText.back(), etl::string_out_of_bounds); } //************************************************************************* @@ -1238,6 +1254,10 @@ namespace CHECK(text.back() == compare_text.back()); CHECK_FALSE(text.is_truncated()); + + TextBuffer buffer2{0}; + const Text emptyText(buffer2.data(), buffer2.size()); + CHECK_THROW(emptyText.back(), etl::string_out_of_bounds); } //************************************************************************* @@ -1632,6 +1652,22 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_value_outofbounds) + { + const size_t INITIAL_SIZE = 5; + const value_t INITIAL_VALUE = STR('A'); + + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); + + TextBuffer buffer2{0}; + Text text2(buffer2.data(), buffer2.size()); + + CHECK_THROW(text.insert(text2.cbegin(), INITIAL_VALUE), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { @@ -1709,6 +1745,23 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_n_value_outofbounds) + { + const size_t INITIAL_SIZE = 5UL; + const size_t INSERT_SIZE = 3UL; + const value_t INITIAL_VALUE = STR('A'); + + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); + + TextBuffer buffer2{0}; + Text text2(buffer2.data(), buffer2.size()); + + CHECK_THROW(text.insert(text2.cbegin(), INSERT_SIZE, INITIAL_VALUE), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { @@ -1810,6 +1863,33 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_range_outofbounds) + { + const size_t INITIAL_SIZE = 5UL; + + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); + + TextBuffer buffer2{0}; + Text text2(buffer2.data(), buffer2.size()); + + CHECK_THROW(text.insert(text2.cbegin(), insert_text.cbegin(), insert_text.cend()), etl::string_out_of_bounds); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_range_swapped_iterators) + { + const size_t INITIAL_SIZE = 5UL; + + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); + + CHECK_THROW(text.insert(text.cbegin(), insert_text.cend(), insert_text.cbegin()), etl::string_iterator); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range_excess) { @@ -3542,6 +3622,25 @@ namespace CHECK_FALSE(text.is_truncated()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_outofbounds) + { + TextBuffer buffer{0}; + Text text(initial_text.c_str(), buffer.data(), buffer.size()); + + CHECK_THROW(text.erase(text.end()), etl::string_out_of_bounds); + CHECK_THROW(text.erase(text.cend()), etl::string_out_of_bounds); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_position_outofbounds) + { + TextBuffer buffer{0}; + Text text(initial_text.c_str(), buffer.data(), buffer.size()); + + CHECK_THROW(text.erase(text.size() + 1), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { @@ -3559,6 +3658,17 @@ namespace CHECK_FALSE(text.is_truncated()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_range_outofbounds) + { + TextBuffer buffer{0}; + Text text(initial_text.c_str(), buffer.data(), buffer.size()); + TextBuffer buffer2{0}; + Text text2(initial_text.c_str(), buffer2.data(), buffer2.size()); + + CHECK_THROW(text.erase(text2.begin(), text2.end()), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_clear) { @@ -5402,7 +5512,7 @@ namespace TextBuffer buffer{0}; Text text(STR("ABCDEFHIJKL"), buffer.data(), buffer.size()); size_t hash = etl::hash()(text); - size_t compare_hash = etl::private_hash::generic_hash(reinterpret_cast(&text[0]), reinterpret_cast(&text[text.size()])); + size_t compare_hash = etl::private_hash::generic_hash(reinterpret_cast(text.data()), reinterpret_cast(text.data_end())); CHECK_EQUAL(compare_hash, hash); // Test with interface string type. @@ -5689,7 +5799,7 @@ namespace for (size_t i = text.size(); i < text.max_size(); ++i) { - CHECK_EQUAL(0, text[i]); + CHECK_EQUAL(0, text.data()[i]); } } @@ -5709,7 +5819,7 @@ namespace for (size_t i = text.size(); i < text.max_size(); ++i) { - CHECK_EQUAL(0, text[i]); + CHECK_EQUAL(0, text.data()[i]); } } diff --git a/test/test_string_u32.cpp b/test/test_string_u32.cpp index 7b6be11d..5201371e 100644 --- a/test/test_string_u32.cpp +++ b/test/test_string_u32.cpp @@ -658,8 +658,8 @@ namespace Text text(initial_text.c_str()); const Text constText(initial_text.c_str()); - CHECK_EQUAL(&text[initial_text.size()], text.end()); - CHECK_EQUAL(&constText[initial_text.size()], constText.end()); + CHECK_EQUAL(text.begin() + text.size(), text.end()); + CHECK_EQUAL(constText.begin() + constText.size(), constText.end()); } //************************************************************************* @@ -954,6 +954,8 @@ namespace } CHECK_FALSE(text.is_truncated()); + + CHECK_THROW(text[text.size()], etl::string_out_of_bounds); } //************************************************************************* @@ -968,6 +970,8 @@ namespace } CHECK_FALSE(text.is_truncated()); + + CHECK_THROW(text[text.size()], etl::string_out_of_bounds); } //************************************************************************* @@ -1008,6 +1012,9 @@ namespace CHECK(text.front() == compare_text.front()); CHECK_FALSE(text.is_truncated()); + + Text emptyText; + CHECK_THROW(emptyText.front(), etl::string_out_of_bounds); } //************************************************************************* @@ -1018,6 +1025,9 @@ namespace CHECK(text.front() == compare_text.front()); CHECK_FALSE(text.is_truncated()); + + const Text emptyText; + CHECK_THROW(emptyText.front(), etl::string_out_of_bounds); } //************************************************************************* @@ -1028,6 +1038,9 @@ namespace CHECK(text.back() == compare_text.back()); CHECK_FALSE(text.is_truncated()); + + Text emptyText; + CHECK_THROW(emptyText.back(), etl::string_out_of_bounds); } //************************************************************************* @@ -1038,6 +1051,9 @@ namespace CHECK(text.back() == compare_text.back()); CHECK_FALSE(text.is_truncated()); + + const Text emptyText; + CHECK_THROW(emptyText.back(), etl::string_out_of_bounds); } //************************************************************************* @@ -1399,6 +1415,20 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_value_outofbounds) + { + const size_t INITIAL_SIZE = 5; + const value_t INITIAL_VALUE = STR('A'); + + Text text; + text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); + + Text text2; + + CHECK_THROW(text.insert(text2.cbegin(), INITIAL_VALUE), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { @@ -1474,6 +1504,21 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_n_value_outofbounds) + { + const size_t INITIAL_SIZE = 5UL; + const size_t INSERT_SIZE = 3UL; + const value_t INITIAL_VALUE = STR('A'); + + Text text; + text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); + + Text text2; + + CHECK_THROW(text.insert(text2.cbegin(), INSERT_SIZE, INITIAL_VALUE), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { @@ -1573,6 +1618,30 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_range_outofbounds) + { + const size_t INITIAL_SIZE = 5UL; + + Text text; + text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); + + Text text2; + + CHECK_THROW(text.insert(text2.cbegin(), insert_text.cbegin(), insert_text.cend()), etl::string_out_of_bounds); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_range_swapped_iterators) + { + const size_t INITIAL_SIZE = 5UL; + + Text text; + text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); + + CHECK_THROW(text.insert(text.cbegin(), insert_text.cend(), insert_text.cbegin()), etl::string_iterator); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range_excess) { @@ -3338,6 +3407,23 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_outofbounds) + { + Text text(initial_text.c_str()); + + CHECK_THROW(text.erase(text.end()), etl::string_out_of_bounds); + CHECK_THROW(text.erase(text.cend()), etl::string_out_of_bounds); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_position_outofbounds) + { + Text text(initial_text.c_str()); + + CHECK_THROW(text.erase(text.size() + 1), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { @@ -3355,6 +3441,15 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_range_outofbounds) + { + Text text(initial_text.c_str()); + Text text2(initial_text.c_str()); + + CHECK_THROW(text.erase(text2.begin(), text2.end()), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_clear) { @@ -5115,7 +5210,7 @@ namespace // Test with actual string type. Text text(STR("ABCDEFHIJKL")); size_t hash = etl::hash()(text); - size_t compare_hash = etl::private_hash::generic_hash(reinterpret_cast(&text[0]), reinterpret_cast(&text[text.size()])); + size_t compare_hash = etl::private_hash::generic_hash(reinterpret_cast(text.data()), reinterpret_cast(text.data_end())); CHECK_EQUAL(compare_hash, hash); // Test with interface string type. @@ -5377,7 +5472,7 @@ namespace for (size_t i = text.size(); i < text.max_size(); ++i) { - CHECK_EQUAL(0, text[i]); + CHECK_EQUAL(0, text.data()[i]); } } @@ -5395,7 +5490,7 @@ namespace for (size_t i = text.size(); i < text.max_size(); ++i) { - CHECK_EQUAL(0, text[i]); + CHECK_EQUAL(0, text.data()[i]); } } diff --git a/test/test_string_u32_external_buffer.cpp b/test/test_string_u32_external_buffer.cpp index fb7d2104..f02a460d 100644 --- a/test/test_string_u32_external_buffer.cpp +++ b/test/test_string_u32_external_buffer.cpp @@ -836,8 +836,8 @@ namespace TextBuffer buffer2{0}; const Text constText(initial_text.c_str(), buffer2.data(), buffer2.size()); - CHECK_EQUAL(&text[initial_text.size()], text.end()); - CHECK_EQUAL(&constText[initial_text.size()], constText.end()); + CHECK_EQUAL(text.begin() + text.size(), text.end()); + CHECK_EQUAL(constText.begin() + constText.size(), constText.end()); } //************************************************************************* @@ -1138,6 +1138,8 @@ namespace } CHECK_FALSE(text.is_truncated()); + + CHECK_THROW(text[text.size()], etl::string_out_of_bounds); } //************************************************************************* @@ -1154,6 +1156,8 @@ namespace } CHECK_FALSE(text.is_truncated()); + + CHECK_THROW(text[text.size()], etl::string_out_of_bounds); } //************************************************************************* @@ -1202,6 +1206,10 @@ namespace CHECK(text.front() == compare_text.front()); CHECK_FALSE(text.is_truncated()); + + TextBuffer buffer2{0}; + Text emptyText(buffer2.data(), buffer2.size()); + CHECK_THROW(emptyText.front(), etl::string_out_of_bounds); } //************************************************************************* @@ -1214,6 +1222,10 @@ namespace CHECK(text.front() == compare_text.front()); CHECK_FALSE(text.is_truncated()); + + TextBuffer buffer2{0}; + const Text emptyText(buffer2.data(), buffer2.size()); + CHECK_THROW(emptyText.front(), etl::string_out_of_bounds); } //************************************************************************* @@ -1226,6 +1238,10 @@ namespace CHECK(text.back() == compare_text.back()); CHECK_FALSE(text.is_truncated()); + + TextBuffer buffer2{0}; + Text emptyText(buffer2.data(), buffer2.size()); + CHECK_THROW(emptyText.back(), etl::string_out_of_bounds); } //************************************************************************* @@ -1238,6 +1254,10 @@ namespace CHECK(text.back() == compare_text.back()); CHECK_FALSE(text.is_truncated()); + + TextBuffer buffer2{0}; + const Text emptyText(buffer2.data(), buffer2.size()); + CHECK_THROW(emptyText.back(), etl::string_out_of_bounds); } //************************************************************************* @@ -1632,6 +1652,22 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_value_outofbounds) + { + const size_t INITIAL_SIZE = 5; + const value_t INITIAL_VALUE = STR('A'); + + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); + + TextBuffer buffer2{0}; + Text text2(buffer2.data(), buffer2.size()); + + CHECK_THROW(text.insert(text2.cbegin(), INITIAL_VALUE), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { @@ -1709,6 +1745,23 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_n_value_outofbounds) + { + const size_t INITIAL_SIZE = 5UL; + const size_t INSERT_SIZE = 3UL; + const value_t INITIAL_VALUE = STR('A'); + + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); + + TextBuffer buffer2{0}; + Text text2(buffer2.data(), buffer2.size()); + + CHECK_THROW(text.insert(text2.cbegin(), INSERT_SIZE, INITIAL_VALUE), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { @@ -1810,6 +1863,33 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_range_outofbounds) + { + const size_t INITIAL_SIZE = 5UL; + + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); + + TextBuffer buffer2{0}; + Text text2(buffer2.data(), buffer2.size()); + + CHECK_THROW(text.insert(text2.cbegin(), insert_text.cbegin(), insert_text.cend()), etl::string_out_of_bounds); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_range_swapped_iterators) + { + const size_t INITIAL_SIZE = 5UL; + + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); + + CHECK_THROW(text.insert(text.cbegin(), insert_text.cend(), insert_text.cbegin()), etl::string_iterator); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range_excess) { @@ -3542,6 +3622,25 @@ namespace CHECK_FALSE(text.is_truncated()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_outofbounds) + { + TextBuffer buffer{0}; + Text text(initial_text.c_str(), buffer.data(), buffer.size()); + + CHECK_THROW(text.erase(text.end()), etl::string_out_of_bounds); + CHECK_THROW(text.erase(text.cend()), etl::string_out_of_bounds); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_position_outofbounds) + { + TextBuffer buffer{0}; + Text text(initial_text.c_str(), buffer.data(), buffer.size()); + + CHECK_THROW(text.erase(text.size() + 1), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { @@ -3559,6 +3658,17 @@ namespace CHECK_FALSE(text.is_truncated()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_range_outofbounds) + { + TextBuffer buffer{0}; + Text text(initial_text.c_str(), buffer.data(), buffer.size()); + TextBuffer buffer2{0}; + Text text2(initial_text.c_str(), buffer2.data(), buffer2.size()); + + CHECK_THROW(text.erase(text2.begin(), text2.end()), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_clear) { @@ -5402,7 +5512,7 @@ namespace TextBuffer buffer{0}; Text text(STR("ABCDEFHIJKL"), buffer.data(), buffer.size()); size_t hash = etl::hash()(text); - size_t compare_hash = etl::private_hash::generic_hash(reinterpret_cast(&text[0]), reinterpret_cast(&text[text.size()])); + size_t compare_hash = etl::private_hash::generic_hash(reinterpret_cast(text.data()), reinterpret_cast(text.data_end())); CHECK_EQUAL(compare_hash, hash); // Test with interface string type. @@ -5689,7 +5799,7 @@ namespace for (size_t i = text.size(); i < text.max_size(); ++i) { - CHECK_EQUAL(0, text[i]); + CHECK_EQUAL(0, text.data()[i]); } } @@ -5709,7 +5819,7 @@ namespace for (size_t i = text.size(); i < text.max_size(); ++i) { - CHECK_EQUAL(0, text[i]); + CHECK_EQUAL(0, text.data()[i]); } } diff --git a/test/test_string_u8.cpp b/test/test_string_u8.cpp index b01a67f2..65eeb767 100644 --- a/test/test_string_u8.cpp +++ b/test/test_string_u8.cpp @@ -631,8 +631,8 @@ namespace Text text(initial_text.c_str()); const Text constText(initial_text.c_str()); - CHECK_EQUAL(&text[initial_text.size()], text.end()); - CHECK_EQUAL(&constText[initial_text.size()], constText.end()); + CHECK_EQUAL(text.begin() + text.size(), text.end()); + CHECK_EQUAL(constText.begin() + constText.size(), constText.end()); } //************************************************************************* @@ -927,6 +927,8 @@ namespace } CHECK_FALSE(text.is_truncated()); + + CHECK_THROW(text[text.size()], etl::string_out_of_bounds); } //************************************************************************* @@ -941,6 +943,8 @@ namespace } CHECK_FALSE(text.is_truncated()); + + CHECK_THROW(text[text.size()], etl::string_out_of_bounds); } //************************************************************************* @@ -981,6 +985,9 @@ namespace CHECK(text.front() == compare_text.front()); CHECK_FALSE(text.is_truncated()); + + Text emptyText; + CHECK_THROW(emptyText.front(), etl::string_out_of_bounds); } //************************************************************************* @@ -991,6 +998,9 @@ namespace CHECK(text.front() == compare_text.front()); CHECK_FALSE(text.is_truncated()); + + const Text emptyText; + CHECK_THROW(emptyText.front(), etl::string_out_of_bounds); } //************************************************************************* @@ -1001,6 +1011,9 @@ namespace CHECK(text.back() == compare_text.back()); CHECK_FALSE(text.is_truncated()); + + Text emptyText; + CHECK_THROW(emptyText.back(), etl::string_out_of_bounds); } //************************************************************************* @@ -1011,6 +1024,9 @@ namespace CHECK(text.back() == compare_text.back()); CHECK_FALSE(text.is_truncated()); + + const Text emptyText; + CHECK_THROW(emptyText.back(), etl::string_out_of_bounds); } //************************************************************************* @@ -1344,6 +1360,20 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_value_outofbounds) + { + const size_t INITIAL_SIZE = 5; + const value_t INITIAL_VALUE = STR('A'); + + Text text; + text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); + + Text text2; + + CHECK_THROW(text.insert(text2.cbegin(), INITIAL_VALUE), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { @@ -1419,6 +1449,21 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_n_value_outofbounds) + { + const size_t INITIAL_SIZE = 5UL; + const size_t INSERT_SIZE = 3UL; + const value_t INITIAL_VALUE = STR('A'); + + Text text; + text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); + + Text text2; + + CHECK_THROW(text.insert(text2.cbegin(), INSERT_SIZE, INITIAL_VALUE), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { @@ -1512,12 +1557,36 @@ namespace compare_text.insert(compare_text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); CHECK_FALSE(text.is_truncated()); -# + bool is_equal = Equal(compare_text, text); CHECK(is_equal); } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_range_outofbounds) + { + const size_t INITIAL_SIZE = 5UL; + + Text text; + text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); + + Text text2; + + CHECK_THROW(text.insert(text2.cbegin(), insert_text.cbegin(), insert_text.cend()), etl::string_out_of_bounds); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_range_swapped_iterators) + { + const size_t INITIAL_SIZE = 5UL; + + Text text; + text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); + + CHECK_THROW(text.insert(text.cbegin(), insert_text.cend(), insert_text.cbegin()), etl::string_iterator); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range_excess) { @@ -3283,6 +3352,23 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_outofbounds) + { + Text text(initial_text.c_str()); + + CHECK_THROW(text.erase(text.end()), etl::string_out_of_bounds); + CHECK_THROW(text.erase(text.cend()), etl::string_out_of_bounds); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_position_outofbounds) + { + Text text(initial_text.c_str()); + + CHECK_THROW(text.erase(text.size() + 1), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { @@ -3300,6 +3386,15 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_range_outofbounds) + { + Text text(initial_text.c_str()); + Text text2(initial_text.c_str()); + + CHECK_THROW(text.erase(text2.begin(), text2.end()), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_clear) { @@ -5060,7 +5155,7 @@ namespace // Test with actual string type. Text text(STR("ABCDEFHIJKL")); size_t hash = etl::hash()(text); - size_t compare_hash = etl::private_hash::generic_hash(reinterpret_cast(&text[0]), reinterpret_cast(&text[text.size()])); + size_t compare_hash = etl::private_hash::generic_hash(reinterpret_cast(text.data()), reinterpret_cast(text.data_end())); CHECK_EQUAL(compare_hash, hash); // Test with interface string type. @@ -5322,7 +5417,7 @@ namespace for (size_t i = text.size(); i < text.max_size(); ++i) { - CHECK_EQUAL(0, text[i]); + CHECK_EQUAL(0, text.data()[i]); } } @@ -5340,7 +5435,7 @@ namespace for (size_t i = text.size(); i < text.max_size(); ++i) { - CHECK_EQUAL(0, text[i]); + CHECK_EQUAL(0, text.data()[i]); } } diff --git a/test/test_string_u8_external_buffer.cpp b/test/test_string_u8_external_buffer.cpp index fe79d570..6f4befa5 100644 --- a/test/test_string_u8_external_buffer.cpp +++ b/test/test_string_u8_external_buffer.cpp @@ -784,8 +784,8 @@ namespace TextBuffer buffer2{0}; const Text constText(initial_text.c_str(), buffer2.data(), buffer2.size()); - CHECK_EQUAL(&text[initial_text.size()], text.end()); - CHECK_EQUAL(&constText[initial_text.size()], constText.end()); + CHECK_EQUAL(text.begin() + text.size(), text.end()); + CHECK_EQUAL(constText.begin() + constText.size(), constText.end()); } //************************************************************************* @@ -1086,6 +1086,8 @@ namespace } CHECK_FALSE(text.is_truncated()); + + CHECK_THROW(text[text.size()], etl::string_out_of_bounds); } //************************************************************************* @@ -1102,6 +1104,8 @@ namespace } CHECK_FALSE(text.is_truncated()); + + CHECK_THROW(text[text.size()], etl::string_out_of_bounds); } //************************************************************************* @@ -1150,6 +1154,10 @@ namespace CHECK(text.front() == compare_text.front()); CHECK_FALSE(text.is_truncated()); + + TextBuffer buffer2{0}; + Text emptyText(buffer2.data(), buffer2.size()); + CHECK_THROW(emptyText.front(), etl::string_out_of_bounds); } //************************************************************************* @@ -1162,6 +1170,10 @@ namespace CHECK(text.front() == compare_text.front()); CHECK_FALSE(text.is_truncated()); + + TextBuffer buffer2{0}; + const Text emptyText(buffer2.data(), buffer2.size()); + CHECK_THROW(emptyText.front(), etl::string_out_of_bounds); } //************************************************************************* @@ -1174,6 +1186,10 @@ namespace CHECK(text.back() == compare_text.back()); CHECK_FALSE(text.is_truncated()); + + TextBuffer buffer2{0}; + Text emptyText(buffer2.data(), buffer2.size()); + CHECK_THROW(emptyText.back(), etl::string_out_of_bounds); } //************************************************************************* @@ -1186,6 +1202,10 @@ namespace CHECK(text.back() == compare_text.back()); CHECK_FALSE(text.is_truncated()); + + TextBuffer buffer2{0}; + const Text emptyText(buffer2.data(), buffer2.size()); + CHECK_THROW(emptyText.back(), etl::string_out_of_bounds); } //************************************************************************* @@ -1548,6 +1568,22 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_value_outofbounds) + { + const size_t INITIAL_SIZE = 5; + const value_t INITIAL_VALUE = STR('A'); + + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); + + TextBuffer buffer2{0}; + Text text2(buffer2.data(), buffer2.size()); + + CHECK_THROW(text.insert(text2.cbegin(), INITIAL_VALUE), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { @@ -1625,6 +1661,23 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_n_value_outofbounds) + { + const size_t INITIAL_SIZE = 5UL; + const size_t INSERT_SIZE = 3UL; + const value_t INITIAL_VALUE = STR('A'); + + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); + + TextBuffer buffer2{0}; + Text text2(buffer2.data(), buffer2.size()); + + CHECK_THROW(text.insert(text2.cbegin(), INSERT_SIZE, INITIAL_VALUE), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { @@ -1726,6 +1779,33 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_range_outofbounds) + { + const size_t INITIAL_SIZE = 5UL; + + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); + + TextBuffer buffer2{0}; + Text text2(buffer2.data(), buffer2.size()); + + CHECK_THROW(text.insert(text2.cbegin(), insert_text.cbegin(), insert_text.cend()), etl::string_out_of_bounds); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_range_swapped_iterators) + { + const size_t INITIAL_SIZE = 5UL; + + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); + + CHECK_THROW(text.insert(text.cbegin(), insert_text.cend(), insert_text.cbegin()), etl::string_iterator); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range_excess) { @@ -3458,6 +3538,25 @@ namespace CHECK_FALSE(text.is_truncated()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_outofbounds) + { + TextBuffer buffer{0}; + Text text(initial_text.c_str(), buffer.data(), buffer.size()); + + CHECK_THROW(text.erase(text.end()), etl::string_out_of_bounds); + CHECK_THROW(text.erase(text.cend()), etl::string_out_of_bounds); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_position_outofbounds) + { + TextBuffer buffer{0}; + Text text(initial_text.c_str(), buffer.data(), buffer.size()); + + CHECK_THROW(text.erase(text.size() + 1), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { @@ -3475,6 +3574,17 @@ namespace CHECK_FALSE(text.is_truncated()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_range_outofbounds) + { + TextBuffer buffer{0}; + Text text(initial_text.c_str(), buffer.data(), buffer.size()); + TextBuffer buffer2{0}; + Text text2(initial_text.c_str(), buffer2.data(), buffer2.size()); + + CHECK_THROW(text.erase(text2.begin(), text2.end()), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_clear) { @@ -5321,7 +5431,7 @@ namespace TextBuffer buffer{0}; Text text(STR("ABCDEFHIJKL"), buffer.data(), buffer.size()); size_t hash = etl::hash()(text); - size_t compare_hash = etl::private_hash::generic_hash(reinterpret_cast(&text[0]), reinterpret_cast(&text[text.size()])); + size_t compare_hash = etl::private_hash::generic_hash(reinterpret_cast(text.data()), reinterpret_cast(text.data_end())); CHECK_EQUAL(compare_hash, hash); // Test with interface string type. @@ -5608,7 +5718,7 @@ namespace for (size_t i = text.size(); i < text.max_size(); ++i) { - CHECK_EQUAL(0, text[i]); + CHECK_EQUAL(0, text.data()[i]); } } @@ -5628,7 +5738,7 @@ namespace for (size_t i = text.size(); i < text.max_size(); ++i) { - CHECK_EQUAL(0, text[i]); + CHECK_EQUAL(0, text.data()[i]); } } diff --git a/test/test_string_wchar_t.cpp b/test/test_string_wchar_t.cpp index b269b70c..4ac88729 100644 --- a/test/test_string_wchar_t.cpp +++ b/test/test_string_wchar_t.cpp @@ -659,8 +659,8 @@ namespace Text text(initial_text.c_str()); const Text constText(initial_text.c_str()); - CHECK_EQUAL(&text[initial_text.size()], text.end()); - CHECK_EQUAL(&constText[initial_text.size()], constText.end()); + CHECK_EQUAL(text.begin() + text.size(), text.end()); + CHECK_EQUAL(constText.begin() + constText.size(), constText.end()); } //************************************************************************* @@ -955,6 +955,8 @@ namespace } CHECK_FALSE(text.is_truncated()); + + CHECK_THROW(text[text.size()], etl::string_out_of_bounds); } //************************************************************************* @@ -969,6 +971,8 @@ namespace } CHECK_FALSE(text.is_truncated()); + + CHECK_THROW(text[text.size()], etl::string_out_of_bounds); } //************************************************************************* @@ -1009,6 +1013,9 @@ namespace CHECK(text.front() == compare_text.front()); CHECK_FALSE(text.is_truncated()); + + Text emptyText; + CHECK_THROW(emptyText.front(), etl::string_out_of_bounds); } //************************************************************************* @@ -1019,6 +1026,9 @@ namespace CHECK(text.front() == compare_text.front()); CHECK_FALSE(text.is_truncated()); + + const Text emptyText; + CHECK_THROW(emptyText.front(), etl::string_out_of_bounds); } //************************************************************************* @@ -1029,6 +1039,9 @@ namespace CHECK(text.back() == compare_text.back()); CHECK_FALSE(text.is_truncated()); + + Text emptyText; + CHECK_THROW(emptyText.back(), etl::string_out_of_bounds); } //************************************************************************* @@ -1039,6 +1052,9 @@ namespace CHECK(text.back() == compare_text.back()); CHECK_FALSE(text.is_truncated()); + + const Text emptyText; + CHECK_THROW(emptyText.back(), etl::string_out_of_bounds); } //************************************************************************* @@ -1400,6 +1416,20 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_value_outofbounds) + { + const size_t INITIAL_SIZE = 5; + const value_t INITIAL_VALUE = STR('A'); + + Text text; + text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); + + Text text2; + + CHECK_THROW(text.insert(text2.cbegin(), INITIAL_VALUE), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { @@ -1475,6 +1505,21 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_n_value_outofbounds) + { + const size_t INITIAL_SIZE = 5UL; + const size_t INSERT_SIZE = 3UL; + const value_t INITIAL_VALUE = STR('A'); + + Text text; + text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); + + Text text2; + + CHECK_THROW(text.insert(text2.cbegin(), INSERT_SIZE, INITIAL_VALUE), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { @@ -1568,12 +1613,36 @@ namespace compare_text.insert(compare_text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); CHECK_FALSE(text.is_truncated()); -# + bool is_equal = Equal(compare_text, text); CHECK(is_equal); } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_range_outofbounds) + { + const size_t INITIAL_SIZE = 5UL; + + Text text; + text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); + + Text text2; + + CHECK_THROW(text.insert(text2.cbegin(), insert_text.cbegin(), insert_text.cend()), etl::string_out_of_bounds); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_range_swapped_iterators) + { + const size_t INITIAL_SIZE = 5UL; + + Text text; + text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); + + CHECK_THROW(text.insert(text.cbegin(), insert_text.cend(), insert_text.cbegin()), etl::string_iterator); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range_excess) { @@ -3339,6 +3408,23 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_outofbounds) + { + Text text(initial_text.c_str()); + + CHECK_THROW(text.erase(text.end()), etl::string_out_of_bounds); + CHECK_THROW(text.erase(text.cend()), etl::string_out_of_bounds); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_position_outofbounds) + { + Text text(initial_text.c_str()); + + CHECK_THROW(text.erase(text.size() + 1), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { @@ -3356,6 +3442,15 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_range_outofbounds) + { + Text text(initial_text.c_str()); + Text text2(initial_text.c_str()); + + CHECK_THROW(text.erase(text2.begin(), text2.end()), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_clear) { @@ -5116,7 +5211,7 @@ namespace // Test with actual string type. Text text(STR("ABCDEFHIJKL")); size_t hash = etl::hash()(text); - size_t compare_hash = etl::private_hash::generic_hash(reinterpret_cast(&text[0]), reinterpret_cast(&text[text.size()])); + size_t compare_hash = etl::private_hash::generic_hash(reinterpret_cast(text.data()), reinterpret_cast(text.data_end())); CHECK_EQUAL(compare_hash, hash); // Test with interface string type. @@ -5378,7 +5473,7 @@ namespace for (size_t i = text.size(); i < text.max_size(); ++i) { - CHECK_EQUAL(0, text[i]); + CHECK_EQUAL(0, text.data()[i]); } } @@ -5396,7 +5491,7 @@ namespace for (size_t i = text.size(); i < text.max_size(); ++i) { - CHECK_EQUAL(0, text[i]); + CHECK_EQUAL(0, text.data()[i]); } } diff --git a/test/test_string_wchar_t_external_buffer.cpp b/test/test_string_wchar_t_external_buffer.cpp index 2926beb2..6b1b5e08 100644 --- a/test/test_string_wchar_t_external_buffer.cpp +++ b/test/test_string_wchar_t_external_buffer.cpp @@ -839,8 +839,8 @@ namespace TextBuffer buffer2{0}; const Text constText(initial_text.c_str(), buffer2.data(), buffer2.size()); - CHECK_EQUAL(&text[initial_text.size()], text.end()); - CHECK_EQUAL(&constText[initial_text.size()], constText.end()); + CHECK_EQUAL(text.begin() + text.size(), text.end()); + CHECK_EQUAL(constText.begin() + constText.size(), constText.end()); } //************************************************************************* @@ -1141,6 +1141,8 @@ namespace } CHECK_FALSE(text.is_truncated()); + + CHECK_THROW(text[text.size()], etl::string_out_of_bounds); } //************************************************************************* @@ -1157,6 +1159,8 @@ namespace } CHECK_FALSE(text.is_truncated()); + + CHECK_THROW(text[text.size()], etl::string_out_of_bounds); } //************************************************************************* @@ -1205,6 +1209,10 @@ namespace CHECK(text.front() == compare_text.front()); CHECK_FALSE(text.is_truncated()); + + TextBuffer buffer2{0}; + Text emptyText(buffer2.data(), buffer2.size()); + CHECK_THROW(emptyText.front(), etl::string_out_of_bounds); } //************************************************************************* @@ -1217,6 +1225,10 @@ namespace CHECK(text.front() == compare_text.front()); CHECK_FALSE(text.is_truncated()); + + TextBuffer buffer2{0}; + const Text emptyText(buffer2.data(), buffer2.size()); + CHECK_THROW(emptyText.front(), etl::string_out_of_bounds); } //************************************************************************* @@ -1229,6 +1241,10 @@ namespace CHECK(text.back() == compare_text.back()); CHECK_FALSE(text.is_truncated()); + + TextBuffer buffer2{0}; + Text emptyText(buffer2.data(), buffer2.size()); + CHECK_THROW(emptyText.back(), etl::string_out_of_bounds); } //************************************************************************* @@ -1241,6 +1257,10 @@ namespace CHECK(text.back() == compare_text.back()); CHECK_FALSE(text.is_truncated()); + + TextBuffer buffer2{0}; + const Text emptyText(buffer2.data(), buffer2.size()); + CHECK_THROW(emptyText.back(), etl::string_out_of_bounds); } //************************************************************************* @@ -1635,6 +1655,22 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_value_outofbounds) + { + const size_t INITIAL_SIZE = 5; + const value_t INITIAL_VALUE = STR('A'); + + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); + + TextBuffer buffer2{0}; + Text text2(buffer2.data(), buffer2.size()); + + CHECK_THROW(text.insert(text2.cbegin(), INITIAL_VALUE), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { @@ -1712,6 +1748,23 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_n_value_outofbounds) + { + const size_t INITIAL_SIZE = 5UL; + const size_t INSERT_SIZE = 3UL; + const value_t INITIAL_VALUE = STR('A'); + + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); + + TextBuffer buffer2{0}; + Text text2(buffer2.data(), buffer2.size()); + + CHECK_THROW(text.insert(text2.cbegin(), INSERT_SIZE, INITIAL_VALUE), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { @@ -1813,6 +1866,33 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_range_outofbounds) + { + const size_t INITIAL_SIZE = 5UL; + + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); + + TextBuffer buffer2{0}; + Text text2(buffer2.data(), buffer2.size()); + + CHECK_THROW(text.insert(text2.cbegin(), insert_text.cbegin(), insert_text.cend()), etl::string_out_of_bounds); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_range_swapped_iterators) + { + const size_t INITIAL_SIZE = 5UL; + + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); + + CHECK_THROW(text.insert(text.cbegin(), insert_text.cend(), insert_text.cbegin()), etl::string_iterator); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range_excess) { @@ -3545,6 +3625,25 @@ namespace CHECK_FALSE(text.is_truncated()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_outofbounds) + { + TextBuffer buffer{0}; + Text text(initial_text.c_str(), buffer.data(), buffer.size()); + + CHECK_THROW(text.erase(text.end()), etl::string_out_of_bounds); + CHECK_THROW(text.erase(text.cend()), etl::string_out_of_bounds); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_position_outofbounds) + { + TextBuffer buffer{0}; + Text text(initial_text.c_str(), buffer.data(), buffer.size()); + + CHECK_THROW(text.erase(text.size() + 1), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { @@ -3562,6 +3661,17 @@ namespace CHECK_FALSE(text.is_truncated()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_range_outofbounds) + { + TextBuffer buffer{0}; + Text text(initial_text.c_str(), buffer.data(), buffer.size()); + TextBuffer buffer2{0}; + Text text2(initial_text.c_str(), buffer2.data(), buffer2.size()); + + CHECK_THROW(text.erase(text2.begin(), text2.end()), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_clear) { @@ -5405,7 +5515,7 @@ namespace TextBuffer buffer{0}; Text text(STR("ABCDEFHIJKL"), buffer.data(), buffer.size()); size_t hash = etl::hash()(text); - size_t compare_hash = etl::private_hash::generic_hash(reinterpret_cast(&text[0]), reinterpret_cast(&text[text.size()])); + size_t compare_hash = etl::private_hash::generic_hash(reinterpret_cast(text.data()), reinterpret_cast(text.data_end())); CHECK_EQUAL(compare_hash, hash); // Test with interface string type. @@ -5692,7 +5802,7 @@ namespace for (size_t i = text.size(); i < text.max_size(); ++i) { - CHECK_EQUAL(0, text[i]); + CHECK_EQUAL(0, text.data()[i]); } } @@ -5712,7 +5822,7 @@ namespace for (size_t i = text.size(); i < text.max_size(); ++i) { - CHECK_EQUAL(0, text[i]); + CHECK_EQUAL(0, text.data()[i]); } }