diff options
author | Bartlomiej Moskal <bartlomiej.moskal@qt.io> | 2023-11-21 09:11:31 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-12-13 02:06:28 +0000 |
commit | 220baf91c989682368a0ffd399dadd9b5c6ddcc0 (patch) | |
tree | c4bd6f66515363a65f7f864efcde12a33df22482 | |
parent | 8dba504cabf443298fccfbaf15af229831045d4c (diff) |
tst_qscreencapturebackend: Change comparison for captured image sizev6.7.0-beta1
Before this fix, the size of the captured image was compared to the
expected size. The expected size was calculated as the screen size
multiplied by the pixel ratio. This solution works when the pixel ratio
is an integer value, but some Android devices may have different value
(like 2.75). In such case, the expected value may be incorrectly
calculated. It happens because some precision is lost when rounding.
For example on device with 1080x2280 resolution and pixel ratio 2,75
the screen size will be calculated to (392.7272, 829.0909) and rounded
to (393, 829). In such situation, expected size will be wrongly
calculated: 2,75 * QSize(393, 829) = QSize(1080.75, 2279.75).
Because of that it will be better to compare calculated screen size from
captured image rather than calculated expected screen size.
Pick-to: 6.6 6.5
Fixes: QTBUG-118573
Change-Id: Ie2fc371f2f651ba7754b17cc020e8deedfdf11b3
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
(cherry picked from commit 03b2e3d161d18f2cd15b57a3e0ab86be7c32a0b0)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | tests/auto/integration/qscreencapturebackend/tst_qscreencapturebackend.cpp | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/tests/auto/integration/qscreencapturebackend/tst_qscreencapturebackend.cpp b/tests/auto/integration/qscreencapturebackend/tst_qscreencapturebackend.cpp index 8f3eb8e09..5d36ffc2d 100644 --- a/tests/auto/integration/qscreencapturebackend/tst_qscreencapturebackend.cpp +++ b/tests/auto/integration/qscreencapturebackend/tst_qscreencapturebackend.cpp @@ -227,15 +227,13 @@ void tst_QScreenCaptureBackend::capture(QTestWidget &widget, const QPoint &drawi QCOMPARE_LE(framesCount, expectedFramesCount + 2); QCOMPARE_GE(framesCount, expectedFramesCount / 2); - const QSize expectedSizeForComparison(qFloor(expectedSize.width() * pixelRatio), - qFloor(expectedSize.height() * pixelRatio)); - for (const auto &image : sink.images()) { auto pixelColor = [&drawingOffset, pixelRatio, &image](int x, int y) { return image.pixelColor((QPoint(x, y) + drawingOffset) * pixelRatio).toRgb(); }; - - QCOMPARE(image.size(), expectedSizeForComparison); + const int capturedWidth = qRound(image.size().width() / pixelRatio); + const int capturedHeight = qRound(image.size().height() / pixelRatio); + QCOMPARE(QSize(capturedWidth, capturedHeight), expectedSize); QCOMPARE(pixelColor(0, 0), QColor(0xFF, 0, 0)); QCOMPARE(pixelColor(39, 50), QColor(0xFF, 0, 0)); |