diff options
Diffstat (limited to 'tests/auto/unit/multimedia/qscreencapture')
-rw-r--r-- | tests/auto/unit/multimedia/qscreencapture/CMakeLists.txt | 18 | ||||
-rw-r--r-- | tests/auto/unit/multimedia/qscreencapture/tst_qscreencapture.cpp | 64 |
2 files changed, 82 insertions, 0 deletions
diff --git a/tests/auto/unit/multimedia/qscreencapture/CMakeLists.txt b/tests/auto/unit/multimedia/qscreencapture/CMakeLists.txt new file mode 100644 index 000000000..f5b152034 --- /dev/null +++ b/tests/auto/unit/multimedia/qscreencapture/CMakeLists.txt @@ -0,0 +1,18 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +##################################################################### +## tst_qscreencapture Test: +##################################################################### + +qt_internal_add_test(tst_qscreencapture + SOURCES + tst_qscreencapture.cpp + INCLUDE_DIRECTORIES + ../../mockbackend + LIBRARIES + # Remove: L${CMAKE_CURRENT_SOURCE_DIR} + Qt::Gui + Qt::MultimediaPrivate + MockMultimediaPlugin +) diff --git a/tests/auto/unit/multimedia/qscreencapture/tst_qscreencapture.cpp b/tests/auto/unit/multimedia/qscreencapture/tst_qscreencapture.cpp new file mode 100644 index 000000000..ad574ddf6 --- /dev/null +++ b/tests/auto/unit/multimedia/qscreencapture/tst_qscreencapture.cpp @@ -0,0 +1,64 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +// TESTED_COMPONENT=src/multimedia + +#include <QtTest/QtTest> +#include <QDebug> + +#include "qmockintegration.h" +#include "qscreencapture.h" +#include "qmocksurfacecapture.h" +#include "qatomic.h" + +QT_USE_NAMESPACE + +Q_ENABLE_MOCK_MULTIMEDIA_PLUGIN + +class tst_QScreenCapture : public QObject +{ + Q_OBJECT + +private: + // Use custom waiting instead of QSignalSpy since the spy tries copying not sharable object + // QVideoFrame to QVariant and gets an assert + bool waitForFrame(QPlatformSurfaceCapture &psc) + { + QAtomicInteger<bool> newFrameReceived = false; + QObject o; + auto connection = connect(&psc, &QPlatformSurfaceCapture::newVideoFrame, &o, + [&newFrameReceived]() { newFrameReceived = true; }); + + return QTest::qWaitFor([&newFrameReceived]() { return newFrameReceived; }); + } + +private slots: + void destructionOfActiveCapture(); + +}; + +void tst_QScreenCapture::destructionOfActiveCapture() +{ + // Run a few times in order to catch random UB on deletion + for (int i = 0; i < 10; ++i) { + auto sc = std::make_unique<QScreenCapture>(); + QPointer<QPlatformSurfaceCapture> psc = QMockIntegration::instance()->lastScreenCapture(); + QVERIFY(psc); + + sc->setActive(true); + + QVERIFY(waitForFrame(*psc)); + + QSignalSpy spy(sc.get(), &QScreenCapture::activeChanged); + + psc->setParent(nullptr); + sc.reset(); + + QVERIFY2(spy.empty(), "No signals from QScreenCapture are expected on deletion"); + QVERIFY2(!psc, "Platform screen capture must be deleted whether or not it has a parent"); + } +} + +QTEST_MAIN(tst_QScreenCapture) + +#include "tst_qscreencapture.moc" |