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

« back to all changes in this revision

Viewing changes to tests/rendering/main.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
 
 * This file is part of Maliit Plugins
3
 
 *
4
 
 * Copyright (C) 2012 One Laptop per Child Association
5
 
 *
6
 
 * Contact: maliit-discuss@lists.maliit.org
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 "logic/layout.h"
34
 
#include "view/renderer.h"
35
 
#include "view/glass.h"
36
 
 
37
 
 
38
 
#include <maliit/plugins/abstractwidgetssurface.h>
39
 
#include <maliit/plugins/abstractsurfacefactory.h>
40
 
 
41
 
#include <QtCore>
42
 
#include <QtGui>
43
 
#include <QtTest>
44
 
 
45
 
using namespace MaliitKeyboard;
46
 
 
47
 
namespace {
48
 
const QSize g_screen_size(200, 100);
49
 
bool g_create_overlay_surfaces(false);
50
 
}
51
 
 
52
 
namespace Maliit {
53
 
namespace Plugins {
54
 
 
55
 
class SurfaceProbe
56
 
    : public virtual AbstractSurface
57
 
{
58
 
private:
59
 
    QSize m_size;
60
 
    QPoint m_relpos;
61
 
    QGraphicsScene *m_scene;
62
 
    QGraphicsView *m_view;
63
 
    QGraphicsItem *m_root;
64
 
 
65
 
public:
66
 
    explicit SurfaceProbe()
67
 
        : m_size()
68
 
        , m_relpos()
69
 
    {}
70
 
 
71
 
    virtual ~SurfaceProbe() {}
72
 
 
73
 
    //! \reimp
74
 
    void show() {}
75
 
    void hide() {}
76
 
 
77
 
    QSize size() const
78
 
    {
79
 
        return m_size;
80
 
    }
81
 
 
82
 
    void setSize(const QSize &size)
83
 
    {
84
 
        m_size = size;
85
 
    }
86
 
 
87
 
    QPoint relativePosition() const
88
 
    {
89
 
        return m_relpos;
90
 
    }
91
 
 
92
 
    void setRelativePosition(const QPoint &position)
93
 
    {
94
 
        m_relpos = position;
95
 
    }
96
 
 
97
 
    QSharedPointer<AbstractSurface> parent() const
98
 
    {
99
 
        return QSharedPointer<AbstractSurface>();
100
 
    }
101
 
 
102
 
    QPoint translateEventPosition(const QPoint &event_position,
103
 
                                  const QSharedPointer<AbstractSurface> &event_surface = QSharedPointer<AbstractSurface>()) const
104
 
    {
105
 
        Q_UNUSED(event_surface)
106
 
        return event_position;
107
 
    }
108
 
};
109
 
 
110
 
class FactoryProbe
111
 
    : public AbstractSurfaceFactory
112
 
{
113
 
public:
114
 
    explicit FactoryProbe() {}
115
 
    virtual ~FactoryProbe() {}
116
 
 
117
 
    //! \reimp
118
 
    QSize screenSize() const
119
 
    {
120
 
        return g_screen_size;
121
 
    }
122
 
 
123
 
    bool supported(AbstractSurface::Options options) const
124
 
    {
125
 
        Q_UNUSED(options);
126
 
        return true;
127
 
    }
128
 
 
129
 
    QSharedPointer<AbstractSurface> create(AbstractSurface::Options options,
130
 
                                           const QSharedPointer<AbstractSurface> &parent = QSharedPointer<AbstractSurface>())
131
 
    {
132
 
        Q_UNUSED(parent)
133
 
 
134
 
        if (not g_create_overlay_surfaces
135
 
            && (options & AbstractSurface::PositionOverlay)) {
136
 
            return QSharedPointer<AbstractSurface>();
137
 
        }
138
 
 
139
 
        QSharedPointer<AbstractSurface> surface(new SurfaceProbe);
140
 
        return surface;
141
 
    }
142
 
};
143
 
 
144
 
class GraphicsViewSurfaceProbe
145
 
    : public SurfaceProbe, public AbstractGraphicsViewSurface
146
 
{
147
 
private:
148
 
    QGraphicsScene *m_scene;
149
 
    QGraphicsView *m_view;
150
 
    QGraphicsItem *m_root;
151
 
 
152
 
public:
153
 
    explicit GraphicsViewSurfaceProbe()
154
 
        : SurfaceProbe()
155
 
        , m_scene(new QGraphicsScene)
156
 
        , m_view(new QGraphicsView(m_scene))
157
 
        , m_root(new QGraphicsRectItem(0))
158
 
    {
159
 
        m_scene->addItem(m_root);
160
 
    }
161
 
 
162
 
    virtual ~GraphicsViewSurfaceProbe() {}
163
 
 
164
 
    QGraphicsScene * scene() const
165
 
    {
166
 
        return m_scene;
167
 
    }
168
 
 
169
 
    QGraphicsView * view() const
170
 
    {
171
 
        return m_view;
172
 
    }
173
 
 
174
 
    QGraphicsItem * root() const
175
 
    {
176
 
        return m_root;
177
 
    }
178
 
 
179
 
    void clear() {};
180
 
};
181
 
 
182
 
class GraphicsViewFactoryProbe
183
 
