From 886662d409f6422bc43df500314470f776958bfd Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Thu, 31 Mar 2016 17:42:43 +0200 Subject: Give a nicer error if the passed item doesn't exist Instead of Cannot read property 'width' of null and a line pointing to TestCase.qml, you get No item given to mouseWheel and a line pointing to the offending code Change-Id: I8e035878035cb836a4c0c33a772ad4353d8dd000 Reviewed-by: Filippo Cucchetto Reviewed-by: Robin Burchell Reviewed-by: Mitch Curtis --- src/imports/testlib/TestCase.qml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/imports/testlib/TestCase.qml b/src/imports/testlib/TestCase.qml index 8bedad40e9..c736a1a93a 100644 --- a/src/imports/testlib/TestCase.qml +++ b/src/imports/testlib/TestCase.qml @@ -966,6 +966,9 @@ Item { \sa mouseRelease(), mouseClick(), mouseDoubleClick(), mouseDoubleClickSequence(), mouseMove(), mouseDrag(), mouseWheel() */ function mousePress(item, x, y, button, modifiers, delay) { + if (!item) + qtest_fail("No item given to mousePress", 1) + if (button === undefined) button = Qt.LeftButton if (modifiers === undefined) @@ -997,6 +1000,9 @@ Item { \sa mousePress(), mouseClick(), mouseDoubleClick(), mouseDoubleClickSequence(), mouseMove(), mouseDrag(), mouseWheel() */ function mouseRelease(item, x, y, button, modifiers, delay) { + if (!item) + qtest_fail("No item given to mouseRelease", 1) + if (button === undefined) button = Qt.LeftButton if (modifiers === undefined) @@ -1030,6 +1036,9 @@ Item { \sa mousePress(), mouseClick(), mouseDoubleClick(), mouseDoubleClickSequence(), mouseMove(), mouseRelease(), mouseWheel() */ function mouseDrag(item, x, y, dx, dy, button, modifiers, delay) { + if (!item) + qtest_fail("No item given to mouseDrag", 1) + if (item.x === undefined || item.y === undefined) return if (button === undefined) @@ -1077,6 +1086,9 @@ Item { \sa mousePress(), mouseRelease(), mouseDoubleClick(), mouseDoubleClickSequence(), mouseMove(), mouseDrag(), mouseWheel() */ function mouseClick(item, x, y, button, modifiers, delay) { + if (!item) + qtest_fail("No item given to mouseClick", 1) + if (button === undefined) button = Qt.LeftButton if (modifiers === undefined) @@ -1108,6 +1120,9 @@ Item { \sa mouseDoubleClickSequence(), mousePress(), mouseRelease(), mouseClick(), mouseMove(), mouseDrag(), mouseWheel() */ function mouseDoubleClick(item, x, y, button, modifiers, delay) { + if (!item) + qtest_fail("No item given to mouseDoubleClick", 1) + if (button === undefined) button = Qt.LeftButton if (modifiers === undefined) @@ -1146,6 +1161,9 @@ Item { \sa mouseDoubleClick(), mousePress(), mouseRelease(), mouseClick(), mouseMove(), mouseDrag(), mouseWheel() */ function mouseDoubleClickSequence(item, x, y, button, modifiers, delay) { + if (!item) + qtest_fail("No item given to mouseDoubleClickSequence", 1) + if (button === undefined) button = Qt.LeftButton if (modifiers === undefined) @@ -1175,6 +1193,9 @@ Item { \sa mousePress(), mouseRelease(), mouseClick(), mouseDoubleClick(), mouseDoubleClickSequence(), mouseDrag(), mouseWheel() */ function mouseMove(item, x, y, delay, buttons) { + if (!item) + qtest_fail("No item given to mouseMove", 1) + if (delay == undefined) delay = -1 if (buttons == undefined) @@ -1200,6 +1221,9 @@ Item { \sa mousePress(), mouseClick(), mouseDoubleClick(), mouseDoubleClickSequence(), mouseMove(), mouseRelease(), mouseDrag(), QWheelEvent::angleDelta() */ function mouseWheel(item, x, y, xDelta, yDelta, buttons, modifiers, delay) { + if (!item) + qtest_fail("No item given to mouseWheel", 1) + if (delay == undefined) delay = -1 if (buttons == undefined) -- cgit v1.2.3