~michael-sheldon/ubuntu-keyboard/fix-oxide-dismiss-test

« back to all changes in this revision

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

  • Committer: Guenter Schwann
  • Date: 2013-10-24 10:17:12 UTC
  • mto: This revision was merged to the branch mainline in revision 87.
  • Revision ID: guenter.schwann@canonical.com-20131024101712-82euciqg8delaxie
Reorganize tests let "make check" pass

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
    void connectUiConstToScreen(const MockScreen& mockScreen)
 
46
    {
 
47
        const QScreen* screen = qGuiApp->primaryScreen();
 
48
        disconnect( screen, SIGNAL(primaryOrientationChanged(Qt::ScreenOrientation)), uiConst, SLOT(onPrimaryOrientationChanged(Qt::ScreenOrientation)) );
 
49
        disconnect( screen, SIGNAL(orientationChanged(Qt::ScreenOrientation)), uiConst, SLOT(onPrimaryOrientationChanged(Qt::ScreenOrientation)) );
 
50
        disconnect( screen, SIGNAL(geometryChanged(QRect)), uiConst, SLOT(onGeometryChanged(QRect)) );
 
51
 
 
52
        connect( &mockScreen, SIGNAL(primaryOrientationChanged(Qt::ScreenOrientation)), uiConst, SLOT(onPrimaryOrientationChanged(Qt::ScreenOrientation)) );
 
53
        connect( &mockScreen, SIGNAL(orientationChanged(Qt::ScreenOrientation)), uiConst, SLOT(onPrimaryOrientationChanged(Qt::ScreenOrientation)) );
 
54
        connect( &mockScreen, SIGNAL(geometryChanged(QRect)), uiConst, SLOT(onGeometryChanged(QRect)) );
 
55
    }
 
56
 
 
57
  Q_SLOT void dynamicLayout()
 
58
  {
 
59
        uiConst->instance();
 
60
        QVERIFY(uiConst);
 
61
 
 
62
        MockScreen mockScreen;
 
63
        connectUiConstToScreen(mockScreen);
 
64
 
 
65
        mockScreen.setGeometry(QRect(0,0, 300,400));
 
66
        mockScreen.setOrientation(Qt::PortraitOrientation);
 
67
        mockScreen.setPrimaryOrientation(Qt::PortraitOrientation);
 
68
 
 
69
        uiConst->initDynamicLayout( "maliit-keyboard/tests/unittests/dynamic-layout/test-ui-constants.qml" );
 
70
        QCOMPARE( uiConst->windowGeometryRect(Qt::PortraitOrientation).width(), 300 );
 
71
 
 
72
        KeyboardLoader loader;
 
73
        loader.setActiveId("en_us");    // TODO add a test layout
 
74
        Keyboard kb = loader.keyboard();
 
75
 
 
76
        QVERIFY(kb.keys.size() > 0);
 
77
        QVERIFY2(kb.keys.size() == 33, "test if en_us layout contains 33 keys");
 
78
 
 
79
        uiConst->reset();
 
80
        connectUiConstToScreen(mockScreen);
 
81
 
 
82
        // this is important, so uiConst gets signals and changes internally
 
83
        mockScreen.setGeometry( referenceScreenGeometry );
 
84
        mockScreen.setOrientation(Qt::PortraitOrientation);
 
85
        mockScreen.setPrimaryOrientation(Qt::PortraitOrientation);
 
86
 
 
87
        uiConst->initDynamicLayout( "maliit-keyboard/tests/dynamic-layout/test-ui-constants.qml" );
 
88
 
 
89
        QCOMPARE( uiConst->windowGeometryRect(Qt::PortraitOrientation).width(), 720 );
 
90
 
 
91
        // this should remain the same even if we rotate the screen, as we depend on contentOrientation
 
92
        mockScreen.setOrientation(Qt::LandscapeOrientation);
 
93
        QCOMPARE( uiConst->windowGeometryRect(Qt::PortraitOrientation).width(), 720 );
 
94
 
 
95
        // virtual width depending on contentOrientation
 
96
        QCOMPARE( uiConst->windowWidth(LayoutHelper::Portrait), 720 );
 
97
        QCOMPARE( uiConst->windowWidth(LayoutHelper::Landscape), 1280 );
 
98
 
 
99
        // not sure if we need this in future
 
100
        QVector<int> margins = uiConst->calculateMargins(LayoutHelper::Portrait, kb);
 
101
        QVERIFY( margins[0] > 0 );
 
102
 
 
103
        // TODO orientation argument not needed, qreal not needed
 
104
        QCOMPARE( uiConst->keyWidth(LayoutHelper::Portrait, KeyDescription::Small),     10.0 );
 
105
        QCOMPARE( uiConst->keyWidth(LayoutHelper::Portrait, KeyDescription::Medium),    12.0 );
 
106
        QCOMPARE( uiConst->keyWidth(LayoutHelper::Portrait, KeyDescription::Large),     15.0 );
 
107
        QCOMPARE( uiConst->keyWidth(LayoutHelper::Portrait, KeyDescription::XLarge),    18.0 );
 
108
        QCOMPARE( uiConst->keyWidth(LayoutHelper::Portrait, KeyDescription::XXLarge),   24.0 );
 
109
        QCOMPARE( uiConst->keyWidth(LayoutHelper::Portrait, KeyDescription::Stretched), 30.0 );
 
110
 
 
111
        // keyHeight() not tested, calculated
 
112
 
 
113
        QCOMPARE( uiConst->fontSize(LayoutHelper::Portrait), 12.0 );
 
114
        QCOMPARE( uiConst->fontSizeSmall(LayoutHelper::Portrait), 10.0 );
 
115
  }
 
