tests/auto/qvarlengtharray/tst_qvarlengtharray.cpp
changeset 19 fcece45ef507
parent 18 2f34d5167611
child 29 b72c6db6890b
--- a/tests/auto/qvarlengtharray/tst_qvarlengtharray.cpp	Fri Apr 16 15:50:13 2010 +0300
+++ b/tests/auto/qvarlengtharray/tst_qvarlengtharray.cpp	Mon May 03 13:17:34 2010 +0300
@@ -42,6 +42,7 @@
 
 #include <QtTest/QtTest>
 #include <qvarlengtharray.h>
+#include <qvariant.h>
 
 const int N = 1;
 
@@ -61,6 +62,7 @@
     void removeLast();
     void oldTests();
     void task214223();
+    void QTBUG6718_resize();
 };
 
 int fooCtor = 0;
@@ -71,7 +73,7 @@
     int *p;
 
     Foo() { p = new int; ++fooCtor; }
-    Foo(const Foo &other) { p = new int; ++fooCtor; }
+    Foo(const Foo &/*other*/) { p = new int; ++fooCtor; }
 
     void operator=(const Foo & /* other */) { }
 
@@ -244,9 +246,50 @@
     // will make the next call to append(const T&) corrupt the memory
     // you should get a segfault pretty soon after that :-)
     QVarLengthArray<float, 1> d(1);
-    for (int i=0; i<30; i++) 
+    for (int i=0; i<30; i++)
         d.append(i);
 }
 
+void tst_QVarLengthArray::QTBUG6718_resize()
+{
+    //MOVABLE
+    {
+        QVarLengthArray<QVariant,1> values(1);
+        QCOMPARE(values.size(), 1);
+        values[0] = 1;
+        values.resize(2);
+        QCOMPARE(values[1], QVariant());
+        QCOMPARE(values[0], QVariant(1));
+        values[1] = 2;
+        QCOMPARE(values[1], QVariant(2));
+        QCOMPARE(values.size(), 2);
+    }
+
+    //POD
+    {
+        QVarLengthArray<int,1> values(1);
+        QCOMPARE(values.size(), 1);
+        values[0] = 1;
+        values.resize(2);
+        QCOMPARE(values[0], 1);
+        values[1] = 2;
+        QCOMPARE(values[1], 2);
+        QCOMPARE(values.size(), 2);
+    }
+
+    //COMPLEX
+    {
+        QVarLengthArray<QVarLengthArray<QString, 15>,1> values(1);
+        QCOMPARE(values.size(), 1);
+        values[0].resize(10);
+        values.resize(2);
+        QCOMPARE(values[1].size(), 0);
+        QCOMPARE(values[0].size(), 10);
+        values[1].resize(20);
+        QCOMPARE(values[1].size(), 20);
+        QCOMPARE(values.size(), 2);
+    }
+}
+
 QTEST_APPLESS_MAIN(tst_QVarLengthArray)
 #include "tst_qvarlengtharray.moc"