~cherojeong/ubuntu-keyboard/korean-layout

« back to all changes in this revision

Viewing changes to tests/unittests/ut_dynamic-layout/ut_dynamic-layout.cpp

  • Committer: Michael Terry
  • Date: 2013-11-04 17:48:55 UTC
  • mfrom: (96 trunk)
  • mto: This revision was merged to the branch mainline in revision 97.
  • Revision ID: michael.terry@canonical.com-20131104174855-mtmwbdavrq77nl1r
MergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2013 Canonical Ltd.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU Lesser General Public License as published by
 
6
 * the Free Software Foundation; version 3.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU Lesser General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 */
 
16
 
 
17
 
 
18
#include "plugin/inputmethod.h"
 
19
#include "lib/models/wordribbon.h"
 
20
#include "lib/models/styleattributes.h"
 
21
 
 
22
#include "lib/logic/dynamiclayout.h"
 
23
#include "lib/logic/keyboardloader.h"
 
24
#include "lib/logic/layouthelper.h"
 
25
#include "lib/logic/keyareaconverter.h"
 
26
#include "lib/logic/style.h"
 
27
 
 
28
#include "common/inputmethodhostprobe.h"
 
29
#include "common/mockscreen.h"
 
30
 
 
31
#include <maliit/plugins/abstractinputmethodhost.h>
 
32
 
 
33
#include <QtTest/QtTest>
 
34
 
 
35
using namespace MaliitKeyboard;
 
36
using namespace MaliitKeyboard::Logic;
 
37
 
 
38
const QRect referenceScreenGeometry(0,0,720,1280);
 
39
 
 
40
class TestDynamicLayout: public QObject
 
