diff options
author | Robin Burchell <robin.burchell@crimson.no> | 2017-01-27 17:13:34 +0100 |
---|---|---|
committer | Robin Burchell <robin.burchell@crimson.no> | 2017-04-04 20:47:54 +0000 |
commit | fdb822613989c5975ba282b775e6d194467bdef4 (patch) | |
tree | b478f3361f91f5b2812648e1b66ae1d656e75171 /src/imports | |
parent | 09aa8ba83fcd68608173d949f7f4de155befb1c8 (diff) |
TestCase: Use the new instanceof support for QML types to ensure we have an Item
Using !item is not enough in a loosely-typed language like QML.
Previously, passing numbers to these methods (for example) would have
worked in misleading ways, or not at all.
We allow Window here too as for the most part it is useful, and some
tests actually use it.
Change-Id: I99de081798d1c503d0b01dc99ca095654cf58aa4
Reported-by: Albert Astals Cid <albert.astals@canonical.com>
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/imports')
-rw-r--r-- | src/imports/testlib/TestCase.qml | 58 |
1 files changed, 38 insertions, 20 deletions
diff --git a/src/imports/testlib/TestCase.qml b/src/imports/testlib/TestCase.qml index 18c70e1169..3e6eb64311 100644 --- a/src/imports/testlib/TestCase.qml +++ b/src/imports/testlib/TestCase.qml @@ -38,6 +38,7 @@ ****************************************************************************/ import QtQuick 2.0 +import QtQuick.Window 2.0 // used for qtest_verifyItem import QtTest 1.1 import "testlogger.js" as TestLogger import Qt.test.qtestroot 1.0 @@ -1085,8 +1086,8 @@ Item { function waitForRendering(item, timeout) { if (timeout === undefined) timeout = 5000 - if (!item) - qtest_fail("No item given to waitForRendering", 1) + if (!qtest_verifyItem(item, "waitForRendering")) + return return qtest_results.waitForRendering(item, timeout) } @@ -1198,8 +1199,8 @@ 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 (!qtest_verifyItem(item, "mousePress")) + return if (button === undefined) button = Qt.LeftButton @@ -1232,8 +1233,8 @@ 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 (!qtest_verifyItem(item, "mouseRelease")) + return if (button === undefined) button = Qt.LeftButton @@ -1268,8 +1269,8 @@ 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 (!qtest_verifyItem(item, "mouseDrag")) + return if (item.x === undefined || item.y === undefined) return @@ -1319,8 +1320,8 @@ 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 (!qtest_verifyItem(item, "mouseClick")) + return if (button === undefined) button = Qt.LeftButton @@ -1353,8 +1354,8 @@ 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 (!qtest_verifyItem(item, "mouseDoubleClick")) + return if (button === undefined) button = Qt.LeftButton @@ -1394,8 +1395,8 @@ 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 (!qtest_verifyItem(item, "mouseDoubleClickSequence")) + return if (button === undefined) button = Qt.LeftButton @@ -1426,8 +1427,8 @@ 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 (!qtest_verifyItem(item, "mouseMove")) + return if (delay == undefined) delay = -1 @@ -1454,8 +1455,8 @@ 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 (!qtest_verifyItem(item, "mouseWheel")) + return if (delay == undefined) delay = -1 @@ -1515,8 +1516,8 @@ Item { */ function touchEvent(item) { - if (!item) - qtest_fail("No item given to touchEvent", 1) + if (!qtest_verifyItem(item, "touchEvent")) + return return { _defaultItem: item, @@ -1625,6 +1626,23 @@ Item { function cleanup() {} /*! \internal */ + function qtest_verifyItem(item, method) { + try { + if (!(item instanceof Item) && + !(item instanceof Window)) { + // it's a QObject, but not a type + qtest_fail("TypeError: %1 requires an Item or Window type".arg(method), 2); + return false; + } + } catch (e) { // it's not a QObject + qtest_fail("TypeError: %1 requires an Item or Window type".arg(method), 3); + return false; + } + + return true; + } + + /*! \internal */ function qtest_runInternal(prop, arg) { try { qtest_testCaseResult = testCase[prop](arg) |