summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLars Sutterud <lars.sutterud@qt.io>2023-02-28 12:42:04 +0100
committerLars Sutterud <lars.sutterud@qt.io>2023-03-14 19:03:25 +0100
commitddcb4776ae0d914b23349f37f8415b090fc8c005 (patch)
treebf7dfd87275a5ce4ed33bdd257fc16d22eb74357 /tests
parentd4a1ab3fc4f9f12943475cf1f57f6d8756729419 (diff)
Extend recordToFile() in tst_qscreencapture_integration.cpp w/window
The test now checks the recorded file for errors by measuring color changes at one pixel point of multiple frames at the start and end of the file. Task-number: QTBUG-103226 Pick-to: 6.5 Change-Id: I07b47f6482b868fc68c967d558f89838bf705ed5 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Artem Dyomin <artem.dyomin@qt.io> Reviewed-by: Lars Knoll <lars@knoll.priv.no>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/integration/qscreencapture_integration/tst_qscreencapture_integration.cpp66
1 files changed, 61 insertions, 5 deletions
diff --git a/tests/auto/integration/qscreencapture_integration/tst_qscreencapture_integration.cpp b/tests/auto/integration/qscreencapture_integration/tst_qscreencapture_integration.cpp
index 328fc125a..839bcd365 100644
--- a/tests/auto/integration/qscreencapture_integration/tst_qscreencapture_integration.cpp
+++ b/tests/auto/integration/qscreencapture_integration/tst_qscreencapture_integration.cpp
@@ -52,6 +52,13 @@ public:
return widget;
}
+ void setColors(QColor firstColor, QColor secondColor)
+ {
+ m_firstColor = firstColor;
+ m_secondColor = secondColor;
+ this->repaint();
+ }
+
protected:
void paintEvent(QPaintEvent * /*event*/) override
{
@@ -379,20 +386,29 @@ void tst_QScreenCaptureIntegration::removeWindowWhileCapture()
void tst_QScreenCaptureIntegration::recordToFile()
{
+ // Create widget with blue color
+ auto widget = QTestWidget::createAndShow(Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint,
+ QRect{ 200, 100, 430, 351 });
+ widget->setColors(QColor(0, 0, 0xFF), QColor(0, 0, 0xFF));
+
QScreenCapture sc;
QSignalSpy errorsSpy(&sc, &QScreenCapture::errorOccurred);
- // sc.setScreen(screen);
QMediaCaptureSession session;
QMediaRecorder recorder;
session.setScreenCapture(&sc);
session.setRecorder(&recorder);
- recorder.setVideoResolution(1280, 960);
+ auto screen = QApplication::primaryScreen();
+ QSize screenSize = screen->geometry().size();
+ QSize videoResolution = QSize(1920, 1080);
+ recorder.setVideoResolution(videoResolution);
+ recorder.setQuality(QMediaRecorder::VeryHighQuality);
// Insert metadata
QMediaMetaData metaData;
metaData.insert(QMediaMetaData::Author, QString::fromUtf8("Author"));
metaData.insert(QMediaMetaData::Date, QDateTime::currentDateTime());
recorder.setMetaData(metaData);
+
sc.setActive(true);
QTest::qWait(200); // wait a bit for SC threading activating
@@ -406,7 +422,9 @@ void tst_QScreenCaptureIntegration::recordToFile()
QCOMPARE(recorder.recorderState(), QMediaRecorder::RecordingState);
}
- QTest::qWait(600);
+ QTest::qWait(300);
+ widget->setColors(QColor(0, 0xFF, 0), QColor(0, 0xFF, 0)); // Change widget color
+ QTest::qWait(300);
{
QSignalSpy recorderStateChanged(&recorder, &QMediaRecorder::recorderStateChanged);
@@ -423,11 +441,49 @@ void tst_QScreenCaptureIntegration::recordToFile()
QMediaPlayer player;
player.setSource(fileName);
- QCOMPARE_EQ(player.metaData().value(QMediaMetaData::Resolution).toSize(), QSize(1280, 960));
+ QCOMPARE_EQ(player.metaData().value(QMediaMetaData::Resolution).toSize(), QSize(videoResolution));
QCOMPARE_GT(player.duration(), 350);
QCOMPARE_LT(player.duration(), 650);
- // TODO: check frames changes with QMediaPlayer
+ // Convert video frames to QImages
+ TestVideoSink sink;
+ player.setVideoSink(&sink);
+ sink.setStoreImagesEnabled();
+ player.setPlaybackRate(10);
+ player.play();
+ QTRY_COMPARE(player.mediaStatus(), QMediaPlayer::EndOfMedia);
+ const int framesCount = sink.images().size();
+
+ // Find pixel point at center of widget
+ int x = 415 * videoResolution.width() / screenSize.width();
+ int y = 275 * videoResolution.height() / screenSize.height();
+ auto point = QPoint(x, y);
+
+ // Verify color of first fourth of the video frames
+ for (int i = 0; i <= static_cast<int>(framesCount * 0.25); i++) {
+ QImage image = sink.images().at(i);
+ QVERIFY(!image.isNull());
+ QRgb rgb = image.pixel(point);
+// qDebug() << QString("RGB: %1, %2, %3").arg(qRed(rgb)).arg(qGreen(rgb)).arg(qBlue(rgb));
+
+ // RGB values should be 0, 0, 255. Compensating for inaccurate video encoding.
+ QVERIFY(qRed(rgb) <= 60);
+ QVERIFY(qGreen(rgb) <= 60);
+ QVERIFY(qBlue(rgb) >= 200);
+ }
+
+ // Verify color of last fourth of the video frames
+ for (int i = static_cast<int>(framesCount * 0.75); i < framesCount; i++) {
+ QImage image = sink.images().at(i);
+ QVERIFY(!image.isNull());
+ QRgb rgb = image.pixel(point);
+// qDebug() << QString("RGB: %1, %2, %3").arg(qRed(rgb)).arg(qGreen(rgb)).arg(qBlue(rgb));
+
+ // RGB values should be 0, 255, 0. Compensating for inaccurate video encoding.
+ QVERIFY(qRed(rgb) <= 60);
+ QVERIFY(qGreen(rgb) >= 200);
+ QVERIFY(qBlue(rgb) <= 60);
+ }
QFile(fileName).remove();
}