0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the test suite of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
|
|
43 |
// test the container forwards
|
|
44 |
#include <QtContainerFwd>
|
|
45 |
|
|
46 |
static QCache<int, int> *cacheX;
|
|
47 |
static QHash<int, int> *hashX;
|
|
48 |
static QLinkedList<int> *linkedListX;
|
|
49 |
static QList<int> *listX;
|
|
50 |
static QMap<int, int> *mapX;
|
|
51 |
static QMultiHash<int, int> *multiHashX;
|
|
52 |
static QMultiMap<int, int> *multiMapX;
|
|
53 |
static QPair<int, int> *pairX;
|
|
54 |
static QQueue<int> *queueX;
|
|
55 |
static QSet<int> *setX;
|
|
56 |
static QStack<int> *stackX;
|
|
57 |
static QVarLengthArray<int> *varLengthArrayX;
|
|
58 |
static QVarLengthArray<int, 512> *varLengthArrayY;
|
|
59 |
static QVector<int> *vectorX;
|
|
60 |
|
|
61 |
void foo()
|
|
62 |
{
|
|
63 |
cacheX = 0;
|
|
64 |
hashX = 0;
|
|
65 |
linkedListX = 0;
|
|
66 |
listX = 0;
|
|
67 |
mapX = 0;
|
|
68 |
multiHashX = 0;
|
|
69 |
multiMapX = 0;
|
|
70 |
pairX = 0;
|
|
71 |
queueX = 0;
|
|
72 |
setX = 0;
|
|
73 |
stackX = 0;
|
|
74 |
varLengthArrayX = 0;
|
|
75 |
varLengthArrayY = 0;
|
|
76 |
vectorX = 0;
|
|
77 |
}
|
|
78 |
|
|
79 |
#include <QtTest/QtTest>
|
|
80 |
|
|
81 |
#ifndef QT_NO_STL
|
|
82 |
# include <algorithm>
|
|
83 |
#endif
|
|
84 |
|
|
85 |
#include "qalgorithms.h"
|
|
86 |
#include "qbitarray.h"
|
|
87 |
#include "qbytearray.h"
|
|
88 |
#include "qcache.h"
|
|
89 |
#include "qhash.h"
|
|
90 |
#include "qlinkedlist.h"
|
|
91 |
#include "qlist.h"
|
|
92 |
#include "qmap.h"
|
|
93 |
#include "qpair.h"
|
|
94 |
#include "qregexp.h"
|
|
95 |
#include "qset.h"
|
|
96 |
#include "qstack.h"
|
|
97 |
#include "qstring.h"
|
|
98 |
#include "qstringlist.h"
|
|
99 |
#include "qvarlengtharray.h"
|
|
100 |
#include "qvector.h"
|
|
101 |
#include "qqueue.h"
|
|
102 |
|
|
103 |
#ifdef QT3_SUPPORT
|
|
104 |
#include "q3cleanuphandler.h"
|
|
105 |
#endif
|
|
106 |
|
|
107 |
// Do not test initialization of pods on msvc6 and msvc 2002
|
|
108 |
// This is a known issue
|
|
109 |
#if defined Q_CC_MSVC && _MSC_VER < 1310
|
|
110 |
# define NOPODINITIALIZATION
|
|
111 |
#endif
|
|
112 |
|
|
113 |
|
|
114 |
template class QList<int>;
|
|
115 |
|
|
116 |
//TESTED_FILES=
|
|
117 |
|
|
118 |
class tst_Collections : public QObject
|
|
119 |
{
|
|
120 |
Q_OBJECT
|
|
121 |
|
|
122 |
public:
|
|
123 |
tst_Collections();
|
|
124 |
~tst_Collections();
|
|
125 |
|
|
126 |
public slots:
|
|
127 |
void init();
|
|
128 |
void cleanup();
|
|
129 |
private slots:
|
|
130 |
void typeinfo();
|
|
131 |
void qstring();
|
|
132 |
void list();
|
|
133 |
void linkedList();
|
|
134 |
void vector();
|
|
135 |
void byteArray();
|
|
136 |
void stack();
|
|
137 |
void hash();
|
|
138 |
void map();
|
|
139 |
void bitArray();
|
|
140 |
void cache();
|
|
141 |
void regexp();
|
|
142 |
void pair();
|
|
143 |
void cleanupHandler();
|
|
144 |
void sharableQList();
|
|
145 |
void sharableQLinkedList();
|
|
146 |
void sharableQVector();
|
|
147 |
void sharableQMap();
|
|
148 |
void sharableQHash();
|
|
149 |
void q_foreach();
|
|
150 |
void conversions();
|
|
151 |
void javaStyleIterators();
|
|
152 |
void constAndNonConstStlIterators();
|
|
153 |
#ifndef QT_NO_STL
|
|
154 |
void vector_stl_data();
|
|
155 |
void vector_stl();
|
|
156 |
void list_stl_data();
|
|
157 |
void list_stl();
|
|
158 |
void linkedlist_stl_data();
|
|
159 |
void linkedlist_stl();
|
|
160 |
#endif
|
|
161 |
void q_init();
|
|
162 |
void pointersize();
|
|
163 |
void containerInstantiation();
|
|
164 |
void qtimerList();
|
|
165 |
void containerTypedefs();
|
|
166 |
void forwardDeclared();
|
|
167 |
};
|
|
168 |
|
|
169 |
struct LargeStatic {
|
|
170 |
static int count;
|
|
171 |
LargeStatic():c(count) { ++count; }
|
|
172 |
LargeStatic(const LargeStatic& o):c(o.c) { ++count; }
|
|
173 |
~LargeStatic() { --count; }
|
|
174 |
int c;
|
|
175 |
int data[8];
|
|
176 |
};
|
|
177 |
|
|
178 |
int LargeStatic::count = 0;
|
|
179 |
|
|
180 |
struct Movable {
|
|
181 |
static int count;
|
|
182 |
Movable():c(count) { ++count; }
|
|
183 |
Movable(const Movable& o):c(o.c) { ++count; }
|
|
184 |
~Movable() { --count; }
|
|
185 |
int c;
|
|
186 |
};
|
|
187 |
|
|
188 |
int Movable::count = 0;
|
|
189 |
QT_BEGIN_NAMESPACE
|
|
190 |
Q_DECLARE_TYPEINFO(Movable, Q_MOVABLE_TYPE);
|
|
191 |
QT_END_NAMESPACE
|
|
192 |
|
|
193 |
|
|
194 |
struct Pod {
|
|
195 |
int i1, i2;
|
|
196 |
|
|
197 |
#if defined NOPODINITIALIZATION
|
|
198 |
Pod() : i1(0), i2(0) { }
|
|
199 |
#endif
|
|
200 |
};
|
|
201 |
|
|
202 |
tst_Collections::tst_Collections()
|
|
203 |
{
|
|
204 |
}
|
|
205 |
|
|
206 |
tst_Collections::~tst_Collections()
|
|
207 |
{
|
|
208 |
|
|
209 |
}
|
|
210 |
|
|
211 |
void tst_Collections::init()
|
|
212 |
{
|
|
213 |
}
|
|
214 |
|
|
215 |
void tst_Collections::cleanup()
|
|
216 |
{
|
|
217 |
}
|
|
218 |
|
|
219 |
void tst_Collections::typeinfo()
|
|
220 |
{
|
|
221 |
QVERIFY(QTypeInfo<int*>::isPointer);
|
|
222 |
QVERIFY(!QTypeInfo<int>::isPointer);
|
|
223 |
QVERIFY(QTypeInfo<QString>::isComplex);
|
|
224 |
QVERIFY(!QTypeInfo<int>::isComplex);
|
|
225 |
}
|
|
226 |
|
|
227 |
void tst_Collections::list()
|
|
228 |
{
|
|
229 |
{
|
|
230 |
QList<int> list;
|
|
231 |
QVERIFY(list.isEmpty());
|
|
232 |
list.append(1);
|
|
233 |
QVERIFY(list.size() == 1);
|
|
234 |
|
|
235 |
QVERIFY(*list.begin() == 1);
|
|
236 |
|
|
237 |
list.push_back(2);
|
|
238 |
list += (3);
|
|
239 |
list << 4 << 5 << 6;
|
|
240 |
QVERIFY(!list.isEmpty());
|
|
241 |
QVERIFY(list.size() == 6);
|
|
242 |
QVERIFY(list.end() - list.begin() == list.size());
|
|
243 |
|
|
244 |
#if !defined(QT_NO_STL) && !defined(Q_CC_MSVC) && !defined(Q_CC_SUN)
|
|
245 |
QVERIFY(std::binary_search(list.begin(), list.end(), 2) == true);
|
|
246 |
QVERIFY(std::binary_search(list.begin(), list.end(), 9) == false);
|
|
247 |
#endif
|
|
248 |
QVERIFY(qBinaryFind(list.begin(), list.end(), 2) == list.begin() + 1);
|
|
249 |
QVERIFY(qLowerBound(list.begin(), list.end(), 2) == list.begin() + 1);
|
|
250 |
QVERIFY(qUpperBound(list.begin(), list.end(), 2) == list.begin() + 2);
|
|
251 |
QVERIFY(qBinaryFind(list.begin(), list.end(), 9) == list.end());
|
|
252 |
QVERIFY(qLowerBound(list.begin(), list.end(), 9) == list.end());
|
|
253 |
QVERIFY(qUpperBound(list.begin(), list.end(), 9) == list.end());
|
|
254 |
{
|
|
255 |
int sum = 0;
|
|
256 |
QListIterator<int> i(list);
|
|
257 |
while (i.hasNext())
|
|
258 |
sum += i.next();
|
|
259 |
QVERIFY(sum == 21);
|
|
260 |
}
|
|
261 |
|
|
262 |
{
|
|
263 |
QList<int> list1;
|
|
264 |
list1 << 1 << 2 << 3 << 5 << 7 << 8 << 9;
|
|
265 |
QList<int> list2 = list1;
|
|
266 |
|
|
267 |
QMutableListIterator<int> i1(list1);
|
|
268 |
while (i1.hasNext()) {
|
|
269 |
if (i1.next() % 2 != 0)
|
|
270 |
i1.remove();
|
|
271 |
}
|
|
272 |
|
|
273 |
QMutableListIterator<int> i2(list2);
|
|
274 |
i2.toBack();
|
|
275 |
while (i2.hasPrevious()) {
|
|
276 |
if (i2.previous() % 2 != 0)
|
|
277 |
i2.remove();
|
|
278 |
}
|
|
279 |
QVERIFY(list1.size() == 2);
|
|
280 |
QVERIFY(list2.size() == 2);
|
|
281 |
QVERIFY(list1 == list2);
|
|
282 |
}
|
|
283 |
|
|
284 |
{
|
|
285 |
int sum = 0;
|
|
286 |
for (int i = 0; i < list.size(); ++i)
|
|
287 |
sum += list[i];
|
|
288 |
QVERIFY(sum == 21);
|
|
289 |
}
|
|
290 |
{
|
|
291 |
int sum = 0;
|
|
292 |
QList<int>::const_iterator i = list.begin();
|
|
293 |
while (i != list.end())
|
|
294 |
sum += *i++;
|
|
295 |
QVERIFY(sum == 21);
|
|
296 |
}
|
|
297 |
{
|
|
298 |
int sum = 0;
|
|
299 |
QList<int>::ConstIterator i = list.begin();
|
|
300 |
while (i != list.end())
|
|
301 |
sum += *i++;
|
|
302 |
QVERIFY(sum == 21);
|
|
303 |
}
|
|
304 |
{
|
|
305 |
QList<int>::Iterator i = list.begin();
|
|
306 |
i += 2;
|
|
307 |
QCOMPARE(*i, 3);
|
|
308 |
i -= 1;
|
|
309 |
QCOMPARE(*i, 2);
|
|
310 |
}
|
|
311 |
{
|
|
312 |
QList<int>::ConstIterator i = list.begin();
|
|
313 |
i += 2;
|
|
314 |
QCOMPARE(*i, 3);
|
|
315 |
i -= 1;
|
|
316 |
QCOMPARE(*i, 2);
|
|
317 |
}
|
|
318 |
{
|
|
319 |
int sum = 0;
|
|
320 |
int i;
|
|
321 |
for (i = 0; i < list.size(); ++i)
|
|
322 |
list[i] = list[i] +1;
|
|
323 |
for (i = 0; i < list.size(); ++i)
|
|
324 |
sum += list[i];
|
|
325 |
QVERIFY(sum == 21 + list.size());
|
|
326 |
}
|
|
327 |
{
|
|
328 |
int sum = 0;
|
|
329 |
int i;
|
|
330 |
for (i = 0; i < list.size(); ++i)
|
|
331 |
--list[i];
|
|
332 |
for (i = 0; i < list.size(); ++i)
|
|
333 |
sum += list[i];
|
|
334 |
QVERIFY(sum == 21);
|
|
335 |
}
|
|
336 |
{
|
|
337 |
QMutableListIterator<int> i(list);
|
|
338 |
while (i.hasNext())
|
|
339 |
i.setValue(2*i.next());
|
|
340 |
}
|
|
341 |
{
|
|
342 |
int sum = 0;
|
|
343 |
QListIterator<int> i(list);
|
|
344 |
i.toBack();
|
|
345 |
while (i.hasPrevious())
|
|
346 |
sum += i.previous();
|
|
347 |
QVERIFY(sum == 2*21);
|
|
348 |
}
|
|
349 |
{
|
|
350 |
QMutableListIterator<int> i(list);
|
|
351 |
i.toBack();
|
|
352 |
while (i.hasPrevious())
|
|
353 |
i.setValue(2*i.previous());
|
|
354 |
}
|
|
355 |
{
|
|
356 |
int sum = 0;
|
|
357 |
QListIterator<int> i(list);
|
|
358 |
i.toBack();
|
|
359 |
while (i.hasPrevious())
|
|
360 |
sum += i.previous();
|
|
361 |
QVERIFY(sum == 2*2*21);
|
|
362 |
}
|
|
363 |
{
|
|
364 |
QMutableListIterator<int> i(list);
|
|
365 |
while (i.hasNext()) {
|
|
366 |
int a = i.next();
|
|
367 |
i.insert(a);
|
|
368 |
}
|
|
369 |
}
|
|
370 |
{
|
|
371 |
int sum = 0;
|
|
372 |
QList<int>::iterator i = list.begin();
|
|
373 |
while (i != list.end())
|
|
374 |
sum += *i++;
|
|
375 |
QVERIFY(sum == 2*2*2*21);
|
|
376 |
}
|
|
377 |
{
|
|
378 |
int duplicates = 0;
|
|
379 |
QListIterator<int> i(list);
|
|
380 |
while (i.hasNext()) {
|
|
381 |
int a = i.next();
|
|
382 |
if (i.hasNext() && a == i.peekNext())
|
|
383 |
duplicates++;
|
|
384 |
}
|
|
385 |
QVERIFY(duplicates == 6);
|
|
386 |
}
|
|
387 |
{
|
|
388 |
int duplicates = 0;
|
|
389 |
QListIterator<int> i(list);
|
|
390 |
i.toBack();
|
|
391 |
while (i.hasPrevious()) {
|
|
392 |
int a = i.previous();
|
|
393 |
if (i.hasPrevious() && a == i.peekPrevious())
|
|
394 |
duplicates++;
|
|
395 |
}
|
|
396 |
QVERIFY(duplicates == 6);
|
|
397 |
}
|
|
398 |
{
|
|
399 |
QMutableListIterator<int> i(list);
|
|
400 |
while (i.hasNext()) {
|
|
401 |
int a = i.next();
|
|
402 |
if (i.hasNext() &&
|
|
403 |
i.peekNext() == a)
|
|
404 |
i.remove();
|
|
405 |
}
|
|
406 |
}
|
|
407 |
{
|
|
408 |
int duplicates = 0;
|
|
409 |
QMutableListIterator<int> i = list;
|
|
410 |
i.toBack();
|
|
411 |
while (i.hasPrevious()) {
|
|
412 |
int a = i.previous();
|
|
413 |
if (i.hasPrevious() && a == i.peekPrevious())
|
|
414 |
duplicates++;
|
|
415 |
}
|
|
416 |
QVERIFY(duplicates == 0);
|
|
417 |
}
|
|
418 |
{
|
|
419 |
QVERIFY(list.size() == 6);
|
|
420 |
QMutableListIterator<int> i = list;
|
|
421 |
while (i.hasNext()) {
|
|
422 |
int a = i.peekNext();
|
|
423 |
i.insert(42);
|
|
424 |
QVERIFY(i.peekPrevious() == 42 && i.peekNext() == a);
|
|
425 |
i.next();
|
|
426 |
}
|
|
427 |
QVERIFY(list.size() == 12);
|
|
428 |
i.toFront();
|
|
429 |
while (i.findNext(42))
|
|
430 |
i.remove();
|
|
431 |
}
|
|
432 |
{
|
|
433 |
QList<int> l;
|
|
434 |
l << 4 << 8 << 12 << 16 << 20 << 24;
|
|
435 |
QVERIFY(l == list);
|
|
436 |
QList<int> copy = list;
|
|
437 |
list += list;
|
|
438 |
QVERIFY(l != list && l.size() == list.size()/2 && l == copy);
|
|
439 |
l += copy;
|
|
440 |
QVERIFY(l == list);
|
|
441 |
list = copy;
|
|
442 |
}
|
|
443 |
{
|
|
444 |
QList<int> copy = list;
|
|
445 |
list << 8;
|
|
446 |
QVERIFY(list.indexOf(8) == 1);
|
|
447 |
QVERIFY(list.indexOf(8, list.indexOf(8)+1) == 6);
|
|
448 |
int a = list.indexOf(8);
|
|
449 |
QVERIFY(list.count(8) == 2);
|
|
450 |
int r = list.removeAll(8);
|
|
451 |
QVERIFY(r == 2);
|
|
452 |
list.insert(a, 8);
|
|
453 |
QVERIFY(list == copy);
|
|
454 |
}
|
|
455 |
{
|
|
456 |
QList<QString> list;
|
|
457 |
list << "one" << "two" << "three" << "four" << "five" << "six";
|
|
458 |
while (!list.isEmpty())
|
|
459 |
list.removeAll(list.first());
|
|
460 |
}
|
|
461 |
{
|
|
462 |
QList<QString> list;
|
|
463 |
list << "one" << "two" << "one" << "two";
|
|
464 |
QVERIFY(!list.removeOne("three"));
|
|
465 |
QVERIFY(list.removeOne("two"));
|
|
466 |
QCOMPARE(list, QList<QString>() << "one" << "one" << "two");;
|
|
467 |
QVERIFY(list.removeOne("two"));
|
|
468 |
QCOMPARE(list, QList<QString>() << "one" << "one");
|
|
469 |
QVERIFY(!list.removeOne("two"));
|
|
470 |
QCOMPARE(list, QList<QString>() << "one" << "one");
|
|
471 |
QVERIFY(list.removeOne("one"));
|
|
472 |
QCOMPARE(list, QList<QString>() << "one");
|
|
473 |
QVERIFY(list.removeOne("one"));
|
|
474 |
QVERIFY(list.isEmpty());
|
|
475 |
QVERIFY(!list.removeOne("one"));
|
|
476 |
QVERIFY(list.isEmpty());
|
|
477 |
}
|
|
478 |
{
|
|
479 |
QList<int> copy = list;
|
|
480 |
list << 8;
|
|
481 |
QVERIFY(list.lastIndexOf(8) == 6);
|
|
482 |
QVERIFY(list.lastIndexOf(8, list.lastIndexOf(8)-1) == 1);
|
|
483 |
list = copy;
|
|
484 |
}
|
|
485 |
{
|
|
486 |
QList<int> copy = list;
|
|
487 |
list.insert(3, 999);
|
|
488 |
QVERIFY(list[3] == 999);
|
|
489 |
list.replace(3, 222);
|
|
490 |
QVERIFY(list[3] == 222);
|
|
491 |
QVERIFY(list.contains(222) && ! list.contains(999));
|
|
492 |
list.removeAt(3);
|
|
493 |
list = copy;
|
|
494 |
QVERIFY(list == copy);
|
|
495 |
}
|
|
496 |
{
|
|
497 |
list.clear();
|
|
498 |
QVERIFY(list.isEmpty());
|
|
499 |
QVERIFY(list.begin() == list.end());
|
|
500 |
QListIterator<int> i(list);
|
|
501 |
QVERIFY(!i.hasNext() && !i.hasPrevious());
|
|
502 |
}
|
|
503 |
{
|
|
504 |
QList<int> l1;
|
|
505 |
QList<int> l2;
|
|
506 |
l1 << 1 << 2 << 3;
|
|
507 |
l2 << 4 << 5 << 6;
|
|
508 |
QList<int> l3 = l1 + l2;
|
|
509 |
l1 += l2;
|
|
510 |
QVERIFY(l3 == l1);
|
|
511 |
}
|
|
512 |
{
|
|
513 |
QList<int> list;
|
|
514 |
QVERIFY(list.isEmpty());
|
|
515 |
list.append(1);
|
|
516 |
QList<int> list2;
|
|
517 |
list2 = list;
|
|
518 |
list2.clear();
|
|
519 |
QVERIFY(list2.size() == 0);
|
|
520 |
QVERIFY(list.size() == 1);
|
|
521 |
}
|
|
522 |
{
|
|
523 |
QList<int> list;
|
|
524 |
list.append(1);
|
|
525 |
list = list;
|
|
526 |
QVERIFY(list.size() == 1);
|
|
527 |
}
|
|
528 |
}
|
|
529 |
{
|
|
530 |
QList<void*> list;
|
|
531 |
list.append(0);
|
|
532 |
list.append((void*)42);
|
|
533 |
QCOMPARE(list.size(), 2);
|
|
534 |
QCOMPARE(list.at(0), (void*)0);
|
|
535 |
QCOMPARE(list.at(1), (void*)42);
|
|
536 |
}
|
|
537 |
|
|
538 |
{
|
|
539 |
QVector<QString> vector(5);
|
|
540 |
vector[0] = "99";
|
|
541 |
vector[4] ="100";
|
|
542 |
QList<QString> list = vector.toList();
|
|
543 |
|
|
544 |
QVERIFY(list.size() == 5);
|
|
545 |
QVERIFY(list.at(0) == "99");
|
|
546 |
QVERIFY(list.at(4) == "100");
|
|
547 |
list[0] = "10";
|
|
548 |
QVERIFY(list.at(0) == "10");
|
|
549 |
QVERIFY(vector.at(0) == "99");
|
|
550 |
|
|
551 |
}
|
|
552 |
|
|
553 |
{
|
|
554 |
QList<QString> list;
|
|
555 |
list.append("Hello");
|
|
556 |
|
|
557 |
QList<QString>::iterator it = list.begin();
|
|
558 |
QVERIFY((*it)[0] == QChar('H'));
|
|
559 |
QVERIFY(it->constData()[0] == QChar('H'));
|
|
560 |
it->replace(QChar('H'), QChar('X'));
|
|
561 |
QVERIFY(list.first() == "Xello");
|
|
562 |
|
|
563 |
QList<QString>::const_iterator cit = list.constBegin();
|
|
564 |
QVERIFY((*cit).toLower() == "xello");
|
|
565 |
QVERIFY(cit->toUpper() == "XELLO");
|
|
566 |
}
|
|
567 |
|
|
568 |
{
|
|
569 |
QList<int *> list;
|
|
570 |
QVERIFY(list.value(0) == 0);
|
|
571 |
int i;
|
|
572 |
list.append(&i);
|
|
573 |
QVERIFY(list.value(0) == &i);
|
|
574 |
}
|
|
575 |
{
|
|
576 |
QList<const int *> list;
|
|
577 |
QVERIFY(list.value(0) == 0);
|
|
578 |
int i;
|
|
579 |
list.append(&i);
|
|
580 |
QVERIFY(list.value(0) == &i);
|
|
581 |
}
|
|
582 |
{
|
|
583 |
QList<int> list;
|
|
584 |
QVERIFY(list.value(0) == 0);
|
|
585 |
list.append(10);
|
|
586 |
QVERIFY(list.value(0) == 10);
|
|
587 |
}
|
|
588 |
{
|
|
589 |
QList<Pod> list;
|
|
590 |
QCOMPARE(list.value(0).i1, 0);
|
|
591 |
QCOMPARE(list.value(0).i2, 0);
|
|
592 |
}
|
|
593 |
|
|
594 |
{
|
|
595 |
QList<QString> list;
|
|
596 |
list << "alpha" << "beta";
|
|
597 |
list += list;
|
|
598 |
QVERIFY(list.size() == 4);
|
|
599 |
QVERIFY(list.at(0) == "alpha");
|
|
600 |
QVERIFY(list.at(1) == "beta");
|
|
601 |
QVERIFY(list.at(2) == "alpha");
|
|
602 |
QVERIFY(list.at(3) == "beta");
|
|
603 |
}
|
|
604 |
|
|
605 |
// test endcases for inserting into a qlist
|
|
606 |
{
|
|
607 |
QList<QString> list;
|
|
608 |
list << "foo" << "bar";
|
|
609 |
QVERIFY(!list.isEmpty());
|
|
610 |
|
|
611 |
list.insert(-1, "lessthanzero");
|
|
612 |
QCOMPARE(list.at(0), QString("lessthanzero"));
|
|
613 |
|
|
614 |
list.insert(0, "atzero");
|
|
615 |
QCOMPARE(list.at(0), QString("atzero"));
|
|
616 |
|
|
617 |
int listCount = list.count();
|
|
618 |
list.insert(listCount, "atcount");
|
|
619 |
QCOMPARE(list.at(listCount), QString("atcount"));
|
|
620 |
|
|
621 |
listCount = list.count();
|
|
622 |
list.insert(listCount + 1, "beyondcount");
|
|
623 |
QCOMPARE(list.at(listCount), QString("beyondcount"));
|
|
624 |
}
|
|
625 |
|
|
626 |
{
|
|
627 |
QList<int> list1;
|
|
628 |
list1 << 0 << 1 << 2 << 3;
|
|
629 |
list1.removeFirst();
|
|
630 |
|
|
631 |
list1.swap(0, 0);
|
|
632 |
QVERIFY(list1 == QList<int>() << 1 << 2 << 3);
|
|
633 |
|
|
634 |
list1.swap(1, 1);
|
|
635 |
QVERIFY(list1 == QList<int>() << 1 << 2 << 3);
|
|
636 |
|
|
637 |
list1.swap(2, 2);
|
|
638 |
QVERIFY(list1 == QList<int>() << 1 << 2 << 3);
|
|
639 |
|
|
640 |
list1.swap(0, 1);
|
|
641 |
QVERIFY(list1 == QList<int>() << 2 << 1 << 3);
|
|
642 |
|
|
643 |
list1.swap(0, 2);
|
|
644 |
QVERIFY(list1 == QList<int>() << 3 << 1 << 2);
|
|
645 |
|
|
646 |
list1.swap(1, 2);
|
|
647 |
QVERIFY(list1 == QList<int>() << 3 << 2 << 1);
|
|
648 |
|
|
649 |
list1.swap(1, 2);
|
|
650 |
QVERIFY(list1 == QList<int>() << 3 << 1 << 2);
|
|
651 |
|
|
652 |
QList<QString> list2;
|
|
653 |
list2 << "1" << "2" << "3";
|
|
654 |
|
|
655 |
list2.swap(0, 0);
|
|
656 |
QVERIFY(list2 == QList<QString>() << "1" << "2" << "3");
|
|
657 |
|
|
658 |
list2.swap(1, 1);
|
|
659 |
QVERIFY(list2 == QList<QString>() << "1" << "2" << "3");
|
|
660 |
|
|
661 |
list2.swap(2, 2);
|
|
662 |
QVERIFY(list2 == QList<QString>() << "1" << "2" << "3");
|
|
663 |
|
|
664 |
list2.swap(0, 1);
|
|
665 |
QVERIFY(list2 == QList<QString>() << "2" << "1" << "3");
|
|
666 |
|
|
667 |
list2.swap(0, 2);
|
|
668 |
QVERIFY(list2 == QList<QString>() << "3" << "1" << "2");
|
|
669 |
|
|
670 |
list2.swap(1, 2);
|
|
671 |
QVERIFY(list2 == QList<QString>() << "3" << "2" << "1");
|
|
672 |
|
|
673 |
list2.swap(1, 2);
|
|
674 |
QVERIFY(list2 == QList<QString>() << "3" << "1" << "2");
|
|
675 |
|
|
676 |
QList<double> list3;
|
|
677 |
list3 << 1.0 << 2.0 << 3.0;
|
|
678 |
|
|
679 |
list3.swap(0, 0);
|
|
680 |
QVERIFY(list3 == QList<double>() << 1.0 << 2.0 << 3.0);
|
|
681 |
|
|
682 |
list3.swap(1, 1);
|
|
683 |
QVERIFY(list3 == QList<double>() << 1.0 << 2.0 << 3.0);
|
|
684 |
|
|
685 |
list3.swap(2, 2);
|
|
686 |
QVERIFY(list3 == QList<double>() << 1.0 << 2.0 << 3.0);
|
|
687 |
|
|
688 |
list3.swap(0, 1);
|
|
689 |
QVERIFY(list3 == QList<double>() << 2.0 << 1.0 << 3.0);
|
|
690 |
|
|
691 |
list3.swap(0, 2);
|
|
692 |
QVERIFY(list3 == QList<double>() << 3.0 << 1.0 << 2.0);
|
|
693 |
|
|
694 |
list3.swap(1, 2);
|
|
695 |
QVERIFY(list3 == QList<double>() << 3.0 << 2.0 << 1.0);
|
|
696 |
|
|
697 |
list3.swap(1, 2);
|
|
698 |
QVERIFY(list3 == QList<double>() << 3.0 << 1.0 << 2.0);
|
|
699 |
}
|
|
700 |
|
|
701 |
// Check what happens when using references to own items.
|
|
702 |
// Ideally we should run valgrind on this.
|
|
703 |
{
|
|
704 |
int i;
|
|
705 |
|
|
706 |
QList<void *> list1;
|
|
707 |
list1.append(reinterpret_cast<void *>(50));
|
|
708 |
|
|
709 |
for (i = 1; i < 100; ++i) {
|
|
710 |
list1.append(list1.at(i - 1));
|
|
711 |
list1.prepend(list1.at(i));
|
|
712 |
list1.insert(i, list1.at(i - 1));
|
|
713 |
list1.insert(i, list1.at(i));
|
|
714 |
list1.insert(i, list1.at(i + 1));
|
|
715 |
list1.replace(i, list1.at(i - 1));
|
|
716 |
list1.replace(i, list1.at(i));
|
|
717 |
list1.replace(i, list1.at(i + 1));
|
|
718 |
}
|
|
719 |
QCOMPARE(list1.size(), 496);
|
|
720 |
for (i = 0; i < list1.size(); ++i) {
|
|
721 |
QCOMPARE(list1.at(i), reinterpret_cast<void *>(50));
|
|
722 |
}
|
|
723 |
|
|
724 |
QList<QString> list2;
|
|
725 |
list2.append("50");
|
|
726 |
|
|
727 |
for (i = 1; i < 100; ++i) {
|
|
728 |
list2.append(list2.at(i - 1));
|
|
729 |
list2.prepend(list2.at(i));
|
|
730 |
list2.insert(i, list2.at(i - 1));
|
|
731 |
list2.insert(i, list2.at(i));
|
|
732 |
list2.insert(i, list2.at(i + 1));
|
|
733 |
list2.replace(i, list2.at(i - 1));
|
|
734 |
list2.replace(i, list2.at(i));
|
|
735 |
list2.replace(i, list2.at(i + 1));
|
|
736 |
}
|
|
737 |
QCOMPARE(list2.size(), 496);
|
|
738 |
for (i = 0; i < list2.size(); ++i) {
|
|
739 |
QCOMPARE(list2.at(i), QString::fromLatin1("50"));
|
|
740 |
}
|
|
741 |
|
|
742 |
QList<double> list3;
|
|
743 |
list3.append(50.0);
|
|
744 |
|
|
745 |
for (i = 1; i < 100; ++i) {
|
|
746 |
list3.append(list3.at(i - 1));
|
|
747 |
list3.prepend(list3.at(i));
|
|
748 |
list3.insert(i, list3.at(i - 1));
|
|
749 |
list3.insert(i, list3.at(i));
|
|
750 |
list3.insert(i, list3.at(i + 1));
|
|
751 |
list3.replace(i, list3.at(i - 1));
|
|
752 |
list3.replace(i, list3.at(i));
|
|
753 |
list3.replace(i, list3.at(i + 1));
|
|
754 |
}
|
|
755 |
QCOMPARE(list3.size(), 496);
|
|
756 |
for (i = 0; i < list3.size(); ++i) {
|
|
757 |
QCOMPARE(list3.at(i), 50.0);
|
|
758 |
}
|
|
759 |
|
|
760 |
QList<QTime> list4;
|
|
761 |
list4.append(QTime(12, 34, 56));
|
|
762 |
|
|
763 |
for (i = 1; i < 100; ++i) {
|
|
764 |
list4.append(list4.at(i - 1));
|
|
765 |
list4.prepend(list4.at(i));
|
|
766 |
list4.insert(i, list4.at(i - 1));
|
|
767 |
list4.insert(i, list4.at(i));
|
|
768 |
list4.insert(i, list4.at(i + 1));
|
|
769 |
list4.replace(i, list4.at(i - 1));
|
|
770 |
list4.replace(i, list4.at(i));
|
|
771 |
list4.replace(i, list4.at(i + 1));
|
|
772 |
}
|
|
773 |
QCOMPARE(list4.size(), 496);
|
|
774 |
for (i = 0; i < list4.size(); ++i) {
|
|
775 |
QVERIFY(list4.at(i) == QTime(12, 34, 56));
|
|
776 |
}
|
|
777 |
|
|
778 |
}
|
|
779 |
{
|
|
780 |
QList<int> a;
|
|
781 |
QCOMPARE(a.startsWith(1), false);
|
|
782 |
QCOMPARE(a.endsWith(1), false);
|
|
783 |
a.append(1);
|
|
784 |
QCOMPARE(a.startsWith(1), true);
|
|
785 |
QCOMPARE(a.startsWith(2), false);
|
|
786 |
QCOMPARE(a.endsWith(1), true);
|
|
787 |
QCOMPARE(a.endsWith(2), false);
|
|
788 |
a.append(2);
|
|
789 |
QCOMPARE(a.startsWith(1), true);
|
|
790 |
QCOMPARE(a.startsWith(2), false);
|
|
791 |
QCOMPARE(a.endsWith(1), false);
|
|
792 |
QCOMPARE(a.endsWith(2), true);
|
|
793 |
}
|
|
794 |
}
|
|
795 |
|
|
796 |
void tst_Collections::linkedList()
|
|
797 |
{
|
|
798 |
{
|
|
799 |
QLinkedList<int> list;
|
|
800 |
QVERIFY(list.isEmpty());
|
|
801 |
list.append(1);
|
|
802 |
list.push_back(2);
|
|
803 |
list += (3);
|
|
804 |
list << 4 << 5 << 6;
|
|
805 |
QVERIFY(!list.isEmpty());
|
|
806 |
QVERIFY(list.size() == 6);
|
|
807 |
{
|
|
808 |
int sum = 0;
|
|
809 |
QLinkedListIterator<int> i = list;
|
|
810 |
while (i.hasNext()) {
|
|
811 |
sum += i.next();
|
|
812 |
}
|
|
813 |
QVERIFY(sum == 21);
|
|
814 |
}
|
|
815 |
{
|
|
816 |
int sum = 0;
|
|
817 |
QLinkedList<int>::const_iterator i = list.begin();
|
|
818 |
while (i != list.end())
|
|
819 |
sum += *i++;
|
|
820 |
QVERIFY(sum == 21);
|
|
821 |
}
|
|
822 |
{
|
|
823 |
QMutableLinkedListIterator<int> i = list;
|
|
824 |
while (i.hasNext())
|
|
825 |
i.setValue(2*i.next());
|
|
826 |
}
|
|
827 |
{
|
|
828 |
int sum = 0;
|
|
829 |
QLinkedListIterator<int> i = list;
|
|
830 |
i.toBack();
|
|
831 |
while (i.hasPrevious())
|
|
832 |
sum += i.previous();
|
|
833 |
QVERIFY(sum == 2*21);
|
|
834 |
}
|
|
835 |
{
|
|
836 |
QMutableLinkedListIterator<int> i = list;
|
|
837 |
i.toBack();
|
|
838 |
while (i.hasPrevious())
|
|
839 |
i.setValue(2*i.previous());
|
|
840 |
}
|
|
841 |
{
|
|
842 |
int sum = 0;
|
|
843 |
QLinkedListIterator<int> i = list;
|
|
844 |
i.toBack();
|
|
845 |
while (i.hasPrevious())
|
|
846 |
sum += i.previous();
|
|
847 |
QVERIFY(sum == 2*2*21);
|
|
848 |
}
|
|
849 |
{
|
|
850 |
QMutableLinkedListIterator<int> i = list;
|
|
851 |
while (i.hasNext()) {
|
|
852 |
int a = i.next();
|
|
853 |
i.insert(a);
|
|
854 |
}
|
|
855 |
}
|
|
856 |
{
|
|
857 |
int sum = 0;
|
|
858 |
QLinkedList<int>::iterator i = list.begin();
|
|
859 |
while (i != list.end())
|
|
860 |
sum += *i++;
|
|
861 |
QVERIFY(sum == 2*2*2*21);
|
|
862 |
}
|
|
863 |
{
|
|
864 |
int duplicates = 0;
|
|
865 |
QLinkedListIterator<int> i = list;
|
|
866 |
while (i.hasNext()) {
|
|
867 |
int a = i.next();
|
|
868 |
if (i.hasNext() && a == i.peekNext())
|
|
869 |
duplicates++;
|
|
870 |
}
|
|
871 |
QVERIFY(duplicates == 6);
|
|
872 |
}
|
|
873 |
{
|
|
874 |
int duplicates = 0;
|
|
875 |
QLinkedListIterator<int> i = list;
|
|
876 |
i.toBack();
|
|
877 |
while (i.hasPrevious()) {
|
|
878 |
int a = i.previous();
|
|
879 |
if (i.hasPrevious() && a == i.peekPrevious())
|
|
880 |
duplicates++;
|
|
881 |
}
|
|
882 |
QVERIFY(duplicates == 6);
|
|
883 |
}
|
|
884 |
{
|
|
885 |
QMutableLinkedListIterator<int> i = list;
|
|
886 |
while (i.hasNext()) {
|
|
887 |
int a = i.next();
|
|
888 |
if (i.hasNext() &&
|
|
889 |
i.peekNext() == a)
|
|
890 |
i.remove();
|
|
891 |
}
|
|
892 |
}
|
|
893 |
{
|
|
894 |
int duplicates = 0;
|
|
895 |
QMutableLinkedListIterator<int> i = list;
|
|
896 |
i.toBack();
|
|
897 |
while (i.hasPrevious()) {
|
|
898 |
int a = i.previous();
|
|
899 |
if (i.hasPrevious() && a == i.peekPrevious())
|
|
900 |
duplicates++;
|
|
901 |
}
|
|
902 |
QVERIFY(duplicates == 0);
|
|
903 |
}
|
|
904 |
{
|
|
905 |
QVERIFY(list.size() == 6);
|
|
906 |
QMutableLinkedListIterator<int> i = list;
|
|
907 |
while (i.hasNext()) {
|
|
908 |
int a = i.peekNext();
|
|
909 |
i.insert(42);
|
|
910 |
QVERIFY(i.peekPrevious() == 42 && i.peekNext() == a);
|
|
911 |
i.next();
|
|
912 |
}
|
|
913 |
QVERIFY(list.size() == 12);
|
|
914 |
i.toFront();
|
|
915 |
while (i.findNext(42))
|
|
916 |
i.remove();
|
|
917 |
}
|
|
918 |
{
|
|
919 |
QLinkedList<int> l;
|
|
920 |
l << 4 << 8 << 12 << 16 << 20 << 24;
|
|
921 |
QVERIFY(l == list);
|
|
922 |
QLinkedList<int> copy = list;
|
|
923 |
list += list;
|
|
924 |
QVERIFY(l != list && l.size() == list.size()/2 && l == copy);
|
|
925 |
l += copy;
|
|
926 |
QVERIFY(l == list);
|
|
927 |
list = copy;
|
|
928 |
}
|
|
929 |
{
|
|
930 |
QLinkedList<int> copy = list;
|
|
931 |
list.prepend(999);
|
|
932 |
list.append(999);
|
|
933 |
QVERIFY(list.contains(999));
|
|
934 |
QVERIFY(list.count(999) == 2);
|
|
935 |
list.removeAll(999);
|
|
936 |
QVERIFY(list == copy);
|
|
937 |
}
|
|
938 |
{
|
|
939 |
QLinkedList<QString> list;
|
|
940 |
list << "one" << "two" << "three" << "four" << "five" << "six";
|
|
941 |
while (!list.isEmpty())
|
|
942 |
list.removeAll(list.first());
|
|
943 |
}
|
|
944 |
{
|
|
945 |
QLinkedList<QString> list;
|
|
946 |
list << "one" << "two" << "one" << "two";
|
|
947 |
QVERIFY(!list.removeOne("three"));
|
|
948 |
QVERIFY(list.removeOne("two"));
|
|
949 |
QCOMPARE(list, QLinkedList<QString>() << "one" << "one" << "two");;
|
|
950 |
QVERIFY(list.removeOne("two"));
|
|
951 |
QCOMPARE(list, QLinkedList<QString>() << "one" << "one");
|
|
952 |
QVERIFY(!list.removeOne("two"));
|
|
953 |
QCOMPARE(list, QLinkedList<QString>() << "one" << "one");
|
|
954 |
QVERIFY(list.removeOne("one"));
|
|
955 |
QCOMPARE(list, QLinkedList<QString>() << "one");
|
|
956 |
QVERIFY(list.removeOne("one"));
|
|
957 |
QVERIFY(list.isEmpty());
|
|
958 |
QVERIFY(!list.removeOne("one"));
|
|
959 |
QVERIFY(list.isEmpty());
|
|
960 |
}
|
|
961 |
{
|
|
962 |
list.clear();
|
|
963 |
QVERIFY(list.isEmpty());
|
|
964 |
QVERIFY(list.begin() == list.end());
|
|
965 |
QLinkedListIterator<int> i(list);
|
|
966 |
QVERIFY(!i.hasNext() && !i.hasPrevious());
|
|
967 |
}
|
|
968 |
}
|
|
969 |
|
|
970 |
{
|
|
971 |
QLinkedList<QString> list;
|
|
972 |
list.append("Hello");
|
|
973 |
|
|
974 |
QLinkedList<QString>::iterator it = list.begin();
|
|
975 |
QVERIFY((*it)[0] == QChar('H'));
|
|
976 |
QVERIFY(it->constData()[0] == QChar('H'));
|
|
977 |
it->replace(QChar('H'), QChar('X'));
|
|
978 |
QVERIFY(list.first() == "Xello");
|
|
979 |
|
|
980 |
QLinkedList<QString>::const_iterator cit = list.constBegin();
|
|
981 |
QVERIFY((*cit).toLower() == "xello");
|
|
982 |
QVERIFY(cit->toUpper() == "XELLO");
|
|
983 |
}
|
|
984 |
|
|
985 |
{
|
|
986 |
QLinkedList<QString> list;
|
|
987 |
list << "alpha" << "beta";
|
|
988 |
list += list;
|
|
989 |
QVERIFY(list.size() == 4);
|
|
990 |
QVERIFY(*list.begin() == "alpha");
|
|
991 |
QVERIFY(*(list.begin() + 1) == "beta");
|
|
992 |
QVERIFY(*(list.begin() + 2) == "alpha");
|
|
993 |
QVERIFY(*(list.begin() + 3) == "beta");
|
|
994 |
}
|
|
995 |
|
|
996 |
{
|
|
997 |
QLinkedList<int> a;
|
|
998 |
QCOMPARE(a.startsWith(1), false);
|
|
999 |
QCOMPARE(a.endsWith(1), false);
|
|
1000 |
a.append(1);
|
|
1001 |
QCOMPARE(a.startsWith(1), true);
|
|
1002 |
QCOMPARE(a.startsWith(2), false);
|
|
1003 |
QCOMPARE(a.endsWith(1), true);
|
|
1004 |
QCOMPARE(a.endsWith(2), false);
|
|
1005 |
a.append(2);
|
|
1006 |
QCOMPARE(a.startsWith(1), true);
|
|
1007 |
QCOMPARE(a.startsWith(2), false);
|
|
1008 |
QCOMPARE(a.endsWith(1), false);
|
|
1009 |
QCOMPARE(a.endsWith(2), true);
|
|
1010 |
}
|
|
1011 |
};
|
|
1012 |
|
|
1013 |
|
|
1014 |
void tst_Collections::vector()
|
|
1015 |
{
|
|
1016 |
QVector<int> v1;
|
|
1017 |
v1 << 1 << 2 << 3;
|
|
1018 |
QVector<int> v2;
|
|
1019 |
v2 << 4 << 5;
|
|
1020 |
QVector<int> v3;
|
|
1021 |
v3 << 1 << 2 << 3 << 4 << 5;
|
|
1022 |
QVERIFY(v1 + v2 == v3);
|
|
1023 |
|
|
1024 |
QVector<int> emptyVector;
|
|
1025 |
QCOMPARE(emptyVector.size(), 0);
|
|
1026 |
#if 0
|
|
1027 |
// this should trigger an assert
|
|
1028 |
emptyVector.remove(3, -3);
|
|
1029 |
QCOMPARE(emptyVector.size(), 0);
|
|
1030 |
#endif
|
|
1031 |
emptyVector.remove(0, 0);
|
|
1032 |
QCOMPARE(emptyVector.size(), 0);
|
|
1033 |
|
|
1034 |
QVector<int> v4;
|
|
1035 |
v4 << 1 << 2 << 3;
|
|
1036 |
QCOMPARE(v4.size(), 3);
|
|
1037 |
v4.remove(1, 0);
|
|
1038 |
QCOMPARE(v4.size(), 3);
|
|
1039 |
|
|
1040 |
QVector<int> v;
|
|
1041 |
v.append(2);
|
|
1042 |
QVERIFY(*v.begin() == 2);
|
|
1043 |
v.prepend(1);
|
|
1044 |
|
|
1045 |
v << 3 << 4 << 5 << 6;
|
|
1046 |
#if !defined(QT_NO_STL)
|
|
1047 |
QVERIFY(std::binary_search(v.begin(), v.end(), 2) == true);
|
|
1048 |
QVERIFY(std::binary_search(v.begin(), v.end(), 9) == false);
|
|
1049 |
#endif
|
|
1050 |
QVERIFY(qBinaryFind(v.begin(), v.end(), 2) == v.begin() + 1);
|
|
1051 |
QVERIFY(qLowerBound(v.begin(), v.end(), 2) == v.begin() + 1);
|
|
1052 |
QVERIFY(qUpperBound(v.begin(), v.end(), 2) == v.begin() + 2);
|
|
1053 |
QVERIFY(qBinaryFind(v.begin(), v.end(), 9) == v.end());
|
|
1054 |
QVERIFY(qLowerBound(v.begin(), v.end(), 9) == v.end());
|
|
1055 |
QVERIFY(qUpperBound(v.begin(), v.end(), 9) == v.end());
|
|
1056 |
|
|
1057 |
v.clear();
|
|
1058 |
v << 1 << 2 << 3;
|
|
1059 |
v.insert(v.begin(), 0);
|
|
1060 |
v.insert(v.end(), 4);
|
|
1061 |
v.insert(v.begin()+2, 9);
|
|
1062 |
|
|
1063 |
QVector<int> result;
|
|
1064 |
result << 0 << 1 << 9 << 2 << 3 << 4;
|
|
1065 |
|
|
1066 |
QVERIFY( v == result );
|
|
1067 |
|
|
1068 |
v.clear();
|
|
1069 |
v << 1 << 2 << 3;
|
|
1070 |
v.insert(0, 0);
|
|
1071 |
v.insert(4, 4);
|
|
1072 |
v.insert(2, 9);
|
|
1073 |
|
|
1074 |
QVERIFY( v == result );
|
|
1075 |
|
|
1076 |
QVector<QString> vec;
|
|
1077 |
vec << "foo" << "bar";
|
|
1078 |
vec.reserve( 512 );
|
|
1079 |
QVERIFY(vec[0] == "foo");
|
|
1080 |
QVERIFY(vec[1] == "bar");
|
|
1081 |
|
|
1082 |
int initialLargeStaticCount = LargeStatic::count;
|
|
1083 |
{
|
|
1084 |
QVector<LargeStatic> vector;
|
|
1085 |
vector.append(LargeStatic());
|
|
1086 |
vector.resize(0);
|
|
1087 |
}
|
|
1088 |
QCOMPARE(LargeStatic::count, initialLargeStaticCount);
|
|
1089 |
|
|
1090 |
{
|
|
1091 |
QVector<QString> vector;
|
|
1092 |
vector << "alpha" << "beta";
|
|
1093 |
vector += vector;
|
|
1094 |
QVERIFY(vector.size() == 4);
|
|
1095 |
QVERIFY(vector.at(0) == "alpha");
|
|
1096 |
QVERIFY(vector.at(1) == "beta");
|
|
1097 |
QVERIFY(vector.at(2) == "alpha");
|
|
1098 |
QVERIFY(vector.at(3) == "beta");
|
|
1099 |
}
|
|
1100 |
|
|
1101 |
int originalLargeStaticCount = LargeStatic::count;
|
|
1102 |
{
|
|
1103 |
QVector<LargeStatic> vector(5);
|
|
1104 |
}
|
|
1105 |
QVERIFY(LargeStatic::count == originalLargeStaticCount);
|
|
1106 |
{
|
|
1107 |
QVector<LargeStatic> vector(5);
|
|
1108 |
QList<LargeStatic> list = vector.toList();
|
|
1109 |
}
|
|
1110 |
QVERIFY(LargeStatic::count == originalLargeStaticCount);
|
|
1111 |
{
|
|
1112 |
QVector<LargeStatic> vector;
|
|
1113 |
LargeStatic *dummy = 0;
|
|
1114 |
for (int i = 0; i < 10000; ++i) {
|
|
1115 |
delete dummy;
|
|
1116 |
dummy = new LargeStatic;
|
|
1117 |
vector.append(LargeStatic());
|
|
1118 |
}
|
|
1119 |
delete dummy;
|
|
1120 |
}
|
|
1121 |
QVERIFY(LargeStatic::count == originalLargeStaticCount);
|
|
1122 |
|
|
1123 |
int originalMovableCount = Movable::count;
|
|
1124 |
{
|
|
1125 |
QVector<Movable> vector(5);
|
|
1126 |
}
|
|
1127 |
QVERIFY(Movable::count == originalMovableCount);
|
|
1128 |
{
|
|
1129 |
QVector<Movable> vector(5);
|
|
1130 |
QList<Movable> list = vector.toList();
|
|
1131 |
}
|
|
1132 |
QVERIFY(Movable::count == originalMovableCount);
|
|
1133 |
{
|
|
1134 |
QVector<Movable> vector;
|
|
1135 |
Movable *dummy = 0;
|
|
1136 |
for (int i = 0; i < 10000; ++i) {
|
|
1137 |
delete dummy;
|
|
1138 |
dummy = new Movable;
|
|
1139 |
vector.append(Movable());
|
|
1140 |
}
|
|
1141 |
delete dummy;
|
|
1142 |
}
|
|
1143 |
QVERIFY(Movable::count == originalMovableCount);
|
|
1144 |
|
|
1145 |
// Check what happens when using references to own items.
|
|
1146 |
// Ideally we should run valgrind on this.
|
|
1147 |
{
|
|
1148 |
int i;
|
|
1149 |
|
|
1150 |
QVector<void *> vect1;
|
|
1151 |
vect1.append(reinterpret_cast<void *>(50));
|
|
1152 |
|
|
1153 |
for (i = 1; i < 100; ++i) {
|
|
1154 |
vect1.append(vect1.at(i - 1));
|
|
1155 |
vect1.prepend(vect1.at(i));
|
|
1156 |
vect1.insert(i, vect1.at(i - 1));
|
|
1157 |
vect1.insert(i, vect1.at(i));
|
|
1158 |
vect1.insert(i, vect1.at(i + 1));
|
|
1159 |
vect1.replace(i, vect1.at(i - 1));
|
|
1160 |
vect1.replace(i, vect1.at(i));
|
|
1161 |
vect1.replace(i, vect1.at(i + 1));
|
|
1162 |
}
|
|
1163 |
QCOMPARE(vect1.size(), 496);
|
|
1164 |
for (i = 0; i < vect1.size(); ++i) {
|
|
1165 |
QCOMPARE(vect1.at(i), reinterpret_cast<void *>(50));
|
|
1166 |
}
|
|
1167 |
|
|
1168 |
QVector<QString> vect2;
|
|
1169 |
vect2.append("50");
|
|
1170 |
|
|
1171 |
for (i = 1; i < 100; ++i) {
|
|
1172 |
vect2.append(vect2.at(i - 1));
|
|
1173 |
vect2.prepend(vect2.at(i));
|
|
1174 |
vect2.insert(i, vect2.at(i - 1));
|
|
1175 |
vect2.insert(i, vect2.at(i));
|
|
1176 |
vect2.insert(i, vect2.at(i + 1));
|
|
1177 |
vect2.replace(i, vect2.at(i - 1));
|
|
1178 |
vect2.replace(i, vect2.at(i));
|
|
1179 |
vect2.replace(i, vect2.at(i + 1));
|
|
1180 |
}
|
|
1181 |
QCOMPARE(vect2.size(), 496);
|
|
1182 |
for (i = 0; i < vect2.size(); ++i) {
|
|
1183 |
QCOMPARE(vect2.at(i), QString::fromLatin1("50"));
|
|
1184 |
}
|
|
1185 |
|
|
1186 |
QVector<double> vect3;
|
|
1187 |
vect3.append(50.0);
|
|
1188 |
|
|
1189 |
for (i = 1; i < 100; ++i) {
|
|
1190 |
vect3.append(vect3.at(i - 1));
|
|
1191 |
vect3.prepend(vect3.at(i));
|
|
1192 |
vect3.insert(i, vect3.at(i - 1));
|
|
1193 |
vect3.insert(i, vect3.at(i));
|
|
1194 |
vect3.insert(i, vect3.at(i + 1));
|
|
1195 |
vect3.replace(i, vect3.at(i - 1));
|
|
1196 |
vect3.replace(i, vect3.at(i));
|
|
1197 |
vect3.replace(i, vect3.at(i + 1));
|
|
1198 |
}
|
|
1199 |
QCOMPARE(vect3.size(), 496);
|
|
1200 |
for (i = 0; i < vect3.size(); ++i) {
|
|
1201 |
QCOMPARE(vect3.at(i), 50.0);
|
|
1202 |
}
|
|
1203 |
|
|
1204 |
QVector<QTime> vect4;
|
|
1205 |
vect4.append(QTime(12, 34, 56));
|
|
1206 |
|
|
1207 |
for (i = 1; i < 100; ++i) {
|
|
1208 |
vect4.append(vect4.at(i - 1));
|
|
1209 |
vect4.prepend(vect4.at(i));
|
|
1210 |
vect4.insert(i, vect4.at(i - 1));
|
|
1211 |
vect4.insert(i, vect4.at(i));
|
|
1212 |
vect4.insert(i, vect4.at(i + 1));
|
|
1213 |
vect4.replace(i, vect4.at(i - 1));
|
|
1214 |
vect4.replace(i, vect4.at(i));
|
|
1215 |
vect4.replace(i, vect4.at(i + 1));
|
|
1216 |
}
|
|
1217 |
QCOMPARE(vect4.size(), 496);
|
|
1218 |
for (i = 0; i < vect4.size(); ++i) {
|
|
1219 |
QVERIFY(vect4.at(i) == QTime(12, 34, 56));
|
|
1220 |
}
|
|
1221 |
}
|
|
1222 |
|
|
1223 |
// this used to trigger an unitialized read in valgrind
|
|
1224 |
QVector<char> foo;
|
|
1225 |
foo.resize(144);
|
|
1226 |
|
|
1227 |
{
|
|
1228 |
QVector<int> a;
|
|
1229 |
QCOMPARE(a.startsWith(1), false);
|
|
1230 |
QCOMPARE(a.endsWith(1), false);
|
|
1231 |
a.append(1);
|
|
1232 |
QCOMPARE(a.startsWith(1), true);
|
|
1233 |
QCOMPARE(a.startsWith(2), false);
|
|
1234 |
QCOMPARE(a.endsWith(1), true);
|
|
1235 |
QCOMPARE(a.endsWith(2), false);
|
|
1236 |
a.append(2);
|
|
1237 |
QCOMPARE(a.startsWith(1), true);
|
|
1238 |
QCOMPARE(a.startsWith(2), false);
|
|
1239 |
QCOMPARE(a.endsWith(1), false);
|
|
1240 |
QCOMPARE(a.endsWith(2), true);
|
|
1241 |
}
|
|
1242 |
}
|
|
1243 |
|
|
1244 |
void tst_Collections::byteArray()
|
|
1245 |
{
|
|
1246 |
QByteArray hello = "hello";
|
|
1247 |
QByteArray ello = "ello";
|
|
1248 |
QByteArray World = "World";
|
|
1249 |
QByteArray Wor = "Wor";
|
|
1250 |
QByteArray helloWorld = "helloWorld";
|
|
1251 |
QVERIFY(hello + World == helloWorld);
|
|
1252 |
QVERIFY(hello + "World" == helloWorld);
|
|
1253 |
QVERIFY("hello" + World == helloWorld);
|
|
1254 |
|
|
1255 |
|
|
1256 |
QByteArray l;
|
|
1257 |
QVERIFY('h' + ello == hello);
|
|
1258 |
QVERIFY(Wor + 'l' + 'd' == "World");
|
|
1259 |
QVERIFY(hello + World == "helloWorld");
|
|
1260 |
QVERIFY(hello + "World" == "helloWorld");
|
|
1261 |
QVERIFY("hello" + World == "helloWorld");
|
|
1262 |
QVERIFY('h' + ello == "hello");
|
|
1263 |
QVERIFY(Wor + 'l' + 'd' == "World");
|
|
1264 |
QVERIFY("helloWorld" == hello + World);
|
|
1265 |
QVERIFY("helloWorld" == hello + "World");
|
|
1266 |
QVERIFY("helloWorld" == "hello" + World);
|
|
1267 |
QVERIFY("hello" == 'h' + ello);
|
|
1268 |
QVERIFY("World" == Wor + 'l' + 'd');
|
|
1269 |
|
|
1270 |
QVERIFY(hello.contains('e'));
|
|
1271 |
QVERIFY (true == hello.contains('e'));
|
|
1272 |
QVERIFY (hello.contains('e') != false);
|
|
1273 |
|
|
1274 |
QVERIFY(hello.indexOf('e') == 1);
|
|
1275 |
QVERIFY(hello.indexOf('e', -10) == 1);
|
|
1276 |
QVERIFY(hello.indexOf('l') == 2);
|
|
1277 |
QVERIFY(hello.indexOf('l',2) == 2);
|
|
1278 |
QVERIFY(hello.indexOf('l',3) == 3);
|
|
1279 |
|
|
1280 |
QByteArray large = "000 100 200 300 400 500 600 700 800 900";
|
|
1281 |
|
|
1282 |
QVERIFY(large.indexOf("700") == 28);
|
|
1283 |
QVERIFY(large.indexOf("700", 28) == 28);
|
|
1284 |
QVERIFY(large.indexOf("700", 29) == -1);
|
|
1285 |
QVERIFY(large.lastIndexOf("700") == 28);
|
|
1286 |
QVERIFY(large.lastIndexOf("700", 28) == 28);
|
|
1287 |
QVERIFY(large.lastIndexOf("700", 27) == -1);
|
|
1288 |
|
|
1289 |
QVERIFY(large.contains("200"));
|
|
1290 |
QVERIFY(!large.contains("201"));
|
|
1291 |
QVERIFY(large.contains('3'));
|
|
1292 |
QVERIFY(!large.contains('a'));
|
|
1293 |
|
|
1294 |
QVERIFY(large.count("00") == 11);
|
|
1295 |
QVERIFY(large.count('3') == 1);
|
|
1296 |
QVERIFY(large.count('0') == 21);
|
|
1297 |
QVERIFY(large.count("0") == 21);
|
|
1298 |
QVERIFY(large.count("200") == 1);
|
|
1299 |
QVERIFY(large.count("201") == 0);
|
|
1300 |
|
|
1301 |
QVERIFY(hello.left(0) == "");
|
|
1302 |
QVERIFY(!hello.left(0).isNull());
|
|
1303 |
QVERIFY(hello.left(1) == "h");
|
|
1304 |
QVERIFY(hello.left(2) == "he");
|
|
1305 |
QVERIFY(hello.left(200) == "hello");
|
|
1306 |
QVERIFY(hello.left(hello.size()) == hello);
|
|
1307 |
QVERIFY(hello.left(hello.size()+1) == hello);
|
|
1308 |
|
|
1309 |
QVERIFY(hello.right(0) == "");
|
|
1310 |
QVERIFY(!hello.right(0).isNull());
|
|
1311 |
QVERIFY(hello.right(1) == "o");
|
|
1312 |
QVERIFY(hello.right(2) == "lo");
|
|
1313 |
QVERIFY(hello.right(200) == "hello");
|
|
1314 |
QVERIFY(hello.right(hello.size()) == hello);
|
|
1315 |
QVERIFY(hello.right(hello.size()+1) == hello);
|
|
1316 |
|
|
1317 |
QVERIFY(!hello.mid(0, 0).isNull());
|
|
1318 |
QVERIFY(hello.mid(0, 1) == "h");
|
|
1319 |
QVERIFY(hello.mid(0, 2) == "he");
|
|
1320 |
QVERIFY(hello.mid(0, 200) == "hello");
|
|
1321 |
QVERIFY(hello.mid(0) == "hello");
|
|
1322 |
QVERIFY(hello.mid(0, hello.size()) == hello);
|
|
1323 |
QVERIFY(hello.mid(0, hello.size()+1) == hello);
|
|
1324 |
|
|
1325 |
QVERIFY(hello.mid(hello.size()-0) == "");
|
|
1326 |
|
|
1327 |
QVERIFY(hello.mid(hello.size()-0).isNull()); // weird but valid 3.x semantics
|
|
1328 |
QVERIFY(hello.mid(hello.size()-1) == "o");
|
|
1329 |
QVERIFY(hello.mid(hello.size()-2) == "lo");
|
|
1330 |
QVERIFY(hello.mid(hello.size()-200) == "hello");
|
|
1331 |
|
|
1332 |
QByteArray null;
|
|
1333 |
QByteArray nonNull = "";
|
|
1334 |
QVERIFY(null.left(10).isNull());
|
|
1335 |
QVERIFY(null.mid(0).isNull());
|
|
1336 |
|
|
1337 |
#if 0
|
|
1338 |
QVERIFY(null == QByteArray::null);
|
|
1339 |
QVERIFY(QByteArray::null == null);
|
|
1340 |
QVERIFY(nonNull != QByteArray::null);
|
|
1341 |
QVERIFY(QByteArray::null != nonNull);
|
|
1342 |
QVERIFY(null == nonNull);
|
|
1343 |
QVERIFY(QByteArray::null == QByteArray::null);
|
|
1344 |
#endif
|
|
1345 |
|
|
1346 |
QByteArray str = "Hello";
|
|
1347 |
QByteArray cstr(str.data(), str.size());
|
|
1348 |
QVERIFY(str == "Hello");
|
|
1349 |
QVERIFY(cstr == "Hello");
|
|
1350 |
cstr.clear();
|
|
1351 |
QVERIFY(str == "Hello");
|
|
1352 |
QVERIFY(cstr.isEmpty());
|
|
1353 |
|
|
1354 |
{
|
|
1355 |
QByteArray ba1("Foo");
|
|
1356 |
ba1.prepend(ba1);
|
|
1357 |
QCOMPARE(ba1, QByteArray("FooFoo"));
|
|
1358 |
ba1.append(ba1);
|
|
1359 |
QCOMPARE(ba1, QByteArray("FooFooFooFoo"));
|
|
1360 |
ba1.insert(2, ba1);
|
|
1361 |
QCOMPARE(ba1, QByteArray("FoFooFooFooFoooFooFooFoo"));
|
|
1362 |
ba1.replace(3, 3, ba1);
|
|
1363 |
QCOMPARE(ba1, QByteArray("FoFFoFooFooFooFoooFooFooFooooFooFoooFooFooFoo"));
|
|
1364 |
ba1 = "FooFoo";
|
|
1365 |
ba1.replace(char('F'), ba1);
|
|
1366 |
QCOMPARE(ba1, QByteArray("FooFooooFooFoooo"));
|
|
1367 |
ba1 = "FooFoo";
|
|
1368 |
ba1.replace(char('o'), ba1);
|
|
1369 |
QCOMPARE(ba1, QByteArray("FFooFooFooFooFFooFooFooFoo"));
|
|
1370 |
|
|
1371 |
ba1.replace(ba1, "xxx");
|
|
1372 |
QCOMPARE(ba1, QByteArray("xxx"));
|
|
1373 |
ba1.replace(ba1, QByteArray("yyy"));
|
|
1374 |
QCOMPARE(ba1, QByteArray("yyy"));
|
|
1375 |
ba1 += ba1;
|
|
1376 |
QCOMPARE(ba1, QByteArray("yyyyyy"));
|
|
1377 |
|
|
1378 |
ba1.remove(1, -1); // do nothing
|
|
1379 |
QCOMPARE(ba1, QByteArray("yyyyyy"));
|
|
1380 |
|
|
1381 |
ba1.replace(0, -1, "ZZZ");
|
|
1382 |
QCOMPARE(ba1, QByteArray("ZZZyyyyyy"));
|
|
1383 |
}
|
|
1384 |
};
|
|
1385 |
|
|
1386 |
void tst_Collections::stack()
|
|
1387 |
{
|
|
1388 |
QStack<int> stack;
|
|
1389 |
stack.push(1);
|
|
1390 |
stack.push(2);
|
|
1391 |
stack.push(3);
|
|
1392 |
QVectorIterator<int> i = stack;
|
|
1393 |
i.toBack();
|
|
1394 |
int sum = 0;
|
|
1395 |
while (i.hasPrevious())
|
|
1396 |
sum += i.previous();
|
|
1397 |
QVERIFY(sum == 6);
|
|
1398 |
|
|
1399 |
sum = 0;
|
|
1400 |
for (QStack<int>::iterator i = stack.begin(); i != stack.end(); ++i)
|
|
1401 |
sum += *i;
|
|
1402 |
QVERIFY(sum == 6);
|
|
1403 |
|
|
1404 |
while (!stack.isEmpty())
|
|
1405 |
sum -= stack.pop();
|
|
1406 |
QVERIFY(sum == 0);
|
|
1407 |
}
|
|
1408 |
|
|
1409 |
void tst_Collections::hash()
|
|
1410 |
{
|
|
1411 |
const char *hello = "hello";
|
|
1412 |
const char *world = "world";
|
|
1413 |
const char *allo = "allo";
|
|
1414 |
const char *monde = "monde";
|
|
1415 |
|
|
1416 |
{
|
|
1417 |
typedef QHash<QString, QString> Hash;
|
|
1418 |
Hash hash;
|
|
1419 |
QString key;
|
|
1420 |
for (int i = 0; i < 10; ++i) {
|
|
1421 |
key[0] = i + '0';
|
|
1422 |
for (int j = 0; j < 10; ++j) {
|
|
1423 |
key[1] = j + '0';
|
|
1424 |
hash.insert(key, "V" + key);
|
|
1425 |
}
|
|
1426 |
}
|
|
1427 |
|
|
1428 |
for (int i = 0; i < 10; ++i) {
|
|
1429 |
key[0] = i + '0';
|
|
1430 |
for (int j = 0; j < 10; ++j) {
|
|
1431 |
key[1] = j + '0';
|
|
1432 |
hash.remove(key);
|
|
1433 |
}
|
|
1434 |
}
|
|
1435 |
}
|
|
1436 |
|
|
1437 |
{
|
|
1438 |
typedef QHash<int, const char *> Hash;
|
|
1439 |
Hash hash;
|
|
1440 |
hash.insert(1, hello);
|
|
1441 |
hash.insert(2, world);
|
|
1442 |
|
|
1443 |
QVERIFY(hash.size() == 2);
|
|
1444 |
QVERIFY(!hash.isEmpty());
|
|
1445 |
|
|
1446 |
{
|
|
1447 |
Hash hash2 = hash;
|
|
1448 |
hash2 = hash;
|
|
1449 |
hash = hash2;
|
|
1450 |
hash2 = hash2;
|
|
1451 |
hash = hash;
|
|
1452 |
hash2.clear();
|
|
1453 |
hash2 = hash2;
|
|
1454 |
QVERIFY(hash2.size() == 0);
|
|
1455 |
QVERIFY(hash2.isEmpty());
|
|
1456 |
}
|
|
1457 |
QVERIFY(hash.size() == 2);
|
|
1458 |
|
|
1459 |
{
|
|
1460 |
Hash hash2 = hash;
|
|
1461 |
hash2[1] = allo;
|
|
1462 |
hash2[2] = monde;
|
|
1463 |
|
|
1464 |
QVERIFY(hash2[1] == allo);
|
|
1465 |
QVERIFY(hash2[2] == monde);
|
|
1466 |
QVERIFY(hash[1] == hello);
|
|
1467 |
QVERIFY(hash[2] == world);
|
|
1468 |
|
|
1469 |
hash2[1] = hash[1];
|
|
1470 |
hash2[2] = hash[2];
|
|
1471 |
|
|
1472 |
QVERIFY(hash2[1] == hello);
|
|
1473 |
QVERIFY(hash2[2] == world);
|
|
1474 |
|
|
1475 |
hash[1] = hash[1];
|
|
1476 |
QVERIFY(hash[1] == hello);
|
|
1477 |
}
|
|
1478 |
|
|
1479 |
{
|
|
1480 |
Hash hash2 = hash;
|
|
1481 |
hash2.detach();
|
|
1482 |
hash2.remove(1);
|
|
1483 |
QVERIFY(hash2.size() == 1);
|
|
1484 |
hash2.remove(1);
|
|
1485 |
QVERIFY(hash2.size() == 1);
|
|
1486 |
hash2.remove(0);
|
|
1487 |
QVERIFY(hash2.size() == 1);
|
|
1488 |
hash2.remove(2);
|
|
1489 |
QVERIFY(hash2.size() == 0);
|
|
1490 |
QVERIFY(hash.size() == 2);
|
|
1491 |
}
|
|
1492 |
|
|
1493 |
hash.detach();
|
|
1494 |
|
|
1495 |
{
|
|
1496 |
Hash::iterator it1 = hash.find(1);
|
|
1497 |
QVERIFY(it1 != hash.end());
|
|
1498 |
|
|
1499 |
Hash::iterator it2 = hash.find(0);
|
|
1500 |
QVERIFY(it2 != hash.begin());
|
|
1501 |
QVERIFY(it2 == hash.end());
|
|
1502 |
|
|
1503 |
*it1 = monde;
|
|
1504 |
QVERIFY(*it1 == monde);
|
|
1505 |
QVERIFY(hash[1] == monde);
|
|
1506 |
|
|
1507 |
*it1 = hello;
|
|
1508 |
QVERIFY(*it1 == hello);
|
|
1509 |
QVERIFY(hash[1] == hello);
|
|
1510 |
|
|
1511 |
hash[1] = monde;
|
|
1512 |
QVERIFY(it1.key() == 1);
|
|
1513 |
QVERIFY(it1.value() == monde);
|
|
1514 |
QVERIFY(*it1 == monde);
|
|
1515 |
QVERIFY(hash[1] == monde);
|
|
1516 |
|
|
1517 |
hash[1] = hello;
|
|
1518 |
QVERIFY(*it1 == hello);
|
|
1519 |
QVERIFY(hash[1] == hello);
|
|
1520 |
}
|
|
1521 |
|
|
1522 |
{
|
|
1523 |
const Hash hash2 = hash;
|
|
1524 |
|
|
1525 |
Hash::const_iterator it1 = hash2.find(1);
|
|
1526 |
QVERIFY(it1 != hash2.end());
|
|
1527 |
QVERIFY(it1.key() == 1);
|
|
1528 |
QVERIFY(it1.value() == hello);
|
|
1529 |
QVERIFY(*it1 == hello);
|
|
1530 |
|
|
1531 |
Hash::const_iterator it2 = hash2.find(2);
|
|
1532 |
QVERIFY(it1 != it2);
|
|
1533 |
QVERIFY(it1 != hash2.end());
|
|
1534 |
QVERIFY(it2 != hash2.end());
|
|
1535 |
|
|
1536 |
int count = 0;
|
|
1537 |
it1 = hash2.begin();
|
|
1538 |
while (it1 != hash2.end()) {
|
|
1539 |
count++;
|
|
1540 |
++it1;
|
|
1541 |
}
|
|
1542 |
QVERIFY(count == 2);
|
|
1543 |
|
|
1544 |
count = 0;
|
|
1545 |
it1 = hash.begin();
|
|
1546 |
while (it1 != hash.end()) {
|
|
1547 |
count++;
|
|
1548 |
++it1;
|
|
1549 |
}
|
|
1550 |
QVERIFY(count == 2);
|
|
1551 |
}
|
|
1552 |
|
|
1553 |
{
|
|
1554 |
QVERIFY(hash.contains(1));
|
|
1555 |
QVERIFY(hash.contains(2));
|
|
1556 |
QVERIFY(!hash.contains(0));
|
|
1557 |
QVERIFY(!hash.contains(3));
|
|
1558 |
}
|
|
1559 |
|
|
1560 |
{
|
|
1561 |
QVERIFY(hash.value(1) == hello);
|
|
1562 |
QVERIFY(hash.value(2) == world);
|
|
1563 |
QVERIFY(hash.value(3) == 0);
|
|
1564 |
QVERIFY(hash.value(1, allo) == hello);
|
|
1565 |
QVERIFY(hash.value(2, allo) == world);
|
|
1566 |
QVERIFY(hash.value(3, allo) == allo);
|
|
1567 |
QVERIFY(hash.value(0, monde) == monde);
|
|
1568 |
}
|
|
1569 |
|
|
1570 |
{
|
|
1571 |
QHash<int,LargeStatic> hash;
|
|
1572 |
for (int i = 0; i < 10; i++)
|
|
1573 |
hash.insert(i, LargeStatic());
|
|
1574 |
QVERIFY(LargeStatic::count == 10);
|
|
1575 |
hash.remove(7);
|
|
1576 |
QVERIFY(LargeStatic::count == 9);
|
|
1577 |
|
|
1578 |
}
|
|
1579 |
QVERIFY(LargeStatic::count == 0);
|
|
1580 |
{
|
|
1581 |
QHash<int, int*> hash;
|
|
1582 |
QVERIFY(((const QHash<int,int*>*) &hash)->operator[](7) == 0);
|
|
1583 |
}
|
|
1584 |
|
|
1585 |
{
|
|
1586 |
/*
|
|
1587 |
This test relies on a certain implementation of
|
|
1588 |
QHash. If you change the way QHash works internally,
|
|
1589 |
change this test as well.
|
|
1590 |
*/
|
|
1591 |
QHash<int, int> hash;
|
|
1592 |
for (int i = 0; i < 1000; ++i)
|
|
1593 |
hash.insert(i, i);
|
|
1594 |
QVERIFY(hash.capacity() == 1031);
|
|
1595 |
hash.squeeze();
|
|
1596 |
QVERIFY(hash.capacity() == 521);
|
|
1597 |
|
|
1598 |
hash.insert(12345, 12345);
|
|
1599 |
QVERIFY(hash.capacity() == 1031);
|
|
1600 |
|
|
1601 |
for (int j = 0; j < 900; ++j)
|
|
1602 |
hash.remove(j);
|
|
1603 |
QVERIFY(hash.capacity() == 257);
|
|
1604 |
hash.squeeze();
|
|
1605 |
QVERIFY(hash.capacity() == 67);
|
|
1606 |
hash.reserve(0);
|
|
1607 |
}
|
|
1608 |
}
|
|
1609 |
|
|
1610 |
{
|
|
1611 |
QHash<int, QString> hash;
|
|
1612 |
hash.insert(0, "Hello");
|
|
1613 |
|
|
1614 |
QHash<int, QString>::iterator it = hash.begin();
|
|
1615 |
QVERIFY((*it)[0] == QChar('H'));
|
|
1616 |
QVERIFY(it->constData()[0] == QChar('H'));
|
|
1617 |
it->replace(QChar('H'), QChar('X'));
|
|
1618 |
QVERIFY(*hash.begin() == "Xello");
|
|
1619 |
|
|
1620 |
QHash<int, QString>::const_iterator cit = hash.constBegin();
|
|
1621 |
QVERIFY((*cit).toLower() == "xello");
|
|
1622 |
QVERIFY(cit->toUpper() == "XELLO");
|
|
1623 |
}
|
|
1624 |
|
|
1625 |
{
|
|
1626 |
QHash<int, QString> hash1, hash2;
|
|
1627 |
hash1.insertMulti(1, "Alpha");
|
|
1628 |
hash1.insertMulti(1, "Gamma");
|
|
1629 |
hash2.insertMulti(1, "Beta");
|
|
1630 |
hash2.insertMulti(1, "Gamma");
|
|
1631 |
hash2.insertMulti(1, "Gamma");
|
|
1632 |
|
|
1633 |
hash1.unite(hash2);
|
|
1634 |
QCOMPARE(hash1.size(), 5);
|
|
1635 |
QCOMPARE(hash1.values(),
|
|
1636 |
(QList<QString>() << "Gamma" << "Gamma" << "Beta" << "Gamma" << "Alpha"));
|
|
1637 |
|
|
1638 |
hash2 = hash1;
|
|
1639 |
hash2.unite(hash2);
|
|
1640 |
QCOMPARE(hash2.size(), 10);
|
|
1641 |
QCOMPARE(hash2.values(), hash1.values() + hash1.values());
|
|
1642 |
}
|
|
1643 |
|
|
1644 |
#if 0
|
|
1645 |
{
|
|
1646 |
QMultiHash<QString, int> hash1;
|
|
1647 |
hash1.insert("1", 2);
|
|
1648 |
hash1.insert("1", 1);
|
|
1649 |
hash1.insert("a", 3);
|
|
1650 |
hash1.insert("a", 2);
|
|
1651 |
hash1.insert("a", 1);
|
|
1652 |
hash1.insert("b", 2);
|
|
1653 |
hash1.insert("b", 1);
|
|
1654 |
|
|
1655 |
// hash1: [ "1" -> 1, "1" -> 2, "a" -> 1, "a" -> 2, "a" -> 3, "b" -> 1, "b" -> 2 ]
|
|
1656 |
|
|
1657 |
QHashIterator<QString, int> i1(hash1);
|
|
1658 |
i1.toBack();
|
|
1659 |
|
|
1660 |
bool found;
|
|
1661 |
|
|
1662 |
found = i1.findPreviousKey("1");
|
|
1663 |
QVERIFY(found && i1.value() == 2);
|
|
1664 |
|
|
1665 |
found = i1.findPreviousKey("1");
|
|
1666 |
QVERIFY(found && i1.value() == 1);
|
|
1667 |
|
|
1668 |
found = i1.findPreviousKey("1");
|
|
1669 |
QVERIFY(!found);
|
|
1670 |
|
|
1671 |
i1.toFront();
|
|
1672 |
found = i1.findNextKey("1");
|
|
1673 |
QVERIFY(found && i1.value() == 1);
|
|
1674 |
|
|
1675 |
found = i1.findNextKey("1");
|
|
1676 |
QVERIFY(found && i1.value() == 2);
|
|
1677 |
|
|
1678 |
found = i1.findNextKey("1");
|
|
1679 |
QVERIFY(!found);
|
|
1680 |
|
|
1681 |
i1.toBack();
|
|
1682 |
found = i1.findPreviousKey("b");
|
|
1683 |
QVERIFY(found && i1.value() == 2);
|
|
1684 |
|
|
1685 |
found = i1.findPreviousKey("b");
|
|
1686 |
QVERIFY(found && i1.value() == 1);
|
|
1687 |
|
|
1688 |
found = i1.findPreviousKey("b");
|
|
1689 |
QVERIFY(!found);
|
|
1690 |
|
|
1691 |
i1.toFront();
|
|
1692 |
found = i1.findNextKey("b");
|
|
1693 |
QVERIFY(found && i1.value() == 1);
|
|
1694 |
|
|
1695 |
found = i1.findNextKey("b");
|
|
1696 |
QVERIFY(found && i1.value() == 2);
|
|
1697 |
|
|
1698 |
found = i1.findNextKey("b");
|
|
1699 |
QVERIFY(!found);
|
|
1700 |
}
|
|
1701 |
#endif
|
|
1702 |
}
|
|
1703 |
|
|
1704 |
void tst_Collections::map()
|
|
1705 |
{
|
|
1706 |
const char *hello = "hello";
|
|
1707 |
const char *world = "world";
|
|
1708 |
const char *allo = "allo";
|
|
1709 |
const char *monde = "monde";
|
|
1710 |
|
|
1711 |
{
|
|
1712 |
typedef QMap<int, const char *> Map;
|
|
1713 |
Map map;
|
|
1714 |
map.insert(1, hello);
|
|
1715 |
map.insert(2, world);
|
|
1716 |
|
|
1717 |
QVERIFY(*map.begin() == hello);
|
|
1718 |
|
|
1719 |
QVERIFY(map.size() == 2);
|
|
1720 |
QVERIFY(!map.isEmpty());
|
|
1721 |
|
|
1722 |
{
|
|
1723 |
Map map2 = map;
|
|
1724 |
map2 = map;
|
|
1725 |
map = map2;
|
|
1726 |
map2 = map2;
|
|
1727 |
map = map;
|
|
1728 |
map2.clear();
|
|
1729 |
map2 = map2;
|
|
1730 |
QVERIFY(map2.size() == 0);
|
|
1731 |
QVERIFY(map2.isEmpty());
|
|
1732 |
}
|
|
1733 |
QVERIFY(map.size() == 2);
|
|
1734 |
|
|
1735 |
{
|
|
1736 |
Map map2 = map;
|
|
1737 |
map2[1] = allo;
|
|
1738 |
map2[2] = monde;
|
|
1739 |
|
|
1740 |
QVERIFY(map2[1] == allo);
|
|
1741 |
QVERIFY(map2[2] == monde);
|
|
1742 |
QVERIFY(map[1] == hello);
|
|
1743 |
QVERIFY(map[2] == world);
|
|
1744 |
|
|
1745 |
map2[1] = map[1];
|
|
1746 |
map2[2] = map[2];
|
|
1747 |
|
|
1748 |
QVERIFY(map2[1] == hello);
|
|
1749 |
QVERIFY(map2[2] == world);
|
|
1750 |
|
|
1751 |
map[1] = map[1];
|
|
1752 |
QVERIFY(map[1] == hello);
|
|
1753 |
}
|
|
1754 |
|
|
1755 |
{
|
|
1756 |
Map map2 = map;
|
|
1757 |
map2.detach();
|
|
1758 |
map2.remove(1);
|
|
1759 |
QVERIFY(map2.size() == 1);
|
|
1760 |
map2.remove(1);
|
|
1761 |
QVERIFY(map2.size() == 1);
|
|
1762 |
map2.remove(0);
|
|
1763 |
QVERIFY(map2.size() == 1);
|
|
1764 |
map2.remove(2);
|
|
1765 |
QVERIFY(map2.size() == 0);
|
|
1766 |
QVERIFY(map.size() == 2);
|
|
1767 |
}
|
|
1768 |
|
|
1769 |
map.detach();
|
|
1770 |
|
|
1771 |
{
|
|
1772 |
Map::iterator it1 = map.find(1);
|
|
1773 |
QVERIFY(it1 == map.begin());
|
|
1774 |
QVERIFY(it1 != map.end());
|
|
1775 |
|
|
1776 |
Map::iterator it2 = map.find(0);
|
|
1777 |
QVERIFY(it2 != map.begin());
|
|
1778 |
QVERIFY(it2 == map.end());
|
|
1779 |
|
|
1780 |
*it1 = monde;
|
|
1781 |
QVERIFY(*it1 == monde);
|
|
1782 |
QVERIFY(map[1] == monde);
|
|
1783 |
|
|
1784 |
*it1 = hello;
|
|
1785 |
QVERIFY(*it1 == hello);
|
|
1786 |
QVERIFY(map[1] == hello);
|
|
1787 |
|
|
1788 |
map[1] = monde;
|
|
1789 |
QVERIFY(it1.key() == 1);
|
|
1790 |
QVERIFY(it1.value() == monde);
|
|
1791 |
QVERIFY(*it1 == monde);
|
|
1792 |
QVERIFY(map[1] == monde);
|
|
1793 |
|
|
1794 |
map[1] = hello;
|
|
1795 |
QVERIFY(*it1 == hello);
|
|
1796 |
QVERIFY(map[1] == hello);
|
|
1797 |
|
|
1798 |
*++it1 = allo;
|
|
1799 |
QVERIFY(*it1 == allo);
|
|
1800 |
QVERIFY(map[2] == allo);
|
|
1801 |
*it1 = world;
|
|
1802 |
|
|
1803 |
++it1;
|
|
1804 |
QVERIFY(it1 == map.end());
|
|
1805 |
|
|
1806 |
int count = 0;
|
|
1807 |
it1 = map.begin();
|
|
1808 |
while (it1 != map.end()) {
|
|
1809 |
count++;
|
|
1810 |
++it1;
|
|
1811 |
}
|
|
1812 |
QVERIFY(count == 2);
|
|
1813 |
}
|
|
1814 |
|
|
1815 |
{
|
|
1816 |
const Map map2 = map;
|
|
1817 |
|
|
1818 |
Map::const_iterator it1 = map2.find(1);
|
|
1819 |
QVERIFY(it1 != map2.end());
|
|
1820 |
QVERIFY(it1.key() == 1);
|
|
1821 |
QVERIFY(it1.value() == hello);
|
|
1822 |
QVERIFY(*it1 == hello);
|
|
1823 |
++it1;
|
|
1824 |
|
|
1825 |
Map::const_iterator it2 = map2.find(2);
|
|
1826 |
QVERIFY(it1 == it2);
|
|
1827 |
++it1;
|
|
1828 |
QVERIFY(it1 == map2.end());
|
|
1829 |
QVERIFY(it2 != map2.end());
|
|
1830 |
QVERIFY(it1 != it2);
|
|
1831 |
|
|
1832 |
int count = 0;
|
|
1833 |
it1 = map2.begin();
|
|
1834 |
while (it1 != map2.end()) {
|
|
1835 |
count++;
|
|
1836 |
++it1;
|
|
1837 |
}
|
|
1838 |
QVERIFY(count == 2);
|
|
1839 |
|
|
1840 |
count = 0;
|
|
1841 |
it1 = map.begin();
|
|
1842 |
while (it1 != map.end()) {
|
|
1843 |
count++;
|
|
1844 |
++it1;
|
|
1845 |
}
|
|
1846 |
QVERIFY(count == 2);
|
|
1847 |
}
|
|
1848 |
|
|
1849 |
{
|
|
1850 |
QVERIFY(map.contains(1));
|
|
1851 |
QVERIFY(map.contains(2));
|
|
1852 |
QVERIFY(!map.contains(0));
|
|
1853 |
QVERIFY(!map.contains(3));
|
|
1854 |
}
|
|
1855 |
|
|
1856 |
{
|
|
1857 |
QVERIFY(map.value(1) == hello);
|
|
1858 |
QVERIFY(map.value(2) == world);
|
|
1859 |
QVERIFY(map.value(3) == 0);
|
|
1860 |
QVERIFY(map.value(1, allo) == hello);
|
|
1861 |
QVERIFY(map.value(2, allo) == world);
|
|
1862 |
QVERIFY(map.value(3, allo) == allo);
|
|
1863 |
QVERIFY(map.value(0, monde) == monde);
|
|
1864 |
}
|
|
1865 |
int originalLargeStaticCount = LargeStatic::count;
|
|
1866 |
{
|
|
1867 |
QMap<int,LargeStatic> map;
|
|
1868 |
for (int i = 0; i < 10; i++)
|
|
1869 |
map.insert(i, LargeStatic());
|
|
1870 |
QVERIFY(LargeStatic::count == (originalLargeStaticCount + 10));
|
|
1871 |
map.remove(7);
|
|
1872 |
QVERIFY(LargeStatic::count == (originalLargeStaticCount + 9));
|
|
1873 |
|
|
1874 |
}
|
|
1875 |
QVERIFY(LargeStatic::count == originalLargeStaticCount);
|
|
1876 |
{
|
|
1877 |
QMap<int, int*> map;
|
|
1878 |
QVERIFY(((const QMap<int,int*>*) &map)->operator[](7) == 0);
|
|
1879 |
}
|
|
1880 |
|
|
1881 |
{
|
|
1882 |
QMap<int, int> map;
|
|
1883 |
map[0] = 1;
|
|
1884 |
map[1] = 2;
|
|
1885 |
map[2] = 4;
|
|
1886 |
map[3] = 8;
|
|
1887 |
int sum = 0;
|
|
1888 |
int sumkey = 0;
|
|
1889 |
QMapIterator<int,int> i = map;
|
|
1890 |
while (i.hasNext()) {
|
|
1891 |
sum += i.next().value();
|
|
1892 |
sumkey += i.key();
|
|
1893 |
}
|
|
1894 |
QVERIFY(sum == 15);
|
|
1895 |
QVERIFY(sumkey == 6);
|
|
1896 |
}
|
|
1897 |
{
|
|
1898 |
QMap<int, int> map;
|
|
1899 |
map[0] = 1;
|
|
1900 |
map[1] = 2;
|
|
1901 |
map[2] = 4;
|
|
1902 |
map[3] = 8;
|
|
1903 |
int sum = 0;
|
|
1904 |
QMutableMapIterator<int,int> i = map;
|
|
1905 |
while(i.hasNext())
|
|
1906 |
if (i.next().key() == 2)
|
|
1907 |
i.remove();
|
|
1908 |
i.toFront();
|
|
1909 |
while(i.hasNext()) {
|
|
1910 |
sum += i.next().value();
|
|
1911 |
i.setValue(10);
|
|
1912 |
i.value() += 22;
|
|
1913 |
QVERIFY(i.value() == 32);
|
|
1914 |
}
|
|
1915 |
QVERIFY(sum == 11);
|
|
1916 |
}
|
|
1917 |
{
|
|
1918 |
QMap<int, int> map;
|
|
1919 |
map[0] = 1;
|
|
1920 |
QMutableMapIterator<int,int> i(map);
|
|
1921 |
i.toBack();
|
|
1922 |
while (i.hasPrevious()) {
|
|
1923 |
i.previous();
|
|
1924 |
QCOMPARE(i.key(), 0);
|
|
1925 |
QCOMPARE(i.value(), 1);
|
|
1926 |
}
|
|
1927 |
}
|
|
1928 |
}
|
|
1929 |
|
|
1930 |
{
|
|
1931 |
QMultiMap<QString, int> map1;
|
|
1932 |
map1.insert("1", 2);
|
|
1933 |
map1.insert("1", 1);
|
|
1934 |
map1.insert("a", 3);
|
|
1935 |
map1.insert("a", 2);
|
|
1936 |
map1.insert("a", 1);
|
|
1937 |
map1.insert("b", 2);
|
|
1938 |
map1.insert("b", 1);
|
|
1939 |
|
|
1940 |
// map1: [ "1" -> 1, "1" -> 2, "a" -> 1, "a" -> 2, "a" -> 3, "b" -> 1, "b" -> 2 ]
|
|
1941 |
|
|
1942 |
#if 0
|
|
1943 |
QMapIterator<QString, int> i1(map1);
|
|
1944 |
i1.toBack();
|
|
1945 |
|
|
1946 |
bool found;
|
|
1947 |
found = i1.findPreviousKey("1");
|
|
1948 |
QVERIFY(found && i1.value() == 2);
|
|
1949 |
|
|
1950 |
found = i1.findPreviousKey("1");
|
|
1951 |
QVERIFY(found && i1.value() == 1);
|
|
1952 |
|
|
1953 |
found = i1.findPreviousKey("1");
|
|
1954 |
QVERIFY(!found);
|
|
1955 |
|
|
1956 |
i1.toFront();
|
|
1957 |
found = i1.findNextKey("1");
|
|
1958 |
QVERIFY(found && i1.value() == 1);
|
|
1959 |
|
|
1960 |
found = i1.findNextKey("1");
|
|
1961 |
QVERIFY(found && i1.value() == 2);
|
|
1962 |
|
|
1963 |
found = i1.findNextKey("1");
|
|
1964 |
QVERIFY(!found);
|
|
1965 |
|
|
1966 |
i1.toBack();
|
|
1967 |
found = i1.findPreviousKey("b");
|
|
1968 |
QVERIFY(found && i1.value() == 2);
|
|
1969 |
|
|
1970 |
found = i1.findPreviousKey("b");
|
|
1971 |
QVERIFY(found && i1.value() == 1);
|
|
1972 |
|
|
1973 |
found = i1.findPreviousKey("b");
|
|
1974 |
QVERIFY(!found);
|
|
1975 |
|
|
1976 |
i1.toFront();
|
|
1977 |
found = i1.findNextKey("b");
|
|
1978 |
QVERIFY(found && i1.value() == 1);
|
|
1979 |
|
|
1980 |
found = i1.findNextKey("b");
|
|
1981 |
QVERIFY(found && i1.value() == 2);
|
|
1982 |
|
|
1983 |
found = i1.findNextKey("b");
|
|
1984 |
QVERIFY(!found);
|
|
1985 |
#endif
|
|
1986 |
|
|
1987 |
QMultiMap<QString, int>::iterator j1, k1;
|
|
1988 |
|
|
1989 |
j1 = map1.lowerBound("0"); k1 = map1.upperBound("0");
|
|
1990 |
QVERIFY(j1 == map1.begin() && k1 == j1);
|
|
1991 |
j1 = map1.lowerBound("00"); k1 = map1.upperBound("00");
|
|
1992 |
QVERIFY(j1 == map1.find("1") && k1 == j1);
|
|
1993 |
j1 = map1.lowerBound("1"); k1 = map1.upperBound("1");
|
|
1994 |
QVERIFY(j1 == map1.find("1") && --(--k1) == j1);
|
|
1995 |
j1 = map1.lowerBound("11"); k1 = map1.upperBound("11");
|
|
1996 |
QVERIFY(j1 == map1.find("a") && k1 == j1);
|
|
1997 |
j1 = map1.lowerBound("a"); k1 = map1.upperBound("a");
|
|
1998 |
QVERIFY(j1 == map1.find("a") && k1 == map1.find("b"));
|
|
1999 |
QVERIFY(j1.value() == 1 && j1.value() == 1);
|
|
2000 |
j1 = map1.lowerBound("aa"); k1 = map1.upperBound("aa");
|
|
2001 |
QVERIFY(j1 == map1.find("b") && k1 == j1);
|
|
2002 |
QVERIFY(j1.value() == 1);
|
|
2003 |
j1 = map1.lowerBound("b"); k1 = map1.upperBound("b");
|
|
2004 |
QVERIFY(j1 == map1.find("b") && k1 == map1.end());
|
|
2005 |
QVERIFY(j1.value() == 1);
|
|
2006 |
j1 = map1.lowerBound("bb"); k1 = map1.upperBound("bb");
|
|
2007 |
QVERIFY(j1 == map1.end() && k1 == j1);
|
|
2008 |
|
|
2009 |
const QMultiMap<QString, int> map2 = map1;
|
|
2010 |
QMultiMap<QString, int>::const_iterator j2, k2;
|
|
2011 |
|
|
2012 |
j2 = map2.lowerBound("0"); k2 = map2.upperBound("0");
|
|
2013 |
QVERIFY(j2 == map2.begin() && k2 == j2);
|
|
2014 |
j2 = map2.lowerBound("00"); k2 = map2.upperBound("00");
|
|
2015 |
QVERIFY(j2 == map2.find("1") && k2 == j2);
|
|
2016 |
j2 = map2.lowerBound("1"); k2 = map2.upperBound("1");
|
|
2017 |
QVERIFY(j2 == map2.find("1") && --(--k2) == j2);
|
|
2018 |
j2 = map2.lowerBound("11"); k2 = map2.upperBound("11");
|
|
2019 |
QVERIFY(j2 == map2.find("a") && k2 == j2);
|
|
2020 |
j2 = map2.lowerBound("a"); k2 = map2.upperBound("a");
|
|
2021 |
QVERIFY(j2 == map2.find("a") && k2 == map2.find("b"));
|
|
2022 |
QVERIFY(j2.value() == 1 && j2.value() == 1);
|
|
2023 |
j2 = map2.lowerBound("aa"); k2 = map2.upperBound("aa");
|
|
2024 |
QVERIFY(j2 == map2.find("b") && k2 == j2);
|
|
2025 |
QVERIFY(j2.value() == 1);
|
|
2026 |
j2 = map2.lowerBound("b"); k2 = map2.upperBound("b");
|
|
2027 |
QVERIFY(j2 == map2.find("b") && k2 == map2.end());
|
|
2028 |
QVERIFY(j2.value() == 1);
|
|
2029 |
j2 = map2.lowerBound("bb"); k2 = map2.upperBound("bb");
|
|
2030 |
QVERIFY(j2 == map2.end() && k2 == j2);
|
|
2031 |
}
|
|
2032 |
|
|
2033 |
{
|
|
2034 |
QMap<int, QString> map;
|
|
2035 |
map.insert(0, "Hello");
|
|
2036 |
|
|
2037 |
QMap<int, QString>::iterator it = map.begin();
|
|
2038 |
QVERIFY((*it)[0] == QChar('H'));
|
|
2039 |
QVERIFY(it->constData()[0] == QChar('H'));
|
|
2040 |
it->replace(QChar('H'), QChar('X'));
|
|
2041 |
QVERIFY(*map.begin() == "Xello");
|
|
2042 |
|
|
2043 |
QMap<int, QString>::const_iterator cit = map.constBegin();
|
|
2044 |
QVERIFY((*cit).toLower() == "xello");
|
|
2045 |
QVERIFY(cit->toUpper() == "XELLO");
|
|
2046 |
}
|
|
2047 |
|
|
2048 |
{
|
|
2049 |
QMap<int, QString> map1, map2;
|
|
2050 |
map1.insertMulti(1, "Alpha");
|
|
2051 |
map1.insertMulti(1, "Gamma");
|
|
2052 |
map2.insertMulti(1, "Beta");
|
|
2053 |
map2.insertMulti(1, "Gamma");
|
|
2054 |
map2.insertMulti(1, "Gamma");
|
|
2055 |
|
|
2056 |
map1.unite(map2);
|
|
2057 |
QCOMPARE(map1.size(), 5);
|
|
2058 |
QCOMPARE(static_cast<QStringList>(map1.values()),
|
|
2059 |
(QStringList() << "Gamma" << "Gamma" << "Beta" << "Gamma" << "Alpha"));
|
|
2060 |
|
|
2061 |
map2 = map1;
|
|
2062 |
map2.unite(map2);
|
|
2063 |
QCOMPARE(map2.size(), 10);
|
|
2064 |
QCOMPARE(map2.values(), map1.values() + map1.values());
|
|
2065 |
}
|
|
2066 |
}
|
|
2067 |
|
|
2068 |
void tst_Collections::qstring()
|
|
2069 |
{
|
|
2070 |
QString hello = "hello";
|
|
2071 |
QString ello = "ello";
|
|
2072 |
QString World = "World";
|
|
2073 |
QString Wor = "Wor";
|
|
2074 |
QString helloWorld = "helloWorld";
|
|
2075 |
|
|
2076 |
QString s = hello + "World";
|
|
2077 |
QVERIFY(hello + World == helloWorld);
|
|
2078 |
QVERIFY(hello + "World" == helloWorld);
|
|
2079 |
QVERIFY("hello" + World == helloWorld);
|
|
2080 |
|
|
2081 |
|
|
2082 |
QString l;
|
|
2083 |
QVERIFY('h' + ello == hello);
|
|
2084 |
QVERIFY(Wor + 'l' + 'd' == "World");
|
|
2085 |
QVERIFY(hello + World == "helloWorld");
|
|
2086 |
QVERIFY(hello + "World" == "helloWorld");
|
|
2087 |
QVERIFY("hello" + World == "helloWorld");
|
|
2088 |
QVERIFY('h' + ello == "hello");
|
|
2089 |
QVERIFY(Wor + 'l' + 'd' == "World");
|
|
2090 |
QVERIFY("helloWorld" == hello + World);
|
|
2091 |
QVERIFY("helloWorld" == hello + "World");
|
|
2092 |
QVERIFY("helloWorld" == "hello" + World);
|
|
2093 |
QVERIFY("hello" == 'h' + ello);
|
|
2094 |
QVERIFY("World" == Wor + 'l' + 'd');
|
|
2095 |
|
|
2096 |
QVERIFY(hello.contains('e'));
|
|
2097 |
QVERIFY (true == hello.contains('e'));
|
|
2098 |
QVERIFY (hello.contains('e') != false);
|
|
2099 |
|
|
2100 |
QVERIFY(hello.indexOf('e') == 1);
|
|
2101 |
QVERIFY(hello.indexOf('e', -10) == 1);
|
|
2102 |
QVERIFY(hello.indexOf('l') == 2);
|
|
2103 |
QVERIFY(hello.indexOf('l',2) == 2);
|
|
2104 |
QVERIFY(hello.indexOf('l',3) == 3);
|
|
2105 |
|
|
2106 |
QString large = "000 100 200 300 400 500 600 700 800 900";
|
|
2107 |
|
|
2108 |
QVERIFY(large.indexOf("700") == 28);
|
|
2109 |
QVERIFY(large.indexOf("700", 28) == 28);
|
|
2110 |
QVERIFY(large.indexOf("700", 29) == -1);
|
|
2111 |
QVERIFY(large.lastIndexOf("700") == 28);
|
|
2112 |
QVERIFY(large.lastIndexOf("700", 28) == 28);
|
|
2113 |
QVERIFY(large.lastIndexOf("700", 27) == -1);
|
|
2114 |
|
|
2115 |
QVERIFY(large.contains("200"));
|
|
2116 |
QVERIFY(!large.contains("201"));
|
|
2117 |
QVERIFY(large.contains('3'));
|
|
2118 |
QVERIFY(!large.contains('a'));
|
|
2119 |
|
|
2120 |
QVERIFY(large.count("00") == 11);
|
|
2121 |
QVERIFY(large.count('3') == 1);
|
|
2122 |
QVERIFY(large.count('0') == 21);
|
|
2123 |
QVERIFY(large.count("0") == 21);
|
|
2124 |
QVERIFY(large.count("200") == 1);
|
|
2125 |
QVERIFY(large.count("201") == 0);
|
|
2126 |
|
|
2127 |
QVERIFY(hello.left(0) == "");
|
|
2128 |
QVERIFY(!hello.left(0).isNull());
|
|
2129 |
QVERIFY(hello.left(1) == "h");
|
|
2130 |
QVERIFY(hello.left(2) == "he");
|
|
2131 |
QVERIFY(hello.left(200) == "hello");
|
|
2132 |
QVERIFY(hello.left(hello.size()) == hello);
|
|
2133 |
QVERIFY(hello.left(hello.size()+1) == hello);
|
|
2134 |
|
|
2135 |
QVERIFY(hello.right(0) == "");
|
|
2136 |
QVERIFY(!hello.right(0).isNull());
|
|
2137 |
QVERIFY(hello.right(1) == "o");
|
|
2138 |
QVERIFY(hello.right(2) == "lo");
|
|
2139 |
QVERIFY(hello.right(200) == "hello");
|
|
2140 |
QVERIFY(hello.right(hello.size()) == hello);
|
|
2141 |
QVERIFY(hello.right(hello.size()+1) == hello);
|
|
2142 |
|
|
2143 |
QVERIFY(!hello.mid(0, 0).isNull());
|
|
2144 |
QVERIFY(hello.mid(0, 1) == "h");
|
|
2145 |
QVERIFY(hello.mid(0, 2) == "he");
|
|
2146 |
QVERIFY(hello.mid(0, 200) == "hello");
|
|
2147 |
QVERIFY(hello.mid(0) == "hello");
|
|
2148 |
QVERIFY(hello.mid(0, hello.size()) == hello);
|
|
2149 |
QVERIFY(hello.mid(0, hello.size()+1) == hello);
|
|
2150 |
|
|
2151 |
QVERIFY(hello.mid(hello.size()-0) == "");
|
|
2152 |
|
|
2153 |
QVERIFY(hello.mid(hello.size()-0).isNull());
|
|
2154 |
QVERIFY(hello.mid(hello.size()-1) == "o");
|
|
2155 |
QVERIFY(hello.mid(hello.size()-2) == "lo");
|
|
2156 |
QVERIFY(hello.mid(hello.size()-200) == "hello");
|
|
2157 |
|
|
2158 |
QString null;
|
|
2159 |
QString nonNull = "";
|
|
2160 |
QVERIFY(null.left(10).isNull());
|
|
2161 |
QVERIFY(null.mid(0).isNull());
|
|
2162 |
|
|
2163 |
QVERIFY(null == QString::null);
|
|
2164 |
QVERIFY(QString::null == null);
|
|
2165 |
QVERIFY(nonNull != QString::null);
|
|
2166 |
QVERIFY(QString::null != nonNull);
|
|
2167 |
QVERIFY(null == nonNull);
|
|
2168 |
QVERIFY(QString::null == QString::null);
|
|
2169 |
|
|
2170 |
QString fill = "123";
|
|
2171 |
fill.fill('a');
|
|
2172 |
QVERIFY(fill == "aaa");
|
|
2173 |
|
|
2174 |
s.clear();
|
|
2175 |
s = hello;
|
|
2176 |
s.append(World);
|
|
2177 |
QVERIFY(s == helloWorld);
|
|
2178 |
s.clear();
|
|
2179 |
s = World;
|
|
2180 |
s.insert(0,hello);
|
|
2181 |
QVERIFY(s == helloWorld);
|
|
2182 |
s = "012345";
|
|
2183 |
s.insert(3, 'E');
|
|
2184 |
QVERIFY(s == "012E345");
|
|
2185 |
s.insert(3, "INSID");
|
|
2186 |
QVERIFY(s == "012INSIDE345");
|
|
2187 |
s = "short";
|
|
2188 |
s.insert(7, 'E');
|
|
2189 |
QVERIFY(s == "short E");
|
|
2190 |
s = "short";
|
|
2191 |
s.insert(7, "END");
|
|
2192 |
QVERIFY(s == "short END");
|
|
2193 |
|
|
2194 |
QVERIFY(QString::fromLatin1("hello") == "hello");
|
|
2195 |
|
|
2196 |
s = "first";
|
|
2197 |
QVERIFY(s.toLatin1() == "first");
|
|
2198 |
s = "second";
|
|
2199 |
QVERIFY(s.toLatin1() == "second");
|
|
2200 |
#ifdef QT3_SUPPORT
|
|
2201 |
const char* cache = s.latin1();
|
|
2202 |
QVERIFY(cache == s.latin1());
|
|
2203 |
#endif
|
|
2204 |
s.clear();
|
|
2205 |
#ifdef QT3_SUPPORT
|
|
2206 |
QVERIFY(*s.latin1() == '\0');
|
|
2207 |
#endif
|
|
2208 |
QVERIFY(s.isNull());
|
|
2209 |
QVERIFY(s.toLatin1().size() == 0);
|
|
2210 |
QVERIFY(s.toLatin1().isEmpty());
|
|
2211 |
QVERIFY(s.toLatin1().isNull());
|
|
2212 |
|
|
2213 |
s = "first-utf8";
|
|
2214 |
QVERIFY(s.toUtf8() == "first-utf8");
|
|
2215 |
s = "second-utf8";
|
|
2216 |
QVERIFY(s.toUtf8() == "second-utf8");
|
|
2217 |
#ifdef QT3_SUPPORT
|
|
2218 |
cache = s.utf8();
|
|
2219 |
QVERIFY(cache == s.utf8());
|
|
2220 |
#endif
|
|
2221 |
s.clear();
|
|
2222 |
#ifdef QT3_SUPPORT
|
|
2223 |
QVERIFY(*s.utf8() == '\0');
|
|
2224 |
#endif
|
|
2225 |
QVERIFY(s.isNull());
|
|
2226 |
QVERIFY(s.toUtf8().size() == 0);
|
|
2227 |
QVERIFY(s.toUtf8().isEmpty());
|
|
2228 |
QVERIFY(s.toUtf8().isNull());
|
|
2229 |
|
|
2230 |
s = "first-utf8";
|
|
2231 |
QVERIFY(s.toUtf8() == "first-utf8");
|
|
2232 |
s = "second-utf8";
|
|
2233 |
QVERIFY(s.toUtf8() == "second-utf8");
|
|
2234 |
#ifdef QT3_SUPPORT
|
|
2235 |
cache = s.utf8();
|
|
2236 |
QVERIFY(cache == s.utf8());
|
|
2237 |
#endif
|
|
2238 |
s.clear();
|
|
2239 |
#ifdef QT3_SUPPORT
|
|
2240 |
QVERIFY(*s.utf8() == '\0');
|
|
2241 |
#endif
|
|
2242 |
QVERIFY(s.isNull());
|
|
2243 |
QVERIFY(s.toUtf8().size() == 0);
|
|
2244 |
QVERIFY(s.toUtf8().isEmpty());
|
|
2245 |
QVERIFY(s.toUtf8().isNull());
|
|
2246 |
|
|
2247 |
s = "first-local8Bit";
|
|
2248 |
QVERIFY(s.toLocal8Bit() == "first-local8Bit");
|
|
2249 |
s = "second-local8Bit";
|
|
2250 |
QVERIFY(s.toLocal8Bit() == "second-local8Bit");
|
|
2251 |
#ifdef QT3_SUPPORT
|
|
2252 |
cache = s.local8Bit();
|
|
2253 |
QVERIFY(cache == s.local8Bit());
|
|
2254 |
#endif
|
|
2255 |
s.clear();
|
|
2256 |
#ifdef QT3_SUPPORT
|
|
2257 |
QVERIFY(*s.local8Bit() == '\0');
|
|
2258 |
#endif
|
|
2259 |
QVERIFY(s.isNull());
|
|
2260 |
QVERIFY(s.toLocal8Bit().size() == 0);
|
|
2261 |
QVERIFY(s.toLocal8Bit().isEmpty());
|
|
2262 |
QVERIFY(!s.toLocal8Bit().isNull());
|
|
2263 |
|
|
2264 |
s = "first-ascii";
|
|
2265 |
QVERIFY(s.toAscii() == "first-ascii");
|
|
2266 |
s = "second-ascii";
|
|
2267 |
QVERIFY(s.toAscii() == "second-ascii");
|
|
2268 |
#ifdef QT3_SUPPORT
|
|
2269 |
cache = s.ascii();
|
|
2270 |
QVERIFY(cache == s.ascii());
|
|
2271 |
#endif
|
|
2272 |
s.clear();
|
|
2273 |
#ifdef QT3_SUPPORT
|
|
2274 |
QVERIFY(*s.ascii() == '\0');
|
|
2275 |
#endif
|
|
2276 |
QVERIFY(s.isNull());
|
|
2277 |
QVERIFY(s.toAscii().size() == 0);
|
|
2278 |
QVERIFY(s.toAscii().isEmpty());
|
|
2279 |
QVERIFY(s.toAscii().isNull());
|
|
2280 |
|
|
2281 |
s = "ascii";
|
|
2282 |
s += (uchar) 0xb0;
|
|
2283 |
QVERIFY(s.toUtf8() != s.toLatin1());
|
|
2284 |
QString sa = s.toLatin1().constData();
|
|
2285 |
QVERIFY(sa[sa.length()-1] == (ushort) 0xb0);
|
|
2286 |
QVERIFY(sa.left(sa.length()-1) == "ascii");
|
|
2287 |
|
|
2288 |
QVERIFY(s == QString::fromUtf8(s.toUtf8().constData()));
|
|
2289 |
|
|
2290 |
s = "12";
|
|
2291 |
s.append('3');
|
|
2292 |
s += '4';
|
|
2293 |
QVERIFY(s == "1234");
|
|
2294 |
|
|
2295 |
s = "repend";
|
|
2296 |
s.prepend('p');
|
|
2297 |
QVERIFY(s == "prepend");
|
|
2298 |
s.prepend("abc ");
|
|
2299 |
QVERIFY(s == "abc prepend");
|
|
2300 |
|
|
2301 |
s = " whitespace ";
|
|
2302 |
QVERIFY(s.trimmed() == "whitespace");
|
|
2303 |
s = " lots of stuff ";
|
|
2304 |
QVERIFY(s.simplified() == "lots of stuff");
|
|
2305 |
|
|
2306 |
s = "a hat, a stick, a ski";
|
|
2307 |
QVERIFY(s[2] == 'h');
|
|
2308 |
QVERIFY(s[1] < 'b');
|
|
2309 |
|
|
2310 |
|
|
2311 |
s = "12223";
|
|
2312 |
s.remove(1, 2);
|
|
2313 |
QVERIFY(s == "123");
|
|
2314 |
|
|
2315 |
s = "(%1)(%2)";
|
|
2316 |
s = s.arg("foo").arg(7);
|
|
2317 |
QVERIFY(s == "(foo)(7)");
|
|
2318 |
|
|
2319 |
|
|
2320 |
#if 0
|
|
2321 |
s = "stl rocks";
|
|
2322 |
std::string stl_string = s;
|
|
2323 |
s = stl_string;
|
|
2324 |
QVERIFY(s == "stl rocks");
|
|
2325 |
#endif
|
|
2326 |
|
|
2327 |
{
|
|
2328 |
QString str("Bananas");
|
|
2329 |
QVERIFY(str.startsWith("Ban"));
|
|
2330 |
QVERIFY(false == str.startsWith("Car"));
|
|
2331 |
}
|
|
2332 |
{
|
|
2333 |
QString str("Bananas");
|
|
2334 |
QVERIFY(str.endsWith("anas"));
|
|
2335 |
QVERIFY(false == str.endsWith("pple"));
|
|
2336 |
}
|
|
2337 |
|
|
2338 |
|
|
2339 |
QString str = "Hello";
|
|
2340 |
QString cstr = QString::fromRawData(str.unicode(), str.length());
|
|
2341 |
QVERIFY(str == "Hello");
|
|
2342 |
QVERIFY(cstr == "Hello");
|
|
2343 |
cstr.clear();
|
|
2344 |
QVERIFY(str == "Hello");
|
|
2345 |
QVERIFY(cstr.isEmpty());
|
|
2346 |
|
|
2347 |
{
|
|
2348 |
QString str1("Foo");
|
|
2349 |
str1.prepend(str1);
|
|
2350 |
QCOMPARE(str1, QString("FooFoo"));
|
|
2351 |
str1.append(str1);
|
|
2352 |
QCOMPARE(str1, QString("FooFooFooFoo"));
|
|
2353 |
str1.insert(2, str1);
|
|
2354 |
QCOMPARE(str1, QString("FoFooFooFooFoooFooFooFoo"));
|
|
2355 |
str1.replace(3, 3, str1);
|
|
2356 |
QCOMPARE(str1, QString("FoFFoFooFooFooFoooFooFooFooooFooFoooFooFooFoo"));
|
|
2357 |
str1 = "FooFoo";
|
|
2358 |
str1.replace(char('F'), str1);
|
|
2359 |
QCOMPARE(str1, QString("FooFooooFooFoooo"));
|
|
2360 |
str1 = "FooFoo";
|
|
2361 |
str1.replace(char('o'), str1);
|
|
2362 |
QCOMPARE(str1, QString("FFooFooFooFooFFooFooFooFoo"));
|
|
2363 |
|
|
2364 |
str1 = "Foo";
|
|
2365 |
str1.replace("Foo", str1);
|
|
2366 |
QCOMPARE(str1, QString("Foo"));
|
|
2367 |
str1.replace(str1, str1);
|
|
2368 |
QCOMPARE(str1, QString("Foo"));
|
|
2369 |
|
|
2370 |
str1 = "Foo";
|
|
2371 |
str1.replace("Foo", str1, Qt::CaseInsensitive);
|
|
2372 |
QCOMPARE(str1, QString("Foo"));
|
|
2373 |
str1.replace(str1, str1);
|
|
2374 |
QCOMPARE(str1, QString("Foo"));
|
|
2375 |
|
|
2376 |
str1 = "FooFoo";
|
|
2377 |
str1.reserve(100);
|
|
2378 |
str1.replace("oo", str1);
|
|
2379 |
QCOMPARE(str1, QString("FFooFooFFooFoo"));
|
|
2380 |
|
|
2381 |
str1 = "Bar";
|
|
2382 |
str1.replace("FooFoo", str1);
|
|
2383 |
QCOMPARE(str1, QString("Bar"));
|
|
2384 |
|
|
2385 |
str1.replace(str1, "xxx");
|
|
2386 |
QCOMPARE(str1, QString("xxx"));
|
|
2387 |
str1.replace(str1, QString("yyy"));
|
|
2388 |
QCOMPARE(str1, QString("yyy"));
|
|
2389 |
str1 += str1;
|
|
2390 |
QCOMPARE(str1, QString("yyyyyy"));
|
|
2391 |
}
|
|
2392 |
}
|
|
2393 |
|
|
2394 |
|
|
2395 |
void tst_Collections::bitArray()
|
|
2396 |
{
|
|
2397 |
QBitArray ba(20);
|
|
2398 |
QVERIFY(ba.testBit(17) == false);
|
|
2399 |
ba.setBit(17);
|
|
2400 |
QVERIFY(ba.size() == 20);
|
|
2401 |
QVERIFY(ba.testBit(17)==true);
|
|
2402 |
QVERIFY(!ba.testBit(16));
|
|
2403 |
ba[4] = true;
|
|
2404 |
QVERIFY(ba.testBit(4));
|
|
2405 |
QVERIFY(ba[4]);
|
|
2406 |
int sum = 0;
|
|
2407 |
for(int i = 0; i < 20; i++)
|
|
2408 |
sum += ba.testBit(i) ? 1 : 0;
|
|
2409 |
QVERIFY(sum == 2);
|
|
2410 |
|
|
2411 |
ba = QBitArray(7, true);
|
|
2412 |
QVERIFY(ba.size() == 7);
|
|
2413 |
QVERIFY(ba[5]);
|
|
2414 |
|
|
2415 |
ba = QBitArray(3);
|
|
2416 |
ba[0] = ba[2] = true;
|
|
2417 |
|
|
2418 |
QBitArray nba(3);
|
|
2419 |
nba[1] = true;
|
|
2420 |
|
|
2421 |
QVERIFY(~ba == nba);
|
|
2422 |
|
|
2423 |
};
|
|
2424 |
|
|
2425 |
struct CacheFoo
|
|
2426 |
{
|
|
2427 |
CacheFoo(int v):val(v) { counter++; }
|
|
2428 |
~CacheFoo() { counter--; }
|
|
2429 |
int val;
|
|
2430 |
static int counter;
|
|
2431 |
bool isDetached() const { return val != 2; }
|
|
2432 |
};
|
|
2433 |
|
|
2434 |
int CacheFoo::counter = 0;
|
|
2435 |
|
|
2436 |
void tst_Collections::cache()
|
|
2437 |
{
|
|
2438 |
{
|
|
2439 |
CacheFoo* cf;
|
|
2440 |
QCache<int, CacheFoo> cache(120);
|
|
2441 |
int i;
|
|
2442 |
for (i = 0; i < 30; i++) {
|
|
2443 |
cf = cache.object(10);
|
|
2444 |
cache.insert(i, new CacheFoo(i), i);
|
|
2445 |
}
|
|
2446 |
|
|
2447 |
QVERIFY(cache.contains(10));
|
|
2448 |
QVERIFY(!cache.contains(1));
|
|
2449 |
QVERIFY(!cache.contains(2));
|
|
2450 |
delete cache.take(10);
|
|
2451 |
}
|
|
2452 |
{
|
|
2453 |
QCache<int, QString> cache(120);
|
|
2454 |
int i;
|
|
2455 |
QString two;
|
|
2456 |
for (i = 0; i < 30; i++) {
|
|
2457 |
QString s = QString::number(i);
|
|
2458 |
cache.insert(i, new QString(s), i);
|
|
2459 |
if (i == 2)
|
|
2460 |
two = s;
|
|
2461 |
}
|
|
2462 |
QVERIFY(!cache.contains(3));
|
|
2463 |
QVERIFY(cache.contains(2));
|
|
2464 |
}
|
|
2465 |
{
|
|
2466 |
QCache<int, int> cache(100);
|
|
2467 |
cache.insert(2, new int(2));
|
|
2468 |
*cache[2] = 3;
|
|
2469 |
QVERIFY(*cache.object(2) == 3);
|
|
2470 |
}
|
|
2471 |
|
|
2472 |
QVERIFY(CacheFoo::counter == 0);
|
|
2473 |
|
|
2474 |
}
|
|
2475 |
|
|
2476 |
void tst_Collections::regexp()
|
|
2477 |
{
|
|
2478 |
QRegExp rx("^\\d\\d?$");
|
|
2479 |
QVERIFY(rx.indexIn("123") == -1);
|
|
2480 |
QVERIFY(rx.indexIn("-6") == -1);
|
|
2481 |
QVERIFY(rx.indexIn("6") == 0) ;
|
|
2482 |
}
|
|
2483 |
|
|
2484 |
void tst_Collections::pair()
|
|
2485 |
{
|
|
2486 |
QPair<double, int> p;
|
|
2487 |
QVERIFY(p.first == 0.0);
|
|
2488 |
QVERIFY(p.second == 0);
|
|
2489 |
|
|
2490 |
QPair<int, QString> a(1, "Zebra"), b(2, "Ying"), c(3, "Yang"), d(3, "Ying"), e(5, "Alabama");
|
|
2491 |
QVERIFY(a.first == 1);
|
|
2492 |
QVERIFY(a.second == "Zebra");
|
|
2493 |
QVERIFY(a == qMakePair(1, QString("Zebra")));
|
|
2494 |
|
|
2495 |
QVERIFY(a == a && b == b && c == c && d == d && e == e);
|
|
2496 |
QVERIFY(a != b && a != c && a != d && a != e && b != c && b != d && b != e && c != d && c != e
|
|
2497 |
&& d != e);
|
|
2498 |
|
|
2499 |
QVERIFY(a < b && b < c && c < d && d < e);
|
|
2500 |
QVERIFY(a <= b && b <= c && c <= d && d <= e);
|
|
2501 |
|
|
2502 |
QVERIFY(e > d && d > c && c > b && b > a);
|
|
2503 |
QVERIFY(e >= d && d >= c && c >= b && b >= a);
|
|
2504 |
|
|
2505 |
QVERIFY(!(a > b || b > c || c > d || d > e));
|
|
2506 |
QVERIFY(!(a >= b || b >= c || c >= d || d >= e));
|
|
2507 |
|
|
2508 |
QVERIFY(!(e < d || d < c || c < b || b < a));
|
|
2509 |
QVERIFY(!(e <= d || d <= c || c <= b || b <= a));
|
|
2510 |
|
|
2511 |
QVERIFY(a <= a && b <= b && c <= c && d <= d && e <= e);
|
|
2512 |
QVERIFY(!(a < a || b < b || c < c || d < d || e < e));
|
|
2513 |
|
|
2514 |
QVERIFY(a >= a && b >= b && c >= c && d >= d && e >= e);
|
|
2515 |
QVERIFY(!(a > a || b > b || c > c || d > d || e > e));
|
|
2516 |
}
|
|
2517 |
|
|
2518 |
void tst_Collections::cleanupHandler()
|
|
2519 |
{
|
|
2520 |
#ifdef QT3_SUPPORT
|
|
2521 |
LargeStatic * f1 = 0;
|
|
2522 |
LargeStatic * f2 = 0;
|
|
2523 |
{
|
|
2524 |
Q3CleanupHandler<LargeStatic> cleanup;
|
|
2525 |
f1 = new LargeStatic;
|
|
2526 |
f2 = new LargeStatic;
|
|
2527 |
cleanup.add(&f1);
|
|
2528 |
cleanup.add(&f2);
|
|
2529 |
}
|
|
2530 |
QVERIFY(f1 == 0 && f2 == 0);
|
|
2531 |
#else
|
|
2532 |
QSKIP("No Qt3 support", SkipAll);
|
|
2533 |
#endif
|
|
2534 |
}
|
|
2535 |
|
|
2536 |
/*
|
|
2537 |
These test that Java-style mutable iterators don't trash shared
|
|
2538 |
copy (the setSharable() mechanism).
|
|
2539 |
*/
|
|
2540 |
|
|
2541 |
template <class Container>
|
|
2542 |
void populate(Container &);
|
|
2543 |
|
|
2544 |
template <>
|
|
2545 |
void populate(QList<int> &container)
|
|
2546 |
{
|
|
2547 |
container << 1 << 2 << 4 << 8;
|
|
2548 |
}
|
|
2549 |
|
|
2550 |
template <>
|
|
2551 |
void populate(QLinkedList<int> &container)
|
|
2552 |
{
|
|
2553 |
container << 1 << 2 << 4 << 8;
|
|
2554 |
}
|
|
2555 |
|
|
2556 |
template <>
|
|
2557 |
void populate(QVector<int> &container)
|
|
2558 |
{
|
|
2559 |
container << 1 << 2 << 4 << 8;
|
|
2560 |
}
|
|
2561 |
|
|
2562 |
template <>
|
|
2563 |
void populate(QMap<int, int> &container)
|
|
2564 |
{
|
|
2565 |
container.insert(1, 1);
|
|
2566 |
container.insert(2, 2);
|
|
2567 |
container.insert(4, 4);
|
|
2568 |
container.insert(8, 8);
|
|
2569 |
}
|
|
2570 |
|
|
2571 |
template <>
|
|
2572 |
void populate(QHash<int, int> &container)
|
|
2573 |
{
|
|
2574 |
container.insert(1, 1);
|
|
2575 |
container.insert(2, 2);
|
|
2576 |
container.insert(4, 4);
|
|
2577 |
container.insert(8, 8);
|
|
2578 |
}
|
|
2579 |
|
|
2580 |
template <class Container>
|
|
2581 |
bool isSharable(const Container &container)
|
|
2582 |
{
|
|
2583 |
Container copy = container;
|
|
2584 |
return !container.isDetached();
|
|
2585 |
}
|
|
2586 |
|
|
2587 |
template <class Container, class ContainerMutableIterator>
|
|
2588 |
void testContainer()
|
|
2589 |
{
|
|
2590 |
/*
|
|
2591 |
Verify that shared_null's 'sharable' flag is set to true.
|
|
2592 |
*/
|
|
2593 |
{
|
|
2594 |
Container c1;
|
|
2595 |
QVERIFY(!c1.isDetached());
|
|
2596 |
|
|
2597 |
Container c2 = c1;
|
|
2598 |
QVERIFY(!c1.isDetached());
|
|
2599 |
QVERIFY(!c2.isDetached());
|
|
2600 |
}
|
|
2601 |
|
|
2602 |
/*
|
|
2603 |
Verify that the 'sharable' flag is true while no mutable
|
|
2604 |
iterator is active.
|
|
2605 |
*/
|
|
2606 |
{
|
|
2607 |
Container c1;
|
|
2608 |
populate(c1);
|
|
2609 |
QVERIFY(c1.size() == 4);
|
|
2610 |
QVERIFY(c1.isDetached());
|
|
2611 |
|
|
2612 |
Container c2 = c1;
|
|
2613 |
QVERIFY(c1.size() == 4);
|
|
2614 |
QVERIFY(c2.size() == 4);
|
|
2615 |
QVERIFY(!c1.isDetached());
|
|
2616 |
QVERIFY(!c2.isDetached());
|
|
2617 |
}
|
|
2618 |
|
|
2619 |
/*
|
|
2620 |
Verify that the 'sharable' flag is set to false by the
|
|
2621 |
mutable iterator.
|
|
2622 |
*/
|
|
2623 |
{
|
|
2624 |
Container c1;
|
|
2625 |
populate(c1);
|
|
2626 |
QVERIFY(c1.size() == 4);
|
|
2627 |
QVERIFY(c1.isDetached());
|
|
2628 |
|
|
2629 |
ContainerMutableIterator i(c1);
|
|
2630 |
i.next();
|
|
2631 |
|
|
2632 |
Container c2 = c1;
|
|
2633 |
QVERIFY(c1.size() == 4);
|
|
2634 |
QVERIFY(c2.size() == 4);
|
|
2635 |
QVERIFY(c1.isDetached());
|
|
2636 |
QVERIFY(c2.isDetached());
|
|
2637 |
|
|
2638 |
i.remove();
|
|
2639 |
QVERIFY(c1.size() == 3);
|
|
2640 |
QVERIFY(c2.size() == 4);
|
|
2641 |
}
|
|
2642 |
|
|
2643 |
/*
|
|
2644 |
Verify that the 'sharable' flag is reset to true by the
|
|
2645 |
mutable iterator's destructor.
|
|
2646 |
*/
|
|
2647 |
{
|
|
2648 |
Container c1;
|
|
2649 |
populate(c1);
|
|
2650 |
QVERIFY(c1.size() == 4);
|
|
2651 |
QVERIFY(c1.isDetached());
|
|
2652 |
|
|
2653 |
{
|
|
2654 |
ContainerMutableIterator i(c1);
|
|
2655 |
i.next();
|
|
2656 |
}
|
|
2657 |
|
|
2658 |
Container c2 = c1;
|
|
2659 |
QVERIFY(c1.size() == 4);
|
|
2660 |
QVERIFY(c2.size() == 4);
|
|
2661 |
QVERIFY(!c1.isDetached());
|
|
2662 |
QVERIFY(!c2.isDetached());
|
|
2663 |
}
|
|
2664 |
|
|
2665 |
/*
|
|
2666 |
Verify that the 'sharable' flag only affects the original
|
|
2667 |
object, not the copies.
|
|
2668 |
*/
|
|
2669 |
{
|
|
2670 |
Container c1;
|
|
2671 |
populate(c1);
|
|
2672 |
QVERIFY(c1.size() == 4);
|
|
2673 |
QVERIFY(c1.isDetached());
|
|
2674 |
|
|
2675 |
Container c2 = c1;
|
|
2676 |
QVERIFY(isSharable(c2));
|
|
2677 |
|
|
2678 |
ContainerMutableIterator i(c1);
|
|
2679 |
QVERIFY(!isSharable(c1));
|
|
2680 |
QVERIFY(isSharable(c2));
|
|
2681 |
|
|
2682 |
Container c3 = c1;
|
|
2683 |
QVERIFY(!isSharable(c1));
|
|
2684 |
QVERIFY(isSharable(c2));
|
|
2685 |
QVERIFY(isSharable(c3));
|
|
2686 |
QVERIFY(c1.isDetached());
|
|
2687 |
QVERIFY(c2.isDetached());
|
|
2688 |
QVERIFY(c3.isDetached());
|
|
2689 |
|
|
2690 |
Container c4;
|
|
2691 |
c4 = c1;
|
|
2692 |
QVERIFY(!isSharable(c1));
|
|
2693 |
QVERIFY(isSharable(c2));
|
|
2694 |
QVERIFY(isSharable(c4));
|
|
2695 |
QVERIFY(c1.isDetached());
|
|
2696 |
QVERIFY(c2.isDetached());
|
|
2697 |
QVERIFY(c4.isDetached());
|
|
2698 |
|
|
2699 |
c3 = c2;
|
|
2700 |
QVERIFY(!isSharable(c1));
|
|
2701 |
QVERIFY(isSharable(c2));
|
|
2702 |
QVERIFY(isSharable(c3));
|
|
2703 |
QVERIFY(c1.isDetached());
|
|
2704 |
QVERIFY(!c2.isDetached());
|
|
2705 |
QVERIFY(!c3.isDetached());
|
|
2706 |
}
|
|
2707 |
}
|
|
2708 |
|
|
2709 |
#define TEST_SEQUENTIAL_CONTAINER(Container) \
|
|
2710 |
testContainer<Q##Container<int>, QMutable##Container##Iterator<int> >()
|
|
2711 |
|
|
2712 |
#define TEST_ASSOCIATIVE_CONTAINER(Container) \
|
|
2713 |
testContainer<Q##Container<int, int>, QMutable##Container##Iterator<int, int> >()
|
|
2714 |
|
|
2715 |
void tst_Collections::sharableQList()
|
|
2716 |
{
|
|
2717 |
TEST_SEQUENTIAL_CONTAINER(List);
|
|
2718 |
}
|
|
2719 |
|
|
2720 |
void tst_Collections::sharableQLinkedList()
|
|
2721 |
{
|
|
2722 |
TEST_SEQUENTIAL_CONTAINER(LinkedList);
|
|
2723 |
}
|
|
2724 |
|
|
2725 |
void tst_Collections::sharableQVector()
|
|
2726 |
{
|
|
2727 |
TEST_SEQUENTIAL_CONTAINER(Vector);
|
|
2728 |
}
|
|
2729 |
|
|
2730 |
void tst_Collections::sharableQMap()
|
|
2731 |
{
|
|
2732 |
TEST_ASSOCIATIVE_CONTAINER(Map);
|
|
2733 |
}
|
|
2734 |
|
|
2735 |
void tst_Collections::sharableQHash()
|
|
2736 |
{
|
|
2737 |
TEST_ASSOCIATIVE_CONTAINER(Hash);
|
|
2738 |
}
|
|
2739 |
|
|
2740 |
static int getList_calls = 0;
|
|
2741 |
QList<int> getList()
|
|
2742 |
{
|
|
2743 |
++getList_calls;
|
|
2744 |
QList<int> list;
|
|
2745 |
list << 1 << 2 << 3 << 4 << 5 << 6;
|
|
2746 |
return list;
|
|
2747 |
}
|
|
2748 |
|
|
2749 |
|
|
2750 |
void tst_Collections::q_foreach()
|
|
2751 |
{
|
|
2752 |
QList<int> list;
|
|
2753 |
list << -2 << -1 << 0 << 1 << 2;
|
|
2754 |
|
|
2755 |
int sum = 0;
|
|
2756 |
int j = 0;
|
|
2757 |
foreach(int i, list) {
|
|
2758 |
QCOMPARE(i, list.at(j));
|
|
2759 |
sum += i;
|
|
2760 |
++j;
|
|
2761 |
}
|
|
2762 |
QCOMPARE(sum, 0);
|
|
2763 |
|
|
2764 |
// again, but without scope
|
|
2765 |
foreach(int i, list)
|
|
2766 |
sum += i;
|
|
2767 |
QCOMPARE(sum, 0);
|
|
2768 |
|
|
2769 |
foreach(int i, list) {
|
|
2770 |
sum += i;
|
|
2771 |
if (i == 0)
|
|
2772 |
break;
|
|
2773 |
}
|
|
2774 |
QCOMPARE(sum, -3);
|
|
2775 |
|
|
2776 |
sum = 0;
|
|
2777 |
foreach(int i, list) {
|
|
2778 |
if (i < 0)
|
|
2779 |
continue;
|
|
2780 |
sum += i;
|
|
2781 |
}
|
|
2782 |
QCOMPARE(sum, 3);
|
|
2783 |
|
|
2784 |
sum = 0;
|
|
2785 |
getList_calls = 0;
|
|
2786 |
foreach(int i, getList())
|
|
2787 |
sum += i;
|
|
2788 |
QCOMPARE(sum, 21);
|
|
2789 |
QCOMPARE(getList_calls, 1);
|
|
2790 |
}
|
|
2791 |
|
|
2792 |
|
|
2793 |
void tst_Collections::conversions()
|
|
2794 |
{
|
|
2795 |
#define STUFF "A" << "C" << "B" << "A"
|
|
2796 |
|
|
2797 |
{
|
|
2798 |
QList<QString> list1;
|
|
2799 |
list1 << STUFF;
|
|
2800 |
|
|
2801 |
QVector<QString> vect1 = list1.toVector();
|
|
2802 |
QCOMPARE(list1.size(), 4);
|
|
2803 |
QVERIFY(vect1 == (QVector<QString>() << STUFF));
|
|
2804 |
|
|
2805 |
QList<QString> list2 = vect1.toList();
|
|
2806 |
QCOMPARE(list2.size(), 4);
|
|
2807 |
QVERIFY(list2 == (QList<QString>() << STUFF));
|
|
2808 |
|
|
2809 |
QSet<QString> set1 = list1.toSet();
|
|
2810 |
QCOMPARE(set1.size(), 3);
|
|
2811 |
QVERIFY(set1.contains("A"));
|
|
2812 |
QVERIFY(set1.contains("B"));
|
|
2813 |
QVERIFY(set1.contains("C"));
|
|
2814 |
QVERIFY(!set1.contains("D"));
|
|
2815 |
|
|
2816 |
QList<QString> list3 = set1.toList();
|
|
2817 |
QCOMPARE(list3.size(), 3);
|
|
2818 |
QVERIFY(list3.contains("A"));
|
|
2819 |
QVERIFY(list3.contains("B"));
|
|
2820 |
QVERIFY(list3.contains("C"));
|
|
2821 |
QVERIFY(!list3.contains("D"));
|
|
2822 |
|
|
2823 |
QVERIFY(QList<int>().toVector().isEmpty());
|
|
2824 |
QVERIFY(QList<int>().toSet().isEmpty());
|
|
2825 |
QVERIFY(QVector<int>().toList().isEmpty());
|
|
2826 |
QVERIFY(QSet<int>().toList().isEmpty());
|
|
2827 |
}
|
|
2828 |
|
|
2829 |
{
|
|
2830 |
QList<QString> list1;
|
|
2831 |
list1 << STUFF;
|
|
2832 |
|
|
2833 |
QVector<QString> vect1 = QVector<QString>::fromList(list1);
|
|
2834 |
QCOMPARE(list1.size(), 4);
|
|
2835 |
QVERIFY(vect1 == (QVector<QString>() << STUFF));
|
|
2836 |
|
|
2837 |
QList<QString> list2 = QList<QString>::fromVector(vect1);
|
|
2838 |
QCOMPARE(list2.size(), 4);
|
|
2839 |
QVERIFY(list2 == (QList<QString>() << STUFF));
|
|
2840 |
|
|
2841 |
QSet<QString> set1 = QSet<QString>::fromList(list1);
|
|
2842 |
QCOMPARE(set1.size(), 3);
|
|
2843 |
QVERIFY(set1.contains("A"));
|
|
2844 |
QVERIFY(set1.contains("B"));
|
|
2845 |
QVERIFY(set1.contains("C"));
|
|
2846 |
QVERIFY(!set1.contains("D"));
|
|
2847 |
|
|
2848 |
QList<QString> list3 = QList<QString>::fromSet(set1);
|
|
2849 |
QCOMPARE(list3.size(), 3);
|
|
2850 |
QVERIFY(list3.contains("A"));
|
|
2851 |
QVERIFY(list3.contains("B"));
|
|
2852 |
QVERIFY(list3.contains("C"));
|
|
2853 |
QVERIFY(!list3.contains("D"));
|
|
2854 |
|
|
2855 |
QVERIFY(QVector<int>::fromList(QList<int>()).isEmpty());
|
|
2856 |
QVERIFY(QSet<int>::fromList(QList<int>()).isEmpty());
|
|
2857 |
QVERIFY(QList<int>::fromVector(QVector<int>()).isEmpty());
|
|
2858 |
QVERIFY(QList<int>::fromSet(QSet<int>()).isEmpty());
|
|
2859 |
}
|
|
2860 |
#undef STUFF
|
|
2861 |
}
|
|
2862 |
|
|
2863 |
void tst_Collections::javaStyleIterators()
|
|
2864 |
{
|
|
2865 |
QStringList list;
|
|
2866 |
list << "a" << "b" << "c";
|
|
2867 |
QMutableStringListIterator i(list);
|
|
2868 |
while (i.hasNext()) {
|
|
2869 |
i.next();
|
|
2870 |
i.setValue("");
|
|
2871 |
}
|
|
2872 |
while (i.hasPrevious()) {
|
|
2873 |
i.previous();
|
|
2874 |
QVERIFY(i.value().isEmpty());
|
|
2875 |
i.value() = "x";
|
|
2876 |
QCOMPARE(i.value(), QString("x"));
|
|
2877 |
}
|
|
2878 |
}
|
|
2879 |
|
|
2880 |
template <class Container>
|
|
2881 |
void testLinkedListLikeStlIterators()
|
|
2882 |
{
|
|
2883 |
Container fake;
|
|
2884 |
typename Container::value_type t;
|
|
2885 |
fake << t;
|
|
2886 |
|
|
2887 |
typename Container::iterator i1 = fake.begin(), i2 = i1 + 1;
|
|
2888 |
typename Container::const_iterator c1 = i1, c2 = c1 + 1;
|
|
2889 |
|
|
2890 |
QVERIFY(i1 == i1);
|
|
2891 |
QVERIFY(i1 == c1);
|
|
2892 |
QVERIFY(c1 == i1);
|
|
2893 |
QVERIFY(c1 == c1);
|
|
2894 |
QVERIFY(i2 == i2);
|
|
2895 |
QVERIFY(i2 == c2);
|
|
2896 |
QVERIFY(c2 == i2);
|
|
2897 |
QVERIFY(c2 == c2);
|
|
2898 |
|
|
2899 |
QVERIFY(i1 != i2);
|
|
2900 |
QVERIFY(i1 != c2);
|
|
2901 |
QVERIFY(c1 != i2);
|
|
2902 |
QVERIFY(c1 != c2);
|
|
2903 |
QVERIFY(i2 != i1);
|
|
2904 |
QVERIFY(i2 != c1);
|
|
2905 |
QVERIFY(c2 != i1);
|
|
2906 |
QVERIFY(c2 != c1);
|
|
2907 |
}
|
|
2908 |
|
|
2909 |
template <class Container>
|
|
2910 |
void testListLikeStlIterators()
|
|
2911 |
{
|
|
2912 |
testLinkedListLikeStlIterators<Container>();
|
|
2913 |
|
|
2914 |
Container fake;
|
|
2915 |
typename Container::value_type t;
|
|
2916 |
fake << t;
|
|
2917 |
|
|
2918 |
typename Container::iterator i1 = fake.begin(), i2 = i1 + 1;
|
|
2919 |
typename Container::const_iterator c1 = i1, c2 = c1 + 1;
|
|
2920 |
|
|
2921 |
QVERIFY(i1 < i2);
|
|
2922 |
QVERIFY(i1 < c2);
|
|
2923 |
QVERIFY(c1 < i2);
|
|
2924 |
QVERIFY(c1 < c2);
|
|
2925 |
QVERIFY(!(i2 < i1));
|
|
2926 |
QVERIFY(!(i2 < c1));
|
|
2927 |
QVERIFY(!(c2 < i1));
|
|
2928 |
QVERIFY(!(c2 < c1));
|
|
2929 |
QVERIFY(!(i1 < i1));
|
|
2930 |
QVERIFY(!(i1 < c1));
|
|
2931 |
QVERIFY(!(c1 < i1));
|
|
2932 |
QVERIFY(!(c1 < c1));
|
|
2933 |
QVERIFY(!(i2 < i2));
|
|
2934 |
QVERIFY(!(i2 < c2));
|
|
2935 |
QVERIFY(!(c2 < i2));
|
|
2936 |
QVERIFY(!(c2 < c2));
|
|
2937 |
|
|
2938 |
QVERIFY(i2 > i1);
|
|
2939 |
QVERIFY(i2 > c1);
|
|
2940 |
QVERIFY(c2 > i1);
|
|
2941 |
QVERIFY(c2 > c1);
|
|
2942 |
QVERIFY(!(i1 > i2));
|
|
2943 |
QVERIFY(!(i1 > c2));
|
|
2944 |
QVERIFY(!(c1 > i2));
|
|
2945 |
QVERIFY(!(c1 > c2));
|
|
2946 |
QVERIFY(!(i1 > i1));
|
|
2947 |
QVERIFY(!(i1 > c1));
|
|
2948 |
QVERIFY(!(c1 > i1));
|
|
2949 |
QVERIFY(!(c1 > c1));
|
|
2950 |
QVERIFY(!(i2 > i2));
|
|
2951 |
QVERIFY(!(i2 > c2));
|
|
2952 |
QVERIFY(!(c2 > i2));
|
|
2953 |
QVERIFY(!(c2 > c2));
|
|
2954 |
|
|
2955 |
QVERIFY(!(i1 >= i2));
|
|
2956 |
QVERIFY(!(i1 >= c2));
|
|
2957 |
QVERIFY(!(c1 >= i2));
|
|
2958 |
QVERIFY(!(c1 >= c2));
|
|
2959 |
QVERIFY(i2 >= i1);
|
|
2960 |
QVERIFY(i2 >= c1);
|
|
2961 |
QVERIFY(c2 >= i1);
|
|
2962 |
QVERIFY(c2 >= c1);
|
|
2963 |
QVERIFY(i1 >= i1);
|
|
2964 |
QVERIFY(i1 >= c1);
|
|
2965 |
QVERIFY(c1 >= i1);
|
|
2966 |
QVERIFY(c1 >= c1);
|
|
2967 |
QVERIFY(i2 >= i2);
|
|
2968 |
QVERIFY(i2 >= c2);
|
|
2969 |
QVERIFY(c2 >= i2);
|
|
2970 |
QVERIFY(c2 >= c2);
|
|
2971 |
|
|
2972 |
QVERIFY(!(i2 <= i1));
|
|
2973 |
QVERIFY(!(i2 <= c1));
|
|
2974 |
QVERIFY(!(c2 <= i1));
|
|
2975 |
QVERIFY(!(c2 <= c1));
|
|
2976 |
QVERIFY(i1 <= i2);
|
|
2977 |
QVERIFY(i1 <= c2);
|
|
2978 |
QVERIFY(c1 <= i2);
|
|
2979 |
QVERIFY(c1 <= c2);
|
|
2980 |
QVERIFY(i1 <= i1);
|
|
2981 |
QVERIFY(i1 <= c1);
|
|
2982 |
QVERIFY(c1 <= i1);
|
|
2983 |
QVERIFY(c1 <= c1);
|
|
2984 |
QVERIFY(i2 <= i2);
|
|
2985 |
QVERIFY(i2 <= c2);
|
|
2986 |
QVERIFY(c2 <= i2);
|
|
2987 |
QVERIFY(c2 <= c2);
|
|
2988 |
}
|
|
2989 |
|
|
2990 |
template <class Container>
|
|
2991 |
void testMapLikeStlIterators()
|
|
2992 |
{
|
|
2993 |
Container fake;
|
|
2994 |
QString k;
|
|
2995 |
QString t;
|
|
2996 |
fake.insert(k, t);
|
|
2997 |
|
|
2998 |
typename Container::iterator i1 = fake.begin(), i2 = i1 + 1;
|
|
2999 |
typename Container::const_iterator c1 = i1, c2 = c1 + 1;
|
|
3000 |
|
|
3001 |
QVERIFY(i1 == i1);
|
|
3002 |
QVERIFY(i1 == c1);
|
|
3003 |
QVERIFY(c1 == i1);
|
|
3004 |
QVERIFY(c1 == c1);
|
|
3005 |
QVERIFY(i2 == i2);
|
|
3006 |
QVERIFY(i2 == c2);
|
|
3007 |
QVERIFY(c2 == i2);
|
|
3008 |
QVERIFY(c2 == c2);
|
|
3009 |
|
|
3010 |
QVERIFY(i1 != i2);
|
|
3011 |
QVERIFY(i1 != c2);
|
|
3012 |
QVERIFY(c1 != i2);
|
|
3013 |
QVERIFY(c1 != c2);
|
|
3014 |
QVERIFY(i2 != i1);
|
|
3015 |
QVERIFY(i2 != c1);
|
|
3016 |
QVERIFY(c2 != i1);
|
|
3017 |
QVERIFY(c2 != c1);
|
|
3018 |
}
|
|
3019 |
|
|
3020 |
void tst_Collections::constAndNonConstStlIterators()
|
|
3021 |
{
|
|
3022 |
testListLikeStlIterators<QList<int> >();
|
|
3023 |
testListLikeStlIterators<QStringList >();
|
|
3024 |
testLinkedListLikeStlIterators<QLinkedList<int> >();
|
|
3025 |
testListLikeStlIterators<QVector<int> >();
|
|
3026 |
testMapLikeStlIterators<QMap<QString, QString> >();
|
|
3027 |
testMapLikeStlIterators<QMultiMap<QString, QString> >();
|
|
3028 |
testMapLikeStlIterators<QHash<QString, QString> >();
|
|
3029 |
testMapLikeStlIterators<QMultiHash<QString, QString> >();
|
|
3030 |
}
|
|
3031 |
|
|
3032 |
#ifndef QT_NO_STL
|
|
3033 |
void tst_Collections::vector_stl_data()
|
|
3034 |
{
|
|
3035 |
QTest::addColumn<QStringList>("elements");
|
|
3036 |
|
|
3037 |
QTest::newRow("empty") << QStringList();
|
|
3038 |
QTest::newRow("one") << (QStringList() << "Hei");
|
|
3039 |
QTest::newRow("two") << (QStringList() << "Hei" << "Hopp");
|
|
3040 |
QTest::newRow("three") << (QStringList() << "Hei" << "Hopp" << "Sann");
|
|
3041 |
}
|
|
3042 |
|
|
3043 |
void tst_Collections::vector_stl()
|
|
3044 |
{
|
|
3045 |
QFETCH(QStringList, elements);
|
|
3046 |
|
|
3047 |
QVector<QString> vector;
|
|
3048 |
for (int i = 0; i < elements.count(); ++i)
|
|
3049 |
vector << elements.at(i);
|
|
3050 |
|
|
3051 |
std::vector<QString> stdVector = vector.toStdVector();
|
|
3052 |
|
|
3053 |
QCOMPARE(int(stdVector.size()), elements.size());
|
|
3054 |
|
|
3055 |
std::vector<QString>::const_iterator it = stdVector.begin();
|
|
3056 |
for (uint j = 0; j < stdVector.size() && it != stdVector.end(); ++j, ++it)
|
|
3057 |
QCOMPARE(*it, vector[j]);
|
|
3058 |
|
|
3059 |
QCOMPARE(QVector<QString>::fromStdVector(stdVector), vector);
|
|
3060 |
}
|
|
3061 |
|
|
3062 |
void tst_Collections::linkedlist_stl_data()
|
|
3063 |
{
|
|
3064 |
list_stl_data();
|
|
3065 |
}
|
|
3066 |
|
|
3067 |
void tst_Collections::linkedlist_stl()
|
|
3068 |
{
|
|
3069 |
QFETCH(QStringList, elements);
|
|
3070 |
|
|
3071 |
QLinkedList<QString> list;
|
|
3072 |
for (int i = 0; i < elements.count(); ++i)
|
|
3073 |
list << elements.at(i);
|
|
3074 |
|
|
3075 |
std::list<QString> stdList = list.toStdList();
|
|
3076 |
|
|
3077 |
QCOMPARE(int(stdList.size()), elements.size());
|
|
3078 |
|
|
3079 |
std::list<QString>::const_iterator it = stdList.begin();
|
|
3080 |
QLinkedList<QString>::const_iterator it2 = list.constBegin();
|
|
3081 |
for (uint j = 0; j < stdList.size(); ++j, ++it, ++it2)
|
|
3082 |
QCOMPARE(*it, *it2);
|
|
3083 |
|
|
3084 |
QCOMPARE(QLinkedList<QString>::fromStdList(stdList), list);
|
|
3085 |
}
|
|
3086 |
|
|
3087 |
void tst_Collections::list_stl_data()
|
|
3088 |
{
|
|
3089 |
QTest::addColumn<QStringList>("elements");
|
|
3090 |
|
|
3091 |
QTest::newRow("empty") << QStringList();
|
|
3092 |
QTest::newRow("one") << (QStringList() << "Hei");
|
|
3093 |
QTest::newRow("two") << (QStringList() << "Hei" << "Hopp");
|
|
3094 |
QTest::newRow("three") << (QStringList() << "Hei" << "Hopp" << "Sann");
|
|
3095 |
}
|
|
3096 |
|
|
3097 |
void tst_Collections::list_stl()
|
|
3098 |
{
|
|
3099 |
QFETCH(QStringList, elements);
|
|
3100 |
|
|
3101 |
QList<QString> list;
|
|
3102 |
for (int i = 0; i < elements.count(); ++i)
|
|
3103 |
list << elements.at(i);
|
|
3104 |
|
|
3105 |
std::list<QString> stdList = list.toStdList();
|
|
3106 |
|
|
3107 |
QCOMPARE(int(stdList.size()), elements.size());
|
|
3108 |
|
|
3109 |
std::list<QString>::const_iterator it = stdList.begin();
|
|
3110 |
for (uint j = 0; j < stdList.size() && it != stdList.end(); ++j, ++it)
|
|
3111 |
QCOMPARE(*it, list[j]);
|
|
3112 |
|
|
3113 |
QCOMPARE(QList<QString>::fromStdList(stdList), list);
|
|
3114 |
}
|
|
3115 |
#endif
|
|
3116 |
|
|
3117 |
template <typename T>
|
|
3118 |
T qtInit(T * = 0)
|
|
3119 |
{
|
|
3120 |
return T();
|
|
3121 |
}
|
|
3122 |
|
|
3123 |
void tst_Collections::q_init()
|
|
3124 |
{
|
|
3125 |
QCOMPARE(qtInit<int>(), 0);
|
|
3126 |
QCOMPARE(qtInit<double>(), 0.0);
|
|
3127 |
QCOMPARE(qtInit<QString>(), QString());
|
|
3128 |
QCOMPARE(qtInit<int *>(), static_cast<int *>(0));
|
|
3129 |
QCOMPARE(qtInit<double *>(), static_cast<double *>(0));
|
|
3130 |
QCOMPARE(qtInit<QString *>(), static_cast<QString *>(0));
|
|
3131 |
QCOMPARE(qtInit<Pod>().i1, 0);
|
|
3132 |
QCOMPARE(qtInit<Pod>().i2, 0);
|
|
3133 |
}
|
|
3134 |
|
|
3135 |
void tst_Collections::pointersize()
|
|
3136 |
{
|
|
3137 |
QCOMPARE(int(sizeof(void *)), QT_POINTER_SIZE);
|
|
3138 |
}
|
|
3139 |
|
|
3140 |
class LessThanComparable
|
|
3141 |
{
|
|
3142 |
public:
|
|
3143 |
bool operator<(const LessThanComparable &) const { return true; }
|
|
3144 |
};
|
|
3145 |
|
|
3146 |
class EqualsComparable
|
|
3147 |
{
|
|
3148 |
public:
|
|
3149 |
bool operator==(const EqualsComparable &) const { return true; }
|
|
3150 |
};
|
|
3151 |
|
|
3152 |
uint qHash(const EqualsComparable &)
|
|
3153 |
{
|
|
3154 |
return 0;
|
|
3155 |
}
|
|
3156 |
|
|
3157 |
/*
|
|
3158 |
The following functions instatiates every member functions in the
|
|
3159 |
Qt containers that requires either operator== or operator<.
|
|
3160 |
They are ordered in a concept inheritance tree:
|
|
3161 |
|
|
3162 |
Container
|
|
3163 |
MutableIterationContainer
|
|
3164 |
Sequence (QLinkedList)
|
|
3165 |
Random Access (QVector, QList, QQueue, QStack)
|
|
3166 |
Pair Associative (QHash, QMap)
|
|
3167 |
Associative (QSet)
|
|
3168 |
*/
|
|
3169 |
template <typename ContainerType, typename ValueType>
|
|
3170 |
void instantiateContainer()
|
|
3171 |
{
|
|
3172 |
const ValueType value = ValueType();
|
|
3173 |
ContainerType container;
|
|
3174 |
const ContainerType constContainer(container);
|
|
3175 |
|
|
3176 |
#ifndef QT_NO_STL
|
|
3177 |
typename ContainerType::const_iterator constIt;
|
|
3178 |
constIt = constContainer.begin();
|
|
3179 |
container.constBegin();
|
|
3180 |
|
|
3181 |
constIt = constContainer.end();
|
|
3182 |
container.constEnd();
|
|
3183 |
#endif
|
|
3184 |
container.clear();
|
|
3185 |
container.contains(value);
|
|
3186 |
container.count();
|
|
3187 |
container.empty();
|
|
3188 |
container.isEmpty();
|
|
3189 |
container.size();
|
|
3190 |
|
|
3191 |
container != constContainer;
|
|
3192 |
container == constContainer;
|
|
3193 |
container = constContainer;
|
|
3194 |
}
|
|
3195 |
|
|
3196 |
template <typename ContainerType, typename ValueType>
|
|
3197 |
void instantiateMutableIterationContainer()
|
|
3198 |
{
|
|
3199 |
instantiateContainer<ContainerType, ValueType>();
|
|
3200 |
ContainerType container;
|
|
3201 |
|
|
3202 |
#ifndef QT_NO_STL
|
|
3203 |
typename ContainerType::iterator it;
|
|
3204 |
it = container.begin();
|
|
3205 |
it = container.end();
|
|
3206 |
#endif
|
|
3207 |
|
|
3208 |
// QSet lacks count(T).
|
|
3209 |
const ValueType value = ValueType();
|
|
3210 |
container.count(value);
|
|
3211 |
}
|
|
3212 |
|
|
3213 |
template <typename ContainerType, typename ValueType>
|
|
3214 |
void instantiateSequence()
|
|
3215 |
{
|
|
3216 |
instantiateMutableIterationContainer<ContainerType, ValueType>();
|
|
3217 |
|
|
3218 |
// QVector lacks removeAll(T)
|
|
3219 |
// ValueType value = ValueType();
|
|
3220 |
// ContainerType container;
|
|
3221 |
// container.removeAll(value);
|
|
3222 |
}
|
|
3223 |
|
|
3224 |
template <typename ContainerType, typename ValueType>
|
|
3225 |
void instantiateRandomAccess()
|
|
3226 |
{
|
|
3227 |
instantiateSequence<ContainerType, ValueType>();
|
|
3228 |
|
|
3229 |
ValueType value = ValueType();
|
|
3230 |
ContainerType container;
|
|
3231 |
container.indexOf(value);
|
|
3232 |
container.lastIndexOf(value);
|
|
3233 |
}
|
|
3234 |
|
|
3235 |
template <typename ContainerType, typename ValueType>
|
|
3236 |
void instantiateAssociative()
|
|
3237 |
{
|
|
3238 |
instantiateContainer<ContainerType, ValueType>();
|
|
3239 |
|
|
3240 |
const ValueType value = ValueType();
|
|
3241 |
ContainerType container;
|
|
3242 |
const ContainerType constContainer(container);
|
|
3243 |
|
|
3244 |
container.reserve(1);
|
|
3245 |
container.capacity();
|
|
3246 |
container.squeeze();
|
|
3247 |
|
|
3248 |
container.remove(value);
|
|
3249 |
container.values();
|
|
3250 |
|
|
3251 |
container.unite(constContainer);
|
|
3252 |
container.intersect(constContainer);
|
|
3253 |
container.subtract(constContainer);
|
|
3254 |
|
|
3255 |
container != constContainer;
|
|
3256 |
container == constContainer;
|
|
3257 |
container & constContainer;
|
|
3258 |
container &= constContainer;
|
|
3259 |
container &= value;
|
|
3260 |
container + constContainer;
|
|
3261 |
container += constContainer;
|
|
3262 |
container += value;
|
|
3263 |
container - constContainer;
|
|
3264 |
container -= constContainer;
|
|
3265 |
container -= value;
|
|
3266 |
container | constContainer;
|
|
3267 |
container |= constContainer;
|
|
3268 |
container |= value;
|
|
3269 |
}
|
|
3270 |
|
|
3271 |
template <typename ContainerType, typename KeyType, typename ValueType>
|
|
3272 |
void instantiatePairAssociative()
|
|
3273 |
{
|
|
3274 |
instantiateMutableIterationContainer<ContainerType, KeyType>();
|
|
3275 |
|
|
3276 |
typename ContainerType::iterator it;
|
|
3277 |
typename ContainerType::const_iterator constIt;
|
|
3278 |
const KeyType key = KeyType();
|
|
3279 |
const ValueType value = ValueType();
|
|
3280 |
ContainerType container;
|
|
3281 |
const ContainerType constContainer(container);
|
|
3282 |
|
|
3283 |
it = container.insert(key, value);
|
|
3284 |
container.erase(it);
|
|
3285 |
container.find(key);
|
|
3286 |
container.constFind(key);
|
|
3287 |
constContainer.find(key);
|
|
3288 |
|
|
3289 |
container.key(value);
|
|
3290 |
container.keys();
|
|
3291 |
constContainer.keys();
|
|
3292 |
container.remove(key);
|
|
3293 |
container.take(key);
|
|
3294 |
container.unite(constContainer);
|
|
3295 |
container.value(key);
|
|
3296 |
container.value(key, value);
|
|
3297 |
container.values();
|
|
3298 |
container.values(key);
|
|
3299 |
container[key];
|
|
3300 |
const int foo = constContainer[key];
|
|
3301 |
Q_UNUSED(foo);
|
|
3302 |
}
|
|
3303 |
|
|
3304 |
/*
|
|
3305 |
Instantiate all Qt containers using a datatype that
|
|
3306 |
defines the minimum amount of operators.
|
|
3307 |
*/
|
|
3308 |
void tst_Collections::containerInstantiation()
|
|
3309 |
{
|
|
3310 |
// Instantiate QHash member functions.
|
|
3311 |
typedef QHash<EqualsComparable, int> Hash;
|
|
3312 |
instantiatePairAssociative<Hash, EqualsComparable, int>();
|
|
3313 |
|
|
3314 |
Hash hash;
|
|
3315 |
hash.reserve(1);
|
|
3316 |
hash.capacity();
|
|
3317 |
hash.squeeze();
|
|
3318 |
|
|
3319 |
// Instantiate QMap member functions.
|
|
3320 |
typedef QMap<LessThanComparable, int> Map;
|
|
3321 |
instantiatePairAssociative<Map, LessThanComparable, int>();
|
|
3322 |
|
|
3323 |
// Instantiate QSet member functions.
|
|
3324 |
typedef QSet<EqualsComparable> Set;
|
|
3325 |
instantiateAssociative<Set, EqualsComparable>();
|
|
3326 |
|
|
3327 |
//Instantiate QLinkedList member functions.
|
|
3328 |
typedef QLinkedList<EqualsComparable> LinkedList;
|
|
3329 |
instantiateSequence<LinkedList, EqualsComparable> ();
|
|
3330 |
{
|
|
3331 |
EqualsComparable value;
|
|
3332 |
LinkedList list;
|
|
3333 |
list.removeAll(value);
|
|
3334 |
}
|
|
3335 |
|
|
3336 |
//Instantiate QList member functions.
|
|
3337 |
typedef QList<EqualsComparable> List;
|
|
3338 |
instantiateRandomAccess<List, EqualsComparable>();
|
|
3339 |
{
|
|
3340 |
EqualsComparable value;
|
|
3341 |
List list;
|
|
3342 |
list.removeAll(value);
|
|
3343 |
}
|
|
3344 |
|
|
3345 |
//Instantiate QVector member functions.
|
|
3346 |
typedef QVector<EqualsComparable> Vector;
|
|
3347 |
instantiateRandomAccess<Vector, EqualsComparable>();
|
|
3348 |
|
|
3349 |
//Instantiate QQueue member functions.
|
|
3350 |
typedef QQueue<EqualsComparable> Queue;
|
|
3351 |
instantiateRandomAccess<Queue, EqualsComparable>();
|
|
3352 |
|
|
3353 |
//Instantiate QStack member functions.
|
|
3354 |
typedef QStack<EqualsComparable> Stack;
|
|
3355 |
instantiateRandomAccess<Stack, EqualsComparable>();
|
|
3356 |
}
|
|
3357 |
|
|
3358 |
void tst_Collections::qtimerList()
|
|
3359 |
{
|
|
3360 |
QList<double> foo;
|
|
3361 |
const int N = 10000;
|
|
3362 |
|
|
3363 |
foo.append(99.9);
|
|
3364 |
foo.append(99.9);
|
|
3365 |
foo.append(99.9);
|
|
3366 |
|
|
3367 |
for(int i = 0; i < N; i++) {
|
|
3368 |
foo.removeFirst();
|
|
3369 |
foo.insert(1, 99.9);
|
|
3370 |
}
|
|
3371 |
|
|
3372 |
QList<double>::Iterator end = foo.end();
|
|
3373 |
for (int i = 0; i < (N / 2) - 10; ++i) {
|
|
3374 |
foo.prepend(99.9);
|
|
3375 |
if (foo.end() != end)
|
|
3376 |
return;
|
|
3377 |
}
|
|
3378 |
QFAIL("QList preallocates too much memory");
|
|
3379 |
}
|
|
3380 |
|
|
3381 |
template <typename Container>
|
|
3382 |
void testContainerTypedefs(Container container)
|
|
3383 |
{
|
|
3384 |
Q_UNUSED(container)
|
|
3385 |
{ typedef typename Container::value_type Foo; }
|
|
3386 |
{ typedef typename Container::iterator Foo; }
|
|
3387 |
{ typedef typename Container::const_iterator Foo; }
|
|
3388 |
{ typedef typename Container::reference Foo; }
|
|
3389 |
{ typedef typename Container::const_reference Foo; }
|
|
3390 |
{ typedef typename Container::pointer Foo; }
|
|
3391 |
{ typedef typename Container::difference_type Foo; }
|
|
3392 |
{ typedef typename Container::size_type Foo; }
|
|
3393 |
}
|
|
3394 |
|
|
3395 |
template <typename Container>
|
|
3396 |
void testPairAssociativeContainerTypedefs(Container container)
|
|
3397 |
{
|
|
3398 |
Q_UNUSED(container)
|
|
3399 |
|
|
3400 |
// TODO: Not sure how to define value_type for our associative containers
|
|
3401 |
// { typedef typename Container::value_type Foo; }
|
|
3402 |
// { typedef typename Container::const_iterator Foo; }
|
|
3403 |
// { typedef typename Container::reference Foo; }
|
|
3404 |
// { typedef typename Container::const_reference Foo; }
|
|
3405 |
// { typedef typename Container::pointer Foo; }
|
|
3406 |
|
|
3407 |
{ typedef typename Container::difference_type Foo; }
|
|
3408 |
{ typedef typename Container::size_type Foo; }
|
|
3409 |
{ typedef typename Container::iterator Foo; }
|
|
3410 |
{ typedef typename Container::key_type Foo; }
|
|
3411 |
{ typedef typename Container::mapped_type Foo; }
|
|
3412 |
// TODO
|
|
3413 |
// { typedef typename Container::key_compare Foo; }
|
|
3414 |
// { typedef typename Container::value_comare Foo; }
|
|
3415 |
}
|
|
3416 |
|
|
3417 |
template <typename Container>
|
|
3418 |
void testSetContainerTypedefs(Container container)
|
|
3419 |
{
|
|
3420 |
Q_UNUSED(container)
|
|
3421 |
{ typedef typename Container::iterator Foo; }
|
|
3422 |
{ typedef typename Container::const_iterator Foo; }
|
|
3423 |
{ typedef typename Container::reference Foo; }
|
|
3424 |
{ typedef typename Container::const_reference Foo; }
|
|
3425 |
{ typedef typename Container::pointer Foo; }
|
|
3426 |
{ typedef typename Container::difference_type Foo; }
|
|
3427 |
{ typedef typename Container::size_type Foo; }
|
|
3428 |
{ typedef typename Container::key_type Foo; }
|
|
3429 |
}
|
|
3430 |
|
|
3431 |
/*
|
|
3432 |
Compile-time test that verifies that the Qt containers
|
|
3433 |
have STL-compatable typedefs.
|
|
3434 |
*/
|
|
3435 |
void tst_Collections::containerTypedefs()
|
|
3436 |
{
|
|
3437 |
testContainerTypedefs(QVector<int>());
|
|
3438 |
testContainerTypedefs(QStack<int>());
|
|
3439 |
testContainerTypedefs(QList<int>());
|
|
3440 |
testContainerTypedefs(QLinkedList<int>());
|
|
3441 |
testContainerTypedefs(QQueue<int>());
|
|
3442 |
|
|
3443 |
testPairAssociativeContainerTypedefs(QMap<int, int>());
|
|
3444 |
testPairAssociativeContainerTypedefs(QMultiMap<int, int>());
|
|
3445 |
testPairAssociativeContainerTypedefs(QHash<int, int>());
|
|
3446 |
|
|
3447 |
testSetContainerTypedefs(QSet<int>());
|
|
3448 |
}
|
|
3449 |
|
|
3450 |
#if defined(Q_CC_MSVC) && !defined(Q_CC_MSVC_NET)
|
|
3451 |
class Key1
|
|
3452 |
{};
|
|
3453 |
class T1
|
|
3454 |
{};
|
|
3455 |
class T2
|
|
3456 |
{};
|
|
3457 |
#else
|
|
3458 |
class Key1;
|
|
3459 |
class T1;
|
|
3460 |
class T2;
|
|
3461 |
#endif
|
|
3462 |
|
|
3463 |
void tst_Collections::forwardDeclared()
|
|
3464 |
{
|
|
3465 |
{ typedef QHash<Key1, T1> C; C *x = 0; C::iterator i; C::const_iterator j; Q_UNUSED(x) }
|
|
3466 |
{ typedef QMultiHash<Key1, T1> C; C *x = 0; C::iterator i; C::const_iterator j; Q_UNUSED(x) }
|
|
3467 |
#if !defined(Q_CC_MSVC_NET) || _MSC_VER >= 1310
|
|
3468 |
{ typedef QMap<Key1, T1> C; C *x = 0; C::iterator i; C::const_iterator j; Q_UNUSED(x) }
|
|
3469 |
{ typedef QMultiMap<Key1, T1> C; C *x = 0; C::iterator i; C::const_iterator j; Q_UNUSED(x) }
|
|
3470 |
#endif
|
|
3471 |
#if !defined(Q_CC_RVCT)
|
|
3472 |
// RVCT can't handle forward declared template parameters if those are used to declare
|
|
3473 |
// class members inside templated class.
|
|
3474 |
{ typedef QPair<T1, T2> C; C *x = 0; Q_UNUSED(x) }
|
|
3475 |
#endif
|
|
3476 |
{ typedef QList<T1> C; C *x = 0; C::iterator i; C::const_iterator j; Q_UNUSED(x) }
|
|
3477 |
{ typedef QLinkedList<T1> C; C *x = 0; C::iterator i; C::const_iterator j; Q_UNUSED(x) }
|
|
3478 |
{ typedef QVector<T1> C; C *x = 0; C::iterator i; C::const_iterator j; Q_UNUSED(x) Q_UNUSED(i) Q_UNUSED(j) }
|
|
3479 |
{ typedef QStack<T1> C; C *x = 0; C::iterator i; C::const_iterator j; Q_UNUSED(x) Q_UNUSED(i) Q_UNUSED(j) }
|
|
3480 |
{ typedef QQueue<T1> C; C *x = 0; C::iterator i; C::const_iterator j; Q_UNUSED(x) }
|
|
3481 |
{ typedef QSet<T1> C; C *x = 0; /* C::iterator i; */ C::const_iterator j; Q_UNUSED(x) }
|
|
3482 |
}
|
|
3483 |
|
|
3484 |
QTEST_APPLESS_MAIN(tst_Collections)
|
|
3485 |
#include "tst_collections.moc"
|