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 3 | 41300fa6a67c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
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 |
#include <QtTest/QtTest> |
|
43 |
#include <QtCore/QScopedPointer> |
|
44 |
||
45 |
/*! |
|
46 |
\class tst_QScopedPointer |
|
47 |
\internal |
|
48 |
\since 4.6 |
|
49 |
\brief Tests class QScopedPointer. |
|
50 |
||
51 |
*/ |
|
52 |
class tst_QScopedPointer : public QObject |
|
53 |
{ |
|
54 |
Q_OBJECT |
|
55 |
||
56 |
private Q_SLOTS: |
|
57 |
void defaultConstructor(); |
|
58 |
void dataOnDefaultConstructed(); |
|
59 |
void useSubClassInConstructor(); |
|
60 |
void dataOnValue(); |
|
61 |
void dataSignature(); |
|
62 |
void reset(); |
|
63 |
void dereferenceOperator(); |
|
64 |
void dereferenceOperatorSignature(); |
|
65 |
void pointerOperator(); |
|
66 |
void pointerOperatorSignature(); |
|
67 |
void negationOperator(); |
|
68 |
void negationOperatorSignature(); |
|
69 |
void operatorBool(); |
|
70 |
void operatorBoolSignature(); |
|
71 |
void isNull(); |
|
72 |
void isNullSignature(); |
|
73 |
void objectSize(); |
|
74 |
void comparison(); |
|
75 |
// TODO instanciate on const object |
|
76 |
}; |
|
77 |
||
78 |
void tst_QScopedPointer::defaultConstructor() |
|
79 |
{ |
|
80 |
/* Check that the members, one, is correctly initialized. */ |
|
81 |
QScopedPointer<int> p; |
|
82 |
QCOMPARE(p.data(), static_cast<int *>(0)); |
|
83 |
} |
|
84 |
||
85 |
void tst_QScopedPointer::dataOnDefaultConstructed() |
|
86 |
{ |
|
87 |
QScopedPointer<int> p; |
|
88 |
||
89 |
QCOMPARE(p.data(), static_cast<int *>(0)); |
|
90 |
} |
|
91 |
||
92 |
class MyClass |
|
93 |
{ |
|
94 |
}; |
|
95 |
||
96 |
class MySubClass : public MyClass |
|
97 |
{ |
|
98 |
}; |
|
99 |
||
100 |
void tst_QScopedPointer::useSubClassInConstructor() |
|
101 |
{ |
|
102 |
/* Use a syntax which users typically would do. */ |
|
103 |
QScopedPointer<MyClass> p(new MyClass()); |
|
104 |
} |
|
105 |
||
106 |
void tst_QScopedPointer::dataOnValue() |
|
107 |
{ |
|
108 |
int *const rawPointer = new int(5); |
|
109 |
QScopedPointer<int> p(rawPointer); |
|
110 |
||
111 |
QCOMPARE(p.data(), rawPointer); |
|
112 |
} |
|
113 |
||
114 |
void tst_QScopedPointer::dataSignature() |
|
115 |
{ |
|
116 |
const QScopedPointer<int> p; |
|
117 |
/* data() should be const. */ |
|
118 |
p.data(); |
|
119 |
} |
|
120 |
||
121 |
void tst_QScopedPointer::reset() |
|
122 |
{ |
|
123 |
/* Call reset() on a default constructed value. */ |
|
124 |
{ |
|
125 |
QScopedPointer<int> p; |
|
126 |
p.reset(); |
|
127 |
QCOMPARE(p.data(), static_cast<int *>(0)); |
|
128 |
} |
|
129 |
||
130 |
/* Call reset() on an active value. */ |
|
131 |
{ |
|
132 |
QScopedPointer<int> p(new int(3)); |
|
133 |
p.reset(); |
|
134 |
QCOMPARE(p.data(), static_cast<int *>(0)); |
|
135 |
} |
|
136 |
||
137 |
/* Call reset() with a value, on an active value. */ |
|
138 |
{ |
|
139 |
QScopedPointer<int> p(new int(3)); |
|
140 |
||
141 |
int *const value = new int(9); |
|
142 |
p.reset(value); |
|
143 |
QCOMPARE(*p.data(), 9); |
|
144 |
} |
|
145 |
||
146 |
/* Call reset() with a value, on default constructed value. */ |
|
147 |
{ |
|
148 |
QScopedPointer<int> p; |
|
149 |
||
150 |
int *const value = new int(9); |
|
151 |
p.reset(value); |
|
152 |
QCOMPARE(*p.data(), 9); |
|
153 |
} |
|
154 |
} |
|
155 |
||
156 |
class AbstractClass |
|
157 |
{ |
|
158 |
public: |
|
159 |
virtual ~AbstractClass() |
|
160 |
{ |
|
161 |
} |
|
162 |
||
163 |
virtual int member() const = 0; |
|
164 |
}; |
|
165 |
||
166 |
class SubClass : public AbstractClass |
|
167 |
{ |
|
168 |
public: |
|
169 |
virtual int member() const |
|
170 |
{ |
|
171 |
return 5; |
|
172 |
} |
|
173 |
}; |
|
174 |
||
175 |
void tst_QScopedPointer::dereferenceOperator() |
|
176 |
{ |
|
177 |
/* Dereference a basic value. */ |
|
178 |
{ |
|
179 |
QScopedPointer<int> p(new int(5)); |
|
180 |
||
181 |
const int value2 = *p; |
|
182 |
QCOMPARE(value2, 5); |
|
183 |
} |
|
184 |
||
185 |
/* Dereference a pointer to an abstract class. This verifies |
|
186 |
* that the operator returns a reference, when compiling |
|
187 |
* with MSVC 2005. */ |
|
188 |
{ |
|
189 |
QScopedPointer<AbstractClass> p(new SubClass()); |
|
190 |
||
191 |
QCOMPARE((*p).member(), 5); |
|
192 |
} |
|
193 |
} |
|
194 |
||
195 |
void tst_QScopedPointer::dereferenceOperatorSignature() |
|
196 |
{ |
|
197 |
/* The operator should be const. */ |
|
198 |
{ |
|
199 |
const QScopedPointer<int> p(new int(5)); |
|
200 |
*p; |
|
201 |
} |
|
202 |
||
203 |
/* A reference should be returned, not a value. */ |
|
204 |
{ |
|
205 |
const QScopedPointer<int> p(new int(5)); |
|
206 |
Q_UNUSED(static_cast<int &>(*p)); |
|
207 |
} |
|
208 |
||
209 |
/* Instantiated on a const object, the returned object is a const reference. */ |
|
210 |
{ |
|
211 |
const QScopedPointer<const int> p(new int(5)); |
|
212 |
Q_UNUSED(static_cast<const int &>(*p)); |
|
213 |
} |
|
214 |
} |
|
215 |
||
216 |
class AnyForm |
|
217 |
{ |
|
218 |
public: |
|
219 |
int value; |
|
220 |
}; |
|
221 |
||
222 |
void tst_QScopedPointer::pointerOperator() |
|
223 |
{ |
|
224 |
QScopedPointer<AnyForm> p(new AnyForm()); |
|
225 |
p->value = 5; |
|
226 |
||
227 |
QCOMPARE(p->value, 5); |
|
228 |
} |
|
229 |
||
230 |
void tst_QScopedPointer::pointerOperatorSignature() |
|
231 |
{ |
|
232 |
/* The operator should be const. */ |
|
233 |
const QScopedPointer<AnyForm> p(new AnyForm); |
|
234 |
p->value = 5; |
|
235 |
||
236 |
QVERIFY(p->value); |
|
237 |
} |
|
238 |
||
239 |
void tst_QScopedPointer::negationOperator() |
|
240 |
{ |
|
241 |
/* Invoke on default constructed value. */ |
|
242 |
{ |
|
243 |
QScopedPointer<int> p; |
|
244 |
QVERIFY(!p); |
|
245 |
} |
|
246 |
||
247 |
/* Invoke on a value. */ |
|
248 |
{ |
|
249 |
QScopedPointer<int> p(new int(2)); |
|
250 |
QCOMPARE(!p, false); |
|
251 |
} |
|
252 |
} |
|
253 |
||
254 |
void tst_QScopedPointer::negationOperatorSignature() |
|
255 |
{ |
|
256 |
/* The signature should be const. */ |
|
257 |
const QScopedPointer<int> p; |
|
258 |
!p; |
|
259 |
||
260 |
/* The return value should be bool. */ |
|
261 |
static_cast<bool>(!p); |
|
262 |
} |
|
263 |
||
264 |
void tst_QScopedPointer::operatorBool() |
|
265 |
{ |
|
266 |
/* Invoke on default constructed value. */ |
|
267 |
{ |
|
268 |
QScopedPointer<int> p; |
|
269 |
QCOMPARE(bool(p), false); |
|
270 |
} |
|
271 |
||
272 |
/* Invoke on active value. */ |
|
273 |
{ |
|
274 |
QScopedPointer<int> p(new int(3)); |
|
275 |
QVERIFY(p); |
|
276 |
} |
|
277 |
} |
|
278 |
||
279 |
void tst_QScopedPointer::operatorBoolSignature() |
|
280 |
{ |
|
281 |
/* The signature should be const and return bool. */ |
|
282 |
const QScopedPointer<int> p; |
|
283 |
||
284 |
(void)static_cast<bool>(p); |
|
285 |
} |
|
286 |
||
287 |
void tst_QScopedPointer::isNull() |
|
288 |
{ |
|
289 |
/* Invoke on default constructed value. */ |
|
290 |
{ |
|
291 |
QScopedPointer<int> p; |
|
292 |
QVERIFY(p.isNull()); |
|
293 |
} |
|
294 |
||
295 |
/* Invoke on a set value. */ |
|
296 |
{ |
|
297 |
QScopedPointer<int> p(new int(69)); |
|
298 |
QVERIFY(!p.isNull()); |
|
299 |
} |
|
300 |
} |
|
301 |
||
302 |
void tst_QScopedPointer::isNullSignature() |
|
303 |
{ |
|
304 |
const QScopedPointer<int> p(new int(69)); |
|
305 |
||
306 |
/* The signature should be const and return bool. */ |
|
307 |
static_cast<bool>(p.isNull()); |
|
308 |
} |
|
309 |
||
310 |
void tst_QScopedPointer::objectSize() |
|
311 |
{ |
|
312 |
/* The size of QScopedPointer should be the same as one pointer. */ |
|
313 |
QCOMPARE(sizeof(QScopedPointer<int>), sizeof(void *)); |
|
314 |
} |
|
315 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
316 |
struct RefCounted |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
317 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
318 |
RefCounted() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
319 |
: ref(0) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
320 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
321 |
instanceCount.ref(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
322 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
323 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
324 |
RefCounted(RefCounted const &) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
325 |
: ref(0) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
326 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
327 |
instanceCount.ref(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
328 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
329 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
330 |
~RefCounted() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
331 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
332 |
QVERIFY( ref == 0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
333 |
instanceCount.deref(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
334 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
335 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
336 |
RefCounted &operator=(RefCounted const &) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
337 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
338 |
return *this; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
339 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
340 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
341 |
QAtomicInt ref; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
342 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
343 |
static QAtomicInt instanceCount; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
344 |
}; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
345 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
346 |
QAtomicInt RefCounted::instanceCount = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
347 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
348 |
template <class A1, class A2, class B> |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
349 |
void scopedPointerComparisonTest(const A1 &a1, const A2 &a2, const B &b) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
350 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
351 |
// test equality on equal pointers |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
352 |
QVERIFY(a1 == a2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
353 |
QVERIFY(a2 == a1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
354 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
355 |
// test inequality on equal pointers |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
356 |
QVERIFY(!(a1 != a2)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
357 |
QVERIFY(!(a2 != a1)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
358 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
359 |
// test equality on unequal pointers |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
360 |
QVERIFY(!(a1 == b)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
361 |
QVERIFY(!(a2 == b)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
362 |
QVERIFY(!(b == a1)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
363 |
QVERIFY(!(b == a2)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
364 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
365 |
// test inequality on unequal pointers |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
366 |
QVERIFY(b != a1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
367 |
QVERIFY(b != a2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
368 |
QVERIFY(a1 != b); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
369 |
QVERIFY(a2 != b); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
370 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
371 |
|
0 | 372 |
void tst_QScopedPointer::comparison() |
373 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
374 |
QCOMPARE( int(RefCounted::instanceCount), 0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
375 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
376 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
377 |
RefCounted *a = new RefCounted; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
378 |
RefCounted *b = new RefCounted; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
379 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
380 |
QCOMPARE( int(RefCounted::instanceCount), 2 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
381 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
382 |
QScopedPointer<RefCounted> pa1(a); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
383 |
QScopedPointer<RefCounted> pa2(a); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
384 |
QScopedPointer<RefCounted> pb(b); |
0 | 385 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
386 |
scopedPointerComparisonTest(pa1, pa1, pb); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
387 |
scopedPointerComparisonTest(pa2, pa2, pb); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
388 |
scopedPointerComparisonTest(pa1, pa2, pb); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
389 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
390 |
pa2.take(); |
0 | 391 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
392 |
QCOMPARE( int(RefCounted::instanceCount), 2 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
393 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
394 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
395 |
QCOMPARE( int(RefCounted::instanceCount), 0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
396 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
397 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
398 |
RefCounted *a = new RefCounted[42]; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
399 |
RefCounted *b = new RefCounted[43]; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
400 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
401 |
QCOMPARE( int(RefCounted::instanceCount), 85 ); |
0 | 402 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
403 |
QScopedArrayPointer<RefCounted> pa1(a); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
404 |
QScopedArrayPointer<RefCounted> pa2(a); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
405 |
QScopedArrayPointer<RefCounted> pb(b); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
406 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
407 |
scopedPointerComparisonTest(pa1, pa2, pb); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
408 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
409 |
pa2.take(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
410 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
411 |
QCOMPARE( int(RefCounted::instanceCount), 85 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
412 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
413 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
414 |
QCOMPARE( int(RefCounted::instanceCount), 0 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
415 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
416 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
417 |
// QScopedSharedPointer is an internal helper class -- it is unsupported! |
0 | 418 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
419 |
RefCounted *a = new RefCounted; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
420 |
RefCounted *b = new RefCounted; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
421 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
422 |
QCOMPARE( int(RefCounted::instanceCount), 2 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
423 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
424 |
QSharedDataPointer<RefCounted> pa1(a); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
425 |
QSharedDataPointer<RefCounted> pa2(a); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
426 |
QSharedDataPointer<RefCounted> pb(b); |
0 | 427 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
428 |
QCOMPARE( int(a->ref), 2 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
429 |
QCOMPARE( int(b->ref), 1 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
430 |
QCOMPARE( int(RefCounted::instanceCount), 2 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
431 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
432 |
scopedPointerComparisonTest(pa1, pa2, pb); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
433 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
434 |
QCOMPARE( int(RefCounted::instanceCount), 2 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
435 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
436 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
437 |
QCOMPARE( int(RefCounted::instanceCount), 0 ); |
0 | 438 |
} |
439 |
||
440 |
QTEST_MAIN(tst_QScopedPointer) |
|
441 |
#include "tst_qscopedpointer.moc" |