@@ -52,8 +52,11 @@ TestCase {
5252 this.getCurrentTimeMs = function() {return this.currentTimeMs}
5353 }
5454
55− // TODO This function can be removed altogether once we use Qt 5.5 which has the same feature
55+ // TODO This function can be removed altogether once we use Qt 5.7 which has the same feature
5656 function mouseClick(item, x, y, button, modifiers, delay) {
57+ if (!item)
58+ qtest_fail("no item given", 1);
59+
5760 if (button === undefined)
5861 button = Qt.LeftButton;
5962 if (modifiers === undefined)
@@ -68,8 +71,11 @@ TestCase {
6871 qtest_fail("window not shown", 2);
6972 }
7073
71− // TODO This function can be removed altogether once we use Qt 5.5 which has the same feature
74+ // TODO This function can be removed altogether once we use Qt 5.7 which has the same feature
7275 function mouseDoubleClick(item, x, y, button, modifiers, delay) {
76+ if (!item)
77+ qtest_fail("no item given", 1);
78+
7379 if (button === undefined)
7480 button = Qt.LeftButton;
7581 if (modifiers === undefined)
@@ -84,8 +90,11 @@ TestCase {
8490 qtest_fail("window not shown", 2)
8591 }
8692
87− // TODO This function can be removed altogether once we use Qt 5.5 which has the same feature
93+ // TODO This function can be removed altogether once we use Qt 5.7 which has the same feature
8894 function mousePress(item, x, y, button, modifiers, delay) {
95+ if (!item)
96+ qtest_fail("no item given", 1);
97+
8998 if (button === undefined)
9099 button = Qt.LeftButton;
91100 if (modifiers === undefined)
@@ -100,8 +109,11 @@ TestCase {
100109 qtest_fail("window not shown", 2)
101110 }
102111
103− // TODO This function can be removed altogether once we use Qt 5.5 which has the same feature
112+ // TODO This function can be removed altogether once we use Qt 5.7 which has the same feature
104113 function mouseRelease(item, x, y, button, modifiers, delay) {
114+ if (!item)
115+ qtest_fail("no item given", 1);
116+
105117 if (button === undefined)
106118 button = Qt.LeftButton;
107119 if (modifiers === undefined)
@@ -123,6 +135,9 @@ TestCase {
123135 // speed is in pixels/second
124136 function mouseFlick(item, x, y, toX, toY, pressMouse, releaseMouse,
125137 speed, iterations) {
138+ if (!item)
139+ qtest_fail("no item given", 1);
140+
126141 pressMouse = ((pressMouse != null) ? pressMouse : true); // Default to true for pressMouse if not present
127142 releaseMouse = ((releaseMouse != null) ? releaseMouse : true); // Default to true for releaseMouse if not present
128143
@@ -161,6 +176,9 @@ TestCase {
161176
162177 // Find an object with the given name in the children tree of "obj"
163178 function findChild(obj, objectName) {
179+ if (!obj)
180+ qtest_fail("no obj given", 1);
181+
164182 return findChildIn(obj, "children", objectName);
165183 }
166184
@@ -170,11 +188,17 @@ TestCase {
170188 // as this tree is much bigger and might contain stuff that goes
171189 // away randomly.
172190 function findInvisibleChild(obj, objectName) {
191+ if (!obj)
192+ qtest_fail("no obj given", 1);
193+
173194 return findChildIn(obj, "data", objectName);
174195 }
175196
176197 // Find a child in the named property
177198 function findChildIn(obj, prop, objectName) {
199+ if (!obj)
200+ qtest_fail("no obj given", 1);
201+
178202 var childs = new Array(0);
179203 childs.push(obj)
180204 while (childs.length > 0) {
@@ -190,6 +214,9 @@ TestCase {
190214 }
191215
192216 function findChildsByType(obj, typeName) {
217+ if (!obj)
218+ qtest_fail("no obj given", 1);
219+
193220 var res = new Array(0);
194221 for (var i in obj.children) {
195222 var c = obj.children[i];
@@ -237,6 +264,9 @@ TestCase {
237264 }
238265
239266 function flickToYEnd(item) {
267+ if (!item)
268+ qtest_fail("no item given", 1);
269+
240270 var i = 0;
241271 var x = item.width / 2;
242272 var y = item.height - units.gu(1);
@@ -256,6 +286,9 @@ TestCase {
256286
257287 // speed is in pixels/second
258288 function touchFlick(item, x, y, toX, toY, beginTouch, endTouch, speed, iterations) {
289+ if (!item)
290+ qtest_fail("no item given", 1);
291+
259292 // Make sure the item is rendered
260293 waitForRendering(item);
261294
@@ -315,10 +348,16 @@ TestCase {
315348 // perform a drag in the given direction until the given condition is true
316349 // The condition is a function to be evaluated after every step
317350 function touchDragUntil(item, startX, startY, stepX, stepY, condition) {
351+ if (!item)
352+ qtest_fail("no item given", 1);
353+
318354 multiTouchDragUntil([0], item, startX, startY, stepX, stepY, condition);
319355 }
320356
321357 function multiTouchDragUntil(touchIds, item, startX, startY, stepX, stepY, condition) {
358+ if (!item)
359+ qtest_fail("no item given", 1);
360+
322361 var root = fetchRootItem(item);
323362 var pos = item.mapToItem(root, startX, startY);
324363
@@ -363,9 +402,17 @@ TestCase {
363402 event.commit()
364403 }
365404
366− function touchMove(item, tox, toy) { multiTouchMove(0, item, tox, toy); }
405+ function touchMove(item, tox, toy) {
406+ if (!item)
407+ qtest_fail("no item given", 1);
408+
409+ multiTouchMove(0, item, tox, toy);
410+ }
367411
368412 function multiTouchMove(touchId, item, tox, toy) {
413+ if (!item)
414+ qtest_fail("no item given", 1);
415+
369416 if (typeof touchId !== "number") touchId = 0;
370417 var root = fetchRootItem(item)
371418 var rootPoint = item.mapToItem(root, tox, toy)
@@ -376,6 +423,9 @@ TestCase {
376423 }
377424
378425 function touchPinch(item, x1Start, y1Start, x1End, y1End, x2Start, y2Start, x2End, y2End) {
426+ if (!item)
427+ qtest_fail("no item given", 1);
428+
379429 // Make sure the item is rendered
380430 waitForRendering(item);
381431
@@ -402,13 +452,21 @@ TestCase {
402452 }
403453
404454 function fetchRootItem(item) {
455+ if (!item)
456+ qtest_fail("no item given", 1);
457+
405458 if (item.parent)
406459 return fetchRootItem(item.parent)
407460 else
408461 return item
409462 }
410463
411− function touchPress(item, x, y) { multiTouchPress(0, item, x, y, []); }
464+ function touchPress(item, x, y) {
465+ if (!item)
466+ qtest_fail("no item given", 1);
467+
468+ multiTouchPress(0, item, x, y, []);
469+ }
412470
413471 /*! \brief Release a touch point
414472
@@ -419,6 +477,9 @@ TestCase {
419477 \param stationaryPoints An array of touchIds which are "already touched"
420478 */
421479 function multiTouchPress(touchId, item, x, y, stationaryPoints) {
480+ if (!item)
481+ qtest_fail("no item given", 1);
482+
422483 if (typeof touchId !== "number") touchId = 0;
423484 if (typeof x !== "number") x = item.width / 2;
424485 if (typeof y !== "number") y = item.height / 2;
@@ -434,7 +495,12 @@ TestCase {
434495 event.commit()
435496 }
436497
437− function touchRelease(item, x, y) { multiTouchRelease(0, item, x, y, []); }
498+ function touchRelease(item, x, y) {
499+ if (!item)
500+ qtest_fail("no item given", 1);
501+
502+ multiTouchRelease(0, item, x, y, []);
503+ }
438504
439505 /*! \brief Release a touch point
440506
@@ -445,6 +511,9 @@ TestCase {
445511 \param stationaryPoints An array of touchIds which are "still touched"
446512 */
447513 function multiTouchRelease(touchId, item, x, y, stationaryPoints) {
514+ if (!item)
515+ qtest_fail("no item given", 1);
516+
448517 if (typeof touchId !== "number") touchId = 0;
449518 if (typeof x !== "number") x = item.width / 2;
450519 if (typeof y !== "number") y = item.height / 2;
@@ -467,10 +536,16 @@ TestCase {
467536 \param y The y coordinate of the tap, defaults to vertical center
468537 */
469538 function tap(item, x, y) {
539+ if (!item)
540+ qtest_fail("no item given", 1);
541+
470542 multiTouchTap([0], item, x, y);
471543 }
472544
473545 function multiTouchTap(touchIds, item, x, y) {
546+ if (!item)
547+ qtest_fail("no item given", 1);
548+
474549 if (typeof touchIds !== "object") touchIds = [0];
475550 if (typeof x !== "number") x = item.width / 2;
476551 if (typeof y !== "number") y = item.height / 2;
@@ -510,6 +585,8 @@ TestCase {
510585 This effectively makes DirectionalDragAreas easier to fool.
511586 */
512587 function removeTimeConstraintsFromDirectionalDragAreas(item) {
588+ if (!item)
589+ qtest_fail("no item given", 1);
513590
514591 // use duck-typing to identify a DirectionalDragArea
515592 if (item.removeTimeConstraints != undefined) {