summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp4
-rw-r--r--tests/auto/widgets/widgets/qbuttongroup/tst_qbuttongroup.cpp68
-rw-r--r--tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp116
3 files changed, 186 insertions, 2 deletions
diff --git a/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp b/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp
index 2a9c1e1e41..898ac86874 100644
--- a/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp
+++ b/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp
@@ -428,9 +428,9 @@ void tst_QEasingCurve::setCustomType()
QCOMPARE(curve.valueForProgress(0.15), 0.1);
QCOMPARE(curve.valueForProgress(0.20), 0.2);
QCOMPARE(curve.valueForProgress(0.25), 0.2);
- // QTBUG-69947, MinGW 7.3 returns 0.2
+ // QTBUG-69947, MinGW 7.3, 8.1 x86 returns 0.2
#if defined(Q_CC_MINGW)
-#if !defined(__GNUC__) || __GNUC__ != 7 || __GNUC_MINOR__ < 3
+#if !defined(__GNUC__) || defined(__MINGW64__)
QCOMPARE(curve.valueForProgress(0.30), 0.3);
#endif
#endif
diff --git a/tests/auto/widgets/widgets/qbuttongroup/tst_qbuttongroup.cpp b/tests/auto/widgets/widgets/qbuttongroup/tst_qbuttongroup.cpp
index 279fe49e3a..3b8bcf98c3 100644
--- a/tests/auto/widgets/widgets/qbuttongroup/tst_qbuttongroup.cpp
+++ b/tests/auto/widgets/widgets/qbuttongroup/tst_qbuttongroup.cpp
@@ -83,6 +83,7 @@ Q_OBJECT
private slots:
void arrowKeyNavigation();
+ void keyNavigationPushButtons();
void exclusive();
void exclusiveWithActions();
void testSignals();
@@ -185,6 +186,73 @@ void tst_QButtonGroup::arrowKeyNavigation()
QVERIFY(bt3.hasFocus());
}
+/*
+ Test that tab and arrow key navigation through buttons
+ in an invisible button group works as expected. Tabbing
+ into the group should give focus to the checked button,
+ and arrow navigation should change the checked button and
+ move focus.
+*/
+void tst_QButtonGroup::keyNavigationPushButtons()
+{
+ if (!qt_tab_all_widgets())
+ QSKIP("This test requires full keyboard control to be enabled.");
+
+ QDialog dlg(nullptr);
+ QLineEdit *le1 = new QLineEdit;
+ le1->setObjectName("le1");
+ QPushButton *pb1 = new QPushButton("Exclusive 1");
+ pb1->setObjectName("pb1");
+ pb1->setCheckable(true);
+ pb1->setChecked(true);
+ QPushButton *pb2 = new QPushButton("Exclusive 2");
+ pb2->setObjectName("pb2");
+ pb2->setCheckable(true);
+ QPushButton *pb3 = new QPushButton("Exclusive 3");
+ pb3->setObjectName("pb3");
+ pb3->setCheckable(true);
+ QLineEdit *le2 = new QLineEdit;
+ le2->setObjectName("le2");
+
+ QVBoxLayout* layout = new QVBoxLayout(&dlg);
+ layout->addWidget(le1);
+ layout->addWidget(pb1);
+ layout->addWidget(pb2);
+ layout->addWidget(pb3);
+ layout->addWidget(le2);
+
+ QButtonGroup *buttonGroup = new QButtonGroup;
+ buttonGroup->addButton(pb1);
+ buttonGroup->addButton(pb2);
+ buttonGroup->addButton(pb3);
+
+ dlg.show();
+ qApp->setActiveWindow(&dlg);
+ if (!QTest::qWaitForWindowActive(&dlg))
+ QSKIP("Window activation failed, skipping test");
+
+ QVERIFY2(le1->hasFocus(), qPrintable(qApp->focusWidget()->objectName()));
+ QTest::keyClick(qApp->focusWidget(), Qt::Key_Tab);
+ QVERIFY2(pb1->hasFocus(), qPrintable(qApp->focusWidget()->objectName()));
+ QVERIFY2(pb1->isChecked(), qPrintable(buttonGroup->checkedButton()->objectName()));
+ QTest::keyClick(qApp->focusWidget(), Qt::Key_Down);
+ QVERIFY2(pb2->hasFocus(), qPrintable(qApp->focusWidget()->objectName()));
+ QVERIFY2(pb2->isChecked(), qPrintable(buttonGroup->checkedButton()->objectName()));
+ QTest::keyClick(qApp->focusWidget(), Qt::Key_Down);
+ QVERIFY2(pb3->hasFocus(), qPrintable(qApp->focusWidget()->objectName()));
+ QVERIFY2(pb3->isChecked(), qPrintable(buttonGroup->checkedButton()->objectName()));
+ QTest::keyClick(qApp->focusWidget(), Qt::Key_Up);
+ QVERIFY2(pb2->hasFocus(), qPrintable(qApp->focusWidget()->objectName()));
+ QVERIFY2(pb2->isChecked(), qPrintable(buttonGroup->checkedButton()->objectName()));
+ QTest::keyClick(qApp->focusWidget(), Qt::Key_Tab);
+ QVERIFY2(le2->hasFocus(), qPrintable(qApp->focusWidget()->objectName()));
+ QTest::keyClick(qApp->focusWidget(), Qt::Key_Backtab);
+ QVERIFY2(pb2->hasFocus(), qPrintable(qApp->focusWidget()->objectName()));
+ QVERIFY2(pb2->isChecked(), qPrintable(buttonGroup->checkedButton()->objectName()));
+ QTest::keyClick(qApp->focusWidget(), Qt::Key_Backtab);
+ QVERIFY2(le1->hasFocus(), qPrintable(qApp->focusWidget()->objectName()));
+}
+
void tst_QButtonGroup::exclusiveWithActions()
{
QDialog dlg(0);
diff --git a/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp b/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp
index 4c6cf3588a..6345d238e1 100644
--- a/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp
+++ b/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp
@@ -195,6 +195,8 @@ private slots:
void specialValueText();
void setRange_data();
void setRange();
+ void editingRanged_data();
+ void editingRanged();
void selectAndScrollWithKeys();
void backspaceKey();
@@ -1310,6 +1312,120 @@ void tst_QDateTimeEdit::setRange()
}
}
+/*
+ Test that a user can input a date into a ranged QDateTimeEdit or QDateEdit
+ where a part of date is larger than the respective part of the maximum, or
+ smaller than the respective part of the minimum of the range.
+
+ This test is expected to fail unless keyboard tracking of the edit is set
+ to off. Otherwise the changed-signal would be emitted with values outside
+ of the allowed range as the user types.
+*/
+void tst_QDateTimeEdit::editingRanged_data()
+{
+ QTest::addColumn<QDate>("minDate");
+ QTest::addColumn<QTime>("minTime");
+ QTest::addColumn<QDate>("maxDate");
+ QTest::addColumn<QTime>("maxTime");
+ QTest::addColumn<QString>("userInput");
+ QTest::addColumn<QDateTime>("expected");
+
+ QTest::addRow("trivial")
+ << QDate(2010, 1, 1) << QTime(9, 0)
+ << QDate(2011, 12, 31) << QTime(16, 0)
+ << QString::fromLatin1("311220101600")
+ << QDateTime(QDate(2010, 12, 31), QTime(16, 0));
+
+ QTest::addRow("data0")
+ << QDate(2010, 12, 30) << QTime(16, 0)
+ << QDate(2011, 1, 2) << QTime(9, 0)
+ << QString::fromLatin1("311220102359")
+ << QDateTime(QDate(2010, 12, 31), QTime(23, 59));
+
+ QTest::addRow("data1")
+ << QDate(2010, 12, 30) << QTime(16, 0)
+ << QDate(2011, 1, 2) << QTime(9, 0)
+ << QString::fromLatin1("010120111823")
+ << QDateTime(QDate(2011, 1, 1), QTime(18, 23));
+
+ QTest::addRow("Out of range")
+ << QDate(2010, 12, 30) << QTime(16, 0)
+ << QDate(2011, 1, 2) << QTime(9, 0)
+ << QString::fromLatin1("090920111823")
+ << QDateTime(QDate(2011, 1, 2), QTime(9, 0));
+
+ QTest::addRow("only date")
+ << QDate(2010, 12, 30) << QTime()
+ << QDate(2011, 1, 2) << QTime()
+ << QString::fromLatin1("01012011")
+ << QDateTime(QDate(2011, 1, 1), QTime());
+}
+
+void tst_QDateTimeEdit::editingRanged()
+{
+ QFETCH(QDate, minDate);
+ QFETCH(QTime, minTime);
+ QFETCH(QDate, maxDate);
+ QFETCH(QTime, maxTime);
+ QFETCH(QString, userInput);
+ QFETCH(QDateTime, expected);
+
+ QDateTimeEdit *edit;
+ if (minTime.isValid()) {
+ edit = new QDateTimeEdit;
+ edit->setDisplayFormat("dd.MM.yyyy hh:mm");
+ edit->setDateTimeRange(QDateTime(minDate, minTime), QDateTime(maxDate, maxTime));
+ } else {
+ edit = new QDateEdit;
+ edit->setDisplayFormat("dd.MM.yyyy");
+ edit->setDateRange(minDate, maxDate);
+ }
+
+ int callCount = 0;
+ connect(edit, &QDateTimeEdit::dateTimeChanged, [&](const QDateTime &dateTime) {
+ ++callCount;
+ if (minTime.isValid()) {
+ QVERIFY(dateTime >= QDateTime(minDate, minTime));
+ QVERIFY(dateTime <= QDateTime(maxDate, maxTime));
+ } else {
+ QVERIFY(dateTime.date() >= minDate);
+ QVERIFY(dateTime.date() <= maxDate);
+ }
+ });
+
+ edit->show();
+ QApplication::setActiveWindow(edit);
+ if (!QTest::qWaitForWindowActive(edit))
+ QSKIP("Failed to make window active, aborting");
+ edit->setFocus();
+
+ // with keyboard tracking, never get a signal with an out-of-range value
+ edit->setKeyboardTracking(true);
+ QTest::keyClicks(edit, userInput);
+ QTest::keyClick(edit, Qt::Key_Return);
+ QVERIFY(callCount > 0);
+
+ // QDateTimeEdit blocks these dates from being entered - see QTBUG-65
+ QEXPECT_FAIL("data0", "Can't enter this date", Continue);
+ QEXPECT_FAIL("data1", "Can't enter this date", Continue);
+ QEXPECT_FAIL("Out of range", "Can't enter this date", Continue);
+ QEXPECT_FAIL("only date", "Can't enter this date", Continue);
+ QCOMPARE(edit->dateTime(), expected);
+
+ // reset
+ edit->clearFocus();
+ edit->setFocus();
+ callCount = 0;
+
+ edit->setKeyboardTracking(false);
+ QTest::keyClicks(edit, userInput);
+ QTest::keyClick(edit, Qt::Key_Return);
+ QCOMPARE(edit->dateTime(), expected);
+ QCOMPARE(callCount, 1);
+
+ delete edit;
+}
+
void tst_QDateTimeEdit::wrappingTime_data()
{
QTest::addColumn<bool>("startWithMin");