mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
Added uninitialized_resize() tests to external buffer containers
This commit is contained in:
parent
9ef9bdeb72
commit
378e5cbd20
@ -825,6 +825,78 @@ namespace
|
||||
#endif
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up)
|
||||
{
|
||||
const size_t INITIAL_SIZE = 5;
|
||||
const size_t NEW_SIZE = 8;
|
||||
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(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)
|
||||
|
||||
@ -825,6 +825,78 @@ namespace
|
||||
#endif
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up)
|
||||
{
|
||||
const size_t INITIAL_SIZE = 5;
|
||||
const size_t NEW_SIZE = 8;
|
||||
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(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)
|
||||
|
||||
@ -825,6 +825,78 @@ namespace
|
||||
#endif
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up)
|
||||
{
|
||||
const size_t INITIAL_SIZE = 5;
|
||||
const size_t NEW_SIZE = 8;
|
||||
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(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)
|
||||
|
||||
@ -825,6 +825,78 @@ namespace
|
||||
#endif
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up)
|
||||
{
|
||||
const size_t INITIAL_SIZE = 5;
|
||||
const size_t NEW_SIZE = 8;
|
||||
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(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)
|
||||
|
||||
@ -337,6 +337,78 @@ namespace
|
||||
CHECK_EQUAL(data.size(), NEW_SIZE);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up)
|
||||
{
|
||||
const size_t INITIAL_SIZE = 5;
|
||||
const size_t NEW_SIZE = 8;
|
||||
|
||||
Data data(INITIAL_SIZE, buffer1, SIZE);
|
||||
|
||||
int* pbegin = &data.front();
|
||||
int* pend = &data.back() + 1;
|
||||
int* pmax = pbegin + data.max_size();
|
||||
|
||||
constexpr int Pattern = 0x12345678;
|
||||
|
||||
// Fill free space with a pattern.
|
||||
std::fill(pend, pmax, Pattern);
|
||||
|
||||
data.uninitialized_resize(NEW_SIZE);
|
||||
|
||||
for (int* p = pbegin; p != pend; ++p)
|
||||
{
|
||||
CHECK_EQUAL(*p, 0);
|
||||
}
|
||||
|
||||
for (int* p = pend; p != pmax; ++p)
|
||||
{
|
||||
CHECK_EQUAL(*p, Pattern);
|
||||
}
|
||||
|
||||
CHECK_EQUAL(data.size(), NEW_SIZE);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up_excess)
|
||||
{
|
||||
const size_t INITIAL_SIZE = 5;
|
||||
const size_t NEW_SIZE = SIZE + 1;
|
||||
|
||||
Data data(INITIAL_SIZE, buffer1, SIZE);
|
||||
|
||||
CHECK_THROW(data.resize(NEW_SIZE), etl::vector_full);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_uninitialized_resize_down)
|
||||
{
|
||||
const size_t INITIAL_SIZE = 5;
|
||||
const size_t NEW_SIZE = 2;
|
||||
|
||||
Data data(INITIAL_SIZE, buffer1, SIZE);
|
||||
|
||||
int* pbegin = &data.front();
|
||||
int* pend = &data.back() + 1;
|
||||
int* pmax = pbegin + data.max_size();
|
||||
|
||||
constexpr int Pattern = 0x12345678;
|
||||
|
||||
// Fill free space with a pattern.
|
||||
std::fill(pend, pmax, Pattern);
|
||||
|
||||
data.uninitialized_resize(NEW_SIZE);
|
||||
|
||||
pend = &data.back() + 1;
|
||||
|
||||
for (int* p = pbegin; p < pend; ++p)
|
||||
{
|
||||
CHECK_EQUAL(*p, 0);
|
||||
}
|
||||
|
||||
CHECK_EQUAL(data.size(), NEW_SIZE);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_empty)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user