~sil/ubuntu-keyboard/numbers-on-top-row

« back to all changes in this revision

Viewing changes to tests/unittests/ut_language-layout-switching/ut_language-layout-switching.cpp

  • Committer: Guenter Schwann
  • Date: 2013-11-13 15:36:39 UTC
  • mfrom: (101.4.5 keyboard-cleanups)
  • Revision ID: guenter.schwann@canonical.com-20131113153639-9i9irt1mle00vy1t
Remove some dead code

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * This file is part of Maliit Plugins
3
 
 *
4
 
 * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
5
 
 *
6
 
 * Contact: Mohammad Anwari <Mohammad.Anwari@nokia.com>
7
 
 *
8
 
 * Redistribution and use in source and binary forms, with or without modification,
9
 
 * are permitted provided that the following conditions are met:
10
 
 *
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.
19
 
 *
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.
29
 
 *
30
 
 */
31
 
 
32
 
#include "utils.h"
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"
44
 
 
45
 
#include <QtCore>
46
 
#include <QtTest>
47
 
 
48
 
using namespace MaliitKeyboard;
49
 
 
50
 
class TestLanguageLayoutSwitching
51
 
    : public QObject
52
 
{
53
 
    Q_OBJECT
54
 
 
55
 
private:
56
 
    Q_SLOT void initTestCase()
57
 
    {
58
 
        QVERIFY(qputenv("UBUNTU_KEYBOARD_DATA_DIR", TEST_MALIIT_KEYBOARD_DATADIR));
59
 
    }
60
 
 
61
 
    Q_SLOT void testActiveKeyboardId_data()
62
 
    {
63
 
        QTest::addColumn<QString>("keyboard_id");
64
 
        QTest::addColumn<int>("expected_key_count");
65
 
 
66
 
        QTest::newRow("Using invalid keyboard id: expect empty KeyArea.")
67
 
            << "invalid_language_layout_id" << 0;
68
 
 
69
 
        QTest::newRow("Using 'en_gb' as keyboard id: expect KeyArea with 33 keys.")
70
 
            << "en_gb" << 33;
71
 
 
72
 
        QTest::newRow("Using 'de' as keyboard id: expect KeyArea with 36 keys.")
73
 
            << "de" << 36;
74
 
    }
75
 
 
76
 
    Q_SLOT void testActiveKeyboardId()
77
 
    {
78
 
        QFETCH(QString, keyboard_id);
79
 
        QFETCH(int, expected_key_count);
80
 
 
81
 
        Logic::LayoutUpdater layout_updater;
82
 
 
83
 
        uiConst->initDynamicLayout( TEST_QML_DATADIR "/maliit-ui-constants.qml" );
84
 
 
85
 
        Logic::LayoutHelper layout(new Logic::LayoutHelper);
86
 
        layout_updater.setLayout(&layout);
87
 
 
88
 
        SharedStyle style(new Style);
89
 
        layout_updater.setStyle(style);
90
 
 
91
 
        layout_updater.setActiveKeyboardId(keyboard_id);
92
 
        TestUtils::waitForSignal(&layout, SIGNAL(centerPanelChanged(KeyArea,Logic::KeyOverrides)));
93
 
 
94
 
        QCOMPARE(layout.activePanel(), Logic::LayoutHelper::CenterPanel);
95
 
        QCOMPARE(layout.activeKeyArea().keys().count(), expected_key_count);
96
 
    }
97
 
 
98
 
    // Note: this feature is not important in Ubuntu UX
99
 
 
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
104
 
    // keys.
105
 
    Q_SLOT void testLayoutSwitchKeys()
106
 
    {
107
 
        Key left_layout;
108
 
        left_layout.setAction(Key::ActionLeftLayout);
109
 
 
110
 
        Key right_layout;
111
 
        right_layout.setAction(Key::ActionRightLayout);
112
 
 
113
 
        Editor editor(EditorOptions(), new Model::Text,
114
 
                      new Logic::WordEngineProbe, new Logic::LanguageFeatures);
115
 
        InputMethodHostProbe probe;
116
 
        editor.setHost(&probe);
117
 
 
118
 
        QSignalSpy left_spy(&editor, SIGNAL(leftLayoutSelected()));
119
 
        QSignalSpy right_spy(&editor, SIGNAL(rightLayoutSelected()));
120
 
 
121
 
        editor.onKeyPressed(left_layout);
122
 
        QCOMPARE(left_spy.count(), 0);
123
 
 
124
 
        editor.onKeyReleased(left_layout);
125
 
        QCOMPARE(left_spy.count(), 1);
126
 
 
127
 
        editor.onKeyPressed(right_layout);
128
 
        QCOMPARE(right_spy.count(), 0);
129
 
 
130
 
        editor.onKeyReleased(right_layout);
131
 
        QCOMPARE(right_spy.count(), 1);
132
 
    }
133
 
};
134
 
 
135
 
QTEST_MAIN(TestLanguageLayoutSwitching)
136
 
#include "ut_language-layout-switching.moc"