summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJędrzej Nowacki <jedrzej.nowacki@nokia.com>2012-03-13 14:15:53 +0100
committerQt by Nokia <qt-info@nokia.com>2012-03-14 09:45:07 +0100
commit22494ea8e82d5d5588e67e8067f0273687ed9098 (patch)
treef0b7a4f6d498ba8e109677756183ff371f5f9171 /tests
parente92ceba13d751c151604726c3fa67ff4c918629f (diff)
Unify QMetaType::TypeFlags detection.
Duplicated code was removed. As an side effect: - one runtime flag check was replaced by a compile time check. - is enum flag can be used together with built-in types. Change-Id: I54173e7b07ce7e487d3cc21ba24dcccd28b5d049 Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp48
1 files changed, 29 insertions, 19 deletions
diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
index bc5fa2716b..a3959f6d33 100644
--- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
+++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
@@ -717,39 +717,47 @@ Q_DECLARE_METATYPE(QPairPC)
Q_DECLARE_METATYPE(QPairPM)
Q_DECLARE_METATYPE(QPairPP)
+enum FlagsDataEnum {};
+Q_DECLARE_METATYPE(FlagsDataEnum);
+
void tst_QMetaType::flags_data()
{
QTest::addColumn<int>("type");
QTest::addColumn<bool>("isMovable");
QTest::addColumn<bool>("isComplex");
QTest::addColumn<bool>("isPointerToQObject");
+ QTest::addColumn<bool>("isEnum");
#define ADD_METATYPE_TEST_ROW(MetaTypeName, MetaTypeId, RealType) \
- QTest::newRow(#RealType) << MetaTypeId << bool(!QTypeInfo<RealType>::isStatic) << bool(QTypeInfo<RealType>::isComplex) << bool(QtPrivate::IsPointerToTypeDerivedFromQObject<RealType>::Value);
+ QTest::newRow(#RealType) << MetaTypeId \
+ << bool(!QTypeInfo<RealType>::isStatic) \
+ << bool(QTypeInfo<RealType>::isComplex) \
+ << bool(QtPrivate::IsPointerToTypeDerivedFromQObject<RealType>::Value) \
+ << bool(Q_IS_ENUM(RealType));
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 << 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;
- QTest::newRow("QPair<C,C>") << ::qMetaTypeId<QPair<C,C> >() << false << true << false;
- QTest::newRow("QPair<C,M>") << ::qMetaTypeId<QPair<C,M> >() << false << true << false;
- QTest::newRow("QPair<C,P>") << ::qMetaTypeId<QPair<C,P> >() << false << true << false;
- QTest::newRow("QPair<M,C>") << ::qMetaTypeId<QPair<M,C> >() << false << true << false;
- QTest::newRow("QPair<M,M>") << ::qMetaTypeId<QPair<M,M> >() << true << true << false;
- QTest::newRow("QPair<M,P>") << ::qMetaTypeId<QPair<M,P> >() << true << true << false;
- QTest::newRow("QPair<P,C>") << ::qMetaTypeId<QPair<P,C> >() << false << true << false;
- QTest::newRow("QPair<P,M>") << ::qMetaTypeId<QPair<P,M> >() << true << true << false;
- QTest::newRow("QPair<P,P>") << ::qMetaTypeId<QPair<P,P> >() << true << false << false;
+ QTest::newRow("TestSpace::Foo") << ::qMetaTypeId<TestSpace::Foo>() << false << true << false << false;
+ QTest::newRow("Whity<double>") << ::qMetaTypeId<Whity<double> >() << false << true << false << false;
+ QTest::newRow("CustomMovable") << ::qMetaTypeId<CustomMovable>() << true << true << false << false;
+ QTest::newRow("CustomObject*") << ::qMetaTypeId<CustomObject*>() << true << false << true << false;
+ QTest::newRow("CustomMultiInheritanceObject*") << ::qMetaTypeId<CustomMultiInheritanceObject*>() << true << false << true << false;
+ QTest::newRow("QPair<C,C>") << ::qMetaTypeId<QPair<C,C> >() << false << true << false << false;
+ QTest::newRow("QPair<C,M>") << ::qMetaTypeId<QPair<C,M> >() << false << true << false << false;
+ QTest::newRow("QPair<C,P>") << ::qMetaTypeId<QPair<C,P> >() << false << true << false << false;
+ QTest::newRow("QPair<M,C>") << ::qMetaTypeId<QPair<M,C> >() << false << true << false << false;
+ QTest::newRow("QPair<M,M>") << ::qMetaTypeId<QPair<M,M> >() << true << true << false << false;
+ QTest::newRow("QPair<M,P>") << ::qMetaTypeId<QPair<M,P> >() << true << true << false << false;
+ QTest::newRow("QPair<P,C>") << ::qMetaTypeId<QPair<P,C> >() << false << true << false << false;
+ QTest::newRow("QPair<P,M>") << ::qMetaTypeId<QPair<P,M> >() << true << true << false << false;
+ QTest::newRow("QPair<P,P>") << ::qMetaTypeId<QPair<P,P> >() << true << false << false << false;
+ QTest::newRow("FlagsDataEnum") << ::qMetaTypeId<FlagsDataEnum>() << false << true << false << true;
// invalid ids.
- QTest::newRow("-1") << -1 << false << false << false;
- QTest::newRow("-124125534") << -124125534 << false << false << false;
- QTest::newRow("124125534") << 124125534 << false << false << false;
-
+ QTest::newRow("-1") << -1 << false << false << false << false;
+ QTest::newRow("-124125534") << -124125534 << false << false << false << false;
+ QTest::newRow("124125534") << 124125534 << false << false << false << false;
}
void tst_QMetaType::flags()
@@ -758,11 +766,13 @@ void tst_QMetaType::flags()
QFETCH(bool, isMovable);
QFETCH(bool, isComplex);
QFETCH(bool, isPointerToQObject);
+ QFETCH(bool, isEnum);
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);
+ QCOMPARE(bool(QMetaType::typeFlags(type) & QMetaType::IsEnumeration), isEnum);
}
void tst_QMetaType::flagsStaticLess_data()