author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 22 Apr 2010 16:15:11 +0300 | |
branch | RCL_3 |
changeset 14 | 8c4229025c0b |
parent 4 | 3b1da2848fc7 |
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 |
||
43 |
#include <QtTest/QtTest> |
|
44 |
#include <qvector.h> |
|
45 |
||
46 |
//TESTED_CLASS= |
|
47 |
//TESTED_FILES=corelib/tools/qregexp.h corelib/tools/qregexp.cpp |
|
48 |
||
49 |
class tst_QVector : public QObject |
|
50 |
{ |
|
51 |
Q_OBJECT |
|
52 |
||
53 |
public: |
|
54 |
tst_QVector() {} |
|
55 |
virtual ~tst_QVector() {} |
|
56 |
||
57 |
private slots: |
|
58 |
void outOfMemory(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
59 |
void QTBUG6416_reserve(); |
0 | 60 |
}; |
61 |
||
62 |
int fooCtor; |
|
63 |
int fooDtor; |
|
64 |
||
65 |
struct Foo |
|
66 |
{ |
|
67 |
int *p; |
|
68 |
||
69 |
Foo() { p = new int; ++fooCtor; } |
|
70 |
Foo(const Foo &other) { Q_UNUSED(other); p = new int; ++fooCtor; } |
|
71 |
||
72 |
void operator=(const Foo & /* other */) { } |
|
73 |
||
74 |
~Foo() { delete p; ++fooDtor; } |
|
75 |
}; |
|
76 |
||
77 |
void tst_QVector::outOfMemory() |
|
78 |
{ |
|
79 |
fooCtor = 0; |
|
80 |
fooDtor = 0; |
|
81 |
||
82 |
const int N = 0x7fffffff / sizeof(Foo); |
|
83 |
||
84 |
{ |
|
85 |
QVector<Foo> a; |
|
86 |
||
87 |
QSKIP("This test crashes on many of our machines.", SkipSingle); |
|
88 |
a.resize(N); |
|
89 |
if (a.size() == N) { |
|
90 |
QVERIFY(a.capacity() >= N); |
|
91 |
QCOMPARE(fooCtor, N); |
|
92 |
QCOMPARE(fooDtor, 0); |
|
93 |
||
94 |
for (int i = 0; i < N; i += 35000) |
|
95 |
a[i] = Foo(); |
|
96 |
} else { |
|
97 |
// this is the case we're actually testing |
|
98 |
QCOMPARE(a.size(), 0); |
|
99 |
QCOMPARE(a.capacity(), 0); |
|
100 |
QCOMPARE(fooCtor, 0); |
|
101 |
QCOMPARE(fooDtor, 0); |
|
102 |
||
103 |
a.resize(5); |
|
104 |
QCOMPARE(a.size(), 5); |
|
105 |
QVERIFY(a.capacity() >= 5); |
|
106 |
QCOMPARE(fooCtor, 5); |
|
107 |
QCOMPARE(fooDtor, 0); |
|
108 |
||
109 |
const int Prealloc = a.capacity(); |
|
110 |
a.resize(Prealloc + 1); |
|
111 |
QCOMPARE(a.size(), Prealloc + 1); |
|
112 |
QVERIFY(a.capacity() >= Prealloc + 1); |
|
113 |
QCOMPARE(fooCtor, Prealloc + 6); |
|
114 |
QCOMPARE(fooDtor, 5); |
|
115 |
||
116 |
a.resize(0x10000000); |
|
117 |
QCOMPARE(a.size(), 0); |
|
118 |
QCOMPARE(a.capacity(), 0); |
|
119 |
QCOMPARE(fooCtor, Prealloc + 6); |
|
120 |
QCOMPARE(fooDtor, Prealloc + 6); |
|
121 |
} |
|
122 |
} |
|
123 |
||
124 |
fooCtor = 0; |
|
125 |
fooDtor = 0; |
|
126 |
||
127 |
{ |
|
128 |
QVector<Foo> a(N); |
|
129 |
if (a.size() == N) { |
|
130 |
QVERIFY(a.capacity() >= N); |
|
131 |
QCOMPARE(fooCtor, N); |
|
132 |
QCOMPARE(fooDtor, 0); |
|
133 |
||
134 |
for (int i = 0; i < N; i += 35000) |
|
135 |
a[i] = Foo(); |
|
136 |
} else { |
|
137 |
// this is the case we're actually testing |
|
138 |
QCOMPARE(a.size(), 0); |
|
139 |
QCOMPARE(a.capacity(), 0); |
|
140 |
QCOMPARE(fooCtor, 0); |
|
141 |
QCOMPARE(fooDtor, 0); |
|
142 |
} |
|
143 |
} |
|
144 |
||
145 |
Foo foo; |
|
146 |
||
147 |
fooCtor = 0; |
|
148 |
fooDtor = 0; |
|
149 |
||
150 |
{ |
|
151 |
QVector<Foo> a(N, foo); |
|
152 |
if (a.size() == N) { |
|
153 |
QVERIFY(a.capacity() >= N); |
|
154 |
QCOMPARE(fooCtor, N); |
|
155 |
QCOMPARE(fooDtor, 0); |
|
156 |
||
157 |
for (int i = 0; i < N; i += 35000) |
|
158 |
a[i] = Foo(); |
|
159 |
} else { |
|
160 |
// this is the case we're actually testing |
|
161 |
QCOMPARE(a.size(), 0); |
|
162 |
QCOMPARE(a.capacity(), 0); |
|
163 |
QCOMPARE(fooCtor, 0); |
|
164 |
QCOMPARE(fooDtor, 0); |
|
165 |
} |
|
166 |
} |
|
167 |
||
168 |
fooCtor = 0; |
|
169 |
fooDtor = 0; |
|
170 |
||
171 |
{ |
|
172 |
QVector<Foo> a; |
|
173 |
a.resize(10); |
|
174 |
QCOMPARE(fooCtor, 10); |
|
175 |
QCOMPARE(fooDtor, 0); |
|
176 |
||
177 |
QVector<Foo> b(a); |
|
178 |
QCOMPARE(fooCtor, 10); |
|
179 |
QCOMPARE(fooDtor, 0); |
|
180 |
||
181 |
a.resize(N); |
|
182 |
if (a.size() == N) { |
|
183 |
QCOMPARE(fooCtor, N + 10); |
|
184 |
} else { |
|
185 |
QCOMPARE(a.size(), 0); |
|
186 |
QCOMPARE(a.capacity(), 0); |
|
187 |
QCOMPARE(fooCtor, 10); |
|
188 |
QCOMPARE(fooDtor, 0); |
|
189 |
||
190 |
QCOMPARE(b.size(), 10); |
|
191 |
QVERIFY(b.capacity() >= 10); |
|
192 |
} |
|
193 |
} |
|
194 |
||
195 |
{ |
|
196 |
QVector<int> a; |
|
197 |
a.resize(10); |
|
198 |
||
199 |
QVector<int> b(a); |
|
200 |
||
201 |
a.resize(N); |
|
202 |
if (a.size() == N) { |
|
203 |
for (int i = 0; i < N; i += 60000) |
|
204 |
a[i] = i; |
|
205 |
} else { |
|
206 |
QCOMPARE(a.size(), 0); |
|
207 |
QCOMPARE(a.capacity(), 0); |
|
208 |
||
209 |
QCOMPARE(b.size(), 10); |
|
210 |
QVERIFY(b.capacity() >= 10); |
|
211 |
} |
|
212 |
||
213 |
b.resize(N - 1); |
|
214 |
if (b.size() == N - 1) { |
|
215 |
for (int i = 0; i < N - 1; i += 60000) |
|
216 |
b[i] = i; |
|
217 |
} else { |
|
218 |
QCOMPARE(b.size(), 0); |
|
219 |
QCOMPARE(b.capacity(), 0); |
|
220 |
} |
|
221 |
} |
|
222 |
} |
|
223 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
224 |
void tst_QVector::QTBUG6416_reserve() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
225 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
226 |
fooCtor = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
227 |
fooDtor = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
228 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
229 |
QVector<Foo> a; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
230 |
a.resize(2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
231 |
QVector<Foo> b(a); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
232 |
b.reserve(1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
233 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
234 |
QCOMPARE(fooCtor, fooDtor); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
235 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
236 |
|
0 | 237 |
QTEST_APPLESS_MAIN(tst_QVector) |
238 |
#include "tst_qvector.moc" |