2
* This file is part of Maliit Plugins
4
* Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
6
* Contact: Mohammad Anwari <Mohammad.Anwari@nokia.com>
8
* Redistribution and use in source and binary forms, with or without modification,
9
* are permitted provided that the following conditions are met:
11
* Redistributions of source code must retain the above copyright notice, this list
12
* of conditions and the following disclaimer.
13
* Redistributions in binary form must reproduce the above copyright notice, this list
14
* of conditions and the following disclaimer in the documentation and/or other materials
15
* provided with the distribution.
16
* Neither the name of Nokia Corporation nor the names of its contributors may be
17
* used to endorse or promote products derived from this software without specific
18
* prior written permission.
20
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
21
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23
* THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
#include "wordengineprobe.h"
34
#include "inputmethodhostprobe.h"
35
#include "models/key.h"
36
#include "models/keyarea.h"
37
#include "view/setup.h"
38
#include "logic/dynamiclayout.h"
39
#include "logic/layouthelper.h"
40
#include "logic/layoutupdater.h"
41
#include "logic/style.h"
42
#include "logic/languagefeatures.h"
43
#include "plugin/editor.h"
48
using namespace MaliitKeyboard;
50
class TestLanguageLayoutSwitching
56
Q_SLOT void initTestCase()
58
QVERIFY(qputenv("UBUNTU_KEYBOARD_DATA_DIR", TEST_MALIIT_KEYBOARD_DATADIR));
61
Q_SLOT void testActiveKeyboardId_data()
63
QTest::addColumn<QString>("keyboard_id");
64
QTest::addColumn<int>("expected_key_count");
66
QTest::newRow("Using invalid keyboard id: expect empty KeyArea.")
67
<< "invalid_language_layout_id" << 0;
69
QTest::newRow("Using 'en_gb' as keyboard id: expect KeyArea with 33 keys.")
72
QTest::newRow("Using 'de' as keyboard id: expect KeyArea with 36 keys.")
76
Q_SLOT void testActiveKeyboardId()
78
QFETCH(QString, keyboard_id);
79
QFETCH(int, expected_key_count);
81
Logic::LayoutUpdater layout_updater;
83
uiConst->initDynamicLayout( TEST_QML_DATADIR "/maliit-ui-constants.qml" );
85
Logic::LayoutHelper layout(new Logic::LayoutHelper);
86
layout_updater.setLayout(&layout);
88
SharedStyle style(new Style);
89
layout_updater.setStyle(style);
91
layout_updater.setActiveKeyboardId(keyboard_id);
92
TestUtils::waitForSignal(&layout, SIGNAL(centerPanelChanged(KeyArea,Logic::KeyOverrides)));
94
QCOMPARE(layout.activePanel(), Logic::LayoutHelper::CenterPanel);
95
QCOMPARE(layout.activeKeyArea().keys().count(), expected_key_count);
98
// Note: this feature is not important in Ubuntu UX
100
// This test is very trivial. It's required however because none of the
101
// current mainline layouts feature layout switch keys, thus making
102
// regressions impossible to spot.
103
// TODO: Let this test run on actual language layouts w/ layout switch
105
Q_SLOT void testLayoutSwitchKeys()
108
left_layout.setAction(Key::ActionLeftLayout);
111
right_layout.setAction(Key::ActionRightLayout);
113
Editor editor(EditorOptions(), new Model::Text,
114
new Logic::WordEngineProbe, new Logic::LanguageFeatures);
115
InputMethodHostProbe probe;
116
editor.setHost(&probe);
118
QSignalSpy left_spy(&editor, SIGNAL(leftLayoutSelected()));
119
QSignalSpy right_spy(&editor, SIGNAL(rightLayoutSelected()));
121
editor.onKeyPressed(left_layout);
122
QCOMPARE(left_spy.count(), 0);
124
editor.onKeyReleased(left_layout);
125
QCOMPARE(left_spy.count(), 1);
127
editor.onKeyPressed(right_layout);
128
QCOMPARE(right_spy.count(), 0);
130
editor.onKeyReleased(right_layout);
131
QCOMPARE(right_spy.count(), 1);
135
QTEST_MAIN(TestLanguageLayoutSwitching)
136
#include "ut_language-layout-switching.moc"