242 { |
244 { |
243 //creating a QVarLengthArray of the same size as the prealloc size |
245 //creating a QVarLengthArray of the same size as the prealloc size |
244 // will make the next call to append(const T&) corrupt the memory |
246 // will make the next call to append(const T&) corrupt the memory |
245 // you should get a segfault pretty soon after that :-) |
247 // you should get a segfault pretty soon after that :-) |
246 QVarLengthArray<float, 1> d(1); |
248 QVarLengthArray<float, 1> d(1); |
247 for (int i=0; i<30; i++) |
249 for (int i=0; i<30; i++) |
248 d.append(i); |
250 d.append(i); |
|
251 } |
|
252 |
|
253 void tst_QVarLengthArray::QTBUG6718_resize() |
|
254 { |
|
255 //MOVABLE |
|
256 { |
|
257 QVarLengthArray<QVariant,1> values(1); |
|
258 QCOMPARE(values.size(), 1); |
|
259 values[0] = 1; |
|
260 values.resize(2); |
|
261 QCOMPARE(values[1], QVariant()); |
|
262 QCOMPARE(values[0], QVariant(1)); |
|
263 values[1] = 2; |
|
264 QCOMPARE(values[1], QVariant(2)); |
|
265 QCOMPARE(values.size(), 2); |
|
266 } |
|
267 |
|
268 //POD |
|
269 { |
|
270 QVarLengthArray<int,1> values(1); |
|
271 QCOMPARE(values.size(), 1); |
|
272 values[0] = 1; |
|
273 values.resize(2); |
|
274 QCOMPARE(values[0], 1); |
|
275 values[1] = 2; |
|
276 QCOMPARE(values[1], 2); |
|
277 QCOMPARE(values.size(), 2); |
|
278 } |
|
279 |
|
280 //COMPLEX |
|
281 { |
|
282 QVarLengthArray<QVarLengthArray<QString, 15>,1> values(1); |
|
283 QCOMPARE(values.size(), 1); |
|
284 values[0].resize(10); |
|
285 values.resize(2); |
|
286 QCOMPARE(values[1].size(), 0); |
|
287 QCOMPARE(values[0].size(), 10); |
|
288 values[1].resize(20); |
|
289 QCOMPARE(values[1].size(), 20); |
|
290 QCOMPARE(values.size(), 2); |
|
291 } |
249 } |
292 } |
250 |
293 |
251 QTEST_APPLESS_MAIN(tst_QVarLengthArray) |
294 QTEST_APPLESS_MAIN(tst_QVarLengthArray) |
252 #include "tst_qvarlengtharray.moc" |
295 #include "tst_qvarlengtharray.moc" |