33 #include <QScopedValueRollback>
37 #if __cplusplus >= 202002L && (!defined(_GLIBCXX_RELEASE) || _GLIBCXX_RELEASE >= 11)
38 # if __has_include(<concepts>)
40 # if defined(__cpp_lib_concepts) && __cpp_lib_concepts >= 202002L
45 # if __has_include(<ranges>)
47 # if defined(__cpp_lib_ranges)
48 namespace rns = std::ranges;
50 static_assert(rns::contiguous_range<
QList<int>>);
51 static_assert(rns::contiguous_range<
const QList<int>>);
69 check(
other.state, Constructed);
77 check(
other.state, Constructed);
84 check(state, Constructed);
92 check(state, Constructed);
93 check(
other.state, Constructed);
99 check(state, Constructed);
100 check(
other.state, Constructed);
107 check(state, Constructed);
108 check(
other.state, Constructed);
111 other.that =
nullptr;
116 return that ==
other;
123 enum State { Constructed = 106, Destructed = 110 };
126 static void check(
const State state1,
const State state2)
160 counter.fetchAndAddRelaxed(-1);
162 QVERIFY(heapData.use_count() > 0);
193 std::shared_ptr<int> heapData = std::shared_ptr<int>(
new int(42));
195 enum State { Constructed = 106, Destructed = 110 };
198 static void check(
const Custom *
c)
202 QCOMPARE(
int(
c->state),
int(Constructed));
229 #define TST_QLIST_CHECK_LEAKS(Type) \
230 LeakChecker<Type> checker; \
238 void constructors_empty()
const;
239 void constructors_emptyReserveZero()
const;
240 void constructors_emptyReserve()
const;
241 void constructors_reserveAndInitialize()
const;
242 void copyConstructorInt()
const { copyConstructor<int>(); }
243 void copyConstructorMovable()
const { copyConstructor<Movable>(); }
244 void copyConstructorCustom()
const { copyConstructor<Custom>(); }
245 void assignmentInt()
const { testAssignment<int>(); }
246 void assignmentMovable()
const { testAssignment<Movable>(); }
247 void assignmentCustom()
const { testAssignment<Custom>(); }
248 void assignFromInitializerListInt()
const { assignFromInitializerList<int>(); }
249 void assignFromInitializerListMovable()
const { assignFromInitializerList<Movable>(); }
250 void assignFromInitializerListCustom()
const { assignFromInitializerList<Custom>(); }
251 void addInt()
const { add<int>(); }
252 void addMovable()
const { add<Movable>(); }
253 void addCustom()
const { add<Custom>(); }
254 void appendInt()
const { append<int>(); }
255 void appendMovable()
const { append<Movable>(); }
256 void appendCustom()
const { append<Custom>(); }
257 void appendRvalue()
const;
258 void appendList()
const;
260 void capacityInt()
const { capacity<int>(); }
261 void capacityMovable()
const { capacity<Movable>(); }
262 void capacityCustom()
const { capacity<Custom>(); }
263 void clearInt()
const { clear<int>(); }
264 void clearMovable()
const { clear<Movable>(); }
265 void clearCustom()
const { clear<Custom>(); }
266 void constData()
const;
267 void constFirst()
const;
268 void constLast()
const;
269 void contains()
const;
273 void cpp17ctad()
const;
275 void emptyInt()
const { empty<int>(); }
276 void emptyMovable()
const { empty<Movable>(); }
277 void emptyCustom()
const { empty<Custom>(); }
278 void endsWith()
const;
279 void eraseEmptyInt()
const { eraseEmpty<int>(); }
280 void eraseEmptyMovable()
const { eraseEmpty<Movable>(); }
281 void eraseEmptyCustom()
const { eraseEmpty<Custom>(); }
282 void eraseEmptyReservedInt()
const { eraseEmptyReserved<int>(); }
283 void eraseEmptyReservedMovable()
const { eraseEmptyReserved<Movable>(); }
284 void eraseEmptyReservedCustom()
const { eraseEmptyReserved<Custom>(); }
285 void eraseInt()
const { erase<int>(
false); }
286 void eraseIntShared()
const { erase<int>(
true); }
287 void eraseMovable()
const { erase<Movable>(
false); }
288 void eraseMovableShared()
const { erase<Movable>(
true); }
289 void eraseCustom()
const { erase<Custom>(
false); }
290 void eraseCustomShared()
const { erase<Custom>(
true); }
291 void eraseReservedInt()
const { eraseReserved<int>(); }
292 void eraseReservedMovable()
const { eraseReserved<Movable>(); }
293 void eraseReservedCustom()
const { eraseReserved<Custom>(); }
294 void fillInt()
const { fill<int>(); }
295 void fillMovable()
const { fill<Movable>(); }
296 void fillCustom()
const { fill<Custom>(); }
297 void fillDetachInt()
const { fillDetach<int>(); }
298 void fillDetachMovable()
const { fillDetach<Movable>(); }
299 void fillDetachCustom()
const { fillDetach<Custom>(); }
301 void fromListInt()
const { fromList<int>(); }
302 void fromListMovable()
const { fromList<Movable>(); }
303 void fromListCustom()
const { fromList<Custom>(); }
304 void indexOf()
const;
305 void insertInt()
const { insert<int>(); }
306 void insertMovable()
const { insert<Movable>(); }
307 void insertCustom()
const { insert<Custom>(); }
308 void insertZeroCount_data();
309 void insertZeroCount()
const;
310 void isEmpty()
const;
312 void lastIndexOf()
const;
315 void moveInt()
const { move<int>(); }
316 void moveMovable()
const { move<Movable>(); }
317 void moveCustom()
const { move<Custom>(); }
318 void prependInt()
const { prepend<int>(); }
319 void prependMovable()
const { prepend<Movable>(); }
320 void prependCustom()
const { prepend<Custom>(); }
321 void prependRvalue()
const;
322 void qhashInt()
const { qhash<int>(); }
323 void qhashMovable()
const { qhash<Movable>(); }
324 void qhashCustom()
const { qhash<Custom>(); }
325 void removeAllWithAlias()
const;
326 void removeInt()
const { remove<int>(); }
327 void removeMovable()
const { remove<Movable>(); }
328 void removeCustom()
const { remove<Custom>(); }
329 void removeFirstLast()
const;
330 void resizePOD_data()
const;
331 void resizePOD()
const;
332 void resizeComplexMovable_data()
const;
333 void resizeComplexMovable()
const;
334 void resizeComplex_data()
const;
335 void resizeComplex()
const;
336 void resizeCtorAndDtor()
const;
337 void resizeToZero()
const;
338 void resizeToTheSameSize_data();
339 void resizeToTheSameSize()
const;
340 void iterators()
const;
341 void constIterators()
const;
342 void reverseIterators()
const;
346 void startsWith()
const;
347 void swapInt()
const { swap<int>(); }
348 void swapMovable()
const { swap<Movable>(); }
349 void swapCustom()
const { swap<Custom>(); }
351 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
352 void fromStdVector()
const;
353 void toStdVector()
const;
356 void testOperators()
const;
359 void initializeListInt() { initializeList<int>(); }
360 void initializeListMovable() { initializeList<Movable>(); }
361 void initializeListCustom() { initializeList<Custom>(); }
362 void const_shared_null();
363 void detachInt()
const { detach<int>(); }
364 void detachMovable()
const { detach<Movable>(); }
365 void detachCustom()
const { detach<Custom>(); }
366 void detachThreadSafetyInt()
const;
367 void detachThreadSafetyMovable()
const;
368 void detachThreadSafetyCustom()
const;
369 void insertMove()
const;
370 void swapItemsAt()
const;
371 void emplaceInt() { emplaceImpl<int>(); }
372 void emplaceCustom() { emplaceImpl<Custom>(); }
373 void emplaceMovable() { emplaceImpl<Movable>(); }
374 void emplaceConsistentWithStdVectorInt() { emplaceConsistentWithStdVectorImpl<int>(); }
375 void emplaceConsistentWithStdVectorCustom() { emplaceConsistentWithStdVectorImpl<Custom>(); }
376 void emplaceConsistentWithStdVectorMovable() { emplaceConsistentWithStdVectorImpl<Movable>(); }
377 void emplaceConsistentWithStdVectorQString() { emplaceConsistentWithStdVectorImpl<QString>(); }
378 void emplaceReturnsIterator();
379 void emplaceFront()
const;
380 void emplaceFrontReturnsRef()
const;
382 void emplaceBackReturnsRef();
383 void emplaceWithElementFromTheSameContainer();
384 void emplaceWithElementFromTheSameContainer_data();
385 void replaceInt()
const { replace<int>(); }
386 void replaceCustom()
const { replace<Custom>(); }
387 void replaceMovable()
const { replace<Movable>(); }
388 void fromReadOnlyData()
const;
389 void reallocateCustomAlignedType_qtbug90359()
const;
390 void reinsertToBeginInt_qtbug91360()
const { reinsertToBegin<int>(); }
391 void reinsertToBeginMovable_qtbug91360()
const { reinsertToBegin<Movable>(); }
392 void reinsertToBeginCustom_qtbug91360()
const { reinsertToBegin<Custom>(); }
393 void reinsertToEndInt_qtbug91360()
const { reinsertToEnd<int>(); }
394 void reinsertToEndMovable_qtbug91360()
const { reinsertToEnd<Movable>(); }
395 void reinsertToEndCustom_qtbug91360()
const { reinsertToEnd<Custom>(); }
396 void reinsertRangeToEndInt_qtbug91360()
const { reinsertRangeToEnd<int>(); }
397 void reinsertRangeToEndMovable_qtbug91360()
const { reinsertRangeToEnd<Movable>(); }
398 void reinsertRangeToEndCustom_qtbug91360()
const { reinsertRangeToEnd<Custom>(); }
400 void stability_reserveInt()
const { stability_reserve<int>(); }
401 void stability_reserveMovable()
const { stability_reserve<Movable>(); }
402 void stability_reserveCustom()
const { stability_reserve<Custom>(); }
403 void stability_eraseInt()
const { stability_erase<int>(); }
404 void stability_eraseMovable()
const { stability_erase<Movable>(); }
405 void stability_eraseCustom()
const { stability_erase<Custom>(); }
406 void stability_appendInt()
const { stability_append<int>(); }
407 void stability_appendMovable()
const { stability_append<Movable>(); }
408 void stability_appendCustom()
const { stability_append<Custom>(); }
409 void stability_insertElementInt()
const { stability_insertElement<int>(); }
410 void stability_insertElementMovable()
const { stability_insertElement<Movable>(); }
411 void stability_insertElementCustom()
const { stability_insertElement<Custom>(); }
412 void stability_emplaceInt()
const { stability_emplace<int>(); }
413 void stability_emplaceMovable()
const { stability_emplace<Movable>(); }
414 void stability_emplaceCustom()
const { stability_emplace<Custom>(); }
415 void stability_resizeInt()
const { stability_resize<int>(); }
416 void stability_resizeMovable()
const { stability_resize<Movable>(); }
417 void stability_resizeCustom()
const { stability_resize<Custom>(); }
420 template<
typename T>
void copyConstructor()
const;
421 template<
typename T>
void testAssignment()
const;
422 template<
typename T>
void add()
const;
423 template<
typename T>
void append()
const;
424 template<
typename T>
void assignFromInitializerList()
const;
425 template<
typename T>
void capacity()
const;
426 template<
typename T>
void clear()
const;
427 template<
typename T>
void count()
const;
428 template<
typename T>
void empty()
const;
429 template<
typename T>
void eraseEmpty()
const;
430 template<
typename T>
void eraseEmptyReserved()
const;
431 template<
typename T>
void erase(
bool shared)
const;
432 template<
typename T>
void eraseReserved()
const;
433 template<
typename T>
void fill()
const;
434 template<
typename T>
void fillDetach()
const;
435 template<
typename T>
void fromList()
const;
436 template<
typename T>
void insert()
const;
437 template<
typename T>
void qhash()
const;
438 template<
typename T>
void move()
const;
439 template<
typename T>
void prepend()
const;
440 template<
typename T>
void remove()
const;
441 template<
typename T>
void size()
const;
442 template<
typename T>
void swap()
const;
443 template<
typename T>
void initializeList();
444 template<
typename T>
void detach()
const;
445 template<
typename T>
void detachThreadSafety()
const;
446 template<
typename T>
void emplaceImpl()
const;
447 template<
typename T>
void emplaceConsistentWithStdVectorImpl()
const;
448 template<
typename T>
void replace()
const;
449 template<
typename T,
typename Reinsert>
450 void reinsert(Reinsert
op)
const;
452 void reinsertToBegin()
const
460 void reinsertToEnd()
const
468 void reinsertRangeToEnd()
const
476 void stability_reserve()
const;
478 void stability_erase()
const;
480 void stability_append()
const;
481 template<
typename T,
typename Insert>
482 void stability_insert(Insert
op)
const;
484 void stability_resize()
const;
487 void stability_insertElement()
const
493 void stability_emplace()
const
528 #define T_FOO SimpleValue<T>::at(0)
529 #define T_BAR SimpleValue<T>::at(1)
530 #define T_BAZ SimpleValue<T>::at(2)
531 #define T_CAT SimpleValue<T>::at(3)
532 #define T_DOG SimpleValue<T>::at(4)
533 #define T_BLAH SimpleValue<T>::at(5)
536 template<
typename It>
547 void tst_QList::constructors_empty()
const
554 void tst_QList::constructors_emptyReserveZero()
const
561 void tst_QList::constructors_emptyReserve()
const
565 QVERIFY(myInt.capacity() == 5);
567 QVERIFY(myMovable.capacity() == 5);
569 QVERIFY(myCustom.capacity() == 4);
572 void tst_QList::constructors_reserveAndInitialize()
const
577 QVERIFY(myInt.capacity() == 5);
578 foreach (
int meaningoflife, myInt) {
583 QVERIFY(myString.capacity() == 5);
585 foreach (
QString meaningoflife, myString) {
590 QVERIFY(myCustom.capacity() == 5);
592 foreach (
Custom meaningoflife, myCustom) {
598 void tst_QList::copyConstructor()
const
613 v1 << value1 << value2 << value3 << value4;
620 void tst_QList::testAssignment()
const
640 const void *
const data1 =
v1.constData();
641 const void *
const data2 =
v2.constData();
653 void tst_QList::assignFromInitializerList()
const
670 void tst_QList::add()
const
677 QVERIFY((empty1 + empty2).isEmpty());
703 void tst_QList::append()
const
741 combined << 1 << 2 << 3 << 4 << 5 << 6;
751 myvec.
append(otherVec.cbegin(), otherVec.cbegin() + 3);
761 emptyVec.
append(otherEmptyVec);
778 void tst_QList::appendRvalue()
const
783 v.append(std::move(
world));
790 myvec.
append(std::move(test));
832 return lhs.
i ==
rhs.i;
845 char *
str =
new char[5];
852 void tst_QList::appendList()
const
861 QList<int> expected = { 1, 2, 3, 4, 5, 6, 7, 8 };
864 QList<int> doubleExpected = { 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8 };
925 v1.append(std::move(
v3));
955 v1.append(std::move(v5_2));
957 QList<ConstructionCounted> expectedTwelve = { 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4 };
969 v6 << (QList<ConstructionCounted>() << 1 << 2);
970 v6 << (QList<ConstructionCounted>() << 3 << 4);
989 void tst_QList::at()
const
992 myvec <<
"foo" <<
"bar" <<
"baz";
1015 template<
typename T>
1016 void tst_QList::capacity()
const
1048 template<
typename T>
1049 void tst_QList::clear()
const
1059 const auto oldCapacity = myvec.
capacity();
1066 void tst_QList::constData()
const
1068 int arr[] = { 42, 43, 44 };
1073 myvec << 42 << 43 << 44;
1075 QCOMPARE(memcmp(myvec.
constData(),
reinterpret_cast<const int *
>(&arr),
sizeof(
int) * 3), 0);
1078 void tst_QList::contains()
const
1085 myvec <<
"aaa" <<
"bbb" <<
"ccc";
1097 template<
typename T>
1098 void tst_QList::count()
const
1144 void tst_QList::cpp17ctad()
const
1146 #define QVERIFY_IS_VECTOR_OF(obj, Type) \
1147 QVERIFY2((std::is_same<decltype(obj), QList<Type>>::value), \
1148 QMetaType::fromType<decltype(obj)::value_type>().name())
1149 #define CHECK(Type, One, Two, Three) \
1151 const Type v[] = {One, Two, Three}; \
1152 QList v1 = {One, Two, Three}; \
1153 QVERIFY_IS_VECTOR_OF(v1, Type); \
1154 QList v2(v1.begin(), v1.end()); \
1155 QVERIFY_IS_VECTOR_OF(v2, Type); \
1156 QList v3(std::begin(v), std::end(v)); \
1157 QVERIFY_IS_VECTOR_OF(v3, Type); \
1160 CHECK(
int, 1, 2, 3);
1161 CHECK(
double, 1.0, 2.0, 3.0);
1163 #undef QVERIFY_IS_VECTOR_OF
1167 void tst_QList::data()
const
1172 myvec << 42 << 43 << 44;
1178 *(myvec.
data() + 1) = 69;
1183 int arr[] = { 42, 69, 44 };
1184 QCOMPARE(memcmp(myvec.
data(),
reinterpret_cast<int *
>(&arr),
sizeof(
int) * 3), 0);
1187 QCOMPARE(memcmp(constVec.
data(),
reinterpret_cast<const int *
>(&arr),
sizeof(
int) * 3), 0);
1191 template<
typename T>
1192 void tst_QList::empty()
const
1211 void tst_QList::endsWith()
const
1231 template<
typename T>
1232 void tst_QList::eraseEmpty()
const
1237 v.erase(
v.begin(),
v.end());
1241 template<
typename T>
1242 void tst_QList::eraseEmptyReserved()
const
1248 v.erase(
v.begin(),
v.end());
1252 template<
typename T>
1279 template<
typename T>
1280 void tst_QList::erase(
bool shared)
const
1293 for (
int i = 0;
i < 11;
i++)
1295 v.erase(
v.begin(),
v.end());
1306 for (
int i = 1;
i < 11;
i++)
1308 v.erase(
v.begin() + 1,
v.end());
1317 v.erase(
v.begin(),
v.end() - 1);
1328 for (
int i = 0;
i < 5;
i++)
1330 for (
int i = 5;
i < 11;
i++)
1332 v.erase(
v.begin() + 1,
v.end() - 1);
1341 template<
typename T>
1342 void tst_QList::eraseReserved()
const
1351 v.erase(
v.begin(),
v.end());
1357 v.erase(
v.begin() + 1);
1359 v.erase(
v.begin() + 1,
v.end());
1365 v.erase(
v.begin(),
v.end() - 1);
1371 v.erase(
v.begin() + 5);
1373 v.erase(
v.begin() + 1,
v.end() - 1);
1378 template<
typename T>
1379 void tst_QList::fill()
const
1409 template<
typename T>
1410 void tst_QList::fillDetach()
const
1451 void tst_QList::first()
const
1454 myvec << 69 << 42 << 3;
1478 void tst_QList::constFirst()
const
1481 myvec << 69 << 42 << 3;
1545 template<
typename T>
1546 void tst_QList::fromList()
const
1561 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
1562 void tst_QList::fromStdVector()
const
1565 std::vector<QString> svec;
1577 void tst_QList::indexOf()
const
1585 myvec <<
"A" <<
"B" <<
"C" <<
"B" <<
"A";
1606 template <
typename T>
1607 void tst_QList::insert()
const
1620 myvec << tA << tB << tC;
1657 << tA << tB << tC << tT);
1663 myvec.
insert(0, 1, myvec[5]);
1664 myvec2.
insert(0, 1, myvec2[5]);
1666 << tA << tB << tC << tT);
1672 << tA << tB << tC << tT);
1707 auto it = myvec.
insert(0, std::move(test));
1722 void tst_QList::insertZeroCount_data()
1724 QTest::addColumn<int>(
"pos");
1729 void tst_QList::insertZeroCount()
const
1734 x.insert(
pos, 0, 1);
1738 y.insert(
pos, 0, 2);
1742 void tst_QList::isEmpty()
const
1759 void tst_QList::last()
const
1762 myvec <<
"A" <<
"B" <<
"C";
1785 void tst_QList::constLast()
const
1788 myvec << 69 << 42 << 3;
1851 void tst_QList::lastIndexOf()
const
1859 myvec <<
"A" <<
"B" <<
"C" <<
"B" <<
"A";
1879 void tst_QList::mid()
const
1888 list <<
"foo" <<
"bar" <<
"baz" <<
"bak" <<
"buck" <<
"hello" <<
"kitty";
1896 void tst_QList::sliced()
const
1899 list <<
"foo" <<
"bar" <<
"baz" <<
"bak" <<
"buck" <<
"hello" <<
"kitty";
1912 template <
typename T>
1913 void tst_QList::qhash()
const
1924 template <
typename T>
1925 void tst_QList::move()
const
1945 template<
typename T>
1946 void tst_QList::prepend()
const
1964 myvec << val1 << val2 << val3;
1991 void tst_QList::prependRvalue()
const
2006 void tst_QList::removeAllWithAlias()
const
2009 strings <<
"One" <<
"Two" <<
"Three" <<
"One" ;
2013 template<
typename T>
2014 void tst_QList::remove()
const
2031 myvec << val1 << val2 << val3 << val4;
2032 myvec << val1 << val2 << val3 << val4;
2033 myvec << val1 << val2 << val3 << val4;
2036 QCOMPARE(myvec,
QList<T>({ val1, val3, val4, val1, val2, val3, val4, val1, val2, val3, val4 }));
2038 QCOMPARE(myvec,
QList<T>({ val1, val3, val4, val1, val2, val3, val1, val2, val3, val4 }));
2043 QCOMPARE(myvec,
QList<T>({ val1, val3, val4, val1, val3, val1, val2, val3, val4 }));
2053 QCOMPARE(myvecCopy,
QList<T>({ val1, val3, val4, val1, val3, val1, val2, val3, val4 }));
2084 void tst_QList::removeFirstLast()
const
2102 int n1 =
t2.takeLast();
2107 n1 =
t2.takeFirst();
2126 v[0].other = &(
v[1]);
2127 v[1].other = &(
v[0]);
2168 void tst_QList::resizePOD_data()
const
2170 QTest::addColumn<QList<int> >(
"vector");
2171 QTest::addColumn<int>(
"size");
2184 nonEmpty << 0 << 1 << 2 << 3 << 4;
2185 nonEmptyReserved << 0 << 1 << 2 << 3 << 4 << 5 << 6;
2195 QTest::newRow(
"nonEmptyReserved") << nonEmptyReserved << 10;
2198 void tst_QList::resizePOD()
const
2211 for (
int i = oldSize;
i <
size; ++
i)
2221 void tst_QList::resizeComplexMovable_data()
const
2223 QTest::addColumn<QList<Movable> >(
"vector");
2224 QTest::addColumn<int>(
"size");
2237 nonEmpty <<
'0' <<
'1' <<
'2' <<
'3' <<
'4';
2238 nonEmptyReserved <<
'0' <<
'1' <<
'2' <<
'3' <<
'4' <<
'5' <<
'6';
2248 QTest::newRow(
"nonEmptyReserved") << nonEmptyReserved << 10;
2251 void tst_QList::resizeComplexMovable()
const
2265 for (
int i = oldSize;
i <
size; ++
i)
2277 void tst_QList::resizeComplex_data()
const
2279 QTest::addColumn<QList<Custom> >(
"vector");
2280 QTest::addColumn<int>(
"size");
2293 nonEmpty <<
'0' <<
'1' <<
'2' <<
'3' <<
'4';
2294 nonEmptyReserved <<
'0' <<
'1' <<
'2' <<
'3' <<
'4' <<
'5' <<
'6';
2304 QTest::newRow(
"nonEmptyReserved") << nonEmptyReserved << 10;
2307 void tst_QList::resizeComplex()
const
2320 for (
int i = oldSize;
i <
size; ++
i)
2333 void tst_QList::resizeCtorAndDtor()
const
2345 nonEmpty <<
'0' <<
'1' <<
'2' <<
'3' <<
'4';
2346 nonEmptyReserved <<
'0' <<
'1' <<
'2' <<
'3' <<
'4' <<
'5' <<
'6';
2355 nonEmptyReserved.
resize(2);
2360 void tst_QList::resizeToZero()
const
2376 void tst_QList::resizeToTheSameSize_data()
2378 QTest::addColumn<QList<int>>(
"x");
2383 void tst_QList::resizeToTheSameSize()
const
2392 void tst_QList::iterators()
const
2405 auto it =
v.begin();
2409 std::advance(
it, 7);
2424 std::advance(
it, -3);
2444 it =
it + ptrdiff_t(1);
2459 it =
it - ptrdiff_t(1);
2505 auto rit =
v.rbegin();
2512 std::advance(rit, 5);
2524 std::advance(rit, -4);
2537 void tst_QList::constIterators()
const
2548 const QList<int> v { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
2552 auto it =
v.cbegin();
2556 std::advance(
it, 7);
2571 std::advance(
it, -3);
2591 it =
it + ptrdiff_t(1);
2606 it =
it - ptrdiff_t(1);
2648 auto rit =
v.crbegin();
2651 std::advance(rit, 5);
2663 std::advance(rit, -4);
2676 void tst_QList::reverseIterators()
const
2679 v << 1 << 2 << 3 << 4;
2681 std::reverse(vr.
begin(), vr.
end());
2691 template<
typename T>
2692 void tst_QList::size()
const
2723 void tst_QList::startsWith()
const
2743 template<
typename T>
2744 void tst_QList::swap()
const
2755 v1 << val1 << val2 << val3;
2756 v2 << val4 << val5 << val6;
2763 void tst_QList::toList()
const
2766 myvec <<
"A" <<
"B" <<
"C";
2773 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
2774 void tst_QList::toStdVector()
const
2777 myvec <<
"A" <<
"B" <<
"C";
2779 std::vector<QString> svec = myvec.toStdVector();
2788 void tst_QList::value()
const
2796 myvec <<
"A" <<
"B" <<
"C";
2817 void tst_QList::testOperators()
const
2820 myvec <<
"A" <<
"B" <<
"C";
2822 myvectwo <<
"D" <<
"E" <<
"F";
2824 combined <<
"A" <<
"B" <<
"C" <<
"D" <<
"E" <<
"F";
2830 QCOMPARE(myvec + myvectwo, combined);
2850 QVERIFY(!(myvec >= combined));
2879 void tst_QList::reserve()
2896 void tst_QList::reserveZero()
2922 template<
typename T>
2923 void tst_QList::initializeList()
2945 void tst_QList::const_shared_null()
2951 template<
typename T>
2952 void tst_QList::detach()
const
3022 for (
int i = 0;
i <
v.size(); ++
i)
3032 for (
int i = 0;
i <
v.size(); ++
i)
3045 for (
int i = 0;
i <
v.size(); ++
i)
3061 template<
typename T>
3062 void tst_QList::detachThreadSafety()
const
3066 static const uint threadsCount = 5;
3071 QList<T> copy(*detachThreadSafetyData<T>()->loadRelaxed());
3073 detachThreadSafetyLock.
release();
3074 detachThreadSafetyLock.
acquire(100);
3079 for (
uint i = 0;
i < threadsCount; ++
i)
3082 detachThreadSafetyLock.
acquire(threadsCount);
3085 delete detachThreadSafetyData<T>()->fetchAndStoreOrdered(0);
3088 detachThreadSafetyLock.
release(threadsCount * 100);
3091 for (
uint i = 0;
i < threadsCount; ++
i)
3095 void tst_QList::detachThreadSafetyInt()
const
3097 for (
uint i = 0;
i < 128; ++
i)
3098 detachThreadSafety<int>();
3101 void tst_QList::detachThreadSafetyMovable()
const
3104 for (
uint i = 0;
i < 128; ++
i) {
3105 detachThreadSafety<Movable>();
3110 void tst_QList::detachThreadSafetyCustom()
const
3113 for (
uint i = 0;
i < 128; ++
i) {
3114 detachThreadSafety<Custom>();
3119 void tst_QList::insertMove()
const
3133 vec.append(std::move(m3));
3136 vec.push_back(std::move(m4));
3140 vec.prepend(std::move(m1));
3145 vec.insert(1, std::move(m2));
3151 vec += std::move(m5);
3158 vec << std::move(m6);
3166 vec.push_front(std::move(m0));
3181 void tst_QList::swapItemsAt()
const
3184 v << 0 << 1 << 2 << 3;
3186 v.swapItemsAt(0, 2);
3198 void tst_QList::emplaceReturnsIterator()
3202 vec.emplace(0,
'k')->i =
'p';
3207 void tst_QList::emplaceFront()
const
3212 vec.emplaceFront(
'b');
3215 vec.emplaceFront(
'a');
3221 void tst_QList::emplaceFrontReturnsRef()
const
3227 vec.emplaceFront(
'b').i =
'a';
3232 void tst_QList::emplaceBack()
3238 vec.emplaceBack(
'k');
3243 void tst_QList::emplaceBackReturnsRef()
3247 vec.emplaceBack(
'k').i =
'p';
3252 void tst_QList::emplaceWithElementFromTheSameContainer()
3262 vec.emplace(insertPos,
vec[elementPos]);
3264 vec.emplace(insertPos, std::move(
vec[elementPos]));
3269 void tst_QList::emplaceWithElementFromTheSameContainer_data()
3271 QTest::addColumn<int>(
"elementPos");
3272 QTest::addColumn<int>(
"insertPos");
3273 QTest::addColumn<bool>(
"doCopy");
3275 for (
int i = 0;
i < 2; ++
i) {
3276 const bool doCopy =
i == 0;
3277 const char *opName = doCopy ?
"copy" :
"move";
3279 QTest::addRow(
"%s: begin -> end" , opName) << 0 << 5 << doCopy;
3280 QTest::addRow(
"%s: begin -> middle", opName) << 0 << 2 << doCopy;
3281 QTest::addRow(
"%s: middle -> begin" , opName) << 2 << 0 << doCopy;
3282 QTest::addRow(
"%s: middle -> end" , opName) << 2 << 5 << doCopy;
3283 QTest::addRow(
"%s: end -> middle", opName) << 4 << 2 << doCopy;
3284 QTest::addRow(
"%s: end -> begin" , opName) << 4 << 0 << doCopy;
3288 template<
typename T>
3289 void tst_QList::emplaceImpl()
const
3295 vec.emplace(2,
'k');
3300 vec.emplace(
vec.end(),
T(
'f'));
3308 vec.emplace(
vec.begin(),
'a');
3314 vec.emplace(0,
'a');
3320 template <
typename T>
3321 void tst_QList::replace()
const
3331 vec.replace(2, std::move(
f));
3336 static void vecEq(
const QList<T> &qVec,
const std::vector<T> &stdVec)
3339 QVERIFY(std::equal(qVec.
begin(), qVec.
end(), stdVec.begin(), stdVec.end()));
3343 static void squeezeVec(
QList<T> &qVec, std::vector<T> &stdVec)
3346 stdVec.shrink_to_fit();
3349 template<
typename T>
3350 void tst_QList::emplaceConsistentWithStdVectorImpl()
const
3356 if constexpr (std::is_same_v<QString, T>) {
3365 vecEq(qVec, stdVec);
3368 stdVec.emplace_back(
convert(
'f'));
3369 vecEq(qVec, stdVec);
3372 stdVec.emplace(stdVec.begin() + 3,
convert(
'g'));
3373 vecEq(qVec, stdVec);
3379 stdVec.emplace_back(std::move(
t = std::move(stdVec[0])));
3380 vecEq(qVec, stdVec);
3382 squeezeVec(qVec, stdVec);
3385 stdVec.emplace_back(std::move(
t = std::move(stdVec[1])));
3386 vecEq(qVec, stdVec);
3388 squeezeVec(qVec, stdVec);
3390 qVec.
emplace(3, std::move(qVec[5]));
3391 stdVec.emplace(stdVec.begin() + 3, std::move(
t = std::move(stdVec[5])));
3393 vecEq(qVec, stdVec);
3396 stdVec.emplace_back((
t = stdVec[3]));
3397 vecEq(qVec, stdVec);
3399 squeezeVec(qVec, stdVec);
3402 stdVec.emplace_back((
t = stdVec[4]));
3403 vecEq(qVec, stdVec);
3405 squeezeVec(qVec, stdVec);
3408 stdVec.emplace(stdVec.begin() + 5, (
t = stdVec[7]));
3409 vecEq(qVec, stdVec);
3412 void tst_QList::fromReadOnlyData()
const
3420 for (
int i = 0;
i < 10; ++
i)
3428 for (
int i = 0;
i < 10; ++
i)
3434 const char data[] =
"ABCDEFGHIJ";
3442 QCOMPARE((
void*)(
v.constBegin() +
v.size()).operator->(), (
void*)
v.constEnd().operator->());
3444 for (
int i = 0;
i < 10; ++
i)
3450 struct LiteralType {
3452 constexpr LiteralType(
int v = 0) :
value(
v) {}
3454 const LiteralType literal[] = {LiteralType(0), LiteralType(1), LiteralType(2)};
3458 for (
int i = 0;
i < 3; ++
i)
3471 void tst_QList::reallocateCustomAlignedType_qtbug90359()
const
3475 if constexpr (!canFail)
3476 qWarning() <<
"This test will always succeed on this system.";
3477 if constexpr (
alignof(
CustomAligned) >
alignof(std::max_align_t))
3478 QSKIP(
"The codepaths tested here wouldn't be executed.");
3482 for (
int i = 0;
i < 7; ++
i) {
3489 template<
typename T,
typename Reinsert>
3490 void tst_QList::reinsert(Reinsert
op)
const
3497 const int maxIters = 128;
3498 for (
int i = 0;
i < maxIters; ++
i) {
3504 for (
int i = 0, enoughIters =
int(capacity) * 2;
i < enoughIters; ++
i) {
3510 template<
typename T>
3511 void tst_QList::stability_reserve()
const
3529 const T *ptr =
vec.constData();
3539 const T *ptr =
vec.constData();
3546 const T *ptr =
vec.constData();
3547 vec.reserve(
vec.capacity());
3557 vec.reserve(
vec.capacity());
3558 const T *ptr =
vec.constData();
3567 const T *ptr =
vec.constData();
3581 const T *ptr =
vec.constData();
3592 template<
typename T>
3593 void tst_QList::stability_erase()
const
3601 std::generate(
v.begin(),
v.end(), [&k]() { return SimpleValue<T>::at(k++); });
3602 const auto ptr =
v.constData();
3608 for (
int i = 0;
i < copy.
size(); ++
i)
3615 const auto ptr =
v.constData();
3624 const auto ptr =
v.constData();
3625 v.remove(0,
v.size());
3630 template<
typename T>
3631 void tst_QList::stability_append()
const
3638 std::generate(
v.begin(),
v.end(), [&k]() { return SimpleValue<T>::at(k++); });
3640 v.append(
src.begin(),
src.end());
3643 for (
int i = 0;
i <
v.capacity() -
v.size(); ++
i) {
3646 for (
int i = 0;
i < copy.
size(); ++
i)
3655 const T *ptr =
v.constData();
3661 const qsizetype freeSpaceAtBegin =
v.constData() - ptr;
3662 const qsizetype freeSpaceAtEnd =
v.capacity() -
v.size() - freeSpaceAtBegin;
3664 QVERIFY(
v.size() + freeSpaceAtBegin + freeSpaceAtEnd ==
v.capacity());
3666 for (
int i = 0;
i < freeSpaceAtEnd; ++
i) {
3669 v.append(
src.begin(),
src.end());
3670 for (
int i = 0;
i < copy.
size(); ++
i)
3676 template<
typename T,
typename Insert>
3677 void tst_QList::stability_insert(Insert
op)
const
3685 std::generate(
v.begin(),
v.end(), [&k]() { return SimpleValue<T>::at(k++); });
3693 for (
int i = 0;
i <
pos; ++
i)
3700 std::generate(
v.begin(),
v.end(), [&k]() { return SimpleValue<T>::at(k++); });
3708 for (
int i = 0;
i <
pos; ++
i)
3713 template<
typename T>
3714 void tst_QList::stability_resize()
const
3723 std::generate(
v.begin(),
v.end(), [&k]() { return SimpleValue<T>::at(k++); });
3727 for (
int i = 0;
i < copy.
size(); ++
i)
3734 std::generate(
v.begin(),
v.end(), [&k]() { return SimpleValue<T>::at(k++); });
3738 for (
int i = 0;
i < 10; ++
i)
3745 std::generate(
v.begin(),
v.end(), [&k]() { return SimpleValue<T>::at(k++); });
3749 for (
int i = 0;
i < 5; ++
i)
3758 const T *ptr =
v.constData();
3766 const qsizetype freeSpaceAtBegin =
v.constData() - ptr;
3767 const qsizetype freeSpaceAtEnd =
v.capacity() -
v.size() - freeSpaceAtBegin;
3769 QVERIFY(
v.size() + freeSpaceAtBegin + freeSpaceAtEnd ==
v.capacity());
3771 std::generate(
v.begin(),
v.end(), [&k]() { return SimpleValue<T>::at(k++); });
3774 v.resize(
v.size() + freeSpaceAtEnd);
3775 for (
int i = 0;
i < copy.
size(); ++
i)
3781 #include "tst_qlist.moc"
small capitals from c petite p scientific f u
small capitals from c petite p scientific i
[1]
void operator=(const Foo &)
The QAtomicInt class provides platform-independent atomic operations on int.
The QAtomicPointer class is a template class that provides platform-independent atomic operations on ...
T loadAcquire() const noexcept
The QChar class provides a 16-bit Unicode character.
template< typename Enum > size_t qHash(QFlags< Enum > flags, size_t seed=0) noexcept
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal.
qsizetype size() const noexcept
QList< T > & fill(parameter_type t, qsizetype size=-1)
const_pointer constData() const noexcept
bool isEmpty() const noexcept
bool isDetached() const noexcept
void removeAt(qsizetype i)
bool isSharedWith(const QList< T > &other) const
iterator insert(qsizetype i, parameter_type t)
bool empty() const noexcept
bool removeOne(const AT &t)
qsizetype capacity() const
void swapItemsAt(qsizetype i, qsizetype j)
void push_back(parameter_type t)
const T & constFirst() const noexcept
bool endsWith(parameter_type t) const
bool startsWith(parameter_type t) const
qsizetype length() const noexcept
const_reference at(qsizetype i) const noexcept
T value(qsizetype i) const
static QList< T > fromList(const QList< T > &list) noexcept
const_reverse_iterator crbegin() const noexcept
const_iterator constBegin() const noexcept
void remove(qsizetype i, qsizetype n=1)
qsizetype removeIf(Predicate pred)
qsizetype removeAll(const AT &t)
qsizetype count() const noexcept
reference emplaceBack(Args &&... args)
void prepend(rvalue_ref t)
iterator emplace(const_iterator before, Args &&... args)
void reserve(qsizetype size)
reverse_iterator rbegin()
const T & constLast() const noexcept
void removeLast() noexcept
void resize(qsizetype size)
static QList< T > fromReadOnlyData(const T(&t)[N]) noexcept
const_iterator cend() const noexcept
void append(parameter_type t)
const_iterator constEnd() const noexcept
const_iterator cbegin() const noexcept
QList< T > toList() const noexcept
const_reverse_iterator crend() const noexcept
The QObject class is the base class of all Qt objects.
The QScopedValueRollback class resets a variable to its previous value on destruction.
The QSemaphore class provides a general counting semaphore.
The QString class provides a Unicode character string.
static QString fromLatin1(QByteArrayView ba)
static QString number(int, int base=10)
static void yieldCurrentThread()
auto generate(StringRef generatorName, SourceLineInfo const &lineInfo, L const &generatorExpression) -> decltype(std::declval< decltype(generatorExpression())>().get())
typename C::value_type value_type
Q_TESTLIB_EXPORT QTestData & newRow(const char *dataTag)
Q_TESTLIB_EXPORT QTestData & addRow(const char *format,...) Q_ATTRIBUTE_FORMAT_PRINTF(1
char * toString(const MyPoint &point)
typing.Tuple[int, int] test(str binary_directory, *debug=False)
set set set set set set set macro pixldst1 op
Q_CORE_EXPORT int qsnprintf(char *str, size_t n, const char *fmt,...)
EGLOutputLayerEXT EGLint EGLAttrib value
QList(InputIterator, InputIterator) -> QList< ValueType >
GLint GLfloat GLfloat GLfloat v2
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLint GLint GLint GLint GLint x
[0]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLsizei const GLchar ** strings
[1]
GLenum GLenum GLsizei count
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint GLfloat GLfloat GLfloat GLfloat v3
GLenum GLenum GLenum input
#define QStringLiteral(str)
#define QTEST_MAIN(TestObject)
#define QSKIP(statement,...)
#define QFETCH(Type, name)
#define QVERIFY(statement)
QLatin1String world("world")
~ConstructionCounted()=default
ConstructionCounted & operator=(ConstructionCounted &&other) noexcept
ConstructionCounted & operator=(const ConstructionCounted &other) noexcept
ConstructionCounted(int i)
ConstructionCounted(ConstructionCounted &&other) noexcept
friend bool operator==(const ConstructionCounted &lhs, const ConstructionCounted &rhs)
ConstructionCounted(const ConstructionCounted &other) noexcept
friend bool operator==(const CustomAligned &x, const CustomAligned &y)
static QAtomicInt counter
Custom & operator=(const Custom &other)
bool operator==(const Custom &other) const
bool operator<(const Custom &other) const
Custom(const Custom &other)
bool operator==(const Movable &other) const
Movable & operator=(const Movable &other)
Movable & operator=(Movable &&other)
static QAtomicInt counter
bool wasConstructedAt(const Movable *other) const
Movable(const Movable &other)
qsizetype lastIndexOf(const QString &str, qsizetype from=-1) const noexcept
qsizetype indexOf(const QString &str, qsizetype from=0) const noexcept
bool contains(QLatin1String str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
RemoveLastTestClass * other
SharedVectorChecker(const QList< T > &original, bool doCopyVector)
static const T Values[MaxIndex]
static const uint MaxIndex
static QList< T > vector(int size)
bool run(const QString &name, QString *errorMessage)
decltype(auto) qlistCopyAndReferenceFromRange(It first, It last)
QAtomicPointer< QList< T > > * detachThreadSafetyData()
QT_END_NAMESPACE Q_DECLARE_METATYPE(Movable)
QT_BEGIN_NAMESPACE Q_DECLARE_TYPEINFO(Movable, Q_RELOCATABLE_TYPE)
size_t qHash(const Movable &key, size_t seed=0)
#define TST_QLIST_CHECK_LEAKS(Type)
#define CHECK(Type, One, Two, Three)
QSet< QThread * > threads