diff options
Diffstat (limited to 'tests/auto/corelib/kernel')
-rw-r--r-- | tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp | 67 | ||||
-rw-r--r-- | tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp | 29 | ||||
-rw-r--r-- | tests/auto/corelib/kernel/qsignalmapper/tst_qsignalmapper.cpp | 14 | ||||
-rw-r--r-- | tests/auto/corelib/kernel/qtranslator/hellotr_la.qm | bin | 230 -> 237 bytes | |||
-rw-r--r-- | tests/auto/corelib/kernel/qtranslator/tst_qtranslator.cpp | 15 |
5 files changed, 115 insertions, 10 deletions
diff --git a/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp b/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp index 49c10c6a24..025106a81f 100644 --- a/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp +++ b/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp @@ -67,6 +67,7 @@ private slots: void sendPostedEvents_data(); void sendPostedEvents(); void processEventsOnlySendsQueuedEvents(); + void eventLoopExit(); }; bool tst_QEventDispatcher::event(QEvent *e) @@ -205,10 +206,26 @@ void tst_QEventDispatcher::registerTimer() QVERIFY(timers.foundCoarse()); QVERIFY(timers.foundVeryCoarse()); +#ifdef Q_OS_DARWIN + /* + We frequently experience flaky failures on macOS. Assumption is that this is + due to undeterministic VM scheduling, making us process events for significantly + longer than expected and resulting in timers firing in undefined order. + To detect this condition, we use a QElapsedTimer, and skip the test. + */ + QElapsedTimer elapsedTimer; + elapsedTimer.start(); +#endif + // process events, waiting for the next event... this should only fire the precise timer receivedEventType = -1; timerIdFromEvent = -1; QTRY_COMPARE_WITH_TIMEOUT(receivedEventType, int(QEvent::Timer), PreciseTimerInterval * 2); +#ifdef Q_OS_DARWIN + if (timerIdFromEvent != timers.preciseTimerId() + && elapsedTimer.elapsed() > PreciseTimerInterval * 3) + QSKIP("Ignore flaky test behavior due to VM scheduling on macOS"); +#endif QCOMPARE(timerIdFromEvent, timers.preciseTimerId()); // now unregister it and make sure it's gone timers.unregister(timers.preciseTimerId()); @@ -223,6 +240,12 @@ void tst_QEventDispatcher::registerTimer() receivedEventType = -1; timerIdFromEvent = -1; QTRY_COMPARE_WITH_TIMEOUT(receivedEventType, int(QEvent::Timer), CoarseTimerInterval * 2); +#ifdef Q_OS_DARWIN + if (timerIdFromEvent != timers.coarseTimerId() + && elapsedTimer.elapsed() > CoarseTimerInterval * 3) + QSKIP("Ignore flaky test behavior due to VM scheduling on macOS"); +#endif + QCOMPARE(timerIdFromEvent, timers.coarseTimerId()); // now unregister it and make sure it's gone timers.unregister(timers.coarseTimerId()); @@ -314,5 +337,49 @@ void tst_QEventDispatcher::processEventsOnlySendsQueuedEvents() QCOMPARE(object.eventsReceived, 4); } +void tst_QEventDispatcher::eventLoopExit() +{ + // This test was inspired by QTBUG-79477. A particular + // implementation detail in QCocoaEventDispatcher allowed + // QEventLoop::exit() to fail to really exit the event loop. + // Thus this test is a part of the dispatcher auto-test. + + // Imitates QApplication::exec(): + QEventLoop mainLoop; + // The test itself is a lambda: + QTimer::singleShot(0, [&mainLoop]() { + // Two more single shots, both will be posted as events + // (zero timeout) and supposed to be processes by the + // mainLoop: + + QTimer::singleShot(0, [&mainLoop]() { + // wakeUp triggers QCocoaEventDispatcher into incrementing + // its 'serialNumber': + mainLoop.wakeUp(); + // QCocoaEventDispatcher::processEvents() will process + // posted events and execute the second lambda defined below: + QCoreApplication::processEvents(); + }); + + QTimer::singleShot(0, [&mainLoop]() { + // With QCocoaEventDispatcher this is executed while in the + // processEvents (see above) and would fail to actually + // interrupt the loop. + mainLoop.exit(); + }); + }); + + bool timeoutObserved = false; + QTimer::singleShot(500, [&timeoutObserved, &mainLoop]() { + // In case the QEventLoop::exit above failed, we have to bail out + // early, not wasting time: + mainLoop.exit(); + timeoutObserved = true; + }); + + mainLoop.exec(); + QVERIFY(!timeoutObserved); +} + QTEST_MAIN(tst_QEventDispatcher) #include "tst_qeventdispatcher.moc" diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp index 12c29a6e13..19b3289390 100644 --- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp @@ -125,6 +125,7 @@ private slots: void compareCustomEqualOnlyType(); void customDebugStream(); void unknownType(); + void fromType(); }; struct BaseGenericType @@ -482,6 +483,7 @@ void tst_QMetaType::id() { QCOMPARE(QMetaType(QMetaType::QString).id(), QMetaType::QString); QCOMPARE(QMetaType(::qMetaTypeId<TestSpace::Foo>()).id(), ::qMetaTypeId<TestSpace::Foo>()); + QCOMPARE(QMetaType::fromType<TestSpace::Foo>().id(), ::qMetaTypeId<TestSpace::Foo>()); } void tst_QMetaType::qMetaTypeId() @@ -600,6 +602,12 @@ void tst_QMetaType::typeName() QCOMPARE(name, aTypeName); QCOMPARE(name.toLatin1(), QMetaObject::normalizedType(name.toLatin1().constData())); QCOMPARE(rawname == nullptr, aTypeName.isNull()); + + QMetaType mt(aType); + if (mt.isValid()) { // Gui type are not valid + QCOMPARE(QString::fromLatin1(QMetaType(aType).name()), aTypeName); + } + } void tst_QMetaType::type_data() @@ -1728,6 +1736,7 @@ void tst_QMetaType::automaticTemplateRegistration() const int type = QMetaType::type(tn); \ const int expectedType = ::qMetaTypeId<CONTAINER< __VA_ARGS__ > >(); \ QCOMPARE(type, expectedType); \ + QCOMPARE((QMetaType::fromType<CONTAINER< __VA_ARGS__ >>().id()), expectedType); \ } #define FOR_EACH_1ARG_TEMPLATE_TYPE(F, TYPE) \ @@ -2572,6 +2581,26 @@ void tst_QMetaType::unknownType() invalid.construct(&buffer); QCOMPARE(buffer, 0xBAD); } + +void tst_QMetaType::fromType() +{ + #define FROMTYPE_CHECK(MetaTypeName, MetaTypeId, RealType) \ + QCOMPARE(QMetaType::fromType<RealType>(), QMetaType(MetaTypeId)); \ + QVERIFY(QMetaType::fromType<RealType>() == QMetaType(MetaTypeId)); \ + QVERIFY(!(QMetaType::fromType<RealType>() != QMetaType(MetaTypeId))); \ + QCOMPARE(QMetaType::fromType<RealType>().id(), MetaTypeId); + + FOR_EACH_CORE_METATYPE(FROMTYPE_CHECK) + + QVERIFY(QMetaType::fromType<QString>() != QMetaType()); + QCOMPARE(QMetaType(), QMetaType()); + QCOMPARE(QMetaType(QMetaType::UnknownType), QMetaType()); + + FROMTYPE_CHECK(_, ::qMetaTypeId<Whity<int>>(), Whity<int>) + #undef FROMTYPE_CHECK +} + + // Compile-time test, it should be possible to register function pointer types class Undefined; diff --git a/tests/auto/corelib/kernel/qsignalmapper/tst_qsignalmapper.cpp b/tests/auto/corelib/kernel/qsignalmapper/tst_qsignalmapper.cpp index c03e3e8e9f..78b0b5dc55 100644 --- a/tests/auto/corelib/kernel/qsignalmapper/tst_qsignalmapper.cpp +++ b/tests/auto/corelib/kernel/qsignalmapper/tst_qsignalmapper.cpp @@ -41,8 +41,8 @@ class QtTestObject : public QObject { Q_OBJECT public slots: - void myslot(int id); - void myslot(const QString &str); + void myIntSlot(int id); + void myStringSlot(const QString &str); signals: void mysignal(int); @@ -54,12 +54,12 @@ public: QString str; }; -void QtTestObject::myslot(int id) +void QtTestObject::myIntSlot(int id) { this->id = id; } -void QtTestObject::myslot(const QString &str) +void QtTestObject::myStringSlot(const QString &str) { this->str = str; } @@ -71,7 +71,7 @@ void QtTestObject::emit_mysignal(int value) void tst_QSignalMapper::mapped() { - QSignalMapper mapper(0); + QSignalMapper mapper; QtTestObject target; QtTestObject src1; @@ -88,8 +88,8 @@ void tst_QSignalMapper::mapped() mapper.setMapping(&src2, "two"); mapper.setMapping(&src3, "three"); - connect(&mapper, SIGNAL(mapped(int)), &target, SLOT(myslot(int))); - connect(&mapper, SIGNAL(mapped(QString)), &target, SLOT(myslot(QString))); + connect(&mapper, &QSignalMapper::mappedInt, &target, &QtTestObject::myIntSlot); + connect(&mapper, &QSignalMapper::mappedString, &target, &QtTestObject::myStringSlot); src1.emit_mysignal(20); QCOMPARE(target.id, 1); diff --git a/tests/auto/corelib/kernel/qtranslator/hellotr_la.qm b/tests/auto/corelib/kernel/qtranslator/hellotr_la.qm Binary files differindex cc42afe05c..25c0aad583 100644 --- a/tests/auto/corelib/kernel/qtranslator/hellotr_la.qm +++ b/tests/auto/corelib/kernel/qtranslator/hellotr_la.qm diff --git a/tests/auto/corelib/kernel/qtranslator/tst_qtranslator.cpp b/tests/auto/corelib/kernel/qtranslator/tst_qtranslator.cpp index b3efa97dbd..9fde7da816 100644 --- a/tests/auto/corelib/kernel/qtranslator/tst_qtranslator.cpp +++ b/tests/auto/corelib/kernel/qtranslator/tst_qtranslator.cpp @@ -110,9 +110,10 @@ void tst_QTranslator::load_data() QTest::addColumn<QString>("filepath"); QTest::addColumn<bool>("isEmpty"); QTest::addColumn<QString>("translation"); + QTest::addColumn<QString>("language"); - QTest::newRow("hellotr_la") << "hellotr_la.qm" << false << "Hallo Welt!"; - QTest::newRow("hellotr_empty") << "hellotr_empty.qm" << true << ""; + QTest::newRow("hellotr_la") << "hellotr_la.qm" << false << "Hallo Welt!" << "de"; + QTest::newRow("hellotr_empty") << "hellotr_empty.qm" << true << "" << ""; } void tst_QTranslator::load() @@ -120,12 +121,15 @@ void tst_QTranslator::load() QFETCH(QString, filepath); QFETCH(bool, isEmpty); QFETCH(QString, translation); + QFETCH(QString, language); { QTranslator tor; QVERIFY(tor.load(QFileInfo(filepath).baseName())); QCOMPARE(tor.isEmpty(), isEmpty); QCOMPARE(tor.translate("QPushButton", "Hello world!"), translation); + QCOMPARE(tor.filePath(), filepath); + QCOMPARE(tor.language(), language); } { @@ -136,13 +140,18 @@ void tst_QTranslator::load() QVERIFY(tor.load((const uchar *)data.constData(), data.length())); QCOMPARE(tor.isEmpty(), isEmpty); QCOMPARE(tor.translate("QPushButton", "Hello world!"), translation); + QCOMPARE(tor.filePath(), ""); + QCOMPARE(tor.language(), language); } { QTranslator tor; - QVERIFY(tor.load(QString(":/tst_qtranslator/%1").arg(filepath))); + QString path = QString(":/tst_qtranslator/%1").arg(filepath); + QVERIFY(tor.load(path)); QCOMPARE(tor.isEmpty(), isEmpty); QCOMPARE(tor.translate("QPushButton", "Hello world!"), translation); + QCOMPARE(tor.filePath(), path); + QCOMPARE(tor.language(), language); } } |