on xenial help sign in
Better error message if the item does not exist
3a9749aAlbert Astals Cid
tests/qmltests/Dash/Previews/tst_PreviewImageGallery.qml+3−2
@@ -70,8 +70,6 @@ Rectangle {
70 when: windowShown
70 when: windowShown
71
71
72 property Item overlay: findChild(imageGallery.rootItem, "overlay")
72 property Item overlay: findChild(imageGallery.rootItem, "overlay")
73− property Item overlayCloseButton: findChild(overlay, "overlayCloseButton")
74− property Item overlayListView: findChild(overlay, "overlayListView")
75
73
76 function cleanup() {
74 function cleanup() {
77 overlay.hide();
75 overlay.hide();
@@ -87,6 +85,7 @@ Rectangle {
87 }
85 }
88
86
89 function test_overlayOpenClose() {
87 function test_overlayOpenClose() {
88+ var overlayCloseButton = findChild(overlay, "overlayCloseButton");
90 var image0 = findChild(imageGallery, "previewImage0");
89 var image0 = findChild(imageGallery, "previewImage0");
91 mouseClick(image0);
90 mouseClick(image0);
92 tryCompare(overlay, "visible", true);
91 tryCompare(overlay, "visible", true);
@@ -97,6 +96,7 @@ Rectangle {
97 }
96 }
98
97
99 function test_overlayShowHideHeader() {
98 function test_overlayShowHideHeader() {
99+ var overlayCloseButton = findChild(overlay, "overlayCloseButton");
100 var image0 = findChild(imageGallery, "previewImage0");
100 var image0 = findChild(imageGallery, "previewImage0");
101 mouseClick(image0);
101 mouseClick(image0);
102 tryCompare(overlay, "visible", true);
102 tryCompare(overlay, "visible", true);
@@ -117,6 +117,7 @@ Rectangle {
117 }
117 }
118
118
119 function test_overlayOpenCorrectImage(data) {
119 function test_overlayOpenCorrectImage(data) {
120+ var overlayListView = findChild(overlay, "overlayListView");
120 var image = findChild(imageGallery, "previewImage" + data.index);
121 var image = findChild(imageGallery, "previewImage" + data.index);
121 mouseClick(image);
122 mouseClick(image);
122 tryCompare(overlay, "visible", true);
123 tryCompare(overlay, "visible", true);
tests/qmltests/Dash/tst_Card.qml+10−10
@@ -217,16 +217,16 @@ Rectangle {
217
217
218 when: windowShown
218 when: windowShown
219
219
220− property Item title: findChild(card, "titleLabel")
220+ property Item title: findChild(loader, "titleLabel")
221− property Item subtitle: findChild(card, "subtitleLabel")
221+ property Item subtitle: findChild(loader, "subtitleLabel")
222− property var headerRow: findChild(card, "outerRow")
222+ property var headerRow: findChild(loader, "outerRow")
223− property var art: findChild(card, "artShape")
223+ property var art: findChild(loader, "artShape")
224− property Item artImage: findChild(card, "artImage")
224+ property Item artImage: findChild(loader, "artImage")
225− property Item summary: findChild(card, "summaryLabel")
225+ property Item summary: findChild(loader, "summaryLabel")
226− property Item background: findChild(card, "background")
226+ property Item background: findChild(loader, "background")
227− property Item backgroundLoader: findChild(card, "backgroundLoader")
227+ property Item backgroundLoader: findChild(loader, "backgroundLoader")
228− property Item backgroundImage: findChild(card, "backgroundImage")
228+ property Item backgroundImage: findChild(loader, "backgroundImage")
229− property Item mascotImage: findChild(card, "mascotImage");
229+ property Item mascotImage: findChild(loader, "mascotImage");
230
230
231 function init() {
231 function init() {
232 cardTool.components = Qt.binding(function() { return Helpers.update(JSON.parse(Helpers.defaultLayout), Helpers.tryParse(layoutArea.text, layoutError))['components']; });
232 cardTool.components = Qt.binding(function() { return Helpers.update(JSON.parse(Helpers.defaultLayout), Helpers.tryParse(layoutArea.text, layoutError))['components']; });
tests/utils/modules/Unity/Test/UnityTestCase.qml+84−7
@@ -52,8 +52,11 @@ TestCase {
52 this.getCurrentTimeMs = function() {return this.currentTimeMs}
52 this.getCurrentTimeMs = function() {return this.currentTimeMs}
53 }
53 }
54
54
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
56 function mouseClick(item, x, y, button, modifiers, delay) {
56 function mouseClick(item, x, y, button, modifiers, delay) {
57+ if (!item)
58+ qtest_fail("no item given", 1);
59+
57 if (button === undefined)
60 if (button === undefined)
58 button = Qt.LeftButton;
61 button = Qt.LeftButton;
59 if (modifiers === undefined)
62 if (modifiers === undefined)
@@ -68,8 +71,11 @@ TestCase {
68 qtest_fail("window not shown", 2);
71 qtest_fail("window not shown", 2);
69 }
72 }
70
73
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
72 function mouseDoubleClick(item, x, y, button, modifiers, delay) {
75 function mouseDoubleClick(item, x, y, button, modifiers, delay) {
76+ if (!item)
77+ qtest_fail("no item given", 1);
78+
73 if (button === undefined)
79 if (button === undefined)
74 button = Qt.LeftButton;
80 button = Qt.LeftButton;
75 if (modifiers === undefined)
81 if (modifiers === undefined)
@@ -84,8 +90,11 @@ TestCase {
84 qtest_fail("window not shown", 2)
90 qtest_fail("window not shown", 2)
85 }
91 }
86
92
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
88 function mousePress(item, x, y, button, modifiers, delay) {
94 function mousePress(item, x, y, button, modifiers, delay) {
95+ if (!item)
96+ qtest_fail("no item given", 1);
97+
89 if (button === undefined)
98 if (button === undefined)
90 button = Qt.LeftButton;
99 button = Qt.LeftButton;
91 if (modifiers === undefined)
100 if (modifiers === undefined)
@@ -100,8 +109,11 @@ TestCase {
100 qtest_fail("window not shown", 2)
109 qtest_fail("window not shown", 2)
101 }
110 }
102
111
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
104 function mouseRelease(item, x, y, button, modifiers, delay) {
113 function mouseRelease(item, x, y, button, modifiers, delay) {
114+ if (!item)
115+ qtest_fail("no item given", 1);
116+
105 if (button === undefined)
117 if (button === undefined)
106 button = Qt.LeftButton;
118 button = Qt.LeftButton;
107 if (modifiers === undefined)
119 if (modifiers === undefined)
@@ -123,6 +135,9 @@ TestCase {
123 // speed is in pixels/second
135 // speed is in pixels/second
124 function mouseFlick(item, x, y, toX, toY, pressMouse, releaseMouse,
136 function mouseFlick(item, x, y, toX, toY, pressMouse, releaseMouse,
125 speed, iterations) {
137 speed, iterations) {
138+ if (!item)
139+ qtest_fail("no item given", 1);
140+
126 pressMouse = ((pressMouse != null) ? pressMouse : true); // Default to true for pressMouse if not present
141 pressMouse = ((pressMouse != null) ? pressMouse : true); // Default to true for pressMouse if not present
127 releaseMouse = ((releaseMouse != null) ? releaseMouse : true); // Default to true for releaseMouse if not present
142 releaseMouse = ((releaseMouse != null) ? releaseMouse : true); // Default to true for releaseMouse if not present
128
143
@@ -161,6 +176,9 @@ TestCase {
161
176
162 // Find an object with the given name in the children tree of "obj"
177 // Find an object with the given name in the children tree of "obj"
163 function findChild(obj, objectName) {
178 function findChild(obj, objectName) {
179+ if (!obj)
180+ qtest_fail("no obj given", 1);
181+
164 return findChildIn(obj, "children", objectName);
182 return findChildIn(obj, "children", objectName);
165 }
183 }
166
184
@@ -170,11 +188,17 @@ TestCase {
170 // as this tree is much bigger and might contain stuff that goes
188 // as this tree is much bigger and might contain stuff that goes
171 // away randomly.
189 // away randomly.
172 function findInvisibleChild(obj, objectName) {
190 function findInvisibleChild(obj, objectName) {
191+ if (!obj)
192+ qtest_fail("no obj given", 1);
193+
173 return findChildIn(obj, "data", objectName);
194 return findChildIn(obj, "data", objectName);
174 }
195 }
175
196
176 // Find a child in the named property
197 // Find a child in the named property
177 function findChildIn(obj, prop, objectName) {
198 function findChildIn(obj, prop, objectName) {
199+ if (!obj)
200+ qtest_fail("no obj given", 1);
201+
178 var childs = new Array(0);
202 var childs = new Array(0);
179 childs.push(obj)
203 childs.push(obj)
180 while (childs.length > 0) {
204 while (childs.length > 0) {
@@ -190,6 +214,9 @@ TestCase {
190 }
214 }
191
215
192 function findChildsByType(obj, typeName) {
216 function findChildsByType(obj, typeName) {
217+ if (!obj)
218+ qtest_fail("no obj given", 1);
219+
193 var res = new Array(0);
220 var res = new Array(0);
194 for (var i in obj.children) {
221 for (var i in obj.children) {
195 var c = obj.children[i];
222 var c = obj.children[i];
@@ -237,6 +264,9 @@ TestCase {
237 }
264 }
238
265
239 function flickToYEnd(item) {
266 function flickToYEnd(item) {
267+ if (!item)
268+ qtest_fail("no item given", 1);
269+
240 var i = 0;
270 var i = 0;
241 var x = item.width / 2;
271 var x = item.width / 2;
242 var y = item.height - units.gu(1);
272 var y = item.height - units.gu(1);
@@ -256,6 +286,9 @@ TestCase {
256
286
257 // speed is in pixels/second
287 // speed is in pixels/second
258 function touchFlick(item, x, y, toX, toY, beginTouch, endTouch, speed, iterations) {
288 function touchFlick(item, x, y, toX, toY, beginTouch, endTouch, speed, iterations) {
289+ if (!item)
290+ qtest_fail("no item given", 1);
291+
259 // Make sure the item is rendered
292 // Make sure the item is rendered
260 waitForRendering(item);
293 waitForRendering(item);
261
294
@@ -315,10 +348,16 @@ TestCase {
315 // perform a drag in the given direction until the given condition is true
348 // perform a drag in the given direction until the given condition is true
316 // The condition is a function to be evaluated after every step
349 // The condition is a function to be evaluated after every step
317 function touchDragUntil(item, startX, startY, stepX, stepY, condition) {
350 function touchDragUntil(item, startX, startY, stepX, stepY, condition) {
351+ if (!item)
352+ qtest_fail("no item given", 1);
353+
318 multiTouchDragUntil([0], item, startX, startY, stepX, stepY, condition);
354 multiTouchDragUntil([0], item, startX, startY, stepX, stepY, condition);
319 }
355 }
320
356
321 function multiTouchDragUntil(touchIds, item, startX, startY, stepX, stepY, condition) {
357 function multiTouchDragUntil(touchIds, item, startX, startY, stepX, stepY, condition) {
358+ if (!item)
359+ qtest_fail("no item given", 1);
360+
322 var root = fetchRootItem(item);
361 var root = fetchRootItem(item);
323 var pos = item.mapToItem(root, startX, startY);
362 var pos = item.mapToItem(root, startX, startY);
324
363
@@ -363,9 +402,17 @@ TestCase {
363 event.commit()
402 event.commit()
364 }
403 }
365
404
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+ }
367
411
368 function multiTouchMove(touchId, item, tox, toy) {
412 function multiTouchMove(touchId, item, tox, toy) {
413+ if (!item)
414+ qtest_fail("no item given", 1);
415+
369 if (typeof touchId !== "number") touchId = 0;
416 if (typeof touchId !== "number") touchId = 0;
370 var root = fetchRootItem(item)
417 var root = fetchRootItem(item)
371 var rootPoint = item.mapToItem(root, tox, toy)
418 var rootPoint = item.mapToItem(root, tox, toy)
@@ -376,6 +423,9 @@ TestCase {
376 }
423 }
377
424
378 function touchPinch(item, x1Start, y1Start, x1End, y1End, x2Start, y2Start, x2End, y2End) {
425 function touchPinch(item, x1Start, y1Start, x1End, y1End, x2Start, y2Start, x2End, y2End) {
426+ if (!item)
427+ qtest_fail("no item given", 1);
428+
379 // Make sure the item is rendered
429 // Make sure the item is rendered
380 waitForRendering(item);
430 waitForRendering(item);
381
431
@@ -402,13 +452,21 @@ TestCase {
402 }
452 }
403
453
404 function fetchRootItem(item) {
454 function fetchRootItem(item) {
455+ if (!item)
456+ qtest_fail("no item given", 1);
457+
405 if (item.parent)
458 if (item.parent)
406 return fetchRootItem(item.parent)
459 return fetchRootItem(item.parent)
407 else
460 else
408 return item
461 return item
409 }
462 }
410
463
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+ }
412
470
413 /*! \brief Release a touch point
471 /*! \brief Release a touch point
414
472
@@ -419,6 +477,9 @@ TestCase {
419 \param stationaryPoints An array of touchIds which are "already touched"
477 \param stationaryPoints An array of touchIds which are "already touched"
420 */
478 */
421 function multiTouchPress(touchId, item, x, y, stationaryPoints) {
479 function multiTouchPress(touchId, item, x, y, stationaryPoints) {
480+ if (!item)
481+ qtest_fail("no item given", 1);
482+
422 if (typeof touchId !== "number") touchId = 0;
483 if (typeof touchId !== "number") touchId = 0;
423 if (typeof x !== "number") x = item.width / 2;
484 if (typeof x !== "number") x = item.width / 2;
424 if (typeof y !== "number") y = item.height / 2;
485 if (typeof y !== "number") y = item.height / 2;
@@ -434,7 +495,12 @@ TestCase {
434 event.commit()
495 event.commit()
435 }
496 }
436
497
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+ }
438
504
439 /*! \brief Release a touch point
505 /*! \brief Release a touch point
440
506
@@ -445,6 +511,9 @@ TestCase {
445 \param stationaryPoints An array of touchIds which are "still touched"
511 \param stationaryPoints An array of touchIds which are "still touched"
446 */
512 */
447 function multiTouchRelease(touchId, item, x, y, stationaryPoints) {
513 function multiTouchRelease(touchId, item, x, y, stationaryPoints) {
514+ if (!item)
515+ qtest_fail("no item given", 1);
516+
448 if (typeof touchId !== "number") touchId = 0;
517 if (typeof touchId !== "number") touchId = 0;
449 if (typeof x !== "number") x = item.width / 2;
518 if (typeof x !== "number") x = item.width / 2;
450 if (typeof y !== "number") y = item.height / 2;
519 if (typeof y !== "number") y = item.height / 2;
@@ -467,10 +536,16 @@ TestCase {
467 \param y The y coordinate of the tap, defaults to vertical center
536 \param y The y coordinate of the tap, defaults to vertical center
468 */
537 */
469 function tap(item, x, y) {
538 function tap(item, x, y) {
539+ if (!item)
540+ qtest_fail("no item given", 1);
541+
470 multiTouchTap([0], item, x, y);
542 multiTouchTap([0], item, x, y);
471 }
543 }
472
544
473 function multiTouchTap(touchIds, item, x, y) {
545 function multiTouchTap(touchIds, item, x, y) {
546+ if (!item)
547+ qtest_fail("no item given", 1);
548+
474 if (typeof touchIds !== "object") touchIds = [0];
549 if (typeof touchIds !== "object") touchIds = [0];
475 if (typeof x !== "number") x = item.width / 2;
550 if (typeof x !== "number") x = item.width / 2;
476 if (typeof y !== "number") y = item.height / 2;
551 if (typeof y !== "number") y = item.height / 2;
@@ -510,6 +585,8 @@ TestCase {
510 This effectively makes DirectionalDragAreas easier to fool.
585 This effectively makes DirectionalDragAreas easier to fool.
511 */
586 */
512 function removeTimeConstraintsFromDirectionalDragAreas(item) {
587 function removeTimeConstraintsFromDirectionalDragAreas(item) {
588+ if (!item)
589+ qtest_fail("no item given", 1);
513
590
514 // use duck-typing to identify a DirectionalDragArea
591 // use duck-typing to identify a DirectionalDragArea
515 if (item.removeTimeConstraints != undefined) {
592 if (item.removeTimeConstraints != undefined) {