File: tst_lomiritestcase.qml

package info (click to toggle)
lomiri-ui-toolkit 1.3.5010%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 25,900 kB
  • sloc: cpp: 85,772; python: 5,528; sh: 1,364; javascript: 919; ansic: 573; makefile: 204
file content (310 lines) | stat: -rw-r--r-- 9,155 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
/*
 * Copyright 2012 Canonical Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; version 3.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import QtQuick 2.0
import QtTest 1.0
import Lomiri.Test 1.0
import Lomiri.Components 1.0

Rectangle {
 id: root
 width: 800
 height: 1000

 Column {
     anchors.fill: parent
     MultiPointTouchArea {
         id: topTouchArea
         width: parent.width
         height: 100
         touchPoints: TouchPoint {
//             id: point
         }
     }
     MouseArea {
        id: mouseArea
        objectName: "myMouseArea"
        width: parent.width
        height: 200
        hoverEnabled: true
        acceptedButtons: Qt.LeftButton | Qt.MiddleButton | Qt.RightButton
        property int testX : 0
        property int testY : 0
        property int steps : 0

        onPositionChanged: {
           testX = mouseX;
           testY = mouseY;
           steps++;
        }
     }
     MultiPointTouchArea {
         id: touchArea
         width: parent.width
         height: 100
         touchPoints: TouchPoint {
             id: point
         }
     }

     Flickable {
         id: flicker
         width: parent.width
         height: 400
         contentWidth: rect.width
         contentHeight: rect.height
         clip: true
         Rectangle {
             id: rect
             color: "blue"
             width: 1000
             height: 1000
         }
     }
     TextField {
         id: textField
     }
 }
 
 LomiriTestCase {
    name: "TestTheLomiriTestCase"
    when: windowShown

    function initTestCase() {
        TestExtras.registerTouchDevice();
    }

    function init() {
        mouseArea.steps = 0;
    }
    function cleanup() {
        movementSpy.clear();
        longPressSpy.clear();
        touchPressSpy.clear();
        touchReleaseSpy.clear();
        touchUpdateSpy.clear();
        touchPressSpy.target = null;
        touchReleaseSpy.target = null;
        touchUpdateSpy.target = null;
    }

    function test_mouseMoveSlowly() {
       mouseMoveSlowly(mouseArea,0,0,800,200,10,100);
       compare(mouseArea.testX,800);
       compare(mouseArea.testY,200);
       compare(mouseArea.steps,10);
    }

    function test_findChild() {
        var child = findChild(root,"myMouseArea");
        compare(child!==null,true, "When a child is found, it is returned");
        compare(child.objectName,"myMouseArea");

        child = findChild(root,"NoSuchChildHere");
        compare(child===null,true,"When there is no child, function should return null");
    }

    SignalSpy {
        id: longPressSpy
        target: mouseArea
        signalName: "onPressAndHold"
    }

    function test_longPress_left() {
        longPressSpy.clear();
        mouseLongPress(mouseArea, mouseArea.width / 2, mouseArea.height / 2);
        longPressSpy.wait();
        // cleanup
        mouseRelease(mouseArea, mouseArea.width / 2, mouseArea.height / 2);
    }

    function test_longPress_right() {
        longPressSpy.clear();
        mouseLongPress(mouseArea, mouseArea.width / 2, mouseArea.height / 2, Qt.RightButton);
        longPressSpy.wait();
        // cleanup
        mouseRelease(mouseArea, mouseArea.width / 2, mouseArea.height / 2, Qt.RightButton);
    }

    function test_longPress_middle() {
        longPressSpy.clear();
        mouseLongPress(mouseArea, mouseArea.width / 2, mouseArea.height / 2, Qt.MiddleButton);
        longPressSpy.wait();
        // cleanup
        mouseRelease(mouseArea, mouseArea.width / 2, mouseArea.height / 2, Qt.MiddleButton);
    }

    SignalSpy {
        id: movementSpy
        target: flicker
        signalName: "onMovementEnded"
    }

    function test_flick_default() {
        flick(flicker, 0, 0, flicker.width, flicker.height);
        movementSpy.wait();
    }
    function test_flick_long() {
        flick(flicker, 0, 0, flicker.width, flicker.height, -1, 10);
        movementSpy.wait();
    }
    function test_flick_short() {
        flick(flicker, 0, 0, flicker.width, flicker.height, -1, 1);
        movementSpy.wait();
    }
    function test_flick_pressTimeout() {
        flick(flicker, 0, 0, flicker.width, flicker.height, 400);
        movementSpy.wait();
    }
    function test_flick_pressTimeout_short() {
        flick(flicker, flicker.width, flicker.height, -flicker.width, -flicker.height, 400, 1);
        movementSpy.wait();
    }
    function test_flick_pressTimeout_long() {
        flick(flicker, flicker.width, flicker.height, -flicker.width, -flicker.height, 400, 100);
        movementSpy.wait();
    }
    function test_typeString() {
        textField.forceActiveFocus();
        typeString("Hello Lomiri");
        tryCompare(textField, "text", "Hello Lomiri");
    }

    SignalSpy {
        id: touchPressSpy
        signalName: "onPressed"
        target: touchArea
    }
    SignalSpy {
        id: touchReleaseSpy
        signalName: "onReleased"
        target: touchArea
    }
    SignalSpy {
        id: touchUpdateSpy
        signalName: "onUpdated"
        target: touchArea
    }

    function test_has_property() {
        verify(TestExtras.hasOwnProperty("touchPresent"), "touchPresent property missing");
    }

    function test_touchPress_data() {
        return [
            {touch: touchArea},
            {touch: topTouchArea}
        ];
    }
    function test_touchPress(data) {
        touchPressSpy.target = data.touch;
        TestExtras.touchPress(0, data.touch, Qt.point(10, 10));
        touchPressSpy.wait();
        // cleanup
        TestExtras.touchRelease(0, data.touch, Qt.point(10, 10));
    }

    function test_touchRelease_data() {
        return [
            {touch: touchArea},
            {touch: topTouchArea}
        ];
    }
    function test_touchRelease(data) {
        // prerequisite: do a press so we get a release
        TestExtras.touchPress(0, data.touch, Qt.point(10, 10));

        touchReleaseSpy.target = data.touch;
        TestExtras.touchRelease(0, data.touch, Qt.point(10, 10));
        touchReleaseSpy.wait();
    }

    function test_touchClick_data() {
        return [
            {touch: touchArea},
            {touch: topTouchArea}
        ];
    }
    function test_touchClick(data) {
        touchPressSpy.target = data.touch;
        touchReleaseSpy.target = data.touch;
        TestExtras.touchClick(0, data.touch, Qt.point(10, 10));
        touchReleaseSpy.wait();
        compare(touchPressSpy.count, 1, "Not pressed?");
        compare(touchReleaseSpy.count, 1, "Not released?");
    }

    function test_touchDoubleClick_data() {
        return [
            {touch: touchArea},
            {touch: topTouchArea}
        ];
    }
    function test_touchDoubleClick(data) {
        touchPressSpy.target = data.touch;
        touchReleaseSpy.target = data.touch;
        TestExtras.touchDoubleClick(0, data.touch, Qt.point(10, 10));
        compare(touchPressSpy.count, 2, "Not pressed twice?");
        compare(touchReleaseSpy.count, 2, "Not released twice?");
    }

    function test_touchMove_data() {
        return [
            {touch: touchArea},
            {touch: topTouchArea}
        ];
    }
    function test_touchMove(data) {
        touchUpdateSpy.target = data.touch;
        TestExtras.touchPress(0, data.touch, Qt.point(0, 0));
        TestExtras.touchMove(0, data.touch, Qt.point(10, 10));
        touchUpdateSpy.wait();
        TestExtras.touchRelease(0, data.touch, Qt.point(10, 10));
    }

    function test_touchDrag_default_steps_data() {
        return [
            {touch: touchArea},
            {touch: topTouchArea}
        ];
    }
    function test_touchDrag_default_steps(data) {
        touchPressSpy.target = data.touch;
        touchReleaseSpy.target = data.touch;
        touchUpdateSpy.target = data.touch;
        TestExtras.touchDrag(0, data.touch, Qt.point(0, 0), Qt.point(10, 10));
        compare(touchPressSpy.count, 1, "Not pressed?");
        compare(touchReleaseSpy.count, 1, "Not released?");
        compare(touchUpdateSpy.count, 5, "Not moved?");
    }

    function test_touchDrag_10_steps_data() {
        return [
            {touch: touchArea},
            {touch: topTouchArea}
        ];
    }
    function test_touchDrag_10_steps(data) {
        touchPressSpy.target = data.touch;
        touchReleaseSpy.target = data.touch;
        touchUpdateSpy.target = data.touch;
        TestExtras.touchDrag(0, data.touch, Qt.point(0, 0), Qt.point(100, 100), 10);
        compare(touchPressSpy.count, 1, "Not pressed?");
        compare(touchReleaseSpy.count, 1, "Not released?");
        compare(touchUpdateSpy.count, 10, "Not moved?");
    }
 }
}