1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the test suite of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#ifndef MOCKPLAYERSERVICE_H
30#define MOCKPLAYERSERVICE_H
31
32#include "qmediaservice.h"
33
34#include "mockmediaplayercontrol.h"
35#include "mockmediastreamscontrol.h"
36#include "mockmedianetworkaccesscontrol.h"
37#include "mockvideorenderercontrol.h"
38#include "mockvideoprobecontrol.h"
39#include "mockvideowindowcontrol.h"
40#include "mockaudiorolecontrol.h"
41#include "mockcustomaudiorolecontrol.h"
42
43class MockMediaPlayerService : public QMediaService
44{
45 Q_OBJECT
46
47public:
48 MockMediaPlayerService():QMediaService(0)
49 {
50 mockControl = new MockMediaPlayerControl;
51 mockAudioRoleControl = new MockAudioRoleControl;
52 mockCustomAudioRoleControl = new MockCustomAudioRoleControl;
53 mockStreamsControl = new MockStreamsControl;
54 mockNetworkControl = new MockNetworkAccessControl;
55 rendererControl = new MockVideoRendererControl;
56 rendererRef = 0;
57 mockVideoProbeControl = new MockVideoProbeControl;
58 windowControl = new MockVideoWindowControl;
59 windowRef = 0;
60 enableAudioRole = true;
61 enableCustomAudioRole = true;
62 }
63
64 ~MockMediaPlayerService()
65 {
66 delete mockControl;
67 delete mockAudioRoleControl;
68 delete mockCustomAudioRoleControl;
69 delete mockStreamsControl;
70 delete mockNetworkControl;
71 delete rendererControl;
72 delete mockVideoProbeControl;
73 delete windowControl;
74 }
75
76 QMediaControl* requestControl(const char *iid)
77 {
78 if (qstrcmp(str1: iid, QMediaPlayerControl_iid) == 0) {
79 return mockControl;
80 } else if (qstrcmp(str1: iid, QVideoRendererControl_iid) == 0) {
81 if (rendererRef == 0) {
82 rendererRef += 1;
83 return rendererControl;
84 }
85 } else if (qstrcmp(str1: iid, QMediaVideoProbeControl_iid) == 0) {
86 return mockVideoProbeControl;
87 }
88 if (qstrcmp(str1: iid, QVideoWindowControl_iid) == 0) {
89 if (windowRef == 0) {
90 windowRef += 1;
91 return windowControl;
92 }
93 } else if (enableAudioRole && qstrcmp(str1: iid, QAudioRoleControl_iid) == 0) {
94 return mockAudioRoleControl;
95 } else if (enableCustomAudioRole && qstrcmp(str1: iid, QCustomAudioRoleControl_iid) == 0) {
96 return mockCustomAudioRoleControl;
97 }
98
99 if (qstrcmp(str1: iid, QMediaNetworkAccessControl_iid) == 0)
100 return mockNetworkControl;
101 return 0;
102 }
103
104 void releaseControl(QMediaControl *control)
105 {
106 if (control == rendererControl)
107 rendererRef -= 1;
108 if (control == windowControl)
109 windowRef -= 1;
110 }
111
112 void setState(QMediaPlayer::State state) { emit mockControl->stateChanged(newState: mockControl->_state = state); }
113 void setState(QMediaPlayer::State state, QMediaPlayer::MediaStatus status) {
114 mockControl->_state = state;
115 mockControl->_mediaStatus = status;
116 emit mockControl->mediaStatusChanged(status);
117 emit mockControl->stateChanged(newState: state);
118 }
119 void setMediaStatus(QMediaPlayer::MediaStatus status) { emit mockControl->mediaStatusChanged(status: mockControl->_mediaStatus = status); }
120 void setIsValid(bool isValid) { mockControl->_isValid = isValid; }
121 void setMedia(QMediaContent media) { mockControl->_media = media; }
122 void setDuration(qint64 duration) { mockControl->_duration = duration; }
123 void setPosition(qint64 position) { mockControl->_position = position; }
124 void setSeekable(bool seekable) { mockControl->_isSeekable = seekable; }
125 void setVolume(int volume) { mockControl->_volume = volume; }
126 void setMuted(bool muted) { mockControl->_muted = muted; }
127 void setVideoAvailable(bool videoAvailable) { mockControl->_videoAvailable = videoAvailable; }
128 void setBufferStatus(int bufferStatus) { mockControl->_bufferStatus = bufferStatus; }
129 void setPlaybackRate(qreal playbackRate) { mockControl->_playbackRate = playbackRate; }
130 void setError(QMediaPlayer::Error error) { mockControl->_error = error; emit mockControl->error(error: mockControl->_error, errorString: mockControl->_errorString); }
131 void setErrorString(QString errorString) { mockControl->_errorString = errorString; emit mockControl->error(error: mockControl->_error, errorString: mockControl->_errorString); }
132
133 void selectCurrentConfiguration(QNetworkConfiguration config) { mockNetworkControl->setCurrentConfiguration(config); }
134
135 void setHasAudioRole(bool enable) { enableAudioRole = enable; }
136 void setHasCustomAudioRole(bool enable) { enableCustomAudioRole = enable; }
137
138 void reset()
139 {
140 mockControl->_state = QMediaPlayer::StoppedState;
141 mockControl->_mediaStatus = QMediaPlayer::UnknownMediaStatus;
142 mockControl->_error = QMediaPlayer::NoError;
143 mockControl->_duration = 0;
144 mockControl->_position = 0;
145 mockControl->_volume = 0;
146 mockControl->_muted = false;
147 mockControl->_bufferStatus = 0;
148 mockControl->_videoAvailable = false;
149 mockControl->_isSeekable = false;
150 mockControl->_playbackRate = 0.0;
151 mockControl->_media = QMediaContent();
152 mockControl->_stream = 0;
153 mockControl->_isValid = false;
154 mockControl->_errorString = QString();
155
156 enableAudioRole = true;
157 mockAudioRoleControl->m_audioRole = QAudio::UnknownRole;
158 enableCustomAudioRole = true;
159 mockCustomAudioRoleControl->m_customAudioRole.clear();
160
161 mockNetworkControl->_current = QNetworkConfiguration();
162 mockNetworkControl->_configurations = QList<QNetworkConfiguration>();
163 }
164
165 MockMediaPlayerControl *mockControl;
166 MockAudioRoleControl *mockAudioRoleControl;
167 MockCustomAudioRoleControl *mockCustomAudioRoleControl;
168 MockStreamsControl *mockStreamsControl;
169 MockNetworkAccessControl *mockNetworkControl;
170 MockVideoRendererControl *rendererControl;
171 MockVideoProbeControl *mockVideoProbeControl;
172 MockVideoWindowControl *windowControl;
173 int windowRef;
174 int rendererRef;
175 bool enableAudioRole;
176 bool enableCustomAudioRole;
177};
178
179
180
181#endif // MOCKPLAYERSERVICE_H
182

source code of qtmultimedia/tests/auto/unit/qmultimedia_common/mockmediaplayerservice.h