~mterry/+junk/u8.2

« back to all changes in this revision

Viewing changes to tests/plugins/Ubuntu/Gestures/tst_DirectionalDragArea.cpp

  • Committer: Michael Terry
  • Date: 2014-11-17 14:56:04 UTC
  • mfrom: (1317.1.118 unity8)
  • Revision ID: michael.terry@canonical.com-20141117145604-96dn9p5nwkifq2f4
MergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include <QPointer>
22
22
#include <private/qquickmousearea_p.h>
23
23
 
24
 
// C++ std lib
25
 
#include <functional>
26
24
 
27
25
#include <DirectionalDragArea.h>
28
26
#include <TouchRegistry.h>
31
29
 
32
30
using namespace UbuntuGestures;
33
31
 
34
 
class TouchMemento {
35
 
public:
36
 
    TouchMemento(const QTouchEvent *touchEvent);
37
 
    Qt::TouchPointStates touchPointStates;
38
 
    QList<QTouchEvent::TouchPoint> touchPoints;
39
 
 
40
 
    bool containsTouchWithId(int touchId) const;
41
 
};
42
 
 
43
 
class DummyItem : public QQuickItem
44
 
{
45
 
    Q_OBJECT
46
 
public:
47
 
    DummyItem(QQuickItem *parent = 0);
48
 
 
49
 
    QList<TouchMemento> touchEvents;
50
 
    std::function<void(QTouchEvent*)> touchEventHandler;
51
 
protected:
52
 
    void touchEvent(QTouchEvent *event) override;
53
 
private:
54
 
    static void defaultTouchEventHandler(QTouchEvent *event);
55
 
};
56
32
 
57
33
class ComplexFakeTimer : public FakeTimer
58
34
{
149
125
 
150
126
private:
151
127
    void passTime(qint64 timeSpanMs);
152
 
    TouchRegistry *touchRegistry;
153
128
    ComplexFakeTimer *fakeTimer;
154
129
    QSharedPointer<FakeTimeSource> fakeTimeSource;
155
130
};
171
146
    QTRY_COMPARE(m_view->width(), (int)m_view->rootObject()->width());
172
147
    QTRY_COMPARE(m_view->height(), (int)m_view->rootObject()->height());
173
148
 
174
 
    touchRegistry = new TouchRegistry;
175
 
    m_view->installEventFilter(touchRegistry);
176
 
 
177
149
    fakeTimeSource.reset(new FakeTimeSource);
178
150
    fakeTimer = new ComplexFakeTimer(fakeTimeSource);
179
151
}
180
152
 
181
153
void tst_DirectionalDragArea::cleanup()
182
154
{
183
 
    m_view->removeEventFilter(touchRegistry);
184
 
    delete touchRegistry;
185
 
    touchRegistry = nullptr;
186
 
 
187
155
    delete fakeTimer;
188
156
    fakeTimer = 0;
189
157
 
1015
983
    QPoint touchPos(edgeDragArea->width()/2.0f, m_view->height()/2.0f);
1016
984
 
1017
985
    dummyItem->touchEventHandler = [&](QTouchEvent *event) {
1018
 
        touchRegistry->addCandidateOwnerForTouch(0, dummyItem);
 
986
        m_touchRegistry->addCandidateOwnerForTouch(0, dummyItem);
1019
987
        event->ignore();
1020
988
    };
1021
989
 
1023
991
 
1024
992
    QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::Undecided);
1025
993
 
1026
 
    touchRegistry->requestTouchOwnership(0, dummyItem);
 
994
    m_touchRegistry->requestTouchOwnership(0, dummyItem);
1027
995
 
1028
996
    QCOMPARE((int)edgeDragArea->status(), (int)DirectionalDragArea::WaitingForTouch);
1029
997
 
1172
1140
 
1173
1141
    // edgeDragArea should be an undecided candidate
1174
1142
    {
1175
 
        auto touchInfo = touchRegistry->findTouchInfo(0);
 
1143
        auto touchInfo = m_touchRegistry->findTouchInfo(0);
1176
1144
        QCOMPARE(touchInfo->candidates.size(), 1);
1177
1145
        QCOMPARE(touchInfo->candidates.at(0).item.data(), edgeDragArea);
1178
1146
        QCOMPARE(touchInfo->candidates.at(0).undecided, true);
1188
1156
 
1189
1157
    // edgeDragArea should no longer be a candidate
1190
1158
    {
1191
 
        auto touchInfo = touchRegistry->findTouchInfo(0);
 
1159
        auto touchInfo = m_touchRegistry->findTouchInfo(0);
1192
1160
        QCOMPARE(touchInfo->candidates.size(), 0);
1193
1161
    }
1194
1162
 
1289
1257
    QTest::touchEvent(m_view, m_device).release(0, touchPoint.toPoint());
1290
1258
}
1291
1259
 
1292
 
////////////////////////// TouchMemento /////////////////////////////
1293
 
 
1294
 
TouchMemento::TouchMemento(const QTouchEvent *touchEvent)
1295
 
    : touchPointStates(touchEvent->touchPointStates()), touchPoints(touchEvent->touchPoints())
1296
 
{
1297
 
 
1298
 
}
1299
 
 
1300
 
bool TouchMemento::containsTouchWithId(int touchId) const
1301
 
{
1302
 
    for (int i = 0; i < touchPoints.count(); ++i) {
1303
 
        if (touchPoints.at(i).id() == touchId) {
1304
 
            return true;
1305
 
        }
1306
 
    }
1307
 
    return false;
1308
 
}
1309
 
 
1310
 
////////////////////////// DummyItem /////////////////////////////
1311
 
 
1312
 
DummyItem::DummyItem(QQuickItem *parent)
1313
 
    : QQuickItem(parent)
1314
 
{
1315
 
    touchEventHandler = defaultTouchEventHandler;
1316
 
}
1317
 
 
1318
 
void DummyItem::touchEvent(QTouchEvent *event)
1319
 
{
1320
 
    touchEvents.append(TouchMemento(event));
1321
 
    touchEventHandler(event);
1322
 
}
1323
 
 
1324
 
void DummyItem::defaultTouchEventHandler(QTouchEvent *event)
1325
 
{
1326
 
    event->accept();
1327
 
}
1328
 
 
1329
1260
QTEST_MAIN(tst_DirectionalDragArea)
1330
1261
 
1331
1262
#include "tst_DirectionalDragArea.moc"