diff options
author | Olivier Goffart <ogoffart@kde.org> | 2011-11-01 11:24:10 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-11-01 12:56:09 +0100 |
commit | d2ed5884192202dae8efefa66b9bdc2caaf8c551 (patch) | |
tree | f6d6a031b4b1b4ebdb66f56a812ec239ac43b4ee /tests/auto/corelib/kernel | |
parent | cf6ef44ffd348fbfabadde7e5ed7aae02daedbc6 (diff) |
tst_qvariant: add a test QVariant works with not movable types
Soon, QVariant will use more internal storage. It is important
that it still work with not movable types
Also, check with type that are movable but cannot be copyed
without their copy constructor to be called such as QSharedDataPointer
Change-Id: I6d67755476e4822468599bebfa8774ad96a15306
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@nokia.com>
Diffstat (limited to 'tests/auto/corelib/kernel')
-rw-r--r-- | tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp index d307564028..f126151a4c 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -3055,6 +3055,34 @@ struct MyMovable int MyMovable::count = 0; +struct MyNotMovable +{ + static int count; + MyNotMovable *that; + MyNotMovable() : that(this) { count++; } + ~MyNotMovable() { QCOMPARE(that, this); count--; } + MyNotMovable(const MyNotMovable &o) : that(this) { QCOMPARE(o.that, &o); count++; } + MyNotMovable &operator=(const MyNotMovable &o) { + bool ok = that == this && o.that == &o; + if (!ok) qFatal("MyNotMovable has been moved"); + return *this; + } + + //PLAY_WITH_VARIANT test that they are equal, but never that they are not equal + // so it would be fine just to always return true + bool operator==(const MyNotMovable &o) const + { + bool ok = that == this && o.that == &o; + if (!ok) qFatal("MyNotMovable has been moved"); + return ok; + } +}; + +int MyNotMovable::count = 0; + +struct MyShared : QSharedData { + MyMovable movable; +}; QT_BEGIN_NAMESPACE Q_DECLARE_TYPEINFO(MyMovable, Q_MOVABLE_TYPE); @@ -3064,12 +3092,16 @@ Q_DECLARE_METATYPE(QList<QSize>) Q_DECLARE_METATYPE(MyPrimitive) Q_DECLARE_METATYPE(MyData) Q_DECLARE_METATYPE(MyMovable) +Q_DECLARE_METATYPE(MyNotMovable) Q_DECLARE_METATYPE(QList<MyPrimitive>) Q_DECLARE_METATYPE(QList<MyData>) Q_DECLARE_METATYPE(QList<MyMovable>) +Q_DECLARE_METATYPE(QList<MyNotMovable>) Q_DECLARE_METATYPE(MyPrimitive *) Q_DECLARE_METATYPE(MyData *) Q_DECLARE_METATYPE(MyMovable *) +Q_DECLARE_METATYPE(MyNotMovable *) +Q_DECLARE_METATYPE(QSharedDataPointer<MyShared>) void tst_QVariant::moreCustomTypes() @@ -3125,6 +3157,18 @@ void tst_QVariant::moreCustomTypes() } QCOMPARE(MyMovable::count, 0); + QCOMPARE(MyNotMovable::count, 0); + { + MyNotMovable d; + PLAY_WITH_VARIANT(d, false, QString(), 0, false); + PLAY_WITH_VARIANT(&d, false, QString(), 0, false); + QList<MyNotMovable> l; + PLAY_WITH_VARIANT(l, false, QString(), 0, false); + l << MyNotMovable() << d; + PLAY_WITH_VARIANT(l, false, QString(), 0, false); + } + QCOMPARE(MyNotMovable::count, 0); + { PLAY_WITH_VARIANT(12.12, false, "12.12", 12.12, true); PLAY_WITH_VARIANT(12.12f, false, "12.12", 12.12f, true); @@ -3170,6 +3214,13 @@ void tst_QVariant::moreCustomTypes() PLAY_WITH_VARIANT(v5, false, QString(), 0, false); } + + QCOMPARE(MyMovable::count, 0); + { + QSharedDataPointer<MyShared> d(new MyShared); + PLAY_WITH_VARIANT(d, false, QString(), 0, false); + } + QCOMPARE(MyMovable::count, 0); } |