From 3f5de324c551757bf052b73a4bf6a0d648cc9d76 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 13 Mar 2019 12:43:32 +0000 Subject: [PATCH 1/6] Partial unit test updates --- include/etl/basic_string.h | 8 +++++++ test/test_string_char.cpp | 49 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/include/etl/basic_string.h b/include/etl/basic_string.h index 1aa9818ad..4d91c25b2 100644 --- a/include/etl/basic_string.h +++ b/include/etl/basic_string.h @@ -393,6 +393,8 @@ namespace etl //********************************************************************* void resize(size_t new_size, T value) { + is_truncated = (new_size > CAPACITY); + new_size = std::min(new_size, CAPACITY); // Size up? @@ -560,6 +562,8 @@ namespace etl //********************************************************************* void assign(const_pointer other, size_t length_) { + is_truncated = (length_ > CAPACITY); + length_ = std::min(length_, CAPACITY); initialise(); @@ -593,6 +597,8 @@ namespace etl } p_buffer[current_size] = 0; + + is_truncated = (first != last); } //********************************************************************* @@ -605,6 +611,8 @@ namespace etl { initialise(); + is_truncated = (n > CAPACITY); + n = std::min(n, CAPACITY); std::fill_n(begin(), n, value); diff --git a/test/test_string_char.cpp b/test/test_string_char.cpp index 4022f5eca..eff59282b 100644 --- a/test/test_string_char.cpp +++ b/test/test_string_char.cpp @@ -102,6 +102,7 @@ namespace CHECK_EQUAL(text.capacity(), SIZE); CHECK_EQUAL(text.max_size(), SIZE); CHECK(text.begin() == text.end()); + CHECK(!text.truncated()); } //************************************************************************* @@ -113,6 +114,7 @@ namespace CHECK(text.cbegin() == text.cend()); CHECK(text.rbegin() == text.rend()); CHECK(text.crbegin() == text.crend()); + CHECK(!text.truncated()); } //************************************************************************* @@ -130,6 +132,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -138,6 +141,7 @@ namespace Text text(SIZE + 1, STR('A')); CHECK_EQUAL(SIZE, text.size()); + CHECK(text.truncated()); } //************************************************************************* @@ -151,6 +155,21 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_excess) + { + Compare_Text compare_text(initial_text.c_str()); + + Text text(longer_text.c_str()); + + CHECK(!text.empty()); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -164,6 +183,21 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size_excess) + { + Compare_Text compare_text(SIZE, STR('A')); + + Text text(SIZE + 1, STR('A')); + + CHECK(!text.empty()); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -177,6 +211,21 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_size_char_excess) + { + Compare_Text compare_text(initial_text.c_str(), initial_text.size()); + + Text text(longer_text.c_str(), longer_text.size()); + + CHECK(!text.empty()); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* From 54330998af1b3d4cb9e80caae3699e5d74a5135d Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 13 Mar 2019 14:25:03 +0000 Subject: [PATCH 2/6] Added truncate clear to Clear() --- include/etl/basic_string.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/etl/basic_string.h b/include/etl/basic_string.h index 4d91c25b2..a30b15f43 100644 --- a/include/etl/basic_string.h +++ b/include/etl/basic_string.h @@ -1927,7 +1927,8 @@ namespace etl void initialise() { current_size = 0; - p_buffer[0] = 0; + p_buffer[0] = 0; + is_truncated = false; } //************************************************************************* From 150fdf7f54455ca14f1a6e231129b7287eb4508b Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 13 Mar 2019 21:24:42 +0000 Subject: [PATCH 3/6] Partial updates --- include/etl/basic_string.h | 8 +++++++- include/etl/cstring.h | 7 ++----- include/etl/u16string.h | 5 +---- include/etl/u32string.h | 5 +---- include/etl/wstring.h | 5 +---- test/test_string_char.cpp | 36 ++++++++++++++++++++++++++++++++++++ 6 files changed, 48 insertions(+), 18 deletions(-) diff --git a/include/etl/basic_string.h b/include/etl/basic_string.h index a30b15f43..f84fe709e 100644 --- a/include/etl/basic_string.h +++ b/include/etl/basic_string.h @@ -612,7 +612,7 @@ namespace etl initialise(); is_truncated = (n > CAPACITY); - + n = std::min(n, CAPACITY); std::fill_n(begin(), n, value); @@ -1002,6 +1002,8 @@ namespace etl std::copy(i_element + 1, end(), i_element); p_buffer[--current_size] = 0; + is_truncated = false; + return i_element; } @@ -1021,6 +1023,8 @@ namespace etl current_size -= n_delete; p_buffer[current_size] = 0; + is_truncated = false; + return first; } @@ -1040,6 +1044,8 @@ namespace etl //********************************************************************* size_t copy(pointer s, size_t len, size_t pos = 0) { + is_truncated = (pos + len > size()); + size_t endpos = std::min(pos + len, size()); for (size_t i = pos; i < endpos; ++i) diff --git a/include/etl/cstring.h b/include/etl/cstring.h index 3dea55922..7e9ae7e21 100644 --- a/include/etl/cstring.h +++ b/include/etl/cstring.h @@ -94,14 +94,11 @@ namespace etl ///\param position The position of the first character. ///\param length The number of characters. Default = npos. //************************************************************************* - string(const etl::string& other, size_t position, size_t length_ = npos) + string(const etl::istring& other, size_t position, size_t length_ = npos) : istring(reinterpret_cast(&buffer), MAX_SIZE) { ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); - // Set the length to the exact amount. - length_ = (length_ > MAX_SIZE_) ? MAX_SIZE_ : length_; - this->assign(other.begin() + position, other.begin() + position + length_); } @@ -186,7 +183,7 @@ namespace etl //************************************************************************* /// Assignment operator. //************************************************************************* - string& operator = (const string& rhs) + string& operator = (const istring& rhs) { if (&rhs != this) { diff --git a/include/etl/u16string.h b/include/etl/u16string.h index ef864d63b..67027206f 100644 --- a/include/etl/u16string.h +++ b/include/etl/u16string.h @@ -95,14 +95,11 @@ namespace etl ///\param position The position of the first character. ///\param length The number of characters. Default = npos. //************************************************************************* - u16string(const etl::u16string& other, size_t position, size_t length_ = npos) + u16string(const etl::iu16string& other, size_t position, size_t length_ = npos) : iu16string(reinterpret_cast(&buffer), MAX_SIZE) { ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); - // Set the length to the exact amount. - length_ = (length_ > MAX_SIZE_) ? MAX_SIZE_ : length_; - this->initialise(); this->assign(other.begin() + position, other.begin() + position + length_); } diff --git a/include/etl/u32string.h b/include/etl/u32string.h index 7684f9aab..3e349e967 100644 --- a/include/etl/u32string.h +++ b/include/etl/u32string.h @@ -95,14 +95,11 @@ namespace etl ///\param position The position of the first character. ///\param length The number of characters. Default = npos. //************************************************************************* - u32string(const etl::u32string& other, size_t position, size_t length_ = npos) + u32string(const etl::iu32string& other, size_t position, size_t length_ = npos) : iu32string(reinterpret_cast(&buffer), MAX_SIZE) { ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); - // Set the length to the exact amount. - length_ = (length_ > MAX_SIZE_) ? MAX_SIZE_ : length_; - this->initialise(); this->assign(other.begin() + position, other.begin() + position + length_); } diff --git a/include/etl/wstring.h b/include/etl/wstring.h index 8272953c2..68e372f01 100644 --- a/include/etl/wstring.h +++ b/include/etl/wstring.h @@ -96,14 +96,11 @@ namespace etl ///\param position The position of the first character. ///\param length The number of characters. Default = npos. //************************************************************************* - wstring(const etl::wstring& other, size_t position, size_t length_ = npos) + wstring(const etl::iwstring& other, size_t position, size_t length_ = npos) : iwstring(reinterpret_cast(&buffer), MAX_SIZE) { ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); - // Set the length to the exact amount. - length_ = (length_ > MAX_SIZE_) ? MAX_SIZE_ : length_; - this->initialise(); this->assign(other.begin() + position, other.begin() + position + length_); } diff --git a/test/test_string_char.cpp b/test/test_string_char.cpp index eff59282b..cb8bc26c3 100644 --- a/test/test_string_char.cpp +++ b/test/test_string_char.cpp @@ -237,6 +237,7 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); + CHECK(!text.truncated()); } //************************************************************************* @@ -250,6 +251,7 @@ namespace CHECK(is_equal); CHECK(text.size() == SIZE); CHECK(!text.empty()); + CHECK(text.truncated()); } //************************************************************************* @@ -258,6 +260,27 @@ namespace Text text(initial_text.c_str()); Text text2(text); CHECK(text2 == text); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_copy_constructor_i) + { + Text text(initial_text.c_str()); + IText& itext = text; + Text text2(itext); + CHECK(text2 == text); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_copy_constructor_excess) + { + Text text(initial_text.c_str()); + TextL textl(longer_text.c_str()); + Text text2(textl); + CHECK(text2 == text); + CHECK(!text.truncated()); } //************************************************************************* @@ -273,6 +296,19 @@ namespace CHECK(is_equal); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_construct_position_length_excess) + { + Compare_Text compare_text(longer_text.c_str()); + Compare_Text compare_text2(compare_text, 2, 11); + + TextL textl(longer_text.c_str()); + Text text2(textl, 2, 12); + + bool is_equal = Equal(compare_text2, text2); + CHECK(is_equal); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list) { From 2f586c2a9141e4d2260d58e2ac15d5ca465913af Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 14 Mar 2019 05:52:43 +0000 Subject: [PATCH 4/6] Partial updates --- test/test_string_char.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/test_string_char.cpp b/test/test_string_char.cpp index cb8bc26c3..e074da1dd 100644 --- a/test/test_string_char.cpp +++ b/test/test_string_char.cpp @@ -260,7 +260,7 @@ namespace Text text(initial_text.c_str()); Text text2(text); CHECK(text2 == text); - CHECK(!text.truncated()); + CHECK(!text2.truncated()); } //************************************************************************* @@ -270,7 +270,7 @@ namespace IText& itext = text; Text text2(itext); CHECK(text2 == text); - CHECK(!text.truncated()); + CHECK(!text2.truncated()); } //************************************************************************* @@ -280,7 +280,7 @@ namespace TextL textl(longer_text.c_str()); Text text2(textl); CHECK(text2 == text); - CHECK(!text.truncated()); + CHECK(text2.truncated()); } //************************************************************************* From 0db5da44f2f9bcb7fd683653f098edb55e8e2774 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 14 Mar 2019 21:13:42 +0000 Subject: [PATCH 5/6] Partial updates --- test/test_string_char.cpp | 218 +++++++++++++++++++++++++++++++------- 1 file changed, 178 insertions(+), 40 deletions(-) diff --git a/test/test_string_char.cpp b/test/test_string_char.cpp index e074da1dd..b51c9492e 100644 --- a/test/test_string_char.cpp +++ b/test/test_string_char.cpp @@ -294,6 +294,7 @@ namespace bool is_equal = Equal(compare_text2, text2); CHECK(is_equal); + CHECK(!text2.truncated()); } //************************************************************************* @@ -307,6 +308,7 @@ namespace bool is_equal = Equal(compare_text2, text2); CHECK(is_equal); + CHECK(text2.truncated()); } //************************************************************************* @@ -317,6 +319,21 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_construct_initializer_list_excess) + { + Compare_Text compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), + STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; + Text text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), + STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), + STR('T'), STR('h'), STR('e'), STR('r'), STR('e') }; + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -329,6 +346,22 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); + CHECK(!text.truncated()); + CHECK(!other_text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_excess) + { + Text text(longer_text.begin(), longer_text.end()); + Text other_text; + + other_text = text; + + bool is_equal = Equal(text, other_text); + CHECK(is_equal); + CHECK(text.truncated()); + CHECK(!other_text.truncated()); } //************************************************************************* @@ -345,8 +378,27 @@ namespace bool is_equal = Equal(text1, text2); CHECK(is_equal); + CHECK(!text1.truncated()); + CHECK(!text2.truncated()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_iterface_excess) + { + Text text1(longer_text.begin(), longer_text.end()); + Text text2; + + IText& itext1 = text1; + IText& itext2 = text2; + + itext2 = itext1; + + bool is_equal = Equal(text1, text2); + + CHECK(is_equal); + CHECK(text1.truncated()); + CHECK(!text2.truncated()); + } //************************************************************************* TEST_FIXTURE(SetupFixture, test_self_assignment) @@ -359,6 +411,23 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); + CHECK(!text.truncated()); + CHECK(!other_text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_self_assignment_excess) + { + Text text(longer_text.begin(), longer_text.end()); + Text other_text(text); + + other_text = other_text; + + bool is_equal = Equal(text, other_text); + + CHECK(is_equal); + CHECK(text.truncated()); + CHECK(!other_text.truncated()); } //************************************************************************* @@ -392,6 +461,7 @@ namespace text.resize(NEW_SIZE); CHECK_EQUAL(text.size(), NEW_SIZE); + CHECK(!text.truncated()); } //************************************************************************* @@ -408,8 +478,8 @@ namespace compare_text.fill(INITIAL_VALUE); bool is_equal = Equal(compare_text, text); - CHECK(is_equal); + CHECK(!text.truncated()); } @@ -422,6 +492,7 @@ namespace Text text(INITIAL_SIZE, STR('A')); text.resize(NEW_SIZE, STR('A')); CHECK_EQUAL(SIZE, text.size()); + CHECK(text.truncated()); } //************************************************************************* @@ -434,6 +505,7 @@ namespace text.resize(NEW_SIZE); CHECK_EQUAL(text.size(), NEW_SIZE); + CHECK(!text.truncated()); } //************************************************************************* @@ -453,26 +525,66 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_empty) + TEST_FIXTURE(SetupFixture, test_empty_full) { Text text; text.resize(text.max_size(), STR('A')); - CHECK(text.full()); CHECK(!text.empty()); + CHECK(!text.truncated()); } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_full) + TEST_FIXTURE(SetupFixture, test_empty_half) + { + Text text; + text.resize(text.max_size() / 2, STR('A')); + + CHECK(!text.empty()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_empty_empty) { Text text; - CHECK(!text.full()); CHECK(text.empty()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_full_full) + { + Text text; + text.resize(text.max_size(), STR('A')); + + CHECK(text.full()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_full_half) + { + Text text; + text.resize(text.max_size() / 2, STR('A')); + + CHECK(!text.full()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_full_empty) + { + Text text; + + CHECK(!text.full()); + CHECK(!text.truncated()); } //************************************************************************* @@ -485,30 +597,36 @@ namespace { CHECK_EQUAL(text[i], compare_text[i]); } + + CHECK(!text.truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_index_const) { - const Compare_Text compare_text(initial_text.c_str()); - const Text text(initial_text.c_str()); + const Compare_Text compare_text(initial_text.c_str()); + const Text text(initial_text.c_str()); + + for (size_t i = 0; i < text.size(); ++i) + { + CHECK_EQUAL(text[i], compare_text[i]); + } - for (size_t i = 0; i < text.size(); ++i) - { - CHECK_EQUAL(text[i], compare_text[i]); - } + CHECK(!text.truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_at) { - Compare_Text compare_text(initial_text.c_str()); - Text text(initial_text.c_str()); + Compare_Text compare_text(initial_text.c_str()); + Text text(initial_text.c_str()); - for (size_t i = 0; i < text.size(); ++i) - { - CHECK_EQUAL(text.at(i), compare_text.at(i)); - } + for (size_t i = 0; i < text.size(); ++i) + { + CHECK_EQUAL(text.at(i), compare_text.at(i)); + } + + CHECK(!text.truncated()); CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } @@ -516,15 +634,17 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at_const) { - const Compare_Text compare_text(initial_text.c_str()); - const Text text(initial_text.c_str()); + const Compare_Text compare_text(initial_text.c_str()); + const Text text(initial_text.c_str()); + + for (size_t i = 0; i < text.size(); ++i) + { + CHECK_EQUAL(text.at(i), compare_text.at(i)); + } - for (size_t i = 0; i < text.size(); ++i) - { - CHECK_EQUAL(text.at(i), compare_text.at(i)); - } + CHECK(!text.truncated()); - CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); + CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } //************************************************************************* @@ -534,6 +654,7 @@ namespace Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); + CHECK(!text.truncated()); } //************************************************************************* @@ -543,6 +664,7 @@ namespace const Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); + CHECK(!text.truncated()); } //************************************************************************* @@ -552,6 +674,7 @@ namespace Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); + CHECK(!text.truncated()); } //************************************************************************* @@ -561,6 +684,7 @@ namespace const Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); + CHECK(!text.truncated()); } //************************************************************************* @@ -575,6 +699,7 @@ namespace compare_text.begin()); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -589,6 +714,7 @@ namespace compare_text.begin()); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -597,20 +723,24 @@ namespace Compare_Text compare_text(initial_text.c_str()); Text text; - - text.assign(compare_text.c_str()); + text.assign(initial_text.c_str()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); + } - compare_text.assign(longer_text.c_str()); - compare_text.resize(std::min(compare_text.size(), SIZE)); - - text.assign(compare_text.c_str()); + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_pointer_excess) + { + Compare_Text compare_text(initial_text.c_str()); - is_equal = Equal(compare_text, text); + Text text; + text.assign(longer_text.c_str()); + bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -623,8 +753,8 @@ namespace text.assign(compare_text.begin(), compare_text.end()); bool is_equal = Equal(compare_text, text); - CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -636,11 +766,9 @@ namespace CHECK_EQUAL(initial_text.size(), text.size()); - bool is_equal = std::equal(text.begin(), - text.end(), - initial_text.begin()); - + bool is_equal = Equal(initial_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -658,8 +786,8 @@ namespace CHECK(text.size() == INITIAL_SIZE); bool is_equal = Equal(compare_text, text); - CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -676,10 +804,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } - - //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back) { @@ -701,13 +828,20 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back_excess) { + Compare_Text compare_text; Text text; + for (size_t i = 0; i < SIZE; ++i) + { + compare_text.push_back(STR('A') + value_t(i)); + } + for (size_t i = 0; i < SIZE; ++i) { text.push_back(STR('A') + value_t(i)); @@ -716,8 +850,12 @@ namespace text.push_back(STR('A') + value_t(SIZE)); + CHECK_EQUAL(etl::strlen(compare_text.data()), etl::strlen(text.data())); + CHECK_EQUAL(compare_text.size(), text.size()); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); CHECK(text.truncated()); - CHECK_EQUAL(SIZE, text.size()); } //************************************************************************* From 92989feda9422afc4800e0677da67dccb652c583 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 17 Mar 2019 17:49:25 +0000 Subject: [PATCH 6/6] Fixed setting of 'truncated' --- include/etl/basic_string.h | 6 +- include/etl/string_view.h | 10 + include/etl/version.h | 2 +- support/Release notes.txt | 4 + test/test_string_char.cpp | 137 +++++++-- test/test_string_u16.cpp | 542 ++++++++++++++++++++++++++-------- test/test_string_u32.cpp | 544 ++++++++++++++++++++++++++-------- test/test_string_view.cpp | 12 + test/test_string_wchar_t.cpp | 545 +++++++++++++++++++++++++++-------- 9 files changed, 1420 insertions(+), 382 deletions(-) diff --git a/include/etl/basic_string.h b/include/etl/basic_string.h index f84fe709e..043e3553c 100644 --- a/include/etl/basic_string.h +++ b/include/etl/basic_string.h @@ -794,8 +794,9 @@ namespace etl const size_t start = std::distance(cbegin(), position); // No effect. - if (start == CAPACITY) + if (start >= CAPACITY) { + is_truncated = true; return; } @@ -854,8 +855,9 @@ namespace etl const size_t n = std::distance(first, last); // No effect. - if (start == CAPACITY) + if (start >= CAPACITY) { + is_truncated = true; return; } diff --git a/include/etl/string_view.h b/include/etl/string_view.h index 319ca8016..b8ada8763 100644 --- a/include/etl/string_view.h +++ b/include/etl/string_view.h @@ -39,6 +39,7 @@ SOFTWARE. #include "char_traits.h" #include "integral_limits.h" #include "hash.h" +#include "basic_string.h" #include "algorithm.h" @@ -124,6 +125,15 @@ namespace etl { } + //************************************************************************* + /// Construct from string. + //************************************************************************* + ETL_CONSTEXPR basic_string_view(const etl::ibasic_string& str) + : mbegin(str.begin()), + mend(str.end()) + { + } + //************************************************************************* /// Construct from T*. //************************************************************************* diff --git a/include/etl/version.h b/include/etl/version.h index 397d714f2..1198ebb6b 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -39,7 +39,7 @@ SOFTWARE. #define ETL_VERSION_MAJOR 14 #define ETL_VERSION_MINOR 14 -#define ETL_VERSION_PATCH 0 +#define ETL_VERSION_PATCH 1 #define ETL_VERSION ETL_STRINGIFY(ETL_VERSION_MAJOR) ETL_STRINGIFY(ETL_VERSION_MINOR) ETL_STRINGIFY(ETL_VERSION_PATCH) #define ETL_VERSION_W ETL_WIDE_STRING(ETL_CONCAT(ETL_CONCAT(ETL_VERSION_MAJOR, ETL_VERSION_MINOR), ETL_VERSION_PATCH)) diff --git a/support/Release notes.txt b/support/Release notes.txt index b038a690e..e3eb2130d 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,7 @@ +=============================================================================== +14.14.1 +Fixed bug where 'truncated' was not always set correctly for strings. + =============================================================================== 14.14.0 Fixed string push_back() bug where ther internal terminator was not updated. diff --git a/test/test_string_char.cpp b/test/test_string_char.cpp index b51c9492e..ceffa8bb4 100644 --- a/test/test_string_char.cpp +++ b/test/test_string_char.cpp @@ -3,7 +3,7 @@ The MIT License(MIT) Embedded Template Library. https://github.com/ETLCPP/etl -http://www.etlcpp.com +https://www.etlcpp.com Copyright(c) 2016 jwellbelove @@ -1020,7 +1020,7 @@ namespace text.assign(initial_text.begin(), initial_text.end()); text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - CHECK(!text.truncated()); + CHECK(text.truncated()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -1114,6 +1114,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); } } @@ -1132,6 +1133,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); } } @@ -1150,6 +1152,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } } @@ -1166,6 +1169,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); compare_text.assign(short_text.begin(), short_text.end()); text.assign(short_text.begin(), short_text.end()); @@ -1178,6 +1182,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); compare_text.assign(short_text.begin(), short_text.end()); text.assign(short_text.begin(), short_text.end()); @@ -1188,6 +1193,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -1203,6 +1209,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1215,6 +1222,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1230,6 +1238,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Partial string. compare_text.assign(short_text.c_str()); @@ -1242,6 +1251,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1254,6 +1264,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1269,6 +1280,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1280,6 +1292,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1295,6 +1308,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1306,6 +1320,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1321,6 +1336,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1333,6 +1349,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1348,6 +1365,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Non-overflow short text. compare_text.assign(short_text.c_str()); @@ -1359,6 +1377,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -1370,6 +1389,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -1381,17 +1401,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 2, Compare_Text(STR("Replace"))); + compare_text.replace(2, 7, Compare_Text(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, Text(STR("Replace"))); + text.replace(2, 7, Text(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -1403,6 +1425,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Overflow, npos. compare_text.assign(initial_text.c_str()); @@ -1414,6 +1437,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1429,6 +1453,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -1440,17 +1465,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, Compare_Text(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, Compare_Text(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, Text(STR("Replace"))); + text.replace(text.begin() + 2, text.begin() + 9, Text(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -1462,6 +1489,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1477,6 +1505,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -1488,6 +1517,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -1499,6 +1529,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -1510,17 +1541,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, Compare_Text(STR("Replace")), 1, 5); + compare_text.replace(2, 7, Compare_Text(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, Text(STR("Replace")), 1, 5); + text.replace(2, 7, Text(STR("Replace")), 1, 5); is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); @@ -1532,6 +1565,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -1543,6 +1577,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Overflow, npos. compare_text.assign(initial_text.c_str()); @@ -1554,6 +1589,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1569,6 +1605,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -1580,6 +1617,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -1591,6 +1629,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -1602,17 +1641,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, Compare_Text(STR("Replace")).c_str()); + compare_text.replace(2, 7, Compare_Text(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, Text(STR("Replace")).c_str()); + text.replace(2, 7, Text(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); @@ -1624,6 +1665,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -1635,6 +1677,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Overflow, npos. compare_text.assign(initial_text.c_str()); @@ -1646,6 +1689,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1661,6 +1705,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -1672,17 +1717,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, Compare_Text(STR("Replace")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, Compare_Text(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, Text(STR("Replace")).c_str()); + text.replace(text.begin() + 2, text.begin() + 9, Text(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -1694,6 +1741,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1709,6 +1757,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -1720,6 +1769,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -1731,6 +1781,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -1742,17 +1793,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, Compare_Text(STR("Replace")).c_str(), 5); + compare_text.replace(2, 7, Compare_Text(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, Text(STR("Replace")).c_str(), 5); + text.replace(2, 7, Text(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); @@ -1764,6 +1817,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -1775,6 +1829,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Overflow, npos. compare_text.assign(initial_text.c_str()); @@ -1786,6 +1841,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1801,6 +1857,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -1812,17 +1869,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, Compare_Text(STR("Replace")).c_str(), 5); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, Compare_Text(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, Text(STR("Replace")).c_str(), 5); + text.replace(text.begin() + 2, text.begin() + 9, Text(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -1834,6 +1893,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1849,6 +1909,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -1860,6 +1921,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -1871,6 +1933,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -1882,17 +1945,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, 7, STR('A')); + compare_text.replace(2, 7, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, 7, STR('A')); + text.replace(2, 7, 7, STR('A')); is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); @@ -1904,6 +1969,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -1915,6 +1981,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Overflow, npos. compare_text.assign(initial_text.c_str()); @@ -1926,6 +1993,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1941,6 +2009,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -1952,17 +2021,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 7, STR('A')); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, 7, STR('A')); + text.replace(text.begin() + 2, text.begin() + 9, 7, STR('A')); is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -1974,6 +2045,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1992,6 +2064,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2003,17 +2076,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, replace.begin() + 1, replace.begin() + 5); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 7, replace.begin() + 1, replace.begin() + 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, replace_long.begin() + 1, replace_long.begin() + 5); + text.replace(text.begin() + 2, text.begin() + 7, replace_long.begin() + 1, replace_long.begin() + 5); is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2025,6 +2100,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -2038,6 +2114,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -2052,6 +2129,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -2061,6 +2139,7 @@ namespace text.clear(); CHECK_EQUAL(text.size(), size_t(0)); + CHECK(!text.truncated()); } //************************************************************************* @@ -2069,8 +2148,9 @@ namespace Compare_Text compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - bool is_equal = Equal(compare_text, text); + bool is_equal = std::equal(text.begin(), text.end(), compare_text.begin()); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -2079,8 +2159,9 @@ namespace Compare_Text compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - bool is_equal = Equal(compare_text, text); + bool is_equal = std::equal(text.cbegin(), text.cend(), compare_text.cbegin()); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -2089,8 +2170,9 @@ namespace Compare_Text compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - bool is_equal = Equal(compare_text, text); + bool is_equal = std::equal(text.rbegin(), text.rend(), compare_text.rbegin()); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -2099,8 +2181,9 @@ namespace Compare_Text compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - bool is_equal = Equal(compare_text, text); + bool is_equal = std::equal(text.crbegin(), text.crend(), compare_text.crbegin()); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -2293,6 +2376,7 @@ namespace buffer2[length2] = STR('\0'); CHECK_EQUAL(length1, length2); + CHECK(!text.truncated()); bool is_equal = std::equal(buffer1, buffer1 + length1, @@ -3289,6 +3373,7 @@ namespace CHECK_EQUAL(compare_hash, hash); } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_memcpy_repair) { Text text; diff --git a/test/test_string_u16.cpp b/test/test_string_u16.cpp index 46a6e921e..8fa7769b9 100644 --- a/test/test_string_u16.cpp +++ b/test/test_string_u16.cpp @@ -3,7 +3,7 @@ The MIT License(MIT) Embedded Template Library. https://github.com/ETLCPP/etl -http://www.etlcpp.com +https://www.etlcpp.com Copyright(c) 2016 jwellbelove @@ -101,6 +101,7 @@ namespace CHECK_EQUAL(text.capacity(), SIZE); CHECK_EQUAL(text.max_size(), SIZE); CHECK(text.begin() == text.end()); + CHECK(!text.truncated()); } //************************************************************************* @@ -108,10 +109,11 @@ namespace { Text text; - CHECK(text.begin() == text.end()); - CHECK(text.cbegin() == text.cend()); - CHECK(text.rbegin() == text.rend()); + CHECK(text.begin() == text.end()); + CHECK(text.cbegin() == text.cend()); + CHECK(text.rbegin() == text.rend()); CHECK(text.crbegin() == text.crend()); + CHECK(!text.truncated()); } //************************************************************************* @@ -129,6 +131,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -137,6 +140,7 @@ namespace Text text(SIZE + 1, STR('A')); CHECK_EQUAL(SIZE, text.size()); + CHECK(text.truncated()); } //************************************************************************* @@ -150,6 +154,21 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_excess) + { + Compare_Text compare_text(initial_text.c_str()); + + Text text(longer_text.c_str()); + + CHECK(!text.empty()); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -163,6 +182,21 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size_excess) + { + Compare_Text compare_text(SIZE, STR('A')); + + Text text(SIZE + 1, STR('A')); + + CHECK(!text.empty()); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -176,6 +210,21 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_size_char_excess) + { + Compare_Text compare_text(initial_text.c_str(), initial_text.size()); + + Text text(longer_text.c_str(), longer_text.size()); + + CHECK(!text.empty()); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -187,6 +236,7 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); + CHECK(!text.truncated()); } //************************************************************************* @@ -200,6 +250,7 @@ namespace CHECK(is_equal); CHECK(text.size() == SIZE); CHECK(!text.empty()); + CHECK(text.truncated()); } //************************************************************************* @@ -208,6 +259,27 @@ namespace Text text(initial_text.c_str()); Text text2(text); CHECK(text2 == text); + CHECK(!text2.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_copy_constructor_i) + { + Text text(initial_text.c_str()); + IText& itext = text; + Text text2(itext); + CHECK(text2 == text); + CHECK(!text2.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_copy_constructor_excess) + { + Text text(initial_text.c_str()); + TextL textl(longer_text.c_str()); + Text text2(textl); + CHECK(text2 == text); + CHECK(text2.truncated()); } //************************************************************************* @@ -221,6 +293,21 @@ namespace bool is_equal = Equal(compare_text2, text2); CHECK(is_equal); + CHECK(!text2.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_construct_position_length_excess) + { + Compare_Text compare_text(longer_text.c_str()); + Compare_Text compare_text2(compare_text, 2, 11); + + TextL textl(longer_text.c_str()); + Text text2(textl, 2, 12); + + bool is_equal = Equal(compare_text2, text2); + CHECK(is_equal); + CHECK(text2.truncated()); } //************************************************************************* @@ -231,6 +318,21 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_construct_initializer_list_excess) + { + Compare_Text compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), + STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; + Text text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), + STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), + STR('T'), STR('h'), STR('e'), STR('r'), STR('e') }; + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -243,6 +345,22 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); + CHECK(!text.truncated()); + CHECK(!other_text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_excess) + { + Text text(longer_text.begin(), longer_text.end()); + Text other_text; + + other_text = text; + + bool is_equal = Equal(text, other_text); + CHECK(is_equal); + CHECK(text.truncated()); + CHECK(!other_text.truncated()); } //************************************************************************* @@ -259,8 +377,27 @@ namespace bool is_equal = Equal(text1, text2); CHECK(is_equal); + CHECK(!text1.truncated()); + CHECK(!text2.truncated()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_iterface_excess) + { + Text text1(longer_text.begin(), longer_text.end()); + Text text2; + + IText& itext1 = text1; + IText& itext2 = text2; + + itext2 = itext1; + + bool is_equal = Equal(text1, text2); + + CHECK(is_equal); + CHECK(text1.truncated()); + CHECK(!text2.truncated()); + } //************************************************************************* TEST_FIXTURE(SetupFixture, test_self_assignment) @@ -273,6 +410,23 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); + CHECK(!text.truncated()); + CHECK(!other_text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_self_assignment_excess) + { + Text text(longer_text.begin(), longer_text.end()); + Text other_text(text); + + other_text = other_text; + + bool is_equal = Equal(text, other_text); + + CHECK(is_equal); + CHECK(text.truncated()); + CHECK(!other_text.truncated()); } //************************************************************************* @@ -281,7 +435,7 @@ namespace Text text(initial_text.c_str()); const Text constText(initial_text.c_str()); - CHECK_EQUAL(&text[0], text.begin()); + CHECK_EQUAL(&text[0], text.begin()); CHECK_EQUAL(&constText[0], constText.begin()); } @@ -292,7 +446,7 @@ namespace Text text(initial_text.c_str()); const Text constText(initial_text.c_str()); - CHECK_EQUAL(&text[initial_text.size()], text.end()); + CHECK_EQUAL(&text[initial_text.size()], text.end()); CHECK_EQUAL(&constText[initial_text.size()], constText.end()); } @@ -306,6 +460,7 @@ namespace text.resize(NEW_SIZE); CHECK_EQUAL(text.size(), NEW_SIZE); + CHECK(!text.truncated()); } //************************************************************************* @@ -322,8 +477,8 @@ namespace compare_text.fill(INITIAL_VALUE); bool is_equal = Equal(compare_text, text); - CHECK(is_equal); + CHECK(!text.truncated()); } @@ -336,6 +491,7 @@ namespace Text text(INITIAL_SIZE, STR('A')); text.resize(NEW_SIZE, STR('A')); CHECK_EQUAL(SIZE, text.size()); + CHECK(text.truncated()); } //************************************************************************* @@ -348,6 +504,7 @@ namespace text.resize(NEW_SIZE); CHECK_EQUAL(text.size(), NEW_SIZE); + CHECK(!text.truncated()); } //************************************************************************* @@ -367,26 +524,66 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_empty) + TEST_FIXTURE(SetupFixture, test_empty_full) { Text text; text.resize(text.max_size(), STR('A')); - CHECK(text.full()); CHECK(!text.empty()); + CHECK(!text.truncated()); } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_full) + TEST_FIXTURE(SetupFixture, test_empty_half) + { + Text text; + text.resize(text.max_size() / 2, STR('A')); + + CHECK(!text.empty()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_empty_empty) { Text text; - CHECK(!text.full()); CHECK(text.empty()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_full_full) + { + Text text; + text.resize(text.max_size(), STR('A')); + + CHECK(text.full()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_full_half) + { + Text text; + text.resize(text.max_size() / 2, STR('A')); + + CHECK(!text.full()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_full_empty) + { + Text text; + + CHECK(!text.full()); + CHECK(!text.truncated()); } //************************************************************************* @@ -399,6 +596,8 @@ namespace { CHECK_EQUAL(text[i], compare_text[i]); } + + CHECK(!text.truncated()); } //************************************************************************* @@ -411,6 +610,8 @@ namespace { CHECK_EQUAL(text[i], compare_text[i]); } + + CHECK(!text.truncated()); } //************************************************************************* @@ -424,6 +625,8 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } + CHECK(!text.truncated()); + CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } @@ -438,6 +641,8 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } + CHECK(!text.truncated()); + CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } @@ -448,6 +653,7 @@ namespace Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); + CHECK(!text.truncated()); } //************************************************************************* @@ -457,6 +663,7 @@ namespace const Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); + CHECK(!text.truncated()); } //************************************************************************* @@ -466,6 +673,7 @@ namespace Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); + CHECK(!text.truncated()); } //************************************************************************* @@ -475,6 +683,7 @@ namespace const Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); + CHECK(!text.truncated()); } //************************************************************************* @@ -489,6 +698,7 @@ namespace compare_text.begin()); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -503,6 +713,7 @@ namespace compare_text.begin()); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -511,20 +722,24 @@ namespace Compare_Text compare_text(initial_text.c_str()); Text text; - - text.assign(compare_text.c_str()); + text.assign(initial_text.c_str()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); + } - compare_text.assign(longer_text.c_str()); - compare_text.resize(std::min(compare_text.size(), SIZE)); - - text.assign(compare_text.c_str()); + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_pointer_excess) + { + Compare_Text compare_text(initial_text.c_str()); - is_equal = Equal(compare_text, text); + Text text; + text.assign(longer_text.c_str()); + bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -537,8 +752,8 @@ namespace text.assign(compare_text.begin(), compare_text.end()); bool is_equal = Equal(compare_text, text); - CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -550,11 +765,9 @@ namespace CHECK_EQUAL(initial_text.size(), text.size()); - bool is_equal = std::equal(text.begin(), - text.end(), - initial_text.begin()); - + bool is_equal = Equal(initial_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -572,8 +785,8 @@ namespace CHECK(text.size() == INITIAL_SIZE); bool is_equal = Equal(compare_text, text); - CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -590,10 +803,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } - - //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back) { @@ -615,13 +827,20 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back_excess) { + Compare_Text compare_text; Text text; + for (size_t i = 0; i < SIZE; ++i) + { + compare_text.push_back(STR('A') + value_t(i)); + } + for (size_t i = 0; i < SIZE; ++i) { text.push_back(STR('A') + value_t(i)); @@ -630,8 +849,12 @@ namespace text.push_back(STR('A') + value_t(SIZE)); + CHECK_EQUAL(etl::strlen(compare_text.data()), etl::strlen(text.data())); + CHECK_EQUAL(compare_text.size(), text.size()); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); CHECK(text.truncated()); - CHECK_EQUAL(SIZE, text.size()); } //************************************************************************* @@ -657,7 +880,7 @@ namespace TEST_FIXTURE(SetupFixture, test_insert_position_value) { const size_t INITIAL_SIZE = 5; - const value_t INITIAL_VALUE = STR('A'); + const value_t INITIAL_VALUE = STR('A'); for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) { @@ -720,15 +943,15 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value) { - const size_t INITIAL_SIZE = 5; - const size_t INSERT_SIZE = 3; - const value_t INITIAL_VALUE = STR('A'); + Compare_Text compare_text; + Text text; + + const size_t INITIAL_SIZE = 5; + const size_t INSERT_SIZE = 3; + const value_t INITIAL_VALUE = STR('A'); for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) { - Compare_Text compare_text; - Text text; - text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); compare_text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); text.insert(text.begin() + offset, INSERT_SIZE, INITIAL_VALUE); @@ -748,7 +971,7 @@ namespace Text text; const size_t INSERT_SIZE = 4; - const value_t INSERT_VALUE = STR('A'); + const value_t INSERT_VALUE = STR('A'); size_t offset = 0; compare_text.assign(initial_text.begin(), initial_text.end()); @@ -796,7 +1019,7 @@ namespace text.assign(initial_text.begin(), initial_text.end()); text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - CHECK(!text.truncated()); + CHECK(text.truncated()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -828,7 +1051,7 @@ namespace TEST_FIXTURE(SetupFixture, test_insert_position_range_excess) { const size_t INITIAL_SIZE = 5; - const value_t INITIAL_VALUE = STR('A'); + const value_t INITIAL_VALUE = STR('A'); Compare_Text compare_text; Text text; @@ -890,6 +1113,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); } } @@ -908,6 +1132,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); } } @@ -926,6 +1151,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } } @@ -942,6 +1168,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); compare_text.assign(short_text.begin(), short_text.end()); text.assign(short_text.begin(), short_text.end()); @@ -954,6 +1181,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); compare_text.assign(short_text.begin(), short_text.end()); text.assign(short_text.begin(), short_text.end()); @@ -964,6 +1192,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -979,6 +1208,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -991,6 +1221,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1002,10 +1233,11 @@ namespace // Whole string. compare_text.append(insert_text, 0, std::u16string::npos); - text.append(append, 0, etl::iu16string::npos); + text.append(append, 0, Text::npos); bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Partial string. compare_text.assign(short_text.c_str()); @@ -1018,6 +1250,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1030,6 +1263,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1045,6 +1279,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1056,6 +1291,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1071,6 +1307,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1082,6 +1319,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1097,6 +1335,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1109,6 +1348,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1124,6 +1364,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Non-overflow short text. compare_text.assign(short_text.c_str()); @@ -1135,6 +1376,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -1146,6 +1388,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -1157,17 +1400,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 2, Compare_Text(STR("Replace"))); + compare_text.replace(2, 7, Compare_Text(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, Text(STR("Replace"))); + text.replace(2, 7, Text(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -1179,6 +1424,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Overflow, npos. compare_text.assign(initial_text.c_str()); @@ -1190,6 +1436,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1205,6 +1452,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -1216,17 +1464,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, Compare_Text(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, Compare_Text(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, Text(STR("Replace"))); + text.replace(text.begin() + 2, text.begin() + 9, Text(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -1238,6 +1488,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1253,6 +1504,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -1264,6 +1516,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -1275,6 +1528,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -1286,17 +1540,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, Compare_Text(STR("Replace")), 1, 5); + compare_text.replace(2, 7, Compare_Text(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, Text(STR("Replace")), 1, 5); + text.replace(2, 7, Text(STR("Replace")), 1, 5); is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); @@ -1308,6 +1564,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -1319,6 +1576,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Overflow, npos. compare_text.assign(initial_text.c_str()); @@ -1330,6 +1588,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1345,6 +1604,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -1356,6 +1616,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -1367,6 +1628,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -1378,17 +1640,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, Compare_Text(STR("Replace")).c_str()); + compare_text.replace(2, 7, Compare_Text(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, Text(STR("Replace")).c_str()); + text.replace(2, 7, Text(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); @@ -1400,6 +1664,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -1411,6 +1676,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Overflow, npos. compare_text.assign(initial_text.c_str()); @@ -1422,6 +1688,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1437,6 +1704,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -1448,17 +1716,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, Compare_Text(STR("Replace")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, Compare_Text(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, Text(STR("Replace")).c_str()); + text.replace(text.begin() + 2, text.begin() + 9, Text(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -1470,6 +1740,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1485,6 +1756,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -1496,6 +1768,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -1507,6 +1780,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -1518,17 +1792,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, Compare_Text(STR("Replace")).c_str(), 5); + compare_text.replace(2, 7, Compare_Text(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, Text(STR("Replace")).c_str(), 5); + text.replace(2, 7, Text(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); @@ -1540,6 +1816,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -1551,6 +1828,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Overflow, npos. compare_text.assign(initial_text.c_str()); @@ -1562,6 +1840,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1577,6 +1856,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -1588,17 +1868,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, Compare_Text(STR("Replace")).c_str(), 5); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, Compare_Text(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, Text(STR("Replace")).c_str(), 5); + text.replace(text.begin() + 2, text.begin() + 9, Text(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -1610,6 +1892,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1625,6 +1908,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -1636,6 +1920,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -1647,6 +1932,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -1658,17 +1944,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, 7, STR('A')); + compare_text.replace(2, 7, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, 7, STR('A')); + text.replace(2, 7, 7, STR('A')); is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); @@ -1680,6 +1968,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -1691,6 +1980,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Overflow, npos. compare_text.assign(initial_text.c_str()); @@ -1702,6 +1992,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1717,6 +2008,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -1728,17 +2020,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 7, STR('A')); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, 7, STR('A')); + text.replace(text.begin() + 2, text.begin() + 9, 7, STR('A')); is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -1750,6 +2044,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1768,6 +2063,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -1779,17 +2075,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, replace.begin() + 1, replace.begin() + 5); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 7, replace.begin() + 1, replace.begin() + 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, replace_long.begin() + 1, replace_long.begin() + 5); + text.replace(text.begin() + 2, text.begin() + 7, replace_long.begin() + 1, replace_long.begin() + 5); is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -1801,6 +2099,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1814,6 +2113,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -1828,6 +2128,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -1837,6 +2138,7 @@ namespace text.clear(); CHECK_EQUAL(text.size(), size_t(0)); + CHECK(!text.truncated()); } //************************************************************************* @@ -1845,8 +2147,9 @@ namespace Compare_Text compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - bool is_equal = Equal(compare_text, text); + bool is_equal = std::equal(text.begin(), text.end(), compare_text.begin()); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -1855,8 +2158,9 @@ namespace Compare_Text compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - bool is_equal = Equal(compare_text, text); + bool is_equal = std::equal(text.cbegin(), text.cend(), compare_text.cbegin()); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -1865,8 +2169,9 @@ namespace Compare_Text compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - bool is_equal = Equal(compare_text, text); + bool is_equal = std::equal(text.rbegin(), text.rend(), compare_text.rbegin()); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -1875,8 +2180,9 @@ namespace Compare_Text compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - bool is_equal = Equal(compare_text, text); + bool is_equal = std::equal(text.crbegin(), text.crend(), compare_text.crbegin()); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -1936,16 +2242,16 @@ namespace // String-Pointer Pointer-String CHECK((less < pinitial_text) == (less_text < pinitial_text)); - CHECK((pinitial_text < less) == (pinitial_text < less_text)); + CHECK((pinitial_text < less) == (pinitial_text < less_text)); CHECK((greater < pinitial_text) == (greater_text < pinitial_text)); - CHECK((pinitial_text < greater) == (pinitial_text < greater_text)); + CHECK((pinitial_text < greater) == (pinitial_text < greater_text)); CHECK((shorter < pinitial_text) == (shorter_text < pinitial_text)); - CHECK((pinitial_text < shorter) == (pinitial_text < shorter_text)); + CHECK((pinitial_text < shorter) == (pinitial_text < shorter_text)); CHECK((initial < pinitial_text) == (initial_text < pinitial_text)); - CHECK((pinitial_text < initial) == (pinitial_text < initial_text)); + CHECK((pinitial_text < initial) == (pinitial_text < initial_text)); } //************************************************************************* @@ -1955,8 +2261,8 @@ namespace const Text initial(initial_text.c_str()); // String-String - CHECK((less <= initial) == (less_text <= initial_text)); - CHECK((initial <= less) == (initial_text <= less_text)); + CHECK((less <= initial) == (less_text <= initial_text)); + CHECK((initial <= less) == (initial_text <= less_text)); const Text greater(greater_text.c_str()); CHECK((greater <= initial) == (greater_text <= initial_text)); @@ -1970,17 +2276,17 @@ namespace CHECK((initial <= initial) == (initial_text <= initial_text)); // String-Pointer Pointer-String - CHECK((less <= pinitial_text) == (less_text <= pinitial_text)); - CHECK((pinitial_text <= less) == (pinitial_text <= less_text)); + CHECK((less <= pinitial_text) == (less_text <= pinitial_text)); + CHECK((pinitial_text <= less) == (pinitial_text <= less_text)); - CHECK((greater <= pinitial_text) == (greater_text <= pinitial_text)); - CHECK((pinitial_text <= greater) == (pinitial_text <= greater_text)); + CHECK((greater <= pinitial_text) == (greater_text <= pinitial_text)); + CHECK((pinitial_text <= greater) == (pinitial_text <= greater_text)); - CHECK((shorter <= pinitial_text) == (shorter_text <= pinitial_text)); - CHECK((pinitial_text <= shorter) == (pinitial_text <= shorter_text)); + CHECK((shorter <= pinitial_text) == (shorter_text <= pinitial_text)); + CHECK((pinitial_text <= shorter) == (pinitial_text <= shorter_text)); - CHECK((initial <= pinitial_text) == (initial_text <= pinitial_text)); - CHECK((pinitial_text <= initial) == (pinitial_text <= initial_text)); + CHECK((initial <= pinitial_text) == (initial_text <= pinitial_text)); + CHECK((pinitial_text <= initial) == (pinitial_text <= initial_text)); } //************************************************************************* @@ -2006,16 +2312,16 @@ namespace // String-Pointer Pointer-String CHECK((less > pinitial_text) == (less_text > pinitial_text)); - CHECK((pinitial_text > less) == (pinitial_text > less_text)); + CHECK((pinitial_text > less) == (pinitial_text > less_text)); CHECK((greater > pinitial_text) == (greater_text > pinitial_text)); - CHECK((pinitial_text > greater) == (pinitial_text > greater_text)); + CHECK((pinitial_text > greater) == (pinitial_text > greater_text)); CHECK((shorter > pinitial_text) == (shorter_text > pinitial_text)); - CHECK((pinitial_text > shorter) == (pinitial_text > shorter_text)); + CHECK((pinitial_text > shorter) == (pinitial_text > shorter_text)); CHECK((initial > pinitial_text) == (initial_text > pinitial_text)); - CHECK((pinitial_text > initial) == (pinitial_text > initial_text)); + CHECK((pinitial_text > initial) == (pinitial_text > initial_text)); } //************************************************************************* @@ -2025,8 +2331,8 @@ namespace const Text initial(initial_text.begin(), initial_text.end()); // String-String - CHECK((less >= initial) == (less_text >= initial_text)); - CHECK((initial >= less) == (initial_text >= less_text)); + CHECK((less >= initial) == (less_text >= initial_text)); + CHECK((initial >= less) == (initial_text >= less_text)); const Text greater(greater_text.begin(), greater_text.end()); CHECK((greater >= initial) == (greater_text >= initial_text)); @@ -2040,17 +2346,17 @@ namespace CHECK((initial >= initial) == (initial_text >= initial_text)); // String-Pointer Pointer-String - CHECK((less >= pinitial_text) == (less_text >= pinitial_text)); - CHECK((pinitial_text >= less) == (pinitial_text >= less_text)); + CHECK((less >= pinitial_text) == (less_text >= pinitial_text)); + CHECK((pinitial_text >= less) == (pinitial_text >= less_text)); - CHECK((greater >= pinitial_text) == (greater_text >= pinitial_text)); - CHECK((pinitial_text >= greater) == (pinitial_text >= greater_text)); + CHECK((greater >= pinitial_text) == (greater_text >= pinitial_text)); + CHECK((pinitial_text >= greater) == (pinitial_text >= greater_text)); - CHECK((shorter >= pinitial_text) == (shorter_text >= pinitial_text)); - CHECK((pinitial_text >= shorter) == (pinitial_text >= shorter_text)); + CHECK((shorter >= pinitial_text) == (shorter_text >= pinitial_text)); + CHECK((pinitial_text >= shorter) == (pinitial_text >= shorter_text)); - CHECK((initial >= pinitial_text) == (initial_text >= pinitial_text)); - CHECK((pinitial_text >= initial) == (pinitial_text >= initial_text)); + CHECK((initial >= pinitial_text) == (initial_text >= pinitial_text)); + CHECK((pinitial_text >= initial) == (pinitial_text >= initial_text)); } //************************************************************************* @@ -2065,10 +2371,11 @@ namespace size_t length1 = compare_text.copy(buffer1, 5, 2); buffer1[length1] = STR('\0'); - size_t length2 = compare_text.copy(buffer2, 5, 2); + size_t length2 = text.copy(buffer2, 5, 2); buffer2[length2] = STR('\0'); CHECK_EQUAL(length1, length2); + CHECK(!text.truncated()); bool is_equal = std::equal(buffer1, buffer1 + length1, @@ -2079,7 +2386,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_string) { - const value_t *the_haystack = STR("A haystack with a needle and another needle"); + const value_t* the_haystack = STR("A haystack with a needle and another needle"); std::u16string compare_needle(STR("needle")); etl::u16string<50> needle(STR("needle")); @@ -2099,7 +2406,7 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::iu16string::npos, position2); + CHECK_EQUAL(etl::u16string<50>::npos, position2); etl::u16string<50> pin(STR("pin")); position2 = haystack.find(pin); @@ -2107,9 +2414,9 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_char_pointer) + TEST_FIXTURE(SetupFixture, test_find_pointer) { - const value_t *the_haystack = STR("A haystack with a needle and another needle"); + const value_t* the_haystack = STR("A haystack with a needle and another needle"); const value_t* needle = STR("needle"); @@ -2138,7 +2445,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_char_pointer_n) { - const value_t *the_haystack = STR("A haystack with a needle and another needle"); + const value_t* the_haystack = STR("A haystack with a needle and another needle"); const value_t* needle = STR("needle"); @@ -2274,7 +2581,7 @@ namespace Compare_Text compare_result; Text result; - // Empty string. + // Equal. compare_result = compare_text.substr(compare_text.size()); result = text.substr(text.size()); CHECK(Equal(compare_result, result)); @@ -2625,8 +2932,8 @@ namespace CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(STR('C'), 5); - position2 = text.find_first_of(STR('C'), 5); + position1 = compare_text.find_first_of(STR('C'), compare_text.size()); + position2 = text.find_first_of(STR('C'), text.size()); CHECK_EQUAL(position1, position2); @@ -2652,13 +2959,13 @@ namespace CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(Compare_Text(STR("ZCXE")), 3); - position2 = text.find_last_of(Text(STR("ZCXE")), 3); + position1 = compare_text.find_last_of(Compare_Text(STR("ZCXE")), 5); + position2 = text.find_last_of(Text(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(Compare_Text(STR("ZCXE")), 10); - position2 = text.find_last_of(Text(STR("ZCXE")), 10); + position1 = compare_text.find_last_of(Compare_Text(STR("ZCXE")), compare_text.size()); + position2 = text.find_last_of(Text(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); @@ -2684,8 +2991,8 @@ namespace CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(STR("ZCXE"), 3); - position2 = text.find_last_of(STR("ZCXE"), 3); + position1 = compare_text.find_last_of(STR("ZCXE"), 5); + position2 = text.find_last_of(STR("ZCXE"), 5); CHECK_EQUAL(position1, position2); @@ -2694,8 +3001,8 @@ namespace CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(STR("ZCXE"), 10); - position2 = text.find_last_of(STR("ZCXE"), 10); + position1 = compare_text.find_last_of(STR("ZCXE"), compare_text.size()); + position2 = text.find_last_of(STR("ZCXE"), text.size()); CHECK_EQUAL(position1, position2); @@ -2711,8 +3018,8 @@ namespace Compare_Text compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_of(STR("ZCXE"), 11, 4); - size_t position2 = text.find_last_of(STR("ZCXE"), 11, 4); + size_t position1 = compare_text.find_last_of(STR("AZCXE"), 0, 4); + size_t position2 = text.find_last_of(STR("AZCXE"), 0, 4); CHECK_EQUAL(position1, position2); @@ -2721,8 +3028,8 @@ namespace CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(STR("ZCXE"), 4, 3); - position2 = text.find_last_of(STR("ZCXE"), 4, 3); + position1 = compare_text.find_last_of(STR("ZCXE"), 5, 3); + position2 = text.find_last_of(STR("ZCXE"), 5, 3); CHECK_EQUAL(position1, position2); @@ -2731,8 +3038,8 @@ namespace CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(STR("ZCXE"), 10, 4); - position2 = text.find_last_of(STR("ZCXE"), 10, 4); + position1 = compare_text.find_last_of(STR("ZCXE"), compare_text.size(), 4); + position2 = text.find_last_of(STR("ZCXE"), text.size(), 4); CHECK_EQUAL(position1, position2); @@ -2758,8 +3065,8 @@ namespace CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(STR('F'), 5); - position2 = text.find_last_of(STR('F'), 5); + position1 = compare_text.find_last_of(STR('F'), compare_text.size()); + position2 = text.find_last_of(STR('F'), text.size()); CHECK_EQUAL(position1, position2); @@ -2768,8 +3075,8 @@ namespace CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(STR('C'), 5); - position2 = text.find_last_of(STR('C'), 5); + position1 = compare_text.find_last_of(STR('C'), compare_text.size()); + position2 = text.find_last_of(STR('C'), text.size()); CHECK_EQUAL(position1, position2); @@ -3065,6 +3372,7 @@ namespace CHECK_EQUAL(compare_hash, hash); } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_memcpy_repair) { Text text; diff --git a/test/test_string_u32.cpp b/test/test_string_u32.cpp index 161369acb..7207c0702 100644 --- a/test/test_string_u32.cpp +++ b/test/test_string_u32.cpp @@ -3,7 +3,7 @@ The MIT License(MIT) Embedded Template Library. https://github.com/ETLCPP/etl -http://www.etlcpp.com +https://www.etlcpp.com Copyright(c) 2016 jwellbelove @@ -101,6 +101,7 @@ namespace CHECK_EQUAL(text.capacity(), SIZE); CHECK_EQUAL(text.max_size(), SIZE); CHECK(text.begin() == text.end()); + CHECK(!text.truncated()); } //************************************************************************* @@ -108,10 +109,11 @@ namespace { Text text; - CHECK(text.begin() == text.end()); - CHECK(text.cbegin() == text.cend()); - CHECK(text.rbegin() == text.rend()); + CHECK(text.begin() == text.end()); + CHECK(text.cbegin() == text.cend()); + CHECK(text.rbegin() == text.rend()); CHECK(text.crbegin() == text.crend()); + CHECK(!text.truncated()); } //************************************************************************* @@ -129,6 +131,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -137,6 +140,7 @@ namespace Text text(SIZE + 1, STR('A')); CHECK_EQUAL(SIZE, text.size()); + CHECK(text.truncated()); } //************************************************************************* @@ -150,6 +154,21 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_excess) + { + Compare_Text compare_text(initial_text.c_str()); + + Text text(longer_text.c_str()); + + CHECK(!text.empty()); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -163,6 +182,21 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size_excess) + { + Compare_Text compare_text(SIZE, STR('A')); + + Text text(SIZE + 1, STR('A')); + + CHECK(!text.empty()); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -176,6 +210,21 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_size_char_excess) + { + Compare_Text compare_text(initial_text.c_str(), initial_text.size()); + + Text text(longer_text.c_str(), longer_text.size()); + + CHECK(!text.empty()); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -187,6 +236,7 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); + CHECK(!text.truncated()); } //************************************************************************* @@ -200,6 +250,7 @@ namespace CHECK(is_equal); CHECK(text.size() == SIZE); CHECK(!text.empty()); + CHECK(text.truncated()); } //************************************************************************* @@ -208,6 +259,27 @@ namespace Text text(initial_text.c_str()); Text text2(text); CHECK(text2 == text); + CHECK(!text2.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_copy_constructor_i) + { + Text text(initial_text.c_str()); + IText& itext = text; + Text text2(itext); + CHECK(text2 == text); + CHECK(!text2.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_copy_constructor_excess) + { + Text text(initial_text.c_str()); + TextL textl(longer_text.c_str()); + Text text2(textl); + CHECK(text2 == text); + CHECK(text2.truncated()); } //************************************************************************* @@ -221,6 +293,21 @@ namespace bool is_equal = Equal(compare_text2, text2); CHECK(is_equal); + CHECK(!text2.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_construct_position_length_excess) + { + Compare_Text compare_text(longer_text.c_str()); + Compare_Text compare_text2(compare_text, 2, 11); + + TextL textl(longer_text.c_str()); + Text text2(textl, 2, 12); + + bool is_equal = Equal(compare_text2, text2); + CHECK(is_equal); + CHECK(text2.truncated()); } //************************************************************************* @@ -231,6 +318,21 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_construct_initializer_list_excess) + { + Compare_Text compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), + STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; + Text text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), + STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), + STR('T'), STR('h'), STR('e'), STR('r'), STR('e') }; + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -243,6 +345,22 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); + CHECK(!text.truncated()); + CHECK(!other_text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_excess) + { + Text text(longer_text.begin(), longer_text.end()); + Text other_text; + + other_text = text; + + bool is_equal = Equal(text, other_text); + CHECK(is_equal); + CHECK(text.truncated()); + CHECK(!other_text.truncated()); } //************************************************************************* @@ -259,8 +377,27 @@ namespace bool is_equal = Equal(text1, text2); CHECK(is_equal); + CHECK(!text1.truncated()); + CHECK(!text2.truncated()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_iterface_excess) + { + Text text1(longer_text.begin(), longer_text.end()); + Text text2; + + IText& itext1 = text1; + IText& itext2 = text2; + + itext2 = itext1; + + bool is_equal = Equal(text1, text2); + + CHECK(is_equal); + CHECK(text1.truncated()); + CHECK(!text2.truncated()); + } //************************************************************************* TEST_FIXTURE(SetupFixture, test_self_assignment) @@ -273,6 +410,23 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); + CHECK(!text.truncated()); + CHECK(!other_text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_self_assignment_excess) + { + Text text(longer_text.begin(), longer_text.end()); + Text other_text(text); + + other_text = other_text; + + bool is_equal = Equal(text, other_text); + + CHECK(is_equal); + CHECK(text.truncated()); + CHECK(!other_text.truncated()); } //************************************************************************* @@ -281,7 +435,7 @@ namespace Text text(initial_text.c_str()); const Text constText(initial_text.c_str()); - CHECK_EQUAL(&text[0], text.begin()); + CHECK_EQUAL(&text[0], text.begin()); CHECK_EQUAL(&constText[0], constText.begin()); } @@ -292,7 +446,7 @@ namespace Text text(initial_text.c_str()); const Text constText(initial_text.c_str()); - CHECK_EQUAL(&text[initial_text.size()], text.end()); + CHECK_EQUAL(&text[initial_text.size()], text.end()); CHECK_EQUAL(&constText[initial_text.size()], constText.end()); } @@ -306,6 +460,7 @@ namespace text.resize(NEW_SIZE); CHECK_EQUAL(text.size(), NEW_SIZE); + CHECK(!text.truncated()); } //************************************************************************* @@ -322,8 +477,8 @@ namespace compare_text.fill(INITIAL_VALUE); bool is_equal = Equal(compare_text, text); - CHECK(is_equal); + CHECK(!text.truncated()); } @@ -336,6 +491,7 @@ namespace Text text(INITIAL_SIZE, STR('A')); text.resize(NEW_SIZE, STR('A')); CHECK_EQUAL(SIZE, text.size()); + CHECK(text.truncated()); } //************************************************************************* @@ -348,6 +504,7 @@ namespace text.resize(NEW_SIZE); CHECK_EQUAL(text.size(), NEW_SIZE); + CHECK(!text.truncated()); } //************************************************************************* @@ -367,26 +524,66 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_empty) + TEST_FIXTURE(SetupFixture, test_empty_full) { Text text; text.resize(text.max_size(), STR('A')); - CHECK(text.full()); CHECK(!text.empty()); + CHECK(!text.truncated()); } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_full) + TEST_FIXTURE(SetupFixture, test_empty_half) + { + Text text; + text.resize(text.max_size() / 2, STR('A')); + + CHECK(!text.empty()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_empty_empty) { Text text; - CHECK(!text.full()); CHECK(text.empty()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_full_full) + { + Text text; + text.resize(text.max_size(), STR('A')); + + CHECK(text.full()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_full_half) + { + Text text; + text.resize(text.max_size() / 2, STR('A')); + + CHECK(!text.full()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_full_empty) + { + Text text; + + CHECK(!text.full()); + CHECK(!text.truncated()); } //************************************************************************* @@ -399,6 +596,8 @@ namespace { CHECK_EQUAL(text[i], compare_text[i]); } + + CHECK(!text.truncated()); } //************************************************************************* @@ -411,6 +610,8 @@ namespace { CHECK_EQUAL(text[i], compare_text[i]); } + + CHECK(!text.truncated()); } //************************************************************************* @@ -424,6 +625,8 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } + CHECK(!text.truncated()); + CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } @@ -438,6 +641,8 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } + CHECK(!text.truncated()); + CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } @@ -448,6 +653,7 @@ namespace Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); + CHECK(!text.truncated()); } //************************************************************************* @@ -457,6 +663,7 @@ namespace const Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); + CHECK(!text.truncated()); } //************************************************************************* @@ -466,6 +673,7 @@ namespace Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); + CHECK(!text.truncated()); } //************************************************************************* @@ -475,6 +683,7 @@ namespace const Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); + CHECK(!text.truncated()); } //************************************************************************* @@ -489,6 +698,7 @@ namespace compare_text.begin()); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -503,6 +713,7 @@ namespace compare_text.begin()); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -511,20 +722,24 @@ namespace Compare_Text compare_text(initial_text.c_str()); Text text; - - text.assign(compare_text.c_str()); + text.assign(initial_text.c_str()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); + } - compare_text.assign(longer_text.c_str()); - compare_text.resize(std::min(compare_text.size(), SIZE)); - - text.assign(compare_text.c_str()); + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_pointer_excess) + { + Compare_Text compare_text(initial_text.c_str()); - is_equal = Equal(compare_text, text); + Text text; + text.assign(longer_text.c_str()); + bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -537,8 +752,8 @@ namespace text.assign(compare_text.begin(), compare_text.end()); bool is_equal = Equal(compare_text, text); - CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -550,11 +765,9 @@ namespace CHECK_EQUAL(initial_text.size(), text.size()); - bool is_equal = std::equal(text.begin(), - text.end(), - initial_text.begin()); - + bool is_equal = Equal(initial_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -572,8 +785,8 @@ namespace CHECK(text.size() == INITIAL_SIZE); bool is_equal = Equal(compare_text, text); - CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -590,6 +803,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -613,13 +827,20 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back_excess) { + Compare_Text compare_text; Text text; + for (size_t i = 0; i < SIZE; ++i) + { + compare_text.push_back(STR('A') + value_t(i)); + } + for (size_t i = 0; i < SIZE; ++i) { text.push_back(STR('A') + value_t(i)); @@ -628,8 +849,12 @@ namespace text.push_back(STR('A') + value_t(SIZE)); + CHECK_EQUAL(etl::strlen(compare_text.data()), etl::strlen(text.data())); + CHECK_EQUAL(compare_text.size(), text.size()); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); CHECK(text.truncated()); - CHECK_EQUAL(SIZE, text.size()); } //************************************************************************* @@ -655,7 +880,7 @@ namespace TEST_FIXTURE(SetupFixture, test_insert_position_value) { const size_t INITIAL_SIZE = 5; - const value_t INITIAL_VALUE = STR('A'); + const value_t INITIAL_VALUE = STR('A'); for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) { @@ -718,15 +943,15 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value) { - const size_t INITIAL_SIZE = 5; - const size_t INSERT_SIZE = 3; - const value_t INITIAL_VALUE = STR('A'); + Compare_Text compare_text; + Text text; + + const size_t INITIAL_SIZE = 5; + const size_t INSERT_SIZE = 3; + const value_t INITIAL_VALUE = STR('A'); for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) { - Compare_Text compare_text; - Text text; - text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); compare_text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); text.insert(text.begin() + offset, INSERT_SIZE, INITIAL_VALUE); @@ -746,7 +971,7 @@ namespace Text text; const size_t INSERT_SIZE = 4; - const value_t INSERT_VALUE = STR('A'); + const value_t INSERT_VALUE = STR('A'); size_t offset = 0; compare_text.assign(initial_text.begin(), initial_text.end()); @@ -794,7 +1019,7 @@ namespace text.assign(initial_text.begin(), initial_text.end()); text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - CHECK(!text.truncated()); + CHECK(text.truncated()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -826,7 +1051,7 @@ namespace TEST_FIXTURE(SetupFixture, test_insert_position_range_excess) { const size_t INITIAL_SIZE = 5; - const value_t INITIAL_VALUE = STR('A'); + const value_t INITIAL_VALUE = STR('A'); Compare_Text compare_text; Text text; @@ -888,6 +1113,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); } } @@ -906,6 +1132,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); } } @@ -924,6 +1151,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } } @@ -940,6 +1168,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); compare_text.assign(short_text.begin(), short_text.end()); text.assign(short_text.begin(), short_text.end()); @@ -952,6 +1181,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); compare_text.assign(short_text.begin(), short_text.end()); text.assign(short_text.begin(), short_text.end()); @@ -962,6 +1192,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -977,6 +1208,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -989,6 +1221,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1000,10 +1233,11 @@ namespace // Whole string. compare_text.append(insert_text, 0, std::u32string::npos); - text.append(append, 0, etl::iu32string::npos); + text.append(append, 0, Text::npos); bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Partial string. compare_text.assign(short_text.c_str()); @@ -1016,6 +1250,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1028,6 +1263,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1043,6 +1279,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1054,6 +1291,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1069,6 +1307,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1080,6 +1319,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1095,6 +1335,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1107,6 +1348,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1122,6 +1364,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Non-overflow short text. compare_text.assign(short_text.c_str()); @@ -1133,6 +1376,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -1144,6 +1388,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -1155,17 +1400,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 2, Compare_Text(STR("Replace"))); + compare_text.replace(2, 7, Compare_Text(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, Text(STR("Replace"))); + text.replace(2, 7, Text(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -1177,6 +1424,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Overflow, npos. compare_text.assign(initial_text.c_str()); @@ -1188,6 +1436,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1203,6 +1452,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -1214,17 +1464,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, Compare_Text(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, Compare_Text(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, Text(STR("Replace"))); + text.replace(text.begin() + 2, text.begin() + 9, Text(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -1236,6 +1488,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1251,6 +1504,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -1262,6 +1516,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -1273,6 +1528,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -1284,17 +1540,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, Compare_Text(STR("Replace")), 1, 5); + compare_text.replace(2, 7, Compare_Text(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, Text(STR("Replace")), 1, 5); + text.replace(2, 7, Text(STR("Replace")), 1, 5); is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); @@ -1306,6 +1564,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -1317,6 +1576,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Overflow, npos. compare_text.assign(initial_text.c_str()); @@ -1328,6 +1588,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1343,6 +1604,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -1354,6 +1616,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -1365,6 +1628,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -1376,17 +1640,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, Compare_Text(STR("Replace")).c_str()); + compare_text.replace(2, 7, Compare_Text(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, Text(STR("Replace")).c_str()); + text.replace(2, 7, Text(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); @@ -1398,6 +1664,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -1409,6 +1676,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Overflow, npos. compare_text.assign(initial_text.c_str()); @@ -1420,6 +1688,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1435,6 +1704,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -1446,17 +1716,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, Compare_Text(STR("Replace")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, Compare_Text(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, Text(STR("Replace")).c_str()); + text.replace(text.begin() + 2, text.begin() + 9, Text(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -1468,6 +1740,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1483,6 +1756,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -1494,6 +1768,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -1505,6 +1780,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -1516,17 +1792,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, Compare_Text(STR("Replace")).c_str(), 5); + compare_text.replace(2, 7, Compare_Text(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, Text(STR("Replace")).c_str(), 5); + text.replace(2, 7, Text(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); @@ -1538,6 +1816,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -1549,6 +1828,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Overflow, npos. compare_text.assign(initial_text.c_str()); @@ -1560,6 +1840,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1575,6 +1856,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -1586,17 +1868,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, Compare_Text(STR("Replace")).c_str(), 5); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, Compare_Text(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, Text(STR("Replace")).c_str(), 5); + text.replace(text.begin() + 2, text.begin() + 9, Text(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -1608,6 +1892,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1623,6 +1908,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -1634,6 +1920,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -1645,6 +1932,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -1656,17 +1944,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, 7, STR('A')); + compare_text.replace(2, 7, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, 7, STR('A')); + text.replace(2, 7, 7, STR('A')); is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); @@ -1678,6 +1968,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -1689,6 +1980,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Overflow, npos. compare_text.assign(initial_text.c_str()); @@ -1700,6 +1992,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1715,6 +2008,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -1726,17 +2020,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 7, STR('A')); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, 7, STR('A')); + text.replace(text.begin() + 2, text.begin() + 9, 7, STR('A')); is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -1748,6 +2044,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1766,6 +2063,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -1777,17 +2075,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, replace.begin() + 1, replace.begin() + 5); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 7, replace.begin() + 1, replace.begin() + 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, replace_long.begin() + 1, replace_long.begin() + 5); + text.replace(text.begin() + 2, text.begin() + 7, replace_long.begin() + 1, replace_long.begin() + 5); is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -1799,6 +2099,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1812,6 +2113,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -1826,6 +2128,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -1835,6 +2138,7 @@ namespace text.clear(); CHECK_EQUAL(text.size(), size_t(0)); + CHECK(!text.truncated()); } //************************************************************************* @@ -1843,8 +2147,9 @@ namespace Compare_Text compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - bool is_equal = Equal(compare_text, text); + bool is_equal = std::equal(text.begin(), text.end(), compare_text.begin()); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -1853,8 +2158,9 @@ namespace Compare_Text compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - bool is_equal = Equal(compare_text, text); + bool is_equal = std::equal(text.cbegin(), text.cend(), compare_text.cbegin()); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -1863,8 +2169,9 @@ namespace Compare_Text compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - bool is_equal = Equal(compare_text, text); + bool is_equal = std::equal(text.rbegin(), text.rend(), compare_text.rbegin()); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -1873,8 +2180,9 @@ namespace Compare_Text compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - bool is_equal = Equal(compare_text, text); + bool is_equal = std::equal(text.crbegin(), text.crend(), compare_text.crbegin()); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -1934,16 +2242,16 @@ namespace // String-Pointer Pointer-String CHECK((less < pinitial_text) == (less_text < pinitial_text)); - CHECK((pinitial_text < less) == (pinitial_text < less_text)); + CHECK((pinitial_text < less) == (pinitial_text < less_text)); CHECK((greater < pinitial_text) == (greater_text < pinitial_text)); - CHECK((pinitial_text < greater) == (pinitial_text < greater_text)); + CHECK((pinitial_text < greater) == (pinitial_text < greater_text)); CHECK((shorter < pinitial_text) == (shorter_text < pinitial_text)); - CHECK((pinitial_text < shorter) == (pinitial_text < shorter_text)); + CHECK((pinitial_text < shorter) == (pinitial_text < shorter_text)); CHECK((initial < pinitial_text) == (initial_text < pinitial_text)); - CHECK((pinitial_text < initial) == (pinitial_text < initial_text)); + CHECK((pinitial_text < initial) == (pinitial_text < initial_text)); } //************************************************************************* @@ -1953,8 +2261,8 @@ namespace const Text initial(initial_text.c_str()); // String-String - CHECK((less <= initial) == (less_text <= initial_text)); - CHECK((initial <= less) == (initial_text <= less_text)); + CHECK((less <= initial) == (less_text <= initial_text)); + CHECK((initial <= less) == (initial_text <= less_text)); const Text greater(greater_text.c_str()); CHECK((greater <= initial) == (greater_text <= initial_text)); @@ -1968,17 +2276,17 @@ namespace CHECK((initial <= initial) == (initial_text <= initial_text)); // String-Pointer Pointer-String - CHECK((less <= pinitial_text) == (less_text <= pinitial_text)); - CHECK((pinitial_text <= less) == (pinitial_text <= less_text)); + CHECK((less <= pinitial_text) == (less_text <= pinitial_text)); + CHECK((pinitial_text <= less) == (pinitial_text <= less_text)); - CHECK((greater <= pinitial_text) == (greater_text <= pinitial_text)); - CHECK((pinitial_text <= greater) == (pinitial_text <= greater_text)); + CHECK((greater <= pinitial_text) == (greater_text <= pinitial_text)); + CHECK((pinitial_text <= greater) == (pinitial_text <= greater_text)); - CHECK((shorter <= pinitial_text) == (shorter_text <= pinitial_text)); - CHECK((pinitial_text <= shorter) == (pinitial_text <= shorter_text)); + CHECK((shorter <= pinitial_text) == (shorter_text <= pinitial_text)); + CHECK((pinitial_text <= shorter) == (pinitial_text <= shorter_text)); - CHECK((initial <= pinitial_text) == (initial_text <= pinitial_text)); - CHECK((pinitial_text <= initial) == (pinitial_text <= initial_text)); + CHECK((initial <= pinitial_text) == (initial_text <= pinitial_text)); + CHECK((pinitial_text <= initial) == (pinitial_text <= initial_text)); } //************************************************************************* @@ -2004,16 +2312,16 @@ namespace // String-Pointer Pointer-String CHECK((less > pinitial_text) == (less_text > pinitial_text)); - CHECK((pinitial_text > less) == (pinitial_text > less_text)); + CHECK((pinitial_text > less) == (pinitial_text > less_text)); CHECK((greater > pinitial_text) == (greater_text > pinitial_text)); - CHECK((pinitial_text > greater) == (pinitial_text > greater_text)); + CHECK((pinitial_text > greater) == (pinitial_text > greater_text)); CHECK((shorter > pinitial_text) == (shorter_text > pinitial_text)); - CHECK((pinitial_text > shorter) == (pinitial_text > shorter_text)); + CHECK((pinitial_text > shorter) == (pinitial_text > shorter_text)); CHECK((initial > pinitial_text) == (initial_text > pinitial_text)); - CHECK((pinitial_text > initial) == (pinitial_text > initial_text)); + CHECK((pinitial_text > initial) == (pinitial_text > initial_text)); } //************************************************************************* @@ -2023,8 +2331,8 @@ namespace const Text initial(initial_text.begin(), initial_text.end()); // String-String - CHECK((less >= initial) == (less_text >= initial_text)); - CHECK((initial >= less) == (initial_text >= less_text)); + CHECK((less >= initial) == (less_text >= initial_text)); + CHECK((initial >= less) == (initial_text >= less_text)); const Text greater(greater_text.begin(), greater_text.end()); CHECK((greater >= initial) == (greater_text >= initial_text)); @@ -2038,17 +2346,17 @@ namespace CHECK((initial >= initial) == (initial_text >= initial_text)); // String-Pointer Pointer-String - CHECK((less >= pinitial_text) == (less_text >= pinitial_text)); - CHECK((pinitial_text >= less) == (pinitial_text >= less_text)); + CHECK((less >= pinitial_text) == (less_text >= pinitial_text)); + CHECK((pinitial_text >= less) == (pinitial_text >= less_text)); - CHECK((greater >= pinitial_text) == (greater_text >= pinitial_text)); - CHECK((pinitial_text >= greater) == (pinitial_text >= greater_text)); + CHECK((greater >= pinitial_text) == (greater_text >= pinitial_text)); + CHECK((pinitial_text >= greater) == (pinitial_text >= greater_text)); - CHECK((shorter >= pinitial_text) == (shorter_text >= pinitial_text)); - CHECK((pinitial_text >= shorter) == (pinitial_text >= shorter_text)); + CHECK((shorter >= pinitial_text) == (shorter_text >= pinitial_text)); + CHECK((pinitial_text >= shorter) == (pinitial_text >= shorter_text)); - CHECK((initial >= pinitial_text) == (initial_text >= pinitial_text)); - CHECK((pinitial_text >= initial) == (pinitial_text >= initial_text)); + CHECK((initial >= pinitial_text) == (initial_text >= pinitial_text)); + CHECK((pinitial_text >= initial) == (pinitial_text >= initial_text)); } //************************************************************************* @@ -2063,21 +2371,22 @@ namespace size_t length1 = compare_text.copy(buffer1, 5, 2); buffer1[length1] = STR('\0'); - size_t length2 = compare_text.copy(buffer2, 5, 2); + size_t length2 = text.copy(buffer2, 5, 2); buffer2[length2] = STR('\0'); CHECK_EQUAL(length1, length2); + CHECK(!text.truncated()); bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_string) { - const value_t *the_haystack = STR("A haystack with a needle and another needle"); + const value_t* the_haystack = STR("A haystack with a needle and another needle"); std::u32string compare_needle(STR("needle")); etl::u32string<50> needle(STR("needle")); @@ -2097,7 +2406,7 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::iu32string::npos, position2); + CHECK_EQUAL(etl::u32string<50>::npos, position2); etl::u32string<50> pin(STR("pin")); position2 = haystack.find(pin); @@ -2105,9 +2414,9 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_char_pointer) + TEST_FIXTURE(SetupFixture, test_find_pointer) { - const value_t *the_haystack = STR("A haystack with a needle and another needle"); + const value_t* the_haystack = STR("A haystack with a needle and another needle"); const value_t* needle = STR("needle"); @@ -2136,7 +2445,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_char_pointer_n) { - const value_t *the_haystack = STR("A haystack with a needle and another needle"); + const value_t* the_haystack = STR("A haystack with a needle and another needle"); const value_t* needle = STR("needle"); @@ -2272,7 +2581,7 @@ namespace Compare_Text compare_result; Text result; - // Empty string. + // Equal. compare_result = compare_text.substr(compare_text.size()); result = text.substr(text.size()); CHECK(Equal(compare_result, result)); @@ -2623,8 +2932,8 @@ namespace CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(STR('C'), 5); - position2 = text.find_first_of(STR('C'), 5); + position1 = compare_text.find_first_of(STR('C'), compare_text.size()); + position2 = text.find_first_of(STR('C'), text.size()); CHECK_EQUAL(position1, position2); @@ -2650,13 +2959,13 @@ namespace CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(Compare_Text(STR("ZCXE")), 3); - position2 = text.find_last_of(Text(STR("ZCXE")), 3); + position1 = compare_text.find_last_of(Compare_Text(STR("ZCXE")), 5); + position2 = text.find_last_of(Text(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(Compare_Text(STR("ZCXE")), 10); - position2 = text.find_last_of(Text(STR("ZCXE")), 10); + position1 = compare_text.find_last_of(Compare_Text(STR("ZCXE")), compare_text.size()); + position2 = text.find_last_of(Text(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); @@ -2682,8 +2991,8 @@ namespace CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(STR("ZCXE"), 3); - position2 = text.find_last_of(STR("ZCXE"), 3); + position1 = compare_text.find_last_of(STR("ZCXE"), 5); + position2 = text.find_last_of(STR("ZCXE"), 5); CHECK_EQUAL(position1, position2); @@ -2692,8 +3001,8 @@ namespace CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(STR("ZCXE"), 10); - position2 = text.find_last_of(STR("ZCXE"), 10); + position1 = compare_text.find_last_of(STR("ZCXE"), compare_text.size()); + position2 = text.find_last_of(STR("ZCXE"), text.size()); CHECK_EQUAL(position1, position2); @@ -2709,8 +3018,8 @@ namespace Compare_Text compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_of(STR("ZCXE"), 11, 4); - size_t position2 = text.find_last_of(STR("ZCXE"), 11, 4); + size_t position1 = compare_text.find_last_of(STR("AZCXE"), 0, 4); + size_t position2 = text.find_last_of(STR("AZCXE"), 0, 4); CHECK_EQUAL(position1, position2); @@ -2719,8 +3028,8 @@ namespace CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(STR("ZCXE"), 4, 3); - position2 = text.find_last_of(STR("ZCXE"), 4, 3); + position1 = compare_text.find_last_of(STR("ZCXE"), 5, 3); + position2 = text.find_last_of(STR("ZCXE"), 5, 3); CHECK_EQUAL(position1, position2); @@ -2729,8 +3038,8 @@ namespace CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(STR("ZCXE"), 10, 4); - position2 = text.find_last_of(STR("ZCXE"), 10, 4); + position1 = compare_text.find_last_of(STR("ZCXE"), compare_text.size(), 4); + position2 = text.find_last_of(STR("ZCXE"), text.size(), 4); CHECK_EQUAL(position1, position2); @@ -2756,8 +3065,8 @@ namespace CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(STR('F'), 5); - position2 = text.find_last_of(STR('F'), 5); + position1 = compare_text.find_last_of(STR('F'), compare_text.size()); + position2 = text.find_last_of(STR('F'), text.size()); CHECK_EQUAL(position1, position2); @@ -2766,8 +3075,8 @@ namespace CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(STR('C'), 5); - position2 = text.find_last_of(STR('C'), 5); + position1 = compare_text.find_last_of(STR('C'), compare_text.size()); + position2 = text.find_last_of(STR('C'), text.size()); CHECK_EQUAL(position1, position2); @@ -3063,6 +3372,7 @@ namespace CHECK_EQUAL(compare_hash, hash); } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_memcpy_repair) { Text text; diff --git a/test/test_string_view.cpp b/test/test_string_view.cpp index 353f8031a..7ae49af70 100644 --- a/test/test_string_view.cpp +++ b/test/test_string_view.cpp @@ -86,6 +86,18 @@ namespace CHECK(isEqual); } + //************************************************************************* + TEST(test_constructor_etl_string) + { + View view(etltext); + + CHECK_EQUAL(etltext.size(), view.size()); + CHECK_EQUAL(etltext.size(), view.max_size()); + + bool isEqual = std::equal(view.begin(), view.end(), etltext.begin()); + CHECK(isEqual); + } + //************************************************************************* TEST(test_constructor_pointer_size) { diff --git a/test/test_string_wchar_t.cpp b/test/test_string_wchar_t.cpp index 25cbc9107..a8e3e060f 100644 --- a/test/test_string_wchar_t.cpp +++ b/test/test_string_wchar_t.cpp @@ -3,7 +3,7 @@ The MIT License(MIT) Embedded Template Library. https://github.com/ETLCPP/etl -http://www.etlcpp.com +https://www.etlcpp.com Copyright(c) 2016 jwellbelove @@ -101,6 +101,7 @@ namespace CHECK_EQUAL(text.capacity(), SIZE); CHECK_EQUAL(text.max_size(), SIZE); CHECK(text.begin() == text.end()); + CHECK(!text.truncated()); } //************************************************************************* @@ -108,10 +109,11 @@ namespace { Text text; - CHECK(text.begin() == text.end()); - CHECK(text.cbegin() == text.cend()); - CHECK(text.rbegin() == text.rend()); + CHECK(text.begin() == text.end()); + CHECK(text.cbegin() == text.cend()); + CHECK(text.rbegin() == text.rend()); CHECK(text.crbegin() == text.crend()); + CHECK(!text.truncated()); } //************************************************************************* @@ -129,6 +131,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -137,6 +140,7 @@ namespace Text text(SIZE + 1, STR('A')); CHECK_EQUAL(SIZE, text.size()); + CHECK(text.truncated()); } //************************************************************************* @@ -150,6 +154,21 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_excess) + { + Compare_Text compare_text(initial_text.c_str()); + + Text text(longer_text.c_str()); + + CHECK(!text.empty()); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -163,6 +182,21 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size_excess) + { + Compare_Text compare_text(SIZE, STR('A')); + + Text text(SIZE + 1, STR('A')); + + CHECK(!text.empty()); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -176,6 +210,21 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_size_char_excess) + { + Compare_Text compare_text(initial_text.c_str(), initial_text.size()); + + Text text(longer_text.c_str(), longer_text.size()); + + CHECK(!text.empty()); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -187,6 +236,7 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); + CHECK(!text.truncated()); } //************************************************************************* @@ -200,6 +250,7 @@ namespace CHECK(is_equal); CHECK(text.size() == SIZE); CHECK(!text.empty()); + CHECK(text.truncated()); } //************************************************************************* @@ -208,6 +259,27 @@ namespace Text text(initial_text.c_str()); Text text2(text); CHECK(text2 == text); + CHECK(!text2.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_copy_constructor_i) + { + Text text(initial_text.c_str()); + IText& itext = text; + Text text2(itext); + CHECK(text2 == text); + CHECK(!text2.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_copy_constructor_excess) + { + Text text(initial_text.c_str()); + TextL textl(longer_text.c_str()); + Text text2(textl); + CHECK(text2 == text); + CHECK(text2.truncated()); } //************************************************************************* @@ -221,6 +293,21 @@ namespace bool is_equal = Equal(compare_text2, text2); CHECK(is_equal); + CHECK(!text2.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_construct_position_length_excess) + { + Compare_Text compare_text(longer_text.c_str()); + Compare_Text compare_text2(compare_text, 2, 11); + + TextL textl(longer_text.c_str()); + Text text2(textl, 2, 12); + + bool is_equal = Equal(compare_text2, text2); + CHECK(is_equal); + CHECK(text2.truncated()); } //************************************************************************* @@ -231,6 +318,21 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_construct_initializer_list_excess) + { + Compare_Text compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), + STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; + Text text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), + STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), + STR('T'), STR('h'), STR('e'), STR('r'), STR('e') }; + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -243,6 +345,22 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); + CHECK(!text.truncated()); + CHECK(!other_text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_excess) + { + Text text(longer_text.begin(), longer_text.end()); + Text other_text; + + other_text = text; + + bool is_equal = Equal(text, other_text); + CHECK(is_equal); + CHECK(text.truncated()); + CHECK(!other_text.truncated()); } //************************************************************************* @@ -259,8 +377,27 @@ namespace bool is_equal = Equal(text1, text2); CHECK(is_equal); + CHECK(!text1.truncated()); + CHECK(!text2.truncated()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_iterface_excess) + { + Text text1(longer_text.begin(), longer_text.end()); + Text text2; + + IText& itext1 = text1; + IText& itext2 = text2; + + itext2 = itext1; + + bool is_equal = Equal(text1, text2); + + CHECK(is_equal); + CHECK(text1.truncated()); + CHECK(!text2.truncated()); + } //************************************************************************* TEST_FIXTURE(SetupFixture, test_self_assignment) @@ -273,6 +410,23 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); + CHECK(!text.truncated()); + CHECK(!other_text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_self_assignment_excess) + { + Text text(longer_text.begin(), longer_text.end()); + Text other_text(text); + + other_text = other_text; + + bool is_equal = Equal(text, other_text); + + CHECK(is_equal); + CHECK(text.truncated()); + CHECK(!other_text.truncated()); } //************************************************************************* @@ -281,7 +435,7 @@ namespace Text text(initial_text.c_str()); const Text constText(initial_text.c_str()); - CHECK_EQUAL(&text[0], text.begin()); + CHECK_EQUAL(&text[0], text.begin()); CHECK_EQUAL(&constText[0], constText.begin()); } @@ -292,7 +446,7 @@ namespace Text text(initial_text.c_str()); const Text constText(initial_text.c_str()); - CHECK_EQUAL(&text[initial_text.size()], text.end()); + CHECK_EQUAL(&text[initial_text.size()], text.end()); CHECK_EQUAL(&constText[initial_text.size()], constText.end()); } @@ -306,6 +460,7 @@ namespace text.resize(NEW_SIZE); CHECK_EQUAL(text.size(), NEW_SIZE); + CHECK(!text.truncated()); } //************************************************************************* @@ -322,8 +477,8 @@ namespace compare_text.fill(INITIAL_VALUE); bool is_equal = Equal(compare_text, text); - CHECK(is_equal); + CHECK(!text.truncated()); } @@ -336,6 +491,7 @@ namespace Text text(INITIAL_SIZE, STR('A')); text.resize(NEW_SIZE, STR('A')); CHECK_EQUAL(SIZE, text.size()); + CHECK(text.truncated()); } //************************************************************************* @@ -348,6 +504,7 @@ namespace text.resize(NEW_SIZE); CHECK_EQUAL(text.size(), NEW_SIZE); + CHECK(!text.truncated()); } //************************************************************************* @@ -367,26 +524,66 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_empty) + TEST_FIXTURE(SetupFixture, test_empty_full) { Text text; text.resize(text.max_size(), STR('A')); - CHECK(text.full()); CHECK(!text.empty()); + CHECK(!text.truncated()); } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_full) + TEST_FIXTURE(SetupFixture, test_empty_half) + { + Text text; + text.resize(text.max_size() / 2, STR('A')); + + CHECK(!text.empty()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_empty_empty) { Text text; - CHECK(!text.full()); CHECK(text.empty()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_full_full) + { + Text text; + text.resize(text.max_size(), STR('A')); + + CHECK(text.full()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_full_half) + { + Text text; + text.resize(text.max_size() / 2, STR('A')); + + CHECK(!text.full()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_full_empty) + { + Text text; + + CHECK(!text.full()); + CHECK(!text.truncated()); } //************************************************************************* @@ -399,6 +596,8 @@ namespace { CHECK_EQUAL(text[i], compare_text[i]); } + + CHECK(!text.truncated()); } //************************************************************************* @@ -411,6 +610,8 @@ namespace { CHECK_EQUAL(text[i], compare_text[i]); } + + CHECK(!text.truncated()); } //************************************************************************* @@ -424,6 +625,8 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } + CHECK(!text.truncated()); + CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } @@ -438,6 +641,8 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } + CHECK(!text.truncated()); + CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } @@ -448,6 +653,7 @@ namespace Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); + CHECK(!text.truncated()); } //************************************************************************* @@ -457,6 +663,7 @@ namespace const Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); + CHECK(!text.truncated()); } //************************************************************************* @@ -466,6 +673,7 @@ namespace Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); + CHECK(!text.truncated()); } //************************************************************************* @@ -475,6 +683,7 @@ namespace const Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); + CHECK(!text.truncated()); } //************************************************************************* @@ -489,6 +698,7 @@ namespace compare_text.begin()); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -503,6 +713,7 @@ namespace compare_text.begin()); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -511,20 +722,24 @@ namespace Compare_Text compare_text(initial_text.c_str()); Text text; - - text.assign(compare_text.c_str()); + text.assign(initial_text.c_str()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); + } - compare_text.assign(longer_text.c_str()); - compare_text.resize(std::min(compare_text.size(), SIZE)); - - text.assign(compare_text.c_str()); + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_pointer_excess) + { + Compare_Text compare_text(initial_text.c_str()); - is_equal = Equal(compare_text, text); + Text text; + text.assign(longer_text.c_str()); + bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -537,8 +752,8 @@ namespace text.assign(compare_text.begin(), compare_text.end()); bool is_equal = Equal(compare_text, text); - CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -550,11 +765,9 @@ namespace CHECK_EQUAL(initial_text.size(), text.size()); - bool is_equal = std::equal(text.begin(), - text.end(), - initial_text.begin()); - + bool is_equal = Equal(initial_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -572,8 +785,8 @@ namespace CHECK(text.size() == INITIAL_SIZE); bool is_equal = Equal(compare_text, text); - CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -590,10 +803,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } - - //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back) { @@ -615,13 +827,20 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back_excess) { + Compare_Text compare_text; Text text; + for (size_t i = 0; i < SIZE; ++i) + { + compare_text.push_back(STR('A') + value_t(i)); + } + for (size_t i = 0; i < SIZE; ++i) { text.push_back(STR('A') + value_t(i)); @@ -630,8 +849,12 @@ namespace text.push_back(STR('A') + value_t(SIZE)); + CHECK_EQUAL(etl::strlen(compare_text.data()), etl::strlen(text.data())); + CHECK_EQUAL(compare_text.size(), text.size()); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); CHECK(text.truncated()); - CHECK_EQUAL(SIZE, text.size()); } //************************************************************************* @@ -657,7 +880,7 @@ namespace TEST_FIXTURE(SetupFixture, test_insert_position_value) { const size_t INITIAL_SIZE = 5; - const value_t INITIAL_VALUE = STR('A'); + const value_t INITIAL_VALUE = STR('A'); for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) { @@ -720,15 +943,15 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value) { - const size_t INITIAL_SIZE = 5; - const size_t INSERT_SIZE = 3; - const value_t INITIAL_VALUE = STR('A'); + Compare_Text compare_text; + Text text; + + const size_t INITIAL_SIZE = 5; + const size_t INSERT_SIZE = 3; + const value_t INITIAL_VALUE = STR('A'); for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) { - Compare_Text compare_text; - Text text; - text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); compare_text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); text.insert(text.begin() + offset, INSERT_SIZE, INITIAL_VALUE); @@ -748,7 +971,7 @@ namespace Text text; const size_t INSERT_SIZE = 4; - const value_t INSERT_VALUE = STR('A'); + const value_t INSERT_VALUE = STR('A'); size_t offset = 0; compare_text.assign(initial_text.begin(), initial_text.end()); @@ -796,7 +1019,7 @@ namespace text.assign(initial_text.begin(), initial_text.end()); text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - CHECK(!text.truncated()); + CHECK(text.truncated()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -828,7 +1051,7 @@ namespace TEST_FIXTURE(SetupFixture, test_insert_position_range_excess) { const size_t INITIAL_SIZE = 5; - const value_t INITIAL_VALUE = STR('A'); + const value_t INITIAL_VALUE = STR('A'); Compare_Text compare_text; Text text; @@ -890,6 +1113,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); } } @@ -908,6 +1132,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); } } @@ -926,6 +1151,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } } @@ -942,6 +1168,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); compare_text.assign(short_text.begin(), short_text.end()); text.assign(short_text.begin(), short_text.end()); @@ -954,6 +1181,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); compare_text.assign(short_text.begin(), short_text.end()); text.assign(short_text.begin(), short_text.end()); @@ -964,6 +1192,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -979,6 +1208,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -991,6 +1221,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1002,10 +1233,11 @@ namespace // Whole string. compare_text.append(insert_text, 0, std::wstring::npos); - text.append(append, 0, etl::iwstring::npos); + text.append(append, 0, Text::npos); bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Partial string. compare_text.assign(short_text.c_str()); @@ -1018,6 +1250,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1030,6 +1263,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1045,6 +1279,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1056,6 +1291,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1071,6 +1307,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1082,6 +1319,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1097,6 +1335,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1109,6 +1348,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1124,6 +1364,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Non-overflow short text. compare_text.assign(short_text.c_str()); @@ -1135,6 +1376,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -1146,6 +1388,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -1157,17 +1400,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 2, Compare_Text(STR("Replace"))); + compare_text.replace(2, 7, Compare_Text(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, Text(STR("Replace"))); + text.replace(2, 7, Text(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -1179,6 +1424,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Overflow, npos. compare_text.assign(initial_text.c_str()); @@ -1190,6 +1436,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1205,6 +1452,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -1216,17 +1464,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, Compare_Text(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, Compare_Text(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, Text(STR("Replace"))); + text.replace(text.begin() + 2, text.begin() + 9, Text(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -1238,6 +1488,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1253,6 +1504,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -1264,6 +1516,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -1275,6 +1528,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -1286,17 +1540,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, Compare_Text(STR("Replace")), 1, 5); + compare_text.replace(2, 7, Compare_Text(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, Text(STR("Replace")), 1, 5); + text.replace(2, 7, Text(STR("Replace")), 1, 5); is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); @@ -1308,6 +1564,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -1319,6 +1576,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Overflow, npos. compare_text.assign(initial_text.c_str()); @@ -1330,6 +1588,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1345,6 +1604,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -1356,6 +1616,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -1367,6 +1628,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -1378,17 +1640,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, Compare_Text(STR("Replace")).c_str()); + compare_text.replace(2, 7, Compare_Text(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, Text(STR("Replace")).c_str()); + text.replace(2, 7, Text(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); @@ -1400,6 +1664,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -1411,6 +1676,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Overflow, npos. compare_text.assign(initial_text.c_str()); @@ -1422,6 +1688,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1437,6 +1704,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -1448,17 +1716,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, Compare_Text(STR("Replace")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, Compare_Text(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, Text(STR("Replace")).c_str()); + text.replace(text.begin() + 2, text.begin() + 9, Text(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -1470,6 +1740,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1485,6 +1756,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -1496,6 +1768,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -1507,6 +1780,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -1518,17 +1792,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, Compare_Text(STR("Replace")).c_str(), 5); + compare_text.replace(2, 7, Compare_Text(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, Text(STR("Replace")).c_str(), 5); + text.replace(2, 7, Text(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); @@ -1540,6 +1816,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -1551,6 +1828,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Overflow, npos. compare_text.assign(initial_text.c_str()); @@ -1562,6 +1840,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1577,6 +1856,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -1588,17 +1868,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, Compare_Text(STR("Replace")).c_str(), 5); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, Compare_Text(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, Text(STR("Replace")).c_str(), 5); + text.replace(text.begin() + 2, text.begin() + 9, Text(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -1610,6 +1892,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1625,6 +1908,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -1636,6 +1920,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -1647,6 +1932,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -1658,17 +1944,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, 7, STR('A')); + compare_text.replace(2, 7, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, 7, STR('A')); + text.replace(2, 7, 7, STR('A')); is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); @@ -1680,6 +1968,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -1691,6 +1980,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Overflow, npos. compare_text.assign(initial_text.c_str()); @@ -1702,6 +1992,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1717,6 +2008,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -1728,17 +2020,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 7, STR('A')); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, 7, STR('A')); + text.replace(text.begin() + 2, text.begin() + 9, 7, STR('A')); is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -1750,6 +2044,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1768,6 +2063,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -1779,17 +2075,19 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, replace.begin() + 1, replace.begin() + 5); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 7, replace.begin() + 1, replace.begin() + 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, replace_long.begin() + 1, replace_long.begin() + 5); + text.replace(text.begin() + 2, text.begin() + 7, replace_long.begin() + 1, replace_long.begin() + 5); is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -1801,6 +2099,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(text.truncated()); } //************************************************************************* @@ -1814,6 +2113,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -1828,6 +2128,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -1837,6 +2138,7 @@ namespace text.clear(); CHECK_EQUAL(text.size(), size_t(0)); + CHECK(!text.truncated()); } //************************************************************************* @@ -1845,8 +2147,9 @@ namespace Compare_Text compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - bool is_equal = Equal(compare_text, text); + bool is_equal = std::equal(text.begin(), text.end(), compare_text.begin()); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -1855,8 +2158,9 @@ namespace Compare_Text compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - bool is_equal = Equal(compare_text, text); + bool is_equal = std::equal(text.cbegin(), text.cend(), compare_text.cbegin()); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -1865,8 +2169,9 @@ namespace Compare_Text compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - bool is_equal = Equal(compare_text, text); + bool is_equal = std::equal(text.rbegin(), text.rend(), compare_text.rbegin()); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -1875,8 +2180,9 @@ namespace Compare_Text compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - bool is_equal = Equal(compare_text, text); + bool is_equal = std::equal(text.crbegin(), text.crend(), compare_text.crbegin()); CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -1936,16 +2242,16 @@ namespace // String-Pointer Pointer-String CHECK((less < pinitial_text) == (less_text < pinitial_text)); - CHECK((pinitial_text < less) == (pinitial_text < less_text)); + CHECK((pinitial_text < less) == (pinitial_text < less_text)); CHECK((greater < pinitial_text) == (greater_text < pinitial_text)); - CHECK((pinitial_text < greater) == (pinitial_text < greater_text)); + CHECK((pinitial_text < greater) == (pinitial_text < greater_text)); CHECK((shorter < pinitial_text) == (shorter_text < pinitial_text)); - CHECK((pinitial_text < shorter) == (pinitial_text < shorter_text)); + CHECK((pinitial_text < shorter) == (pinitial_text < shorter_text)); CHECK((initial < pinitial_text) == (initial_text < pinitial_text)); - CHECK((pinitial_text < initial) == (pinitial_text < initial_text)); + CHECK((pinitial_text < initial) == (pinitial_text < initial_text)); } //************************************************************************* @@ -1955,8 +2261,8 @@ namespace const Text initial(initial_text.c_str()); // String-String - CHECK((less <= initial) == (less_text <= initial_text)); - CHECK((initial <= less) == (initial_text <= less_text)); + CHECK((less <= initial) == (less_text <= initial_text)); + CHECK((initial <= less) == (initial_text <= less_text)); const Text greater(greater_text.c_str()); CHECK((greater <= initial) == (greater_text <= initial_text)); @@ -1970,17 +2276,17 @@ namespace CHECK((initial <= initial) == (initial_text <= initial_text)); // String-Pointer Pointer-String - CHECK((less <= pinitial_text) == (less_text <= pinitial_text)); - CHECK((pinitial_text <= less) == (pinitial_text <= less_text)); + CHECK((less <= pinitial_text) == (less_text <= pinitial_text)); + CHECK((pinitial_text <= less) == (pinitial_text <= less_text)); - CHECK((greater <= pinitial_text) == (greater_text <= pinitial_text)); - CHECK((pinitial_text <= greater) == (pinitial_text <= greater_text)); + CHECK((greater <= pinitial_text) == (greater_text <= pinitial_text)); + CHECK((pinitial_text <= greater) == (pinitial_text <= greater_text)); - CHECK((shorter <= pinitial_text) == (shorter_text <= pinitial_text)); - CHECK((pinitial_text <= shorter) == (pinitial_text <= shorter_text)); + CHECK((shorter <= pinitial_text) == (shorter_text <= pinitial_text)); + CHECK((pinitial_text <= shorter) == (pinitial_text <= shorter_text)); - CHECK((initial <= pinitial_text) == (initial_text <= pinitial_text)); - CHECK((pinitial_text <= initial) == (pinitial_text <= initial_text)); + CHECK((initial <= pinitial_text) == (initial_text <= pinitial_text)); + CHECK((pinitial_text <= initial) == (pinitial_text <= initial_text)); } //************************************************************************* @@ -2006,16 +2312,16 @@ namespace // String-Pointer Pointer-String CHECK((less > pinitial_text) == (less_text > pinitial_text)); - CHECK((pinitial_text > less) == (pinitial_text > less_text)); + CHECK((pinitial_text > less) == (pinitial_text > less_text)); CHECK((greater > pinitial_text) == (greater_text > pinitial_text)); - CHECK((pinitial_text > greater) == (pinitial_text > greater_text)); + CHECK((pinitial_text > greater) == (pinitial_text > greater_text)); CHECK((shorter > pinitial_text) == (shorter_text > pinitial_text)); - CHECK((pinitial_text > shorter) == (pinitial_text > shorter_text)); + CHECK((pinitial_text > shorter) == (pinitial_text > shorter_text)); CHECK((initial > pinitial_text) == (initial_text > pinitial_text)); - CHECK((pinitial_text > initial) == (pinitial_text > initial_text)); + CHECK((pinitial_text > initial) == (pinitial_text > initial_text)); } //************************************************************************* @@ -2025,8 +2331,8 @@ namespace const Text initial(initial_text.begin(), initial_text.end()); // String-String - CHECK((less >= initial) == (less_text >= initial_text)); - CHECK((initial >= less) == (initial_text >= less_text)); + CHECK((less >= initial) == (less_text >= initial_text)); + CHECK((initial >= less) == (initial_text >= less_text)); const Text greater(greater_text.begin(), greater_text.end()); CHECK((greater >= initial) == (greater_text >= initial_text)); @@ -2040,17 +2346,17 @@ namespace CHECK((initial >= initial) == (initial_text >= initial_text)); // String-Pointer Pointer-String - CHECK((less >= pinitial_text) == (less_text >= pinitial_text)); - CHECK((pinitial_text >= less) == (pinitial_text >= less_text)); + CHECK((less >= pinitial_text) == (less_text >= pinitial_text)); + CHECK((pinitial_text >= less) == (pinitial_text >= less_text)); - CHECK((greater >= pinitial_text) == (greater_text >= pinitial_text)); - CHECK((pinitial_text >= greater) == (pinitial_text >= greater_text)); + CHECK((greater >= pinitial_text) == (greater_text >= pinitial_text)); + CHECK((pinitial_text >= greater) == (pinitial_text >= greater_text)); - CHECK((shorter >= pinitial_text) == (shorter_text >= pinitial_text)); - CHECK((pinitial_text >= shorter) == (pinitial_text >= shorter_text)); + CHECK((shorter >= pinitial_text) == (shorter_text >= pinitial_text)); + CHECK((pinitial_text >= shorter) == (pinitial_text >= shorter_text)); - CHECK((initial >= pinitial_text) == (initial_text >= pinitial_text)); - CHECK((pinitial_text >= initial) == (pinitial_text >= initial_text)); + CHECK((initial >= pinitial_text) == (initial_text >= pinitial_text)); + CHECK((pinitial_text >= initial) == (pinitial_text >= initial_text)); } //************************************************************************* @@ -2065,21 +2371,22 @@ namespace size_t length1 = compare_text.copy(buffer1, 5, 2); buffer1[length1] = STR('\0'); - size_t length2 = compare_text.copy(buffer2, 5, 2); + size_t length2 = text.copy(buffer2, 5, 2); buffer2[length2] = STR('\0'); CHECK_EQUAL(length1, length2); + CHECK(!text.truncated()); bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_string) { - const value_t *the_haystack = STR("A haystack with a needle and another needle"); + const value_t* the_haystack = STR("A haystack with a needle and another needle"); std::wstring compare_needle(STR("needle")); etl::wstring<50> needle(STR("needle")); @@ -2099,7 +2406,7 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::iwstring::npos, position2); + CHECK_EQUAL(etl::wstring<50>::npos, position2); etl::wstring<50> pin(STR("pin")); position2 = haystack.find(pin); @@ -2107,9 +2414,9 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_char_pointer) + TEST_FIXTURE(SetupFixture, test_find_pointer) { - const value_t *the_haystack = STR("A haystack with a needle and another needle"); + const value_t* the_haystack = STR("A haystack with a needle and another needle"); const value_t* needle = STR("needle"); @@ -2138,7 +2445,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_char_pointer_n) { - const value_t *the_haystack = STR("A haystack with a needle and another needle"); + const value_t* the_haystack = STR("A haystack with a needle and another needle"); const value_t* needle = STR("needle"); @@ -2274,7 +2581,7 @@ namespace Compare_Text compare_result; Text result; - // Empty string. + // Equal. compare_result = compare_text.substr(compare_text.size()); result = text.substr(text.size()); CHECK(Equal(compare_result, result)); @@ -2625,8 +2932,8 @@ namespace CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(STR('C'), 5); - position2 = text.find_first_of(STR('C'), 5); + position1 = compare_text.find_first_of(STR('C'), compare_text.size()); + position2 = text.find_first_of(STR('C'), text.size()); CHECK_EQUAL(position1, position2); @@ -2652,13 +2959,13 @@ namespace CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(Compare_Text(STR("ZCXE")), 3); - position2 = text.find_last_of(Text(STR("ZCXE")), 3); + position1 = compare_text.find_last_of(Compare_Text(STR("ZCXE")), 5); + position2 = text.find_last_of(Text(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(Compare_Text(STR("ZCXE")), 10); - position2 = text.find_last_of(Text(STR("ZCXE")), 10); + position1 = compare_text.find_last_of(Compare_Text(STR("ZCXE")), compare_text.size()); + position2 = text.find_last_of(Text(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); @@ -2684,8 +2991,8 @@ namespace CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(STR("ZCXE"), 3); - position2 = text.find_last_of(STR("ZCXE"), 3); + position1 = compare_text.find_last_of(STR("ZCXE"), 5); + position2 = text.find_last_of(STR("ZCXE"), 5); CHECK_EQUAL(position1, position2); @@ -2694,8 +3001,8 @@ namespace CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(STR("ZCXE"), 10); - position2 = text.find_last_of(STR("ZCXE"), 10); + position1 = compare_text.find_last_of(STR("ZCXE"), compare_text.size()); + position2 = text.find_last_of(STR("ZCXE"), text.size()); CHECK_EQUAL(position1, position2); @@ -2711,8 +3018,8 @@ namespace Compare_Text compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_of(STR("ZCXE"), 11, 4); - size_t position2 = text.find_last_of(STR("ZCXE"), 11, 4); + size_t position1 = compare_text.find_last_of(STR("AZCXE"), 0, 4); + size_t position2 = text.find_last_of(STR("AZCXE"), 0, 4); CHECK_EQUAL(position1, position2); @@ -2721,8 +3028,8 @@ namespace CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(STR("ZCXE"), 4, 3); - position2 = text.find_last_of(STR("ZCXE"), 4, 3); + position1 = compare_text.find_last_of(STR("ZCXE"), 5, 3); + position2 = text.find_last_of(STR("ZCXE"), 5, 3); CHECK_EQUAL(position1, position2); @@ -2731,8 +3038,8 @@ namespace CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(STR("ZCXE"), 10, 4); - position2 = text.find_last_of(STR("ZCXE"), 10, 4); + position1 = compare_text.find_last_of(STR("ZCXE"), compare_text.size(), 4); + position2 = text.find_last_of(STR("ZCXE"), text.size(), 4); CHECK_EQUAL(position1, position2); @@ -2758,8 +3065,8 @@ namespace CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(STR('F'), 5); - position2 = text.find_last_of(STR('F'), 5); + position1 = compare_text.find_last_of(STR('F'), compare_text.size()); + position2 = text.find_last_of(STR('F'), text.size()); CHECK_EQUAL(position1, position2); @@ -2768,8 +3075,8 @@ namespace CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(STR('C'), 5); - position2 = text.find_last_of(STR('C'), 5); + position1 = compare_text.find_last_of(STR('C'), compare_text.size()); + position2 = text.find_last_of(STR('C'), text.size()); CHECK_EQUAL(position1, position2);