aboutsummaryrefslogtreecommitdiffstats
path: root/src/imports/testlib
diff options
context:
space:
mode:
authorRobin Burchell <robin.burchell@crimson.no>2017-04-22 19:22:48 +0200
committerRobin Burchell <robin.burchell@crimson.no>2017-05-11 07:31:12 +0000
commita9339e3ed4d2db11e75ed6c77fbe420708b44712 (patch)
treee30a558444933c1b4e017b7e0fa6c1b86698595c /src/imports/testlib
parentcef5e9d385d0cf78e43e8ea41edf253b78f0ca13 (diff)
TestCase: Grow some new functionality on grabImage
Add some meta-information about the image that we can use to do slightly stronger checks than just blindly poking pixel data (width & height props). In addition, when a test of a grabbed image fails (which they certainly do), it is always nice if we can perform some diagnostics. To this end, add a save() method to save the grabbed QImage to disk. Tests for the new functionality are blacklisted on Linux at present, as they do not yet appear stable, inheriting the other tst_grabImage flakiness. [ChangeLog][QmlTest] The returned object from TestCase::grabImage now has 'width', 'height', and 'size' properties for additional verification. In addition, there is a save() method to be able to persist the grabbed image to disk (for diagnostics purposes, for example). Change-Id: Ic651e0257102c514c39c3f648c05870f9d9c52e8 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/imports/testlib')
-rw-r--r--src/imports/testlib/TestCase.qml24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/imports/testlib/TestCase.qml b/src/imports/testlib/TestCase.qml
index 8c1744a2b2..dbed896c59 100644
--- a/src/imports/testlib/TestCase.qml
+++ b/src/imports/testlib/TestCase.qml
@@ -837,7 +837,14 @@ Item {
Returns a snapshot image object of the given \a item.
- The returned image object has the following methods:
+ The returned image object has the following properties:
+ \list
+ \li width Returns the width of the underlying image (since 5.10)
+ \li height Returns the height of the underlying image (since 5.10)
+ \li size Returns the size of the underlying image (since 5.10)
+ \endlist
+
+ Additionally, the returned image object has the following methods:
\list
\li red(x, y) Returns the red channel value of the pixel at \a x, \a y position
\li green(x, y) Returns the green channel value of the pixel at \a x, \a y position
@@ -858,6 +865,21 @@ Item {
var newImage = grabImage(rect);
verify(!newImage.equals(image));
\endcode
+ \li save(path) Saves the image to the given \a path. If the image cannot
+ be saved, an exception will be thrown. (since 5.10)
+
+ This can be useful to perform postmortem analysis on failing tests, for
+ example:
+
+ \code
+ var image = grabImage(rect);
+ try {
+ compare(image.width, 100);
+ } catch (ex) {
+ image.save("debug.png");
+ throw ex;
+ }
+ \endcode
\endlist