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 |
||
45 |
||
46 |
#include "q3valuelist.h" |
|
47 |
||
48 |
||
49 |
||
50 |
||
51 |
#include <q3valuelist.h> |
|
52 |
||
53 |
//TESTED_CLASS= |
|
54 |
//TESTED_FILES= |
|
55 |
||
56 |
class tst_Q3ValueList : public QObject |
|
57 |
{ |
|
58 |
Q_OBJECT |
|
59 |
||
60 |
public: |
|
61 |
tst_Q3ValueList(); |
|
62 |
virtual ~tst_Q3ValueList(); |
|
63 |
||
64 |
||
65 |
public slots: |
|
66 |
void init(); |
|
67 |
void cleanup(); |
|
68 |
private slots: |
|
69 |
||
70 |
void isEmpty(); |
|
71 |
void clear(); |
|
72 |
void count(); |
|
73 |
void size(); |
|
74 |
void contains(); |
|
75 |
void findIndex(); |
|
76 |
void indexing(); |
|
77 |
void firstLast(); |
|
78 |
void frontBack(); |
|
79 |
void beginEnd(); |
|
80 |
void pushing(); |
|
81 |
void popping(); |
|
82 |
void remove(); |
|
83 |
void erase(); |
|
84 |
void fromLast(); |
|
85 |
void append(); |
|
86 |
// Doesn't have own test function since all |
|
87 |
// other functions are heavy users of it, |
|
88 |
// thus it must work correctly |
|
89 |
void prepend(); |
|
90 |
void insert(); |
|
91 |
void find(); |
|
92 |
void opEqualNotEqual(); |
|
93 |
void opPlus(); |
|
94 |
void opPlusEqual(); |
|
95 |
void opStreamOut(); |
|
96 |
void shared(); |
|
97 |
void detach_on_append(); |
|
98 |
void detach_on_prepend(); |
|
99 |
void detach_on_insert1(); |
|
100 |
void detach_on_insert2(); |
|
101 |
void detach_on_it_assign(); |
|
102 |
void detach_on_ref_assign(); |
|
103 |
void detach_on_clear(); |
|
104 |
void detach_on_erase1(); |
|
105 |
void detach_on_erase2(); |
|
106 |
void detach_on_opPE1(); |
|
107 |
void detach_on_opPE2(); |
|
108 |
void detach_on_opStream(); |
|
109 |
void detach_on_pop_front(); |
|
110 |
void detach_on_pop_back(); |
|
111 |
void detach_on_push_front(); |
|
112 |
void detach_on_push_back(); |
|
113 |
void detach_on_remove1(); |
|
114 |
void detach_on_remove2(); |
|
115 |
}; |
|
116 |
||
117 |
tst_Q3ValueList::tst_Q3ValueList() |
|
118 |
||
119 |
{ |
|
120 |
} |
|
121 |
||
122 |
tst_Q3ValueList::~tst_Q3ValueList() |
|
123 |
{ |
|
124 |
||
125 |
} |
|
126 |
||
127 |
void tst_Q3ValueList::init() |
|
128 |
{ |
|
129 |
} |
|
130 |
||
131 |
void tst_Q3ValueList::cleanup() |
|
132 |
{ |
|
133 |
} |
|
134 |
||
135 |
void tst_Q3ValueList::isEmpty() |
|
136 |
{ |
|
137 |
Q3ValueList<int> a; |
|
138 |
QVERIFY( a.isEmpty() ); |
|
139 |
QVERIFY( a.empty() ); |
|
140 |
||
141 |
a.append( 1 ); |
|
142 |
QVERIFY( !a.isEmpty() ); |
|
143 |
QVERIFY( !a.empty() ); |
|
144 |
} |
|
145 |
||
146 |
void tst_Q3ValueList::clear() |
|
147 |
{ |
|
148 |
Q3ValueList<int> a; |
|
149 |
a.append( 1 ); |
|
150 |
a.append( 2 ); |
|
151 |
a.append( 3 ); |
|
152 |
a.clear(); |
|
153 |
QVERIFY( a.isEmpty() ); |
|
154 |
} |
|
155 |
||
156 |
void tst_Q3ValueList::count() |
|
157 |
{ |
|
158 |
Q3ValueList<int> a; |
|
159 |
QCOMPARE( (int)a.count(), 0 ); |
|
160 |
||
161 |
a.append( 1 ); |
|
162 |
QCOMPARE( (int)a.count(), 1 ); |
|
163 |
||
164 |
a.append( 2 ); |
|
165 |
QCOMPARE( (int)a.count(), 2 ); |
|
166 |
||
167 |
a.append( 3 ); |
|
168 |
QCOMPARE( (int)a.count(), 3 ); |
|
169 |
||
170 |
a.clear(); |
|
171 |
QCOMPARE( (int)a.count(), 0 ); |
|
172 |
} |
|
173 |
||
174 |
void tst_Q3ValueList::size() |
|
175 |
{ |
|
176 |
Q3ValueList<int> a; |
|
177 |
QCOMPARE( (int)a.size(), 0 ); |
|
178 |
||
179 |
a.append( 1 ); |
|
180 |
QCOMPARE( (int)a.size(), 1 ); |
|
181 |
||
182 |
a.append( 2 ); |
|
183 |
QCOMPARE( (int)a.size(), 2 ); |
|
184 |
||
185 |
a.append( 3 ); |
|
186 |
QCOMPARE( (int)a.size(), 3 ); |
|
187 |
||
188 |
a.clear(); |
|
189 |
QCOMPARE( (int)a.size(), 0 ); |
|
190 |
} |
|
191 |
||
192 |
void tst_Q3ValueList::contains() |
|
193 |
{ |
|
194 |
Q3ValueList<int> a; |
|
195 |
a.append( 1 ); |
|
196 |
a.append( 10 ); |
|
197 |
a.append( 100 ); |
|
198 |
a.append( 1000 ); |
|
199 |
a.append( 1000 ); |
|
200 |
||
201 |
QCOMPARE( (int)a.contains(1), 1 ); |
|
202 |
QCOMPARE( (int)a.contains(10), 1 ); |
|
203 |
QCOMPARE( (int)a.contains(99), 0 ); |
|
204 |
QCOMPARE( (int)a.contains(1000), 2 ); |
|
205 |
} |
|
206 |
||
207 |
void tst_Q3ValueList::findIndex() |
|
208 |
{ |
|
209 |
Q3ValueList<int> a; |
|
210 |
a.append( 1 ); |
|
211 |
a.append( 10 ); |
|
212 |
a.append( 100 ); |
|
213 |
a.append( 1000 ); |
|
214 |
a.append( 1000 ); |
|
215 |
||
216 |
QCOMPARE( a.findIndex( 0 ), -1 ); |
|
217 |
QCOMPARE( a.findIndex( 1 ), 0 ); |
|
218 |
QCOMPARE( a.findIndex( 1000 ), 3 ); |
|
219 |
} |
|
220 |
||
221 |
void tst_Q3ValueList::indexing() |
|
222 |
{ |
|
223 |
Q3ValueList<int> a; |
|
224 |
a.append( 1 ); |
|
225 |
a.append( 10 ); |
|
226 |
a.append( 99 ); |
|
227 |
||
228 |
QCOMPARE( a[0], 1 ); |
|
229 |
QCOMPARE( a[1], 10 ); |
|
230 |
QCOMPARE( a[2], 99 ); |
|
231 |
QCOMPARE( *(a.at(0)), 1 ); |
|
232 |
QCOMPARE( *(a.at(1)), 10 ); |
|
233 |
QCOMPARE( *(a.at(2)), 99 ); |
|
234 |
||
235 |
a[1] = 11; |
|
236 |
QCOMPARE( a[1], 11 ); |
|
237 |
||
238 |
*(a.at(0)) = 2; |
|
239 |
QCOMPARE( a[0], 2 ); |
|
240 |
} |
|
241 |
||
242 |
void tst_Q3ValueList::firstLast() |
|
243 |
{ |
|
244 |
Q3ValueList<int> a; |
|
245 |
a.append( 1 ); |
|
246 |
a.append( 10 ); |
|
247 |
a.append( 100 ); |
|
248 |
a.append( 1000 ); |
|
249 |
a.append( 10000 ); |
|
250 |
||
251 |
QCOMPARE( a.first(), 1 ); |
|
252 |
QCOMPARE( a.last(), 10000 ); |
|
253 |
||
254 |
a.first() = 2; |
|
255 |
a.last() = 20000; |
|
256 |
QCOMPARE( a.first(), 2 ); |
|
257 |
QCOMPARE( a.last(), 20000 ); |
|
258 |
} |
|
259 |
||
260 |
void tst_Q3ValueList::frontBack() |
|
261 |
{ |
|
262 |
Q3ValueList<int> a; |
|
263 |
a.append( 1 ); |
|
264 |
a.append( 10 ); |
|
265 |
a.append( 100 ); |
|
266 |
a.append( 1000 ); |
|
267 |
a.append( 10000 ); |
|
268 |
||
269 |
QCOMPARE( a.front(), 1 ); |
|
270 |
QCOMPARE( a.back(), 10000 ); |
|
271 |
||
272 |
a.first() = 2; |
|
273 |
a.last() = 20000; |
|
274 |
QCOMPARE( a.front(), 2 ); |
|
275 |
QCOMPARE( a.back(), 20000 ); |
|
276 |
} |
|
277 |
||
278 |
void tst_Q3ValueList::beginEnd() |
|
279 |
{ |
|
280 |
Q3ValueList<int> a; |
|
281 |
a.append( 1 ); |
|
282 |
a.append( 10 ); |
|
283 |
a.append( 100 ); |
|
284 |
||
285 |
Q3ValueListConstIterator<int> cit1 = a.begin(); |
|
286 |
Q3ValueListConstIterator<int> cit2 = a.end(); |
|
287 |
QCOMPARE( *(cit1), 1 ); |
|
288 |
QCOMPARE( *(--cit2), 100 ); |
|
289 |
||
290 |
Q3ValueListIterator<int> it1 = a.begin(); |
|
291 |
Q3ValueListIterator<int> it2 = a.end(); |
|
292 |
*(it1) = 2; |
|
293 |
*(--it2) = 200; |
|
294 |
||
295 |
// Using const iterators to verify |
|
296 |
QCOMPARE( *(cit1), 2 ); |
|
297 |
QCOMPARE( *(cit2), 200 ); |
|
298 |
||
299 |
Q3ValueList<int> b; |
|
300 |
b.append( 1 ); |
|
301 |
Q3ValueList<int> b2 = b; |
|
302 |
QVERIFY( b.constBegin() == b2.constBegin() ); |
|
303 |
QVERIFY( b.constEnd() == b2.constEnd() ); |
|
304 |
b2.append( 2 ); |
|
305 |
QVERIFY( b.constBegin() != b2.constBegin() ); |
|
306 |
QVERIFY( b2.constBegin() == b2.constBegin() ); |
|
307 |
} |
|
308 |
||
309 |
void tst_Q3ValueList::pushing() |
|
310 |
{ |
|
311 |
Q3ValueList<int> a; |
|
312 |
a.append( 100 ); |
|
313 |
||
314 |
a.push_front( 10 ); |
|
315 |
QCOMPARE( a.first(), 10 ); |
|
316 |
QCOMPARE( a.last(), 100 ); |
|
317 |
||
318 |
a.push_back( 1000 ); |
|
319 |
QCOMPARE( a.first(), 10 ); |
|
320 |
QCOMPARE( a.last(), 1000 ); |
|
321 |
} |
|
322 |
||
323 |
void tst_Q3ValueList::popping() |
|
324 |
{ |
|
325 |
Q3ValueList<int> a; |
|
326 |
a.append( 1 ); |
|
327 |
a.append( 10 ); |
|
328 |
a.append( 100 ); |
|
329 |
a.append( 1000 ); |
|
330 |
a.append( 10000 ); |
|
331 |
||
332 |
a.pop_front(); |
|
333 |
QCOMPARE( a.first(), 10 ); |
|
334 |
QCOMPARE( a.last(), 10000 ); |
|
335 |
||
336 |
a.pop_back(); |
|
337 |
QCOMPARE( a.first(), 10 ); |
|
338 |
QCOMPARE( a.last(), 1000 ); |
|
339 |
||
340 |
QCOMPARE( (int)a.count(), 3 ); |
|
341 |
||
342 |
a.pop_back(); |
|
343 |
a.pop_back(); |
|
344 |
a.pop_back(); |
|
345 |
QVERIFY( a.isEmpty() ); |
|
346 |
} |
|
347 |
||
348 |
void tst_Q3ValueList::remove() |
|
349 |
{ |
|
350 |
{ |
|
351 |
Q3ValueList<int> a; |
|
352 |
a.append( 1 ); |
|
353 |
a.append( 10 ); |
|
354 |
a.append( 100 ); |
|
355 |
a.append( 1000 ); |
|
356 |
a.append( 1000 ); |
|
357 |
a.append( 10000 ); |
|
358 |
||
359 |
QCOMPARE( (uint)a.remove(100), (uint)1 ); |
|
360 |
QCOMPARE( (uint)a.remove(1000), (uint)2 ); |
|
361 |
QCOMPARE( (int)a.first(), 1 ); |
|
362 |
QCOMPARE( (int)a.last(), 10000 ); |
|
363 |
||
364 |
a.remove( a.at(0) ); |
|
365 |
QCOMPARE( (int)a.first(), 10 ); |
|
366 |
QCOMPARE( (int)a.last(), 10000 ); |
|
367 |
||
368 |
a.remove( a.at(1) ); |
|
369 |
QCOMPARE( (int)a.first(), 10 ); |
|
370 |
QCOMPARE( (int)a.last(), 10 ); |
|
371 |
} |
|
372 |
{ |
|
373 |
Q3ValueList<int> a; |
|
374 |
a.append( 1 ); |
|
375 |
a.append( 10 ); |
|
376 |
a.append( 100 ); |
|
377 |
a.append( 1000 ); |
|
378 |
a.append( 10000 ); |
|
379 |
||
380 |
Q3ValueList<int>::Iterator it = a.begin(); |
|
381 |
++it; |
|
382 |
QVERIFY(*it == 10); |
|
383 |
it = a.remove(it); |
|
384 |
QVERIFY(*it == 100); |
|
385 |
it = a.remove(it); |
|
386 |
QVERIFY(*it == 1000); |
|
387 |
it = a.remove(it); |
|
388 |
QVERIFY(*it == 10000); |
|
389 |
it = a.remove(it); |
|
390 |
QVERIFY(it == a.end()); |
|
391 |
} |
|
392 |
} |
|
393 |
||
394 |
void tst_Q3ValueList::erase() |
|
395 |
{ |
|
396 |
Q3ValueList<int> a; |
|
397 |
a.append( 1 ); |
|
398 |
a.append( 5 ); |
|
399 |
a.append( 10 ); |
|
400 |
a.append( 50 ); |
|
401 |
a.append( 100 ); |
|
402 |
a.append( 500 ); |
|
403 |
a.append( 1000 ); |
|
404 |
a.append( 5000 ); |
|
405 |
a.append( 10000 ); |
|
406 |
a.append( 50000 ); |
|
407 |
||
408 |
a.erase( a.at(0), a.at(5) ); // Remove 1 to 100 (inclusive) |
|
409 |
QCOMPARE( (int)a.first(), 500 ); |
|
410 |
QCOMPARE( (int)a.last(), 50000 ); |
|
411 |
||
412 |
Q3ValueListIterator<int> it = a.erase( a.at(2) ); // remove 5000 |
|
413 |
QCOMPARE( *(it), 10000 ); |
|
414 |
||
415 |
it = a.erase( a.at(3) ); // remove 50000 |
|
416 |
QVERIFY( (it == a.end()) ); |
|
417 |
} |
|
418 |
||
419 |
void tst_Q3ValueList::fromLast() |
|
420 |
{ |
|
421 |
Q3ValueList<int> a; |
|
422 |
Q3ValueListIterator<int> it = a.fromLast(); |
|
423 |
QVERIFY( (it == a.end()) ); |
|
424 |
||
425 |
a.append( 1 ); |
|
426 |
a.append( 10 ); |
|
427 |
a.append( 100 ); |
|
428 |
it = a.fromLast(); |
|
429 |
QVERIFY( (it != a.end()) ); |
|
430 |
||
431 |
QCOMPARE( a.last(), 100 ); |
|
432 |
*(a.fromLast()) = 200; |
|
433 |
QCOMPARE( a.last(), 200 ); |
|
434 |
} |
|
435 |
||
436 |
void tst_Q3ValueList::prepend() |
|
437 |
{ |
|
438 |
Q3ValueList<int> a; |
|
439 |
a.append( 1 ); |
|
440 |
a.append( 10 ); |
|
441 |
a.append( 100 ); |
|
442 |
||
443 |
QCOMPARE( (int)a[0], 1 ); |
|
444 |
Q3ValueList<int>::Iterator it = a.prepend( 1000 ); |
|
445 |
QCOMPARE( (int)a[0], 1000 ); |
|
446 |
QVERIFY( *it == 1000 ); |
|
447 |
} |
|
448 |
||
449 |
void tst_Q3ValueList::insert() |
|
450 |
{ |
|
451 |
Q3ValueList<int> a; |
|
452 |
a.append( 1 ); |
|
453 |
a.append( 10 ); |
|
454 |
a.append( 100 ); |
|
455 |
||
456 |
Q3ValueListIterator<int> it = a.fromLast(); |
|
457 |
it = a.insert( it, 1000 ); |
|
458 |
||
459 |
QCOMPARE( *(it), 1000 ); |
|
460 |
QCOMPARE( *(++it), 100 ); |
|
461 |
QCOMPARE( (int)a.count(), 4 ); |
|
462 |
||
463 |
it = a.fromLast(); |
|
464 |
a.insert( it, 10, 1234 ); |
|
465 |
QCOMPARE( (int)a.count(), 14 ); |
|
466 |
} |
|
467 |
||
468 |
void tst_Q3ValueList::find() |
|
469 |
{ |
|
470 |
Q3ValueList<int> a; |
|
471 |
a.append( 1 ); |
|
472 |
a.append( 10 ); |
|
473 |
a.append( 100 ); |
|
474 |
a.append( 1000 ); |
|
475 |
a.append( 10000 ); |
|
476 |
a.append( 10000 ); |
|
477 |
a.append( 20000 ); |
|
478 |
a.append( 30000 ); |
|
479 |
||
480 |
// Constant iterators |
|
481 |
Q3ValueListConstIterator<int> cit1 = a.find( 200 ); |
|
482 |
QVERIFY( (cit1 == a.end()) ); |
|
483 |
||
484 |
cit1 = a.find( 1000 ); |
|
485 |
QCOMPARE( *(cit1), 1000 ); |
|
486 |
QCOMPARE( *(++cit1), 10000 ); |
|
487 |
QCOMPARE( *(++cit1), 10000 ); |
|
488 |
QCOMPARE( *(++cit1), 20000 ); |
|
489 |
||
490 |
cit1 = a.at( 3 ); |
|
491 |
Q3ValueListConstIterator<int> cit2 = a.find( cit1, 20000 ); |
|
492 |
QCOMPARE( *(cit2), 20000 ); |
|
493 |
QCOMPARE( *(++cit2), 30000 ); |
|
494 |
||
495 |
// Non constant iterators |
|
496 |
Q3ValueListIterator<int> it1 = a.find( 200 ); |
|
497 |
QVERIFY( (it1 == a.end()) ); |
|
498 |
||
499 |
it1 = a.find( 1000 ); |
|
500 |
QCOMPARE( *(it1), 1000 ); |
|
501 |
QCOMPARE( *(++it1), 10000 ); |
|
502 |
QCOMPARE( *(++it1), 10000 ); |
|
503 |
QCOMPARE( *(++it1), 20000 ); |
|
504 |
*(it1) = 25000; |
|
505 |
it1--; |
|
506 |
it1++; |
|
507 |
QCOMPARE( *(it1), 25000 ); |
|
508 |
||
509 |
Q3ValueListIterator<int> it2 = a.find( it1, 30000 ); |
|
510 |
*(it2) = 35000; |
|
511 |
QCOMPARE( *(it2), 35000 ); |
|
512 |
} |
|
513 |
||
514 |
void tst_Q3ValueList::opEqualNotEqual() |
|
515 |
{ |
|
516 |
Q3ValueList<int> a; |
|
517 |
a.append( 1 ); |
|
518 |
a.append( 10 ); |
|
519 |
a.append( 100 ); |
|
520 |
||
521 |
Q3ValueList<int> b; |
|
522 |
b.append( 1 ); |
|
523 |
b.append( 10 ); |
|
524 |
b.append( 100 ); |
|
525 |
||
526 |
QVERIFY( a == b ); |
|
527 |
QVERIFY( !(a != b) ); |
|
528 |
||
529 |
a.append( 1000 ); |
|
530 |
QVERIFY( a != b ); |
|
531 |
QVERIFY( !(a == b) ); |
|
532 |
} |
|
533 |
||
534 |
void tst_Q3ValueList::opPlus() |
|
535 |
{ |
|
536 |
Q3ValueList<int> a; |
|
537 |
a.append( 1 ); |
|
538 |
a.append( 10 ); |
|
539 |
a.append( 100 ); |
|
540 |
||
541 |
Q3ValueList<int> b; |
|
542 |
b.append( 2 ); |
|
543 |
b.append( 20 ); |
|
544 |
b.append( 200 ); |
|
545 |
||
546 |
Q3ValueList<int> c = a + b; |
|
547 |
||
548 |
QCOMPARE( c[0], 1 ); |
|
549 |
QCOMPARE( c[1], 10 ); |
|
550 |
QCOMPARE( c[2], 100 ); |
|
551 |
QCOMPARE( c[3], 2 ); |
|
552 |
QCOMPARE( c[4], 20 ); |
|
553 |
QCOMPARE( c[5], 200 ); |
|
554 |
} |
|
555 |
||
556 |
void tst_Q3ValueList::opPlusEqual() |
|
557 |
{ |
|
558 |
Q3ValueList<int> a; |
|
559 |
a.append( 1 ); |
|
560 |
a.append( 10 ); |
|
561 |
a.append( 100 ); |
|
562 |
||
563 |
Q3ValueList<int> b; |
|
564 |
b.append( 2 ); |
|
565 |
b.append( 20 ); |
|
566 |
b.append( 200 ); |
|
567 |
||
568 |
a += b; |
|
569 |
QCOMPARE( a[0], 1 ); |
|
570 |
QCOMPARE( a[1], 10 ); |
|
571 |
QCOMPARE( a[2], 100 ); |
|
572 |
QCOMPARE( a[3], 2 ); |
|
573 |
QCOMPARE( a[4], 20 ); |
|
574 |
QCOMPARE( a[5], 200 ); |
|
575 |
||
576 |
a += 1000; |
|
577 |
QCOMPARE( a[6], 1000 ); |
|
578 |
} |
|
579 |
||
580 |
void tst_Q3ValueList::opStreamOut() |
|
581 |
{ |
|
582 |
Q3ValueList<int> a; |
|
583 |
a.append( 1 ); |
|
584 |
a.append( 10 ); |
|
585 |
a.append( 100 ); |
|
586 |
||
587 |
a << 1000 << 10000; |
|
588 |
QCOMPARE( a.last(), 10000 ); |
|
589 |
} |
|
590 |
||
591 |
class ListVerifier : public Q3ValueList<int> |
|
592 |
{ |
|
593 |
public: |
|
594 |
const int* pointer() const { return &*begin(); } |
|
595 |
}; |
|
596 |
void tst_Q3ValueList::shared() |
|
597 |
{ |
|
598 |
ListVerifier a; |
|
599 |
a.append( 1 ); |
|
600 |
a.append( 10 ); |
|
601 |
a.append( 100 ); |
|
602 |
||
603 |
ListVerifier b = a; |
|
604 |
||
605 |
//Checking for identical d-pointers |
|
606 |
QVERIFY( (a == b) ); |
|
607 |
QVERIFY( (a.pointer() == b.pointer()) ); |
|
608 |
} |
|
609 |
void tst_Q3ValueList::detach_on_append() |
|
610 |
{ |
|
611 |
ListVerifier a; |
|
612 |
a.append( 1 ); |
|
613 |
a.append( 10 ); |
|
614 |
a.append( 100 ); |
|
615 |
||
616 |
ListVerifier b = a; |
|
617 |
||
618 |
// append detach? |
|
619 |
b.append( 10 ); |
|
620 |
QVERIFY( !(a == b) ); |
|
621 |
QVERIFY( !(a.pointer() == b.pointer()) ); |
|
622 |
} |
|
623 |
||
624 |
void tst_Q3ValueList::detach_on_prepend() |
|
625 |
{ |
|
626 |
ListVerifier a; |
|
627 |
a.append( 1 ); |
|
628 |
a.append( 10 ); |
|
629 |
a.append( 100 ); |
|
630 |
||
631 |
ListVerifier b = a; |
|
632 |
||
633 |
// prepend detach? |
|
634 |
b.prepend( 10000 ); |
|
635 |
QVERIFY( !(a == b) ); |
|
636 |
QVERIFY( !(a.pointer() == b.pointer()) ); |
|
637 |
} |
|
638 |
||
639 |
void tst_Q3ValueList::detach_on_insert1() |
|
640 |
{ |
|
641 |
ListVerifier a; |
|
642 |
a.append( 1 ); |
|
643 |
a.append( 10 ); |
|
644 |
a.append( 100 ); |
|
645 |
||
646 |
ListVerifier b = a; |
|
647 |
||
648 |
// insert detach? |
|
649 |
Q3ValueListIterator<int> it = b.at(1); |
|
650 |
b.insert( it, 20 ); |
|
651 |
QVERIFY( !(a == b) ); |
|
652 |
QVERIFY( !(a.pointer() == b.pointer()) ); |
|
653 |
} |
|
654 |
||
655 |
void tst_Q3ValueList::detach_on_insert2() |
|
656 |
{ |
|
657 |
ListVerifier a; |
|
658 |
a.append( 1 ); |
|
659 |
a.append( 10 ); |
|
660 |
a.append( 100 ); |
|
661 |
||
662 |
ListVerifier b = a; |
|
663 |
// insert detach? |
|
664 |
Q3ValueListIterator<int> it = b.at(1); |
|
665 |
b.insert( it, 2, 20 ); |
|
666 |
QVERIFY( !(a == b) ); |
|
667 |
QVERIFY( !(a.pointer() == b.pointer()) ); |
|
668 |
} |
|
669 |
||
670 |
void tst_Q3ValueList::detach_on_it_assign() |
|
671 |
{ |
|
672 |
ListVerifier a; |
|
673 |
a.append( 1 ); |
|
674 |
a.append( 10 ); |
|
675 |
a.append( 100 ); |
|
676 |
||
677 |
ListVerifier b = a; |
|
678 |
||
679 |
// iterator assignment detach? |
|
680 |
Q3ValueListIterator<int> it = b.at(0); |
|
681 |
*(it) = 2; |
|
682 |
QVERIFY( !(a == b) ); |
|
683 |
QVERIFY( !(a.pointer() == b.pointer()) ); |
|
684 |
} |
|
685 |
||
686 |
void tst_Q3ValueList::detach_on_ref_assign() |
|
687 |
{ |
|
688 |
ListVerifier a; |
|
689 |
a.append( 1 ); |
|
690 |
a.append( 10 ); |
|
691 |
a.append( 100 ); |
|
692 |
||
693 |
ListVerifier b = a; |
|
694 |
||
695 |
// reference assignment detach? |
|
696 |
int &i1 = b.back(); |
|
697 |
i1 = 2; |
|
698 |
QVERIFY( !(a == b) ); |
|
699 |
QVERIFY( !(a.pointer() == b.pointer()) ); |
|
700 |
} |
|
701 |
||
702 |
void tst_Q3ValueList::detach_on_clear() |
|
703 |
{ |
|
704 |
ListVerifier a; |
|
705 |
a.append( 1 ); |
|
706 |
a.append( 10 ); |
|
707 |
a.append( 100 ); |
|
708 |
||
709 |
ListVerifier b = a; |
|
710 |
||
711 |
// clear detach? |
|
712 |
b.clear(); |
|
713 |
QVERIFY( !(a == b) ); |
|
714 |
QVERIFY( !(a.pointer() == b.pointer()) ); |
|
715 |
} |
|
716 |
||
717 |
void tst_Q3ValueList::detach_on_erase1() |
|
718 |
{ |
|
719 |
ListVerifier a; |
|
720 |
a.append( 1 ); |
|
721 |
a.append( 10 ); |
|
722 |
a.append( 100 ); |
|
723 |
||
724 |
ListVerifier b = a; |
|
725 |
||
726 |
// erase detach? |
|
727 |
Q3ValueListIterator<int> it = b.at(1); |
|
728 |
b.erase( it ); |
|
729 |
QVERIFY( !(a == b) ); |
|
730 |
QVERIFY( !(a.pointer() == b.pointer()) ); |
|
731 |
} |
|
732 |
||
733 |
void tst_Q3ValueList::detach_on_erase2() |
|
734 |
{ |
|
735 |
ListVerifier a; |
|
736 |
a.append( 1 ); |
|
737 |
a.append( 10 ); |
|
738 |
a.append( 100 ); |
|
739 |
||
740 |
ListVerifier b = a; |
|
741 |
||
742 |
// erase detach? |
|
743 |
Q3ValueListIterator<int> it1 = b.at(0); |
|
744 |
Q3ValueListIterator<int> it2 = b.at(1); |
|
745 |
b.erase( it1, it2 ); |
|
746 |
QVERIFY( !(a == b) ); |
|
747 |
QVERIFY( !(a.pointer() == b.pointer()) ); |
|
748 |
} |
|
749 |
||
750 |
void tst_Q3ValueList::detach_on_opPE1() |
|
751 |
{ |
|
752 |
ListVerifier a; |
|
753 |
a.append( 1 ); |
|
754 |
a.append( 10 ); |
|
755 |
a.append( 100 ); |
|
756 |
||
757 |
ListVerifier b = a; |
|
758 |
||
759 |
// operator+= detach? |
|
760 |
b += 1000; |
|
761 |
QVERIFY( !(a == b) ); |
|
762 |
QVERIFY( !(a.pointer() == b.pointer()) ); |
|
763 |
} |
|
764 |
||
765 |
void tst_Q3ValueList::detach_on_opPE2() |
|
766 |
{ |
|
767 |
ListVerifier a; |
|
768 |
a.append( 1 ); |
|
769 |
a.append( 10 ); |
|
770 |
a.append( 100 ); |
|
771 |
||
772 |
ListVerifier b = a; |
|
773 |
||
774 |
// operator+= detach? |
|
775 |
b += a; |
|
776 |
QVERIFY( !(a == b) ); |
|
777 |
QVERIFY( !(a.pointer() == b.pointer()) ); |
|
778 |
} |
|
779 |
||
780 |
void tst_Q3ValueList::detach_on_opStream() |
|
781 |
{ |
|
782 |
ListVerifier a; |
|
783 |
a.append( 1 ); |
|
784 |
a.append( 10 ); |
|
785 |
a.append( 100 ); |
|
786 |
||
787 |
ListVerifier b = a; |
|
788 |
||
789 |
// operator<< detach? |
|
790 |
b << 1000; |
|
791 |
QVERIFY( !(a == b) ); |
|
792 |
QVERIFY( !(a.pointer() == b.pointer()) ); |
|
793 |
} |
|
794 |
||
795 |
void tst_Q3ValueList::detach_on_pop_front() |
|
796 |
{ |
|
797 |
ListVerifier a; |
|
798 |
a.append( 1 ); |
|
799 |
a.append( 10 ); |
|
800 |
a.append( 100 ); |
|
801 |
||
802 |
ListVerifier b = a; |
|
803 |
||
804 |
// pop_front detach? |
|
805 |
b.pop_front(); |
|
806 |
QVERIFY( !(a == b) ); |
|
807 |
QVERIFY( !(a.pointer() == b.pointer()) ); |
|
808 |
} |
|
809 |
||
810 |
void tst_Q3ValueList::detach_on_pop_back() |
|
811 |
{ |
|
812 |
ListVerifier a; |
|
813 |
a.append( 1 ); |
|
814 |
a.append( 10 ); |
|
815 |
a.append( 100 ); |
|
816 |
||
817 |
ListVerifier b = a; |
|
818 |
||
819 |
// pop_back detach? |
|
820 |
b.pop_back(); |
|
821 |
QVERIFY( !(a == b) ); |
|
822 |
QVERIFY( !(a.pointer() == b.pointer()) ); |
|
823 |
} |
|
824 |
||
825 |
void tst_Q3ValueList::detach_on_push_front() |
|
826 |
{ |
|
827 |
ListVerifier a; |
|
828 |
a.append( 1 ); |
|
829 |
a.append( 10 ); |
|
830 |
a.append( 100 ); |
|
831 |
||
832 |
ListVerifier b = a; |
|
833 |
||
834 |
// push_front detach? |
|
835 |
b.push_front( 2 ); |
|
836 |
QVERIFY( !(a == b) ); |
|
837 |
QVERIFY( !(a.pointer() == b.pointer()) ); |
|
838 |
} |
|
839 |
||
840 |
void tst_Q3ValueList::detach_on_push_back() |
|
841 |
{ |
|
842 |
ListVerifier a; |
|
843 |
a.append( 1 ); |
|
844 |
a.append( 10 ); |
|
845 |
a.append( 100 ); |
|
846 |
||
847 |
ListVerifier b = a; |
|
848 |
||
849 |
// pop_back detach? |
|
850 |
b.push_back( 2 ); |
|
851 |
QVERIFY( !(a == b) ); |
|
852 |
QVERIFY( !(a.pointer() == b.pointer()) ); |
|
853 |
} |
|
854 |
||
855 |
void tst_Q3ValueList::detach_on_remove1() |
|
856 |
{ |
|
857 |
ListVerifier a; |
|
858 |
a.append( 1 ); |
|
859 |
a.append( 10 ); |
|
860 |
a.append( 100 ); |
|
861 |
||
862 |
ListVerifier b = a; |
|
863 |
||
864 |
// remove detach? |
|
865 |
b.remove( 10 ); |
|
866 |
QVERIFY( !(a == b) ); |
|
867 |
QVERIFY( !(a.pointer() == b.pointer()) ); |
|
868 |
} |
|
869 |
||
870 |
void tst_Q3ValueList::detach_on_remove2() |
|
871 |
{ |
|
872 |
ListVerifier a; |
|
873 |
a.append( 1 ); |
|
874 |
a.append( 10 ); |
|
875 |
a.append( 100 ); |
|
876 |
||
877 |
ListVerifier b = a; |
|
878 |
||
879 |
// remove detach? |
|
880 |
Q3ValueListIterator<int> it6 = b.at(1); |
|
881 |
b.remove( it6 ); |
|
882 |
QVERIFY( !(a == b) ); |
|
883 |
QVERIFY( !(a.pointer() == b.pointer()) ); |
|
884 |
} |
|
885 |
||
886 |
void tst_Q3ValueList::append() |
|
887 |
{ |
|
888 |
Q3ValueList<int> list; |
|
889 |
Q3ValueList<int>::Iterator it = list.append(1); |
|
890 |
QVERIFY(*it == 1); |
|
891 |
it = list.append(2); |
|
892 |
QVERIFY(*it == 2); |
|
893 |
} |
|
894 |
||
895 |
||
896 |
QTEST_APPLESS_MAIN(tst_Q3ValueList) |
|
897 |
#include "tst_q3valuelist.moc" |