diff options
Diffstat (limited to 'tests')
3 files changed, 133 insertions, 23 deletions
diff --git a/tests/auto/testlib/selftests/tst_selftests.cpp b/tests/auto/testlib/selftests/tst_selftests.cpp index b737f823c8..e332f01861 100644 --- a/tests/auto/testlib/selftests/tst_selftests.cpp +++ b/tests/auto/testlib/selftests/tst_selftests.cpp @@ -63,7 +63,7 @@ private slots: void cleanup(); private: - void doRunSubTest(QString const& subdir, QStringList const& loggers, QStringList const& arguments); + void doRunSubTest(QString const& subdir, QStringList const& loggers, QStringList const& arguments, bool crashes); QString logName(const QString &logger) const; QList<LoggerSet> allLoggerSets() const; @@ -324,6 +324,7 @@ void tst_Selftests::runSubTest_data() QTest::addColumn<QString>("subdir"); QTest::addColumn<QStringList>("loggers"); QTest::addColumn<QStringList>("arguments"); + QTest::addColumn<bool>("crashes"); QStringList tests = QStringList() // << "alive" // timer dependent @@ -479,11 +480,14 @@ void tst_Selftests::runSubTest_data() continue; } } - + const bool crashes = subtest == QLatin1String("assert") || subtest == QLatin1String("exceptionthrow") + || subtest == QLatin1String("fetchbogus") || subtest == QLatin1String("crashedterminate") + || subtest == QLatin1String("crashes") || subtest == QLatin1String("silent"); QTest::newRow(qPrintable(QString("%1 %2").arg(subtest).arg(loggerSet.name))) << subtest << loggers << arguments + << crashes ; } } @@ -491,30 +495,41 @@ void tst_Selftests::runSubTest_data() #ifndef QT_NO_PROCESS -static void insertEnvironmentVariable(QString const& name, QProcessEnvironment &result) -{ - const QProcessEnvironment systemEnvironment = QProcessEnvironment::systemEnvironment(); - const QString value = systemEnvironment.value(name); - if (!value.isEmpty()) - result.insert(name, value); -} - -static inline QProcessEnvironment processEnvironment() +static QProcessEnvironment processEnvironment() { - QProcessEnvironment result; - insertEnvironmentVariable(QStringLiteral("PATH"), result); - // Preserve DISPLAY for X11 as some tests use Qt GUI. -#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) - insertEnvironmentVariable(QStringLiteral("DISPLAY"), result); -#endif - insertEnvironmentVariable(QStringLiteral("QT_QPA_PLATFORM"), result); + static QProcessEnvironment result; + if (result.isEmpty()) { + const QProcessEnvironment systemEnvironment = QProcessEnvironment::systemEnvironment(); + foreach (const QString &key, systemEnvironment.keys()) { + const bool useVariable = key == QLatin1String("PATH") || key == QLatin1String("QT_QPA_PLATFORM") +#ifdef Q_OS_UNIX + || key == QLatin1String("HOME") || key == QLatin1String("USER") // Required for X11 on openSUSE +# ifndef Q_OS_MAC + || key == QLatin1String("DISPLAY") || key == QLatin1String("XAUTHLOCALHOSTNAME") + || key.startsWith(QLatin1String("XDG_")) +# endif // !Q_OS_MAC +#endif // Q_OS_UNIX #ifdef __COVERAGESCANNER__ - insertEnvironmentVariable(QStringLiteral("QT_TESTCOCOON_ACTIVE"), result); + || key == QLatin1String("QT_TESTCOCOON_ACTIVE") #endif + ; + if (useVariable) + result.insert(key, systemEnvironment.value(key)); + } + } return result; } -void tst_Selftests::doRunSubTest(QString const& subdir, QStringList const& loggers, QStringList const& arguments) +static inline QByteArray msgProcessError(const QString &binary, const QStringList &args, + const QProcessEnvironment &e, const QString &what) +{ + QString result; + QTextStream(&result) <<"Error running " << binary << ' ' << args.join(' ') + << " with environment " << e.toStringList().join(' ') << ": " << what; + return result.toLocal8Bit(); +} + +void tst_Selftests::doRunSubTest(QString const& subdir, QStringList const& loggers, QStringList const& arguments, bool crashes) { #if defined(__GNUC__) && defined(__i386) && defined(Q_OS_LINUX) if (arguments.contains("-callgrind")) { @@ -532,8 +547,14 @@ void tst_Selftests::doRunSubTest(QString const& subdir, QStringList const& logge proc.setProcessEnvironment(environment); const QString path = subdir + QLatin1Char('/') + subdir; proc.start(path, arguments); - QVERIFY2(proc.waitForStarted(), qPrintable(QString::fromLatin1("Cannot start '%1': %2").arg(path, proc.errorString()))); - QVERIFY2(proc.waitForFinished(), qPrintable(proc.errorString())); + QVERIFY2(proc.waitForStarted(), msgProcessError(path, arguments, environment, QStringLiteral("Cannot start: ") + proc.errorString())); + QVERIFY2(proc.waitForFinished(), msgProcessError(path, arguments, environment, QStringLiteral("Timed out: ") + proc.errorString())); + if (!crashes) { + QVERIFY2(proc.exitStatus() == QProcess::NormalExit, + msgProcessError(path, arguments, environment, + QStringLiteral("Crashed: ") + proc.errorString() + + QStringLiteral(": ") + QString::fromLocal8Bit(proc.readAllStandardError()))); + } QList<QByteArray> actualOutputs; for (int i = 0; i < loggers.count(); ++i) { @@ -700,8 +721,9 @@ void tst_Selftests::runSubTest() QFETCH(QString, subdir); QFETCH(QStringList, loggers); QFETCH(QStringList, arguments); + QFETCH(bool, crashes); - doRunSubTest(subdir, loggers, arguments); + doRunSubTest(subdir, loggers, arguments, crashes); #endif // !QT_NO_PROCESS } diff --git a/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp b/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp index 68502f0d8d..060fa51293 100644 --- a/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp +++ b/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp @@ -57,6 +57,8 @@ public: virtual ~tst_QProgressDialog(); private slots: + void autoShow_data(); + void autoShow(); void getSetCheck(); void task198202(); void QTBUG_31046(); @@ -70,6 +72,34 @@ tst_QProgressDialog::~tst_QProgressDialog() { } +void tst_QProgressDialog::autoShow_data() +{ + QTest::addColumn<int>("min"); + QTest::addColumn<int>("max"); + QTest::addColumn<int>("delay"); + QTest::addColumn<bool>("expectedAutoShow"); + + QTest::newRow("50_to_100_long") << 50 << 100 << 100 << true; // 50*100ms = 5s + QTest::newRow("50_to_100_short") << 50 << 1 << 100 << false; // 50*1ms = 50ms + + QTest::newRow("0_to_100_long") << 0 << 100 << 100 << true; // 100*100ms = 10s + QTest::newRow("0_to_10_short") << 0 << 10 << 100 << false; // 10*100ms = 1s +} + +void tst_QProgressDialog::autoShow() +{ + QFETCH(int, min); + QFETCH(int, max); + QFETCH(int, delay); + QFETCH(bool, expectedAutoShow); + + QProgressDialog dlg("", "", min, max); + dlg.setValue(0); + QThread::msleep(delay); + dlg.setValue(min+1); + QCOMPARE(dlg.isVisible(), expectedAutoShow); +} + // Testing get/set functions void tst_QProgressDialog::getSetCheck() { diff --git a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp index 8d75298673..091927abe4 100644 --- a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp +++ b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp @@ -153,6 +153,7 @@ private slots: void focusChanged(); void focusOut(); + void focusMouseClick(); void execAfterExit(); @@ -1771,6 +1772,63 @@ void tst_QApplication::focusOut() QTest::qWait(2000); } +class SpontaneousEvent +{ + Q_GADGET + QDOC_PROPERTY(bool accepted READ isAccepted WRITE setAccepted) + Q_ENUMS(Type) +public: + enum Type { + Void + }; + + virtual ~SpontaneousEvent() {} + + QEventPrivate *d; + ushort t; + + ushort posted : 1; + ushort spont : 1; +}; + +void tst_QApplication::focusMouseClick() +{ + int argc = 1; + QApplication app(argc, &argv0); + + QWidget w; + w.setFocusPolicy(Qt::StrongFocus); + QWidget w2(&w); + w2.setFocusPolicy(Qt::TabFocus); + w.show(); + w.setFocus(); + QTRY_COMPARE(QApplication::focusWidget(), &w); + + // front most widget has Qt::TabFocus, parent widget accepts clicks as well + // now send a mouse button press event and check what happens with the focus + // it should be given to the parent widget + QMouseEvent ev(QEvent::MouseButtonPress, QPointF(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); + reinterpret_cast<SpontaneousEvent *>(&ev)->spont = 1; + QVERIFY(ev.spontaneous()); + qApp->notify(&w2, &ev); + QCOMPARE(QApplication::focusWidget(), &w); + + // then we give the inner widget strong focus -> it should get focus + w2.setFocusPolicy(Qt::StrongFocus); + reinterpret_cast<SpontaneousEvent *>(&ev)->spont = 1; + QVERIFY(ev.spontaneous()); + qApp->notify(&w2, &ev); + QTRY_COMPARE(QApplication::focusWidget(), &w2); + + // now back to tab focus and click again (it already had focus) -> focus should stay + // (focus was revoked as of QTBUG-34042) + w2.setFocusPolicy(Qt::TabFocus); + reinterpret_cast<SpontaneousEvent *>(&ev)->spont = 1; + QVERIFY(ev.spontaneous()); + qApp->notify(&w2, &ev); + QCOMPARE(QApplication::focusWidget(), &w2); +} + void tst_QApplication::execAfterExit() { int argc = 1; |