text
stringlengths
0
2.2M
Text::pointer pbegin = &text.front();
Text::pointer pend = &text.back() + 1;
Text::pointer pmax = pbegin + text.max_size();
// Fill free space with a pattern.
std::fill(pend, pmax, FILL_VALUE);
text.uninitialized_resize(NEW_SIZE);
std::array<value_t, NEW_SIZE> compare_text;
compare_text.fill(FILL_VALUE);
std::fill(compare_text.begin(), compare_text.begin() + INITIAL_SIZE, INITIAL_VALUE);
bool is_equal = Equal(compare_text, text);
CHECK(is_equal);
CHECK_EQUAL(text.size(), NEW_SIZE);
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up_excess)
{
const size_t INITIAL_SIZE = 5;
const size_t NEW_SIZE = SIZE + 1;
TextBuffer buffer;
Text text(INITIAL_SIZE, STR('A'), buffer.data(), buffer.size());
text.uninitialized_resize(NEW_SIZE);
CHECK_EQUAL(text.size(), SIZE);
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_uninitialized_resize_down)
{
const size_t INITIAL_SIZE = 5;
const size_t NEW_SIZE = 2;
const value_t INITIAL_VALUE = STR('A');
const value_t FILL_VALUE = STR('B');
TextBuffer buffer;
Text text(INITIAL_SIZE, INITIAL_VALUE, buffer.data(), buffer.size());
Text::pointer pbegin = &text.front();
Text::pointer pend = &text.back() + 1;
Text::pointer pmax = pbegin + text.max_size();
// Fill free space with a pattern.
std::fill(pend, pmax, FILL_VALUE);
text.uninitialized_resize(NEW_SIZE);
std::array<value_t, NEW_SIZE> compare_text;
compare_text.fill(INITIAL_VALUE);
bool is_equal = Equal(compare_text, text);
CHECK(is_equal);
CHECK_EQUAL(text.size(), NEW_SIZE);
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_empty_full)
{
TextBuffer buffer;
Text text(buffer.data(), buffer.size());
text.resize(text.max_size(), STR('A'));
CHECK(!text.empty());
#if ETL_STRING_TRUNCATION_CHECKS_ENABLED
CHECK(!text.is_truncated());
#endif
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_empty_half)
{
TextBuffer buffer;
Text text(buffer.data(), buffer.size());
text.resize(text.max_size() / 2, STR('A'));
CHECK(!text.empty());
#if ETL_STRING_TRUNCATION_CHECKS_ENABLED
CHECK(!text.is_truncated());
#endif
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_empty_empty)
{
TextBuffer buffer;
Text text(buffer.data(), buffer.size());
CHECK(text.empty());
#if ETL_STRING_TRUNCATION_CHECKS_ENABLED
CHECK(!text.is_truncated());
#endif
}