    : public FactoryProbe
184
 
{
185
 
public:
186
 
    explicit GraphicsViewFactoryProbe() {}
187
 
    virtual ~GraphicsViewFactoryProbe() {}
188
 
 
189
 
    //! \reimp
190
 
    QSharedPointer<AbstractSurface> create(AbstractSurface::Options options,
191
 
                                           const QSharedPointer<AbstractSurface> &parent = QSharedPointer<AbstractSurface>())
192
 
    {
193
 
        Q_UNUSED(parent)
194
 
 
195
 
        if (not g_create_overlay_surfaces
196
 
            && (options & AbstractSurface::PositionOverlay)) {
197
 
            return QSharedPointer<AbstractSurface>();
198
 
        }
199
 
 
200
 
        QSharedPointer<AbstractSurface> surface(new GraphicsViewSurfaceProbe);
201
 
        return surface;
202
 
    }
203
 
};
204
 
 
205
 
}} // namespace Plugins, Maliit
206
 
 
207
 
Q_DECLARE_METATYPE(Maliit::Plugins::AbstractSurfaceFactory *);
208
 
Q_DECLARE_METATYPE(Maliit::Plugins::FactoryProbe *);
209
 
 
210
 
class TestRendering
211
 
    : public QObject
212
 
{
213
 
    Q_OBJECT
214
 
 
215
 
private:
216
 
    Q_SLOT void initTestCase()
217
 
    {}
218
 
 
219
 
    Q_SLOT void testSurfaceFactory_data()
220
 
    {
221
 
        using namespace Maliit::Plugins;
222
 
        AbstractSurfaceFactory *invalid(0);
223
 
        AbstractSurfaceFactory *probe(new FactoryProbe);
224
 
        AbstractSurfaceFactory *specialized_probe(new GraphicsViewFactoryProbe);
225
 
 
226
 
        QTest::addColumn<Maliit::Plugins::AbstractSurfaceFactory *>("factory");
227
 
        QTest::addColumn<bool>("create_overlay_surfaces");
228
 
        QTest::addColumn<bool>("expected_surface_valid");
229
 
 
230
 
        QTest::newRow("invalid factory")
231
 
            << invalid << false << false;
232
 
        QTest::newRow("invalid factory (w/ overlay surfaces)")
233
 
            << invalid << true << false;
234
 
 
235
 
        QTest::newRow("use valid, but wrong factory probe")
236
 
            << probe << false << false;
237
 
        QTest::newRow("use valid, but wrong factory probe (w/ overlay surfaces)")
238
 
            << probe << true << false;
239
 
 
240
 
        QTest::newRow("use valid, specialized factory probe")
241
 
            << specialized_probe << false << true;
242
 
        QTest::newRow("use valid, specialized factory probe (w/ overlay surfaces)")
243
 
            << specialized_probe << true << true;
244
 
    }
245
 
 
246
 
    Q_SLOT void testSurfaceFactory()
247
 
    {
248
 
        QFETCH(Maliit::Plugins::AbstractSurfaceFactory *, factory);
249
 
        QFETCH(bool, create_overlay_surfaces);
250
 
        QFETCH(bool, expected_surface_valid);
251
 
 
252
 
        g_create_overlay_surfaces = create_overlay_surfaces;
253
 
 
254
 
        Renderer renderer;
255
 
        renderer.setSurfaceFactory(factory);
256
 
 
257
 
        Glass glass;
258
 
        glass.setSurface(renderer.surface());
259
 
        glass.setExtendedSurface(renderer.extendedSurface());
260
 
 
261
 
        Logic::Layout layout;
262
 
        glass.addLayout(&layout);
263
 
 
264
 
        QCOMPARE(not renderer.surface().isNull(), expected_surface_valid);
265
 
        QCOMPARE(not renderer.extendedSurface().isNull(), expected_surface_valid && create_overlay_surfaces);
266
 
 
267
 
        renderer.show();
268
 
        renderer.hide();
269
 
    }
270
 
};
271
 
 
272
 
QTEST_MAIN(TestRendering)
273
 
#include "main.moc"