~nskaggs/ubuntu-ui-toolkit/add-popover-object-support

« back to all changes in this revision

Viewing changes to modules/Ubuntu/Test/plugin/uctestcase.h

  • Committer: CI bot
  • Author(s): Zsombor Egri, Tarmac, Zoltán Balogh
  • Date: 2014-06-18 17:10:31 UTC
  • mfrom: (1000.76.9 landing_04-06)
  • Revision ID: ps-jenkins@lists.canonical.com-20140618171031-1s026ulaxymh2e9f
  [Leo Arias ]
  * On the autopilot helper for the header, fix the swipe to show
    when hidden.
  * Added a fixture for autopilot tests to use a fake home directory.
    Fixes: https://bugs.launchpad.net/bugs/1317639
  * Cleaned the containers in unity test using the alternate
    launcher.

  [ Christian Dywan ]   
  * Add a launcher with a switch for the QQMLEngine.

  [ Tim Peeters ]
  * Anchor the internal PageTreeNode of PageStack to fill its parent.
    Fixes: https://bugs.launchpad.net/bugs/1322527
 

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
#ifndef UBUNTU_TEST_UBUNTUTESTCASE_H
20
20
#define UBUNTU_TEST_UBUNTUTESTCASE_H
21
21
 
 
22
#include <QtTest/QtTest>
22
23
#include <QtQuick/QQuickItem>
23
24
#include <QtQuick/QQuickView>
24
25
#include <QtTest/QSignalSpy>
25
26
 
 
27
#define CHECK_TOUCH_DEVICE()    if (!checkTouchDevice(__FUNCTION__)) return
 
28
 
26
29
class UbuntuTestCase : public QQuickView
27
30
{
28
31
    Q_OBJECT
40
43
            qFatal("Item '%s' found with unexpected type", qPrintable(objectName));
41
44
        qFatal("No item '%s' found", qPrintable(objectName));
42
45
    }
 
46
 
 
47
    static void registerTouchDevice();
 
48
 
 
49
    inline static void touchPress(int touchId, QWindow *window, const QPoint &point)
 
50
    {
 
51
        CHECK_TOUCH_DEVICE();
 
52
        QTest::touchEvent(window, m_touchDevice).press(touchId, point, window);
 
53
    }
 
54
    inline static void touchRelease(int touchId, QWindow *window, const QPoint &point)
 
55
    {
 
56
        CHECK_TOUCH_DEVICE();
 
57
        QTest::touchEvent(window, m_touchDevice).release(touchId, point, window);
 
58
    }
 
59
    inline static void touchClick(int touchId, QWindow *window, const QPoint &point)
 
60
    {
 
61
        CHECK_TOUCH_DEVICE();
 
62
        touchPress(touchId, window, point);
 
63
        QTest::qWait(10);
 
64
        touchRelease(touchId, window, point);
 
65
    }
 
66
    inline static void touchLongPress(int touchId, QWindow *window, const QPoint &point)
 
67
    {
 
68
        CHECK_TOUCH_DEVICE();
 
69
        touchPress(touchId, window, point);
 
70
        QTest::qWait(800);
 
71
    }
 
72
    inline static void touchDoubleClick(int touchId, QWindow *window, const QPoint &point)
 
73
    {
 
74
        CHECK_TOUCH_DEVICE();
 
75
        touchClick(touchId, window, point);
 
76
        QTest::qWait(10);
 
77
        touchClick(touchId, window, point);
 
78
    }
 
79
    inline static void touchMove(int touchId, QWindow *window, const QPoint &point)
 
80
    {
 
81
        CHECK_TOUCH_DEVICE();
 
82
        QTest::touchEvent(window, m_touchDevice).move(touchId, point, window);
 
83
    }
 
84
    inline static void touchDrag(int touchId, QWindow *window, const QPoint &from, const QPoint &delta, int steps = 5)
 
85
    {
 
86
        touchPress(touchId, window, from);
 
87
        QTest::qWait(10);
 
88
        QTest::touchEvent(window, m_touchDevice).move(touchId, from, window);
 
89
        qreal stepDx = delta.x() / steps;
 
90
        qreal stepDy = delta.y() / steps;
 
91
        if (!delta.isNull()) {
 
92
            for (int i = 0; i < steps; i++) {
 
93
                QTest::qWait(10);
 
94
                QTest::touchEvent(window, m_touchDevice).move(touchId, from + QPoint(i * stepDx, i * stepDy), window);
 
95
            }
 
96
        }
 
97
        QTest::qWait(10);
 
98
        touchRelease(touchId, window, from + QPoint(stepDx, stepDy));
 
99
    }
 
100
 
 
101
 
43
102
private:
44
103
    QSignalSpy* m_spy;
 
104
    static QTouchDevice *m_touchDevice;
 
105
 
 
106
    static inline bool checkTouchDevice(const char *func)
 
107
    {
 
108
        if (!m_touchDevice) {
 
109
            qWarning() << QString("No touch device registered. Register one using registerTouchDevice() before using %1").arg(func);
 
110
            return false;
 
111
        }
 
112
        return true;
 
113
    }
45
114
};
46
115
 
47
116
#endif // UBUNTU_TEST_UBUNTUTESTCASE_H