summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2021-10-21 14:10:33 +0200
committerLiang Qi <liang.qi@qt.io>2021-11-09 12:07:31 +0000
commitcac38b4c15cf64d44920eb301acdafd768d969a3 (patch)
tree25a20792204a5f41b109506959902651182d020c /tests
parentd6d67aa9e9946c0ee3a68bd21b1501cd831d0a13 (diff)
downloadqtwayland-cac38b4c15cf64d44920eb301acdafd768d969a3.tar.gz
tests: add test for multiple text input
Change-Id: Ief343ebf9d0d6d00533eb3c698c416f4205bbfac Reviewed-by: Inho Lee <inho.lee@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/client/inputcontext/tst_inputcontext.cpp137
-rw-r--r--tests/auto/client/shared/CMakeLists.txt3
-rw-r--r--tests/auto/client/shared/qttextinput.cpp45
-rw-r--r--tests/auto/client/shared/qttextinput.h51
4 files changed, 203 insertions, 33 deletions
diff --git a/tests/auto/client/inputcontext/tst_inputcontext.cpp b/tests/auto/client/inputcontext/tst_inputcontext.cpp
index d421b0d2..02beb6af 100644
--- a/tests/auto/client/inputcontext/tst_inputcontext.cpp
+++ b/tests/auto/client/inputcontext/tst_inputcontext.cpp
@@ -28,6 +28,7 @@
#include "mockcompositor.h"
#include "textinput.h"
+#include "qttextinput.h"
#include <QtCore/QString>
#include <QtCore/QByteArray>
@@ -48,16 +49,41 @@ private slots:
void initTestCase();
void selectingInputContext_data();
void selectingInputContext();
+ void selectingTextInputProtocol_data();
+ void selectingTextInputProtocol();
void inputContextReconfigurationWhenTogglingTextInputExtension();
private:
QByteArray inputContextName() const;
- void ensureTextInputPresentOnCompositor();
- void ensureTextInputNotPresentOnCompositor();
+
+ template<typename arg_type>
+ void ensurePresentOnCompositor()
+ {
+ exec([&] {
+ QList<arg_type *> extensions = getAll<arg_type>();
+ if (extensions.length() > 1)
+ QFAIL("Requested type is a singleton, hence there should not be more then one object returned");
+ if (extensions.length() == 0)
+ add<arg_type>();
+ });
+ }
+
+ template<typename arg_type>
+ void ensureNotPresentOnCompositor()
+ {
+ exec([&] {
+ QList<arg_type *> extensions = getAll<arg_type>();
+ if (extensions.length() > 1)
+ QFAIL("Requested type is a singleton, hence there should not be more then one object returned");
+ if (extensions.length() == 1)
+ remove(extensions.first());
+ });
+ }
QByteArray mComposeModule = QByteArray("QComposeInputContext"); // default input context
QByteArray mIbusModule = QByteArray("QIBusPlatformInputContext");
- QByteArray mWaylandModule = QByteArray("QtWaylandClient::QWaylandInputContext");
+ QByteArray mTextInputModule = QByteArray("QtWaylandClient::QWaylandInputContext");
+ QByteArray mQtTextInputModule = QByteArray("QtWaylandClient::QWaylandInputMethodContext");
};
void tst_inputcontext::initTestCase()
@@ -82,28 +108,6 @@ QByteArray tst_inputcontext::inputContextName() const
return QByteArray("");
}
-void tst_inputcontext::ensureTextInputPresentOnCompositor()
-{
- exec([&] {
- QList<TextInputManager *> extensions = getAll<TextInputManager>();
- if (extensions.length() > 1)
- QFAIL("TextInputManager is a singleton, hence there should not be more then one object returned");
- if (extensions.length() == 0)
- add<TextInputManager>();
- });
-}
-
-void tst_inputcontext::ensureTextInputNotPresentOnCompositor()
-{
- exec([&] {
- QList<TextInputManager *> extensions = getAll<TextInputManager>();
- if (extensions.length() > 1)
- QFAIL("TextInputManager is a singleton, hence there should not be more then one object returned");
- if (extensions.length() == 1)
- remove(extensions.first());
- });
-}
-
void tst_inputcontext::selectingInputContext_data()
{
QTest::addColumn<QByteArray>("requestedModule");
@@ -120,7 +124,7 @@ void tst_inputcontext::selectingInputContext_data()
QTest::newRow("ibus:text-input") << QByteArray("ibus") << mIbusModule;
QTest::newRow("compose:text-input") << QByteArray("compose") << mComposeModule;
QTest::newRow("empty:text-input") << QByteArray("") << mComposeModule;
- QTest::newRow("null:text-input") << QByteArray() << mWaylandModule;
+ QTest::newRow("null:text-input") << QByteArray() << mTextInputModule;
QTest::newRow("fake:text-input") << QByteArray("fake") << mComposeModule;
}
@@ -137,9 +141,76 @@ void tst_inputcontext::selectingInputContext()
const bool withTextInputAtCompositorSide = QByteArray(QTest::currentDataTag()).endsWith(":text-input");
if (withTextInputAtCompositorSide)
- ensureTextInputPresentOnCompositor();
+ ensurePresentOnCompositor<TextInputManager>();
+ else
+ ensureNotPresentOnCompositor<TextInputManager>();
+
+ int argc = 0;
+ QGuiApplication app(argc, nullptr); // loads the platform plugin
+
+ QCOMPARE(inputContextName(), expectedModule);
+}
+
+void tst_inputcontext::selectingTextInputProtocol_data()
+{
+ QTest::addColumn<bool>("requestQtTextInput");
+ QTest::addColumn<bool>("requestTextInput");
+ QTest::addColumn<QByteArray>("clientProtocol");
+ QTest::addColumn<QByteArray>("expectedModule");
+
+ QTest::newRow("1-1") << true << true << QByteArray() << mQtTextInputModule;
+ QTest::newRow("1-2") << true << false << QByteArray() << mQtTextInputModule;
+ QTest::newRow("1-3") << false << true << QByteArray() << mTextInputModule;
+ QTest::newRow("1-4") << false << false << QByteArray() << mComposeModule;
+
+ QTest::newRow("2-1") << true << true << QByteArray("zwp_text_input_v2") << mTextInputModule;
+ QTest::newRow("2-2") << true << false << QByteArray("zwp_text_input_v2") << mComposeModule;
+ QTest::newRow("2-3") << false << true << QByteArray("zwp_text_input_v2") << mTextInputModule;
+ QTest::newRow("2-4") << false << false << QByteArray("zwp_text_input_v2") << mComposeModule;
+
+ QTest::newRow("3-1") << true << true << QByteArray("qt_text_input_method_v1") << mQtTextInputModule;
+ QTest::newRow("3-2") << true << false << QByteArray("qt_text_input_method_v1") << mQtTextInputModule;
+ QTest::newRow("3-3") << false << true << QByteArray("qt_text_input_method_v1") << mComposeModule;
+ QTest::newRow("3-4") << false << false << QByteArray("qt_text_input_method_v1") << mComposeModule;
+
+ QTest::newRow("4-1") << true << true << QByteArray("qt_text_input_method_v1;zwp_text_input_v2") << mQtTextInputModule;
+ QTest::newRow("4-2") << true << false << QByteArray("qt_text_input_method_v1;zwp_text_input_v2") << mQtTextInputModule;
+ QTest::newRow("4-3") << false << true << QByteArray("qt_text_input_method_v1;zwp_text_input_v2") << mTextInputModule;
+ QTest::newRow("4-4") << false << false << QByteArray("qt_text_input_method_v1;zwp_text_input_v2") << mComposeModule;
+
+ QTest::newRow("5-1") << true << true << QByteArray("zwp_text_input_v2;qt_text_input_method_v1") << mTextInputModule;
+ QTest::newRow("5-2") << true << false << QByteArray("zwp_text_input_v2;qt_text_input_method_v1") << mQtTextInputModule;
+ QTest::newRow("5-3") << false << true << QByteArray("zwp_text_input_v2;qt_text_input_method_v1") << mTextInputModule;
+ QTest::newRow("5-4") << false << false << QByteArray("zwp_text_input_v2;qt_text_input_method_v1") << mComposeModule;
+}
+
+void tst_inputcontext::selectingTextInputProtocol()
+{
+ QFETCH(bool, requestQtTextInput);
+ QFETCH(bool, requestTextInput);
+ QFETCH(QByteArray, clientProtocol);
+ QFETCH(QByteArray, expectedModule);
+
+ exec([this] {
+ qputenv("QT_IM_MODULE", "qtvirtualkeyboard");
+ });
+
+ qunsetenv("QT_IM_MODULE");
+
+ if (clientProtocol.isNull())
+ qunsetenv("QT_WAYLAND_TEXT_INPUT_PROTOCOL");
+ else
+ qputenv("QT_WAYLAND_TEXT_INPUT_PROTOCOL", clientProtocol);
+
+ if (requestTextInput)
+ ensurePresentOnCompositor<TextInputManager>();
+ else
+ ensureNotPresentOnCompositor<TextInputManager>();
+
+ if (requestQtTextInput)
+ ensurePresentOnCompositor<QtTextInputManager>();
else
- ensureTextInputNotPresentOnCompositor();
+ ensureNotPresentOnCompositor<QtTextInputManager>();
int argc = 0;
QGuiApplication app(argc, nullptr); // loads the platform plugin
@@ -151,22 +222,22 @@ void tst_inputcontext::inputContextReconfigurationWhenTogglingTextInputExtension
{
qunsetenv("QT_IM_MODULE");
- ensureTextInputPresentOnCompositor();
+ ensurePresentOnCompositor<TextInputManager>();
int argc = 0;
QGuiApplication app(argc, nullptr); // loads the platform plugin
- QCOMPARE(inputContextName(), mWaylandModule);
+ QCOMPARE(inputContextName(), mTextInputModule);
// remove text input extension after the platform plugin has been loaded
- ensureTextInputNotPresentOnCompositor();
+ ensureNotPresentOnCompositor<TextInputManager>();
// QTRY_* because we need to spin the event loop for wayland QPA plugin
// to handle registry_global_remove()
QTRY_COMPARE(inputContextName(), mComposeModule);
// add text input extension after the platform plugin has been loaded
- ensureTextInputPresentOnCompositor();
+ ensurePresentOnCompositor<TextInputManager>();
// QTRY_* because we need to spin the event loop for wayland QPA plugin
// to handle registry_global()
- QTRY_COMPARE(inputContextName(), mWaylandModule);
+ QTRY_COMPARE(inputContextName(), mTextInputModule);
}
int main(int argc, char *argv[])
diff --git a/tests/auto/client/shared/CMakeLists.txt b/tests/auto/client/shared/CMakeLists.txt
index 2ce9c23a..b028dff1 100644
--- a/tests/auto/client/shared/CMakeLists.txt
+++ b/tests/auto/client/shared/CMakeLists.txt
@@ -10,6 +10,7 @@ qt_manual_moc(moc_files
fullscreenshellv1.h
iviapplication.h
textinput.h
+ qttextinput.h
xdgoutputv1.h
xdgshell.h
)
@@ -23,6 +24,7 @@ add_library(SharedClientTest
iviapplication.cpp iviapplication.h
mockcompositor.cpp mockcompositor.h
textinput.cpp textinput.h
+ qttextinput.cpp qttextinput.h
xdgoutputv1.cpp xdgoutputv1.h
xdgshell.cpp xdgshell.h
${moc_files}
@@ -35,6 +37,7 @@ qt6_generate_wayland_protocol_server_sources(SharedClientTest
${PROJECT_SOURCE_DIR}/src/3rdparty/protocol/wp-primary-selection-unstable-v1.xml
${PROJECT_SOURCE_DIR}/src/3rdparty/protocol/tablet-unstable-v2.xml
${PROJECT_SOURCE_DIR}/src/3rdparty/protocol/text-input-unstable-v2.xml
+ ${PROJECT_SOURCE_DIR}/src/extensions/qt-text-input-method-unstable-v1.xml
${PROJECT_SOURCE_DIR}/src/3rdparty/protocol/wayland.xml
${PROJECT_SOURCE_DIR}/src/3rdparty/protocol/xdg-decoration-unstable-v1.xml
${PROJECT_SOURCE_DIR}/src/3rdparty/protocol/xdg-output-unstable-v1.xml
diff --git a/tests/auto/client/shared/qttextinput.cpp b/tests/auto/client/shared/qttextinput.cpp
new file mode 100644
index 00000000..5cd9a6b6
--- /dev/null
+++ b/tests/auto/client/shared/qttextinput.cpp
@@ -0,0 +1,45 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 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:GPL-EXCEPT$
+** 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 https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** 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-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qttextinput.h"
+
+namespace MockCompositor {
+
+QtTextInputManager::QtTextInputManager(CoreCompositor *compositor)
+{
+ init(compositor->m_display, 1);
+}
+
+void QtTextInputManager::text_input_method_manager_v1_get_text_input_method(Resource *resource, uint32_t id, wl_resource *seatResource)
+{
+ Q_UNUSED(resource);
+ Q_UNUSED(id);
+ Q_UNUSED(seatResource);
+}
+
+} // namespace MockCompositor
diff --git a/tests/auto/client/shared/qttextinput.h b/tests/auto/client/shared/qttextinput.h
new file mode 100644
index 00000000..525711cc
--- /dev/null
+++ b/tests/auto/client/shared/qttextinput.h
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 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:GPL-EXCEPT$
+** 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 https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** 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-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MOCKCOMPOSITOR_QTTEXTINPUT_H
+#define MOCKCOMPOSITOR_QTTEXTINPUT_H
+
+#include "coreprotocol.h"
+#include <qwayland-server-qt-text-input-method-unstable-v1.h>
+
+#include <QtGui/qpa/qplatformnativeinterface.h>
+
+namespace MockCompositor {
+
+class QtTextInputManager : public Global, public QtWaylandServer::qt_text_input_method_manager_v1
+{
+ Q_OBJECT
+public:
+ QtTextInputManager(CoreCompositor *compositor);
+
+protected:
+ void text_input_method_manager_v1_get_text_input_method(Resource *resource, uint32_t id, struct ::wl_resource *seatResource) override;
+};
+
+} // namespace MockCompositor
+
+#endif // MOCKCOMPOSITOR_QTTEXTINPUT_H