diff options
author | Liang Qi <liang.qi@qt.io> | 2017-02-28 13:03:36 +0100 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2017-02-28 13:03:36 +0100 |
commit | 1a4f0deeb44e2bfb107a22a714df3796ac1d0c20 (patch) | |
tree | b1c8db2d1b742d25106225c80893e0b32f98fb15 /tests | |
parent | db0064b767474a89bc72ea4374f477682983c5f4 (diff) | |
parent | 35fa30e65d26b9e4840cfa793ed8369b3475c1fd (diff) |
Merge remote-tracking branch 'origin/5.9' into dev
Change-Id: I7d84cfed0b2a122d334b8a920e6e4f18472d2f11
Diffstat (limited to 'tests')
11 files changed, 343 insertions, 24 deletions
diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp index 450bd1cf3f..d57c4629cc 100644 --- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp @@ -734,7 +734,7 @@ QT_FOR_EACH_STATIC_CORE_POINTER(ADD_METATYPE_TEST_ROW) QTest::newRow("QPair<P,C>") << ::qMetaTypeId<QPair<P,C> >() << false << true << false << false; QTest::newRow("QPair<P,M>") << ::qMetaTypeId<QPair<P,M> >() << true << true << false << false; QTest::newRow("QPair<P,P>") << ::qMetaTypeId<QPair<P,P> >() << true << false << false << false; - QTest::newRow("FlagsDataEnum") << ::qMetaTypeId<FlagsDataEnum>() << true << true << false << true; + QTest::newRow("FlagsDataEnum") << ::qMetaTypeId<FlagsDataEnum>() << true << false << false << true; // invalid ids. QTest::newRow("-1") << -1 << false << false << false << false; diff --git a/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp b/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp index 5b7242fddb..fdc4ecb5c8 100644 --- a/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp +++ b/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp @@ -89,6 +89,7 @@ private slots: void waitForDone(); void clear(); void cancel(); + void tryTake(); void waitForDoneTimeout(); void destroyingWaitsForTasksToFinish(); void stressTest(); @@ -1042,6 +1043,97 @@ void tst_QThreadPool::cancel() delete runnables[runs-1]; } +void tst_QThreadPool::tryTake() +{ + QSemaphore sem(0); + QSemaphore startedThreads(0); + + class SemaphoreReleaser + { + QSemaphore &sem; + int n; + Q_DISABLE_COPY(SemaphoreReleaser) + public: + explicit SemaphoreReleaser(QSemaphore &sem, int n) + : sem(sem), n(n) {} + + ~SemaphoreReleaser() + { + sem.release(n); + } + }; + + class BlockingRunnable : public QRunnable + { + public: + QSemaphore &sem; + QSemaphore &startedThreads; + QAtomicInt &dtorCounter; + QAtomicInt &runCounter; + int dummy; + + explicit BlockingRunnable(QSemaphore &s, QSemaphore &started, QAtomicInt &c, QAtomicInt &r) + : sem(s), startedThreads(started), dtorCounter(c), runCounter(r) {} + + ~BlockingRunnable() + { + dtorCounter.fetchAndAddRelaxed(1); + } + + void run() override + { + startedThreads.release(); + runCounter.fetchAndAddRelaxed(1); + sem.acquire(); + count.ref(); + } + }; + + enum { + MaxThreadCount = 3, + OverProvisioning = 2, + Runs = MaxThreadCount * OverProvisioning + }; + + QThreadPool threadPool; + threadPool.setMaxThreadCount(MaxThreadCount); + BlockingRunnable *runnables[Runs]; + + // ensure that the QThreadPool doesn't deadlock if any of the checks fail + // and cause an early return: + const SemaphoreReleaser semReleaser(sem, Runs); + + count.store(0); + QAtomicInt dtorCounter = 0; + QAtomicInt runCounter = 0; + for (int i = 0; i < Runs; i++) { + runnables[i] = new BlockingRunnable(sem, startedThreads, dtorCounter, runCounter); + runnables[i]->setAutoDelete(i != 0 && i != Runs - 1); // one which will run and one which will not + QVERIFY(!threadPool.tryTake(runnables[i])); // verify NOOP for jobs not in the queue + threadPool.start(runnables[i]); + } + // wait for all worker threads to have started up: + QVERIFY(startedThreads.tryAcquire(MaxThreadCount, 60*1000 /* 1min */)); + + for (int i = 0; i < MaxThreadCount; ++i) { + // check taking runnables doesn't work once they were started: + QVERIFY(!threadPool.tryTake(runnables[i])); + } + for (int i = MaxThreadCount; i < Runs ; ++i) { + QVERIFY(threadPool.tryTake(runnables[i])); + delete runnables[i]; + } + + runnables[0]->dummy = 0; // valgrind will catch this if tryTake() is crazy enough to delete currently running jobs + QCOMPARE(dtorCounter.load(), int(Runs - MaxThreadCount)); + sem.release(MaxThreadCount); + threadPool.waitForDone(); + QCOMPARE(runCounter.load(), int(MaxThreadCount)); + QCOMPARE(count.load(), int(MaxThreadCount)); + QCOMPARE(dtorCounter.load(), int(Runs - 1)); + delete runnables[0]; // if the pool deletes them then we'll get double-free crash +} + void tst_QThreadPool::destroyingWaitsForTasksToFinish() { QTime total, pass; diff --git a/tests/auto/widgets/kernel/qsizepolicy/tst_qsizepolicy.cpp b/tests/auto/widgets/kernel/qsizepolicy/tst_qsizepolicy.cpp index 98b765a6c6..4ae1f02ce2 100644 --- a/tests/auto/widgets/kernel/qsizepolicy/tst_qsizepolicy.cpp +++ b/tests/auto/widgets/kernel/qsizepolicy/tst_qsizepolicy.cpp @@ -113,6 +113,8 @@ void tst_QSizePolicy::constExpr() // check that certain ctors are constexpr (compile-only): { Q_CONSTEXPR QSizePolicy sp; Q_UNUSED(sp); } { Q_CONSTEXPR QSizePolicy sp = QSizePolicy(); Q_UNUSED(sp); } + { Q_CONSTEXPR QSizePolicy sp = QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); Q_UNUSED(sp); } + { Q_CONSTEXPR QSizePolicy sp = QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding, QSizePolicy::DefaultType); Q_UNUSED(sp); } #else QSKIP("QSizePolicy cannot be constexpr with this version of the compiler."); #endif 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..4c0ffdc77c 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(); @@ -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/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 \ diff --git a/tests/manual/windowflags/controllerwindow.cpp b/tests/manual/windowflags/controllerwindow.cpp index 3654bfbad0..9a12c8b2c9 100644 --- a/tests/manual/windowflags/controllerwindow.cpp +++ b/tests/manual/windowflags/controllerwindow.cpp @@ -191,12 +191,12 @@ static bool isTopLevel(const QObject *o) return false; } -static Qt::WindowState windowState(const QObject *o) +static Qt::WindowStates windowState(const QObject *o) { if (o->isWidgetType()) { Qt::WindowStates states = static_cast<const QWidget *>(o)->windowState(); states &= ~Qt::WindowActive; - return static_cast<Qt::WindowState>(int(states)); + return states; } #if QT_VERSION >= 0x050000 if (o->isWindowType()) diff --git a/tests/manual/windowflags/previewwindow.cpp b/tests/manual/windowflags/previewwindow.cpp index 54084fd1bc..65a287f788 100644 --- a/tests/manual/windowflags/previewwindow.cpp +++ b/tests/manual/windowflags/previewwindow.cpp @@ -202,16 +202,21 @@ PreviewWindow::PreviewWindow(QWidget *parent) setWindowTitle(tr("Preview <QWidget> Qt %1").arg(QLatin1String(QT_VERSION_STR))); } -void PreviewWindow::resizeEvent(QResizeEvent *e) +bool PreviewWindow::event(QEvent *event) { - QWidget::resizeEvent(e); - updateInfo(); -} + const bool ret = QWidget::event(event); -void PreviewWindow::moveEvent(QMoveEvent *e) -{ - QWidget::moveEvent(e); - updateInfo(); + switch (event->type()) { + case QEvent::Move: + case QEvent::Resize: + case QEvent::WindowStateChange: + updateInfo(); + break; + default: + break; + } + + return ret; } void PreviewWindow::setWindowFlags(Qt::WindowFlags flags) @@ -234,16 +239,21 @@ PreviewDialog::PreviewDialog(QWidget *parent) setWindowTitle(tr("Preview <QDialog> Qt %1").arg(QLatin1String(QT_VERSION_STR))); } -void PreviewDialog::resizeEvent(QResizeEvent *e) +bool PreviewDialog::event(QEvent *event) { - QDialog::resizeEvent(e); - updateInfo(); -} + const bool ret = QDialog::event(event); -void PreviewDialog::moveEvent(QMoveEvent *e) -{ - QDialog::moveEvent(e); - updateInfo(); + switch (event->type()) { + case QEvent::Move: + case QEvent::Resize: + case QEvent::WindowStateChange: + updateInfo(); + break; + default: + break; + } + + return ret; } void PreviewDialog::setWindowFlags(Qt::WindowFlags flags) diff --git a/tests/manual/windowflags/previewwindow.h b/tests/manual/windowflags/previewwindow.h index acd79735ad..9730e7a3f9 100644 --- a/tests/manual/windowflags/previewwindow.h +++ b/tests/manual/windowflags/previewwindow.h @@ -48,8 +48,7 @@ public slots: void updateInfo(); protected: - void resizeEvent(QResizeEvent *); - void moveEvent(QMoveEvent *); + bool event(QEvent *) override; private: QPlainTextEdit *textEdit; @@ -68,8 +67,7 @@ public slots: void updateInfo(); protected: - void resizeEvent(QResizeEvent *); - void moveEvent(QMoveEvent *); + bool event(QEvent *) override; private: QPlainTextEdit *textEdit; |