31 #include <QtContainerFwd>
66 #include <QScopedPointer>
102 #if QT_CONFIG(regularexpression)
106 void sharableQList();
107 void sharableQVector();
109 void sharableQHash();
112 void javaStyleIterators();
113 void constAndNonConstStlIterators();
114 void vector_stl_data();
116 void list_stl_data();
120 void containerInstantiation();
122 void containerTypedefs();
123 void forwardDeclared();
125 void QTBUG13079_collectionInsideCollection();
128 void insert_remove_loop();
130 void detachAssociativeContainerQMap() { detachAssociativeContainerImpl<QMap>(); }
131 void detachAssociativeContainerQMultiMap() { detachAssociativeContainerImpl<QMultiMap>(); }
132 void detachAssociativeContainerQHash() { detachAssociativeContainerImpl<QHash>(); }
133 void detachAssociativeContainerQMultiHash() { detachAssociativeContainerImpl<QMultiHash>(); }
136 template <
template<
typename,
typename>
typename Container>
137 void detachAssociativeContainerImpl();
282 static_assert(QTypeTraits::has_operator_equal_v<RecursiveList>);
283 static_assert(QTypeTraits::has_operator_less_than_v<RecursiveList>);
284 static_assert(QTypeTraits::has_operator_equal_v<RecursiveSet>);
285 static_assert(QTypeTraits::has_operator_equal_v<RecursiveMapV>);
286 static_assert(QTypeTraits::has_operator_equal_v<RecursiveMapK>);
287 static_assert(QTypeTraits::has_operator_equal_v<RecursiveMultiMapV>);
288 static_assert(QTypeTraits::has_operator_equal_v<RecursiveMultiMapK>);
289 static_assert(QTypeTraits::has_operator_equal_v<RecursiveHashV>);
290 static_assert(QTypeTraits::has_operator_equal_v<RecursiveHashK>);
291 static_assert(QTypeTraits::has_operator_equal_v<RecursiveMultiHashV>);
292 static_assert(QTypeTraits::has_operator_equal_v<RecursiveMultiHashK>);
294 static_assert(!QTypeTraits::has_operator_equal_v<NoCmpParamRecursiveMapV>);
295 static_assert(!QTypeTraits::has_operator_equal_v<NoCmpParamRecursiveMapK>);
296 static_assert(!QTypeTraits::has_operator_equal_v<NoCmpParamRecursiveMultiMapV>);
297 static_assert(!QTypeTraits::has_operator_equal_v<NoCmpParamRecursiveMultiMapK>);
298 static_assert(!QTypeTraits::has_operator_equal_v<NoCmpParamRecursiveHashV>);
299 static_assert(!QTypeTraits::has_operator_equal_v<NoCmpParamRecursiveHashK>);
300 static_assert(!QTypeTraits::has_operator_equal_v<NoCmpParamRecursiveMultiHashV>);
301 static_assert(!QTypeTraits::has_operator_equal_v<NoCmpParamRecursiveMultiHashK>);
303 static_assert(!QTypeTraits::has_operator_equal_v<NoCmpRecursiveList>);
304 static_assert(!QTypeTraits::has_operator_less_than_v<NoCmpRecursiveList>);
305 static_assert(!QTypeTraits::has_operator_equal_v<NoCmpRecursiveSet>);
306 static_assert(!QTypeTraits::has_operator_equal_v<NoCmpRecursiveMapV>);
307 static_assert(!QTypeTraits::has_operator_equal_v<NoCmpRecursiveMapK>);
308 static_assert(!QTypeTraits::has_operator_equal_v<NoCmpRecursiveMultiMapV>);
309 static_assert(!QTypeTraits::has_operator_equal_v<NoCmpRecursiveMultiMapK>);
310 static_assert(!QTypeTraits::has_operator_equal_v<NoCmpRecursiveHashV>);
311 static_assert(!QTypeTraits::has_operator_equal_v<NoCmpRecursiveHashK>);
312 static_assert(!QTypeTraits::has_operator_equal_v<NoCmpRecursiveMultiHashV>);
313 static_assert(!QTypeTraits::has_operator_equal_v<NoCmpRecursiveMultiHashK>);
315 template <
typename T>
317 template <
typename T, qsizetype N>
318 constexpr
inline bool has_prepend_v<QVarLengthArray<T,N>> =
false;
320 void tst_Collections::typeinfo()
328 void tst_Collections::list()
347 QListIterator<int>
i(list);
355 list1 << 1 << 2 << 3 << 5 << 7 << 8 << 9;
358 QMutableListIterator<int> i1(list1);
359 while (i1.hasNext()) {
360 if (i1.next() % 2 != 0)
364 QMutableListIterator<int> i2(
list2);
366 while (i2.hasPrevious()) {
367 if (i2.previous() % 2 != 0)
377 for (
int i = 0;
i <
list.size(); ++
i)
384 while (
i !=
list.end())
391 while (
i !=
list.end())
412 for (
i = 0;
i <
list.size(); ++
i)
413 list[
i] = list[
i] +1;
414 for (
i = 0;
i <
list.size(); ++
i)
421 for (
i = 0;
i <
list.size(); ++
i)
423 for (
i = 0;
i <
list.size(); ++
i)
428 QMutableListIterator<int>
i(list);
430 i.setValue(2*
i.next());
434 QListIterator<int>
i(list);
436 while (
i.hasPrevious())
441 QMutableListIterator<int>
i(list);
443 while (
i.hasPrevious())
444 i.setValue(2*
i.previous());
448 QListIterator<int>
i(list);
450 while (
i.hasPrevious())
455 QMutableListIterator<int>
i(list);
456 while (
i.hasNext()) {
464 while (
i !=
list.end())
470 QListIterator<int>
i(list);
471 while (
i.hasNext()) {
473 if (
i.hasNext() &&
a ==
i.peekNext())
480 QListIterator<int>
i(list);
482 while (
i.hasPrevious()) {
483 int a =
i.previous();
484 if (
i.hasPrevious() &&
a ==
i.peekPrevious())
490 QMutableListIterator<int>
i(list);
491 while (
i.hasNext()) {
500 QMutableListIterator<int>
i =
list;
502 while (
i.hasPrevious()) {
503 int a =
i.previous();
504 if (
i.hasPrevious() &&
a ==
i.peekPrevious())
511 QMutableListIterator<int>
i =
list;
512 while (
i.hasNext()) {
513 int a =
i.peekNext();
515 QVERIFY(
i.peekPrevious() == 42 &&
i.peekNext() ==
a);
520 while (
i.findNext(42))
525 l << 4 << 8 << 12 << 16 << 20 << 24;
539 int a =
list.indexOf(8);
541 int r =
list.removeAll(8);
548 list <<
"one" <<
"two" <<
"three" <<
"four" <<
"five" <<
"six";
549 while (!
list.isEmpty())
554 list <<
"one" <<
"two" <<
"one" <<
"two";
580 list.replace(3, 222);
591 QListIterator<int>
i(list);
592 QVERIFY(!
i.hasNext() && !
i.hasPrevious());
626 list.append((
void*)42);
649 list.append(
"Hello");
694 list <<
"alpha" <<
"beta";
706 list <<
"foo" <<
"bar";
709 list.insert(0,
"atzero");
712 int listCount =
list.count();
713 list.insert(listCount,
"atcount");
719 list1 << 0 << 1 << 2 << 3;
744 list2 <<
"1" <<
"2" <<
"3";
768 list3 << 1.0 << 2.0 << 3.0;
798 list1.
append(
reinterpret_cast<void *
>(50));
800 for (
i = 1;
i < 100; ++
i) {
811 for (
i = 0;
i < list1.
size(); ++
i) {
812 QCOMPARE(list1.
at(
i),
reinterpret_cast<void *
>(50));
818 for (
i = 1;
i < 100; ++
i) {
836 for (
i = 1;
i < 100; ++
i) {
854 for (
i = 1;
i < 100; ++
i) {
865 for (
i = 0;
i < list4.
size(); ++
i) {
887 void tst_Collections::vector()
894 v3 << 1 << 2 << 3 << 4 << 5;
919 v.insert(
v.begin(), 0);
920 v.insert(
v.end(), 4);
921 v.insert(
v.begin()+2, 9);
924 result << 0 << 1 << 9 << 2 << 3 << 4;
937 vec <<
"foo" <<
"bar";
952 vector <<
"alpha" <<
"beta";
974 for (
int i = 0;
i < 10000; ++
i) {
996 for (
int i = 0;
i < 10000; ++
i) {
1011 vect1.
append(
reinterpret_cast<void *
>(50));
1013 for (
i = 1;
i < 100; ++
i) {
1024 for (
i = 0;
i < vect1.
size(); ++
i) {
1025 QCOMPARE(vect1.
at(
i),
reinterpret_cast<void *
>(50));
1031 for (
i = 1;
i < 100; ++
i) {
1042 for (
i = 0;
i < vect2.
size(); ++
i) {
1049 for (
i = 1;
i < 100; ++
i) {
1060 for (
i = 0;
i < vect3.
size(); ++
i) {
1067 for (
i = 1;
i < 100; ++
i) {
1078 for (
i = 0;
i < vect4.
size(); ++
i) {
1104 void tst_Collections::byteArray()
1113 QVERIFY(
"hello" + World == helloWorld);
1116 QVERIFY(Wor +
'l' +
'd' ==
"World");
1119 QVERIFY(
"hello" + World ==
"helloWorld");
1120 QVERIFY(
'h' + ello ==
"hello");
1121 QVERIFY(Wor +
'l' +
'd' ==
"World");
1124 QVERIFY(
"helloWorld" ==
"hello" + World);
1125 QVERIFY(
"hello" ==
'h' + ello);
1126 QVERIFY(
"World" == Wor +
'l' +
'd');
1148 QByteArray large =
"000 100 200 300 400 500 600 700 800 900";
1214 QVERIFY(nullByteArray == nonNullByteArray);
1233 ba1.replace(3, 3, ba1);
1236 ba1.replace(
char(
'F'), ba1);
1239 ba1.replace(
char(
'o'), ba1);
1242 ba1.replace(ba1,
"xxx");
1252 ba1.replace(0, -1,
"ZZZ");
1257 void tst_Collections::stack()
1263 QListIterator<int>
i = stack;
1266 while (
i.hasPrevious())
1267 sum +=
i.previous();
1280 void tst_Collections::hash()
1282 const char *
hello =
"hello";
1283 const char *
world =
"world";
1284 const char *allo =
"allo";
1285 const char *monde =
"monde";
1291 for (
int i = 0;
i < 10; ++
i) {
1293 for (
int j = 0;
j < 10; ++
j) {
1299 for (
int i = 0;
i < 10; ++
i) {
1301 for (
int j = 0;
j < 10; ++
j) {
1387 QVERIFY(it1.value() == monde);
1411 it1 = hash2.begin();
1412 while (it1 != hash2.end()) {
1420 while (it1 !=
hash.end()) {
1446 for (
int i = 0;
i < 10;
i++)
1466 for (
int i = 0;
i < 1000; ++
i)
1470 for (
int j = 0;
j < 900; ++
j)
1480 hash.insert(0,
"Hello");
1492 cit =
hash.cbegin();
1499 hash1.
insert(1,
"Alpha");
1500 hash1.
insert(1,
"Gamma");
1502 hash2.
insert(1,
"Gamma");
1503 hash2.
insert(1,
"Gamma");
1510 expected <<
"Gamma" <<
"Gamma" <<
"Beta" <<
"Gamma" <<
"Alpha";
1511 std::sort(expected.
begin(), expected.
end());
1519 expected += expected;
1520 std::sort(expected.
begin(), expected.
end());
1525 void tst_Collections::map()
1527 const char *
hello =
"hello";
1528 const char *
world =
"world";
1529 const char *allo =
"allo";
1530 const char *monde =
"monde";
1614 QVERIFY(it1.value() == monde);
1632 while (it1 !=
map.
end()) {
1658 while (it1 != map2.
end()) {
1666 while (it1 !=
map.
end()) {
1692 for (
int i = 0;
i < 10;
i++)
1713 QMapIterator<int,int>
i =
map;
1714 while (
i.hasNext()) {
1715 sum +=
i.next().value();
1728 QMutableMapIterator<int,int>
i =
map;
1730 if (
i.next().key() == 2)
1733 while (
i.hasNext()) {
1734 sum +=
i.next().value();
1744 QMutableMapIterator<int,int>
i(map);
1746 while (
i.hasPrevious()) {
1840 (
QStringList() <<
"Gamma" <<
"Gamma" <<
"Beta" <<
"Gamma" <<
"Alpha"));
1849 void tst_Collections::qstring()
1855 QString helloWorld =
"helloWorld";
1860 QVERIFY(
"hello" + World == helloWorld);
1863 QVERIFY(Wor +
'l' +
'd' ==
"World");
1866 QVERIFY(
"hello" + World ==
"helloWorld");
1867 QVERIFY(
'h' + ello ==
"hello");
1868 QVERIFY(Wor +
'l' +
'd' ==
"World");
1871 QVERIFY(
"helloWorld" ==
"hello" + World);
1872 QVERIFY(
"hello" ==
'h' + ello);
1873 QVERIFY(
"World" == Wor +
'l' +
'd');
1895 QString large =
"000 100 200 300 400 500 600 700 800 900";
1964 QVERIFY(
null.mid(0).isNull());
1983 s.insert(3,
"INSID");
2005 QVERIFY(
s.toUtf8() ==
"first-utf8");
2007 QVERIFY(
s.toUtf8() ==
"second-utf8");
2015 QVERIFY(
s.toUtf8() ==
"first-utf8");
2017 QVERIFY(
s.toUtf8() ==
"second-utf8");
2024 s =
"first-local8Bit";
2025 QVERIFY(
s.toLocal8Bit() ==
"first-local8Bit");
2026 s =
"second-local8Bit";
2027 QVERIFY(
s.toLocal8Bit() ==
"second-local8Bit");
2030 QVERIFY(
s.toLocal8Bit().size() == 0);
2031 QVERIFY(
s.toLocal8Bit().isEmpty());
2034 QVERIFY(
s.toLatin1() ==
"first-ascii");
2036 QVERIFY(
s.toLatin1() ==
"second-ascii");
2064 s =
" lots of stuff ";
2067 s =
"a hat, a stick, a ski";
2077 s =
s.arg(
"foo").arg(7);
2112 str1.insert(2, str1);
2114 str1.replace(3, 3, str1);
2115 QCOMPARE(str1,
QString(
"FoFFoFooFooFooFoooFooFooFooooFooFoooFooFooFoo"));
2117 str1.replace(
char(
'F'), str1);
2120 str1.replace(
char(
'o'), str1);
2124 str1.replace(
"Foo", str1);
2126 str1.replace(str1, str1);
2132 str1.replace(str1, str1);
2137 str1.replace(
"oo", str1);
2141 str1.replace(
"FooFoo", str1);
2144 str1.replace(str1,
"xxx");
2146 str1.replace(str1,
QString(
"yyy"));
2154 void tst_Collections::bitArray()
2166 for(
int i = 0;
i < 20;
i++)
2167 sum +=
ba.testBit(
i) ? 1 : 0;
2175 ba[0] =
ba[2] =
true;
2195 void tst_Collections::cache()
2200 for (
i = 0;
i < 30;
i++) {
2208 delete cache.take(10);
2214 for (
i = 0;
i < 30;
i++) {
2225 cache.insert(2,
new int(2));
2227 QVERIFY(*cache.object(2) == 3);
2234 #if QT_CONFIG(regularexpression)
2235 void tst_Collections::regexp()
2244 void tst_Collections::pair()
2250 QPair<int, QString> a(1,
"Zebra"),
b(2,
"Ying"),
c(3,
"Yang"),
d(3,
"Ying"),
e(5,
"Alabama");
2283 template <
class Container>
2289 container << 1 << 2 << 4 << 8;
2310 template <
class Container>
2314 return !container.isDetached();
2320 if (!container.isEmpty())
2325 template <
class Container,
class ContainerMutableIterator>
2360 QVERIFY(c1 == newInstance<Container>());
2361 c1 = newInstance<Container>();
2363 QVERIFY(c1 == newInstance<Container>());
2366 QVERIFY(
c2 == newInstance<Container>());
2370 #define TEST_SEQUENTIAL_CONTAINER(Container) \
2371 testContainer<Q##Container<int>, QMutable##Container##Iterator<int> >() \
2373 #define TEST_ASSOCIATIVE_CONTAINER(Container) \
2374 testContainer<Q##Container<int, int>, QMutable##Container##Iterator<int, int> >()
2376 void tst_Collections::sharableQList()
2381 void tst_Collections::sharableQVector()
2386 void tst_Collections::sharableQMap()
2391 void tst_Collections::sharableQHash()
2396 static int getList_calls = 0;
2401 list << 1 << 2 << 3 << 4 << 5 << 6;
2406 void tst_Collections::q_foreach()
2409 list << -2 << -1 << 0 << 1 << 2;
2413 foreach(
int i, list) {
2421 foreach(
int i, list)
2425 foreach(
int i, list) {
2433 foreach(
int i, list) {
2449 void tst_Collections::conversions()
2451 #define STUFF "A" << "C" << "B" << "A"
2465 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
2485 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
2503 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
2514 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
2527 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
2535 void tst_Collections::javaStyleIterators()
2538 list <<
"a" <<
"b" <<
"c";
2540 while (
i.hasNext()) {
2544 while (
i.hasPrevious()) {
2552 template <
class Container>
2583 template <
class Container>
2586 testLinkedListLikeStlIterators<Container>();
2664 template <
class Container>
2696 void tst_Collections::constAndNonConstStlIterators()
2698 testListLikeStlIterators<QList<int>>();
2699 testListLikeStlIterators<QStringList>();
2700 testMapLikeStlIterators<QMap<QString, QString>>();
2701 testMapLikeStlIterators<QMultiMap<QString, QString>>();
2702 testMapLikeStlIterators<QHash<QString, QString>>();
2703 testMapLikeStlIterators<QMultiHash<QString, QString>>();
2706 void tst_Collections::vector_stl_data()
2708 QTest::addColumn<QStringList>(
"elements");
2716 void tst_Collections::vector_stl()
2721 for (
int i = 0;
i < elements.count(); ++
i)
2722 vector << elements.
at(
i);
2724 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
2725 std::vector<QString> stdVector =
vector.toStdVector();
2729 QCOMPARE(
int(stdVector.size()), elements.size());
2732 for (
uint j = 0;
j < stdVector.size() &&
it != stdVector.end(); ++
j, ++
it)
2735 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
2741 void tst_Collections::list_stl_data()
2743 QTest::addColumn<QStringList>(
"elements");
2751 void tst_Collections::list_stl()
2756 for (
int i = 0;
i < elements.count(); ++
i)
2757 list << elements.at(
i);
2759 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
2760 std::list<QString> stdList =
list.toStdList();
2762 std::list<QString> stdList(
list.begin(),
list.end());
2765 QCOMPARE(
int(stdList.size()), elements.size());
2768 for (
uint j = 0;
j < stdList.size() &&
it != stdList.end(); ++
j, ++
it)
2771 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
2777 template <
typename T>
2783 void tst_Collections::q_init()
2788 QCOMPARE(qtInit<int *>(),
static_cast<int *
>(
nullptr));
2789 QCOMPARE(qtInit<double *>(),
static_cast<double *
>(
nullptr));
2795 void tst_Collections::pointersize()
2830 template <
typename ContainerType,
typename ValueType>
2834 ContainerType container;
2835 const ContainerType constContainer(container);
2838 constIt = constContainer.begin();
2839 constIt = container.cbegin();
2840 container.constBegin();
2842 constIt = constContainer.end();
2843 constIt = constContainer.cend();
2844 container.constEnd();
2848 container.contains(
value);
2851 container.isEmpty();
2854 Q_UNUSED((container != constContainer));
2855 Q_UNUSED((container == constContainer));
2856 container = constContainer;
2859 template <
typename ContainerType,
typename ValueType>
2862 instantiateContainer<ContainerType, ValueType>();
2863 ContainerType container;
2866 it = container.begin();
2867 it = container.end();
2871 template <
typename ContainerType,
typename ValueType>
2874 instantiateMutableIterationContainer<ContainerType, ValueType>();
2877 ContainerType container;
2878 container.removeAll(
value);
2881 template <
typename ContainerType,
typename ValueType>
2884 instantiateSequence<ContainerType, ValueType>();
2887 ContainerType container;
2888 container.indexOf(
value);
2889 container.lastIndexOf(
value);
2892 template <
typename ContainerType,
typename ValueType>
2895 instantiateContainer<ContainerType, ValueType>();
2898 ContainerType container;
2899 const ContainerType constContainer(container);
2901 container.reserve(1);
2902 container.capacity();
2903 container.squeeze();
2905 container.remove(
value);
2908 container.unite(constContainer);
2909 container.intersect(constContainer);
2910 container.subtract(constContainer);
2912 Q_UNUSED((container != constContainer));
2913 Q_UNUSED((container == constContainer));
2914 container & constContainer;
2915 container &= constContainer;
2917 container + constContainer;
2918 container += constContainer;
2920 container - constContainer;
2921 container -= constContainer;
2923 container | constContainer;
2924 container |= constContainer;
2928 template <
typename ContainerType,
typename KeyType,
typename ValueType>
2931 instantiateMutableIterationContainer<ContainerType, KeyType>();
2935 ContainerType container;
2936 const ContainerType constContainer(container);
2939 container.erase(
it);
2940 container.find(
key);
2941 container.constFind(
key);
2942 constContainer.find(
key);
2944 container.key(
value);
2946 constContainer.keys();
2947 container.remove(
key);
2948 container.take(
key);
2949 container.insert(constContainer);
2950 container.value(
key);
2954 const int foo = constContainer[
key];
2962 void tst_Collections::containerInstantiation()
2966 instantiatePairAssociative<Hash, EqualsComparable, int>();
2975 instantiatePairAssociative<Map, LessThanComparable, int>();
2979 instantiateAssociative<Set, EqualsComparable>();
2983 instantiateRandomAccess<List, EqualsComparable>();
2992 instantiateRandomAccess<Queue, EqualsComparable>();
2996 instantiateRandomAccess<Stack, EqualsComparable>();
2999 void tst_Collections::qtimerList()
3002 const int N = 10000;
3008 for(
int i = 0;
i <
N;
i++) {
3010 foo.insert(1, 99.9);
3014 for (
int i = 0;
i < (
N / 2) - 10; ++
i) {
3019 QFAIL(
"QList preallocates too much memory");
3022 #define QVERIFY_TYPE(Type) QVERIFY(sizeof(Type) > 0)
3024 template <
typename Container>
3038 template <
typename Container>
3060 template <
typename Container>
3078 void tst_Collections::containerTypedefs()
3095 void tst_Collections::forwardDeclared()
3098 #define TEST(type) do { \
3102 C::const_iterator j; \
3134 #if defined(Q_PROCESSOR_ARM)
3135 # if defined(Q_COMPILER_ALIGNAS) && defined(__BIGGEST_ALIGNMENT__)
3138 # define BIGGEST_ALIGNMENT_TO_TEST (__BIGGEST_ALIGNMENT__ << 3)
3142 #if !defined(BIGGEST_ALIGNMENT_TO_TEST)
3143 # define BIGGEST_ALIGNMENT_TO_TEST 128
3146 template <
size_t Alignment>
3162 static_assert(
alignof(
Aligned4) % 4 == 0);
3165 static_assert(
alignof(
AlignedStdMax) %
alignof(std::max_align_t) == 0);
3171 template<
typename C>
3176 container.append(Aligned());
3179 for (
int i = 0;
i < 200; ++
i)
3180 container.append(Aligned());
3182 for (
int i = 0;
i < container.size(); ++
i)
3186 template<
typename C>
3191 container.append(Aligned());
3194 for (
int i = 0;
i < 200; ++
i)
3195 container.append(Aligned());
3197 for (
int i = container.firstIndex();
i < container.lastIndex(); ++
i)
3201 template<
typename C>
3214 for (
int i = 0;
i < 200; ++
i)
3217 it = container.constBegin();
3218 for ( ;
it != container.constEnd(); ++
it) {
3224 void tst_Collections::alignment()
3226 testVectorAlignment<QList<Aligned4> >();
3227 testVectorAlignment<QList<AlignedStdMax> >();
3228 testVectorAlignment<QList<AlignedBiggest> >();
3230 testContiguousCacheAlignment<QContiguousCache<Aligned4> >();
3231 testContiguousCacheAlignment<QContiguousCache<AlignedStdMax> >();
3232 testContiguousCacheAlignment<QContiguousCache<AlignedBiggest> >();
3235 testAssociativeContainerAlignment<QMap<Aligned4, Aligned4> >();
3236 testAssociativeContainerAlignment<QMap<Aligned4, AlignedStdMax> >();
3237 testAssociativeContainerAlignment<QMap<AlignedStdMax, Aligned4> >();
3238 testAssociativeContainerAlignment<QMap<AlignedStdMax, AlignedStdMax> >();
3240 testAssociativeContainerAlignment<QHash<Aligned4, Aligned4> >();
3241 testAssociativeContainerAlignment<QHash<Aligned4, AlignedStdMax> >();
3242 testAssociativeContainerAlignment<QHash<Aligned4, AlignedBiggest> >();
3243 testAssociativeContainerAlignment<QHash<AlignedStdMax, Aligned4> >();
3244 testAssociativeContainerAlignment<QHash<AlignedStdMax, AlignedStdMax> >();
3245 testAssociativeContainerAlignment<QHash<AlignedStdMax, AlignedBiggest> >();
3246 testAssociativeContainerAlignment<QHash<AlignedBiggest, Aligned4> >();
3247 testAssociativeContainerAlignment<QHash<AlignedBiggest, AlignedStdMax> >();
3248 testAssociativeContainerAlignment<QHash<AlignedBiggest, AlignedBiggest> >();
3251 #ifndef QT_NO_TEMPLATE_TEMPLATE_PARAMETERS
3253 template<
template<
class>
class C>
3265 nodeList << QTBUG13079_Node<C>();
3266 nodeList.first().s =
"parent";
3268 nodeList.first().children.first().s =
"child";
3270 nodeList = nodeList.first().children;
3273 nodeList = nodeList.first().children;
3275 nodeList << QTBUG13079_Node<C>();
3278 template<
template<
class,
class>
class C>
3291 nodeMap[18].s =
"parent";
3293 nodeMap[18].children[12].s =
"child";
3295 nodeMap = nodeMap[18].children;
3298 nodeMap = nodeMap[12].children;
3311 return a.s ==
b.s &&
a.children ==
b.children;
3314 template<
template<
class>
class C>
3331 nodePtr->s =
"parent";
3333 nodePtr->child->s =
"child";
3334 nodePtr = nodePtr->child;
3336 nodePtr = nodePtr->child;
3342 nodePtr->s =
"parent";
3344 nodePtr->next->s =
"next";
3345 nodePtr = Ptr(nodePtr->next);
3347 nodePtr = Ptr(nodePtr->next);
3354 void tst_Collections::QTBUG13079_collectionInsideCollection()
3356 #ifndef QT_NO_TEMPLATE_TEMPLATE_PARAMETERS
3357 QTBUG13079_collectionInsideCollectionImpl<QVector>();
3358 QTBUG13079_collectionInsideCollectionImpl<QStack>();
3359 QTBUG13079_collectionInsideCollectionImpl<QList>();
3360 QTBUG13079_collectionInsideCollectionImpl<QQueue>();
3364 nodeSet << QTBUG13079_Node<QSet>();
3365 nodeSet = nodeSet.
begin()->children;
3369 QTBUG13079_collectionInsideCollectionAssocImpl<QMap>();
3370 QTBUG13079_collectionInsideCollectionAssocImpl<QHash>();
3372 QTBUG13079_collectionInsidePtrImpl<QSharedPointer>();
3373 QTBUG13079_collectionInsidePtrImpl<QExplicitlySharedDataPointer>();
3374 QTBUG13079_collectionInsidePtrImpl<QSharedDataPointer>();
3383 foreach(
const T &
val, container) {
3396 c2.insert((
i * 89) %
c2.size(),
T() );
3405 void tst_Collections::foreach_2()
3407 QStringList strlist =
QString::fromLatin1(
"a,b,c,d,e,f,g,h,ih,kl,mn,op,qr,st,uvw,xyz").
split(
QLatin1Char(
','));
3413 intlist << 1 << 2 << 3 << 4 <<5 << 6 << 7 << 8 << 9;
3420 foreach(
int i, intlist) {
3447 operator int() {
return val; }
3460 if constexpr (has_prepend_v<Container>)
3468 int expect1[] = { 4 , 1 , 7, 5 , 5 , 8, 8, 8, 6, 5, 2 , 3 };
3469 QCOMPARE(
size_t(
t.count()),
sizeof(expect1)/
sizeof(
int));
3470 for (
int i = 0;
i <
t.count();
i++) {
3483 int expect2[] = { 4 , 1 , 9, 8, 6, 5, 2 , 3 };
3484 QCOMPARE(
size_t(
t.count()),
sizeof(expect2)/
sizeof(
int));
3485 for (
int i = 0;
i <
t.count();
i++) {
3496 int expect3[] = { 1 , 9, 5, 3 };
3497 QCOMPARE(
size_t(
t.count()),
sizeof(expect3)/
sizeof(
int));
3498 for (
int i = 0;
i <
t.count();
i++) {
3502 t.erase(
t.begin() + 1,
t.end() - 1);
3504 int expect4[] = { 1 , 3 };
3505 QCOMPARE(
size_t(
t.count()),
sizeof(expect4)/
sizeof(
int));
3506 for (
int i = 0;
i <
t.count();
i++) {
3521 int expect5[] = { 1, 1, 2, 3*3, 3, 3*3+1, 10, 11*11, 11, 11*11+1, 12 , 13*13, 13, 13*13+1, 14,
3522 15*15, 15, 15*15+1, 16 , 17*17, 17, 17*17+1 ,18 , 19*19, 19, 19*19+1, 20, 21*21, 21, 21*21+1 };
3523 QCOMPARE(
size_t(
t.count()),
sizeof(expect5)/
sizeof(
int));
3524 for (
int i = 0;
i <
t.count();
i++) {
3533 int expect6[] = { 1, 2, 7, 7, 7, 7, 9, 9, 9, 9, 3, 4 };
3534 QCOMPARE(
size_t(
t.count()),
sizeof(expect6)/
sizeof(
int));
3535 for (
int i = 0;
i <
t.count();
i++) {
3542 template<
typename T>
3545 void tst_Collections::insert_remove_loop()
3547 insert_remove_loop_impl<ExtList<int>>();
3548 insert_remove_loop_impl<ExtList<QString>>();
3549 insert_remove_loop_impl<QList<int>>();
3550 insert_remove_loop_impl<QList<QString>>();
3551 insert_remove_loop_impl<QVarLengthArray<int>>();
3552 insert_remove_loop_impl<QVarLengthArray<QString>>();
3553 insert_remove_loop_impl<QVarLengthArray<int, 10>>();
3554 insert_remove_loop_impl<QVarLengthArray<QString, 10>>();
3555 insert_remove_loop_impl<QVarLengthArray<int, 3>>();
3556 insert_remove_loop_impl<QVarLengthArray<QString, 3>>();
3557 insert_remove_loop_impl<QVarLengthArray<int, 15>>();
3558 insert_remove_loop_impl<QVarLengthArray<QString, 15>>();
3560 insert_remove_loop_impl<ExtList<std::string>>();
3561 insert_remove_loop_impl<QList<std::string>>();
3562 insert_remove_loop_impl<QVarLengthArray<std::string>>();
3563 insert_remove_loop_impl<QVarLengthArray<std::string, 10>>();
3564 insert_remove_loop_impl<QVarLengthArray<std::string, 3>>();
3565 insert_remove_loop_impl<QVarLengthArray<std::string, 15>>();
3568 template <
template<
typename,
typename>
typename Container>
3569 void tst_Collections::detachAssociativeContainerImpl()
3571 constexpr
int RUNS = 50;
3576 for (
int i = 0;
i < 1'000; ++
i) {
3577 container.insert(
i,
i);
3578 container.insert(
i,
i);
3581 const auto it = container.constBegin();
3582 const auto &
key =
it.key();
3583 const auto &
value =
it.value();
3584 const auto keyCopy =
key;
3585 const auto valueCopy =
value;
3588 auto detachInAnotherThread = [&sem1, &sem2, copy = container]()
mutable {
3619 QVERIFY(container.contains(keyCopy));
3620 QCOMPARE(container.value(keyCopy), valueCopy);
3627 #include "tst_collections.moc"
small capitals from c petite p scientific i
[1]
friend size_t qHash(const AlignedClass &a)
bool operator==(const AlignedClass &other) const
bool operator<(const AlignedClass &other) const
bool operator==(const EqualsComparable &) const
bool operator<(const LessThanComparable &) const
bool operator==(const LessThanComparable &) const
The QBitArray class provides an array of bits.
The QByteArray class provides an array of bytes.
qsizetype size() const noexcept
qsizetype indexOf(char c, qsizetype from=0) const
bool contains(char c) const
bool isEmpty() const noexcept
QByteArray left(qsizetype len) const
qsizetype lastIndexOf(char c, qsizetype from=-1) const
qsizetype count(char c) const
bool isNull() const noexcept
QByteArray mid(qsizetype index, qsizetype len=-1) const
The QChar class provides a 16-bit Unicode character.
template< typename Enum > size_t qHash(QFlags< Enum > flags, size_t seed=0) noexcept
iterator insert(const Key &key, const T &value)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal.
qsizetype size() const noexcept
void removeFirst() noexcept
bool isEmpty() const noexcept
iterator insert(qsizetype i, parameter_type t)
void swapItemsAt(qsizetype i, qsizetype j)
static QList< T > fromVector(const QList< T > &vector) noexcept
const_reference at(qsizetype i) const noexcept
static QList< T > fromList(const QList< T > &list) noexcept
void remove(qsizetype i, qsizetype n=1)
qsizetype count() const noexcept
void prepend(rvalue_ref t)
void replace(qsizetype i, parameter_type t)
void resize(qsizetype size)
void append(parameter_type t)
QList< T > toVector() const noexcept
QList< T > toList() const noexcept
iterator insert(const Key &key, const T &value)
T value(const Key &key, const T &defaultValue=T()) const
bool contains(const Key &key) const
size_type remove(const Key &key)
const_iterator cbegin() const
iterator find(const Key &key)
const_iterator constBegin() const
The QMultiHash class is a convenience QHash subclass that provides multi-valued hashes.
QMultiHash & unite(const QMultiHash &other)
QList< T > values() const
iterator insert(const Key &key, const T &value)
qsizetype size() const noexcept
iterator lowerBound(const Key &key)
QMultiMap & unite(const QMultiMap &other)
iterator find(const Key &key)
iterator insert(const Key &key, const T &value)
QList< T > values() const
iterator upperBound(const Key &key)
The QObject class is the base class of all Qt objects.
const QObjectList & children() const
The QQueue class is a generic container that provides a queue.
The QRegularExpression class provides pattern matching using regular expressions.
The QScopedPointer class stores a pointer to a dynamically allocated object, and deletes it upon dest...
The QSemaphore class provides a general counting semaphore.
QList< T > values() const
bool contains(const T &value) const
The QSharedData class is a base class for shared data objects. \reentrant.
The QString class provides a Unicode character string.
qsizetype lastIndexOf(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
static QString fromLatin1(QByteArrayView ba)
QStringList split(const QString &sep, Qt::SplitBehavior behavior=Qt::KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
static QString fromStdString(const std::string &s)
std::string toStdString() const
static QString fromUtf8(QByteArrayView utf8)
static QString fromRawData(const QChar *, qsizetype size)
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
QString & insert(qsizetype i, QChar c)
bool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
static QString number(int, int base=10)
static QString static QString qsizetype indexOf(QChar c, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
const QChar * unicode() const
The QStringList class provides a list of strings.
The QStringView class provides a unified view on UTF-16 strings with a read-only subset of the QStrin...
void start(Priority=InheritPriority)
bool wait(QDeadlineTimer deadline=QDeadlineTimer(QDeadlineTimer::Forever))
The QTime class provides clock time functions.
QHash< int, QWidget * > hash
[35multi]
QMap< QString, QString > map
[6]
typename C::value_type value_type
typename C::const_iterator const_iterator
typename C::key_type key_type
typename C::mapped_type mapped_type
typename C::iterator iterator
Q_TESTLIB_EXPORT QTestData & newRow(const char *dataTag)
const T & const_reference()
#define QT_WARNING_DISABLE_CLANG(text)
std::pair< T1, T2 > QPair
QList< QString > QStringList
typedef QByteArray(EGLAPIENTRYP PFNQGSGETDISPLAYSPROC)()
EGLOutputLayerEXT EGLint EGLAttrib value
QT_BEGIN_INCLUDE_NAMESPACE typedef unsigned char uchar
GLint GLfloat GLfloat GLfloat v2
GLenum GLsizei GLsizei GLint * values
[16]
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]
GLenum GLenum GLsizei count
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint GLfloat GLfloat GLfloat GLfloat v3
GLsizei const void * pointer
GLsizei const GLchar *const * string
[0]
constexpr decltype(auto) qMakePair(T1 &&value1, T2 &&value2) noexcept(noexcept(std::make_pair(std::forward< T1 >(value1), std::forward< T2 >(value2))))
QMutableListIterator< QString > QMutableStringListIterator
#define QTEST_APPLESS_MAIN(TestObject)
#define QFETCH(Type, name)
#define QVERIFY(statement)
QLatin1String world("world")
QFuture< QSet< QChar > > set
[10]
bool operator==(const Dummy &) const
bool operator<(const Dummy &) const
IntOrString(const std::string &v)
IntOrString(const QString &v)
LargeStatic & operator=(const LargeStatic &o)
LargeStatic(const LargeStatic &o)
Movable(const Movable &o)
bool operator==(const NoCmpRecursiveHashK &) const =delete
bool operator==(const NoCmpRecursiveHashV &) const =delete
bool operator==(const RecursiveList &) const =delete
bool operator<(const RecursiveList &) const =delete
bool operator==(const NoCmpRecursiveMapK &) const =delete
bool operator==(const NoCmpRecursiveMapV &) const =delete
bool operator==(const NoCmpRecursiveMultiHashK &) const =delete
bool operator==(const NoCmpRecursiveMultiHashV &) const =delete
bool operator==(const NoCmpRecursiveMultiMapK &) const =delete
bool operator==(const NoCmpRecursiveMultiMapV &) const =delete
bool operator==(const NoCmpRecursiveSet &) const =delete
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
bool contains(const AT &t) const noexcept
C< int, QTBUG13079_NodeAssoc > children
C< QTBUG13079_Node > children
C< QTBUG13079_NodePtr > child
QTBUG13079_NodePtr * next
QThreadStorage< int * > dummy[8]
Q_DECLARE_METATYPE(RecursiveList)
void testListLikeStlIterators()
void populate(Container &)
#define TEST_SEQUENTIAL_CONTAINER(Container)
void testSetContainerTypedefs(Container container)
void instantiateRandomAccess()
uint qHash(const Dummy &)
constexpr bool has_prepend_v
void QTBUG13079_collectionInsidePtrImpl()
void instantiateMutableIterationContainer()
void instantiateContainer()
bool operator==(const QTBUG13079_Node< QSet > &a, const QTBUG13079_Node< QSet > &b)
#define TEST_ASSOCIATIVE_CONTAINER(Container)
void instantiatePairAssociative()
void testContiguousCacheAlignment()
#define QVERIFY_TYPE(Type)
void testLinkedListLikeStlIterators()
void testMapLikeStlIterators()
bool isSharable(const Container &container)
void testVectorAlignment()
#define BIGGEST_ALIGNMENT_TO_TEST
void testPairAssociativeContainerTypedefs(Container container)
void instantiateAssociative()
void insert_remove_loop_impl()
QT_BEGIN_NAMESPACE Q_DECLARE_TYPEINFO(Movable, Q_RELOCATABLE_TYPE)
void QTBUG13079_collectionInsideCollectionAssocImpl()
void testContainerTypedefs(Container container)
void foreach_test_arrays(const Container &container)
void instantiateSequence()
void QTBUG13079_collectionInsideCollectionImpl()
void testAssociativeContainerAlignment()
bool run(const QString &name, QString *errorMessage)