From d909c0efba034677d493c6785a4392a433359577 Mon Sep 17 00:00:00 2001 From: Martin Negyokru Date: Thu, 24 Mar 2022 14:00:29 +0100 Subject: Refactor 'inputmethods' manual test Fix build after qtbase patch: 19f9b0d5f5 Disable copying and assigning of QEvent Stop test execution when window is closed Change-Id: I038421ce6cd034b669d5601e8fda1ee33cdf0566 Reviewed-by: Kirill Burtsev Reviewed-by: Peter Varga --- tests/manual/widgets/inputmethods/controlview.cpp | 12 +++-- tests/manual/widgets/inputmethods/controlview.h | 7 +-- tests/manual/widgets/inputmethods/main.cpp | 54 ++++++++++++++++------- tests/manual/widgets/inputmethods/testview.cpp | 17 ++++--- tests/manual/widgets/inputmethods/testview.h | 2 + 5 files changed, 62 insertions(+), 30 deletions(-) (limited to 'tests') diff --git a/tests/manual/widgets/inputmethods/controlview.cpp b/tests/manual/widgets/inputmethods/controlview.cpp index 4538ced4b..358199a7f 100644 --- a/tests/manual/widgets/inputmethods/controlview.cpp +++ b/tests/manual/widgets/inputmethods/controlview.cpp @@ -69,7 +69,7 @@ ControlView::ControlView(QWidget *parent) layout->addRow(m_sendEventButton); setLayout(layout); - connect(m_sendEventButton, &QPushButton::clicked, this, &ControlView::createAndSendInputMethodEvent); + connect(m_sendEventButton, &QPushButton::clicked, this, &ControlView::requestInputMethodEvent); } void ControlView::receiveInputMethodData(int start, @@ -87,7 +87,12 @@ void ControlView::receiveInputMethodData(int start, m_inputLine->setText(input); } -void ControlView::createAndSendInputMethodEvent() +const QString ControlView::getText() const +{ + return m_inputLine->text(); +} + +const QList ControlView::getAtrributes() const { int start = m_startSpin->value(); int length = m_lengthSpin->value(); @@ -102,7 +107,6 @@ void ControlView::createAndSendInputMethodEvent() QList attrs; attrs.append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, start, length, format)); - QInputMethodEvent im(m_inputLine->text(), attrs); - emit sendInputMethodEvent(im); + return attrs; } diff --git a/tests/manual/widgets/inputmethods/controlview.h b/tests/manual/widgets/inputmethods/controlview.h index 0ef10f6a8..b0593012b 100644 --- a/tests/manual/widgets/inputmethods/controlview.h +++ b/tests/manual/widgets/inputmethods/controlview.h @@ -46,12 +46,13 @@ class ControlView : public QWidget public: explicit ControlView(QWidget *parent = 0); + const QString getText() const; + const QList getAtrributes() const; + public slots: void receiveInputMethodData(int, int, QTextCharFormat::UnderlineStyle, const QColor &, const QColor &, const QString &); - void createAndSendInputMethodEvent(); - signals: - void sendInputMethodEvent(QInputMethodEvent); + void requestInputMethodEvent(); private: QComboBox *m_underlineStyleCombo; diff --git a/tests/manual/widgets/inputmethods/main.cpp b/tests/manual/widgets/inputmethods/main.cpp index a96deb83a..2388a95d7 100644 --- a/tests/manual/widgets/inputmethods/main.cpp +++ b/tests/manual/widgets/inputmethods/main.cpp @@ -49,7 +49,12 @@ class MainWindow : public QMainWindow public: explicit MainWindow(QWidget *parent = 0); +private slots: + void sendInputMethodEvents(); + private: + void closeEvent(QCloseEvent *event) override; + ControlView *m_controlView; ReferenceView *m_referenceView; WebView *m_webView; @@ -109,29 +114,44 @@ MainWindow::MainWindow(QWidget *parent) centralLayout->addLayout(leftLayout); centralLayout->addWidget(m_testView); - connect(m_testView, &TestView::sendInputMethodData, m_controlView, &ControlView::receiveInputMethodData); - connect(m_testView, &TestView::requestInputMethodEvent, m_controlView, &ControlView::createAndSendInputMethodEvent); - - connect(m_controlView, &ControlView::sendInputMethodEvent, [=](QInputMethodEvent im) { - bool processed; - QString resultText; - - processed = QApplication::sendEvent(m_referenceView->referenceInput(), &im); - resultText = processed ? QStringLiteral("TRUE") - : QStringLiteral("FALSE"); - m_referenceProcessed->setText(resultText); - - processed = QApplication::sendEvent(m_webView->focusProxy(), &im); - resultText = processed ? QStringLiteral("TRUE") - : QStringLiteral("FALSE"); - m_webProcessed->setText(resultText); - }); + connect(m_testView, &TestView::sendInputMethodData, m_controlView, + &ControlView::receiveInputMethodData); + connect(m_testView, &TestView::requestInputMethodEvent, this, + &MainWindow::sendInputMethodEvents); + connect(m_controlView, &ControlView::requestInputMethodEvent, this, + &MainWindow::sendInputMethodEvents); centralWidget->setLayout(centralLayout); setCentralWidget(centralWidget); setWindowTitle(tr("Input Methods Format Manual Test")); } +void MainWindow::sendInputMethodEvents() +{ + bool processed; + QString resultText; + + QString text = m_controlView->getText(); + QList attrs = m_controlView->getAtrributes(); + QInputMethodEvent im(text, attrs); + + processed = QApplication::sendEvent(m_referenceView->referenceInput(), &im); + resultText = processed ? QStringLiteral("TRUE") + : QStringLiteral("FALSE"); + m_referenceProcessed->setText(resultText); + + processed = QApplication::sendEvent(m_webView->focusProxy(), &im); + resultText = processed ? QStringLiteral("TRUE") + : QStringLiteral("FALSE"); + m_webProcessed->setText(resultText); +} + +void MainWindow::closeEvent(QCloseEvent *event) +{ + m_testView->cancelTest(); + QMainWindow::closeEvent(event); +} + int main(int argc, char *argv[]) { QApplication a(argc, argv); diff --git a/tests/manual/widgets/inputmethods/testview.cpp b/tests/manual/widgets/inputmethods/testview.cpp index 14e355caf..77133d31d 100644 --- a/tests/manual/widgets/inputmethods/testview.cpp +++ b/tests/manual/widgets/inputmethods/testview.cpp @@ -94,11 +94,19 @@ void TestView::loadTestData(const QString &testDataPath) testDataFile.close(); } +void TestView::cancelTest() +{ + if (!m_testRunning) + return; + + m_testRunning = false; + m_testButton->setText(tr("Start Test")); +} + void TestView::startOrCancelTest() { if (m_testRunning) { - m_testRunning = false; - m_testButton->setText(tr("Start Test")); + cancelTest(); return; } @@ -120,10 +128,7 @@ void TestView::startOrCancelTest() QTest::qWait(1000); } - if (m_testRunning) { - m_testRunning = false; - m_testButton->setText(tr("Start Test")); - } + cancelTest(); } void TestView::collectAndSendData() diff --git a/tests/manual/widgets/inputmethods/testview.h b/tests/manual/widgets/inputmethods/testview.h index 4934a5f87..245d98c3e 100644 --- a/tests/manual/widgets/inputmethods/testview.h +++ b/tests/manual/widgets/inputmethods/testview.h @@ -41,6 +41,8 @@ class TestView : public QWidget public: explicit TestView(QWidget *parent = 0); + void cancelTest(); + public slots: void loadTestData(const QString &); void startOrCancelTest(); -- cgit v1.2.3