diff options
Diffstat (limited to 'tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp')
-rw-r--r-- | tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp index 070c25368b..3d90644aa3 100644 --- a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp +++ b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp @@ -64,21 +64,21 @@ private: void initializeList(); }; -int fooCtor = 0; -int fooDtor = 0; - -struct Foo +struct Tracker { - int *p; - - Foo() { p = new int; ++fooCtor; } - Foo(const Foo &/*other*/) { p = new int; ++fooCtor; } + static int count; + Tracker() { ++count; } + Tracker(const Tracker &) { ++count; } + Tracker(Tracker &&) { ++count; } - void operator=(const Foo & /* other */) { } + Tracker &operator=(const Tracker &) = default; + Tracker &operator=(Tracker &&) = default; - ~Foo() { delete p; ++fooDtor; } + ~Tracker() { --count; } }; +int Tracker::count = 0; + void tst_QVarLengthArray::append() { QVarLengthArray<QString, 2> v; @@ -130,6 +130,23 @@ void tst_QVarLengthArray::removeLast() v.removeLast(); QCOMPARE(v.size(), 2); } + + { + Tracker t; + QCOMPARE(Tracker::count, 1); + QVarLengthArray<Tracker, 2> v; + v.append(t); + v.append({}); + QCOMPARE(Tracker::count, 3); + v.removeLast(); + QCOMPARE(Tracker::count, 2); + v.append(t); + v.append({}); + QCOMPARE(Tracker::count, 4); + v.removeLast(); + QCOMPARE(Tracker::count, 3); + } + QCOMPARE(Tracker::count, 0); } void tst_QVarLengthArray::oldTests() |