From 586abbd9732f9ccce127429fe0698c25a09ecefb Mon Sep 17 00:00:00 2001 From: Yoann Lopes Date: Wed, 10 Aug 2016 12:53:13 +0200 Subject: Make tst_QMediaObject::notifySignals() less flaky Rather than expecting a certain amount of signals to be fired within a fixed period, check that all the required signals are emitted and that it doesn't take longer than expected. Use a margin of error to take into account timers firing later because of high system load. Change-Id: I7f77d32a9db3d09881eadbd0dfc6b70f62757d09 Reviewed-by: Christian Stromme --- tests/auto/unit/qmediaobject/tst_qmediaobject.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/auto/unit/qmediaobject/tst_qmediaobject.cpp b/tests/auto/unit/qmediaobject/tst_qmediaobject.cpp index 31775249a..0548d1e1a 100644 --- a/tests/auto/unit/qmediaobject/tst_qmediaobject.cpp +++ b/tests/auto/unit/qmediaobject/tst_qmediaobject.cpp @@ -288,14 +288,19 @@ void tst_QMediaObject::notifySignals() QFETCH(int, count); QtTestMediaObject object; + QSignalSpy spy(&object, SIGNAL(aChanged(int))); + object.setNotifyInterval(interval); object.addPropertyWatch("a"); - QSignalSpy spy(&object, SIGNAL(aChanged(int))); + QElapsedTimer timer; + timer.start(); - QTestEventLoop::instance().enterLoop(1); + QTRY_COMPARE(spy.count(), count); - QCOMPARE(spy.count(), count); + qint64 elapsed = timer.elapsed(); + int expectedElapsed = count * interval * 1.3; // give it some margin of error + QVERIFY2(elapsed < expectedElapsed, QString("elapsed: %1, expected: %2").arg(elapsed).arg(expectedElapsed).toLocal8Bit().constData()); } void tst_QMediaObject::notifyInterval_data() -- cgit v1.2.3 From 87abe0bad1945decd71345633be0509b29ab9396 Mon Sep 17 00:00:00 2001 From: Yoann Lopes Date: Wed, 3 Aug 2016 15:41:30 +0200 Subject: Improve tst_QMediaPlayerBackend::playPauseStop() Check the state of the media player when trying to play or pause without a loaded media. Change-Id: I6685f196457630eb9f4e834426c8e1b9a9eaf8dc Reviewed-by: Christian Stromme --- .../tst_qmediaplayerbackend.cpp | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'tests') diff --git a/tests/auto/integration/qmediaplayerbackend/tst_qmediaplayerbackend.cpp b/tests/auto/integration/qmediaplayerbackend/tst_qmediaplayerbackend.cpp index c032734c5..81fa3dd21 100644 --- a/tests/auto/integration/qmediaplayerbackend/tst_qmediaplayerbackend.cpp +++ b/tests/auto/integration/qmediaplayerbackend/tst_qmediaplayerbackend.cpp @@ -332,6 +332,33 @@ void tst_QMediaPlayerBackend::playPauseStop() QSignalSpy stateSpy(&player, SIGNAL(stateChanged(QMediaPlayer::State))); QSignalSpy statusSpy(&player, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus))); QSignalSpy positionSpy(&player, SIGNAL(positionChanged(qint64))); + QSignalSpy errorSpy(&player, SIGNAL(error(QMediaPlayer::Error))); + + // Check play() without a media + player.play(); + + QCOMPARE(player.state(), QMediaPlayer::StoppedState); + QCOMPARE(player.mediaStatus(), QMediaPlayer::NoMedia); + QCOMPARE(player.error(), QMediaPlayer::NoError); + QCOMPARE(player.position(), 0); + QCOMPARE(stateSpy.count(), 0); + QCOMPARE(statusSpy.count(), 0); + QCOMPARE(positionSpy.count(), 0); + QCOMPARE(errorSpy.count(), 0); + + // Check pause() without a media + player.pause(); + + QCOMPARE(player.state(), QMediaPlayer::StoppedState); + QCOMPARE(player.mediaStatus(), QMediaPlayer::NoMedia); + QCOMPARE(player.error(), QMediaPlayer::NoError); + QCOMPARE(player.position(), 0); + QCOMPARE(stateSpy.count(), 0); + QCOMPARE(statusSpy.count(), 0); + QCOMPARE(positionSpy.count(), 0); + QCOMPARE(errorSpy.count(), 0); + + // The rest is with a valid media player.setMedia(localWavFile); -- cgit v1.2.3