on xenial help sign in
Better error message if the item does not exist
4a93bc7Albert Astals Cid
tests/utils/modules/Unity/Test/UnityTestCase.qml+84−7
@@ -50,8 +50,11 @@ TestCase {
50 this.getCurrentTimeMs = function() {return this.currentTimeMs}
50 this.getCurrentTimeMs = function() {return this.currentTimeMs}
51 }
51 }
52
52
53− // TODO This function can be removed altogether once we use Qt 5.5 which has the same feature
53+ // TODO This function can be removed altogether once we use Qt 5.7 which has the same feature
54 function mouseClick(item, x, y, button, modifiers, delay) {
54 function mouseClick(item, x, y, button, modifiers, delay) {
55+ if (!item)
56+ qtest_fail("no item given", 1);
57+
55 if (button === undefined)
58 if (button === undefined)
56 button = Qt.LeftButton;
59 button = Qt.LeftButton;
57 if (modifiers === undefined)
60 if (modifiers === undefined)
@@ -66,8 +69,11 @@ TestCase {
66 qtest_fail("window not shown", 2);
69 qtest_fail("window not shown", 2);
67 }
70 }
68
71
69− // TODO This function can be removed altogether once we use Qt 5.5 which has the same feature
72+ // TODO This function can be removed altogether once we use Qt 5.7 which has the same feature
70 function mouseDoubleClick(item, x, y, button, modifiers, delay) {
73 function mouseDoubleClick(item, x, y, button, modifiers, delay) {
74+ if (!item)
75+ qtest_fail("no item given", 1);
76+
71 if (button === undefined)
77 if (button === undefined)
72 button = Qt.LeftButton;
78 button = Qt.LeftButton;
73 if (modifiers === undefined)
79 if (modifiers === undefined)
@@ -82,8 +88,11 @@ TestCase {
82 qtest_fail("window not shown", 2)
88 qtest_fail("window not shown", 2)
83 }
89 }
84
90
85− // TODO This function can be removed altogether once we use Qt 5.5 which has the same feature
91+ // TODO This function can be removed altogether once we use Qt 5.7 which has the same feature
86 function mousePress(item, x, y, button, modifiers, delay) {
92 function mousePress(item, x, y, button, modifiers, delay) {
93+ if (!item)
94+ qtest_fail("no item given", 1);
95+
87 if (button === undefined)
96 if (button === undefined)
88 button = Qt.LeftButton;
97 button = Qt.LeftButton;
89 if (modifiers === undefined)
98 if (modifiers === undefined)
@@ -98,8 +107,11 @@ TestCase {
98 qtest_fail("window not shown", 2)
107 qtest_fail("window not shown", 2)
99 }
108 }
100
109
101− // TODO This function can be removed altogether once we use Qt 5.5 which has the same feature
110+ // TODO This function can be removed altogether once we use Qt 5.7 which has the same feature
102 function mouseRelease(item, x, y, button, modifiers, delay) {
111 function mouseRelease(item, x, y, button, modifiers, delay) {
112+ if (!item)
113+ qtest_fail("no item given", 1);
114+
103 if (button === undefined)
115 if (button === undefined)
104 button = Qt.LeftButton;
116 button = Qt.LeftButton;
105 if (modifiers === undefined)
117 if (modifiers === undefined)
@@ -121,6 +133,9 @@ TestCase {
121 // speed is in pixels/second
133 // speed is in pixels/second
122 function mouseFlick(item, x, y, toX, toY, pressMouse, releaseMouse,
134 function mouseFlick(item, x, y, toX, toY, pressMouse, releaseMouse,
123 speed, iterations) {
135 speed, iterations) {
136+ if (!item)
137+ qtest_fail("no item given", 1);
138+
124 pressMouse = ((pressMouse != null) ? pressMouse : true); // Default to true for pressMouse if not present
139 pressMouse = ((pressMouse != null) ? pressMouse : true); // Default to true for pressMouse if not present
125 releaseMouse = ((releaseMouse != null) ? releaseMouse : true); // Default to true for releaseMouse if not present
140 releaseMouse = ((releaseMouse != null) ? releaseMouse : true); // Default to true for releaseMouse if not present
126
141
@@ -159,6 +174,9 @@ TestCase {
159
174
160 // Find an object with the given name in the children tree of "obj"
175 // Find an object with the given name in the children tree of "obj"
161 function findChild(obj, objectName) {
176 function findChild(obj, objectName) {
177+ if (!obj)
178+ qtest_fail("no obj given", 1);
179+
162 return findChildIn(obj, "children", objectName);
180 return findChildIn(obj, "children", objectName);
163 }
181 }
164
182
@@ -168,11 +186,17 @@ TestCase {
168 // as this tree is much bigger and might contain stuff that goes
186 // as this tree is much bigger and might contain stuff that goes
169 // away randomly.
187 // away randomly.
170 function findInvisibleChild(obj, objectName) {
188 function findInvisibleChild(obj, objectName) {
189+ if (!obj)
190+ qtest_fail("no obj given", 1);
191+
171 return findChildIn(obj, "data", objectName);
192 return findChildIn(obj, "data", objectName);
172 }
193 }
173
194
174 // Find a child in the named property
195 // Find a child in the named property
175 function findChildIn(obj, prop, objectName) {
196 function findChildIn(obj, prop, objectName) {
197+ if (!obj)
198+ qtest_fail("no obj given", 1);
199+
176 var childs = new Array(0);
200 var childs = new Array(0);
177 childs.push(obj)
201 childs.push(obj)
178 while (childs.length > 0) {
202 while (childs.length > 0) {
@@ -188,6 +212,9 @@ TestCase {
188 }
212 }
189
213
190 function findChildsByType(obj, typeName) {
214 function findChildsByType(obj, typeName) {
215+ if (!obj)
216+ qtest_fail("no obj given", 1);
217+
191 var res = new Array(0);
218 var res = new Array(0);
192 for (var i in obj.children) {
219 for (var i in obj.children) {
193 var c = obj.children[i];
220 var c = obj.children[i];
@@ -235,6 +262,9 @@ TestCase {
235 }
262 }
236
263
237 function flickToYEnd(item) {
264 function flickToYEnd(item) {
265+ if (!item)
266+ qtest_fail("no item given", 1);
267+
238 var i = 0;
268 var i = 0;
239 var x = item.width / 2;
269 var x = item.width / 2;
240 var y = item.height - units.gu(1);
270 var y = item.height - units.gu(1);
@@ -254,6 +284,9 @@ TestCase {
254
284
255 // speed is in pixels/second
285 // speed is in pixels/second
256 function touchFlick(item, x, y, toX, toY, beginTouch, endTouch, speed, iterations) {
286 function touchFlick(item, x, y, toX, toY, beginTouch, endTouch, speed, iterations) {
287+ if (!item)
288+ qtest_fail("no item given", 1);
289+
257 // Make sure the item is rendered
290 // Make sure the item is rendered
258 waitForRendering(item);
291 waitForRendering(item);
259
292
@@ -313,10 +346,16 @@ TestCase {
313 // perform a drag in the given direction until the given condition is true
346 // perform a drag in the given direction until the given condition is true
314 // The condition is a function to be evaluated after every step
347 // The condition is a function to be evaluated after every step
315 function touchDragUntil(item, startX, startY, stepX, stepY, condition) {
348 function touchDragUntil(item, startX, startY, stepX, stepY, condition) {
349+ if (!item)
350+ qtest_fail("no item given", 1);
351+
316 multiTouchDragUntil([0], item, startX, startY, stepX, stepY, condition);
352 multiTouchDragUntil([0], item, startX, startY, stepX, stepY, condition);
317 }
353 }
318
354
319 function multiTouchDragUntil(touchIds, item, startX, startY, stepX, stepY, condition) {
355 function multiTouchDragUntil(touchIds, item, startX, startY, stepX, stepY, condition) {
356+ if (!item)
357+ qtest_fail("no item given", 1);
358+
320 var root = fetchRootItem(item);
359 var root = fetchRootItem(item);
321 var pos = item.mapToItem(root, startX, startY);
360 var pos = item.mapToItem(root, startX, startY);
322
361
@@ -361,9 +400,17 @@ TestCase {
361 event.commit()
400 event.commit()
362 }
401 }
363
402
364− function touchMove(item, tox, toy) { multiTouchMove(0, item, tox, toy); }
403+ function touchMove(item, tox, toy) {
404+ if (!item)
405+ qtest_fail("no item given", 1);
406+
407+ multiTouchMove(0, item, tox, toy);
408+ }
365
409
366 function multiTouchMove(touchId, item, tox, toy) {
410 function multiTouchMove(touchId, item, tox, toy) {
411+ if (!item)
412+ qtest_fail("no item given", 1);
413+
367 if (typeof touchId !== "number") touchId = 0;
414 if (typeof touchId !== "number") touchId = 0;
368 var root = fetchRootItem(item)
415 var root = fetchRootItem(item)
369 var rootPoint = item.mapToItem(root, tox, toy)
416 var rootPoint = item.mapToItem(root, tox, toy)
@@ -374,6 +421,9 @@ TestCase {
374 }
421 }
375
422
376 function touchPinch(item, x1Start, y1Start, x1End, y1End, x2Start, y2Start, x2End, y2End) {
423 function touchPinch(item, x1Start, y1Start, x1End, y1End, x2Start, y2Start, x2End, y2End) {
424+ if (!item)
425+ qtest_fail("no item given", 1);
426+
377 // Make sure the item is rendered
427 // Make sure the item is rendered
378 waitForRendering(item);
428 waitForRendering(item);
379
429
@@ -400,13 +450,21 @@ TestCase {
400 }
450 }
401
451
402 function fetchRootItem(item) {
452 function fetchRootItem(item) {
453+ if (!item)
454+ qtest_fail("no item given", 1);
455+
403 if (item.parent)
456 if (item.parent)
404 return fetchRootItem(item.parent)
457 return fetchRootItem(item.parent)
405 else
458 else
406 return item
459 return item
407 }
460 }
408
461
409− function touchPress(item, x, y) { multiTouchPress(0, item, x, y, []); }
462+ function touchPress(item, x, y) {
463+ if (!item)
464+ qtest_fail("no item given", 1);
465+
466+ multiTouchPress(0, item, x, y, []);
467+ }
410
468
411 /*! \brief Release a touch point
469 /*! \brief Release a touch point
412
470
@@ -417,6 +475,9 @@ TestCase {
417 \param stationaryPoints An array of touchIds which are "already touched"
475 \param stationaryPoints An array of touchIds which are "already touched"
418 */
476 */
419 function multiTouchPress(touchId, item, x, y, stationaryPoints) {
477 function multiTouchPress(touchId, item, x, y, stationaryPoints) {
478+ if (!item)
479+ qtest_fail("no item given", 1);
480+
420 if (typeof touchId !== "number") touchId = 0;
481 if (typeof touchId !== "number") touchId = 0;
421 if (typeof x !== "number") x = item.width / 2;
482 if (typeof x !== "number") x = item.width / 2;
422 if (typeof y !== "number") y = item.height / 2;
483 if (typeof y !== "number") y = item.height / 2;
@@ -432,7 +493,12 @@ TestCase {
432 event.commit()
493 event.commit()
433 }
494 }
434
495
435− function touchRelease(item, x, y) { multiTouchRelease(0, item, x, y, []); }
496+ function touchRelease(item, x, y) {
497+ if (!item)
498+ qtest_fail("no item given", 1);
499+
500+ multiTouchRelease(0, item, x, y, []);
501+ }
436
502
437 /*! \brief Release a touch point
503 /*! \brief Release a touch point
438
504
@@ -443,6 +509,9 @@ TestCase {
443 \param stationaryPoints An array of touchIds which are "still touched"
509 \param stationaryPoints An array of touchIds which are "still touched"
444 */
510 */
445 function multiTouchRelease(touchId, item, x, y, stationaryPoints) {
511 function multiTouchRelease(touchId, item, x, y, stationaryPoints) {
512+ if (!item)
513+ qtest_fail("no item given", 1);
514+
446 if (typeof touchId !== "number") touchId = 0;
515 if (typeof touchId !== "number") touchId = 0;
447 if (typeof x !== "number") x = item.width / 2;
516 if (typeof x !== "number") x = item.width / 2;
448 if (typeof y !== "number") y = item.height / 2;
517 if (typeof y !== "number") y = item.height / 2;
@@ -465,10 +534,16 @@ TestCase {
465 \param y The y coordinate of the tap, defaults to vertical center
534 \param y The y coordinate of the tap, defaults to vertical center
466 */
535 */
467 function tap(item, x, y) {
536 function tap(item, x, y) {
537+ if (!item)
538+ qtest_fail("no item given", 1);
539+
468 multiTouchTap([0], item, x, y);
540 multiTouchTap([0], item, x, y);
469 }
541 }
470
542
471 function multiTouchTap(touchIds, item, x, y) {
543 function multiTouchTap(touchIds, item, x, y) {
544+ if (!item)
545+ qtest_fail("no item given", 1);
546+
472 if (typeof touchIds !== "object") touchIds = [0];
547 if (typeof touchIds !== "object") touchIds = [0];
473 if (typeof x !== "number") x = item.width / 2;
548 if (typeof x !== "number") x = item.width / 2;
474 if (typeof y !== "number") y = item.height / 2;
549 if (typeof y !== "number") y = item.height / 2;
@@ -508,6 +583,8 @@ TestCase {
508 This effectively makes DirectionalDragAreas easier to fool.
583 This effectively makes DirectionalDragAreas easier to fool.
509 */
584 */
510 function removeTimeConstraintsFromDirectionalDragAreas(item) {
585 function removeTimeConstraintsFromDirectionalDragAreas(item) {
586+ if (!item)
587+ qtest_fail("no item given", 1);
511
588
512 // use duck-typing to identify a DirectionalDragArea
589 // use duck-typing to identify a DirectionalDragArea
513 if (item.removeTimeConstraints != undefined) {
590 if (item.removeTimeConstraints != undefined) {