Changeset View
Changeset View
Standalone View
Standalone View
autotests/integration/keyboard_layout_test.cpp
- This file was added.
1 | /******************************************************************** | ||||
---|---|---|---|---|---|
2 | KWin - the KDE window manager | ||||
3 | This file is part of the KDE project. | ||||
4 | | ||||
5 | Copyright (C) 2017 Martin Gräßlin <mgraesslin@kde.org> | ||||
6 | | ||||
7 | This program is free software; you can redistribute it and/or modify | ||||
8 | it under the terms of the GNU General Public License as published by | ||||
9 | the Free Software Foundation; either version 2 of the License, or | ||||
10 | (at your option) any later version. | ||||
11 | | ||||
12 | This program is distributed in the hope that it will be useful, | ||||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | GNU General Public License for more details. | ||||
16 | | ||||
17 | You should have received a copy of the GNU General Public License | ||||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | *********************************************************************/ | ||||
20 | #include "kwin_wayland_test.h" | ||||
21 | #include "keyboard_input.h" | ||||
22 | #include "platform.h" | ||||
23 | #include "wayland_server.h" | ||||
24 | | ||||
25 | #include <KConfigGroup> | ||||
26 | | ||||
27 | #include <QDBusConnection> | ||||
28 | #include <QDBusMessage> | ||||
29 | | ||||
30 | using namespace KWin; | ||||
31 | using namespace KWayland::Client; | ||||
32 | | ||||
33 | static const QString s_socketName = QStringLiteral("wayland_test_kwin_keyboard_laout-0"); | ||||
34 | | ||||
35 | class KeyboardLayoutTest : public QObject | ||||
36 | { | ||||
37 | Q_OBJECT | ||||
38 | private Q_SLOTS: | ||||
39 | void initTestCase(); | ||||
40 | void init(); | ||||
41 | void cleanup(); | ||||
42 | | ||||
43 | void testReconfigure(); | ||||
44 | }; | ||||
45 | | ||||
46 | void KeyboardLayoutTest::initTestCase() | ||||
47 | { | ||||
48 | QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); | ||||
49 | QVERIFY(workspaceCreatedSpy.isValid()); | ||||
50 | kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024)); | ||||
51 | QVERIFY(waylandServer()->init(s_socketName.toLocal8Bit())); | ||||
52 | | ||||
53 | kwinApp()->setConfig(KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)); | ||||
54 | kwinApp()->setKxkbConfig(KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)); | ||||
55 | | ||||
56 | kwinApp()->start(); | ||||
57 | QVERIFY(workspaceCreatedSpy.wait()); | ||||
58 | waylandServer()->initWorkspace(); | ||||
59 | } | ||||
60 | | ||||
61 | void KeyboardLayoutTest::init() | ||||
62 | { | ||||
63 | } | ||||
64 | | ||||
65 | void KeyboardLayoutTest::cleanup() | ||||
66 | { | ||||
67 | } | ||||
68 | | ||||
69 | void KeyboardLayoutTest::testReconfigure() | ||||
70 | { | ||||
71 | // verifies that we can change the keymap | ||||
72 | | ||||
73 | // default should be a keymap with only us layout | ||||
74 | auto xkb = input()->keyboard()->xkb(); | ||||
75 | QCOMPARE(xkb->numberOfLayouts(), 1u); | ||||
76 | QCOMPARE(xkb->layoutName(), QStringLiteral("English (US)")); | ||||
77 | auto layouts = xkb->layoutNames(); | ||||
78 | QCOMPARE(layouts.size(), 1); | ||||
79 | QVERIFY(layouts.contains(0)); | ||||
80 | QCOMPARE(layouts[0], QStringLiteral("English (US)")); | ||||
81 | | ||||
82 | // create a new keymap | ||||
83 | KConfigGroup layoutGroup = kwinApp()->kxkbConfig()->group("Layout"); | ||||
84 | layoutGroup.writeEntry("LayoutList", QStringLiteral("de,us")); | ||||
85 | layoutGroup.sync(); | ||||
86 | | ||||
87 | // create DBus signal to reload | ||||
88 | QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/Layouts"), QStringLiteral("org.kde.keyboard"), QStringLiteral("reloadConfig")); | ||||
89 | QDBusConnection::sessionBus().send(message); | ||||
90 | // now we should have two layouts | ||||
91 | QTRY_COMPARE(xkb->numberOfLayouts(), 2u); | ||||
92 | // default layout is German | ||||
93 | QCOMPARE(xkb->layoutName(), QStringLiteral("German")); | ||||
94 | layouts = xkb->layoutNames(); | ||||
95 | QCOMPARE(layouts.size(), 2); | ||||
96 | QVERIFY(layouts.contains(0)); | ||||
97 | QVERIFY(layouts.contains(1)); | ||||
98 | QCOMPARE(layouts[0], QStringLiteral("German")); | ||||
99 | QCOMPARE(layouts[1], QStringLiteral("English (US)")); | ||||
100 | } | ||||
101 | | ||||
102 | WAYLANDTEST_MAIN(KeyboardLayoutTest) | ||||
103 | #include "keyboard_layout_test.moc" |