[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kwin] autotests/integration: [autotests] Add test case for changing keyboard layout through DBus
From:       Martin_Gräßlin <null () kde ! org>
Date:       2017-01-31 18:43:39
Message-ID: E1cYdP1-0007NW-4T () code ! kde ! org
[Download RAW message or body]

Git commit d33c96af5ec57d6617b5359d7f60944828756e96 by Martin Gräßlin.
Committed on 31/01/2017 at 18:42.
Pushed by graesslin into branch 'master'.

[autotests] Add test case for changing keyboard layout through DBus

Calls setLayout of org.kde.KeyboardLayouts.

M  +59   -3    autotests/integration/keyboard_layout_test.cpp

https://commits.kde.org/kwin/d33c96af5ec57d6617b5359d7f60944828756e96

diff --git a/autotests/integration/keyboard_layout_test.cpp \
b/autotests/integration/keyboard_layout_test.cpp index 849057e9e..215c7180d 100644
--- a/autotests/integration/keyboard_layout_test.cpp
+++ b/autotests/integration/keyboard_layout_test.cpp
@@ -26,6 +26,7 @@ along with this program.  If not, see \
<http://www.gnu.org/licenses/>.  
 #include <QDBusConnection>
 #include <QDBusMessage>
+#include <QDBusPendingCall>
 
 using namespace KWin;
 using namespace KWayland::Client;
@@ -41,8 +42,19 @@ private Q_SLOTS:
     void cleanup();
 
     void testReconfigure();
+    void testChangeLayoutThroughDBus();
+
+private:
+    void reconfigureLayouts();
 };
 
+void KeyboardLayoutTest::reconfigureLayouts()
+{
+    // create DBus signal to reload
+    QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/Layouts"), \
QStringLiteral("org.kde.keyboard"), QStringLiteral("reloadConfig")); +    \
QDBusConnection::sessionBus().send(message); +}
+
 void KeyboardLayoutTest::initTestCase()
 {
     QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated);
@@ -84,9 +96,7 @@ void KeyboardLayoutTest::testReconfigure()
     layoutGroup.writeEntry("LayoutList", QStringLiteral("de,us"));
     layoutGroup.sync();
 
-    // create DBus signal to reload
-    QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/Layouts"), \
                QStringLiteral("org.kde.keyboard"), QStringLiteral("reloadConfig"));
-    QDBusConnection::sessionBus().send(message);
+    reconfigureLayouts();
     // now we should have two layouts
     QTRY_COMPARE(xkb->numberOfLayouts(), 2u);
     // default layout is German
@@ -99,5 +109,51 @@ void KeyboardLayoutTest::testReconfigure()
     QCOMPARE(layouts[1], QStringLiteral("English (US)"));
 }
 
+void KeyboardLayoutTest::testChangeLayoutThroughDBus()
+{
+    // this test verifies that the layout can be changed through DBus
+    // first configure layouts
+    KConfigGroup layoutGroup = kwinApp()->kxkbConfig()->group("Layout");
+    layoutGroup.writeEntry("LayoutList", QStringLiteral("de,us,de(neo)"));
+    layoutGroup.sync();
+    reconfigureLayouts();
+    // now we should have two layouts
+    auto xkb = input()->keyboard()->xkb();
+    QTRY_COMPARE(xkb->numberOfLayouts(), 3u);
+    // default layout is German
+    xkb->switchToLayout(0);
+    QCOMPARE(xkb->layoutName(), QStringLiteral("German"));
+
+    // now change through DBus to english
+    auto changeLayout = [] (const QString &layoutName) {
+        QDBusMessage msg = \
QDBusMessage::createMethodCall(QStringLiteral("org.kde.keyboard"), \
QStringLiteral("/Layouts"), QStringLiteral("org.kde.KeyboardLayouts"), \
QStringLiteral("setLayout")); +        msg << layoutName;
+        return QDBusConnection::sessionBus().asyncCall(msg);
+    };
+    auto reply = changeLayout(QStringLiteral("English (US)"));
+    reply.waitForFinished();
+    QVERIFY(!reply.isError());
+    QCOMPARE(reply.reply().arguments().first().toBool(), true);
+    QCOMPARE(xkb->layoutName(), QStringLiteral("English (US)"));
+
+    // switch to a layout which does not exist
+    reply = changeLayout(QStringLiteral("French"));
+    QVERIFY(!reply.isError());
+    QCOMPARE(reply.reply().arguments().first().toBool(), false);
+    QCOMPARE(xkb->layoutName(), QStringLiteral("English (US)"));
+
+    // switch to another layout should work
+    reply = changeLayout(QStringLiteral("German"));
+    QVERIFY(!reply.isError());
+    QCOMPARE(reply.reply().arguments().first().toBool(), true);
+    QCOMPARE(xkb->layoutName(), QStringLiteral("German"));
+
+    // switching to same layout should also work
+    reply = changeLayout(QStringLiteral("German"));
+    QVERIFY(!reply.isError());
+    QCOMPARE(reply.reply().arguments().first().toBool(), true);
+    QCOMPARE(xkb->layoutName(), QStringLiteral("German"));
+}
+
 WAYLANDTEST_MAIN(KeyboardLayoutTest)
 #include "keyboard_layout_test.moc"


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic