Skip to content

Commit

Permalink
adjust unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ddanilov committed Jul 20, 2024
1 parent 424613d commit 50eef58
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
10 changes: 5 additions & 5 deletions tests/TestMainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void TestMainWindow::testTrackFromMedia()
auto* track = track_control->track();
QCOMPARE(track->title(), "sound_01");
QCOMPARE(track->volume(), 0.50);
#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)
#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0) || QT_VERSION >= QT_VERSION_CHECK(6, 6, 0)
QVERIFY(track->isPlaying());
#endif

Expand All @@ -54,14 +54,14 @@ void TestMainWindow::testTrackFromMedia()
QVERIFY(track_control != nullptr);
QCOMPARE(track->title(), "sound_02");
QCOMPARE(track->volume(), 0.50);
#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)
#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0) || QT_VERSION >= QT_VERSION_CHECK(6, 6, 0)
QVERIFY(track->isPlaying());
#endif
}

void TestMainWindow::testSaveTracksToJson()
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) && QT_VERSION < QT_VERSION_CHECK(6, 6, 0)
QSKIP("Test does not work");
#endif

Expand Down Expand Up @@ -233,7 +233,7 @@ void TestMainWindow::testLoadTracksFromJson()
auto* track = track_control->track();
QCOMPARE(track->title(), "sound_01");
QCOMPARE(track->volume(), 0.51);
#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)
#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0) || QT_VERSION >= QT_VERSION_CHECK(6, 6, 0)
QVERIFY(track->isPlaying());
#endif
//
Expand All @@ -249,7 +249,7 @@ void TestMainWindow::testLoadTracksFromJson()
track = track_control->track();
QCOMPARE(track->title(), "sound_03");
QCOMPARE(track->volume(), 0.53);
#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)
#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0) || QT_VERSION >= QT_VERSION_CHECK(6, 6, 0)
QVERIFY(track->isPlaying());
#endif
}
Expand Down
6 changes: 3 additions & 3 deletions tests/TestPlayer.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2022-2023 Denis Danilov
// SPDX-FileCopyrightText: 2022-2024 Denis Danilov
// SPDX-License-Identifier: GPL-3.0-only

#include "Player.h"
Expand Down Expand Up @@ -92,7 +92,7 @@ void TestPlayer::testAudioFileDurationZero()

void TestPlayer::testAudioFileBroken()
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) && QT_VERSION < QT_VERSION_CHECK(6, 6, 0)
QSKIP("Test does not work");
#endif

Expand All @@ -105,7 +105,7 @@ void TestPlayer::testAudioFileBroken()

void TestPlayer::testMediaFileWithoutAudio()
{
#if defined Q_OS_WIN
#if defined Q_OS_WIN && QT_VERSION < QT_VERSION_CHECK(6, 6, 0)
QSKIP("Test does not work on Windows");
#endif

Expand Down
15 changes: 11 additions & 4 deletions tests/TestTrack.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2022-2023 Denis Danilov
// SPDX-FileCopyrightText: 2022-2024 Denis Danilov
// SPDX-License-Identifier: GPL-3.0-only

#include "JsonRW.h"
Expand Down Expand Up @@ -326,15 +326,22 @@ void TestTrack::testAudioFileOk()
track.pause();
QCOMPARE(track.isPlaying(), false);
QVERIFY(track.playerA()->playbackState() == QMediaPlayer::PlaybackState::PausedState);
QVERIFY(track.playerB()->playbackState() == QMediaPlayer::PlaybackState::PausedState);
QVERIFY(track.playerB()->playbackState() != QMediaPlayer::PlaybackState::PlayingState);

track.play();
QCOMPARE(track.isPlaying(), true);
QVERIFY(track.playerA()->playbackState() == QMediaPlayer::PlaybackState::PlayingState);
QVERIFY(track.playerB()->playbackState() == QMediaPlayer::PlaybackState::PausedState);
QVERIFY(track.playerB()->playbackState() != QMediaPlayer::PlaybackState::PlayingState);

QSignalSpy playbackStateA(track.playerA(), &QMediaPlayer::playbackStateChanged);
QSignalSpy playbackStateB(track.playerB(), &QMediaPlayer::playbackStateChanged);
track.playerA()->mediaPlayerPositionChanged(track.duration());
track.playerA()->mediaPlayerStatusChanged(QMediaPlayer::MediaStatus::EndOfMedia);
#if QT_VERSION >= QT_VERSION_CHECK(6, 6, 0)
QVERIFY(playbackStateA.wait());
QVERIFY(playbackStateB.wait());
#endif

QVERIFY(track.playerA()->playbackState() == QMediaPlayer::PlaybackState::PausedState);
QVERIFY(track.playerB()->playbackState() == QMediaPlayer::PlaybackState::PlayingState);

Expand Down Expand Up @@ -364,7 +371,7 @@ void TestTrack::testAudioFileDurationZero()

void TestTrack::testAudioFileBroken()
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) && QT_VERSION < QT_VERSION_CHECK(6, 6, 0)
QSKIP("Test does not work");
#endif

Expand Down
10 changes: 8 additions & 2 deletions tests/TestTrackControls.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2022-2023 Denis Danilov
// SPDX-FileCopyrightText: 2022-2024 Denis Danilov
// SPDX-License-Identifier: GPL-3.0-only

#include "JsonRW.h"
Expand Down Expand Up @@ -104,7 +104,7 @@ void TestTrackControls::testAudioFileOk()

void TestTrackControls::testAudioFileBroken()
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) && QT_VERSION < QT_VERSION_CHECK(6, 6, 0)
QSKIP("Test does not work");
#endif

Expand Down Expand Up @@ -187,8 +187,14 @@ void TestTrackControls::testPauseAndResume()
// player A is active, player B is not
test_playing_state(track->playerA(), track->playerB());

QSignalSpy playbackStateA(track->playerA(), &QMediaPlayer::playbackStateChanged);
QSignalSpy playbackStateB(track->playerB(), &QMediaPlayer::playbackStateChanged);
track->playerA()->mediaPlayerPositionChanged(track->duration());
track->playerA()->mediaPlayerStatusChanged(QMediaPlayer::MediaStatus::EndOfMedia);
#if QT_VERSION >= QT_VERSION_CHECK(6, 6, 0)
QVERIFY(playbackStateA.wait());
QVERIFY(playbackStateB.wait());
#endif
// player B is active, player A is not
test_playing_state(track->playerB(), track->playerA());
}
Expand Down

0 comments on commit 50eef58

Please sign in to comment.