diff --git a/autotests/manageaudioplayertest.cpp b/autotests/manageaudioplayertest.cpp index aef24019..3af122eb 100644 --- a/autotests/manageaudioplayertest.cpp +++ b/autotests/manageaudioplayertest.cpp @@ -1,5195 +1,6147 @@ /* * Copyright 2016 Matthieu Gallien * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "manageaudioplayertest.h" #include "manageaudioplayer.h" #include #include #include #include ManageAudioPlayerTest::ManageAudioPlayerTest(QObject *parent) : QObject(parent) { } void ManageAudioPlayerTest::initTestCase() { } void ManageAudioPlayerTest::simpleInitialCase() { ManageAudioPlayer myPlayer; QStandardItemModel myPlayList; QSignalSpy currentTrackChangedSpy(&myPlayer, &ManageAudioPlayer::currentTrackChanged); QSignalSpy playListModelChangedSpy(&myPlayer, &ManageAudioPlayer::playListModelChanged); QSignalSpy playerSourceChangedSpy(&myPlayer, &ManageAudioPlayer::playerSourceChanged); QSignalSpy urlRoleChangedSpy(&myPlayer, &ManageAudioPlayer::urlRoleChanged); QSignalSpy isPlayingRoleChangedSpy(&myPlayer, &ManageAudioPlayer::isPlayingRoleChanged); QSignalSpy playerStatusChangedSpy(&myPlayer, &ManageAudioPlayer::playerStatusChanged); QSignalSpy playerPlaybackStateChangedSpy(&myPlayer, &ManageAudioPlayer::playerPlaybackStateChanged); QSignalSpy playerErrorChangedSpy(&myPlayer, &ManageAudioPlayer::playerErrorChanged); QSignalSpy persistentStateChangedSpy(&myPlayer, &ManageAudioPlayer::persistentStateChanged); QSignalSpy playerPlaySpy(&myPlayer, &ManageAudioPlayer::playerPlay); QSignalSpy playerPauseSpy(&myPlayer, &ManageAudioPlayer::playerPause); QSignalSpy playerStopSpy(&myPlayer, &ManageAudioPlayer::playerStop); QSignalSpy skipNextTrackSpy(&myPlayer, &ManageAudioPlayer::skipNextTrack); + QSignalSpy seekSpy(&myPlayer, &ManageAudioPlayer::seek); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.item(0, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///1.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(1, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///2.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(2, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///3.mp3")), ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayListModel(&myPlayList); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setCurrentTrack(myPlayList.index(0, 0)); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayer.setUrlRole(ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.urlRole(), static_cast(ManageAudioPlayerTest::ResourceRole)); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///1.mp3"))); myPlayer.setIsPlayingRole(ManageAudioPlayerTest::IsPlayingRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.isPlayingRole(), static_cast(ManageAudioPlayerTest::IsPlayingRole)); myPlayer.setPlayerStatus(ManageAudioPlayer::Loading); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Loading)); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerError(ManageAudioPlayer::NoError); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerStatus(ManageAudioPlayer::Loaded); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 2); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Loaded)); myPlayer.setPlayerStatus(ManageAudioPlayer::Buffering); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Buffering)); myPlayer.playPause(); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(playerPlaySpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::PlayingState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::PlayingState)); myPlayer.setPlayerStatus(ManageAudioPlayer::EndOfMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::EndOfMedia)); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::StoppedState)); myPlayer.setPlayerStatus(ManageAudioPlayer::InvalidMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::InvalidMedia)); QCOMPARE(skipNextTrackSpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); } void ManageAudioPlayerTest::noPlayCase() { ManageAudioPlayer myPlayer; QStandardItemModel myPlayList; QSignalSpy currentTrackChangedSpy(&myPlayer, &ManageAudioPlayer::currentTrackChanged); QSignalSpy playListModelChangedSpy(&myPlayer, &ManageAudioPlayer::playListModelChanged); QSignalSpy playerSourceChangedSpy(&myPlayer, &ManageAudioPlayer::playerSourceChanged); QSignalSpy urlRoleChangedSpy(&myPlayer, &ManageAudioPlayer::urlRoleChanged); QSignalSpy isPlayingRoleChangedSpy(&myPlayer, &ManageAudioPlayer::isPlayingRoleChanged); QSignalSpy playerStatusChangedSpy(&myPlayer, &ManageAudioPlayer::playerStatusChanged); QSignalSpy playerPlaybackStateChangedSpy(&myPlayer, &ManageAudioPlayer::playerPlaybackStateChanged); QSignalSpy playerErrorChangedSpy(&myPlayer, &ManageAudioPlayer::playerErrorChanged); QSignalSpy persistentStateChangedSpy(&myPlayer, &ManageAudioPlayer::persistentStateChanged); QSignalSpy playerPlaySpy(&myPlayer, &ManageAudioPlayer::playerPlay); QSignalSpy playerPauseSpy(&myPlayer, &ManageAudioPlayer::playerPause); QSignalSpy playerStopSpy(&myPlayer, &ManageAudioPlayer::playerStop); QSignalSpy skipNextTrackSpy(&myPlayer, &ManageAudioPlayer::skipNextTrack); + QSignalSpy seekSpy(&myPlayer, &ManageAudioPlayer::seek); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.item(0, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///1.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(1, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///2.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(2, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///3.mp3")), ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayListModel(&myPlayList); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setCurrentTrack(myPlayList.index(0, 0)); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayer.setUrlRole(ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.urlRole(), static_cast(ManageAudioPlayerTest::ResourceRole)); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///1.mp3"))); myPlayer.setIsPlayingRole(ManageAudioPlayerTest::IsPlayingRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.isPlayingRole(), static_cast(ManageAudioPlayerTest::IsPlayingRole)); myPlayer.setPlayerStatus(ManageAudioPlayer::Loading); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Loading)); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerError(ManageAudioPlayer::NoError); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerStatus(ManageAudioPlayer::Loaded); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 2); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Loaded)); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 2); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerStatus(ManageAudioPlayer::Buffering); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Buffering)); QCOMPARE(playerPlaySpy.wait(100), false); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); } void ManageAudioPlayerTest::skipNextTrack() { ManageAudioPlayer myPlayer; QStandardItemModel myPlayList; QSignalSpy currentTrackChangedSpy(&myPlayer, &ManageAudioPlayer::currentTrackChanged); QSignalSpy playListModelChangedSpy(&myPlayer, &ManageAudioPlayer::playListModelChanged); QSignalSpy playerSourceChangedSpy(&myPlayer, &ManageAudioPlayer::playerSourceChanged); QSignalSpy urlRoleChangedSpy(&myPlayer, &ManageAudioPlayer::urlRoleChanged); QSignalSpy isPlayingRoleChangedSpy(&myPlayer, &ManageAudioPlayer::isPlayingRoleChanged); QSignalSpy playerStatusChangedSpy(&myPlayer, &ManageAudioPlayer::playerStatusChanged); QSignalSpy playerPlaybackStateChangedSpy(&myPlayer, &ManageAudioPlayer::playerPlaybackStateChanged); QSignalSpy playerErrorChangedSpy(&myPlayer, &ManageAudioPlayer::playerErrorChanged); QSignalSpy persistentStateChangedSpy(&myPlayer, &ManageAudioPlayer::persistentStateChanged); QSignalSpy playerPlaySpy(&myPlayer, &ManageAudioPlayer::playerPlay); QSignalSpy playerPauseSpy(&myPlayer, &ManageAudioPlayer::playerPause); QSignalSpy playerStopSpy(&myPlayer, &ManageAudioPlayer::playerStop); QSignalSpy skipNextTrackSpy(&myPlayer, &ManageAudioPlayer::skipNextTrack); + QSignalSpy seekSpy(&myPlayer, &ManageAudioPlayer::seek); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.item(0, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///1.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(1, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///2.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(2, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///3.mp3")), ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayListModel(&myPlayList); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setCurrentTrack(myPlayList.index(0, 0)); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayer.setUrlRole(ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.urlRole(), static_cast(ManageAudioPlayerTest::ResourceRole)); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///1.mp3"))); myPlayer.setIsPlayingRole(ManageAudioPlayerTest::IsPlayingRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.isPlayingRole(), static_cast(ManageAudioPlayerTest::IsPlayingRole)); myPlayer.setPlayerStatus(ManageAudioPlayer::Loading); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Loading)); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerError(ManageAudioPlayer::NoError); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerStatus(ManageAudioPlayer::Loaded); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 2); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Loaded)); myPlayer.setPlayerStatus(ManageAudioPlayer::Buffering); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Buffering)); myPlayer.playPause(); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(playerPlaySpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::PlayingState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::PlayingState)); myPlayer.setPlayerStatus(ManageAudioPlayer::EndOfMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::EndOfMedia)); myPlayer.setCurrentTrack(myPlayList.index(1, 0)); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(1, 0))); QCOMPARE(playerStopSpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::StoppedState)); QCOMPARE(skipNextTrackSpy.wait(100), false); myPlayer.setPlayerStatus(ManageAudioPlayer::Loaded); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Loaded)); myPlayer.setPlayerStatus(ManageAudioPlayer::Buffering); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 6); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Buffering)); QCOMPARE(playerPlaySpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 6); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); } void ManageAudioPlayerTest::skipPreviousTrack() { ManageAudioPlayer myPlayer; QStandardItemModel myPlayList; QSignalSpy currentTrackChangedSpy(&myPlayer, &ManageAudioPlayer::currentTrackChanged); QSignalSpy playListModelChangedSpy(&myPlayer, &ManageAudioPlayer::playListModelChanged); QSignalSpy playerSourceChangedSpy(&myPlayer, &ManageAudioPlayer::playerSourceChanged); QSignalSpy urlRoleChangedSpy(&myPlayer, &ManageAudioPlayer::urlRoleChanged); QSignalSpy isPlayingRoleChangedSpy(&myPlayer, &ManageAudioPlayer::isPlayingRoleChanged); QSignalSpy playerStatusChangedSpy(&myPlayer, &ManageAudioPlayer::playerStatusChanged); QSignalSpy playerPlaybackStateChangedSpy(&myPlayer, &ManageAudioPlayer::playerPlaybackStateChanged); QSignalSpy playerErrorChangedSpy(&myPlayer, &ManageAudioPlayer::playerErrorChanged); QSignalSpy persistentStateChangedSpy(&myPlayer, &ManageAudioPlayer::persistentStateChanged); QSignalSpy playerPlaySpy(&myPlayer, &ManageAudioPlayer::playerPlay); QSignalSpy playerPauseSpy(&myPlayer, &ManageAudioPlayer::playerPause); QSignalSpy playerStopSpy(&myPlayer, &ManageAudioPlayer::playerStop); QSignalSpy skipNextTrackSpy(&myPlayer, &ManageAudioPlayer::skipNextTrack); + QSignalSpy seekSpy(&myPlayer, &ManageAudioPlayer::seek); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.item(0, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///1.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(1, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///2.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(2, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///3.mp3")), ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayListModel(&myPlayList); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setCurrentTrack(myPlayList.index(1, 0)); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(1, 0))); myPlayer.setUrlRole(ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.urlRole(), static_cast(ManageAudioPlayerTest::ResourceRole)); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///2.mp3"))); myPlayer.setIsPlayingRole(ManageAudioPlayerTest::IsPlayingRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.isPlayingRole(), static_cast(ManageAudioPlayerTest::IsPlayingRole)); myPlayer.setPlayerStatus(ManageAudioPlayer::Loading); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Loading)); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerError(ManageAudioPlayer::NoError); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerStatus(ManageAudioPlayer::Loaded); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 2); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Loaded)); myPlayer.setPlayerStatus(ManageAudioPlayer::Buffering); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Buffering)); myPlayer.playPause(); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(playerPlaySpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::PlayingState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::PlayingState)); myPlayer.setPlayerStatus(ManageAudioPlayer::EndOfMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::EndOfMedia)); myPlayer.setCurrentTrack(myPlayList.index(0, 0)); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); QCOMPARE(playerStopSpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::StoppedState)); QCOMPARE(skipNextTrackSpy.wait(100), false); myPlayer.setPlayerStatus(ManageAudioPlayer::Loaded); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Loaded)); myPlayer.setPlayerStatus(ManageAudioPlayer::Buffering); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 6); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Buffering)); QCOMPARE(playerPlaySpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 6); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); } void ManageAudioPlayerTest::playTrackAndskipNextTrack() { ManageAudioPlayer myPlayer; QStandardItemModel myPlayList; QSignalSpy currentTrackChangedSpy(&myPlayer, &ManageAudioPlayer::currentTrackChanged); QSignalSpy playListModelChangedSpy(&myPlayer, &ManageAudioPlayer::playListModelChanged); QSignalSpy playerSourceChangedSpy(&myPlayer, &ManageAudioPlayer::playerSourceChanged); QSignalSpy urlRoleChangedSpy(&myPlayer, &ManageAudioPlayer::urlRoleChanged); QSignalSpy isPlayingRoleChangedSpy(&myPlayer, &ManageAudioPlayer::isPlayingRoleChanged); QSignalSpy playerStatusChangedSpy(&myPlayer, &ManageAudioPlayer::playerStatusChanged); QSignalSpy playerPlaybackStateChangedSpy(&myPlayer, &ManageAudioPlayer::playerPlaybackStateChanged); QSignalSpy playerErrorChangedSpy(&myPlayer, &ManageAudioPlayer::playerErrorChanged); QSignalSpy persistentStateChangedSpy(&myPlayer, &ManageAudioPlayer::persistentStateChanged); QSignalSpy playerPlaySpy(&myPlayer, &ManageAudioPlayer::playerPlay); QSignalSpy playerPauseSpy(&myPlayer, &ManageAudioPlayer::playerPause); QSignalSpy playerStopSpy(&myPlayer, &ManageAudioPlayer::playerStop); QSignalSpy skipNextTrackSpy(&myPlayer, &ManageAudioPlayer::skipNextTrack); + QSignalSpy seekSpy(&myPlayer, &ManageAudioPlayer::seek); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.item(0, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///1.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(1, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///2.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(2, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///3.mp3")), ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayListModel(&myPlayList); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setCurrentTrack(myPlayList.index(0, 0)); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayer.setUrlRole(ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.urlRole(), static_cast(ManageAudioPlayerTest::ResourceRole)); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///1.mp3"))); myPlayer.setIsPlayingRole(ManageAudioPlayerTest::IsPlayingRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.isPlayingRole(), static_cast(ManageAudioPlayerTest::IsPlayingRole)); myPlayer.setPlayerStatus(ManageAudioPlayer::Loading); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Loading)); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerError(ManageAudioPlayer::NoError); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerStatus(ManageAudioPlayer::Loaded); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 2); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Loaded)); myPlayer.setPlayerStatus(ManageAudioPlayer::Buffering); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Buffering)); myPlayer.playPause(); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(playerPlaySpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::PlayingState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::PlayingState)); myPlayer.setPlayerStatus(ManageAudioPlayer::EndOfMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::EndOfMedia)); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::StoppedState)); myPlayer.setPlayerStatus(ManageAudioPlayer::InvalidMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::InvalidMedia)); QCOMPARE(skipNextTrackSpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); myPlayer.setCurrentTrack(myPlayList.index(1, 0)); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(1, 0))); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///2.mp3"))); myPlayer.setPlayerStatus(ManageAudioPlayer::Loaded); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 6); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Loaded)); myPlayer.setPlayerStatus(ManageAudioPlayer::Buffering); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 7); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Buffering)); QCOMPARE(playerPlaySpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 7); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::PlayingState); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 7); QCOMPARE(playerPlaybackStateChangedSpy.count(), 3); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::PlayingState)); myPlayer.setPlayerStatus(ManageAudioPlayer::EndOfMedia); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 8); QCOMPARE(playerPlaybackStateChangedSpy.count(), 3); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::EndOfMedia)); myPlayer.setCurrentTrack(myPlayList.index(2, 0)); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 8); QCOMPARE(playerPlaybackStateChangedSpy.count(), 3); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(2, 0))); QCOMPARE(playerStopSpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 8); QCOMPARE(playerPlaybackStateChangedSpy.count(), 3); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 3); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 8); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///3.mp3"))); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::StoppedState)); QCOMPARE(skipNextTrackSpy.wait(100), false); myPlayer.setPlayerStatus(ManageAudioPlayer::Loaded); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 3); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 9); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Loaded)); myPlayer.setPlayerStatus(ManageAudioPlayer::Buffering); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 3); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 10); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Buffering)); QCOMPARE(playerPlaySpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 3); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 10); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 3); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::PlayingState); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 3); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 10); QCOMPARE(playerPlaybackStateChangedSpy.count(), 5); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 3); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::PlayingState)); } void ManageAudioPlayerTest::playTrackAndskipPreviousTrack() { ManageAudioPlayer myPlayer; QStandardItemModel myPlayList; QSignalSpy currentTrackChangedSpy(&myPlayer, &ManageAudioPlayer::currentTrackChanged); QSignalSpy playListModelChangedSpy(&myPlayer, &ManageAudioPlayer::playListModelChanged); QSignalSpy playerSourceChangedSpy(&myPlayer, &ManageAudioPlayer::playerSourceChanged); QSignalSpy urlRoleChangedSpy(&myPlayer, &ManageAudioPlayer::urlRoleChanged); QSignalSpy isPlayingRoleChangedSpy(&myPlayer, &ManageAudioPlayer::isPlayingRoleChanged); QSignalSpy playerStatusChangedSpy(&myPlayer, &ManageAudioPlayer::playerStatusChanged); QSignalSpy playerPlaybackStateChangedSpy(&myPlayer, &ManageAudioPlayer::playerPlaybackStateChanged); QSignalSpy playerErrorChangedSpy(&myPlayer, &ManageAudioPlayer::playerErrorChanged); QSignalSpy persistentStateChangedSpy(&myPlayer, &ManageAudioPlayer::persistentStateChanged); QSignalSpy playerPlaySpy(&myPlayer, &ManageAudioPlayer::playerPlay); QSignalSpy playerPauseSpy(&myPlayer, &ManageAudioPlayer::playerPause); QSignalSpy playerStopSpy(&myPlayer, &ManageAudioPlayer::playerStop); QSignalSpy skipNextTrackSpy(&myPlayer, &ManageAudioPlayer::skipNextTrack); + QSignalSpy seekSpy(&myPlayer, &ManageAudioPlayer::seek); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.item(0, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///1.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(1, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///2.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(2, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///3.mp3")), ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayListModel(&myPlayList); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setCurrentTrack(myPlayList.index(1, 0)); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(1, 0))); myPlayer.setUrlRole(ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.urlRole(), static_cast(ManageAudioPlayerTest::ResourceRole)); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///2.mp3"))); myPlayer.setIsPlayingRole(ManageAudioPlayerTest::IsPlayingRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.isPlayingRole(), static_cast(ManageAudioPlayerTest::IsPlayingRole)); myPlayer.setPlayerStatus(ManageAudioPlayer::Loading); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Loading)); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerError(ManageAudioPlayer::NoError); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerStatus(ManageAudioPlayer::Loaded); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 2); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Loaded)); myPlayer.setPlayerStatus(ManageAudioPlayer::Buffering); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Buffering)); myPlayer.playPause(); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(playerPlaySpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::PlayingState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::PlayingState)); myPlayer.setPlayerStatus(ManageAudioPlayer::EndOfMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::EndOfMedia)); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::StoppedState)); myPlayer.setPlayerStatus(ManageAudioPlayer::InvalidMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::InvalidMedia)); QCOMPARE(skipNextTrackSpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); myPlayer.setCurrentTrack(myPlayList.index(2, 0)); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(2, 0))); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///3.mp3"))); myPlayer.setPlayerStatus(ManageAudioPlayer::Loaded); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 6); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Loaded)); myPlayer.setPlayerStatus(ManageAudioPlayer::Buffering); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 7); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Buffering)); QCOMPARE(playerPlaySpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 7); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::PlayingState); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 7); QCOMPARE(playerPlaybackStateChangedSpy.count(), 3); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::PlayingState)); myPlayer.setPlayerStatus(ManageAudioPlayer::EndOfMedia); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 8); QCOMPARE(playerPlaybackStateChangedSpy.count(), 3); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::EndOfMedia)); myPlayer.setCurrentTrack(myPlayList.index(1, 0)); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 8); QCOMPARE(playerPlaybackStateChangedSpy.count(), 3); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(1, 0))); QCOMPARE(playerStopSpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 8); QCOMPARE(playerPlaybackStateChangedSpy.count(), 3); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 3); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 8); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///2.mp3"))); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::StoppedState)); QCOMPARE(skipNextTrackSpy.wait(100), false); myPlayer.setPlayerStatus(ManageAudioPlayer::Loaded); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 3); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 9); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Loaded)); myPlayer.setPlayerStatus(ManageAudioPlayer::Buffering); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 3); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 10); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Buffering)); QCOMPARE(playerPlaySpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 3); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 10); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 3); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::PlayingState); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 3); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 10); QCOMPARE(playerPlaybackStateChangedSpy.count(), 5); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 3); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::PlayingState)); } void ManageAudioPlayerTest::skipNextTrackAndPlayTrack() { ManageAudioPlayer myPlayer; QStandardItemModel myPlayList; QSignalSpy currentTrackChangedSpy(&myPlayer, &ManageAudioPlayer::currentTrackChanged); QSignalSpy playListModelChangedSpy(&myPlayer, &ManageAudioPlayer::playListModelChanged); QSignalSpy playerSourceChangedSpy(&myPlayer, &ManageAudioPlayer::playerSourceChanged); QSignalSpy urlRoleChangedSpy(&myPlayer, &ManageAudioPlayer::urlRoleChanged); QSignalSpy isPlayingRoleChangedSpy(&myPlayer, &ManageAudioPlayer::isPlayingRoleChanged); QSignalSpy playerStatusChangedSpy(&myPlayer, &ManageAudioPlayer::playerStatusChanged); QSignalSpy playerPlaybackStateChangedSpy(&myPlayer, &ManageAudioPlayer::playerPlaybackStateChanged); QSignalSpy playerErrorChangedSpy(&myPlayer, &ManageAudioPlayer::playerErrorChanged); QSignalSpy persistentStateChangedSpy(&myPlayer, &ManageAudioPlayer::persistentStateChanged); QSignalSpy playerPlaySpy(&myPlayer, &ManageAudioPlayer::playerPlay); QSignalSpy playerPauseSpy(&myPlayer, &ManageAudioPlayer::playerPause); QSignalSpy playerStopSpy(&myPlayer, &ManageAudioPlayer::playerStop); QSignalSpy skipNextTrackSpy(&myPlayer, &ManageAudioPlayer::skipNextTrack); + QSignalSpy seekSpy(&myPlayer, &ManageAudioPlayer::seek); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.item(0, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///1.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(1, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///2.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(2, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///3.mp3")), ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayListModel(&myPlayList); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setCurrentTrack(myPlayList.index(0, 0)); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayer.setUrlRole(ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.urlRole(), static_cast(ManageAudioPlayerTest::ResourceRole)); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///1.mp3"))); myPlayer.setIsPlayingRole(ManageAudioPlayerTest::IsPlayingRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.isPlayingRole(), static_cast(ManageAudioPlayerTest::IsPlayingRole)); myPlayer.setPlayerStatus(ManageAudioPlayer::Loading); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Loading)); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerError(ManageAudioPlayer::NoError); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerStatus(ManageAudioPlayer::Loaded); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 2); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Loaded)); myPlayer.setPlayerStatus(ManageAudioPlayer::Buffering); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Buffering)); myPlayer.playPause(); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(playerPlaySpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::PlayingState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::PlayingState)); myPlayer.setPlayerStatus(ManageAudioPlayer::EndOfMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::EndOfMedia)); myPlayer.setCurrentTrack(myPlayList.index(1, 0)); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(1, 0))); QCOMPARE(playerStopSpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///2.mp3"))); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::StoppedState)); QCOMPARE(skipNextTrackSpy.wait(100), false); myPlayer.setPlayerStatus(ManageAudioPlayer::Loaded); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Loaded)); myPlayer.setPlayerStatus(ManageAudioPlayer::Buffering); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 6); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Buffering)); QCOMPARE(playerPlaySpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 6); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::PlayingState); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 6); QCOMPARE(playerPlaybackStateChangedSpy.count(), 3); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::PlayingState)); myPlayer.setPlayerStatus(ManageAudioPlayer::EndOfMedia); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 7); QCOMPARE(playerPlaybackStateChangedSpy.count(), 3); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::EndOfMedia)); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 7); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::StoppedState)); myPlayer.setPlayerStatus(ManageAudioPlayer::InvalidMedia); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 8); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::InvalidMedia)); QCOMPARE(skipNextTrackSpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 8); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); myPlayer.setCurrentTrack(myPlayList.index(2, 0)); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 3); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 8); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(2, 0))); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///3.mp3"))); myPlayer.setPlayerStatus(ManageAudioPlayer::Loaded); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 3); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 9); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Loaded)); myPlayer.setPlayerStatus(ManageAudioPlayer::Buffering); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 3); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 10); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Buffering)); QCOMPARE(playerPlaySpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 3); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 10); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 3); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); } void ManageAudioPlayerTest::skipPreviousTrackAndPlayTrack() { ManageAudioPlayer myPlayer; QStandardItemModel myPlayList; QSignalSpy currentTrackChangedSpy(&myPlayer, &ManageAudioPlayer::currentTrackChanged); QSignalSpy playListModelChangedSpy(&myPlayer, &ManageAudioPlayer::playListModelChanged); QSignalSpy playerSourceChangedSpy(&myPlayer, &ManageAudioPlayer::playerSourceChanged); QSignalSpy urlRoleChangedSpy(&myPlayer, &ManageAudioPlayer::urlRoleChanged); QSignalSpy isPlayingRoleChangedSpy(&myPlayer, &ManageAudioPlayer::isPlayingRoleChanged); QSignalSpy playerStatusChangedSpy(&myPlayer, &ManageAudioPlayer::playerStatusChanged); QSignalSpy playerPlaybackStateChangedSpy(&myPlayer, &ManageAudioPlayer::playerPlaybackStateChanged); QSignalSpy playerErrorChangedSpy(&myPlayer, &ManageAudioPlayer::playerErrorChanged); QSignalSpy persistentStateChangedSpy(&myPlayer, &ManageAudioPlayer::persistentStateChanged); QSignalSpy playerPlaySpy(&myPlayer, &ManageAudioPlayer::playerPlay); QSignalSpy playerPauseSpy(&myPlayer, &ManageAudioPlayer::playerPause); QSignalSpy playerStopSpy(&myPlayer, &ManageAudioPlayer::playerStop); QSignalSpy skipNextTrackSpy(&myPlayer, &ManageAudioPlayer::skipNextTrack); + QSignalSpy seekSpy(&myPlayer, &ManageAudioPlayer::seek); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.item(0, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///1.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(1, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///2.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(2, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///3.mp3")), ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayListModel(&myPlayList); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setCurrentTrack(myPlayList.index(1, 0)); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(1, 0))); myPlayer.setUrlRole(ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.urlRole(), static_cast(ManageAudioPlayerTest::ResourceRole)); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///2.mp3"))); myPlayer.setIsPlayingRole(ManageAudioPlayerTest::IsPlayingRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.isPlayingRole(), static_cast(ManageAudioPlayerTest::IsPlayingRole)); myPlayer.setPlayerStatus(ManageAudioPlayer::Loading); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Loading)); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerError(ManageAudioPlayer::NoError); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerStatus(ManageAudioPlayer::Loaded); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 2); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Loaded)); myPlayer.setPlayerStatus(ManageAudioPlayer::Buffering); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Buffering)); myPlayer.playPause(); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(playerPlaySpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::PlayingState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::PlayingState)); myPlayer.setPlayerStatus(ManageAudioPlayer::EndOfMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::EndOfMedia)); myPlayer.setCurrentTrack(myPlayList.index(0, 0)); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); QCOMPARE(playerStopSpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///1.mp3"))); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::StoppedState)); QCOMPARE(skipNextTrackSpy.wait(100), false); myPlayer.setPlayerStatus(ManageAudioPlayer::Loaded); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Loaded)); myPlayer.setPlayerStatus(ManageAudioPlayer::Buffering); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 6); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Buffering)); QCOMPARE(playerPlaySpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 6); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::PlayingState); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 6); QCOMPARE(playerPlaybackStateChangedSpy.count(), 3); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::PlayingState)); myPlayer.setPlayerStatus(ManageAudioPlayer::EndOfMedia); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 7); QCOMPARE(playerPlaybackStateChangedSpy.count(), 3); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::EndOfMedia)); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 7); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::StoppedState)); myPlayer.setPlayerStatus(ManageAudioPlayer::InvalidMedia); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 8); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::InvalidMedia)); QCOMPARE(skipNextTrackSpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 8); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); myPlayer.setCurrentTrack(myPlayList.index(1, 0)); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 3); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 8); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(1, 0))); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///2.mp3"))); myPlayer.setPlayerStatus(ManageAudioPlayer::Loaded); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 3); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 9); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Loaded)); myPlayer.setPlayerStatus(ManageAudioPlayer::Buffering); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 3); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 10); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Buffering)); QCOMPARE(playerPlaySpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 3); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 3); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 10); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 3); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); } void ManageAudioPlayerTest::playLastCase() { ManageAudioPlayer myPlayer; QStandardItemModel myPlayList; QSignalSpy currentTrackChangedSpy(&myPlayer, &ManageAudioPlayer::currentTrackChanged); QSignalSpy playListModelChangedSpy(&myPlayer, &ManageAudioPlayer::playListModelChanged); QSignalSpy playerSourceChangedSpy(&myPlayer, &ManageAudioPlayer::playerSourceChanged); QSignalSpy urlRoleChangedSpy(&myPlayer, &ManageAudioPlayer::urlRoleChanged); QSignalSpy isPlayingRoleChangedSpy(&myPlayer, &ManageAudioPlayer::isPlayingRoleChanged); QSignalSpy playerStatusChangedSpy(&myPlayer, &ManageAudioPlayer::playerStatusChanged); QSignalSpy playerPlaybackStateChangedSpy(&myPlayer, &ManageAudioPlayer::playerPlaybackStateChanged); QSignalSpy playerErrorChangedSpy(&myPlayer, &ManageAudioPlayer::playerErrorChanged); QSignalSpy persistentStateChangedSpy(&myPlayer, &ManageAudioPlayer::persistentStateChanged); QSignalSpy playerPlaySpy(&myPlayer, &ManageAudioPlayer::playerPlay); QSignalSpy playerPauseSpy(&myPlayer, &ManageAudioPlayer::playerPause); QSignalSpy playerStopSpy(&myPlayer, &ManageAudioPlayer::playerStop); QSignalSpy skipNextTrackSpy(&myPlayer, &ManageAudioPlayer::skipNextTrack); + QSignalSpy seekSpy(&myPlayer, &ManageAudioPlayer::seek); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.item(0, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///1.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(1, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///2.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(2, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///3.mp3")), ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayListModel(&myPlayList); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setCurrentTrack(myPlayList.index(2, 0)); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(2, 0))); myPlayer.setUrlRole(ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.urlRole(), static_cast(ManageAudioPlayerTest::ResourceRole)); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///3.mp3"))); myPlayer.setIsPlayingRole(ManageAudioPlayerTest::IsPlayingRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.isPlayingRole(), static_cast(ManageAudioPlayerTest::IsPlayingRole)); myPlayer.setPlayerStatus(ManageAudioPlayer::Loading); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Loading)); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerError(ManageAudioPlayer::NoError); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerStatus(ManageAudioPlayer::Loaded); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 2); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Loaded)); myPlayer.setPlayerStatus(ManageAudioPlayer::Buffering); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Buffering)); myPlayer.playPause(); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(playerPlaySpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::PlayingState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), true); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::PlayingState)); myPlayer.setPlayerStatus(ManageAudioPlayer::EndOfMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), true); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::EndOfMedia)); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::StoppedState)); myPlayer.setPlayerStatus(ManageAudioPlayer::InvalidMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::InvalidMedia)); QCOMPARE(skipNextTrackSpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.playListFinished(); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setCurrentTrack(myPlayList.index(0, 0)); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayer.setPlayerStatus(ManageAudioPlayer::Loaded); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 6); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Loaded)); QCOMPARE(playerPlaySpy.wait(100), false); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 6); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); } void ManageAudioPlayerTest::playRestoredTrack() { ManageAudioPlayer myPlayer; QStandardItemModel myPlayList; QSignalSpy currentTrackChangedSpy(&myPlayer, &ManageAudioPlayer::currentTrackChanged); QSignalSpy playListModelChangedSpy(&myPlayer, &ManageAudioPlayer::playListModelChanged); QSignalSpy playerSourceChangedSpy(&myPlayer, &ManageAudioPlayer::playerSourceChanged); QSignalSpy urlRoleChangedSpy(&myPlayer, &ManageAudioPlayer::urlRoleChanged); QSignalSpy isPlayingRoleChangedSpy(&myPlayer, &ManageAudioPlayer::isPlayingRoleChanged); QSignalSpy playerStatusChangedSpy(&myPlayer, &ManageAudioPlayer::playerStatusChanged); QSignalSpy playerPlaybackStateChangedSpy(&myPlayer, &ManageAudioPlayer::playerPlaybackStateChanged); QSignalSpy playerErrorChangedSpy(&myPlayer, &ManageAudioPlayer::playerErrorChanged); QSignalSpy persistentStateChangedSpy(&myPlayer, &ManageAudioPlayer::persistentStateChanged); QSignalSpy playerPlaySpy(&myPlayer, &ManageAudioPlayer::playerPlay); QSignalSpy playerPauseSpy(&myPlayer, &ManageAudioPlayer::playerPause); QSignalSpy playerStopSpy(&myPlayer, &ManageAudioPlayer::playerStop); QSignalSpy skipNextTrackSpy(&myPlayer, &ManageAudioPlayer::skipNextTrack); + QSignalSpy seekSpy(&myPlayer, &ManageAudioPlayer::seek); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayListModel(&myPlayList); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setUrlRole(ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.urlRole(), static_cast(ManageAudioPlayerTest::ResourceRole)); myPlayer.setIsPlayingRole(ManageAudioPlayerTest::IsPlayingRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.isPlayingRole(), static_cast(ManageAudioPlayerTest::IsPlayingRole)); myPlayer.setCurrentTrack(myPlayList.index(0, 0)); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayList.item(0, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///1.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(1, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///2.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(2, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///3.mp3")), ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///1.mp3"))); myPlayer.setPlayerStatus(ManageAudioPlayer::Loading); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Loading)); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerError(ManageAudioPlayer::NoError); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerStatus(ManageAudioPlayer::Loaded); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 2); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Loaded)); myPlayer.setPlayerStatus(ManageAudioPlayer::Buffering); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Buffering)); myPlayer.playPause(); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(playerPlaySpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); } -void ManageAudioPlayerTest::testRestoreSettings() +void ManageAudioPlayerTest::testRestoreSettingsAutomaticPlay() { ManageAudioPlayer myPlayer; QStandardItemModel myPlayList; QSignalSpy currentTrackChangedSpy(&myPlayer, &ManageAudioPlayer::currentTrackChanged); QSignalSpy playListModelChangedSpy(&myPlayer, &ManageAudioPlayer::playListModelChanged); QSignalSpy playerSourceChangedSpy(&myPlayer, &ManageAudioPlayer::playerSourceChanged); QSignalSpy urlRoleChangedSpy(&myPlayer, &ManageAudioPlayer::urlRoleChanged); QSignalSpy isPlayingRoleChangedSpy(&myPlayer, &ManageAudioPlayer::isPlayingRoleChanged); QSignalSpy playerStatusChangedSpy(&myPlayer, &ManageAudioPlayer::playerStatusChanged); QSignalSpy playerPlaybackStateChangedSpy(&myPlayer, &ManageAudioPlayer::playerPlaybackStateChanged); QSignalSpy playerErrorChangedSpy(&myPlayer, &ManageAudioPlayer::playerErrorChanged); QSignalSpy persistentStateChangedSpy(&myPlayer, &ManageAudioPlayer::persistentStateChanged); QSignalSpy playerPlaySpy(&myPlayer, &ManageAudioPlayer::playerPlay); QSignalSpy playerPauseSpy(&myPlayer, &ManageAudioPlayer::playerPause); QSignalSpy playerStopSpy(&myPlayer, &ManageAudioPlayer::playerStop); QSignalSpy skipNextTrackSpy(&myPlayer, &ManageAudioPlayer::skipNextTrack); + QSignalSpy seekSpy(&myPlayer, &ManageAudioPlayer::seek); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.item(0, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///1.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(1, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///2.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(2, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///3.mp3")), ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayListModel(&myPlayList); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QVariantMap settings; settings[QStringLiteral("isPlaying")] = true; myPlayer.setPersistentState(settings); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setCurrentTrack(myPlayList.index(0, 0)); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayer.setUrlRole(ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.urlRole(), static_cast(ManageAudioPlayerTest::ResourceRole)); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///1.mp3"))); myPlayer.setIsPlayingRole(ManageAudioPlayerTest::IsPlayingRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.isPlayingRole(), static_cast(ManageAudioPlayerTest::IsPlayingRole)); myPlayer.setPlayerStatus(ManageAudioPlayer::Loading); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Loading)); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerError(ManageAudioPlayer::NoError); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerStatus(ManageAudioPlayer::Loaded); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 2); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Loaded)); myPlayer.setPlayerStatus(ManageAudioPlayer::Buffering); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Buffering)); QCOMPARE(playerPlaySpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::PlayingState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::PlayingState)); myPlayer.setPlayerStatus(ManageAudioPlayer::EndOfMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), true); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::EndOfMedia)); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::StoppedState)); myPlayer.setPlayerStatus(ManageAudioPlayer::InvalidMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::InvalidMedia)); QCOMPARE(skipNextTrackSpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 1); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 0); + QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); +} + +void ManageAudioPlayerTest::testRestoreSettingsNoAutomaticPlay() +{ + ManageAudioPlayer myPlayer; + QStandardItemModel myPlayList; + + QSignalSpy currentTrackChangedSpy(&myPlayer, &ManageAudioPlayer::currentTrackChanged); + QSignalSpy playListModelChangedSpy(&myPlayer, &ManageAudioPlayer::playListModelChanged); + QSignalSpy playerSourceChangedSpy(&myPlayer, &ManageAudioPlayer::playerSourceChanged); + QSignalSpy urlRoleChangedSpy(&myPlayer, &ManageAudioPlayer::urlRoleChanged); + QSignalSpy isPlayingRoleChangedSpy(&myPlayer, &ManageAudioPlayer::isPlayingRoleChanged); + QSignalSpy playerStatusChangedSpy(&myPlayer, &ManageAudioPlayer::playerStatusChanged); + QSignalSpy playerPlaybackStateChangedSpy(&myPlayer, &ManageAudioPlayer::playerPlaybackStateChanged); + QSignalSpy playerErrorChangedSpy(&myPlayer, &ManageAudioPlayer::playerErrorChanged); + QSignalSpy persistentStateChangedSpy(&myPlayer, &ManageAudioPlayer::persistentStateChanged); + QSignalSpy playerPlaySpy(&myPlayer, &ManageAudioPlayer::playerPlay); + QSignalSpy playerPauseSpy(&myPlayer, &ManageAudioPlayer::playerPause); + QSignalSpy playerStopSpy(&myPlayer, &ManageAudioPlayer::playerStop); + QSignalSpy skipNextTrackSpy(&myPlayer, &ManageAudioPlayer::skipNextTrack); + QSignalSpy seekSpy(&myPlayer, &ManageAudioPlayer::seek); + + myPlayList.appendRow(new QStandardItem); + myPlayList.appendRow(new QStandardItem); + myPlayList.appendRow(new QStandardItem); + + myPlayList.item(0, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///1.mp3")), ManageAudioPlayerTest::ResourceRole); + myPlayList.item(1, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///2.mp3")), ManageAudioPlayerTest::ResourceRole); + myPlayList.item(2, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///3.mp3")), ManageAudioPlayerTest::ResourceRole); + + QCOMPARE(currentTrackChangedSpy.count(), 0); + QCOMPARE(playListModelChangedSpy.count(), 0); + QCOMPARE(playerSourceChangedSpy.count(), 0); + QCOMPARE(urlRoleChangedSpy.count(), 0); + QCOMPARE(isPlayingRoleChangedSpy.count(), 0); + QCOMPARE(playerStatusChangedSpy.count(), 0); + QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); + QCOMPARE(playerErrorChangedSpy.count(), 0); + QCOMPARE(persistentStateChangedSpy.count(), 0); + QCOMPARE(playerPlaySpy.count(), 0); + QCOMPARE(playerPauseSpy.count(), 0); + QCOMPARE(playerStopSpy.count(), 0); + QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); + QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + + myPlayer.setPlayListModel(&myPlayList); + + QCOMPARE(currentTrackChangedSpy.count(), 0); + QCOMPARE(playListModelChangedSpy.count(), 1); + QCOMPARE(playerSourceChangedSpy.count(), 0); + QCOMPARE(urlRoleChangedSpy.count(), 0); + QCOMPARE(isPlayingRoleChangedSpy.count(), 0); + QCOMPARE(playerStatusChangedSpy.count(), 0); + QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); + QCOMPARE(playerErrorChangedSpy.count(), 0); + QCOMPARE(persistentStateChangedSpy.count(), 0); + QCOMPARE(playerPlaySpy.count(), 0); + QCOMPARE(playerPauseSpy.count(), 0); + QCOMPARE(playerStopSpy.count(), 0); + QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); + QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + + QVariantMap settings; + settings[QStringLiteral("isPlaying")] = false; + + myPlayer.setPersistentState(settings); + + QCOMPARE(currentTrackChangedSpy.count(), 0); + QCOMPARE(playListModelChangedSpy.count(), 1); + QCOMPARE(playerSourceChangedSpy.count(), 0); + QCOMPARE(urlRoleChangedSpy.count(), 0); + QCOMPARE(isPlayingRoleChangedSpy.count(), 0); + QCOMPARE(playerStatusChangedSpy.count(), 0); + QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); + QCOMPARE(playerErrorChangedSpy.count(), 0); + QCOMPARE(persistentStateChangedSpy.count(), 1); + QCOMPARE(playerPlaySpy.count(), 0); + QCOMPARE(playerPauseSpy.count(), 0); + QCOMPARE(playerStopSpy.count(), 0); + QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); + QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + + myPlayer.setCurrentTrack(myPlayList.index(0, 0)); + + QCOMPARE(currentTrackChangedSpy.count(), 1); + QCOMPARE(playListModelChangedSpy.count(), 1); + QCOMPARE(playerSourceChangedSpy.count(), 0); + QCOMPARE(urlRoleChangedSpy.count(), 0); + QCOMPARE(isPlayingRoleChangedSpy.count(), 0); + QCOMPARE(playerStatusChangedSpy.count(), 0); + QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); + QCOMPARE(playerErrorChangedSpy.count(), 0); + QCOMPARE(persistentStateChangedSpy.count(), 1); + QCOMPARE(playerPlaySpy.count(), 0); + QCOMPARE(playerPauseSpy.count(), 0); + QCOMPARE(playerStopSpy.count(), 0); + QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); + QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + + QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); + + myPlayer.setUrlRole(ManageAudioPlayerTest::ResourceRole); + + QCOMPARE(currentTrackChangedSpy.count(), 1); + QCOMPARE(playListModelChangedSpy.count(), 1); + QCOMPARE(playerSourceChangedSpy.count(), 1); + QCOMPARE(urlRoleChangedSpy.count(), 1); + QCOMPARE(isPlayingRoleChangedSpy.count(), 0); + QCOMPARE(playerStatusChangedSpy.count(), 0); + QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); + QCOMPARE(playerErrorChangedSpy.count(), 0); + QCOMPARE(persistentStateChangedSpy.count(), 1); + QCOMPARE(playerPlaySpy.count(), 0); + QCOMPARE(playerPauseSpy.count(), 0); + QCOMPARE(playerStopSpy.count(), 0); + QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); + QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + + QCOMPARE(myPlayer.urlRole(), static_cast(ManageAudioPlayerTest::ResourceRole)); + QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///1.mp3"))); + + myPlayer.setIsPlayingRole(ManageAudioPlayerTest::IsPlayingRole); + + QCOMPARE(currentTrackChangedSpy.count(), 1); + QCOMPARE(playListModelChangedSpy.count(), 1); + QCOMPARE(playerSourceChangedSpy.count(), 1); + QCOMPARE(urlRoleChangedSpy.count(), 1); + QCOMPARE(isPlayingRoleChangedSpy.count(), 1); + QCOMPARE(playerStatusChangedSpy.count(), 0); + QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); + QCOMPARE(playerErrorChangedSpy.count(), 0); + QCOMPARE(persistentStateChangedSpy.count(), 1); + QCOMPARE(playerPlaySpy.count(), 0); + QCOMPARE(playerPauseSpy.count(), 0); + QCOMPARE(playerStopSpy.count(), 0); + QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); + QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + + QCOMPARE(myPlayer.isPlayingRole(), static_cast(ManageAudioPlayerTest::IsPlayingRole)); + + myPlayer.setPlayerStatus(ManageAudioPlayer::Loading); + + QCOMPARE(currentTrackChangedSpy.count(), 1); + QCOMPARE(playListModelChangedSpy.count(), 1); + QCOMPARE(playerSourceChangedSpy.count(), 1); + QCOMPARE(urlRoleChangedSpy.count(), 1); + QCOMPARE(isPlayingRoleChangedSpy.count(), 1); + QCOMPARE(playerStatusChangedSpy.count(), 1); + QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); + QCOMPARE(playerErrorChangedSpy.count(), 0); + QCOMPARE(persistentStateChangedSpy.count(), 1); + QCOMPARE(playerPlaySpy.count(), 0); + QCOMPARE(playerPauseSpy.count(), 0); + QCOMPARE(playerStopSpy.count(), 0); + QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); + QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + + QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Loading)); + + myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); + + QCOMPARE(currentTrackChangedSpy.count(), 1); + QCOMPARE(playListModelChangedSpy.count(), 1); + QCOMPARE(playerSourceChangedSpy.count(), 1); + QCOMPARE(urlRoleChangedSpy.count(), 1); + QCOMPARE(isPlayingRoleChangedSpy.count(), 1); + QCOMPARE(playerStatusChangedSpy.count(), 1); + QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); + QCOMPARE(playerErrorChangedSpy.count(), 0); + QCOMPARE(persistentStateChangedSpy.count(), 1); + QCOMPARE(playerPlaySpy.count(), 0); + QCOMPARE(playerPauseSpy.count(), 0); + QCOMPARE(playerStopSpy.count(), 0); + QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); + QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + + myPlayer.setPlayerError(ManageAudioPlayer::NoError); + + QCOMPARE(currentTrackChangedSpy.count(), 1); + QCOMPARE(playListModelChangedSpy.count(), 1); + QCOMPARE(playerSourceChangedSpy.count(), 1); + QCOMPARE(urlRoleChangedSpy.count(), 1); + QCOMPARE(isPlayingRoleChangedSpy.count(), 1); + QCOMPARE(playerStatusChangedSpy.count(), 1); + QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); + QCOMPARE(playerErrorChangedSpy.count(), 0); + QCOMPARE(persistentStateChangedSpy.count(), 1); + QCOMPARE(playerPlaySpy.count(), 0); + QCOMPARE(playerPauseSpy.count(), 0); + QCOMPARE(playerStopSpy.count(), 0); + QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); + QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + + myPlayer.setPlayerStatus(ManageAudioPlayer::Loaded); + + QCOMPARE(currentTrackChangedSpy.count(), 1); + QCOMPARE(playListModelChangedSpy.count(), 1); + QCOMPARE(playerSourceChangedSpy.count(), 1); + QCOMPARE(urlRoleChangedSpy.count(), 1); + QCOMPARE(isPlayingRoleChangedSpy.count(), 1); + QCOMPARE(playerStatusChangedSpy.count(), 2); + QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); + QCOMPARE(playerErrorChangedSpy.count(), 0); + QCOMPARE(persistentStateChangedSpy.count(), 1); + QCOMPARE(playerPlaySpy.count(), 0); + QCOMPARE(playerPauseSpy.count(), 0); + QCOMPARE(playerStopSpy.count(), 0); + QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); + QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + + QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Loaded)); + + myPlayer.setPlayerStatus(ManageAudioPlayer::Buffering); + + QCOMPARE(currentTrackChangedSpy.count(), 1); + QCOMPARE(playListModelChangedSpy.count(), 1); + QCOMPARE(playerSourceChangedSpy.count(), 1); + QCOMPARE(urlRoleChangedSpy.count(), 1); + QCOMPARE(isPlayingRoleChangedSpy.count(), 1); + QCOMPARE(playerStatusChangedSpy.count(), 3); + QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); + QCOMPARE(playerErrorChangedSpy.count(), 0); + QCOMPARE(persistentStateChangedSpy.count(), 1); + QCOMPARE(playerPlaySpy.count(), 0); + QCOMPARE(playerPauseSpy.count(), 0); + QCOMPARE(playerStopSpy.count(), 0); + QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); + QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + + QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Buffering)); + + QCOMPARE(playerPlaySpy.wait(1000), false); + + QCOMPARE(currentTrackChangedSpy.count(), 1); + QCOMPARE(playListModelChangedSpy.count(), 1); + QCOMPARE(playerSourceChangedSpy.count(), 1); + QCOMPARE(urlRoleChangedSpy.count(), 1); + QCOMPARE(isPlayingRoleChangedSpy.count(), 1); + QCOMPARE(playerStatusChangedSpy.count(), 3); + QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); + QCOMPARE(playerErrorChangedSpy.count(), 0); + QCOMPARE(persistentStateChangedSpy.count(), 1); + QCOMPARE(playerPlaySpy.count(), 0); + QCOMPARE(playerPauseSpy.count(), 0); + QCOMPARE(playerStopSpy.count(), 0); + QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); + QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); +} + +void ManageAudioPlayerTest::testRestoreSettingsAutomaticPlayAndPosition() +{ + ManageAudioPlayer myPlayer; + QStandardItemModel myPlayList; + + QSignalSpy currentTrackChangedSpy(&myPlayer, &ManageAudioPlayer::currentTrackChanged); + QSignalSpy playListModelChangedSpy(&myPlayer, &ManageAudioPlayer::playListModelChanged); + QSignalSpy playerSourceChangedSpy(&myPlayer, &ManageAudioPlayer::playerSourceChanged); + QSignalSpy urlRoleChangedSpy(&myPlayer, &ManageAudioPlayer::urlRoleChanged); + QSignalSpy isPlayingRoleChangedSpy(&myPlayer, &ManageAudioPlayer::isPlayingRoleChanged); + QSignalSpy playerStatusChangedSpy(&myPlayer, &ManageAudioPlayer::playerStatusChanged); + QSignalSpy playerPlaybackStateChangedSpy(&myPlayer, &ManageAudioPlayer::playerPlaybackStateChanged); + QSignalSpy playerErrorChangedSpy(&myPlayer, &ManageAudioPlayer::playerErrorChanged); + QSignalSpy persistentStateChangedSpy(&myPlayer, &ManageAudioPlayer::persistentStateChanged); + QSignalSpy playerPlaySpy(&myPlayer, &ManageAudioPlayer::playerPlay); + QSignalSpy playerPauseSpy(&myPlayer, &ManageAudioPlayer::playerPause); + QSignalSpy playerStopSpy(&myPlayer, &ManageAudioPlayer::playerStop); + QSignalSpy skipNextTrackSpy(&myPlayer, &ManageAudioPlayer::skipNextTrack); + QSignalSpy seekSpy(&myPlayer, &ManageAudioPlayer::seek); + + myPlayList.appendRow(new QStandardItem); + myPlayList.appendRow(new QStandardItem); + myPlayList.appendRow(new QStandardItem); + + myPlayList.item(0, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///1.mp3")), ManageAudioPlayerTest::ResourceRole); + myPlayList.item(1, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///2.mp3")), ManageAudioPlayerTest::ResourceRole); + myPlayList.item(2, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///3.mp3")), ManageAudioPlayerTest::ResourceRole); + + QCOMPARE(currentTrackChangedSpy.count(), 0); + QCOMPARE(playListModelChangedSpy.count(), 0); + QCOMPARE(playerSourceChangedSpy.count(), 0); + QCOMPARE(urlRoleChangedSpy.count(), 0); + QCOMPARE(isPlayingRoleChangedSpy.count(), 0); + QCOMPARE(playerStatusChangedSpy.count(), 0); + QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); + QCOMPARE(playerErrorChangedSpy.count(), 0); + QCOMPARE(persistentStateChangedSpy.count(), 0); + QCOMPARE(playerPlaySpy.count(), 0); + QCOMPARE(playerPauseSpy.count(), 0); + QCOMPARE(playerStopSpy.count(), 0); + QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); + QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + + myPlayer.setPlayListModel(&myPlayList); + + QCOMPARE(currentTrackChangedSpy.count(), 0); + QCOMPARE(playListModelChangedSpy.count(), 1); + QCOMPARE(playerSourceChangedSpy.count(), 0); + QCOMPARE(urlRoleChangedSpy.count(), 0); + QCOMPARE(isPlayingRoleChangedSpy.count(), 0); + QCOMPARE(playerStatusChangedSpy.count(), 0); + QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); + QCOMPARE(playerErrorChangedSpy.count(), 0); + QCOMPARE(persistentStateChangedSpy.count(), 0); + QCOMPARE(playerPlaySpy.count(), 0); + QCOMPARE(playerPauseSpy.count(), 0); + QCOMPARE(playerStopSpy.count(), 0); + QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); + QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + + QVariantMap settings; + settings[QStringLiteral("isPlaying")] = true; + settings[QStringLiteral("playerPosition")] = 10000; + + myPlayer.setPersistentState(settings); + + QCOMPARE(currentTrackChangedSpy.count(), 0); + QCOMPARE(playListModelChangedSpy.count(), 1); + QCOMPARE(playerSourceChangedSpy.count(), 0); + QCOMPARE(urlRoleChangedSpy.count(), 0); + QCOMPARE(isPlayingRoleChangedSpy.count(), 0); + QCOMPARE(playerStatusChangedSpy.count(), 0); + QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); + QCOMPARE(playerErrorChangedSpy.count(), 0); + QCOMPARE(persistentStateChangedSpy.count(), 1); + QCOMPARE(playerPlaySpy.count(), 0); + QCOMPARE(playerPauseSpy.count(), 0); + QCOMPARE(playerStopSpy.count(), 0); + QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); + QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + + myPlayer.setCurrentTrack(myPlayList.index(0, 0)); + + QCOMPARE(currentTrackChangedSpy.count(), 1); + QCOMPARE(playListModelChangedSpy.count(), 1); + QCOMPARE(playerSourceChangedSpy.count(), 0); + QCOMPARE(urlRoleChangedSpy.count(), 0); + QCOMPARE(isPlayingRoleChangedSpy.count(), 0); + QCOMPARE(playerStatusChangedSpy.count(), 0); + QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); + QCOMPARE(playerErrorChangedSpy.count(), 0); + QCOMPARE(persistentStateChangedSpy.count(), 1); + QCOMPARE(playerPlaySpy.count(), 0); + QCOMPARE(playerPauseSpy.count(), 0); + QCOMPARE(playerStopSpy.count(), 0); + QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); + QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + + QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); + + myPlayer.setUrlRole(ManageAudioPlayerTest::ResourceRole); + + QCOMPARE(currentTrackChangedSpy.count(), 1); + QCOMPARE(playListModelChangedSpy.count(), 1); + QCOMPARE(playerSourceChangedSpy.count(), 1); + QCOMPARE(urlRoleChangedSpy.count(), 1); + QCOMPARE(isPlayingRoleChangedSpy.count(), 0); + QCOMPARE(playerStatusChangedSpy.count(), 0); + QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); + QCOMPARE(playerErrorChangedSpy.count(), 0); + QCOMPARE(persistentStateChangedSpy.count(), 1); + QCOMPARE(playerPlaySpy.count(), 0); + QCOMPARE(playerPauseSpy.count(), 0); + QCOMPARE(playerStopSpy.count(), 0); + QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); + QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + + QCOMPARE(myPlayer.urlRole(), static_cast(ManageAudioPlayerTest::ResourceRole)); + QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///1.mp3"))); + + myPlayer.setIsPlayingRole(ManageAudioPlayerTest::IsPlayingRole); + + QCOMPARE(currentTrackChangedSpy.count(), 1); + QCOMPARE(playListModelChangedSpy.count(), 1); + QCOMPARE(playerSourceChangedSpy.count(), 1); + QCOMPARE(urlRoleChangedSpy.count(), 1); + QCOMPARE(isPlayingRoleChangedSpy.count(), 1); + QCOMPARE(playerStatusChangedSpy.count(), 0); + QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); + QCOMPARE(playerErrorChangedSpy.count(), 0); + QCOMPARE(persistentStateChangedSpy.count(), 1); + QCOMPARE(playerPlaySpy.count(), 0); + QCOMPARE(playerPauseSpy.count(), 0); + QCOMPARE(playerStopSpy.count(), 0); + QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); + QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + + QCOMPARE(myPlayer.isPlayingRole(), static_cast(ManageAudioPlayerTest::IsPlayingRole)); + + myPlayer.setPlayerStatus(ManageAudioPlayer::Loading); + + QCOMPARE(currentTrackChangedSpy.count(), 1); + QCOMPARE(playListModelChangedSpy.count(), 1); + QCOMPARE(playerSourceChangedSpy.count(), 1); + QCOMPARE(urlRoleChangedSpy.count(), 1); + QCOMPARE(isPlayingRoleChangedSpy.count(), 1); + QCOMPARE(playerStatusChangedSpy.count(), 1); + QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); + QCOMPARE(playerErrorChangedSpy.count(), 0); + QCOMPARE(persistentStateChangedSpy.count(), 1); + QCOMPARE(playerPlaySpy.count(), 0); + QCOMPARE(playerPauseSpy.count(), 0); + QCOMPARE(playerStopSpy.count(), 0); + QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); + QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + + QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Loading)); + + myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); + + QCOMPARE(currentTrackChangedSpy.count(), 1); + QCOMPARE(playListModelChangedSpy.count(), 1); + QCOMPARE(playerSourceChangedSpy.count(), 1); + QCOMPARE(urlRoleChangedSpy.count(), 1); + QCOMPARE(isPlayingRoleChangedSpy.count(), 1); + QCOMPARE(playerStatusChangedSpy.count(), 1); + QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); + QCOMPARE(playerErrorChangedSpy.count(), 0); + QCOMPARE(persistentStateChangedSpy.count(), 1); + QCOMPARE(playerPlaySpy.count(), 0); + QCOMPARE(playerPauseSpy.count(), 0); + QCOMPARE(playerStopSpy.count(), 0); + QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); + QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + + myPlayer.setPlayerError(ManageAudioPlayer::NoError); + + QCOMPARE(currentTrackChangedSpy.count(), 1); + QCOMPARE(playListModelChangedSpy.count(), 1); + QCOMPARE(playerSourceChangedSpy.count(), 1); + QCOMPARE(urlRoleChangedSpy.count(), 1); + QCOMPARE(isPlayingRoleChangedSpy.count(), 1); + QCOMPARE(playerStatusChangedSpy.count(), 1); + QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); + QCOMPARE(playerErrorChangedSpy.count(), 0); + QCOMPARE(persistentStateChangedSpy.count(), 1); + QCOMPARE(playerPlaySpy.count(), 0); + QCOMPARE(playerPauseSpy.count(), 0); + QCOMPARE(playerStopSpy.count(), 0); + QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); + QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + + myPlayer.setPlayerStatus(ManageAudioPlayer::Loaded); + + QCOMPARE(currentTrackChangedSpy.count(), 1); + QCOMPARE(playListModelChangedSpy.count(), 1); + QCOMPARE(playerSourceChangedSpy.count(), 1); + QCOMPARE(urlRoleChangedSpy.count(), 1); + QCOMPARE(isPlayingRoleChangedSpy.count(), 1); + QCOMPARE(playerStatusChangedSpy.count(), 2); + QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); + QCOMPARE(playerErrorChangedSpy.count(), 0); + QCOMPARE(persistentStateChangedSpy.count(), 1); + QCOMPARE(playerPlaySpy.count(), 0); + QCOMPARE(playerPauseSpy.count(), 0); + QCOMPARE(playerStopSpy.count(), 0); + QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); + QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + + QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Loaded)); + + myPlayer.setPlayerStatus(ManageAudioPlayer::Buffering); + + QCOMPARE(currentTrackChangedSpy.count(), 1); + QCOMPARE(playListModelChangedSpy.count(), 1); + QCOMPARE(playerSourceChangedSpy.count(), 1); + QCOMPARE(urlRoleChangedSpy.count(), 1); + QCOMPARE(isPlayingRoleChangedSpy.count(), 1); + QCOMPARE(playerStatusChangedSpy.count(), 3); + QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); + QCOMPARE(playerErrorChangedSpy.count(), 0); + QCOMPARE(persistentStateChangedSpy.count(), 1); + QCOMPARE(playerPlaySpy.count(), 0); + QCOMPARE(playerPauseSpy.count(), 0); + QCOMPARE(playerStopSpy.count(), 0); + QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); + QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + + QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Buffering)); + + QCOMPARE(playerPlaySpy.wait(), true); + + QCOMPARE(currentTrackChangedSpy.count(), 1); + QCOMPARE(playListModelChangedSpy.count(), 1); + QCOMPARE(playerSourceChangedSpy.count(), 1); + QCOMPARE(urlRoleChangedSpy.count(), 1); + QCOMPARE(isPlayingRoleChangedSpy.count(), 1); + QCOMPARE(playerStatusChangedSpy.count(), 3); + QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); + QCOMPARE(playerErrorChangedSpy.count(), 0); + QCOMPARE(persistentStateChangedSpy.count(), 1); + QCOMPARE(playerPlaySpy.count(), 1); + QCOMPARE(playerPauseSpy.count(), 0); + QCOMPARE(playerStopSpy.count(), 0); + QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); + QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + + myPlayer.setPlayerPlaybackState(ManageAudioPlayer::PlayingState); + + QCOMPARE(currentTrackChangedSpy.count(), 1); + QCOMPARE(playListModelChangedSpy.count(), 1); + QCOMPARE(playerSourceChangedSpy.count(), 1); + QCOMPARE(urlRoleChangedSpy.count(), 1); + QCOMPARE(isPlayingRoleChangedSpy.count(), 1); + QCOMPARE(playerStatusChangedSpy.count(), 3); + QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); + QCOMPARE(playerErrorChangedSpy.count(), 0); + QCOMPARE(persistentStateChangedSpy.count(), 1); + QCOMPARE(playerPlaySpy.count(), 1); + QCOMPARE(playerPauseSpy.count(), 0); + QCOMPARE(playerStopSpy.count(), 0); + QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 1); + QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), true); + QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + + QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::PlayingState)); + QCOMPARE(seekSpy.at(0).at(0).toInt(), 10000); + + myPlayer.setPlayerStatus(ManageAudioPlayer::EndOfMedia); + + QCOMPARE(currentTrackChangedSpy.count(), 1); + QCOMPARE(playListModelChangedSpy.count(), 1); + QCOMPARE(playerSourceChangedSpy.count(), 1); + QCOMPARE(urlRoleChangedSpy.count(), 1); + QCOMPARE(isPlayingRoleChangedSpy.count(), 1); + QCOMPARE(playerStatusChangedSpy.count(), 4); + QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); + QCOMPARE(playerErrorChangedSpy.count(), 0); + QCOMPARE(persistentStateChangedSpy.count(), 1); + QCOMPARE(playerPlaySpy.count(), 1); + QCOMPARE(playerPauseSpy.count(), 0); + QCOMPARE(playerStopSpy.count(), 0); + QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 1); + QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), true); + QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + + QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::EndOfMedia)); + + myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); + + QCOMPARE(currentTrackChangedSpy.count(), 1); + QCOMPARE(playListModelChangedSpy.count(), 1); + QCOMPARE(playerSourceChangedSpy.count(), 1); + QCOMPARE(urlRoleChangedSpy.count(), 1); + QCOMPARE(isPlayingRoleChangedSpy.count(), 1); + QCOMPARE(playerStatusChangedSpy.count(), 4); + QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); + QCOMPARE(playerErrorChangedSpy.count(), 0); + QCOMPARE(persistentStateChangedSpy.count(), 1); + QCOMPARE(playerPlaySpy.count(), 1); + QCOMPARE(playerPauseSpy.count(), 0); + QCOMPARE(playerStopSpy.count(), 0); + QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 1); + QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + + QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::StoppedState)); + + myPlayer.setPlayerStatus(ManageAudioPlayer::InvalidMedia); + + QCOMPARE(currentTrackChangedSpy.count(), 1); + QCOMPARE(playListModelChangedSpy.count(), 1); + QCOMPARE(playerSourceChangedSpy.count(), 1); + QCOMPARE(urlRoleChangedSpy.count(), 1); + QCOMPARE(isPlayingRoleChangedSpy.count(), 1); + QCOMPARE(playerStatusChangedSpy.count(), 5); + QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); + QCOMPARE(playerErrorChangedSpy.count(), 0); + QCOMPARE(persistentStateChangedSpy.count(), 1); + QCOMPARE(playerPlaySpy.count(), 1); + QCOMPARE(playerPauseSpy.count(), 0); + QCOMPARE(playerStopSpy.count(), 0); + QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 1); + QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); + + QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::InvalidMedia)); + + QCOMPARE(skipNextTrackSpy.wait(), true); + + QCOMPARE(currentTrackChangedSpy.count(), 1); + QCOMPARE(playListModelChangedSpy.count(), 1); + QCOMPARE(playerSourceChangedSpy.count(), 1); + QCOMPARE(urlRoleChangedSpy.count(), 1); + QCOMPARE(isPlayingRoleChangedSpy.count(), 1); + QCOMPARE(playerStatusChangedSpy.count(), 5); + QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); + QCOMPARE(playerErrorChangedSpy.count(), 0); + QCOMPARE(persistentStateChangedSpy.count(), 1); + QCOMPARE(playerPlaySpy.count(), 1); + QCOMPARE(playerPauseSpy.count(), 0); + QCOMPARE(playerStopSpy.count(), 0); + QCOMPARE(skipNextTrackSpy.count(), 1); + QCOMPARE(seekSpy.count(), 1); QCOMPARE(myPlayList.data(myPlayList.index(0, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(1, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); QCOMPARE(myPlayList.data(myPlayList.index(2, 0), ManageAudioPlayerTest::IsPlayingRole).toBool(), false); } void ManageAudioPlayerTest::playTrackPauseAndSkipNextTrack() { ManageAudioPlayer myPlayer; QStandardItemModel myPlayList; QSignalSpy currentTrackChangedSpy(&myPlayer, &ManageAudioPlayer::currentTrackChanged); QSignalSpy playListModelChangedSpy(&myPlayer, &ManageAudioPlayer::playListModelChanged); QSignalSpy playerSourceChangedSpy(&myPlayer, &ManageAudioPlayer::playerSourceChanged); QSignalSpy urlRoleChangedSpy(&myPlayer, &ManageAudioPlayer::urlRoleChanged); QSignalSpy isPlayingRoleChangedSpy(&myPlayer, &ManageAudioPlayer::isPlayingRoleChanged); QSignalSpy playerStatusChangedSpy(&myPlayer, &ManageAudioPlayer::playerStatusChanged); QSignalSpy playerPlaybackStateChangedSpy(&myPlayer, &ManageAudioPlayer::playerPlaybackStateChanged); QSignalSpy playerErrorChangedSpy(&myPlayer, &ManageAudioPlayer::playerErrorChanged); QSignalSpy persistentStateChangedSpy(&myPlayer, &ManageAudioPlayer::persistentStateChanged); QSignalSpy playerPlaySpy(&myPlayer, &ManageAudioPlayer::playerPlay); QSignalSpy playerPauseSpy(&myPlayer, &ManageAudioPlayer::playerPause); QSignalSpy playerStopSpy(&myPlayer, &ManageAudioPlayer::playerStop); QSignalSpy skipNextTrackSpy(&myPlayer, &ManageAudioPlayer::skipNextTrack); + QSignalSpy seekSpy(&myPlayer, &ManageAudioPlayer::seek); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.appendRow(new QStandardItem); myPlayList.item(0, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///1.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(1, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///2.mp3")), ManageAudioPlayerTest::ResourceRole); myPlayList.item(2, 0)->setData(QUrl::fromUserInput(QStringLiteral("file:///3.mp3")), ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 0); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayListModel(&myPlayList); QCOMPARE(currentTrackChangedSpy.count(), 0); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setCurrentTrack(myPlayList.index(0, 0)); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 0); QCOMPARE(urlRoleChangedSpy.count(), 0); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(0, 0))); myPlayer.setUrlRole(ManageAudioPlayerTest::ResourceRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 0); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.urlRole(), static_cast(ManageAudioPlayerTest::ResourceRole)); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///1.mp3"))); myPlayer.setIsPlayingRole(ManageAudioPlayerTest::IsPlayingRole); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 0); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.isPlayingRole(), static_cast(ManageAudioPlayerTest::IsPlayingRole)); myPlayer.setPlayerStatus(ManageAudioPlayer::Loading); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Loading)); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerError(ManageAudioPlayer::NoError); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 1); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerStatus(ManageAudioPlayer::Loaded); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 2); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Loaded)); myPlayer.setPlayerStatus(ManageAudioPlayer::Buffering); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Buffering)); myPlayer.playPause(); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 0); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(playerPlaySpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 0); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::PlayingState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 3); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::PlayingState)); myPlayer.setPlayerStatus(ManageAudioPlayer::EndOfMedia); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::EndOfMedia)); myPlayer.playPause(); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 0); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(playerPauseSpy.wait(), true); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 1); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 1); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::PausedState); QCOMPARE(currentTrackChangedSpy.count(), 1); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 1); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::PausedState)); myPlayer.setCurrentTrack(myPlayList.index(1, 0)); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 1); QCOMPARE(playerStopSpy.count(), 0); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.currentTrack(), QPersistentModelIndex(myPlayList.index(1, 0))); QCOMPARE(playerStopSpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 1); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 2); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 1); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::StoppedState); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 4); QCOMPARE(playerPlaybackStateChangedSpy.count(), 3); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 1); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerSource(), QUrl::fromUserInput(QStringLiteral("file:///2.mp3"))); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::StoppedState)); QCOMPARE(skipNextTrackSpy.wait(100), false); myPlayer.setPlayerStatus(ManageAudioPlayer::Loaded); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 5); QCOMPARE(playerPlaybackStateChangedSpy.count(), 3); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 1); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Loaded)); myPlayer.setPlayerStatus(ManageAudioPlayer::Buffering); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 6); QCOMPARE(playerPlaybackStateChangedSpy.count(), 3); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 1); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::Buffering)); myPlayer.playPause(); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 6); QCOMPARE(playerPlaybackStateChangedSpy.count(), 3); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 1); QCOMPARE(playerPauseSpy.count(), 1); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(playerPlaySpy.wait(100), true); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 6); QCOMPARE(playerPlaybackStateChangedSpy.count(), 3); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 1); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); myPlayer.setPlayerPlaybackState(ManageAudioPlayer::PlayingState); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 6); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 1); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerPlaybackState(), static_cast(ManageAudioPlayer::PlayingState)); myPlayer.setPlayerStatus(ManageAudioPlayer::EndOfMedia); QCOMPARE(currentTrackChangedSpy.count(), 2); QCOMPARE(playListModelChangedSpy.count(), 1); QCOMPARE(playerSourceChangedSpy.count(), 2); QCOMPARE(urlRoleChangedSpy.count(), 1); QCOMPARE(isPlayingRoleChangedSpy.count(), 1); QCOMPARE(playerStatusChangedSpy.count(), 7); QCOMPARE(playerPlaybackStateChangedSpy.count(), 4); QCOMPARE(playerErrorChangedSpy.count(), 0); QCOMPARE(persistentStateChangedSpy.count(), 0); QCOMPARE(playerPlaySpy.count(), 2); QCOMPARE(playerPauseSpy.count(), 1); QCOMPARE(playerStopSpy.count(), 1); QCOMPARE(skipNextTrackSpy.count(), 0); + QCOMPARE(seekSpy.count(), 0); QCOMPARE(myPlayer.playerStatus(), static_cast(ManageAudioPlayer::EndOfMedia)); } QTEST_MAIN(ManageAudioPlayerTest) #include "moc_manageaudioplayertest.cpp" diff --git a/autotests/manageaudioplayertest.h b/autotests/manageaudioplayertest.h index 7af271f7..9eb22262 100644 --- a/autotests/manageaudioplayertest.h +++ b/autotests/manageaudioplayertest.h @@ -1,84 +1,88 @@ /* * Copyright 2016 Matthieu Gallien * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef MANAGEAUDIOPLAYERTEST_H #define MANAGEAUDIOPLAYERTEST_H #include class ManageAudioPlayerTest : public QObject { Q_OBJECT public: enum ColumnsRoles { IsValidRole = Qt::UserRole + 1, TitleRole = IsValidRole + 1, DurationRole = TitleRole + 1, MilliSecondsDurationRole = DurationRole + 1, CreatorRole = MilliSecondsDurationRole + 1, ArtistRole = CreatorRole + 1, AlbumRole = ArtistRole + 1, TrackNumberRole = AlbumRole + 1, RatingRole = TrackNumberRole + 1, ImageRole = RatingRole + 1, ResourceRole = ImageRole + 1, CountRole = ResourceRole + 1, IsPlayingRole = CountRole + 1, }; Q_ENUM(ColumnsRoles) explicit ManageAudioPlayerTest(QObject *parent = 0); Q_SIGNALS: private Q_SLOTS: void initTestCase(); void simpleInitialCase(); void noPlayCase(); void skipNextTrack(); void skipPreviousTrack(); void playTrackAndskipNextTrack(); void playTrackAndskipPreviousTrack(); void skipNextTrackAndPlayTrack(); void skipPreviousTrackAndPlayTrack(); void playLastCase(); void playRestoredTrack(); - void testRestoreSettings(); + void testRestoreSettingsAutomaticPlay(); + + void testRestoreSettingsNoAutomaticPlay(); + + void testRestoreSettingsAutomaticPlayAndPosition(); void playTrackPauseAndSkipNextTrack(); }; #endif // MANAGEAUDIOPLAYERTEST_H diff --git a/src/MediaServer.qml b/src/MediaServer.qml index 0cc2c4e1..2e0a2a23 100644 --- a/src/MediaServer.qml +++ b/src/MediaServer.qml @@ -1,677 +1,679 @@ /* * Copyright 2016 Matthieu Gallien * Copyright 2015 Marco Martin * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ import QtQuick 2.4 import QtQuick.Controls 1.3 import QtQuick.Controls.Styles 1.3 import QtQuick.Layouts 1.1 import QtQuick.Window 2.2 import QtQml.Models 2.1 import org.mgallien.QmlExtension 1.0 import QtMultimedia 5.6 import Qt.labs.settings 1.0 ApplicationWindow { id: mainWindow visible: true minimumWidth: 1000 minimumHeight: 600 x: persistentSettings.x y: persistentSettings.y width: persistentSettings.width height: persistentSettings.height title: 'Elisa' SystemPalette { id: myPalette colorGroup: SystemPalette.Active } Settings { id: persistentSettings property int x property int y property int width property int height property var playListState property var playListControlerState property var audioPlayerState property double playControlItemVolume property bool playControlItemMuted } property string globalBrowseFlag: 'BrowseDirectChildren' property string globalFilter: '*' property string globalSortCriteria: '' /** * Shows a little passive notification at the bottom of the app window * lasting for few seconds, with an optional action button. * * @param message The text message to be shown to the user. * @param timeout How long to show the message: * possible values: "short", "long" or the number of milliseconds * @param actionText Text in the action button, if any. * @param callBack A JavaScript function that will be executed when the * user clicks the button. */ function showPassiveNotification(message, timeout, actionText, callBack) { if (!internal.__passiveNotification) { var component = Qt.createComponent(Qt.resolvedUrl('PassiveNotification.qml')); internal.__passiveNotification = component.createObject(mainWindow); } internal.__passiveNotification.showNotification(message, timeout, actionText, callBack); } /** * Hide the passive notification, if any is shown */ function hidePassiveNotification() { if(internal.__passiveNotification) { internal.__passiveNotification.hideNotification(); } } QtObject { id: internal property Item __passiveNotification } Action { id: quitAction text: i18nc("Action to quit the application", "&Quit") shortcut: StandardKey.Quit onTriggered: Qt.quit() } Connections { target: Qt.application onAboutToQuit: { persistentSettings.x = mainWindow.x; persistentSettings.y = mainWindow.y; persistentSettings.width = mainWindow.width; persistentSettings.height = mainWindow.height; persistentSettings.playListState = playListModelItem.persistentState; persistentSettings.playListControlerState = playListControlerItem.persistentState; persistentSettings.audioPlayerState = manageAudioPlayer.persistentState persistentSettings.playControlItemVolume = playControlItem.volume persistentSettings.playControlItemMuted = playControlItem.muted } } Mpris2 { id: mpris2Interface playerName: 'elisa' playListModel: playListModelItem playListControler: playListControlerItem audioPlayerManager: manageAudioPlayer headerBarManager: myHeaderBarManager manageMediaPlayerControl: myPlayControlManager onRaisePlayer: { mainWindow.raise() mainWindow.requestActivate() } } MusicListenersManager { id: allListeners } Audio { id: audioPlayer audioRole: Audio.MusicRole muted: playControlItem.muted volume: playControlItem.volume source: manageAudioPlayer.playerSource onPlaying: { myPlayControlManager.playerPlaying() } onPaused: { myPlayControlManager.playerPaused() } onStopped: { myPlayControlManager.playerStopped() } } MediaPlayList { id: playListModelItem persistentState: persistentSettings.playListState musicListenersManager: allListeners onTrackHasBeenAdded: mainWindow.showPassiveNotification(i18n("Track %1 has been added", title), 1500, "", {}) } PlayListControler { id: playListControlerItem playListModel: playListModelItem isValidRole: MediaPlayList.IsValidRole onPlayListFinished: manageAudioPlayer.playListFinished() persistentState: persistentSettings.playListControlerState Component.onCompleted: { var d = new Date(); var n = d.getMilliseconds(); seedRandomGenerator(n); } } ManageHeaderBar { id: myHeaderBarManager playListModel: playListModelItem currentTrack: playListControlerItem.currentTrack artistRole: MediaPlayList.ArtistRole titleRole: MediaPlayList.TitleRole albumRole: MediaPlayList.AlbumRole imageRole: MediaPlayList.ImageRole isValidRole: MediaPlayList.IsValidRole } ManageAudioPlayer { id: manageAudioPlayer currentTrack: playListControlerItem.currentTrack playListModel: playListModelItem urlRole: MediaPlayList.ResourceRole isPlayingRole: MediaPlayList.IsPlayingRole playerStatus: audioPlayer.status playerPlaybackState: audioPlayer.playbackState playerError: audioPlayer.error audioDuration: audioPlayer.duration playerIsSeekable: audioPlayer.seekable + playerPosition: audioPlayer.position persistentState: persistentSettings.audioPlayerState onPlayerPlay: audioPlayer.play() onPlayerPause: audioPlayer.pause() onPlayerStop: audioPlayer.stop() onSkipNextTrack: playListControlerItem.skipNextTrack() + onSeek: audioPlayer.seek(position) } ManageMediaPlayerControl { id: myPlayControlManager playListModel: playListModelItem currentTrack: playListControlerItem.currentTrack } AllAlbumsModel { id: allAlbumsModel } Connections { target: allListeners onAlbumAdded: allAlbumsModel.albumAdded(newAlbum) } AllArtistsModel { id: allArtistsModel } Connections { target: allListeners onArtistAdded: allArtistsModel.artistAdded(newArtist) } Rectangle { color: myPalette.base anchors.fill: parent ColumnLayout { anchors.fill: parent spacing: 0 HeaderBar { id: headerBar Layout.preferredHeight: Screen.pixelDensity * 28. Layout.minimumHeight: Layout.preferredHeight Layout.maximumHeight: Layout.preferredHeight Layout.fillWidth: true tracksCount: myHeaderBarManager.remainingTracks album: myHeaderBarManager.album title: myHeaderBarManager.title artist: myHeaderBarManager.artist image: myHeaderBarManager.image ratingVisible: false } MediaPlayerControl { id: playControlItem duration: audioPlayer.duration seekable: audioPlayer.seekable volume: persistentSettings.playControlItemVolume muted: persistentSettings.playControlItemMuted position: audioPlayer.position skipBackwardEnabled: myPlayControlManager.skipBackwardControlEnabled skipForwardEnabled: myPlayControlManager.skipForwardControlEnabled playEnabled: myPlayControlManager.playControlEnabled isPlaying: myPlayControlManager.musicPlaying Layout.preferredHeight: Screen.pixelDensity * 12. Layout.minimumHeight: Layout.preferredHeight Layout.maximumHeight: Layout.preferredHeight Layout.fillWidth: true onSeek: audioPlayer.seek(position) onPlay: manageAudioPlayer.playPause() onPause: manageAudioPlayer.playPause() onPlayPrevious: playListControlerItem.skipPreviousTrack() onPlayNext: playListControlerItem.skipNextTrack() } RowLayout { Layout.fillHeight: true Layout.fillWidth: true spacing: 0 Rectangle { color: myPalette.window Layout.fillHeight: true Layout.preferredWidth: Screen.pixelDensity * 50. Layout.minimumWidth: Screen.pixelDensity * 50. Layout.maximumWidth: Screen.pixelDensity * 50. TableView { id: viewModeView flickableItem.boundsBehavior: Flickable.StopAtBounds anchors.fill: parent headerVisible: false frameVisible: false focus: true backgroundVisible: false z: 2 rowDelegate: Rectangle { color: myPalette.window height: Screen.pixelDensity * 8. width: viewModeView.width } model: ListModel { id: pageModel ListElement { name: 'Now Playing' } ListElement { name: 'Albums' } ListElement { name: 'Artists' } } itemDelegate: Rectangle { height: Screen.pixelDensity * 8. width: viewModeView.width color: (styleData.selected ? myPalette.highlight : myPalette.window) Text { id: nameLabel anchors.verticalCenter: parent.verticalCenter anchors.left: parent.left anchors.right: parent.right anchors.leftMargin: Screen.pixelDensity * 2. anchors.rightMargin: Screen.pixelDensity * 2. verticalAlignment: "AlignVCenter" text: model.name color: (styleData.selected ? myPalette.highlightedText : myPalette.text) } } TableViewColumn { role: 'name' width: viewModeView.width } onRowCountChanged: { viewModeView.selection.clear() viewModeView.currentRow = 1 viewModeView.selection.select(1) } } } Item { Layout.fillHeight: true Layout.fillWidth: true RowLayout { anchors.fill: parent spacing: 0 id: contentZone Item { id: mainContentView Layout.leftMargin: Screen.pixelDensity * 0.5 Layout.rightMargin: Screen.pixelDensity * 0.5 Layout.fillHeight: true Layout.minimumWidth: 0 Layout.maximumWidth: 0 Layout.preferredWidth: 0 //z: 1 visible: Layout.minimumWidth != 0 MediaBrowser { id: localAlbums anchors.fill: parent firstPage: MediaAllAlbumView { playListModel: playListModelItem playerControl: manageAudioPlayer stackView: localAlbums.stackView contentDirectoryModel: allAlbumsModel } visible: opacity > 0 } MediaBrowser { id: localArtists anchors.fill: parent firstPage: MediaAllArtistView { playListModel: playListModelItem artistsModel: allArtistsModel playerControl: manageAudioPlayer stackView: localArtists.stackView contentDirectoryModel: allAlbumsModel } visible: opacity > 0 } } Rectangle { id: firstViewSeparatorItem border.width: 1 border.color: myPalette.mid color: myPalette.mid visible: true Layout.bottomMargin: Screen.pixelDensity * 0.5 Layout.topMargin: Screen.pixelDensity * 0.5 Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter Layout.preferredHeight: parent.height - Screen.pixelDensity * 5. Layout.minimumHeight: parent.height - Screen.pixelDensity * 5. Layout.maximumHeight: parent.height - Screen.pixelDensity * 5. Layout.preferredWidth: 1 Layout.minimumWidth: 1 Layout.maximumWidth: 1 } MediaPlayListView { id: playList playListModel: playListModelItem playListControler: playListControlerItem randomPlayChecked: playListControlerItem.randomPlayControl repeatPlayChecked: playListControlerItem.repeatPlayControl Layout.fillHeight: true Layout.minimumWidth: contentZone.width Layout.maximumWidth: contentZone.width Layout.preferredWidth: contentZone.width Component.onCompleted: { playListControlerItem.randomPlay = Qt.binding(function() { return playList.randomPlayChecked }) playListControlerItem.repeatPlay = Qt.binding(function() { return playList.repeatPlayChecked }) myPlayControlManager.randomOrContinuePlay = Qt.binding(function() { return playList.randomPlayChecked || playList.repeatPlayChecked }) } } Rectangle { id: viewSeparatorItem border.width: 1 border.color: myPalette.mid color: myPalette.mid visible: Layout.minimumWidth != 0 Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter Layout.preferredHeight: parent.height - Screen.pixelDensity * 5. Layout.preferredWidth: 1 Layout.minimumWidth: 1 Layout.maximumWidth: 1 } ContextView { id: albumContext Layout.fillHeight: true Layout.minimumWidth: contentZone.width Layout.maximumWidth: contentZone.width Layout.preferredWidth: contentZone.width visible: Layout.minimumWidth != 0 artistName: myHeaderBarManager.artist albumName: myHeaderBarManager.album albumArtUrl: myHeaderBarManager.image } } states: [ State { name: 'allAlbums' when: viewModeView.currentRow === 1 PropertyChanges { target: mainContentView Layout.minimumWidth: contentZone.width * 0.66 Layout.maximumWidth: contentZone.width * 0.66 Layout.preferredWidth: contentZone.width * 0.66 } PropertyChanges { target: firstViewSeparatorItem Layout.minimumWidth: 1 Layout.maximumWidth: 1 Layout.preferredWidth: 1 } PropertyChanges { target: playList Layout.minimumWidth: contentZone.width * 0.33 Layout.maximumWidth: contentZone.width * 0.33 Layout.preferredWidth: contentZone.width * 0.33 } PropertyChanges { target: viewSeparatorItem Layout.minimumWidth: 0 Layout.maximumWidth: 0 Layout.preferredWidth: 0 } PropertyChanges { target: albumContext Layout.minimumWidth: 0 Layout.maximumWidth: 0 Layout.preferredWidth: 0 } PropertyChanges { target: localAlbums opacity: 1 } PropertyChanges { target: localArtists opacity: 0 } }, State { name: 'allArtists' when: viewModeView.currentRow === 2 PropertyChanges { target: mainContentView Layout.minimumWidth: contentZone.width * 0.66 Layout.maximumWidth: contentZone.width * 0.66 Layout.preferredWidth: contentZone.width * 0.66 } PropertyChanges { target: firstViewSeparatorItem Layout.minimumWidth: 1 Layout.maximumWidth: 1 Layout.preferredWidth: 1 } PropertyChanges { target: playList Layout.minimumWidth: contentZone.width * 0.33 Layout.maximumWidth: contentZone.width * 0.33 Layout.preferredWidth: contentZone.width * 0.33 } PropertyChanges { target: viewSeparatorItem Layout.minimumWidth: 0 Layout.maximumWidth: 0 Layout.preferredWidth: 0 } PropertyChanges { target: albumContext Layout.minimumWidth: 0 Layout.maximumWidth: 0 Layout.preferredWidth: 0 } PropertyChanges { target: localAlbums opacity: 0 } PropertyChanges { target: localArtists opacity: 1 } }, State { name: 'full' when: viewModeView.currentRow == 0 PropertyChanges { target: mainContentView Layout.minimumWidth: 0 Layout.maximumWidth: 0 Layout.preferredWidth: 0 } PropertyChanges { target: firstViewSeparatorItem Layout.minimumWidth: 0 Layout.maximumWidth: 0 Layout.preferredWidth: 0 } PropertyChanges { target: playList Layout.minimumWidth: contentZone.width / 2 Layout.maximumWidth: contentZone.width / 2 Layout.preferredWidth: contentZone.width / 2 } PropertyChanges { target: viewSeparatorItem Layout.minimumWidth: 1 Layout.maximumWidth: 1 Layout.preferredWidth: 1 } PropertyChanges { target: albumContext Layout.minimumWidth: contentZone.width / 2 Layout.maximumWidth: contentZone.width / 2 Layout.preferredWidth: contentZone.width / 2 } PropertyChanges { target: localAlbums opacity: 0 } PropertyChanges { target: localArtists opacity: 0 } } ] transitions: Transition { NumberAnimation { properties: "Layout.minimumWidth, Layout.maximumWidth, Layout.preferredWidth, opacity" easing.type: Easing.InOutQuad duration: 300 } } } } } } } diff --git a/src/manageaudioplayer.cpp b/src/manageaudioplayer.cpp index 1af78d48..eeaaf72d 100644 --- a/src/manageaudioplayer.cpp +++ b/src/manageaudioplayer.cpp @@ -1,400 +1,428 @@ /* * Copyright 2016 Matthieu Gallien * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "manageaudioplayer.h" #include ManageAudioPlayer::ManageAudioPlayer(QObject *parent) : QObject(parent) { } QPersistentModelIndex ManageAudioPlayer::currentTrack() const { return mCurrentTrack; } QAbstractItemModel *ManageAudioPlayer::playListModel() const { return mPlayListModel; } int ManageAudioPlayer::urlRole() const { return mUrlRole; } int ManageAudioPlayer::isPlayingRole() const { return mIsPlayingRole; } QUrl ManageAudioPlayer::playerSource() const { if (!mCurrentTrack.isValid()) { return QUrl(); } return mCurrentTrack.data(mUrlRole).toUrl(); } int ManageAudioPlayer::playerStatus() const { return mPlayerStatus; } int ManageAudioPlayer::playerPlaybackState() const { return mPlayerPlaybackState; } int ManageAudioPlayer::playerError() const { return mPlayerError; } int ManageAudioPlayer::audioDuration() const { return mAudioDuration; } bool ManageAudioPlayer::playerIsSeekable() const { return mPlayerIsSeekable; } +int ManageAudioPlayer::playerPosition() const +{ + return mPlayerPosition; +} + int ManageAudioPlayer::playControlPosition() const { - return mPlayControlPosition; + return mPlayerPosition; } QVariantMap ManageAudioPlayer::persistentState() const { auto persistentStateValue = QVariantMap(); persistentStateValue[QStringLiteral("isPlaying")] = mPlayingState; + persistentStateValue[QStringLiteral("playerPosition")] = mPlayerPosition; return persistentStateValue; } void ManageAudioPlayer::setCurrentTrack(QPersistentModelIndex currentTrack) { if (mCurrentTrack == currentTrack) { return; } mOldCurrentTrack = mCurrentTrack; mCurrentTrack = currentTrack; Q_EMIT currentTrackChanged(); switch (mPlayerPlaybackState) { case StoppedState: notifyPlayerSourceProperty(); break; case PlayingState: case PausedState: triggerStop(); mSkippingCurrentTrack = true; break; } } void ManageAudioPlayer::setPlayListModel(QAbstractItemModel *aPlayListModel) { if (mPlayListModel == aPlayListModel) { return; } if (mPlayListModel) { disconnect(mPlayListModel, &QAbstractItemModel::dataChanged, this, &ManageAudioPlayer::tracksDataChanged); } mPlayListModel = aPlayListModel; if (mPlayListModel) { connect(mPlayListModel, &QAbstractItemModel::dataChanged, this, &ManageAudioPlayer::tracksDataChanged); } Q_EMIT playListModelChanged(); } void ManageAudioPlayer::setUrlRole(int value) { mUrlRole = value; Q_EMIT urlRoleChanged(); notifyPlayerSourceProperty(); } void ManageAudioPlayer::setIsPlayingRole(int value) { if (mIsPlayingRole == value) { return; } mIsPlayingRole = value; Q_EMIT isPlayingRoleChanged(); } void ManageAudioPlayer::setPlayerStatus(int playerStatus) { if (mPlayerStatus == playerStatus) { return; } if (playerStatus < static_cast(NoMedia) || playerStatus > static_cast(UnknownStatus)) { return; } mPlayerStatus = static_cast(playerStatus); Q_EMIT playerStatusChanged(); switch (mPlayerStatus) { case NoMedia: break; case Loading: break; case Loaded: break; case Buffering: if (mPlayingState) { triggerPlay(); } break; case Stalled: break; case Buffered: break; case EndOfMedia: break; case InvalidMedia: break; case UnknownStatus: break; } } void ManageAudioPlayer::setPlayerPlaybackState(int playerPlaybackState) { if (mPlayerPlaybackState == playerPlaybackState) { return; } if (playerPlaybackState < static_cast(StoppedState) || playerPlaybackState > static_cast(PausedState)) { return; } mPlayerPlaybackState = static_cast(playerPlaybackState); Q_EMIT playerPlaybackStateChanged(); if (!mSkippingCurrentTrack) { switch(mPlayerPlaybackState) { case StoppedState: if (mPlayerStatus == EndOfMedia) { triggerSkipNextTrack(); } if (mPlayListModel && mCurrentTrack.isValid()) { mPlayListModel->setData(mCurrentTrack, false, mIsPlayingRole); } break; case PlayingState: + if (isFirstPlayTriggerSeek) { + isFirstPlayTriggerSeek = false; + auto playerPosition = mPersistentState.find(QStringLiteral("playerPosition")); + if (playerPosition != mPersistentState.end()) { + mPlayerPosition = playerPosition->toInt(); + Q_EMIT seek(mPlayerPosition); + } + } if (mPlayListModel && mCurrentTrack.isValid()) { mPlayListModel->setData(mCurrentTrack, true, mIsPlayingRole); } break; case PausedState: break; } } else { switch(mPlayerPlaybackState) { case StoppedState: notifyPlayerSourceProperty(); mSkippingCurrentTrack = false; if (mPlayListModel && mOldCurrentTrack.isValid()) { mPlayListModel->setData(mOldCurrentTrack, false, mIsPlayingRole); } break; case PlayingState: + if (isFirstPlayTriggerSeek) { + isFirstPlayTriggerSeek = false; + auto playerPosition = mPersistentState.find(QStringLiteral("playerPosition")); + if (playerPosition != mPersistentState.end()) { + mPlayerPosition = playerPosition->toInt(); + Q_EMIT seek(mPlayerPosition); + } + } if (mPlayListModel && mCurrentTrack.isValid()) { mPlayListModel->setData(mCurrentTrack, true, mIsPlayingRole); } break; case PausedState: break; } } } void ManageAudioPlayer::setPlayerError(int playerError) { if (mPlayerError == playerError) { return; } if (playerError < static_cast(NoError) || playerError > static_cast(ServiceMissing)) { return; } mPlayerError = static_cast(playerError); Q_EMIT playerErrorChanged(); } void ManageAudioPlayer::playPause() { mPlayingState = !mPlayingState; switch (mPlayerStatus) { case Loaded: case Buffering: if (mPlayingState) { triggerPlay(); } else { triggerPause(); } break; case EndOfMedia: if (mPlayerPlaybackState == PlayingState && !mPlayingState) { triggerPause(); } else if (mPlayerPlaybackState == PausedState && mPlayingState) { triggerPlay(); } break; case NoMedia: case Loading: case Stalled: case Buffered: case InvalidMedia: case UnknownStatus: break; } } void ManageAudioPlayer::setAudioDuration(int audioDuration) { if (mAudioDuration == audioDuration) { return; } mAudioDuration = audioDuration; Q_EMIT audioDurationChanged(); } void ManageAudioPlayer::setPlayerIsSeekable(bool playerIsSeekable) { if (mPlayerIsSeekable == playerIsSeekable) { return; } mPlayerIsSeekable = playerIsSeekable; Q_EMIT playerIsSeekableChanged(); } -void ManageAudioPlayer::setPlayControlPosition(int playControlPosition) +void ManageAudioPlayer::setPlayerPosition(int playerPosition) { - if (mPlayControlPosition == playControlPosition) { + if (mPlayerPosition == playerPosition) { return; } - mPlayControlPosition = playControlPosition; - Q_EMIT playControlPositionChanged(); + mPlayerPosition = playerPosition; + Q_EMIT playerPositionChanged(); + QTimer::singleShot(0, [this]() {Q_EMIT playControlPositionChanged();}); +} + +void ManageAudioPlayer::setPlayControlPosition(int playerPosition) +{ + Q_EMIT seek(playerPosition); } void ManageAudioPlayer::setPersistentState(QVariantMap persistentStateValue) { if (mPersistentState == persistentStateValue) { return; } mPersistentState = persistentStateValue; auto isPlaying = mPersistentState.find(QStringLiteral("isPlaying")); if (isPlaying != mPersistentState.end()) { mPlayingState = isPlaying->toBool(); } Q_EMIT persistentStateChanged(); } void ManageAudioPlayer::playerSeek(int position) { Q_UNUSED(position); } void ManageAudioPlayer::playListFinished() { mPlayingState = false; } void ManageAudioPlayer::tracksDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles) { if (!mCurrentTrack.isValid()) { return; } if (mCurrentTrack.row() > bottomRight.row() || mCurrentTrack.row() < topLeft.row()) { return; } if (mCurrentTrack.column() > bottomRight.column() || mCurrentTrack.column() < topLeft.column()) { return; } if (roles.isEmpty()) { notifyPlayerSourceProperty(); } else { for(auto oneRole : roles) { if (oneRole == mUrlRole) { notifyPlayerSourceProperty(); } } } } void ManageAudioPlayer::notifyPlayerSourceProperty() { auto newUrlValue = mCurrentTrack.data(mUrlRole); if (mOldPlayerSource != newUrlValue) { Q_EMIT playerSourceChanged(); mOldPlayerSource = newUrlValue; } } void ManageAudioPlayer::triggerPlay() { QTimer::singleShot(0, [this]() {Q_EMIT playerPlay();}); } void ManageAudioPlayer::triggerPause() { QTimer::singleShot(0, [this]() {Q_EMIT playerPause();}); } void ManageAudioPlayer::triggerStop() { QTimer::singleShot(0, [this]() {Q_EMIT playerStop();}); } void ManageAudioPlayer::triggerSkipNextTrack() { QTimer::singleShot(0, [this]() {Q_EMIT skipNextTrack();}); } #include "moc_manageaudioplayer.cpp" diff --git a/src/manageaudioplayer.h b/src/manageaudioplayer.h index 245208ec..da4898ba 100644 --- a/src/manageaudioplayer.h +++ b/src/manageaudioplayer.h @@ -1,262 +1,277 @@ /* * Copyright 2016 Matthieu Gallien * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef MANAGEAUDIOPLAYER_H #define MANAGEAUDIOPLAYER_H #include #include #include #include class ManageAudioPlayer : public QObject { Q_OBJECT Q_PROPERTY(QPersistentModelIndex currentTrack READ currentTrack WRITE setCurrentTrack NOTIFY currentTrackChanged) Q_PROPERTY(QAbstractItemModel* playListModel READ playListModel WRITE setPlayListModel NOTIFY playListModelChanged) Q_PROPERTY(QUrl playerSource READ playerSource NOTIFY playerSourceChanged) Q_PROPERTY(int urlRole READ urlRole WRITE setUrlRole NOTIFY urlRoleChanged) Q_PROPERTY(int isPlayingRole READ isPlayingRole WRITE setIsPlayingRole NOTIFY isPlayingRoleChanged) Q_PROPERTY(int playerStatus READ playerStatus WRITE setPlayerStatus NOTIFY playerStatusChanged) Q_PROPERTY(int playerPlaybackState READ playerPlaybackState WRITE setPlayerPlaybackState NOTIFY playerPlaybackStateChanged) Q_PROPERTY(int playerError READ playerError WRITE setPlayerError NOTIFY playerErrorChanged) Q_PROPERTY(int audioDuration READ audioDuration WRITE setAudioDuration NOTIFY audioDurationChanged) Q_PROPERTY(bool playerIsSeekable READ playerIsSeekable WRITE setPlayerIsSeekable NOTIFY playerIsSeekableChanged) + Q_PROPERTY(int playerPosition + READ playerPosition + WRITE setPlayerPosition + NOTIFY playerPositionChanged) + Q_PROPERTY(int playControlPosition READ playControlPosition WRITE setPlayControlPosition NOTIFY playControlPositionChanged) Q_PROPERTY(QVariantMap persistentState READ persistentState WRITE setPersistentState NOTIFY persistentStateChanged) public: enum PlayerStatus { NoMedia = 0, Loading = NoMedia + 1, Loaded = Loading + 1, Buffering = Loaded + 1, Stalled = Buffering + 1, Buffered = Stalled + 1, EndOfMedia = Buffered + 1, InvalidMedia = EndOfMedia + 1, UnknownStatus = InvalidMedia + 1, }; Q_ENUM(PlayerStatus) enum PlayerPlaybackState { PlayingState = 1, PausedState = 2, StoppedState = 0, }; Q_ENUM(PlayerPlaybackState) enum PlayerErrorState { NoError = 0, ResourceError = NoError + 1, FormatError = ResourceError + 1, NetworkError = FormatError + 1, AccessDenied = NetworkError + 1, ServiceMissing = AccessDenied + 1, }; Q_ENUM(PlayerErrorState) explicit ManageAudioPlayer(QObject *parent = 0); QPersistentModelIndex currentTrack() const; QAbstractItemModel* playListModel() const; int urlRole() const; int isPlayingRole() const; QUrl playerSource() const; int playerStatus() const; int playerPlaybackState() const; int playerError() const; int audioDuration() const; bool playerIsSeekable() const; + int playerPosition() const; + int playControlPosition() const; QVariantMap persistentState() const; Q_SIGNALS: void currentTrackChanged(); void playListModelChanged(); void playerSourceChanged(); void urlRoleChanged(); void isPlayingRoleChanged(); void playerStatusChanged(); void playerPlaybackStateChanged(); void playerErrorChanged(); void playerPlay(); void playerPause(); void playerStop(); void skipNextTrack(); void audioDurationChanged(); void playerIsSeekableChanged(); + void playerPositionChanged(); + void playControlPositionChanged(); void persistentStateChanged(); + void seek(int position); + public Q_SLOTS: void setCurrentTrack(QPersistentModelIndex currentTrack); void setPlayListModel(QAbstractItemModel* aPlayListModel); void setUrlRole(int value); void setIsPlayingRole(int value); void setPlayerStatus(int playerStatus); void setPlayerPlaybackState(int playerPlaybackState); void setPlayerError(int playerError); void playPause(); void setAudioDuration(int audioDuration); void setPlayerIsSeekable(bool playerIsSeekable); - void setPlayControlPosition(int playControlPosition); + void setPlayerPosition(int playerPosition); + + void setPlayControlPosition(int playerPosition); void setPersistentState(QVariantMap persistentStateValue); void playerSeek(int position); void playListFinished(); void tracksDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles); private: void notifyPlayerSourceProperty(); void triggerPlay(); void triggerPause(); void triggerStop(); void triggerSkipNextTrack(); QPersistentModelIndex mCurrentTrack; QPersistentModelIndex mOldCurrentTrack; QAbstractItemModel *mPlayListModel = nullptr; int mUrlRole = Qt::DisplayRole; int mIsPlayingRole = Qt::DisplayRole; QVariant mOldPlayerSource; PlayerStatus mPlayerStatus = NoMedia; PlayerPlaybackState mPlayerPlaybackState = StoppedState; PlayerErrorState mPlayerError = NoError; bool mPlayingState = false; bool mSkippingCurrentTrack = false; int mAudioDuration = 0; bool mPlayerIsSeekable = false; - int mPlayControlPosition = 0; + int mPlayerPosition = 0; + + bool isFirstPlayTriggerSeek = true; QVariantMap mPersistentState; }; #endif // MANAGEAUDIOPLAYER_H diff --git a/src/mpris2/mediaplayer2player.cpp b/src/mpris2/mediaplayer2player.cpp index 3fa831e7..1fc4e604 100644 --- a/src/mpris2/mediaplayer2player.cpp +++ b/src/mpris2/mediaplayer2player.cpp @@ -1,375 +1,375 @@ /*************************************************************************** * Copyright 2014 Sujith Haridasan * * Copyright 2014 Ashish Madeti * * Copyright 2016 Matthieu Gallien * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 3 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ #include "mediaplayer2player.h" #include "mpris2.h" #include "playlistcontroler.h" #include "manageaudioplayer.h" #include "managemediaplayercontrol.h" #include "manageheaderbar.h" #include #include #include #include #include #include static const double MAX_RATE = 1.0; static const double MIN_RATE = 1.0; MediaPlayer2Player::MediaPlayer2Player(PlayListControler *playListControler, ManageAudioPlayer *manageAudioPlayer, ManageMediaPlayerControl *manageMediaPlayerControl, ManageHeaderBar *manageHeaderBar, QObject* parent) : QDBusAbstractAdaptor(parent), m_playListControler(playListControler), m_manageAudioPlayer(manageAudioPlayer), m_manageMediaPlayerControl(manageMediaPlayerControl), m_manageHeaderBar(manageHeaderBar) { if (!m_playListControler) { return; } connect(m_manageAudioPlayer, &ManageAudioPlayer::playerSourceChanged, this, &MediaPlayer2Player::playerSourceChanged, Qt::QueuedConnection); connect(m_manageMediaPlayerControl, &ManageMediaPlayerControl::playControlEnabledChanged, this, &MediaPlayer2Player::playControlEnabledChanged); connect(m_manageMediaPlayerControl, &ManageMediaPlayerControl::skipBackwardControlEnabledChanged, this, &MediaPlayer2Player::skipBackwardControlEnabledChanged); connect(m_manageMediaPlayerControl, &ManageMediaPlayerControl::skipForwardControlEnabledChanged, this, &MediaPlayer2Player::skipForwardControlEnabledChanged); connect(m_manageAudioPlayer, &ManageAudioPlayer::playerPlaybackStateChanged, this, &MediaPlayer2Player::playerPlaybackStateChanged); connect(m_manageAudioPlayer, &ManageAudioPlayer::playerIsSeekableChanged, this, &MediaPlayer2Player::playerIsSeekableChanged); - connect(m_manageAudioPlayer, &ManageAudioPlayer::playControlPositionChanged, + connect(m_manageAudioPlayer, &ManageAudioPlayer::playerPositionChanged, this, &MediaPlayer2Player::audioPositionChanged); m_mediaPlayerPresent = 1; } MediaPlayer2Player::~MediaPlayer2Player() { } QString MediaPlayer2Player::PlaybackStatus() const { if (!m_playListControler) { return QLatin1String("Stopped"); } if (m_manageAudioPlayer->playerPlaybackState() == ManageAudioPlayer::StoppedState) { return QStringLiteral("Stopped"); } else if (m_manageAudioPlayer->playerPlaybackState() == ManageAudioPlayer::PlayingState) { return QStringLiteral("Playing"); } else { return QStringLiteral("Paused"); } } bool MediaPlayer2Player::CanGoNext() const { return m_canGoNext; } void MediaPlayer2Player::Next() const { emit next(); if (m_playListControler) { m_playListControler->skipNextTrack(); } } bool MediaPlayer2Player::CanGoPrevious() const { return m_canGoPrevious; } void MediaPlayer2Player::Previous() const { emit previous(); if (m_playListControler) { m_playListControler->skipPreviousTrack(); } } bool MediaPlayer2Player::CanPause() const { return !m_canPlay; } void MediaPlayer2Player::Pause() const { if (m_playListControler) { m_manageAudioPlayer->playPause(); } } void MediaPlayer2Player::PlayPause() { emit playPause(); if (m_playListControler) { m_manageAudioPlayer->playPause(); } } void MediaPlayer2Player::Stop() const { emit stop(); } bool MediaPlayer2Player::CanPlay() const { return m_canPlay; } void MediaPlayer2Player::Play() const { if (m_playListControler) { m_manageAudioPlayer->playPause(); } } double MediaPlayer2Player::Volume() const { return m_volume; } void MediaPlayer2Player::setVolume(double volume) { m_volume= qBound(0.0, volume, 1.0); emit volumeChanged(m_volume); signalPropertiesChange(QStringLiteral("Volume"), Volume()); } QVariantMap MediaPlayer2Player::Metadata() const { return m_metadata; } qlonglong MediaPlayer2Player::Position() const { return m_position; } void MediaPlayer2Player::setPropertyPosition(int newPositionInMs) { m_position = qlonglong(newPositionInMs) * 1000; signalPropertiesChange(QStringLiteral("Position"), Position()); } double MediaPlayer2Player::Rate() const { return m_rate; } void MediaPlayer2Player::setRate(double newRate) { if (newRate == 0) { Pause(); } else { m_rate = qBound(MinimumRate(), newRate, MaximumRate()); emit rateChanged(m_rate); signalPropertiesChange(QStringLiteral("Rate"), Rate()); } } double MediaPlayer2Player::MinimumRate() const { return MIN_RATE; } double MediaPlayer2Player::MaximumRate() const { return MAX_RATE; } bool MediaPlayer2Player::CanSeek() const { return m_playerIsSeekableChanged; } bool MediaPlayer2Player::CanControl() const { return true; } void MediaPlayer2Player::Seek(qlonglong Offset) const { if (mediaPlayerPresent()) { //The seekTo function (to which this signal is linked to) accepts offset in milliseconds int offset = Offset / 1000; emit seek(offset); } } void MediaPlayer2Player::emitSeeked(int pos) { emit Seeked(qlonglong(pos) * 1000); } void MediaPlayer2Player::SetPosition(QDBusObjectPath trackId, qlonglong pos) const { if (trackId.path() == m_currentTrackId) { emit seek((pos - Position()) / 1000); m_manageAudioPlayer->playerSeek((pos - Position()) / 1000); } m_manageAudioPlayer->playerSeek(pos / 1000); } void MediaPlayer2Player::OpenUri(QString uri) const { Q_UNUSED(uri); } void MediaPlayer2Player::playerSourceChanged() { if (!m_playListControler) { return; } setCurrentTrack(m_manageAudioPlayer->playControlPosition()); } void MediaPlayer2Player::playControlEnabledChanged() { if (!m_playListControler) { return; } m_canPlay = m_manageMediaPlayerControl->playControlEnabled(); signalPropertiesChange(QStringLiteral("CanPause"), CanPause()); signalPropertiesChange(QStringLiteral("CanPlay"), CanPlay()); } void MediaPlayer2Player::skipBackwardControlEnabledChanged() { if (!m_playListControler) { return; } m_canGoPrevious = m_manageMediaPlayerControl->skipBackwardControlEnabled(); signalPropertiesChange(QStringLiteral("CanGoPrevious"), CanGoPrevious()); } void MediaPlayer2Player::skipForwardControlEnabledChanged() { if (!m_playListControler) { return; } m_canGoNext = m_manageMediaPlayerControl->skipForwardControlEnabled(); signalPropertiesChange(QStringLiteral("CanGoNext"), CanGoNext()); } void MediaPlayer2Player::playerPlaybackStateChanged() { signalPropertiesChange(QStringLiteral("PlaybackStatus"), PlaybackStatus()); playerIsSeekableChanged(); } void MediaPlayer2Player::playerIsSeekableChanged() { m_playerIsSeekableChanged = m_manageAudioPlayer->playerIsSeekable(); signalPropertiesChange(QStringLiteral("CanSeek"), CanSeek()); } void MediaPlayer2Player::audioPositionChanged() { - setPropertyPosition(m_manageAudioPlayer->playControlPosition()); + setPropertyPosition(m_manageAudioPlayer->playerPosition()); } int MediaPlayer2Player::currentTrack() const { return m_manageAudioPlayer->playControlPosition(); } void MediaPlayer2Player::setCurrentTrack(int newTrackPosition) { m_currentTrack = m_manageAudioPlayer->playerSource().toString(); m_currentTrackId = QDBusObjectPath(QStringLiteral("/org/kde/elisa/playlist/") + QString::number(newTrackPosition)).path(); m_metadata = getMetadataOfCurrentTrack(); signalPropertiesChange(QStringLiteral("Metadata"), Metadata()); skipBackwardControlEnabledChanged(); skipForwardControlEnabledChanged(); playerPlaybackStateChanged(); playerIsSeekableChanged(); audioPositionChanged(); } QVariantMap MediaPlayer2Player::getMetadataOfCurrentTrack() { auto result = QVariantMap(); result[QStringLiteral("mpris:trackid")] = QVariant::fromValue(QDBusObjectPath(m_currentTrackId)); result[QStringLiteral("mpris:length")] = qlonglong(m_manageAudioPlayer->audioDuration()) * 1000; //convert milli-seconds into micro-seconds result[QStringLiteral("xesam:title")] = m_manageHeaderBar->title(); result[QStringLiteral("xesam:url")] = m_manageAudioPlayer->playerSource().toString(); result[QStringLiteral("xesam:album")] = m_manageHeaderBar->album(); result[QStringLiteral("xesam:artist")] = {m_manageHeaderBar->artist()}; result[QStringLiteral("mpris:artUrl")] = m_manageHeaderBar->image().toString(); return result; } int MediaPlayer2Player::mediaPlayerPresent() const { return m_mediaPlayerPresent; } void MediaPlayer2Player::setMediaPlayerPresent(int status) { if (m_mediaPlayerPresent != status) { m_mediaPlayerPresent = status; signalPropertiesChange(QStringLiteral("CanGoNext"), CanGoNext()); signalPropertiesChange(QStringLiteral("CanGoPrevious"), CanGoPrevious()); signalPropertiesChange(QStringLiteral("CanPause"), CanPause()); signalPropertiesChange(QStringLiteral("CanPlay"), CanPlay()); } } void MediaPlayer2Player::signalPropertiesChange(const QString &property, const QVariant &value) { QVariantMap properties; properties[property] = value; const int ifaceIndex = metaObject()->indexOfClassInfo("D-Bus Interface"); QDBusMessage msg = QDBusMessage::createSignal(QStringLiteral("/org/mpris/MediaPlayer2"), QStringLiteral("org.freedesktop.DBus.Properties"), QStringLiteral("PropertiesChanged")); msg << QLatin1String(metaObject()->classInfo(ifaceIndex).value()); msg << properties; msg << QStringList(); QDBusConnection::sessionBus().send(msg); }