diff options
author | Robin Burchell <robin.burchell@crimson.no> | 2017-04-22 19:22:48 +0200 |
---|---|---|
committer | Robin Burchell <robin.burchell@crimson.no> | 2017-05-11 07:31:12 +0000 |
commit | a9339e3ed4d2db11e75ed6c77fbe420708b44712 (patch) | |
tree | e30a558444933c1b4e017b7e0fa6c1b86698595c /tests/auto/qmltest | |
parent | cef5e9d385d0cf78e43e8ea41edf253b78f0ca13 (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 'tests/auto/qmltest')
-rw-r--r-- | tests/auto/qmltest/selftests/BLACKLIST | 5 | ||||
-rw-r--r-- | tests/auto/qmltest/selftests/tst_grabImage.qml | 51 |
2 files changed, 56 insertions, 0 deletions
diff --git a/tests/auto/qmltest/selftests/BLACKLIST b/tests/auto/qmltest/selftests/BLACKLIST index 9cb2313810..ffce42e4c0 100644 --- a/tests/auto/qmltest/selftests/BLACKLIST +++ b/tests/auto/qmltest/selftests/BLACKLIST @@ -6,3 +6,8 @@ # QTBUG-53793: seems to be failing on Linux a little too often... [tst_grabImage::test_equals] linux +[tst_grabImage::test_sizeProps] +linux +[tst_grabImage::test_save] +linux + diff --git a/tests/auto/qmltest/selftests/tst_grabImage.qml b/tests/auto/qmltest/selftests/tst_grabImage.qml index 954daaba42..50c441ab87 100644 --- a/tests/auto/qmltest/selftests/tst_grabImage.qml +++ b/tests/auto/qmltest/selftests/tst_grabImage.qml @@ -1,5 +1,6 @@ /**************************************************************************** ** +** Copyright (C) 2017 Crimson AS <info@crimson.no> ** Copyright (C) 2016 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** @@ -50,4 +51,54 @@ TestCase { verify(!newImage.equals(null)); verify(!newImage.equals(undefined)); } + + function test_sizeProps() { + var rect = createTemporaryQmlObject("import QtQuick 2.0; Rectangle { color: 'red'; width: 10; height: 20; }", testCase); + var image = grabImage(rect); + + try { + compare(image.width, 10) + compare(image.height, 20) + compare(image.size, Qt.size(10, 20)) + } catch (ex) { + image.save("tst_grabImage_test_sizeProps.png") + throw ex; + } + } + + function test_save() { + var rect = createTemporaryQmlObject("import QtQuick 2.0; Rectangle { color: 'red'; width: 10; height: 20; }", testCase); + var grabbedImage = grabImage(rect); + grabbedImage.save("tst_grabImage_test_save.png") + + // Now try to load it + var url = Qt.resolvedUrl("tst_grabImage_test_save.png") + var image = createTemporaryQmlObject("import QtQuick 2.0; Image { source: \"" + url + "\" }", testCase); + tryCompare(image, "status", Image.Ready) + var grabbedImage2 = grabImage(image); + + try { + verify(grabbedImage2.equals(grabbedImage)) + } catch (ex) { + grabbedImage2.save("tst_grabImage_test_save2.png") + throw ex; + } + } + + function test_saveThrowsWhenFailing() { + var rect = createTemporaryQmlObject("import QtQuick 2.0; Rectangle { color: 'red'; width: 10; height: 20; }", testCase); + var grabbedImage = grabImage(rect); + var didThrow = false; + + try { + // Format doesn't exist, so this will throw + grabbedImage.save("tst_grabImage_test_saveThrowsWhenFailing.never-gonna-give-you-up"); + } catch (ex) { + didThrow = true; + } + + if (!didThrow) { + fail("save() should have thrown, but didn't!") + } + } } |