summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets/widgets')
-rw-r--r--tests/auto/widgets/widgets/qabstractspinbox/qabstractspinbox.pro2
-rw-r--r--tests/auto/widgets/widgets/qabstractspinbox/tst_qabstractspinbox.cpp88
-rw-r--r--tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp75
-rw-r--r--tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp63
-rw-r--r--tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp61
-rw-r--r--tests/auto/widgets/widgets/qmenubar/tst_qmenubar_mac.mm34
-rw-r--r--tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp2
-rw-r--r--tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp196
-rw-r--r--tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp2
-rw-r--r--tests/auto/widgets/widgets/widgets.pro1
10 files changed, 492 insertions, 32 deletions
diff --git a/tests/auto/widgets/widgets/qabstractspinbox/qabstractspinbox.pro b/tests/auto/widgets/widgets/qabstractspinbox/qabstractspinbox.pro
index f9b601228e..be758a8bdd 100644
--- a/tests/auto/widgets/widgets/qabstractspinbox/qabstractspinbox.pro
+++ b/tests/auto/widgets/widgets/qabstractspinbox/qabstractspinbox.pro
@@ -4,7 +4,7 @@
CONFIG += testcase
TARGET = tst_qabstractspinbox
-QT += widgets testlib
+QT += widgets gui-private core-private testlib
SOURCES += tst_qabstractspinbox.cpp
diff --git a/tests/auto/widgets/widgets/qabstractspinbox/tst_qabstractspinbox.cpp b/tests/auto/widgets/widgets/qabstractspinbox/tst_qabstractspinbox.cpp
index 36f5df4649..3fb4863b0e 100644
--- a/tests/auto/widgets/widgets/qabstractspinbox/tst_qabstractspinbox.cpp
+++ b/tests/auto/widgets/widgets/qabstractspinbox/tst_qabstractspinbox.cpp
@@ -35,6 +35,20 @@
#include <qlineedit.h>
#include <qspinbox.h>
+#include "../../../shared/platforminputcontext.h"
+#include <private/qinputmethod_p.h>
+
+static inline void centerOnScreen(QWidget *w, const QSize &size)
+{
+ const QPoint offset = QPoint(size.width() / 2, size.height() / 2);
+ w->move(QGuiApplication::primaryScreen()->availableGeometry().center() - offset);
+}
+
+static inline void centerOnScreen(QWidget *w)
+{
+ centerOnScreen(w, w->geometry().size());
+}
+
class tst_QAbstractSpinBox : public QObject
{
Q_OBJECT
@@ -44,11 +58,19 @@ public:
virtual ~tst_QAbstractSpinBox();
private slots:
+ void initTestCase();
+ void cleanupTestCase();
+
void getSetCheck();
// task-specific tests below me:
void task183108_clear();
void task228728_cssselector();
+
+ void inputMethodUpdate();
+
+private:
+ PlatformInputContext m_platformInputContext;
};
tst_QAbstractSpinBox::tst_QAbstractSpinBox()
@@ -67,6 +89,18 @@ public:
void setLineEdit(QLineEdit *le) { QAbstractSpinBox::setLineEdit(le); }
};
+void tst_QAbstractSpinBox::initTestCase()
+{
+ QInputMethodPrivate *inputMethodPrivate = QInputMethodPrivate::get(qApp->inputMethod());
+ inputMethodPrivate->testContext = &m_platformInputContext;
+}
+
+void tst_QAbstractSpinBox::cleanupTestCase()
+{
+ QInputMethodPrivate *inputMethodPrivate = QInputMethodPrivate::get(qApp->inputMethod());
+ inputMethodPrivate->testContext = 0;
+}
+
// Testing get/set functions
void tst_QAbstractSpinBox::getSetCheck()
{
@@ -141,6 +175,60 @@ void tst_QAbstractSpinBox::task228728_cssselector()
QSpinBox box;
}
+void tst_QAbstractSpinBox::inputMethodUpdate()
+{
+ QSpinBox box;
+
+ QSpinBox *testWidget = &box;
+ testWidget->setRange(0, 1);
+
+ centerOnScreen(testWidget);
+ testWidget->clear();
+ testWidget->show();
+ QVERIFY(QTest::qWaitForWindowExposed(testWidget));
+
+ testWidget->activateWindow();
+ testWidget->setFocus();
+ QTRY_VERIFY(testWidget->hasFocus());
+ QTRY_COMPARE(qApp->focusObject(), testWidget);
+
+ m_platformInputContext.m_updateCallCount = 0;
+ {
+ QList<QInputMethodEvent::Attribute> attributes;
+ QInputMethodEvent event("1", attributes);
+ QApplication::sendEvent(testWidget, &event);
+ }
+ QVERIFY(m_platformInputContext.m_updateCallCount >= 1);
+
+ m_platformInputContext.m_updateCallCount = 0;
+ {
+ QList<QInputMethodEvent::Attribute> attributes;
+ attributes << QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, 0, 1, QVariant());
+ QInputMethodEvent event("1", attributes);
+ QApplication::sendEvent(testWidget, &event);
+ }
+ QVERIFY(m_platformInputContext.m_updateCallCount >= 1);
+
+ m_platformInputContext.m_updateCallCount = 0;
+ {
+ QList<QInputMethodEvent::Attribute> attributes;
+ QInputMethodEvent event("", attributes);
+ event.setCommitString("1");
+ QApplication::sendEvent(testWidget, &event);
+ }
+ QVERIFY(m_platformInputContext.m_updateCallCount >= 1);
+ QCOMPARE(testWidget->value(), 1);
+
+ m_platformInputContext.m_updateCallCount = 0;
+ {
+ QList<QInputMethodEvent::Attribute> attributes;
+ attributes << QInputMethodEvent::Attribute(QInputMethodEvent::Selection, 0, 0, QVariant());
+ QInputMethodEvent event("", attributes);
+ QApplication::sendEvent(testWidget, &event);
+ }
+ QVERIFY(m_platformInputContext.m_updateCallCount >= 1);
+}
+
QTEST_MAIN(tst_QAbstractSpinBox)
#include "tst_qabstractspinbox.moc"
diff --git a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp
index 3afdc0a12a..b882055888 100644
--- a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp
+++ b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp
@@ -64,6 +64,9 @@
#include <qproxystyle.h>
#include <qfont.h>
+#include "../../../shared/platforminputcontext.h"
+#include <private/qinputmethod_p.h>
+
static inline void setFrameless(QWidget *w)
{
Qt::WindowFlags flags = w->windowFlags();
@@ -80,6 +83,8 @@ public:
tst_QComboBox() {}
private slots:
+ void initTestCase();
+ void cleanupTestCase();
void getSetCheck();
void ensureReturnIsIgnored();
void setEditable();
@@ -162,6 +167,10 @@ private slots:
void task_QTBUG_39088_inputMethodHints();
void task_QTBUG_49831_scrollerNotActivated();
void task_QTBUG_56693_itemFontFromModel();
+ void inputMethodUpdate();
+
+private:
+ PlatformInputContext m_platformInputContext;
};
class MyAbstractItemDelegate : public QAbstractItemDelegate
@@ -207,6 +216,18 @@ protected:
QRegion visualRegionForSelection(const QItemSelection &) const { return QRegion(); }
};
+void tst_QComboBox::initTestCase()
+{
+ QInputMethodPrivate *inputMethodPrivate = QInputMethodPrivate::get(qApp->inputMethod());
+ inputMethodPrivate->testContext = &m_platformInputContext;
+}
+
+void tst_QComboBox::cleanupTestCase()
+{
+ QInputMethodPrivate *inputMethodPrivate = QInputMethodPrivate::get(qApp->inputMethod());
+ inputMethodPrivate->testContext = 0;
+}
+
// Testing get/set functions
void tst_QComboBox::getSetCheck()
{
@@ -3324,5 +3345,59 @@ void tst_QComboBox::task_QTBUG_56693_itemFontFromModel()
box.hidePopup();
}
+void tst_QComboBox::inputMethodUpdate()
+{
+ TestWidget topLevel;
+ topLevel.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&topLevel));
+ QComboBox *testWidget = topLevel.comboBox();
+ // make sure we have no lineedit
+ QVERIFY(!testWidget->lineEdit());
+ // test setEditable(true)
+ testWidget->setEditable(true);
+ QVERIFY(testWidget->lineEdit());
+
+ testWidget->activateWindow();
+ testWidget->setFocus();
+ QTRY_VERIFY(testWidget->hasFocus());
+ QTRY_COMPARE(qApp->focusObject(), testWidget);
+
+ m_platformInputContext.m_updateCallCount = 0;
+ {
+ QList<QInputMethodEvent::Attribute> attributes;
+ QInputMethodEvent event("preedit text", attributes);
+ QApplication::sendEvent(testWidget, &event);
+ }
+ QVERIFY(m_platformInputContext.m_updateCallCount >= 1);
+
+ m_platformInputContext.m_updateCallCount = 0;
+ {
+ QList<QInputMethodEvent::Attribute> attributes;
+ attributes << QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, 0, 1, QVariant());
+ QInputMethodEvent event("preedit text", attributes);
+ QApplication::sendEvent(testWidget, &event);
+ }
+ QVERIFY(m_platformInputContext.m_updateCallCount >= 1);
+
+ m_platformInputContext.m_updateCallCount = 0;
+ {
+ QList<QInputMethodEvent::Attribute> attributes;
+ QInputMethodEvent event("", attributes);
+ event.setCommitString("preedit text");
+ QApplication::sendEvent(testWidget, &event);
+ }
+ QVERIFY(m_platformInputContext.m_updateCallCount >= 1);
+ QCOMPARE(testWidget->lineEdit()->text(), QString("preedit text"));
+
+ m_platformInputContext.m_updateCallCount = 0;
+ {
+ QList<QInputMethodEvent::Attribute> attributes;
+ attributes << QInputMethodEvent::Attribute(QInputMethodEvent::Selection, 0, 0, QVariant());
+ QInputMethodEvent event("", attributes);
+ QApplication::sendEvent(testWidget, &event);
+ }
+ QVERIFY(m_platformInputContext.m_updateCallCount >= 1);
+}
+
QTEST_MAIN(tst_QComboBox)
#include "tst_qcombobox.moc"
diff --git a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp
index a4614d0a9d..330ce3a836 100644
--- a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp
+++ b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp
@@ -294,6 +294,8 @@ private slots:
void inputMethodQueryImHints_data();
void inputMethodQueryImHints();
+ void inputMethodUpdate();
+
void undoRedoAndEchoModes_data();
void undoRedoAndEchoModes();
@@ -711,8 +713,8 @@ void tst_QLineEdit::clearInputMask()
{
QLineEdit *testWidget = ensureTestWidget();
testWidget->setInputMask("000.000.000.000");
- QVERIFY(testWidget->inputMask() != QString::null);
- testWidget->setInputMask(QString::null);
+ QVERIFY(!testWidget->inputMask().isNull());
+ testWidget->setInputMask(QString());
QCOMPARE(testWidget->inputMask(), QString());
}
@@ -2275,7 +2277,7 @@ void tst_QLineEdit::textChangedAndTextEdited()
changed_count = 0;
edited_count = 0;
- changed_string = QString::null;
+ changed_string.clear();
testWidget->setText("foo");
QCOMPARE(changed_count, 1);
@@ -2284,7 +2286,7 @@ void tst_QLineEdit::textChangedAndTextEdited()
changed_count = 0;
edited_count = 0;
- changed_string = QString::null;
+ changed_string.clear();
testWidget->setText("");
QCOMPARE(changed_count, 1);
@@ -3106,7 +3108,7 @@ void tst_QLineEdit::maxLengthAndInputMask()
QVERIFY(testWidget->inputMask().isNull());
testWidget->setMaxLength(10);
QCOMPARE(testWidget->maxLength(), 10);
- testWidget->setInputMask(QString::null);
+ testWidget->setInputMask(QString());
QVERIFY(testWidget->inputMask().isNull());
QCOMPARE(testWidget->maxLength(), 10);
}
@@ -4184,6 +4186,57 @@ void tst_QLineEdit::inputMethodQueryImHints()
QCOMPARE(static_cast<Qt::InputMethodHints>(value.toInt()), hints);
}
+void tst_QLineEdit::inputMethodUpdate()
+{
+ QLineEdit *testWidget = ensureTestWidget();
+
+ centerOnScreen(testWidget);
+ testWidget->show();
+ QVERIFY(QTest::qWaitForWindowExposed(testWidget));
+
+ testWidget->setText("");
+ testWidget->activateWindow();
+ testWidget->setFocus();
+ QTRY_VERIFY(testWidget->hasFocus());
+ QTRY_COMPARE(qApp->focusObject(), testWidget);
+
+ m_platformInputContext.m_updateCallCount = 0;
+ {
+ QList<QInputMethodEvent::Attribute> attributes;
+ QInputMethodEvent event("preedit text", attributes);
+ QApplication::sendEvent(testWidget, &event);
+ }
+ QVERIFY(m_platformInputContext.m_updateCallCount >= 1);
+
+ m_platformInputContext.m_updateCallCount = 0;
+ {
+ QList<QInputMethodEvent::Attribute> attributes;
+ attributes << QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, 0, 1, QVariant());
+ QInputMethodEvent event("preedit text", attributes);
+ QApplication::sendEvent(testWidget, &event);
+ }
+ QVERIFY(m_platformInputContext.m_updateCallCount >= 1);
+
+ m_platformInputContext.m_updateCallCount = 0;
+ {
+ QList<QInputMethodEvent::Attribute> attributes;
+ QInputMethodEvent event("", attributes);
+ event.setCommitString("preedit text");
+ QApplication::sendEvent(testWidget, &event);
+ }
+ QVERIFY(m_platformInputContext.m_updateCallCount >= 1);
+ QCOMPARE(testWidget->text(), QString("preedit text"));
+
+ m_platformInputContext.m_updateCallCount = 0;
+ {
+ QList<QInputMethodEvent::Attribute> attributes;
+ attributes << QInputMethodEvent::Attribute(QInputMethodEvent::Selection, 0, 0, QVariant());
+ QInputMethodEvent event("", attributes);
+ QApplication::sendEvent(testWidget, &event);
+ }
+ QVERIFY(m_platformInputContext.m_updateCallCount >= 1);
+}
+
void tst_QLineEdit::undoRedoAndEchoModes_data()
{
QTest::addColumn<int>("echoMode");
diff --git a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp
index e3af0135e7..4d57b85f9a 100644
--- a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp
+++ b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp
@@ -119,6 +119,7 @@ private slots:
#if !defined(Q_OS_DARWIN)
void check_shortcutPress();
void check_menuPosition();
+ void taskQTBUG46812_doNotLeaveMenubarHighlighted();
#endif
void task223138_triggered();
void task256322_highlight();
@@ -231,9 +232,14 @@ TestMenu tst_QMenuBar::initSimpleMenuBar(QMenuBar *mb, bool forceNonNative) {
menu = mb->addMenu(QStringLiteral("accel1"));
action = menu->addAction(QStringLiteral("&Open...") );
action->setShortcut(Qt::Key_O);
+ result.actions << action;
+
+ action = menu->addAction(QStringLiteral("action"));
+ action->setShortcut(QKeySequence(Qt::ALT + Qt::Key_Z));
+ result.actions << action;
+
result.menus << menu;
connect(menu, SIGNAL(triggered(QAction*)), this, SLOT(onSimpleActivated(QAction*)));
- result.actions << action;
m_lastSimpleAcceleratorId = 0;
m_simpleActivatedCount = 0;
@@ -319,7 +325,7 @@ inline TestMenu tst_QMenuBar::initWindowWithComplexMenuBar(QMainWindow &w)
return initComplexMenuBar(w.menuBar());
}
-// On Mac/WinCE, native key events are needed to test menu action activation
+// On Mac native key events are needed to test menu action activation
#if !defined(Q_OS_DARWIN)
void tst_QMenuBar::accel()
{
@@ -337,7 +343,7 @@ void tst_QMenuBar::accel()
}
#endif
-// On Mac/WinCE, native key events are needed to test menu action activation
+// On Mac native key events are needed to test menu action activation
#if !defined(Q_OS_DARWIN)
void tst_QMenuBar::activatedCount()
{
@@ -536,7 +542,7 @@ void tst_QMenuBar::insertItem_QString_QObject()
QVERIFY(actions.size() < 4); // there is no menu 4!
}
-// On Mac/WinCE, native key events are needed to test menu action activation
+// On Mac native key events are needed to test menu action activation
#if !defined(Q_OS_DARWIN)
void tst_QMenuBar::check_accelKeys()
{
@@ -609,7 +615,7 @@ void tst_QMenuBar::check_accelKeys()
}
#endif
-// On Mac/WinCE, native key events are needed to test menu action activation
+// On Mac native key events are needed to test menu action activation
#if !defined(Q_OS_DARWIN)
void tst_QMenuBar::check_cursorKeys1()
{
@@ -643,7 +649,7 @@ void tst_QMenuBar::check_cursorKeys1()
}
#endif
-// Qt/Mac,WinCE does not use the native popups/menubar
+// Qt/Mac does not use the native popups/menubar
#if !defined(Q_OS_DARWIN)
void tst_QMenuBar::check_cursorKeys2()
{
@@ -676,7 +682,7 @@ void tst_QMenuBar::check_cursorKeys2()
/*!
If a popupmenu is active you can use Left to move to the menu to the left of it.
*/
-// Qt/Mac,WinCE does not use the native popups/menubar
+// Qt/Mac does not use the native popups/menubar
#if !defined(Q_OS_DARWIN)
void tst_QMenuBar::check_cursorKeys3()
{
@@ -791,7 +797,7 @@ void tst_QMenuBar::check_endKey()
If Down is pressed next the popup is activated again.
*/
-// Qt/Mac,WinCE does not use the native popups/menubar
+// Qt/Mac does not use the native popups/menubar
#if !defined(Q_OS_DARWIN)
void tst_QMenuBar::check_escKey()
{
@@ -1025,7 +1031,7 @@ void tst_QMenuBar::check_altClosePress()
QTRY_VERIFY(!w.menuBar()->activeAction());
}
-// Qt/Mac,WinCE does not use the native popups/menubar
+// Qt/Mac does not use the native popups/menubar
#if !defined(Q_OS_DARWIN)
void tst_QMenuBar::check_shortcutPress()
{
@@ -1068,7 +1074,7 @@ private:
const Qt::LayoutDirection m_oldDirection;
};
-// Qt/Mac,WinCE does not use the native popups/menubar
+// Qt/Mac does not use the native popups/menubar
#if !defined(Q_OS_DARWIN)
void tst_QMenuBar::check_menuPosition()
{
@@ -1530,6 +1536,41 @@ void tst_QMenuBar::slotForTaskQTBUG53205()
taskQTBUG53205MenuBar->setParent(parent);
}
+// Qt/Mac does not use the native popups/menubar
+#if !defined(Q_OS_DARWIN)
+void tst_QMenuBar::taskQTBUG46812_doNotLeaveMenubarHighlighted()
+{
+ QMainWindow mainWindow;
+ QWidget *centralWidget = new QWidget;
+ centralWidget->setFocusPolicy(Qt::StrongFocus);
+ mainWindow.setCentralWidget(centralWidget);
+ initWindowWithSimpleMenuBar(mainWindow);
+
+ mainWindow.show();
+ QApplication::setActiveWindow(&mainWindow);
+ QVERIFY(QTest::qWaitForWindowActive(&mainWindow));
+
+ QVERIFY(!mainWindow.menuBar()->hasFocus());
+ QCOMPARE(m_simpleActivatedCount, 0);
+
+ QTest::keyPress(&mainWindow, Qt::Key_Alt, Qt::AltModifier);
+ QVERIFY(!mainWindow.menuBar()->hasFocus());
+ QCOMPARE(m_simpleActivatedCount, 0);
+
+ QTest::keyPress(&mainWindow, Qt::Key_Z, Qt::AltModifier);
+ QVERIFY(!mainWindow.menuBar()->hasFocus());
+ QCOMPARE(m_simpleActivatedCount, 2); // the action AND the menu will activate
+
+ QTest::keyRelease(&mainWindow, Qt::Key_Alt, Qt::NoModifier);
+ QVERIFY(!mainWindow.menuBar()->hasFocus());
+ QCOMPARE(m_simpleActivatedCount, 2);
+
+ QTest::keyRelease(&mainWindow, Qt::Key_Z, Qt::NoModifier);
+ QVERIFY(!mainWindow.menuBar()->hasFocus());
+ QCOMPARE(m_simpleActivatedCount, 2);
+}
+#endif
+
#ifdef Q_OS_MACOS
extern bool tst_qmenubar_taskQTBUG56275(QMenuBar *);
diff --git a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar_mac.mm b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar_mac.mm
index 4645de4d7a..af93c18712 100644
--- a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar_mac.mm
+++ b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar_mac.mm
@@ -1,31 +1,37 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
diff --git a/tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp b/tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp
index 31bbcf9c7f..af0ad1a601 100644
--- a/tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp
+++ b/tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp
@@ -362,7 +362,7 @@ void tst_QPlainTextEdit::emptyAppend()
{
ed->appendPlainText("Blah");
QCOMPARE(blockCount(), 1);
- ed->appendPlainText(QString::null);
+ ed->appendPlainText(QString());
QCOMPARE(blockCount(), 2);
ed->appendPlainText(QString(" "));
QCOMPARE(blockCount(), 3);
diff --git a/tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp b/tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp
index f490446c8a..72e6ffdeb5 100644
--- a/tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp
+++ b/tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp
@@ -77,6 +77,11 @@ private slots:
void rubberBandNotInSplitter();
void saveAndRestoreStateOfNotYetShownSplitter();
void saveAndRestoreHandleWidth();
+ void replaceWidget_data();
+ void replaceWidget();
+ void replaceWidgetWithSplitterChild_data();
+ void replaceWidgetWithSplitterChild();
+ void handleMinimumWidth();
// task-specific tests below me:
void task187373_addAbstractScrollAreas();
@@ -645,9 +650,200 @@ public:
MyFriendlySplitter(QWidget *parent = 0) : QSplitter(parent) {}
void setRubberBand(int pos) { QSplitter::setRubberBand(pos); }
+ void moveSplitter(int pos, int index) { QSplitter::moveSplitter(pos, index); }
+
friend class tst_QSplitter;
};
+class EventCounterSpy : public QObject
+{
+public:
+ EventCounterSpy(QWidget *parentWidget) : QObject(parentWidget)
+ { }
+
+ bool eventFilter(QObject *watched, QEvent *event) override
+ {
+ // Watch for events in the parent widget and all its children
+ if (watched == parent() || watched->parent() == parent()) {
+ if (event->type() == QEvent::Resize)
+ resizeCount++;
+ else if (event->type() == QEvent::Paint)
+ paintCount++;
+ }
+
+ return QObject::eventFilter(watched, event);
+ }
+
+ int resizeCount = 0;
+ int paintCount = 0;
+};
+
+void tst_QSplitter::replaceWidget_data()
+{
+ QTest::addColumn<int>("index");
+ QTest::addColumn<bool>("visible");
+ QTest::addColumn<bool>("collapsed");
+
+ QTest::newRow("negative index") << -1 << true << false;
+ QTest::newRow("index too large") << 80 << true << false;
+ QTest::newRow("visible, not collapsed") << 3 << true << false;
+ QTest::newRow("visible, collapsed") << 3 << true << true;
+ QTest::newRow("not visible, not collapsed") << 3 << false << false;
+ QTest::newRow("not visible, collapsed") << 3 << false << true;
+}
+
+void tst_QSplitter::replaceWidget()
+{
+ QFETCH(int, index);
+ QFETCH(bool, visible);
+ QFETCH(bool, collapsed);
+
+ // Setup
+ MyFriendlySplitter sp;
+ const int count = 7;
+ for (int i = 0; i < count; i++) {
+ // We use labels instead of plain widgets to
+ // make it easier to fix eventual regressions.
+ QLabel *w = new QLabel(QString::asprintf("WIDGET #%d", i));
+ sp.addWidget(w);
+ }
+ sp.setWindowTitle(QString::asprintf("index %d, visible %d, collapsed %d", index, visible, collapsed));
+ sp.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&sp));
+
+ // Configure splitter
+ QWidget *oldWidget = sp.widget(index);
+ const QRect oldGeom = oldWidget ? oldWidget->geometry() : QRect();
+ if (oldWidget) {
+ // Collapse first, then hide, if necessary
+ if (collapsed) {
+ sp.setCollapsible(index, true);
+ sp.moveSplitter(oldWidget->x() + 1, index + 1);
+ }
+ if (!visible)
+ oldWidget->hide();
+ }
+
+ // Replace widget
+ QTest::qWait(100); // Flush event queue
+ const QList<int> sizes = sp.sizes();
+ // Shorter label: The important thing is to ensure we can set
+ // the same size on the new widget. Because of QLabel's sizing
+ // constraints (they can expand but not shrink) the easiest is
+ // to set a shorter label.
+ QLabel *newWidget = new QLabel(QLatin1String("<b>NEW</b>"));
+
+ EventCounterSpy *ef = new EventCounterSpy(&sp);
+ qApp->installEventFilter(ef);
+ const QWidget *res = sp.replaceWidget(index, newWidget);
+ QTest::qWait(100); // Give visibility and resizing some time
+ qApp->removeEventFilter(ef);
+
+ // Check
+ if (index < 0 || index >= count) {
+ QVERIFY(!res);
+ QVERIFY(!newWidget->parentWidget());
+ QCOMPARE(ef->resizeCount, 0);
+ QCOMPARE(ef->paintCount, 0);
+ } else {
+ QCOMPARE(res, oldWidget);
+ QVERIFY(!res->parentWidget());
+ QVERIFY(!res->isVisible());
+ QCOMPARE(newWidget->parentWidget(), &sp);
+ QCOMPARE(newWidget->isVisible(), visible);
+ if (visible && !collapsed)
+ QCOMPARE(newWidget->geometry(), oldGeom);
+ QCOMPARE(newWidget->size().isEmpty(), !visible || collapsed);
+ const int expectedResizeCount = visible ? 1 : 0; // new widget only
+ const int expectedPaintCount = visible && !collapsed ? 2 : 0; // splitter and new widget
+ QCOMPARE(ef->resizeCount, expectedResizeCount);
+ QCOMPARE(ef->paintCount, expectedPaintCount);
+ delete res;
+ }
+ QCOMPARE(sp.count(), count);
+ QCOMPARE(sp.sizes(), sizes);
+}
+
+void tst_QSplitter::replaceWidgetWithSplitterChild_data()
+{
+ QTest::addColumn<int>("srcIndex");
+ QTest::addColumn<int>("dstIndex");
+
+ QTest::newRow("replace with null widget") << -2 << 3;
+ QTest::newRow("replace with itself") << 3 << 3;
+ QTest::newRow("replace with sibling, after recalc") << 1 << 4;
+ QTest::newRow("replace with sibling, before recalc") << -1 << 4;
+}
+
+void tst_QSplitter::replaceWidgetWithSplitterChild()
+{
+ QFETCH(int, srcIndex);
+ QFETCH(int, dstIndex);
+
+ // Setup
+ MyFriendlySplitter sp;
+ const int count = 7;
+ for (int i = 0; i < count; i++) {
+ // We use labels instead of plain widgets to
+ // make it easier to fix eventual regressions.
+ QLabel *w = new QLabel(QString::asprintf("WIDGET #%d", i));
+ sp.addWidget(w);
+ }
+ sp.setWindowTitle(QLatin1String(QTest::currentTestFunction()) + QLatin1Char(' ') + QLatin1String(QTest::currentDataTag()));
+ sp.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&sp));
+
+ QTest::qWait(100); // Flush event queue before new widget creation
+ const QList<int> sizes = sp.sizes();
+ QWidget *sibling = srcIndex == -1 ? (new QLabel("<b>NEW</b>", &sp)) : sp.widget(srcIndex);
+
+ EventCounterSpy *ef = new EventCounterSpy(&sp);
+ qApp->installEventFilter(ef);
+ const QWidget *res = sp.replaceWidget(dstIndex, sibling);
+ QTest::qWait(100); // Give visibility and resizing some time
+ qApp->removeEventFilter(ef);
+
+ QVERIFY(!res);
+ if (srcIndex == -1) {
+ // Create and replace before recalc. The sibling is scheduled to be
+ // added after replaceWidget(), when QSplitter receives a child event.
+ QVERIFY(ef->resizeCount > 0);
+ QVERIFY(ef->paintCount > 0);
+ QCOMPARE(sp.count(), count + 1);
+ QCOMPARE(sp.sizes().mid(0, count), sizes);
+ QCOMPARE(sp.sizes().last(), sibling->width());
+ } else {
+ // No-op for the rest
+ QCOMPARE(ef->resizeCount, 0);
+ QCOMPARE(ef->paintCount, 0);
+ QCOMPARE(sp.count(), count);
+ QCOMPARE(sp.sizes(), sizes);
+ }
+}
+
+void tst_QSplitter::handleMinimumWidth()
+{
+ MyFriendlySplitter split;
+ split.addWidget(new QLabel("Number Wan"));
+ split.addWidget(new QLabel("Number Too"));
+
+ split.show();
+ QTest::qWaitForWindowExposed(&split);
+ for (int i = 0; i < 10; i++) {
+ split.setHandleWidth(i);
+ QTest::qWait(100); // resizing
+ QCOMPARE(split.handle(1)->width(), qMax(4 + (i & 1), i));
+ }
+
+ split.setOrientation(Qt::Vertical);
+ QTest::qWait(100);
+ for (int i = 0; i < 10; i++) {
+ split.setHandleWidth(i);
+ QTest::qWait(100); // resizing
+ QCOMPARE(split.handle(1)->height(), qMax(4 + (i & 1), i));
+ }
+}
+
void tst_QSplitter::rubberBandNotInSplitter()
{
MyFriendlySplitter split;
diff --git a/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp b/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp
index cecec48113..b9ea310d80 100644
--- a/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp
+++ b/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp
@@ -676,7 +676,7 @@ void tst_QTextEdit::emptyAppend()
{
ed->append("Blah");
QCOMPARE(blockCount(), 1);
- ed->append(QString::null);
+ ed->append(QString());
QCOMPARE(blockCount(), 2);
ed->append(QString(" "));
QCOMPARE(blockCount(), 3);
diff --git a/tests/auto/widgets/widgets/widgets.pro b/tests/auto/widgets/widgets/widgets.pro
index a8e8f6d865..c098108edc 100644
--- a/tests/auto/widgets/widgets/widgets.pro
+++ b/tests/auto/widgets/widgets/widgets.pro
@@ -49,6 +49,7 @@ SUBDIRS=\
# The following tests depend on private API:
!qtConfig(private_tests): SUBDIRS -= \
+ qabstractspinbox \
qcombobox \
qmainwindow \
qtextedit \