diff options
author | Frederik Gladhorn <frederik.gladhorn@digia.com> | 2013-11-26 22:30:27 +0100 |
---|---|---|
committer | Frederik Gladhorn <frederik.gladhorn@digia.com> | 2013-11-26 22:35:48 +0100 |
commit | 4a8273a6fc2e741e811cf5dabc9a3c240306cf7f (patch) | |
tree | 2148abc88f8543eecdc0b97b2dd92594836af9b2 /tests/auto/corelib/kernel | |
parent | 036c5db468164297d213764c59a4b59daa76d90a (diff) | |
parent | 1c2be58fecaff1de5f2849192eb712984ebd59bd (diff) |
Merge remote-tracking branch 'origin/stable' into dev
For the conflicts in msvc_nmake.cpp the ifdefs are extended since we
need to support windows phone in the target branch while it is not there
in the current stable branch (as of Qt 5.2).
Conflicts:
configure
qmake/generators/win32/msvc_nmake.cpp
src/3rdparty/angle/src/libEGL/Surface.cpp
src/angle/src/common/common.pri
src/corelib/global/qglobal.h
src/corelib/io/qstandardpaths.cpp
src/plugins/platforms/qnx/qqnxintegration.cpp
src/plugins/platforms/qnx/qqnxscreeneventhandler.h
src/plugins/platforms/xcb/qglxintegration.h
src/widgets/kernel/win.pri
tests/auto/corelib/thread/qreadwritelock/tst_qreadwritelock.cpp
tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp
tools/configure/configureapp.cpp
Change-Id: I00b579eefebaf61d26ab9b00046d2b5bd5958812
Diffstat (limited to 'tests/auto/corelib/kernel')
4 files changed, 246 insertions, 3 deletions
diff --git a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp index 870e65f0cc..3afc2bc574 100644 --- a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp +++ b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp @@ -155,6 +155,7 @@ private slots: void invokeCustomTypes(); void invokeMetaConstructor(); void invokeTypedefTypes(); + void invokeException(); void qtMetaObjectInheritance(); void normalizedSignature_data(); void normalizedSignature(); @@ -301,6 +302,19 @@ void tst_QMetaObject::connectSlotsByName() struct MyUnregisteredType { }; +static int countedStructObjectsCount = 0; +struct CountedStruct +{ + CountedStruct() { ++countedStructObjectsCount; } + CountedStruct(const CountedStruct &) { ++countedStructObjectsCount; } + CountedStruct &operator=(const CountedStruct &) { return *this; } + ~CountedStruct() { --countedStructObjectsCount; } +}; + +#ifndef QT_NO_EXCEPTIONS +class ObjectException : public std::exception { }; +#endif + class QtTestObject: public QObject { friend class tst_QMetaObject; @@ -340,6 +354,13 @@ public slots: void slotWithUnregisteredParameterType(MyUnregisteredType); + CountedStruct throwingSlot(const CountedStruct &, CountedStruct s2) { +#ifndef QT_NO_EXCEPTIONS + throw ObjectException(); +#endif + return s2; + } + signals: void sig0(); QString sig1(QString s1); @@ -847,6 +868,23 @@ void tst_QMetaObject::invokeTypedefTypes() QCOMPARE(spy.at(0).at(0), QVariant(arg)); } +void tst_QMetaObject::invokeException() +{ +#ifndef QT_NO_EXCEPTIONS + QtTestObject obj; + QCOMPARE(countedStructObjectsCount, 0); + try { + CountedStruct s; + QVERIFY(QMetaObject::invokeMethod(&obj, "throwingSlot", Q_RETURN_ARG(CountedStruct, s), + Q_ARG(CountedStruct, s), Q_ARG(CountedStruct, s))); + QFAIL("Did not throw"); + } catch(ObjectException &) {} + QCOMPARE(countedStructObjectsCount, 0); +#else + QSKIP("Needs exceptions"); +#endif +} + void tst_QMetaObject::normalizedSignature_data() { QTest::addColumn<QString>("signature"); diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp index f429500077..e4804e6079 100644 --- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp +++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp @@ -152,6 +152,7 @@ private slots: void contextDoesNotLeakFunctor(); void connectBase(); void qmlConnect(); + void exceptions(); }; struct QObjectCreatedOnShutdown @@ -6185,6 +6186,102 @@ void tst_QObject::qmlConnect() #endif } +#ifndef QT_NO_EXCEPTIONS +class ObjectException : public std::exception { }; + +struct ThrowFunctor +{ + CountedStruct operator()(const CountedStruct &, CountedStruct s2) const + { + throw ObjectException(); + return s2; + } + CountedStruct s; +}; +#endif + +class ExceptionThrower : public QObject +{ + Q_OBJECT +public slots: + CountedStruct throwException(const CountedStruct &, CountedStruct s2) + { +#ifndef QT_NO_EXCEPTIONS + throw ObjectException(); +#endif + return s2; + } +signals: + CountedStruct mySignal(const CountedStruct &s1, CountedStruct s2); +}; + +void tst_QObject::exceptions() +{ +#ifndef QT_NO_EXCEPTIONS + ReceiverObject receiver; + + // String based syntax + { + QCOMPARE(countedStructObjectsCount, 0); + ExceptionThrower thrower; + receiver.reset(); + + connect(&thrower, SIGNAL(mySignal(CountedStruct,CountedStruct)), &receiver, SLOT(slot1())); + connect(&thrower, SIGNAL(mySignal(CountedStruct,CountedStruct)), &thrower, SLOT(throwException(CountedStruct,CountedStruct))); + connect(&thrower, SIGNAL(mySignal(CountedStruct,CountedStruct)), &receiver, SLOT(slot2())); + try { + CountedStruct s; + emit thrower.mySignal(s, s); + QFAIL("Exception not thrown?"); + } catch (ObjectException&) {} + QCOMPARE(receiver.count_slot1, 1); + QCOMPARE(receiver.count_slot2, 0); + QCOMPARE(countedStructObjectsCount, 0); + } + // Pointer to member function + { + QCOMPARE(countedStructObjectsCount, 0); + ExceptionThrower thrower; + receiver.reset(); + + connect(&thrower, &ExceptionThrower::mySignal, &receiver, &ReceiverObject::slot1); + connect(&thrower, &ExceptionThrower::mySignal, &thrower, &ExceptionThrower::throwException); + connect(&thrower, &ExceptionThrower::mySignal, &receiver, &ReceiverObject::slot2); + try { + CountedStruct s; + emit thrower.mySignal(s, s); + QFAIL("Exception not thrown?"); + } catch (ObjectException&) {} + QCOMPARE(receiver.count_slot1, 1); + QCOMPARE(receiver.count_slot2, 0); + QCOMPARE(countedStructObjectsCount, 0); + } + // Functor + { + QCOMPARE(countedStructObjectsCount, 0); + ExceptionThrower thrower; + receiver.reset(); + + connect(&thrower, &ExceptionThrower::mySignal, &receiver, &ReceiverObject::slot1); + connect(&thrower, &ExceptionThrower::mySignal, ThrowFunctor()); + connect(&thrower, &ExceptionThrower::mySignal, &receiver, &ReceiverObject::slot2); + try { + CountedStruct s; + emit thrower.mySignal(s, s); + QFAIL("Exception not thrown?"); + } catch (ObjectException&) {} + QCOMPARE(receiver.count_slot1, 1); + QCOMPARE(receiver.count_slot2, 0); + QCOMPARE(countedStructObjectsCount, 1); // the Functor + } + QCOMPARE(countedStructObjectsCount, 0); + + +#else + QSKIP("Needs exceptions"); +#endif +} + // Test for QtPrivate::HasQ_OBJECT_Macro Q_STATIC_ASSERT(QtPrivate::HasQ_OBJECT_Macro<tst_QObject>::Value); Q_STATIC_ASSERT(!QtPrivate::HasQ_OBJECT_Macro<SiblingDeleter>::Value); diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp index 422bd63163..aef79e0c2f 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -247,6 +247,8 @@ private slots: void iterateContainerElements(); void pairElements(); + + void enums(); private: void dataStream_data(QDataStream::Version version); void loadQVariantFromDataStream(QDataStream::Version version); @@ -888,6 +890,17 @@ void tst_QVariant::toLongLong_data() bytearray[3] = '0'; QTest::newRow( "QByteArray" ) << QVariant( bytearray ) << (qlonglong) 3200 << true; QTest::newRow("QJsonValue") << QVariant(QJsonValue(321)) << (qlonglong)321 << true; + + qint64 value64 = (Q_INT64_C(12) << 35) + 8; + QTest::newRow("qint64") << QVariant::fromValue(value64) << qlonglong(value64) << true; + QTest::newRow("-qint64") << QVariant::fromValue(-value64) << qlonglong(-value64) << true; + QTest::newRow("long") << QVariant::fromValue(long(464646)) << qlonglong(464646) << true; + QTest::newRow("LONG_MAX") << QVariant::fromValue( LONG_MAX ) << qlonglong(LONG_MAX) << true; + QTest::newRow("LONG_MIN") << QVariant::fromValue( LONG_MIN ) << qlonglong(LONG_MIN) << true; + + QTest::newRow( "short" ) << QVariant(short(12)) << qlonglong(12) << true; + QTest::newRow( "-short" ) << QVariant(short(-24)) << qlonglong(-24) << true; + QTest::newRow( "ushort" ) << QVariant(ushort(15)) << qlonglong(15) << true; } void tst_QVariant::toLongLong() @@ -933,6 +946,15 @@ void tst_QVariant::toULongLong_data() bytearray[3] = '1'; QTest::newRow( "QByteArray" ) << QVariant( bytearray ) << (qulonglong) 3201 << true; QTest::newRow("QJsonValue") << QVariant(QJsonValue(321)) << (qulonglong)321 << true; + + quint64 value64 = (Q_INT64_C(12) << 35) + 8; + QTest::newRow("qint64") << QVariant::fromValue(value64) << qulonglong(value64) << true; + QTest::newRow("long") << QVariant::fromValue(long(464646)) << qulonglong(464646) << true; + QTest::newRow("LONG_MAX") << QVariant::fromValue( LONG_MAX ) << qulonglong(LONG_MAX) << true; + QTest::newRow("ULONG_MAX") << QVariant::fromValue( ULONG_MAX ) << qulonglong(ULONG_MAX) << true; + QTest::newRow( "short" ) << QVariant(short(12)) << qulonglong(12) << true; + QTest::newRow( "-short" ) << QVariant(short(-24)) << qulonglong(-24) << true; + QTest::newRow( "ushort" ) << QVariant(ushort(15)) << qulonglong(15) << true; } void tst_QVariant::toULongLong() @@ -2895,24 +2917,27 @@ void tst_QVariant::numericalConvert() QVariant vuint(uint(5)); QVariant vshort(short(5)); QVariant vlonglong(quint64(5)); + QVariant vlong = QVariant::fromValue(long(5)); QVariant vstringint(QString::fromLatin1("5")); QVariant vstring(QString::fromLatin1("5.3")); QVector<QVariant *> vect; - vect << &vfloat << &vdouble << &vreal << &vint << &vuint << &vshort<< &vlonglong << &vstringint << &vstring; + vect << &vfloat << &vdouble << &vreal << &vint << &vuint << &vshort<< &vlonglong << &vlong << &vstringint << &vstring; for(int i = 0; i < vect.size(); i++) { double num = 5.3; - if (i >= 3 && i <= 7) + if (i >= 3 && i <= 8) num = 5; QVariant *v = vect.at(i); QCOMPARE(v->toFloat() , float(num)); QCOMPARE(float(v->toReal()) , float(num)); QCOMPARE(float(v->toDouble()) , float(num)); - if(i != 8) { + if (i != 9) { QCOMPARE(v->toInt() , int(num)); QCOMPARE(v->toUInt() , uint(num)); QCOMPARE(v->toULongLong() , quint64(num)); + QCOMPARE(v->value<ulong>() , ulong(num)); + QCOMPARE(v->value<ushort>() , ushort(num)); } QCOMPARE(v->toString() , QString::number(num)); } @@ -3930,5 +3955,87 @@ void tst_QVariant::pairElements() TEST_PAIR_ELEMENT_ACCESS(std::pair, int, QVariant, 44, 15) } +enum EnumTest_Enum0 { EnumTest_Enum0_value = 42, ensureSignedEnum0 = -1 }; +Q_DECLARE_METATYPE(EnumTest_Enum0) +enum EnumTest_Enum1 { EnumTest_Enum1_value = 42, EnumTest_Enum1_bigValue = (Q_INT64_C(1) << 33) + 50 }; +Q_DECLARE_METATYPE(EnumTest_Enum1) + +#if defined(Q_COMPILER_CLASS_ENUM) +enum EnumTest_Enum3 : qint64 { EnumTest_Enum3_value = -47, EnumTest_Enum3_bigValue = (Q_INT64_C(1) << 56) + 5 }; +Q_DECLARE_METATYPE(EnumTest_Enum3) +enum EnumTest_Enum4 : quint64 { EnumTest_Enum4_value = 47, EnumTest_Enum4_bigValue = (Q_INT64_C(1) << 52) + 45 }; +Q_DECLARE_METATYPE(EnumTest_Enum4) +enum EnumTest_Enum5 : uint { EnumTest_Enum5_value = 47 }; +Q_DECLARE_METATYPE(EnumTest_Enum5) +enum EnumTest_Enum6 : uchar { EnumTest_Enum6_value = 47 }; +Q_DECLARE_METATYPE(EnumTest_Enum6) +enum class EnumTest_Enum7 { EnumTest_Enum7_value = 47, ensureSignedEnum7 = -1 }; +Q_DECLARE_METATYPE(EnumTest_Enum7) +enum EnumTest_Enum8 : short { EnumTest_Enum8_value = 47 }; +Q_DECLARE_METATYPE(EnumTest_Enum8) +#endif + +template<typename Enum> void testVariant(Enum value, bool *ok) +{ + *ok = false; + QVariant var = QVariant::fromValue(value); + + QCOMPARE(var.userType(), qMetaTypeId<Enum>()); + + QVERIFY(var.canConvert<Enum>()); + QVERIFY(var.canConvert<int>()); + QVERIFY(var.canConvert<unsigned int>()); + QVERIFY(var.canConvert<short>()); + QVERIFY(var.canConvert<unsigned short>()); + QVERIFY(var.canConvert<qint64>()); + QVERIFY(var.canConvert<quint64>()); + + + QCOMPARE(var.value<Enum>(), value); + QCOMPARE(var.value<int>(), static_cast<int>(value)); + QCOMPARE(var.value<uint>(), static_cast<uint>(value)); + QCOMPARE(var.value<short>(), static_cast<short>(value)); + QCOMPARE(var.value<unsigned short>(), static_cast<unsigned short>(value)); + QCOMPARE(var.value<qint64>(), static_cast<qint64>(value)); + QCOMPARE(var.value<quint64>(), static_cast<quint64>(value)); + + QVariant var2 = var; + QVERIFY(var2.convert(QMetaType::Int)); + QCOMPARE(var2.value<int>(), static_cast<int>(value)); + + *ok = true; +} + +void tst_QVariant::enums() +{ + bool ok = false; + testVariant(EnumTest_Enum0_value, &ok); + QVERIFY(ok); + testVariant(EnumTest_Enum1_value, &ok); + QVERIFY(ok); + testVariant(EnumTest_Enum1_bigValue, &ok); + QVERIFY(ok); +#if defined(Q_COMPILER_CLASS_ENUM) + testVariant(EnumTest_Enum3::EnumTest_Enum3_value, &ok); + QVERIFY(ok); + testVariant(EnumTest_Enum3::EnumTest_Enum3_bigValue, &ok); + QVERIFY(ok); + testVariant(EnumTest_Enum4::EnumTest_Enum4_value, &ok); + QVERIFY(ok); + testVariant(EnumTest_Enum4::EnumTest_Enum4_bigValue, &ok); + QVERIFY(ok); + testVariant(EnumTest_Enum5::EnumTest_Enum5_value, &ok); + QVERIFY(ok); + testVariant(EnumTest_Enum6::EnumTest_Enum6_value, &ok); + QVERIFY(ok); + testVariant(EnumTest_Enum7::EnumTest_Enum7_value, &ok); + QVERIFY(ok); + testVariant(EnumTest_Enum8::EnumTest_Enum8_value, &ok); + QVERIFY(ok); + testVariant(EnumTest_Enum3::EnumTest_Enum3_value, &ok); + QVERIFY(ok); +#endif +} + QTEST_MAIN(tst_QVariant) #include "tst_qvariant.moc" diff --git a/tests/auto/corelib/kernel/qwineventnotifier/tst_qwineventnotifier.cpp b/tests/auto/corelib/kernel/qwineventnotifier/tst_qwineventnotifier.cpp index 8a0ff162c6..952cb031b8 100644 --- a/tests/auto/corelib/kernel/qwineventnotifier/tst_qwineventnotifier.cpp +++ b/tests/auto/corelib/kernel/qwineventnotifier/tst_qwineventnotifier.cpp @@ -42,6 +42,7 @@ #include <QtTest/QtTest> #include <qwineventnotifier.h> #include <qtimer.h> +#include <qt_windows.h> class tst_QWinEventNotifier : public QObject { |