tst_ContainerApiSymmetry: make assign_impl() robust w.r.t. overallocation
The parameter passed to reserve() is just a hint. The container implementation is free to choose a larger capacity, and some do (e.g. QList in prepend optimization mode). Fix the test by querying the container for its post-make<>() capacity() and taking a larger-than-expected initial capacity() into account when later re-checking the capacity(). Change-Id: Id8f26f14e8df9d685ca2387ec4a52d74fea7cb9d Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
parent
fb58df3260
commit
3b0536bbe8
@ -783,37 +783,40 @@ void tst_ContainerApiSymmetry::assign_impl() const
|
||||
{
|
||||
// fill version
|
||||
auto c = make<Container>(4);
|
||||
const S oldCapacity = c.capacity();
|
||||
c.assign(4, tData);
|
||||
CHECK(c, tData, c.size(), S(4), c.capacity(), S(4));
|
||||
CHECK(c, tData, c.size(), S(4), c.capacity(), oldCapacity);
|
||||
|
||||
c.assign(8, tData);
|
||||
CHECK(c, tData, c.size(), S(8), c.capacity(), S(8));
|
||||
CHECK(c, tData, c.size(), S(8), c.capacity(), std::max(oldCapacity, S(8)));
|
||||
|
||||
c.assign(0, tData);
|
||||
CHECK(c, tData, c.size(), S(0), c.capacity(), S(8));
|
||||
CHECK(c, tData, c.size(), S(0), c.capacity(), std::max(oldCapacity, S(8)));
|
||||
}
|
||||
{
|
||||
// range version for non input iterator
|
||||
auto c = make<Container>(4);
|
||||
const S oldCapacity = c.capacity();
|
||||
auto iter = make<Container>(1);
|
||||
|
||||
iter.assign(8, tData);
|
||||
c.assign(iter.begin(), iter.end());
|
||||
CHECK(c, tData, c.size(), S(8), c.capacity(), S(8));
|
||||
CHECK(c, tData, c.size(), S(8), c.capacity(), std::max(oldCapacity, S(8)));
|
||||
}
|
||||
{
|
||||
// range version for input iterator
|
||||
auto c = make<Container>(4);
|
||||
const S oldCapacity = c.capacity();
|
||||
|
||||
std::stringstream ss("9 9 ");
|
||||
c.assign(std::istream_iterator<V>{ss}, std::istream_iterator<V>{});
|
||||
CHECK(c, tData, c.size(), S(2), c.capacity(), S(4));
|
||||
CHECK(c, tData, c.size(), S(2), c.capacity(), oldCapacity);
|
||||
|
||||
ss.str("");
|
||||
ss.clear();
|
||||
ss << "9 9 9 9 ";
|
||||
c.assign(std::istream_iterator<V>{ss}, std::istream_iterator<V>{});
|
||||
CHECK(c, tData, c.size(), S(4), c.capacity(), S(4));
|
||||
CHECK(c, tData, c.size(), S(4), c.capacity(), oldCapacity);
|
||||
|
||||
ss.str("");
|
||||
ss.clear();
|
||||
@ -826,9 +829,10 @@ void tst_ContainerApiSymmetry::assign_impl() const
|
||||
{
|
||||
// initializer-list version
|
||||
auto c = make<Container>(4);
|
||||
const S oldCapacity = c.capacity();
|
||||
std::initializer_list<V> list = {tData, tData, tData};
|
||||
c.assign(list);
|
||||
CHECK(c, tData, c.size(), S(3), c.capacity(), S(4));
|
||||
CHECK(c, tData, c.size(), S(3), c.capacity(), oldCapacity);
|
||||
}
|
||||
|
||||
#undef CHECK
|
||||
|
Loading…
Reference in New Issue
Block a user