author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 19 Feb 2010 23:40:16 +0200 | |
branch | RCL_3 |
changeset 4 | 3b1da2848fc7 |
parent 0 | 1918ee327afb |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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 |
#include <QtTest/QtTest> |
|
44 |
#include <qset.h> |
|
45 |
#include <qdebug.h> |
|
46 |
||
47 |
//TESTED_CLASS= |
|
48 |
//TESTED_FILES= |
|
49 |
||
50 |
int toNumber(const QString &str) |
|
51 |
{ |
|
52 |
int res = 0; |
|
53 |
for (int i = 0; i < str.length(); ++i) |
|
54 |
res = (res * 10) + str[i].digitValue(); |
|
55 |
return res; |
|
56 |
} |
|
57 |
||
58 |
class tst_QSet : public QObject |
|
59 |
{ |
|
60 |
Q_OBJECT |
|
61 |
||
62 |
public: |
|
63 |
tst_QSet() {} |
|
64 |
virtual ~tst_QSet() {} |
|
65 |
||
66 |
private slots: |
|
67 |
void operator_eq(); |
|
68 |
void size(); |
|
69 |
void capacity(); |
|
70 |
void reserve(); |
|
71 |
void squeeze(); |
|
72 |
void detach(); |
|
73 |
void isDetached(); |
|
74 |
void clear(); |
|
75 |
void remove(); |
|
76 |
void contains(); |
|
77 |
void containsSet(); |
|
78 |
void begin(); |
|
79 |
void end(); |
|
80 |
void insert(); |
|
81 |
void setOperations(); |
|
82 |
void stlIterator(); |
|
83 |
void stlMutableIterator(); |
|
84 |
void javaIterator(); |
|
85 |
void javaMutableIterator(); |
|
86 |
void makeSureTheComfortFunctionsCompile(); |
|
87 |
}; |
|
88 |
||
89 |
void tst_QSet::operator_eq() |
|
90 |
{ |
|
91 |
{ |
|
92 |
QSet<int> set1, set2; |
|
93 |
QVERIFY(set1 == set2); |
|
94 |
QVERIFY(!(set1 != set2)); |
|
95 |
||
96 |
set1.insert(1); |
|
97 |
QVERIFY(set1 != set2); |
|
98 |
QVERIFY(!(set1 == set2)); |
|
99 |
||
100 |
set2.insert(1); |
|
101 |
QVERIFY(set1 == set2); |
|
102 |
QVERIFY(!(set1 != set2)); |
|
103 |
||
104 |
set2.insert(1); |
|
105 |
QVERIFY(set1 == set2); |
|
106 |
QVERIFY(!(set1 != set2)); |
|
107 |
||
108 |
set1.insert(2); |
|
109 |
QVERIFY(set1 != set2); |
|
110 |
QVERIFY(!(set1 == set2)); |
|
111 |
} |
|
112 |
||
113 |
{ |
|
114 |
QSet<QString> set1, set2; |
|
115 |
QVERIFY(set1 == set2); |
|
116 |
QVERIFY(!(set1 != set2)); |
|
117 |
||
118 |
set1.insert("one"); |
|
119 |
QVERIFY(set1 != set2); |
|
120 |
QVERIFY(!(set1 == set2)); |
|
121 |
||
122 |
set2.insert("one"); |
|
123 |
QVERIFY(set1 == set2); |
|
124 |
QVERIFY(!(set1 != set2)); |
|
125 |
||
126 |
set2.insert("one"); |
|
127 |
QVERIFY(set1 == set2); |
|
128 |
QVERIFY(!(set1 != set2)); |
|
129 |
||
130 |
set1.insert("two"); |
|
131 |
QVERIFY(set1 != set2); |
|
132 |
QVERIFY(!(set1 == set2)); |
|
133 |
} |
|
134 |
||
135 |
{ |
|
136 |
// Task 102658 |
|
137 |
QSet<QString> a; |
|
138 |
QSet<QString> b; |
|
139 |
||
140 |
a += "otto"; |
|
141 |
b += "willy"; |
|
142 |
||
143 |
QVERIFY(a != b); |
|
144 |
QVERIFY(!(a == b)); |
|
145 |
} |
|
146 |
} |
|
147 |
||
148 |
void tst_QSet::size() |
|
149 |
{ |
|
150 |
QSet<int> set; |
|
151 |
QVERIFY(set.size() == 0); |
|
152 |
QVERIFY(set.isEmpty()); |
|
153 |
QVERIFY(set.count() == set.size()); |
|
154 |
QVERIFY(set.isEmpty() == set.empty()); |
|
155 |
||
156 |
set.insert(1); |
|
157 |
QVERIFY(set.size() == 1); |
|
158 |
QVERIFY(!set.isEmpty()); |
|
159 |
QVERIFY(set.count() == set.size()); |
|
160 |
QVERIFY(set.isEmpty() == set.empty()); |
|
161 |
||
162 |
set.insert(1); |
|
163 |
QVERIFY(set.size() == 1); |
|
164 |
QVERIFY(!set.isEmpty()); |
|
165 |
QVERIFY(set.count() == set.size()); |
|
166 |
QVERIFY(set.isEmpty() == set.empty()); |
|
167 |
||
168 |
set.insert(2); |
|
169 |
QVERIFY(set.size() == 2); |
|
170 |
QVERIFY(!set.isEmpty()); |
|
171 |
QVERIFY(set.count() == set.size()); |
|
172 |
QVERIFY(set.isEmpty() == set.empty()); |
|
173 |
||
174 |
set.remove(1); |
|
175 |
QVERIFY(set.size() == 1); |
|
176 |
QVERIFY(!set.isEmpty()); |
|
177 |
QVERIFY(set.count() == set.size()); |
|
178 |
QVERIFY(set.isEmpty() == set.empty()); |
|
179 |
||
180 |
set.remove(1); |
|
181 |
QVERIFY(set.size() == 1); |
|
182 |
QVERIFY(!set.isEmpty()); |
|
183 |
QVERIFY(set.count() == set.size()); |
|
184 |
QVERIFY(set.isEmpty() == set.empty()); |
|
185 |
||
186 |
set.remove(2); |
|
187 |
QVERIFY(set.size() == 0); |
|
188 |
QVERIFY(set.isEmpty()); |
|
189 |
QVERIFY(set.count() == set.size()); |
|
190 |
QVERIFY(set.isEmpty() == set.empty()); |
|
191 |
} |
|
192 |
||
193 |
void tst_QSet::capacity() |
|
194 |
{ |
|
195 |
QSet<int> set; |
|
196 |
int n = set.capacity(); |
|
197 |
QVERIFY(n == 0); |
|
198 |
||
199 |
for (int i = 0; i < 1000; ++i) { |
|
200 |
set.insert(i); |
|
201 |
QVERIFY(set.capacity() >= set.size()); |
|
202 |
} |
|
203 |
} |
|
204 |
||
205 |
void tst_QSet::reserve() |
|
206 |
{ |
|
207 |
QSet<int> set; |
|
208 |
int n = set.capacity(); |
|
209 |
QVERIFY(n == 0); |
|
210 |
||
211 |
set.reserve(1000); |
|
212 |
QVERIFY(set.capacity() >= 1000); |
|
213 |
||
214 |
for (int i = 0; i < 500; ++i) |
|
215 |
set.insert(i); |
|
216 |
||
217 |
QVERIFY(set.capacity() >= 1000); |
|
218 |
||
219 |
for (int j = 0; j < 500; ++j) |
|
220 |
set.remove(j); |
|
221 |
||
222 |
QVERIFY(set.capacity() >= 1000); |
|
223 |
||
224 |
set.clear(); |
|
225 |
QVERIFY(set.capacity() == 0); |
|
226 |
} |
|
227 |
||
228 |
void tst_QSet::squeeze() |
|
229 |
{ |
|
230 |
QSet<int> set; |
|
231 |
int n = set.capacity(); |
|
232 |
QVERIFY(n == 0); |
|
233 |
||
234 |
set.reserve(1000); |
|
235 |
QVERIFY(set.capacity() >= 1000); |
|
236 |
||
237 |
set.squeeze(); |
|
238 |
QVERIFY(set.capacity() < 100); |
|
239 |
||
240 |
for (int i = 0; i < 500; ++i) |
|
241 |
set.insert(i); |
|
242 |
QVERIFY(set.capacity() >= 500 && set.capacity() < 10000); |
|
243 |
||
244 |
set.reserve(50000); |
|
245 |
QVERIFY(set.capacity() >= 50000); |
|
246 |
||
247 |
set.squeeze(); |
|
248 |
QVERIFY(set.capacity() < 500); |
|
249 |
||
250 |
set.remove(499); |
|
251 |
QVERIFY(set.capacity() < 500); |
|
252 |
||
253 |
set.insert(499); |
|
254 |
QVERIFY(set.capacity() >= 500); |
|
255 |
||
256 |
for (int i = 0; i < 500; ++i) |
|
257 |
set.remove(i); |
|
258 |
set.squeeze(); |
|
259 |
QVERIFY(set.capacity() < 100); |
|
260 |
} |
|
261 |
||
262 |
void tst_QSet::detach() |
|
263 |
{ |
|
264 |
QSet<int> set; |
|
265 |
set.detach(); |
|
266 |
||
267 |
set.insert(1); |
|
268 |
set.insert(2); |
|
269 |
set.detach(); |
|
270 |
||
271 |
QSet<int> copy = set; |
|
272 |
set.detach(); |
|
273 |
} |
|
274 |
||
275 |
void tst_QSet::isDetached() |
|
276 |
{ |
|
277 |
QSet<int> set1, set2; |
|
278 |
QVERIFY(!set1.isDetached()); // shared_null |
|
279 |
QVERIFY(!set2.isDetached()); // shared_null |
|
280 |
||
281 |
set1.insert(1); |
|
282 |
QVERIFY(set1.isDetached()); |
|
283 |
QVERIFY(!set2.isDetached()); // shared_null |
|
284 |
||
285 |
set2 = set1; |
|
286 |
QVERIFY(!set1.isDetached()); |
|
287 |
QVERIFY(!set2.isDetached()); |
|
288 |
||
289 |
set1.detach(); |
|
290 |
QVERIFY(set1.isDetached()); |
|
291 |
QVERIFY(set2.isDetached()); |
|
292 |
} |
|
293 |
||
294 |
void tst_QSet::clear() |
|
295 |
{ |
|
296 |
QSet<QString> set1, set2; |
|
297 |
QVERIFY(set1.size() == 0); |
|
298 |
||
299 |
set1.clear(); |
|
300 |
QVERIFY(set1.size() == 0); |
|
301 |
||
302 |
set1.insert("foo"); |
|
303 |
QVERIFY(set1.size() != 0); |
|
304 |
||
305 |
set2 = set1; |
|
306 |
||
307 |
set1.clear(); |
|
308 |
QVERIFY(set1.size() == 0); |
|
309 |
QVERIFY(set2.size() != 0); |
|
310 |
||
311 |
set2.clear(); |
|
312 |
QVERIFY(set1.size() == 0); |
|
313 |
QVERIFY(set2.size() == 0); |
|
314 |
} |
|
315 |
||
316 |
void tst_QSet::remove() |
|
317 |
{ |
|
318 |
QSet<QString> set1; |
|
319 |
||
320 |
for (int i = 0; i < 500; ++i) |
|
321 |
set1.insert(QString::number(i)); |
|
322 |
||
323 |
QCOMPARE(set1.size(), 500); |
|
324 |
||
325 |
for (int j = 0; j < 500; ++j) { |
|
326 |
set1.remove(QString::number((j * 17) % 500)); |
|
327 |
QCOMPARE(set1.size(), 500 - j - 1); |
|
328 |
} |
|
329 |
} |
|
330 |
||
331 |
void tst_QSet::contains() |
|
332 |
{ |
|
333 |
QSet<QString> set1; |
|
334 |
||
335 |
for (int i = 0; i < 500; ++i) { |
|
336 |
QVERIFY(!set1.contains(QString::number(i))); |
|
337 |
set1.insert(QString::number(i)); |
|
338 |
QVERIFY(set1.contains(QString::number(i))); |
|
339 |
} |
|
340 |
||
341 |
QCOMPARE(set1.size(), 500); |
|
342 |
||
343 |
for (int j = 0; j < 500; ++j) { |
|
344 |
int i = (j * 17) % 500; |
|
345 |
QVERIFY(set1.contains(QString::number(i))); |
|
346 |
set1.remove(QString::number(i)); |
|
347 |
QVERIFY(!set1.contains(QString::number(i))); |
|
348 |
} |
|
349 |
} |
|
350 |
||
351 |
void tst_QSet::containsSet() |
|
352 |
{ |
|
353 |
QSet<QString> set1; |
|
354 |
QSet<QString> set2; |
|
355 |
||
356 |
// empty set contains the empty set |
|
357 |
QVERIFY(set1.contains(set2)); |
|
358 |
||
359 |
for (int i = 0; i < 500; ++i) { |
|
360 |
set1.insert(QString::number(i)); |
|
361 |
set2.insert(QString::number(i)); |
|
362 |
} |
|
363 |
QVERIFY(set1.contains(set2)); |
|
364 |
||
365 |
set2.remove(QString::number(19)); |
|
366 |
set2.remove(QString::number(82)); |
|
367 |
set2.remove(QString::number(7)); |
|
368 |
QVERIFY(set1.contains(set2)); |
|
369 |
||
370 |
set1.remove(QString::number(23)); |
|
371 |
QVERIFY(!set1.contains(set2)); |
|
372 |
||
373 |
// filled set contains the empty set as well |
|
374 |
QSet<QString> set3; |
|
375 |
QVERIFY(set1.contains(set3)); |
|
376 |
||
377 |
// the empty set doesn't contain a filled set |
|
378 |
QVERIFY(!set3.contains(set1)); |
|
379 |
||
380 |
// verify const signature |
|
381 |
const QSet<QString> set4; |
|
382 |
QVERIFY(set3.contains(set4)); |
|
383 |
} |
|
384 |
||
385 |
void tst_QSet::begin() |
|
386 |
{ |
|
387 |
QSet<int> set1; |
|
388 |
QSet<int> set2 = set1; |
|
389 |
||
390 |
{ |
|
391 |
QSet<int>::const_iterator i = set1.constBegin(); |
|
392 |
QSet<int>::const_iterator j = set1.constBegin(); |
|
393 |
QSet<int>::const_iterator k = set2.constBegin(); |
|
394 |
QSet<int>::const_iterator ell = set2.constBegin(); |
|
395 |
||
396 |
QVERIFY(i == j); |
|
397 |
QVERIFY(k == ell); |
|
398 |
QVERIFY(i == k); |
|
399 |
QVERIFY(j == ell); |
|
400 |
} |
|
401 |
||
402 |
set1.insert(44); |
|
403 |
||
404 |
{ |
|
405 |
QSet<int>::const_iterator i = set1.constBegin(); |
|
406 |
QSet<int>::const_iterator j = set1.constBegin(); |
|
407 |
QSet<int>::const_iterator k = set2.constBegin(); |
|
408 |
QSet<int>::const_iterator ell = set2.constBegin(); |
|
409 |
||
410 |
QVERIFY(i == j); |
|
411 |
QVERIFY(k == ell); |
|
412 |
QVERIFY(i != k); |
|
413 |
QVERIFY(j != ell); |
|
414 |
} |
|
415 |
||
416 |
set2 = set1; |
|
417 |
||
418 |
{ |
|
419 |
QSet<int>::const_iterator i = set1.constBegin(); |
|
420 |
QSet<int>::const_iterator j = set1.constBegin(); |
|
421 |
QSet<int>::const_iterator k = set2.constBegin(); |
|
422 |
QSet<int>::const_iterator ell = set2.constBegin(); |
|
423 |
||
424 |
QVERIFY(i == j); |
|
425 |
QVERIFY(k == ell); |
|
426 |
QVERIFY(i == k); |
|
427 |
QVERIFY(j == ell); |
|
428 |
} |
|
429 |
} |
|
430 |
||
431 |
void tst_QSet::end() |
|
432 |
{ |
|
433 |
QSet<int> set1; |
|
434 |
QSet<int> set2 = set1; |
|
435 |
||
436 |
{ |
|
437 |
QSet<int>::const_iterator i = set1.constEnd(); |
|
438 |
QSet<int>::const_iterator j = set1.constEnd(); |
|
439 |
QSet<int>::const_iterator k = set2.constEnd(); |
|
440 |
QSet<int>::const_iterator ell = set2.constEnd(); |
|
441 |
||
442 |
QVERIFY(i == j); |
|
443 |
QVERIFY(k == ell); |
|
444 |
QVERIFY(i == k); |
|
445 |
QVERIFY(j == ell); |
|
446 |
||
447 |
QVERIFY(set1.constBegin() == set1.constEnd()); |
|
448 |
QVERIFY(set2.constBegin() == set2.constEnd()); |
|
449 |
} |
|
450 |
||
451 |
set1.insert(44); |
|
452 |
||
453 |
{ |
|
454 |
QSet<int>::const_iterator i = set1.constEnd(); |
|
455 |
QSet<int>::const_iterator j = set1.constEnd(); |
|
456 |
QSet<int>::const_iterator k = set2.constEnd(); |
|
457 |
QSet<int>::const_iterator ell = set2.constEnd(); |
|
458 |
||
459 |
QVERIFY(i == j); |
|
460 |
QVERIFY(k == ell); |
|
461 |
QVERIFY(i != k); |
|
462 |
QVERIFY(j != ell); |
|
463 |
||
464 |
QVERIFY(set1.constBegin() != set1.constEnd()); |
|
465 |
QVERIFY(set2.constBegin() == set2.constEnd()); |
|
466 |
} |
|
467 |
||
468 |
set2 = set1; |
|
469 |
||
470 |
{ |
|
471 |
QSet<int>::const_iterator i = set1.constEnd(); |
|
472 |
QSet<int>::const_iterator j = set1.constEnd(); |
|
473 |
QSet<int>::const_iterator k = set2.constEnd(); |
|
474 |
QSet<int>::const_iterator ell = set2.constEnd(); |
|
475 |
||
476 |
QVERIFY(i == j); |
|
477 |
QVERIFY(k == ell); |
|
478 |
QVERIFY(i == k); |
|
479 |
QVERIFY(j == ell); |
|
480 |
||
481 |
QVERIFY(set1.constBegin() != set1.constEnd()); |
|
482 |
QVERIFY(set2.constBegin() != set2.constEnd()); |
|
483 |
} |
|
484 |
||
485 |
set1.clear(); |
|
486 |
set2.clear(); |
|
487 |
QVERIFY(set1.constBegin() == set1.constEnd()); |
|
488 |
QVERIFY(set2.constBegin() == set2.constEnd()); |
|
489 |
} |
|
490 |
||
491 |
void tst_QSet::insert() |
|
492 |
{ |
|
493 |
{ |
|
494 |
QSet<int> set1; |
|
495 |
QVERIFY(set1.size() == 0); |
|
496 |
set1.insert(1); |
|
497 |
QVERIFY(set1.size() == 1); |
|
498 |
set1.insert(2); |
|
499 |
QVERIFY(set1.size() == 2); |
|
500 |
set1.insert(2); |
|
501 |
QVERIFY(set1.size() == 2); |
|
502 |
QVERIFY(set1.contains(2)); |
|
503 |
set1.remove(2); |
|
504 |
QVERIFY(set1.size() == 1); |
|
505 |
QVERIFY(!set1.contains(2)); |
|
506 |
set1.insert(2); |
|
507 |
QVERIFY(set1.size() == 2); |
|
508 |
QVERIFY(set1.contains(2)); |
|
509 |
} |
|
510 |
||
511 |
{ |
|
512 |
QSet<int> set1; |
|
513 |
QVERIFY(set1.size() == 0); |
|
514 |
set1 << 1; |
|
515 |
QVERIFY(set1.size() == 1); |
|
516 |
set1 << 2; |
|
517 |
QVERIFY(set1.size() == 2); |
|
518 |
set1 << 2; |
|
519 |
QVERIFY(set1.size() == 2); |
|
520 |
QVERIFY(set1.contains(2)); |
|
521 |
set1.remove(2); |
|
522 |
QVERIFY(set1.size() == 1); |
|
523 |
QVERIFY(!set1.contains(2)); |
|
524 |
set1 << 2; |
|
525 |
QVERIFY(set1.size() == 2); |
|
526 |
QVERIFY(set1.contains(2)); |
|
527 |
} |
|
528 |
} |
|
529 |
||
530 |
void tst_QSet::setOperations() |
|
531 |
{ |
|
532 |
QSet<QString> set1, set2; |
|
533 |
set1 << "alpha" << "beta" << "gamma" << "delta" << "zeta" << "omega"; |
|
534 |
set2 << "beta" << "gamma" << "delta" << "epsilon" << "iota" << "omega"; |
|
535 |
||
536 |
QSet<QString> set3 = set1; |
|
537 |
set3.unite(set2); |
|
538 |
QVERIFY(set3.size() == 8); |
|
539 |
QVERIFY(set3.contains("alpha")); |
|
540 |
QVERIFY(set3.contains("beta")); |
|
541 |
QVERIFY(set3.contains("gamma")); |
|
542 |
QVERIFY(set3.contains("delta")); |
|
543 |
QVERIFY(set3.contains("epsilon")); |
|
544 |
QVERIFY(set3.contains("zeta")); |
|
545 |
QVERIFY(set3.contains("iota")); |
|
546 |
QVERIFY(set3.contains("omega")); |
|
547 |
||
548 |
QSet<QString> set4 = set2; |
|
549 |
set4.unite(set1); |
|
550 |
QVERIFY(set4.size() == 8); |
|
551 |
QVERIFY(set4.contains("alpha")); |
|
552 |
QVERIFY(set4.contains("beta")); |
|
553 |
QVERIFY(set4.contains("gamma")); |
|
554 |
QVERIFY(set4.contains("delta")); |
|
555 |
QVERIFY(set4.contains("epsilon")); |
|
556 |
QVERIFY(set4.contains("zeta")); |
|
557 |
QVERIFY(set4.contains("iota")); |
|
558 |
QVERIFY(set4.contains("omega")); |
|
559 |
||
560 |
QVERIFY(set3 == set4); |
|
561 |
||
562 |
QSet<QString> set5 = set1; |
|
563 |
set5.intersect(set2); |
|
564 |
QVERIFY(set5.size() == 4); |
|
565 |
QVERIFY(set5.contains("beta")); |
|
566 |
QVERIFY(set5.contains("gamma")); |
|
567 |
QVERIFY(set5.contains("delta")); |
|
568 |
QVERIFY(set5.contains("omega")); |
|
569 |
||
570 |
QSet<QString> set6 = set2; |
|
571 |
set6.intersect(set1); |
|
572 |
QVERIFY(set6.size() == 4); |
|
573 |
QVERIFY(set6.contains("beta")); |
|
574 |
QVERIFY(set6.contains("gamma")); |
|
575 |
QVERIFY(set6.contains("delta")); |
|
576 |
QVERIFY(set6.contains("omega")); |
|
577 |
||
578 |
QVERIFY(set5 == set6); |
|
579 |
||
580 |
QSet<QString> set7 = set1; |
|
581 |
set7.subtract(set2); |
|
582 |
QVERIFY(set7.size() == 2); |
|
583 |
QVERIFY(set7.contains("alpha")); |
|
584 |
QVERIFY(set7.contains("zeta")); |
|
585 |
||
586 |
QSet<QString> set8 = set2; |
|
587 |
set8.subtract(set1); |
|
588 |
QVERIFY(set8.size() == 2); |
|
589 |
QVERIFY(set8.contains("epsilon")); |
|
590 |
QVERIFY(set8.contains("iota")); |
|
591 |
||
592 |
QSet<QString> set9 = set1 | set2; |
|
593 |
QVERIFY(set9 == set3); |
|
594 |
||
595 |
QSet<QString> set10 = set1 & set2; |
|
596 |
QVERIFY(set10 == set5); |
|
597 |
||
598 |
QSet<QString> set11 = set1 + set2; |
|
599 |
QVERIFY(set11 == set3); |
|
600 |
||
601 |
QSet<QString> set12 = set1 - set2; |
|
602 |
QVERIFY(set12 == set7); |
|
603 |
||
604 |
QSet<QString> set13 = set2 - set1; |
|
605 |
QVERIFY(set13 == set8); |
|
606 |
||
607 |
QSet<QString> set14 = set1; |
|
608 |
set14 |= set2; |
|
609 |
QVERIFY(set14 == set3); |
|
610 |
||
611 |
QSet<QString> set15 = set1; |
|
612 |
set15 &= set2; |
|
613 |
QVERIFY(set15 == set5); |
|
614 |
||
615 |
QSet<QString> set16 = set1; |
|
616 |
set16 += set2; |
|
617 |
QVERIFY(set16 == set3); |
|
618 |
||
619 |
QSet<QString> set17 = set1; |
|
620 |
set17 -= set2; |
|
621 |
QVERIFY(set17 == set7); |
|
622 |
||
623 |
QSet<QString> set18 = set2; |
|
624 |
set18 -= set1; |
|
625 |
QVERIFY(set18 == set8); |
|
626 |
} |
|
627 |
||
628 |
void tst_QSet::stlIterator() |
|
629 |
{ |
|
630 |
QSet<QString> set1; |
|
631 |
for (int i = 0; i < 25000; ++i) |
|
632 |
set1.insert(QString::number(i)); |
|
633 |
||
634 |
{ |
|
635 |
int sum = 0; |
|
636 |
QSet<QString>::const_iterator i = set1.begin(); |
|
637 |
while (i != set1.end()) { |
|
638 |
sum += toNumber(*i); |
|
639 |
++i; |
|
640 |
} |
|
641 |
QVERIFY(sum == 24999 * 25000 / 2); |
|
642 |
} |
|
643 |
||
644 |
{ |
|
645 |
int sum = 0; |
|
646 |
QSet<QString>::const_iterator i = set1.end(); |
|
647 |
while (i != set1.begin()) { |
|
648 |
--i; |
|
649 |
sum += toNumber(*i); |
|
650 |
} |
|
651 |
QVERIFY(sum == 24999 * 25000 / 2); |
|
652 |
} |
|
653 |
} |
|
654 |
||
655 |
void tst_QSet::stlMutableIterator() |
|
656 |
{ |
|
657 |
QSet<QString> set1; |
|
658 |
for (int i = 0; i < 25000; ++i) |
|
659 |
set1.insert(QString::number(i)); |
|
660 |
||
661 |
{ |
|
662 |
int sum = 0; |
|
663 |
QSet<QString>::iterator i = set1.begin(); |
|
664 |
while (i != set1.end()) { |
|
665 |
sum += toNumber(*i); |
|
666 |
++i; |
|
667 |
} |
|
668 |
QVERIFY(sum == 24999 * 25000 / 2); |
|
669 |
} |
|
670 |
||
671 |
{ |
|
672 |
int sum = 0; |
|
673 |
QSet<QString>::iterator i = set1.end(); |
|
674 |
while (i != set1.begin()) { |
|
675 |
--i; |
|
676 |
sum += toNumber(*i); |
|
677 |
} |
|
678 |
QVERIFY(sum == 24999 * 25000 / 2); |
|
679 |
} |
|
680 |
||
681 |
{ |
|
682 |
QSet<QString> set2 = set1; |
|
683 |
QSet<QString> set3 = set2; |
|
684 |
||
685 |
QSet<QString>::iterator i = set2.begin(); |
|
686 |
QSet<QString>::iterator j = set3.begin(); |
|
687 |
||
688 |
while (i != set2.end()) { |
|
689 |
i = set2.erase(i); |
|
690 |
} |
|
691 |
QVERIFY(set2.isEmpty()); |
|
692 |
QVERIFY(!set3.isEmpty()); |
|
693 |
||
694 |
j = set3.end(); |
|
695 |
while (j != set3.begin()) { |
|
696 |
j--; |
|
697 |
if (j + 1 != set3.end()) |
|
698 |
set3.erase(j + 1); |
|
699 |
} |
|
700 |
if (set3.begin() != set3.end()) |
|
701 |
set3.erase(set3.begin()); |
|
702 |
||
703 |
QVERIFY(set2.isEmpty()); |
|
704 |
QVERIFY(set3.isEmpty()); |
|
705 |
||
706 |
#if QT_VERSION >= 0x050000 |
|
707 |
i = set2.insert("foo"); |
|
708 |
#else |
|
709 |
QSet<QString>::const_iterator k = set2.insert("foo"); |
|
710 |
i = reinterpret_cast<QSet<QString>::iterator &>(k); |
|
711 |
#endif |
|
712 |
QVERIFY(*i == "foo"); |
|
713 |
} |
|
714 |
} |
|
715 |
||
716 |
void tst_QSet::javaIterator() |
|
717 |
{ |
|
718 |
QSet<QString> set1; |
|
719 |
for (int k = 0; k < 25000; ++k) |
|
720 |
set1.insert(QString::number(k)); |
|
721 |
||
722 |
{ |
|
723 |
int sum = 0; |
|
724 |
QSetIterator<QString> i(set1); |
|
725 |
while (i.hasNext()) |
|
726 |
sum += toNumber(i.next()); |
|
727 |
QVERIFY(sum == 24999 * 25000 / 2); |
|
728 |
} |
|
729 |
||
730 |
{ |
|
731 |
int sum = 0; |
|
732 |
QSetIterator<QString> i(set1); |
|
733 |
while (i.hasNext()) { |
|
734 |
sum += toNumber(i.peekNext()); |
|
735 |
i.next(); |
|
736 |
} |
|
737 |
QVERIFY(sum == 24999 * 25000 / 2); |
|
738 |
} |
|
739 |
||
740 |
{ |
|
741 |
int sum = 0; |
|
742 |
QSetIterator<QString> i(set1); |
|
743 |
while (i.hasNext()) { |
|
744 |
i.next(); |
|
745 |
sum += toNumber(i.peekPrevious()); |
|
746 |
} |
|
747 |
QVERIFY(sum == 24999 * 25000 / 2); |
|
748 |
} |
|
749 |
||
750 |
{ |
|
751 |
int sum = 0; |
|
752 |
QSetIterator<QString> i(set1); |
|
753 |
i.toBack(); |
|
754 |
while (i.hasPrevious()) |
|
755 |
sum += toNumber(i.previous()); |
|
756 |
QVERIFY(sum == 24999 * 25000 / 2); |
|
757 |
} |
|
758 |
||
759 |
{ |
|
760 |
int sum = 0; |
|
761 |
QSetIterator<QString> i(set1); |
|
762 |
i.toBack(); |
|
763 |
while (i.hasPrevious()) { |
|
764 |
sum += toNumber(i.peekPrevious()); |
|
765 |
i.previous(); |
|
766 |
} |
|
767 |
QVERIFY(sum == 24999 * 25000 / 2); |
|
768 |
} |
|
769 |
||
770 |
{ |
|
771 |
int sum = 0; |
|
772 |
QSetIterator<QString> i(set1); |
|
773 |
i.toBack(); |
|
774 |
while (i.hasPrevious()) { |
|
775 |
i.previous(); |
|
776 |
sum += toNumber(i.peekNext()); |
|
777 |
} |
|
778 |
QVERIFY(sum == 24999 * 25000 / 2); |
|
779 |
} |
|
780 |
||
781 |
int sum1 = 0; |
|
782 |
int sum2 = 0; |
|
783 |
QSetIterator<QString> i(set1); |
|
784 |
QSetIterator<QString> j(set1); |
|
785 |
||
786 |
int n = 0; |
|
787 |
while (i.hasNext()) { |
|
788 |
QVERIFY(j.hasNext()); |
|
789 |
set1.remove(i.peekNext()); |
|
790 |
sum1 += toNumber(i.next()); |
|
791 |
sum2 += toNumber(j.next()); |
|
792 |
++n; |
|
793 |
} |
|
794 |
QVERIFY(!j.hasNext()); |
|
795 |
QVERIFY(sum1 == 24999 * 25000 / 2); |
|
796 |
QVERIFY(sum2 == sum1); |
|
797 |
QVERIFY(set1.isEmpty()); |
|
798 |
} |
|
799 |
||
800 |
void tst_QSet::javaMutableIterator() |
|
801 |
{ |
|
802 |
QSet<QString> set1; |
|
803 |
for (int k = 0; k < 25000; ++k) |
|
804 |
set1.insert(QString::number(k)); |
|
805 |
||
806 |
{ |
|
807 |
int sum = 0; |
|
808 |
QMutableSetIterator<QString> i(set1); |
|
809 |
while (i.hasNext()) |
|
810 |
sum += toNumber(i.next()); |
|
811 |
QVERIFY(sum == 24999 * 25000 / 2); |
|
812 |
} |
|
813 |
||
814 |
{ |
|
815 |
int sum = 0; |
|
816 |
QMutableSetIterator<QString> i(set1); |
|
817 |
while (i.hasNext()) { |
|
818 |
sum += toNumber(i.peekNext()); |
|
819 |
i.next(); |
|
820 |
} |
|
821 |
QVERIFY(sum == 24999 * 25000 / 2); |
|
822 |
} |
|
823 |
||
824 |
{ |
|
825 |
int sum = 0; |
|
826 |
QMutableSetIterator<QString> i(set1); |
|
827 |
while (i.hasNext()) { |
|
828 |
i.next(); |
|
829 |
sum += toNumber(i.peekPrevious()); |
|
830 |
} |
|
831 |
QVERIFY(sum == 24999 * 25000 / 2); |
|
832 |
} |
|
833 |
||
834 |
{ |
|
835 |
int sum = 0; |
|
836 |
QMutableSetIterator<QString> i(set1); |
|
837 |
i.toBack(); |
|
838 |
while (i.hasPrevious()) |
|
839 |
sum += toNumber(i.previous()); |
|
840 |
QVERIFY(sum == 24999 * 25000 / 2); |
|
841 |
} |
|
842 |
||
843 |
{ |
|
844 |
int sum = 0; |
|
845 |
QMutableSetIterator<QString> i(set1); |
|
846 |
i.toBack(); |
|
847 |
while (i.hasPrevious()) { |
|
848 |
sum += toNumber(i.peekPrevious()); |
|
849 |
i.previous(); |
|
850 |
} |
|
851 |
QVERIFY(sum == 24999 * 25000 / 2); |
|
852 |
} |
|
853 |
||
854 |
{ |
|
855 |
int sum = 0; |
|
856 |
QMutableSetIterator<QString> i(set1); |
|
857 |
i.toBack(); |
|
858 |
while (i.hasPrevious()) { |
|
859 |
i.previous(); |
|
860 |
sum += toNumber(i.peekNext()); |
|
861 |
} |
|
862 |
QVERIFY(sum == 24999 * 25000 / 2); |
|
863 |
} |
|
864 |
||
865 |
{ |
|
866 |
QSet<QString> set2 = set1; |
|
867 |
QSet<QString> set3 = set2; |
|
868 |
||
869 |
QMutableSetIterator<QString> i(set2); |
|
870 |
QMutableSetIterator<QString> j(set3); |
|
871 |
||
872 |
while (i.hasNext()) { |
|
873 |
i.next(); |
|
874 |
i.remove(); |
|
875 |
} |
|
876 |
QVERIFY(set2.isEmpty()); |
|
877 |
QVERIFY(!set3.isEmpty()); |
|
878 |
||
879 |
j.toBack(); |
|
880 |
while (j.hasPrevious()) { |
|
881 |
j.previous(); |
|
882 |
j.remove(); |
|
883 |
} |
|
884 |
QVERIFY(set2.isEmpty()); |
|
885 |
QVERIFY(set3.isEmpty()); |
|
886 |
} |
|
887 |
} |
|
888 |
||
889 |
void tst_QSet::makeSureTheComfortFunctionsCompile() |
|
890 |
{ |
|
891 |
QSet<int> set1, set2, set3; |
|
892 |
set1 << 5; |
|
893 |
set1 |= set2; |
|
894 |
set1 |= 5; |
|
895 |
set1 &= set2; |
|
896 |
set1 &= 5; |
|
897 |
set1 += set2; |
|
898 |
set1 += 5; |
|
899 |
set1 -= set2; |
|
900 |
set1 -= 5; |
|
901 |
set1 = set2 | set3; |
|
902 |
set1 = set2 & set3; |
|
903 |
set1 = set2 + set3; |
|
904 |
set1 = set2 - set3; |
|
905 |
} |
|
906 |
||
907 |
QTEST_APPLESS_MAIN(tst_QSet) |
|
908 |
||
909 |
#include "tst_qset.moc" |