Merge remote-tracking branch 'origin/hotfix/string-truncate-bug' into development

This commit is contained in:
John Wellbelove 2019-03-23 14:25:17 +00:00
commit 35883fc370
11 changed files with 1088 additions and 73 deletions

View File

@ -221,6 +221,14 @@ namespace etl
return is_truncated;
}
//*************************************************************************
/// Clears the 'truncated' flag.
//*************************************************************************
void clear_truncated()
{
is_truncated = false;
}
protected:
//*************************************************************************
@ -393,7 +401,10 @@ namespace etl
//*********************************************************************
void resize(size_t new_size, T value)
{
is_truncated = (new_size > CAPACITY);
if (new_size > CAPACITY)
{
is_truncated = true;
}
new_size = std::min(new_size, CAPACITY);
@ -512,8 +523,12 @@ namespace etl
//*********************************************************************
void assign(const etl::ibasic_string<T>& other)
{
size_t len = std::min(CAPACITY, other.size());
assign(other.begin(), other.begin() + len);
assign(other.begin(), other.end());
if (other.truncated())
{
is_truncated = true;
}
}
//*********************************************************************
@ -639,7 +654,6 @@ namespace etl
{
p_buffer[current_size++] = value;
p_buffer[current_size] = 0;
is_truncated = false;
}
else
{
@ -666,6 +680,12 @@ namespace etl
ibasic_string& append(const ibasic_string& str)
{
insert(end(), str.begin(), str.end());
if (str.truncated())
{
is_truncated = true;
}
return *this;
}
@ -680,6 +700,7 @@ namespace etl
ETL_ASSERT(subposition <= str.size(), ETL_ERROR(string_out_of_bounds));
insert(size(), str, subposition, sublength);
return *this;
}
@ -734,8 +755,6 @@ namespace etl
//*********************************************************************
iterator insert(const_iterator position, T value)
{
is_truncated = false;
// Quick hack, as iterators are pointers.
iterator insert_position = const_cast<iterator>(position);
@ -782,8 +801,6 @@ namespace etl
//*********************************************************************
void insert(const_iterator position, size_t n, T value)
{
is_truncated = false;
if (n == 0)
{
return;
@ -803,7 +820,11 @@ namespace etl
// Fills the string to the end?
if ((start + n) >= CAPACITY)
{
is_truncated = ((current_size + n) > CAPACITY);
if ((current_size + n) > CAPACITY)
{
is_truncated = true;
}
current_size = CAPACITY;
std::fill(insert_position, end(), value);
}
@ -844,8 +865,6 @@ namespace etl
template <class TIterator>
void insert(iterator position, TIterator first, TIterator last)
{
is_truncated = false;
if (first == last)
{
return;
@ -864,7 +883,11 @@ namespace etl
// Fills the string to the end?
if ((start + n) >= CAPACITY)
{
is_truncated = ((current_size + n) > CAPACITY);
if (((current_size + n) > CAPACITY))
{
is_truncated = true;
}
current_size = CAPACITY;
while (position != end())
@ -913,6 +936,12 @@ namespace etl
ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
insert(begin() + position, str.cbegin(), str.cend());
if (str.truncated())
{
is_truncated = true;
}
return *this;
}
@ -934,6 +963,12 @@ namespace etl
}
insert(begin() + position, str.cbegin() + subposition, str.cbegin() + subposition + sublength);
if (str.truncated())
{
is_truncated = true;
}
return *this;
}
@ -1004,8 +1039,6 @@ namespace etl
std::copy(i_element + 1, end(), i_element);
p_buffer[--current_size] = 0;
is_truncated = false;
return i_element;
}
@ -1025,8 +1058,6 @@ namespace etl
current_size -= n_delete;
p_buffer[current_size] = 0;
is_truncated = false;
return first;
}
@ -1046,7 +1077,10 @@ namespace etl
//*********************************************************************
size_t copy(pointer s, size_t len, size_t pos = 0)
{
is_truncated = (pos + len > size());
if ((pos + len > size()))
{
is_truncated = true;
}
size_t endpos = std::min(pos + len, size());
@ -1321,6 +1355,11 @@ namespace etl
// Insert the new stuff.
insert(first_, str.begin(), str.end());
if (str.truncated())
{
is_truncated = true;
}
return *this;
}
@ -1872,21 +1911,28 @@ namespace etl
{
if (&rhs != this)
{
assign(rhs.cbegin(), rhs.cend());
assign(rhs);
}
return *this;
}
//*************************************************************************
/// Assignment operator.
//*************************************************************************
ibasic_string& operator = (const_pointer rhs)
{
assign(rhs);
return *this;
}
//*************************************************************************
/// += operator.
//*************************************************************************
ibasic_string& operator += (const ibasic_string& rhs)
{
if (&rhs != this)
{
append(rhs);
}
append(rhs);
return *this;
}
@ -1894,7 +1940,7 @@ namespace etl
//*************************************************************************
/// += operator.
//*************************************************************************
ibasic_string& operator += (const T* rhs)
ibasic_string& operator += (const_pointer rhs)
{
append(rhs);

View File

@ -75,7 +75,7 @@ namespace etl
string(const etl::string<MAX_SIZE_>& other)
: istring(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
{
this->assign(other.begin(), other.end());
this->assign(other);
}
//*************************************************************************
@ -85,7 +85,7 @@ namespace etl
string(const etl::istring& other)
: istring(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
{
this->assign(other.begin(), other.end());
this->assign(other);
}
//*************************************************************************
@ -100,6 +100,11 @@ namespace etl
ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds));
this->assign(other.begin() + position, other.begin() + position + length_);
if (other.truncated())
{
this->is_truncated = true;
}
}
//*************************************************************************
@ -187,12 +192,22 @@ namespace etl
{
if (&rhs != this)
{
this->assign(rhs.cbegin(), rhs.cend());
this->assign(rhs);
}
return *this;
}
//*************************************************************************
/// Assignment operator.
//*************************************************************************
string& operator = (const value_type* text)
{
this->assign(text);
return *this;
}
//*************************************************************************
/// Fix the internal pointers after a low level memory copy.
//*************************************************************************

View File

@ -75,8 +75,7 @@ namespace etl
u16string(const etl::u16string<MAX_SIZE_>& other)
: iu16string(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
{
this->initialise();
this->assign(other.begin(), other.end());
this->assign(other);
}
//*************************************************************************
@ -86,7 +85,7 @@ namespace etl
u16string(const etl::iu16string& other)
: iu16string(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
{
this->assign(other.begin(), other.end());
this->assign(other);
}
//*************************************************************************
@ -100,8 +99,12 @@ namespace etl
{
ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds));
this->initialise();
this->assign(other.begin() + position, other.begin() + position + length_);
if (other.truncated())
{
this->is_truncated = true;
}
}
//*************************************************************************
@ -111,7 +114,6 @@ namespace etl
u16string(const value_type* text)
: iu16string(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
{
this->initialise();
this->assign(text, text + etl::char_traits<value_type>::length(text));
}
@ -123,7 +125,6 @@ namespace etl
u16string(const value_type* text, size_t count)
: iu16string(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
{
this->initialise();
this->assign(text, text + count);
}
@ -191,12 +192,22 @@ namespace etl
{
if (&rhs != this)
{
this->assign(rhs.cbegin(), rhs.cend());
this->assign(rhs);
}
return *this;
}
//*************************************************************************
/// Assignment operator.
//*************************************************************************
u16string& operator = (const value_type* text)
{
this->assign(text);
return *this;
}
//*************************************************************************
/// Fix the internal pointers after a low level memory copy.
//*************************************************************************

View File

@ -75,8 +75,7 @@ namespace etl
u32string(const etl::u32string<MAX_SIZE_>& other)
: iu32string(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
{
this->initialise();
this->assign(other.begin(), other.end());
this->assign(other);
}
//*************************************************************************
@ -86,7 +85,7 @@ namespace etl
u32string(const etl::iu32string& other)
: iu32string(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
{
this->assign(other.begin(), other.end());
this->assign(other);
}
//*************************************************************************
@ -100,8 +99,12 @@ namespace etl
{
ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds));
this->initialise();
this->assign(other.begin() + position, other.begin() + position + length_);
if (other.truncated())
{
this->is_truncated = true;
}
}
//*************************************************************************
@ -111,7 +114,6 @@ namespace etl
u32string(const value_type* text)
: iu32string(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
{
this->initialise();
this->assign(text, text + etl::char_traits<value_type>::length(text));
}
@ -123,7 +125,6 @@ namespace etl
u32string(const value_type* text, size_t count)
: iu32string(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
{
this->initialise();
this->assign(text, text + count);
}
@ -191,12 +192,22 @@ namespace etl
{
if (&rhs != this)
{
this->assign(rhs.cbegin(), rhs.cend());
this->assign(rhs);
}
return *this;
}
//*************************************************************************
/// Assignment operator.
//*************************************************************************
u32string& operator = (const value_type* text)
{
this->assign(text);
return *this;
}
//*************************************************************************
/// Fix the internal pointers after a low level memory copy.
//*************************************************************************

View File

@ -39,7 +39,7 @@ SOFTWARE.
#define ETL_VERSION_MAJOR 14
#define ETL_VERSION_MINOR 14
#define ETL_VERSION_PATCH 1
#define ETL_VERSION_PATCH 2
#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))

View File

@ -75,8 +75,7 @@ namespace etl
wstring(const etl::wstring<MAX_SIZE_>& other)
: iwstring(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
{
wstring::initialise();
wstring::assign(other.begin(), other.end());
this->assign(other);
}
//*************************************************************************
@ -86,7 +85,7 @@ namespace etl
wstring(const etl::iwstring& other)
: iwstring(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
{
this->assign(other.begin(), other.end());
this->assign(other);
}
@ -101,8 +100,12 @@ namespace etl
{
ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds));
this->initialise();
this->assign(other.begin() + position, other.begin() + position + length_);
if (other.truncated())
{
this->is_truncated = true;
}
}
//*************************************************************************
@ -112,7 +115,6 @@ namespace etl
wstring(const value_type* text)
: iwstring(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
{
this->initialise();
this->assign(text, text + etl::char_traits<value_type>::length(text));
}
@ -124,7 +126,6 @@ namespace etl
wstring(const value_type* text, size_t count)
: iwstring(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
{
this->initialise();
this->assign(text, text + count);
}
@ -192,12 +193,22 @@ namespace etl
{
if (&rhs != this)
{
this->assign(rhs.cbegin(), rhs.cend());
this->assign(rhs);
}
return *this;
}
//*************************************************************************
/// Assignment operator.
//*************************************************************************
wstring& operator = (const value_type* text)
{
this->assign(text);
return *this;
}
//*************************************************************************
/// Fix the internal pointers after a low level memory copy.
//*************************************************************************

View File

@ -1,3 +1,8 @@
===============================================================================
14.14.2
Modified 'truncated' to only be cleared on 'clear()' or 'assign()'.
Added assignment from zero terminated string pointer.
===============================================================================
14.14.1
Fixed bug where 'truncated' was not always set correctly for strings.

View File

@ -56,6 +56,7 @@ namespace
typedef std::string Compare_Text;
typedef Text::value_type value_t;
typedef etl::string<52> TextL;
typedef etl::string<4> TextS;
Compare_Text initial_text;
Compare_Text less_text;
@ -243,9 +244,7 @@ namespace
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_constructor_range_excess)
{
Text text;
text.assign(longer_text.begin(), longer_text.end());
Text text(longer_text.begin(), longer_text.end());
bool is_equal = Equal(initial_text, text);
CHECK(is_equal);
@ -283,6 +282,14 @@ namespace
CHECK(text2.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_copy_constructor_from_truncated)
{
Text text(longer_text.c_str());
Text text2(text);
CHECK(text2.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_construct_position_length)
{
@ -361,7 +368,7 @@ namespace
bool is_equal = Equal(text, other_text);
CHECK(is_equal);
CHECK(text.truncated());
CHECK(!other_text.truncated());
CHECK(other_text.truncated());
}
//*************************************************************************
@ -397,7 +404,7 @@ namespace
CHECK(is_equal);
CHECK(text1.truncated());
CHECK(!text2.truncated());
CHECK(text2.truncated());
}
//*************************************************************************
@ -427,7 +434,57 @@ namespace
CHECK(is_equal);
CHECK(text.truncated());
CHECK(!other_text.truncated());
CHECK(other_text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_assignment_from_literal)
{
Text text;
text = STR("Hello World");
bool is_equal = Equal(std::string(STR("Hello World")), text);
CHECK(is_equal);
CHECK(!text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_assignment_from_literal_excess)
{
Text text;
text = STR("Hello World There");
bool is_equal = Equal(std::string(STR("Hello World")), text);
CHECK(is_equal);
CHECK(text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_assignment_from_literal_via_interface)
{
Text text;
IText& itext = text;
itext = STR("Hello World");
bool is_equal = Equal(std::string(STR("Hello World")), itext);
CHECK(is_equal);
CHECK(!itext.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_assignment_from_literal_via_interface_excess)
{
Text text;
IText& itext = text;
itext = STR("Hello World There");
bool is_equal = Equal(std::string(STR("Hello World")), itext);
CHECK(is_equal);
CHECK(itext.truncated());
}
//*************************************************************************
@ -717,6 +774,40 @@ namespace
CHECK(!text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_assign_string)
{
Compare_Text compare_input(initial_text.c_str());
Text input(initial_text.c_str());
Compare_Text compare_text;
Text text;
compare_text.assign(compare_input);
text.assign(input);
bool is_equal = Equal(compare_text, text);
CHECK(is_equal);
CHECK(!text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_assign_string_excess)
{
Compare_Text compare_input(initial_text.c_str());
TextL input(longer_text.c_str());
Compare_Text compare_text;
Text text;
compare_text.assign(compare_input);
text.assign(input);
bool is_equal = Equal(compare_text, text);
CHECK(is_equal);
CHECK(text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_assign_pointer)
{
@ -1156,6 +1247,27 @@ namespace
}
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_from_truncated)
{
for (size_t offset = 0; offset <= short_text.size(); ++offset)
{
Compare_Text compare_text(short_text.begin(), short_text.end());
Text text(short_text.begin(), short_text.end());
Text insert(longer_text.begin(), longer_text.end());
insert.erase(insert.begin(), insert.end());
insert.append(insert_text.begin(), insert_text.end());
text.insert(offset, insert);
compare_text.insert(offset, insert_text);
compare_text.resize(std::min(compare_text.size(), SIZE));
bool is_equal = Equal(compare_text, text);
CHECK(is_equal);
CHECK(text.truncated());
}
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen)
{
@ -1225,6 +1337,44 @@ namespace
CHECK(text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_append_truncated_string)
{
Text text(short_text.c_str());
TextS append(short_text.c_str());
CHECK(append.truncated());
text.append(append);
CHECK(text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_append_string_to_self)
{
Compare_Text compare_text(short_text.c_str());
Text text(short_text.c_str());
// Non-overflow.
compare_text.append(compare_text);
text.append(text);
bool is_equal = Equal(compare_text, text);
CHECK(is_equal);
CHECK(!text.truncated());
// Overflow.
compare_text.assign(shorter_text.c_str());
text.assign(shorter_text.c_str());
compare_text.append(compare_text);
compare_text.resize(std::min(compare_text.size(), SIZE));
text.append(text);
is_equal = Equal(compare_text, text);
CHECK(is_equal);
CHECK(text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_append_string_subpos_sublen)
{
@ -1267,6 +1417,17 @@ namespace
CHECK(text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_append_truncated_string_subpos_sublen)
{
Text text(short_text.c_str());
TextS append(short_text.c_str());
CHECK(append.truncated());
text.append(append, 1, 2);
CHECK(text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_append_c_string)
{
@ -3422,5 +3583,73 @@ namespace
is_equal = Equal(text, itext);
CHECK(!is_equal);
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_truncate_over_many_operations)
{
Text text(short_text.c_str());
CHECK(!text.truncated());
text.insert(3, initial_text.c_str());
CHECK(text.truncated());
while (text.size() != 0)
{
text.pop_back();
CHECK(text.truncated());
}
text.clear();
CHECK(!text.truncated());
text.assign(longer_text.c_str());
CHECK(text.truncated());
text.assign(short_text.c_str());
CHECK(!text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_add_from_truncated)
{
Text text1(short_text.c_str());
TextS text2(short_text.c_str());
CHECK(!text1.truncated());
CHECK(text2.truncated());
// text2 has the truncate flag set.
text1 += text2;
CHECK(text1.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_add_to_truncated)
{
Text text1(longer_text.c_str());
Text text2(short_text.c_str());
CHECK(text1.truncated());
CHECK(!text2.truncated());
// Clear text but not the truncate flag.
text1.erase(text1.begin(), text1.end());
// text1 still has the truncate flag set.
text1 += text2;
CHECK(text1.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_clear_truncated)
{
Text text(longer_text.c_str());
CHECK(text.truncated());
text.clear_truncated();
CHECK(!text.truncated());
}
};
}

View File

@ -55,6 +55,7 @@ namespace
typedef std::u16string Compare_Text;
typedef Text::value_type value_t;
typedef etl::u16string<52> TextL;
typedef etl::u16string<4> TextS;
Compare_Text initial_text;
Compare_Text less_text;
@ -242,9 +243,7 @@ namespace
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_constructor_range_excess)
{
Text text;
text.assign(longer_text.begin(), longer_text.end());
Text text(longer_text.begin(), longer_text.end());
bool is_equal = Equal(initial_text, text);
CHECK(is_equal);
@ -282,6 +281,14 @@ namespace
CHECK(text2.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_copy_constructor_from_truncated)
{
Text text(longer_text.c_str());
Text text2(text);
CHECK(text2.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_construct_position_length)
{
@ -360,7 +367,7 @@ namespace
bool is_equal = Equal(text, other_text);
CHECK(is_equal);
CHECK(text.truncated());
CHECK(!other_text.truncated());
CHECK(other_text.truncated());
}
//*************************************************************************
@ -396,7 +403,7 @@ namespace
CHECK(is_equal);
CHECK(text1.truncated());
CHECK(!text2.truncated());
CHECK(text2.truncated());
}
//*************************************************************************
@ -426,7 +433,57 @@ namespace
CHECK(is_equal);
CHECK(text.truncated());
CHECK(!other_text.truncated());
CHECK(other_text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_assignment_from_literal)
{
Text text;
text = STR("Hello World");
bool is_equal = Equal(std::u16string(STR("Hello World")), text);
CHECK(is_equal);
CHECK(!text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_assignment_from_literal_excess)
{
Text text;
text = STR("Hello World There");
bool is_equal = Equal(std::u16string(STR("Hello World")), text);
CHECK(is_equal);
CHECK(text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_assignment_from_literal_via_interface)
{
Text text;
IText& itext = text;
itext = STR("Hello World");
bool is_equal = Equal(std::u16string(STR("Hello World")), itext);
CHECK(is_equal);
CHECK(!itext.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_assignment_from_literal_via_interface_excess)
{
Text text;
IText& itext = text;
itext = STR("Hello World There");
bool is_equal = Equal(std::u16string(STR("Hello World")), itext);
CHECK(is_equal);
CHECK(itext.truncated());
}
//*************************************************************************
@ -716,6 +773,40 @@ namespace
CHECK(!text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_assign_string)
{
Compare_Text compare_input(initial_text.c_str());
Text input(initial_text.c_str());
Compare_Text compare_text;
Text text;
compare_text.assign(compare_input);
text.assign(input);
bool is_equal = Equal(compare_text, text);
CHECK(is_equal);
CHECK(!text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_assign_string_excess)
{
Compare_Text compare_input(initial_text.c_str());
TextL input(longer_text.c_str());
Compare_Text compare_text;
Text text;
compare_text.assign(compare_input);
text.assign(input);
bool is_equal = Equal(compare_text, text);
CHECK(is_equal);
CHECK(text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_assign_pointer)
{
@ -1155,6 +1246,27 @@ namespace
}
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_from_truncated)
{
for (size_t offset = 0; offset <= short_text.size(); ++offset)
{
Compare_Text compare_text(short_text.begin(), short_text.end());
Text text(short_text.begin(), short_text.end());
Text insert(longer_text.begin(), longer_text.end());
insert.erase(insert.begin(), insert.end());
insert.append(insert_text.begin(), insert_text.end());
text.insert(offset, insert);
compare_text.insert(offset, insert_text);
compare_text.resize(std::min(compare_text.size(), SIZE));
bool is_equal = Equal(compare_text, text);
CHECK(is_equal);
CHECK(text.truncated());
}
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen)
{
@ -1224,6 +1336,44 @@ namespace
CHECK(text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_append_truncated_string)
{
Text text(short_text.c_str());
TextS append(short_text.c_str());
CHECK(append.truncated());
text.append(append);
CHECK(text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_append_string_to_self)
{
Compare_Text compare_text(short_text.c_str());
Text text(short_text.c_str());
// Non-overflow.
compare_text.append(compare_text);
text.append(text);
bool is_equal = Equal(compare_text, text);
CHECK(is_equal);
CHECK(!text.truncated());
// Overflow.
compare_text.assign(shorter_text.c_str());
text.assign(shorter_text.c_str());
compare_text.append(compare_text);
compare_text.resize(std::min(compare_text.size(), SIZE));
text.append(text);
is_equal = Equal(compare_text, text);
CHECK(is_equal);
CHECK(text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_append_string_subpos_sublen)
{
@ -1266,6 +1416,17 @@ namespace
CHECK(text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_append_truncated_string_subpos_sublen)
{
Text text(short_text.c_str());
TextS append(short_text.c_str());
CHECK(append.truncated());
text.append(append, 1, 2);
CHECK(text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_append_c_string)
{
@ -3421,5 +3582,73 @@ namespace
is_equal = Equal(text, itext);
CHECK(!is_equal);
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_truncate_over_many_operations)
{
Text text(short_text.c_str());
CHECK(!text.truncated());
text.insert(3, initial_text.c_str());
CHECK(text.truncated());
while (text.size() != 0)
{
text.pop_back();
CHECK(text.truncated());
}
text.clear();
CHECK(!text.truncated());
text.assign(longer_text.c_str());
CHECK(text.truncated());
text.assign(short_text.c_str());
CHECK(!text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_add_from_truncated)
{
Text text1(short_text.c_str());
TextS text2(short_text.c_str());
CHECK(!text1.truncated());
CHECK(text2.truncated());
// text2 has the truncate flag set.
text1 += text2;
CHECK(text1.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_add_to_truncated)
{
Text text1(longer_text.c_str());
Text text2(short_text.c_str());
CHECK(text1.truncated());
CHECK(!text2.truncated());
// Clear text but not the truncate flag.
text1.erase(text1.begin(), text1.end());
// text1 still has the truncate flag set.
text1 += text2;
CHECK(text1.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_clear_truncated)
{
Text text(longer_text.c_str());
CHECK(text.truncated());
text.clear_truncated();
CHECK(!text.truncated());
}
};
}

View File

@ -55,6 +55,7 @@ namespace
typedef std::u32string Compare_Text;
typedef Text::value_type value_t;
typedef etl::u32string<52> TextL;
typedef etl::u32string<4> TextS;
Compare_Text initial_text;
Compare_Text less_text;
@ -242,9 +243,7 @@ namespace
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_constructor_range_excess)
{
Text text;
text.assign(longer_text.begin(), longer_text.end());
Text text(longer_text.begin(), longer_text.end());
bool is_equal = Equal(initial_text, text);
CHECK(is_equal);
@ -282,6 +281,14 @@ namespace
CHECK(text2.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_copy_constructor_from_truncated)
{
Text text(longer_text.c_str());
Text text2(text);
CHECK(text2.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_construct_position_length)
{
@ -360,7 +367,7 @@ namespace
bool is_equal = Equal(text, other_text);
CHECK(is_equal);
CHECK(text.truncated());
CHECK(!other_text.truncated());
CHECK(other_text.truncated());
}
//*************************************************************************
@ -396,7 +403,7 @@ namespace
CHECK(is_equal);
CHECK(text1.truncated());
CHECK(!text2.truncated());
CHECK(text2.truncated());
}
//*************************************************************************
@ -426,7 +433,57 @@ namespace
CHECK(is_equal);
CHECK(text.truncated());
CHECK(!other_text.truncated());
CHECK(other_text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_assignment_from_literal)
{
Text text;
text = STR("Hello World");
bool is_equal = Equal(std::u32string(STR("Hello World")), text);
CHECK(is_equal);
CHECK(!text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_assignment_from_literal_excess)
{
Text text;
text = STR("Hello World There");
bool is_equal = Equal(std::u32string(STR("Hello World")), text);
CHECK(is_equal);
CHECK(text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_assignment_from_literal_via_interface)
{
Text text;
IText& itext = text;
itext = STR("Hello World");
bool is_equal = Equal(std::u32string(STR("Hello World")), itext);
CHECK(is_equal);
CHECK(!itext.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_assignment_from_literal_via_interface_excess)
{
Text text;
IText& itext = text;
itext = STR("Hello World There");
bool is_equal = Equal(std::u32string(STR("Hello World")), itext);
CHECK(is_equal);
CHECK(itext.truncated());
}
//*************************************************************************
@ -716,6 +773,40 @@ namespace
CHECK(!text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_assign_string)
{
Compare_Text compare_input(initial_text.c_str());
Text input(initial_text.c_str());
Compare_Text compare_text;
Text text;
compare_text.assign(compare_input);
text.assign(input);
bool is_equal = Equal(compare_text, text);
CHECK(is_equal);
CHECK(!text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_assign_string_excess)
{
Compare_Text compare_input(initial_text.c_str());
TextL input(longer_text.c_str());
Compare_Text compare_text;
Text text;
compare_text.assign(compare_input);
text.assign(input);
bool is_equal = Equal(compare_text, text);
CHECK(is_equal);
CHECK(text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_assign_pointer)
{
@ -1155,6 +1246,27 @@ namespace
}
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_from_truncated)
{
for (size_t offset = 0; offset <= short_text.size(); ++offset)
{
Compare_Text compare_text(short_text.begin(), short_text.end());
Text text(short_text.begin(), short_text.end());
Text insert(longer_text.begin(), longer_text.end());
insert.erase(insert.begin(), insert.end());
insert.append(insert_text.begin(), insert_text.end());
text.insert(offset, insert);
compare_text.insert(offset, insert_text);
compare_text.resize(std::min(compare_text.size(), SIZE));
bool is_equal = Equal(compare_text, text);
CHECK(is_equal);
CHECK(text.truncated());
}
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen)
{
@ -1224,6 +1336,44 @@ namespace
CHECK(text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_append_truncated_string)
{
Text text(short_text.c_str());
TextS append(short_text.c_str());
CHECK(append.truncated());
text.append(append);
CHECK(text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_append_string_to_self)
{
Compare_Text compare_text(short_text.c_str());
Text text(short_text.c_str());
// Non-overflow.
compare_text.append(compare_text);
text.append(text);
bool is_equal = Equal(compare_text, text);
CHECK(is_equal);
CHECK(!text.truncated());
// Overflow.
compare_text.assign(shorter_text.c_str());
text.assign(shorter_text.c_str());
compare_text.append(compare_text);
compare_text.resize(std::min(compare_text.size(), SIZE));
text.append(text);
is_equal = Equal(compare_text, text);
CHECK(is_equal);
CHECK(text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_append_string_subpos_sublen)
{
@ -1266,6 +1416,17 @@ namespace
CHECK(text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_append_truncated_string_subpos_sublen)
{
Text text(short_text.c_str());
TextS append(short_text.c_str());
CHECK(append.truncated());
text.append(append, 1, 2);
CHECK(text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_append_c_string)
{
@ -3421,5 +3582,73 @@ namespace
is_equal = Equal(text, itext);
CHECK(!is_equal);
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_truncate_over_many_operations)
{
Text text(short_text.c_str());
CHECK(!text.truncated());
text.insert(3, initial_text.c_str());
CHECK(text.truncated());
while (text.size() != 0)
{
text.pop_back();
CHECK(text.truncated());
}
text.clear();
CHECK(!text.truncated());
text.assign(longer_text.c_str());
CHECK(text.truncated());
text.assign(short_text.c_str());
CHECK(!text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_add_from_truncated)
{
Text text1(short_text.c_str());
TextS text2(short_text.c_str());
CHECK(!text1.truncated());
CHECK(text2.truncated());
// text2 has the truncate flag set.
text1 += text2;
CHECK(text1.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_add_to_truncated)
{
Text text1(longer_text.c_str());
Text text2(short_text.c_str());
CHECK(text1.truncated());
CHECK(!text2.truncated());
// Clear text but not the truncate flag.
text1.erase(text1.begin(), text1.end());
// text1 still has the truncate flag set.
text1 += text2;
CHECK(text1.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_clear_truncated)
{
Text text(longer_text.c_str());
CHECK(text.truncated());
text.clear_truncated();
CHECK(!text.truncated());
}
};
}

View File

@ -55,6 +55,7 @@ namespace
typedef std::wstring Compare_Text;
typedef Text::value_type value_t;
typedef etl::wstring<52> TextL;
typedef etl::wstring<4> TextS;
Compare_Text initial_text;
Compare_Text less_text;
@ -242,9 +243,7 @@ namespace
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_constructor_range_excess)
{
Text text;
text.assign(longer_text.begin(), longer_text.end());
Text text(longer_text.begin(), longer_text.end());
bool is_equal = Equal(initial_text, text);
CHECK(is_equal);
@ -282,6 +281,14 @@ namespace
CHECK(text2.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_copy_constructor_from_truncated)
{
Text text(longer_text.c_str());
Text text2(text);
CHECK(text2.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_construct_position_length)
{
@ -360,7 +367,7 @@ namespace
bool is_equal = Equal(text, other_text);
CHECK(is_equal);
CHECK(text.truncated());
CHECK(!other_text.truncated());
CHECK(other_text.truncated());
}
//*************************************************************************
@ -396,7 +403,7 @@ namespace
CHECK(is_equal);
CHECK(text1.truncated());
CHECK(!text2.truncated());
CHECK(text2.truncated());
}
//*************************************************************************
@ -426,7 +433,57 @@ namespace
CHECK(is_equal);
CHECK(text.truncated());
CHECK(!other_text.truncated());
CHECK(other_text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_assignment_from_literal)
{
Text text;
text = STR("Hello World");
bool is_equal = Equal(std::wstring(STR("Hello World")), text);
CHECK(is_equal);
CHECK(!text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_assignment_from_literal_excess)
{
Text text;
text = STR("Hello World There");
bool is_equal = Equal(std::wstring(STR("Hello World")), text);
CHECK(is_equal);
CHECK(text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_assignment_from_literal_via_interface)
{
Text text;
IText& itext = text;
itext = STR("Hello World");
bool is_equal = Equal(std::wstring(STR("Hello World")), itext);
CHECK(is_equal);
CHECK(!itext.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_assignment_from_literal_via_interface_excess)
{
Text text;
IText& itext = text;
itext = STR("Hello World There");
bool is_equal = Equal(std::wstring(STR("Hello World")), itext);
CHECK(is_equal);
CHECK(itext.truncated());
}
//*************************************************************************
@ -716,6 +773,40 @@ namespace
CHECK(!text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_assign_string)
{
Compare_Text compare_input(initial_text.c_str());
Text input(initial_text.c_str());
Compare_Text compare_text;
Text text;
compare_text.assign(compare_input);
text.assign(input);
bool is_equal = Equal(compare_text, text);
CHECK(is_equal);
CHECK(!text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_assign_string_excess)
{
Compare_Text compare_input(initial_text.c_str());
TextL input(longer_text.c_str());
Compare_Text compare_text;
Text text;
compare_text.assign(compare_input);
text.assign(input);
bool is_equal = Equal(compare_text, text);
CHECK(is_equal);
CHECK(text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_assign_pointer)
{
@ -1155,6 +1246,27 @@ namespace
}
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_from_truncated)
{
for (size_t offset = 0; offset <= short_text.size(); ++offset)
{
Compare_Text compare_text(short_text.begin(), short_text.end());
Text text(short_text.begin(), short_text.end());
Text insert(longer_text.begin(), longer_text.end());
insert.erase(insert.begin(), insert.end());
insert.append(insert_text.begin(), insert_text.end());
text.insert(offset, insert);
compare_text.insert(offset, insert_text);
compare_text.resize(std::min(compare_text.size(), SIZE));
bool is_equal = Equal(compare_text, text);
CHECK(is_equal);
CHECK(text.truncated());
}
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen)
{
@ -1224,6 +1336,44 @@ namespace
CHECK(text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_append_truncated_string)
{
Text text(short_text.c_str());
TextS append(short_text.c_str());
CHECK(append.truncated());
text.append(append);
CHECK(text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_append_string_to_self)
{
Compare_Text compare_text(short_text.c_str());
Text text(short_text.c_str());
// Non-overflow.
compare_text.append(compare_text);
text.append(text);
bool is_equal = Equal(compare_text, text);
CHECK(is_equal);
CHECK(!text.truncated());
// Overflow.
compare_text.assign(shorter_text.c_str());
text.assign(shorter_text.c_str());
compare_text.append(compare_text);
compare_text.resize(std::min(compare_text.size(), SIZE));
text.append(text);
is_equal = Equal(compare_text, text);
CHECK(is_equal);
CHECK(text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_append_string_subpos_sublen)
{
@ -1266,6 +1416,17 @@ namespace
CHECK(text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_append_truncated_string_subpos_sublen)
{
Text text(short_text.c_str());
TextS append(short_text.c_str());
CHECK(append.truncated());
text.append(append, 1, 2);
CHECK(text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_append_c_string)
{
@ -3421,5 +3582,73 @@ namespace
is_equal = Equal(text, itext);
CHECK(!is_equal);
}
};
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_truncate_over_many_operations)
{
Text text(short_text.c_str());
CHECK(!text.truncated());
text.insert(3, initial_text.c_str());
CHECK(text.truncated());
while (text.size() != 0)
{
text.pop_back();
CHECK(text.truncated());
}
text.clear();
CHECK(!text.truncated());
text.assign(longer_text.c_str());
CHECK(text.truncated());
text.assign(short_text.c_str());
CHECK(!text.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_add_from_truncated)
{
Text text1(short_text.c_str());
TextS text2(short_text.c_str());
CHECK(!text1.truncated());
CHECK(text2.truncated());
// text2 has the truncate flag set.
text1 += text2;
CHECK(text1.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_add_to_truncated)
{
Text text1(longer_text.c_str());
Text text2(short_text.c_str());
CHECK(text1.truncated());
CHECK(!text2.truncated());
// Clear text but not the truncate flag.
text1.erase(text1.begin(), text1.end());
// text1 still has the truncate flag set.
text1 += text2;
CHECK(text1.truncated());
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_clear_truncated)
{
Text text(longer_text.c_str());
CHECK(text.truncated());
text.clear_truncated();
CHECK(!text.truncated());
}
};
}