aboutsummaryrefslogtreecommitdiffstats
path: root/src/imports/testlib
diff options
context:
space:
mode:
authorCharles Yin <charles.yin@nokia.com>2012-06-07 13:08:13 +1000
committerQt by Nokia <qt-info@nokia.com>2012-07-18 05:19:44 +0200
commit1ce3a17ef51e10c03627842b9cdd0bb543ee8c83 (patch)
treee1450d6230744cd51421574899fbc00bda7e6ac2 /src/imports/testlib
parent1fb66c77d55cfdbe5df9919cbe2f42ddde34fb22 (diff)
Add fuzzyCompare() to qmltest
Change-Id: I4834f4af0839fb89424ed25f0addfb618e5374f8 Reviewed-by: Yunqiao Yin <charles.yin@nokia.com>
Diffstat (limited to 'src/imports/testlib')
-rw-r--r--src/imports/testlib/TestCase.qml40
-rw-r--r--src/imports/testlib/testcase.qdoc17
2 files changed, 37 insertions, 20 deletions
diff --git a/src/imports/testlib/TestCase.qml b/src/imports/testlib/TestCase.qml
index 9060ecc3b3..ddd7f7030f 100644
--- a/src/imports/testlib/TestCase.qml
+++ b/src/imports/testlib/TestCase.qml
@@ -253,24 +253,9 @@ Item {
return true
}
- function qtest_formatValue(value) {
- if (qtest_typeof(value) == "object") {
- if ("x" in value && "y" in value && "z" in value) {
- return "Qt.vector3d(" + value.x + ", " +
- value.y + ", " + value.z + ")"
- }
- try {
- return JSON.stringify(value)
- } catch (ex) {
- // stringify might fail (e.g. due to circular references)
- }
- }
- return value
- }
-
function compare(actual, expected, msg) {
- var act = testCase.qtest_formatValue(actual)
- var exp = testCase.qtest_formatValue(expected)
+ var act = qtest_results.stringify(actual)
+ var exp = qtest_results.stringify(expected)
var success = qtest_compareInternal(actual, expected)
if (msg === undefined) {
@@ -284,6 +269,23 @@ Item {
}
}
+ function fuzzyCompare(actual, expected, delta, msg) {
+ if (delta === undefined)
+ qtest_fail("A delta value is required for fuzzyCompare", 2)
+
+ var success = qtest_results.fuzzyCompare(actual, expected, delta)
+ if (msg === undefined) {
+ if (success)
+ msg = "FUZZYCOMPARE()"
+ else
+ msg = "Compared values are not the same with delta(" + delta + ")"
+ }
+
+ if (!qtest_results.compare(success, msg, actual, expected, util.callerFile(), util.callerLine())) {
+ throw new Error("QtQuickTest::fail")
+ }
+ }
+
function grabImage(item) {
return qtest_results.grabImage(item);
}
@@ -299,8 +301,8 @@ Item {
i += 50
}
var actual = obj[prop]
- var act = testCase.qtest_formatValue(actual)
- var exp = testCase.qtest_formatValue(value)
+ 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()))
throw new Error("QtQuickTest::fail")
diff --git a/src/imports/testlib/testcase.qdoc b/src/imports/testlib/testcase.qdoc
index 90fc538539..8a0f770544 100644
--- a/src/imports/testlib/testcase.qdoc
+++ b/src/imports/testlib/testcase.qdoc
@@ -345,7 +345,22 @@
\a expected, and displays the optional \a message. Similar
to \c{QCOMPARE(actual, expected)} in C++.
- \sa tryCompare()
+ \sa tryCompare(), fuzzyCompare
+*/
+
+
+/*!
+ \qmlmethod TestCase::fuzzyCompare(actual, expected, delta, message = "")
+
+ Fails the current test case if the difference betwen \a actual and \a expected
+ is greater than \a delta, and displays the optional \a message. Similar
+ to \c{qFuzzyCompare(actual, expected)} in C++ but with a required \a delta value.
+
+ This funtion can also be used for color comparisons if both the \a actual and
+ \a expected values can be converted into color values. If any of the differences
+ for RGBA channel values are greater than \a delta, the test fails.
+
+ \sa tryCompare(), compare()
*/
/*!