41
{
 
42
  Q_OBJECT
 
43
private:
 
44
 
 
45
    Q_SLOT void initTestCase()
 
46
    {
 
47
        QVERIFY(qputenv("UBUNTU_KEYBOARD_DATA_DIR", TEST_MALIIT_KEYBOARD_DATADIR));
 
48
    }
 
49
 
 
50
    void connectUiConstToScreen(const MockScreen& mockScreen)
 
51
    {
 
52
        const QScreen* screen = qGuiApp->primaryScreen();
 
53
        disconnect( screen, SIGNAL(primaryOrientationChanged(Qt::ScreenOrientation)), uiConst, SLOT(onPrimaryOrientationChanged(Qt::ScreenOrientation)) );
 
54
        disconnect( screen, SIGNAL(orientationChanged(Qt::ScreenOrientation)), uiConst, SLOT(onPrimaryOrientationChanged(Qt::ScreenOrientation)) );
 
55
        disconnect( screen, SIGNAL(geometryChanged(QRect)), uiConst, SLOT(onGeometryChanged(QRect)) );
 
56
 
 
57
        connect( &mockScreen, SIGNAL(primaryOrientationChanged(Qt::ScreenOrientation)), uiConst, SLOT(onPrimaryOrientationChanged(Qt::ScreenOrientation)) );
 
58
        connect( &mockScreen, SIGNAL(orientationChanged(Qt::ScreenOrientation)), uiConst, SLOT(onPrimaryOrientationChanged(Qt::ScreenOrientation)) );
 
59
        connect( &mockScreen, SIGNAL(geometryChanged(QRect)), uiConst, SLOT(onGeometryChanged(QRect)) );
 
60
    }
 
61
 
 
62
  Q_SLOT void dynamicLayout()
 
63
  {
 
64
        uiConst->instance();
 
65
        QVERIFY(uiConst);
 
66
 
 
67
        MockScreen mockScreen;
 
68
        connectUiConstToScreen(mockScreen);
 
69
 
 
70
        mockScreen.setGeometry(QRect(0,0, 300,400));
 
71
        mockScreen.setOrientation(Qt::PortraitOrientation);
 
72
        mockScreen.setPrimaryOrientation(Qt::PortraitOrientation);
 
73
 
 
74
        uiConst->initDynamicLayout( "test-ui-constants.qml" );
 
75
        QCOMPARE( uiConst->windowGeometryRect(Qt::PortraitOrientation).width(), 300 );
 
76
 
 
77
        KeyboardLoader loader;
 
78
        loader.setActiveId("en_us");    // TODO add a test layout
 
79
        Keyboard kb = loader.keyboard();
 
80
 
 
81
        QVERIFY(kb.keys.size() > 0);
 
82
        QVERIFY2(kb.keys.size() == 33, "test if en_us layout contains 33 keys");
 
83
 
 
84
        uiConst->reset();
 
85
        connectUiConstToScreen(mockScreen);
 
86
 
 
87
        // this is important, so uiConst gets signals and changes internally
 
88
        mockScreen.setGeometry( referenceScreenGeometry );
 
89
        mockScreen.setOrientation(Qt::PortraitOrientation);
 
90
        mockScreen.setPrimaryOrientation(Qt::PortraitOrientation);
 
91
 
 
92
        uiConst->initDynamicLayout( "test-ui-constants.qml" );
 
93
 
 
94
        QCOMPARE( uiConst->windowGeometryRect(Qt::PortraitOrientation).width(), 720 );
 
95
 
 
96
        // this should remain the same even if we rotate the screen, as we depend on contentOrientation
 
97
        mockScreen.setOrientation(Qt::LandscapeOrientation);
 
98
        QCOMPARE( uiConst->windowGeometryRect(Qt::PortraitOrientation).width(), 720 );
 
99
 
 
100
        // virtual width depending on contentOrientation
 
101
        QCOMPARE( uiConst->windowWidth(LayoutHelper::Portrait), 720 );
 
102
        QCOMPARE( uiConst->windowWidth(LayoutHelper::Landscape), 1280 );
 
103
 
 
104
        // not sure if we need this in future
 
105
        QVector<int> margins = uiConst->calculateMargins(LayoutHelper::Portrait, kb);
 
106
        QVERIFY( margins[0] > 0 );
 
107
 
 
108
        // TODO orientation argument not needed, qreal not needed
 
109
        QCOMPARE( uiConst->keyWidth(LayoutHelper::Portrait, KeyDescription::Small),     10.0 );
 
110
        QCOMPARE( uiConst->keyWidth(LayoutHelper::Portrait, KeyDescription::Medium),    12.0 );
 
111
        QCOMPARE( uiConst->keyWidth(LayoutHelper::Portrait, KeyDescription::Large),     15.0 );
 
112
        QCOMPARE( uiConst->keyWidth(LayoutHelper::Portrait, KeyDescription::XLarge),    18.0 );
 
113
        QCOMPARE( uiConst->keyWidth(LayoutHelper::Portrait, KeyDescription::XXLarge),   24.0 );
 
114
        QCOMPARE( uiConst->keyWidth(LayoutHelper::Portrait, KeyDescription::Stretched), 30.0 );
 
115
 
 
116
        // keyHeight() not tested, calculated
 
117
 
 
118
        QCOMPARE( uiConst->fontSize(LayoutHelper::Portrait), 12.0 );
 
119
        QCOMPARE( uiConst->fontSizeSmall(LayoutHelper::Portrait), 10.0 );
 
120
  }
 
121
 
 
122
    /*
 
123
     *  Area
 
124
     *      size                    QSize
 
125
     *      background              QByteArray
 
126
     *      backgroundBorders       QMargins
 
127
     *
 
128
     *  Key
 
129
     *      origin                  QPoint
 
130
     *      area                    Area
 
131
     *      label                   Label
 
132
     *      action                  Action
 
133
     *      style                   Key::Style (normal, special, dead)
 
134
     *      margins                 QMargins
 
135
     *      icon                    QByteArray
 
136
     *      has_extended_keys       bool
 
137
     *      flags_padding           int
 
138
     *      command_sequence        QString
 
139
     *
 
140
     *  Label
 
141
     *      text                    QString
 
142
     *      font                    Font
 
143
     *      rect                    QRect
 
144
     *
 
145
     *  Font
 
146
     *      name                    QByteArray
 
147
     *      size                    int
 
148
     *      color                   QByteArray
 
149
     *      stretch                 int
 
150
     *
 
151
     *  KeyDescription
 
152
     *      row                     int
 
153
     *      flags: left|right spacer, rtl-icon
 
154
     *      width                   KeyDescription::Width (Small, Medium, ...)
 
155
     *      icon                    KeyDescription::Icon (no, return, backspace, shift, ...)
 
156
     *      font_group              KeyDescription::FontGroup (normal, big)
 
157
     *
 
158
     *  Keyboard
 
159
     *      style name              QString
 
160
     *      keys                    vector of Key
 
161
     *      descriptions            vector of KeyDescription
 
162
     *
 
163
     *  KeyArea
 
164
     *      keys                    vector of Keys
 
165
     *      origin                  QPoint
 
166
     *      area                    Area
 
167
     *      margin                  qreal
 
168
     **/
 
169
 
 
170
 
 
171
  Q_SLOT void keyAreaConverter()
 
172
  {
 
173
        KeyboardLoader loader;
 
174
        loader.setActiveId("en_us");
 
175
 
 
176
        // this really seems overkill
 
177
        Style* style = new Style;
 
178
        style->setProfile("ubuntu");
 
179
 
 
180
        KeyAreaConverter converter(style->attributes(), &loader);
 
181
        converter.setLayoutOrientation(MaliitKeyboard::Logic::LayoutHelper::Portrait);
 
182
 
 
183
        KeyArea area = converter.keyArea();
 
184
 
 
185
        QVERIFY2( area.keys().size() == 33, "Make sure all keys are in keyarea" );
 
186
  }
 
187
};
 
188
 
 
189
 
 
190
QTEST_MAIN(TestDynamicLayout)
 
191
#include "ut_dynamic-layout.moc"