aboutsummaryrefslogtreecommitdiffstats
path: root/src/imports/testlib
diff options
context:
space:
mode:
authorAlbert Astals Cid <albert.astals@canonical.com>2013-08-02 12:44:32 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-08-05 12:00:35 +0200
commitb96479032c3c0c02d9444efe90ccc5ea862d886c (patch)
tree5e3fdc7ecbcd32e3f776786b7f8a2e8b69fd11e5 /src/imports/testlib
parent45792359f25813af18b7416e4c18737ed4b20bff (diff)
Allow passing a message to tryCompare
Also adds a check to make sure timeout is a number, for people that are moving from compare() to tryCompare() and forget of the extra timeout parameter Change-Id: I54e56e2014c022e06622edebca1fd36172c75009 Reviewed-by: Yunqiao Yin <charles@mazymind.com> Reviewed-by: Caroline Chao <caroline.chao@digia.com>
Diffstat (limited to 'src/imports/testlib')
-rw-r--r--src/imports/testlib/TestCase.qml11
-rw-r--r--src/imports/testlib/testcase.qdoc7
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