summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorStephen Kelly <stephen.kelly@kdab.com>2011-12-30 12:00:09 +0100
committerQt by Nokia <qt-info@nokia.com>2012-01-24 15:27:25 +0100
commit4b8ceb41aed352f10d36db5284453f425dbc5f3f (patch)
tree6362bc3353107a7d35b7bb1cefb7f1751fe473fe /tests
parent6efefb3fe5c7c392bc4857d979dee51042a4f043 (diff)
Store the is-a QObject fact with the metatype declaration.
This is a source incompatible change for Q_DECLARE_METATYPE(T*), which now requires T to be fully defined. The consequences of this are: * Forward declared types can no longer be declared as a metatype. (though this is a very uncommon thing to do). There is a trivial workaround where necessary. Change-Id: Id74c40088b8c0b466fcd7c55abd616f69acc82c8 Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp39
-rw-r--r--tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp5
-rw-r--r--tests/auto/other/exceptionsafety_objects/tst_exceptionsafety_objects.cpp5
-rw-r--r--tests/benchmarks/corelib/tools/qstring/main.cpp15
4 files changed, 60 insertions, 4 deletions
diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
index 3107fe49d9..de93c21d43 100644
--- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
+++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
@@ -596,21 +596,50 @@ Q_DECLARE_TYPEINFO(CustomMovable, Q_MOVABLE_TYPE);
QT_END_NAMESPACE
Q_DECLARE_METATYPE(CustomMovable);
+class CustomObject : public QObject
+{
+ Q_OBJECT
+public:
+ CustomObject(QObject *parent = 0)
+ : QObject(parent)
+ {
+
+ }
+};
+Q_DECLARE_METATYPE(CustomObject*);
+
+struct SecondBase {};
+
+class CustomMultiInheritanceObject : public QObject, SecondBase
+{
+ Q_OBJECT
+public:
+ CustomMultiInheritanceObject(QObject *parent = 0)
+ : QObject(parent)
+ {
+
+ }
+};
+Q_DECLARE_METATYPE(CustomMultiInheritanceObject*);
+
void tst_QMetaType::flags_data()
{
QTest::addColumn<int>("type");
QTest::addColumn<bool>("isMovable");
QTest::addColumn<bool>("isComplex");
+ QTest::addColumn<bool>("isPointerToQObject");
#define ADD_METATYPE_TEST_ROW(MetaTypeName, MetaTypeId, RealType) \
- QTest::newRow(#RealType) << MetaTypeId << bool(!QTypeInfo<RealType>::isStatic) << bool(QTypeInfo<RealType>::isComplex);
+ QTest::newRow(#RealType) << MetaTypeId << bool(!QTypeInfo<RealType>::isStatic) << bool(QTypeInfo<RealType>::isComplex) << bool(QtPrivate::IsPointerToTypeDerivedFromQObject<RealType>::Value);
QT_FOR_EACH_STATIC_CORE_CLASS(ADD_METATYPE_TEST_ROW)
QT_FOR_EACH_STATIC_PRIMITIVE_POINTER(ADD_METATYPE_TEST_ROW)
QT_FOR_EACH_STATIC_CORE_POINTER(ADD_METATYPE_TEST_ROW)
#undef ADD_METATYPE_TEST_ROW
- QTest::newRow("TestSpace::Foo") << ::qMetaTypeId<TestSpace::Foo>() << false << true;
- QTest::newRow("Whity<double>") << ::qMetaTypeId<Whity<double> >() << false << true;
- QTest::newRow("CustomMovable") << ::qMetaTypeId<CustomMovable>() << true << true;
+ QTest::newRow("TestSpace::Foo") << ::qMetaTypeId<TestSpace::Foo>() << false << true << false;
+ QTest::newRow("Whity<double>") << ::qMetaTypeId<Whity<double> >() << false << true << false;
+ QTest::newRow("CustomMovable") << ::qMetaTypeId<CustomMovable>() << true << true << false;
+ QTest::newRow("CustomObject*") << ::qMetaTypeId<CustomObject*>() << true << false << true;
+ QTest::newRow("CustomMultiInheritanceObject*") << ::qMetaTypeId<CustomMultiInheritanceObject*>() << true << false << true;
}
void tst_QMetaType::flags()
@@ -618,10 +647,12 @@ void tst_QMetaType::flags()
QFETCH(int, type);
QFETCH(bool, isMovable);
QFETCH(bool, isComplex);
+ QFETCH(bool, isPointerToQObject);
QCOMPARE(bool(QMetaType::typeFlags(type) & QMetaType::NeedsConstruction), isComplex);
QCOMPARE(bool(QMetaType::typeFlags(type) & QMetaType::NeedsDestruction), isComplex);
QCOMPARE(bool(QMetaType::typeFlags(type) & QMetaType::MovableType), isMovable);
+ QCOMPARE(bool(QMetaType::typeFlags(type) & QMetaType::PointerToQObject), isPointerToQObject);
}
void tst_QMetaType::construct_data()
diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
index f8fa92e244..f40b1eae0b 100644
--- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
+++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
@@ -3324,6 +3324,11 @@ void tst_QVariant::colorInteger()
}
class Forward;
+QT_BEGIN_NAMESPACE namespace QtPrivate {
+template <> struct IsPointerToTypeDerivedFromQObject<Forward*> {
+ enum { Value = false };
+};
+} QT_END_NAMESPACE
Q_DECLARE_METATYPE(Forward*);
void tst_QVariant::forwardDeclare()
diff --git a/tests/auto/other/exceptionsafety_objects/tst_exceptionsafety_objects.cpp b/tests/auto/other/exceptionsafety_objects/tst_exceptionsafety_objects.cpp
index 49516b7c9b..65ac276704 100644
--- a/tests/auto/other/exceptionsafety_objects/tst_exceptionsafety_objects.cpp
+++ b/tests/auto/other/exceptionsafety_objects/tst_exceptionsafety_objects.cpp
@@ -99,6 +99,11 @@ struct AbstractTester
Q_DECLARE_METATYPE(AbstractTester *)
typedef void (*TestFunction)(QObject*);
+QT_BEGIN_NAMESPACE namespace QtPrivate {
+template <> struct IsPointerToTypeDerivedFromQObject<TestFunction> {
+ enum { Value = false };
+};
+} QT_END_NAMESPACE
Q_DECLARE_METATYPE(TestFunction)
template <typename T>
diff --git a/tests/benchmarks/corelib/tools/qstring/main.cpp b/tests/benchmarks/corelib/tools/qstring/main.cpp
index be2abe5c51..5ab53e3394 100644
--- a/tests/benchmarks/corelib/tools/qstring/main.cpp
+++ b/tests/benchmarks/corelib/tools/qstring/main.cpp
@@ -1298,6 +1298,11 @@ static int ucstrncmp_ssse3_aligning2(const ushort *a, const ushort *b, int len)
#endif
typedef int (* UcstrncmpFunction)(const ushort *, const ushort *, int);
+QT_BEGIN_NAMESPACE namespace QtPrivate {
+template <> struct IsPointerToTypeDerivedFromQObject<UcstrncmpFunction> {
+ enum { Value = false };
+};
+} QT_END_NAMESPACE
Q_DECLARE_METATYPE(UcstrncmpFunction)
void tst_QString::ucstrncmp_data() const
@@ -1457,6 +1462,11 @@ void tst_QString::fromLatin1() const
}
typedef void (* FromLatin1Function)(ushort *, const char *, int);
+QT_BEGIN_NAMESPACE namespace QtPrivate {
+template <> struct IsPointerToTypeDerivedFromQObject<FromLatin1Function> {
+ enum { Value = false };
+};
+} QT_END_NAMESPACE
Q_DECLARE_METATYPE(FromLatin1Function)
void fromLatin1_regular(ushort *dst, const char *str, int size)
@@ -1907,6 +1917,11 @@ void tst_QString::fromLatin1Alternatives() const
}
typedef int (* FromUtf8Function)(ushort *, const char *, int);
+QT_BEGIN_NAMESPACE namespace QtPrivate {
+template <> struct IsPointerToTypeDerivedFromQObject<FromUtf8Function> {
+ enum { Value = false };
+};
+} QT_END_NAMESPACE
Q_DECLARE_METATYPE(FromUtf8Function)
extern QTextCodec::ConverterState *state;