116
 
 
117
    /*
 
118
     *  Area
 
119
     *      size                    QSize
 
120
     *      background              QByteArray
 
121
     *      backgroundBorders       QMargins
 
122
     *
 
123
     *  Key
 
124
     *      origin                  QPoint
 
125
     *      area                    Area
 
126
     *      label                   Label
 
127
     *      action                  Action
 
128
     *      style                   Key::Style (normal, special, dead)
 
129
     *      margins                 QMargins
 
130
     *      icon                    QByteArray
 
131
     *      has_extended_keys       bool
 
132
     *      flags_padding           int
 
133
     *      command_sequence        QString
 
134
     *
 
135
     *  Label
 
136
     *      text                    QString
 
137
     *      font                    Font
 
138
     *      rect                    QRect
 
139
     *
 
140
     *  Font
 
141
     *      name                    QByteArray
 
142
     *      size                    int
 
143
     *      color                   QByteArray
 
144
     *      stretch                 int
 
145
     *
 
146
     *  KeyDescription
 
147
     *      row                     int
 
148
     *      flags: left|right spacer, rtl-icon
 
149
     *      width                   KeyDescription::Width (Small, Medium, ...)
 
150
     *      icon                    KeyDescription::Icon (no, return, backspace, shift, ...)
 
151
     *      font_group              KeyDescription::FontGroup (normal, big)
 
152
     *
 
153
     *  Keyboard
 
154
     *      style name              QString
 
155
     *      keys                    vector of Key
 
156
     *      descriptions            vector of KeyDescription
 
157
     *
 
158
     *  KeyArea
 
159
     *      keys                    vector of Keys
 
160
     *      origin                  QPoint
 
161
     *      area                    Area
 
162
     *      margin                  qreal
 
163
     **/
 
164
 
 
165
 
 
166
  Q_SLOT void keyAreaConverter()
 
167
  {
 
168
        KeyboardLoader loader;
 
169
        loader.setActiveId("en_us");
 
170
 
 
171
        // this really seems overkill
 
172
        Style* style = new Style;
 
173
        style->setProfile("ubuntu");
 
174
 
 
175
        KeyAreaConverter converter(style->attributes(), &loader);
 
176
        converter.setLayoutOrientation(MaliitKeyboard::Logic::LayoutHelper::Portrait);
 
177
 
 
178
        KeyArea area = converter.keyArea();
 
179
 
 
180
        QVERIFY2( area.keys().size() == 33, "Make sure all keys are in keyarea" );
 
181
  }
 
182
};
 
183
 
 
184
 
 
185
QTEST_MAIN(TestDynamicLayout)
 
186
#include "ut_dynamic-layout.moc"