summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRhys Weatherley <rhys.weatherley@nokia.com>2010-12-07 11:12:43 +1000
committerRhys Weatherley <rhys.weatherley@nokia.com>2010-12-07 11:20:29 +1000
commit27dfe1fb63977807c9c0a430e778a06290d4f4a4 (patch)
tree6feaddd7cdb73536cf16fafd99447ba18f1f9964 /src
parentea4adaa0f859929d9fc1a5e6a169c7f493f64dee (diff)
Add tryCompare() function for asynchronous testing
Diffstat (limited to 'src')
-rw-r--r--src/imports/testlib/TestCase.qml39
1 files changed, 31 insertions, 8 deletions
diff --git a/src/imports/testlib/TestCase.qml b/src/imports/testlib/TestCase.qml
index deb7605..5adee9c 100644
--- a/src/imports/testlib/TestCase.qml
+++ b/src/imports/testlib/TestCase.qml
@@ -84,9 +84,7 @@ Item {
throw new Error("QtTest::fail")
}
- function compare(actual, expected, msg) {
- var act = actual
- var exp = expected
+ function compareInternal(actual, expected) {
var success = false
if (typeof actual == "number" && typeof expected == "number") {
// Use a fuzzy compare if the two values are floats
@@ -99,11 +97,6 @@ Item {
Math.abs(actual.y - expected.y) <= 0.00001 &&
Math.abs(actual.z - expected.z) <= 0.00001) {
success = true
- } else {
- act = "Qt.vector3d(" + actual.x + ", " +
- actual.y + ", " + actual.z + ")"
- exp = "Qt.vector3d(" + expected.x + ", " +
- expected.y + ", " + expected.z + ")"
}
} else if (actual == expected) {
success = true
@@ -111,12 +104,42 @@ Item {
} else if (actual == expected) {
success = true
}
+ return success
+ }
+
+ function formatValue(value) {
+ if (typeof value == "object") {
+ if ("x" in value && "y" in value && "z" in value) {
+ return "Qt.vector3d(" + value.x + ", " +
+ value.y + ", " + value.z + ")"
+ }
+ }
+ return value
+ }
+
+ function compare(actual, expected, msg) {
+ var act = formatValue(actual)
+ var exp = formatValue(expected)
+ var success = compareInternal(actual, expected)
if (!msg)
msg = ""
if (!results.compare(success, msg, act, exp))
throw new Error("QtTest::fail")
}
+ function tryCompare(obj, prop, value, timeout) {
+ if (!timeout)
+ timeout = 5000
+ if (!compareInternal(obj[prop], value))
+ wait(0)
+ var i = 0
+ while (i < timeout && !compareInternal(obj[prop], value)) {
+ wait(50)
+ i += 50
+ }
+ compare(obj[prop], value, "property " + prop)
+ }
+
function skip(msg) {
if (!msg)
msg = ""