diff options
Diffstat (limited to 'src/imports/testlib')
-rw-r--r-- | src/imports/testlib/TestCase.qml | 11 | ||||
-rw-r--r-- | src/imports/testlib/testcase.qdoc | 7 |
2 files changed, 13 insertions, 5 deletions
diff --git a/src/imports/testlib/TestCase.qml b/src/imports/testlib/TestCase.qml index 0bec4cddf2..6e2c8e73ab 100644 --- a/src/imports/testlib/TestCase.qml +++ b/src/imports/testlib/TestCase.qml @@ -290,14 +290,21 @@ Item { return qtest_results.grabImage(item); } - function tryCompare(obj, prop, value, timeout) { + function tryCompare(obj, prop, value, timeout, msg) { if (arguments.length == 2) { qtest_results.fail("A value is required for tryCompare", util.callerFile(), util.callerLine()) throw new Error("QtQuickTest::fail") } + if (timeout !== undefined && typeof(timeout) != "number") { + qtest_results.fail("timeout should be a number", + util.callerFile(), util.callerLine()) + throw new Error("QtQuickTest::fail") + } if (!timeout) timeout = 5000 + if (msg === undefined) + msg = "property " + prop if (!qtest_compareInternal(obj[prop], value)) wait(0) var i = 0 @@ -309,7 +316,7 @@ Item { var act = qtest_results.stringify(actual) var exp = qtest_results.stringify(value) var success = qtest_compareInternal(actual, value) - if (!qtest_results.compare(success, "property " + prop, act, exp, util.callerFile(), util.callerLine())) + if (!qtest_results.compare(success, msg, act, exp, util.callerFile(), util.callerLine())) throw new Error("QtQuickTest::fail") } diff --git a/src/imports/testlib/testcase.qdoc b/src/imports/testlib/testcase.qdoc index 56fcb24beb..dd1d9e5ad3 100644 --- a/src/imports/testlib/testcase.qdoc +++ b/src/imports/testlib/testcase.qdoc @@ -367,11 +367,12 @@ */ /*! - \qmlmethod TestCase::tryCompare(obj, property, expected, timeout = 5000) + \qmlmethod TestCase::tryCompare(obj, property, expected, timeout = 5000, message = "") Fails the current test case if the specified \a property on \a obj - is not the same as \a expected. The test will be retried multiple - times until the \a timeout (in milliseconds) is reached. + is not the same as \a expected, and displays the optional \a message. + The test will be retried multiple times until the + \a timeout (in milliseconds) is reached. This function is intended for testing applications where a property changes value based on asynchronous events. Use compare() for testing |