diff options
Diffstat (limited to 'tests/auto/unit/multimedia/qmediarecorder/tst_qmediarecorder.cpp')
-rw-r--r-- | tests/auto/unit/multimedia/qmediarecorder/tst_qmediarecorder.cpp | 138 |
1 files changed, 68 insertions, 70 deletions
diff --git a/tests/auto/unit/multimedia/qmediarecorder/tst_qmediarecorder.cpp b/tests/auto/unit/multimedia/qmediarecorder/tst_qmediarecorder.cpp index 9808d065d..a11f39207 100644 --- a/tests/auto/unit/multimedia/qmediarecorder/tst_qmediarecorder.cpp +++ b/tests/auto/unit/multimedia/qmediarecorder/tst_qmediarecorder.cpp @@ -1,32 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -//TESTED_COMPONENT=src/multimedia +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtTest/QtTest> #include <QDebug> @@ -35,8 +8,10 @@ #include "private/qguiapplication_p.h" #include <qmediarecorder.h> #include <qaudioformat.h> -#include <qmockintegration_p.h> +#include <qmockintegration.h> #include <qmediacapturesession.h> +#include <qscreencapture.h> +#include <qwindowcapture.h> #include "qguiapplication_platform.h" #include "qmockmediacapturesession.h" @@ -44,6 +19,8 @@ QT_USE_NAMESPACE +Q_ENABLE_MOCK_MULTIMEDIA_PLUGIN + class tst_QMediaRecorder : public QObject { Q_OBJECT @@ -55,7 +32,7 @@ public slots: private slots: void testBasicSession(); void testNullControls(); - void testDeleteMediaSource(); + void testDeleteMediaCapture(); void testError(); void testSink(); void testRecord(); @@ -75,7 +52,6 @@ private slots: void testApplicationInative(); private: - QMockIntegration *mockIntegration = nullptr; QMediaCaptureSession *captureSession; QCamera *object = nullptr; QMockMediaCaptureSession *service = nullptr; @@ -85,13 +61,12 @@ private: void tst_QMediaRecorder::initTestCase() { - mockIntegration = new QMockIntegration; captureSession = new QMediaCaptureSession; object = new QCamera; encoder = new QMediaRecorder; captureSession->setCamera(object); captureSession->setRecorder(encoder); - service = mockIntegration->lastCaptureService(); + service = QMockIntegration::instance()->lastCaptureService(); mock = service->mockControl; } @@ -100,7 +75,6 @@ void tst_QMediaRecorder::cleanupTestCase() delete encoder; delete object; delete captureSession; - delete mockIntegration; } void tst_QMediaRecorder::testBasicSession() @@ -151,56 +125,80 @@ void tst_QMediaRecorder::testNullControls() QCOMPARE(recorder.mediaFormat().videoCodec(), QMediaFormat::VideoCodec::VP9); QCOMPARE(recorder.mediaFormat().fileFormat(), QMediaFormat::MPEG4); - QSignalSpy spy(&recorder, SIGNAL(recorderStateChanged(RecorderState))); + QSignalSpy spy(&recorder, &QMediaRecorder::recorderStateChanged); recorder.record(); QCOMPARE(recorder.recorderState(), QMediaRecorder::StoppedState); QCOMPARE(recorder.error(), QMediaRecorder::NoError); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); recorder.pause(); QCOMPARE(recorder.recorderState(), QMediaRecorder::StoppedState); QCOMPARE(recorder.error(), QMediaRecorder::NoError); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); recorder.stop(); QCOMPARE(recorder.recorderState(), QMediaRecorder::StoppedState); QCOMPARE(recorder.error(), QMediaRecorder::NoError); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); } -void tst_QMediaRecorder::testDeleteMediaSource() +void tst_QMediaRecorder::testDeleteMediaCapture() { QMediaCaptureSession session; - QCamera *camera = new QCamera; - QMediaRecorder *recorder = new QMediaRecorder; - session.setCamera(camera); - session.setRecorder(recorder); + QMediaRecorder recorder; + + session.setRecorder(&recorder); + + auto checkSourceDeleting = [&](auto setter, auto getter, auto signal) { + using Type = std::remove_pointer_t<decltype((session.*getter)())>; + + auto errorPrinter = qScopeGuard( + []() { qDebug() << QMetaType::fromType<Type>().name() << "deleting failed"; }); + + auto capture = std::make_unique<Type>(); + + (session.*setter)(capture.get()); + + QVERIFY((session.*getter)() == capture.get()); + + QSignalSpy spy(&session, signal); + capture.reset(); - QVERIFY(session.camera() == camera); - QVERIFY(recorder->isAvailable()); + QCOMPARE(spy.size(), 1); + QCOMPARE((session.*getter)(), nullptr); - delete camera; + QVERIFY(recorder.isAvailable()); - QVERIFY(session.camera() == nullptr); - QVERIFY(recorder->isAvailable()); + errorPrinter.dismiss(); + }; - delete recorder; + checkSourceDeleting(&QMediaCaptureSession::setImageCapture, + &QMediaCaptureSession::imageCapture, + &QMediaCaptureSession::imageCaptureChanged); + checkSourceDeleting(&QMediaCaptureSession::setCamera, &QMediaCaptureSession::camera, + &QMediaCaptureSession::cameraChanged); + checkSourceDeleting(&QMediaCaptureSession::setScreenCapture, + &QMediaCaptureSession::screenCapture, + &QMediaCaptureSession::screenCaptureChanged); + checkSourceDeleting(&QMediaCaptureSession::setWindowCapture, + &QMediaCaptureSession::windowCapture, + &QMediaCaptureSession::windowCaptureChanged); } void tst_QMediaRecorder::testError() { const QString errorString(QLatin1String("format error")); - QSignalSpy spy(encoder, SIGNAL(errorOccurred(Error, const QString&))); + QSignalSpy spy(encoder, &QMediaRecorder::errorOccurred); QCOMPARE(encoder->error(), QMediaRecorder::NoError); QCOMPARE(encoder->errorString(), QString()); - mock->error(QMediaRecorder::FormatError, errorString); + mock->updateError(QMediaRecorder::FormatError, errorString); QCOMPARE(encoder->error(), QMediaRecorder::FormatError); QCOMPARE(encoder->errorString(), errorString); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QCOMPARE(spy.last()[0].value<QMediaRecorder::Error>(), QMediaRecorder::FormatError); } @@ -209,14 +207,14 @@ void tst_QMediaRecorder::testSink() { encoder->setOutputLocation(QUrl("test.tmp")); QUrl s = encoder->outputLocation(); - QCOMPARE(s.toString(), QString("test.tmp")); + QCOMPARE(s.toString(), QStringLiteral("test.tmp")); QCOMPARE(encoder->actualLocation(), QUrl()); //the actual location is available after record encoder->record(); - QCOMPARE(encoder->actualLocation().toString(), QString("test.tmp")); + QCOMPARE(encoder->actualLocation().toString(), QStringLiteral("test.tmp")); encoder->stop(); - QCOMPARE(encoder->actualLocation().toString(), QString("test.tmp")); + QCOMPARE(encoder->actualLocation().toString(), QStringLiteral("test.tmp")); //setOutputLocation resets the actual location encoder->setOutputLocation(QUrl()); @@ -232,37 +230,37 @@ void tst_QMediaRecorder::testSink() void tst_QMediaRecorder::testRecord() { - QSignalSpy stateSignal(encoder,SIGNAL(recorderStateChanged(RecorderState))); - QSignalSpy progressSignal(encoder, SIGNAL(durationChanged(qint64))); + QSignalSpy stateSignal(encoder, &QMediaRecorder::recorderStateChanged); + QSignalSpy progressSignal(encoder, &QMediaRecorder::durationChanged); encoder->record(); QCOMPARE(encoder->recorderState(), QMediaRecorder::RecordingState); QCOMPARE(encoder->error(), QMediaRecorder::NoError); QCOMPARE(encoder->errorString(), QString()); - QCOMPARE(stateSignal.count(), 1); + QCOMPARE(stateSignal.size(), 1); QCOMPARE(stateSignal.last()[0].value<QMediaRecorder::RecorderState>(), QMediaRecorder::RecordingState); QTestEventLoop::instance().enterLoop(1); - QVERIFY(progressSignal.count() > 0); + QVERIFY(progressSignal.size() > 0); encoder->pause(); QCOMPARE(encoder->recorderState(), QMediaRecorder::PausedState); - QCOMPARE(stateSignal.count(), 2); + QCOMPARE(stateSignal.size(), 2); QTestEventLoop::instance().enterLoop(1); encoder->stop(); QCOMPARE(encoder->recorderState(), QMediaRecorder::StoppedState); - QCOMPARE(stateSignal.count(), 3); + QCOMPARE(stateSignal.size(), 3); QTestEventLoop::instance().enterLoop(1); mock->stop(); - QCOMPARE(stateSignal.count(), 3); + QCOMPARE(stateSignal.size(), 3); mock->reset(); } @@ -388,10 +386,10 @@ void tst_QMediaRecorder::metaData() QVERIFY(recorder.metaData().isEmpty()); QMediaMetaData data; - data.insert(QMediaMetaData::Author, QString::fromUtf8("John Doe")); + data.insert(QMediaMetaData::Author, QStringLiteral("John Doe")); recorder.setMetaData(data); - QCOMPARE(recorder.metaData().value(QMediaMetaData::Author).toString(), QString::fromUtf8("John Doe")); + QCOMPARE(recorder.metaData().value(QMediaMetaData::Author).toString(), QStringLiteral("John Doe")); } void tst_QMediaRecorder::testIsAvailable() @@ -415,15 +413,15 @@ void tst_QMediaRecorder::testEnum() { const QString errorString(QLatin1String("resource error")); - QSignalSpy spy(encoder, SIGNAL(errorOccurred(Error, const QString&))); + QSignalSpy spy(encoder, &QMediaRecorder::errorOccurred); QCOMPARE(encoder->error(), QMediaRecorder::NoError); QCOMPARE(encoder->errorString(), QString()); - emit mock->error(QMediaRecorder::ResourceError, errorString); + mock->updateError(QMediaRecorder::ResourceError, errorString); QCOMPARE(encoder->error(), QMediaRecorder::ResourceError); QCOMPARE(encoder->errorString(), errorString); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QCOMPARE(spy.last()[0].value<QMediaRecorder::Error>(), QMediaRecorder::ResourceError); } @@ -473,7 +471,7 @@ void tst_QMediaRecorder::testApplicationInative() encoder.setQuality(QMediaRecorder::VeryHighQuality); encoder.setOutputLocation(QUrl("test.tmp")); - QCOMPARE(encoder.outputLocation().toString(), QString("test.tmp")); + QCOMPARE(encoder.outputLocation().toString(), QStringLiteral("test.tmp")); QCOMPARE(encoder.actualLocation(), QUrl()); encoder.record(); @@ -487,7 +485,7 @@ void tst_QMediaRecorder::testApplicationInative() encoder.stop(); // the actual location is available after record - QCOMPARE(encoder.actualLocation().toString(), QString("test.tmp")); + QCOMPARE(encoder.actualLocation().toString(), QStringLiteral("test.tmp")); } QTEST_GUILESS_MAIN(tst_QMediaRecorder) |