47
|
1 |
/**
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: Unit test for mpmediakeyhandler
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <QMetaType>
|
|
19 |
|
|
20 |
#include "stub/inc/mpenginefactory.h"
|
|
21 |
#include "stub/inc/remconcoreapitarget.h"
|
|
22 |
#include "stub/inc/remconcoreapitargetobserver.h"
|
|
23 |
#include "stub/inc/remconinterfaceselector.h"
|
|
24 |
#include "unittest_mpmediakeyhandler.h"
|
|
25 |
#include "mpcommondefs.h"
|
|
26 |
|
|
27 |
|
|
28 |
// Do this so we can access all member variables.
|
|
29 |
#define private public
|
|
30 |
#include "mpmediakeyhandler.h"
|
|
31 |
#include "mpmediakeyhandler_p.h"
|
|
32 |
#undef private
|
|
33 |
|
|
34 |
//This so stub classes can be loaded
|
|
35 |
#include "mpmediakeyhandler_p.cpp"
|
|
36 |
#include "mpmediakeyremconresponse.cpp"
|
|
37 |
|
|
38 |
|
|
39 |
/*!
|
|
40 |
Make our test case a stand-alone executable that runs all the test functions.
|
|
41 |
*/
|
|
42 |
int main(int argc, char *argv[])
|
|
43 |
{
|
|
44 |
QApplication app(argc, argv);
|
|
45 |
|
|
46 |
TestMpMediaKeyHandler tv;
|
|
47 |
|
|
48 |
if ( argc > 1 ) {
|
|
49 |
return QTest::qExec( &tv, argc, argv);
|
|
50 |
}
|
|
51 |
else {
|
|
52 |
char *pass[3];
|
|
53 |
pass[0] = argv[0];
|
|
54 |
pass[1] = "-o";
|
|
55 |
pass[2] = "c:\\data\\unittest_mpmediakeyhandler.txt";
|
|
56 |
|
|
57 |
return QTest::qExec(&tv, 3, pass);
|
|
58 |
}
|
|
59 |
}
|
|
60 |
|
|
61 |
TestMpMediaKeyHandler::TestMpMediaKeyHandler()
|
|
62 |
: mTest(0)
|
|
63 |
{
|
|
64 |
}
|
|
65 |
|
|
66 |
TestMpMediaKeyHandler::~TestMpMediaKeyHandler()
|
|
67 |
{
|
|
68 |
delete mTest;
|
|
69 |
}
|
|
70 |
|
|
71 |
/*!
|
|
72 |
Called before the first testfunction is executed.
|
|
73 |
*/
|
|
74 |
void TestMpMediaKeyHandler::initTestCase()
|
|
75 |
{
|
|
76 |
}
|
|
77 |
|
|
78 |
/*!
|
|
79 |
Called after the last testfunction was executed.
|
|
80 |
*/
|
|
81 |
void TestMpMediaKeyHandler::cleanupTestCase()
|
|
82 |
{
|
|
83 |
}
|
|
84 |
|
|
85 |
/*!
|
|
86 |
Called before each testfunction is executed.
|
|
87 |
*/
|
|
88 |
void TestMpMediaKeyHandler::init()
|
|
89 |
{
|
|
90 |
mTest = new MpMediaKeyHandler();
|
|
91 |
mTestPrivate = mTest->d_ptr;
|
|
92 |
}
|
|
93 |
|
|
94 |
/*!
|
|
95 |
Called after every testfunction.
|
|
96 |
*/
|
|
97 |
void TestMpMediaKeyHandler::cleanup()
|
|
98 |
{
|
|
99 |
if (mTest)
|
|
100 |
{
|
|
101 |
delete mTest;
|
|
102 |
mTest = 0;
|
|
103 |
mTestPrivate = 0;
|
|
104 |
|
|
105 |
MpEngineFactory::close();
|
|
106 |
}
|
|
107 |
}
|
|
108 |
|
|
109 |
void TestMpMediaKeyHandler::testConstructor()
|
|
110 |
{
|
|
111 |
QVERIFY( mTest );
|
|
112 |
QVERIFY( mTestPrivate );
|
|
113 |
QVERIFY( mTestPrivate->iInterfaceSelector );
|
|
114 |
QVERIFY( mTestPrivate->iResponseHandler );
|
|
115 |
QVERIFY( mTestPrivate->iMpEngine );
|
|
116 |
}
|
|
117 |
|
|
118 |
void TestMpMediaKeyHandler::testDestructor()
|
|
119 |
{
|
|
120 |
// it is been observed that CRemConCoreApiTarget is not being deleted by anyone
|
|
121 |
// the creator claim it does not own it, while others never claim the ownership neither
|
|
122 |
cleanup();
|
|
123 |
QVERIFY( !mTest );
|
|
124 |
//QCOMPARE(CRemConCoreApiTarget::getCount(), 0);
|
|
125 |
QCOMPARE(CRemConCoreApiTarget::getCount(), 2);
|
|
126 |
QCOMPARE(CRemConInterfaceSelector::getCount(), 0);
|
|
127 |
}
|
|
128 |
|
|
129 |
void TestMpMediaKeyHandler::testCommandPausePlayKey()
|
|
130 |
{
|
|
131 |
int oldCount = CRemConCoreApiTarget::getSendResponseCount();
|
|
132 |
mTestPrivate->MrccatoCommand(ERemConCoreApiPausePlayFunction, ERemConCoreApiButtonClick);
|
|
133 |
QCOMPARE(CRemConCoreApiTarget::getSendResponseCount(), oldCount+1);
|
|
134 |
QCOMPARE(mTestPrivate->iMpEngine->iMediaCommandReceived, CmdPlayPause);
|
|
135 |
|
|
136 |
}
|
|
137 |
|
|
138 |
void TestMpMediaKeyHandler::testCommandPlayKey()
|
|
139 |
{
|
|
140 |
int oldCount = CRemConCoreApiTarget::getSendResponseCount();
|
|
141 |
mTestPrivate->MrccatoCommand(ERemConCoreApiPlay, ERemConCoreApiButtonClick);
|
|
142 |
QCOMPARE(CRemConCoreApiTarget::getSendResponseCount(), oldCount+1);
|
|
143 |
QCOMPARE(mTestPrivate->iMpEngine->iMediaCommandReceived, CmdPlay);
|
|
144 |
}
|
|
145 |
|
|
146 |
void TestMpMediaKeyHandler::testCommandStopKey()
|
|
147 |
{
|
|
148 |
int oldCount = CRemConCoreApiTarget::getSendResponseCount();
|
|
149 |
mTestPrivate->MrccatoCommand(ERemConCoreApiStop, ERemConCoreApiButtonClick);
|
|
150 |
QCOMPARE(CRemConCoreApiTarget::getSendResponseCount(), oldCount+1);
|
|
151 |
QCOMPARE(mTestPrivate->iMpEngine->iMediaCommandReceived, CmdStop);
|
|
152 |
}
|
|
153 |
|
|
154 |
void TestMpMediaKeyHandler::testCommandPauseKey()
|
|
155 |
{
|
|
156 |
int oldCount = CRemConCoreApiTarget::getSendResponseCount();
|
|
157 |
mTestPrivate->MrccatoCommand(ERemConCoreApiPause, ERemConCoreApiButtonClick);
|
|
158 |
QCOMPARE(CRemConCoreApiTarget::getSendResponseCount(), oldCount+1);
|
|
159 |
QCOMPARE(mTestPrivate->iMpEngine->iMediaCommandReceived, CmdPause);
|
|
160 |
}
|
|
161 |
|
|
162 |
void TestMpMediaKeyHandler::testCommandRewindKeyPress()
|
|
163 |
{
|
|
164 |
int oldCount = CRemConCoreApiTarget::getSendResponseCount();
|
|
165 |
mTestPrivate->MrccatoCommand(ERemConCoreApiRewind, ERemConCoreApiButtonPress);
|
|
166 |
QCOMPARE(CRemConCoreApiTarget::getSendResponseCount(), oldCount+1);
|
|
167 |
QCOMPARE(mTestPrivate->iMpEngine->iMediaCommandReceived, CmdStartSeekBackward);
|
|
168 |
}
|
|
169 |
|
|
170 |
void TestMpMediaKeyHandler::testCommandRewindKeyRelease()
|
|
171 |
{
|
|
172 |
int oldCount = CRemConCoreApiTarget::getSendResponseCount();
|
|
173 |
mTestPrivate->MrccatoCommand(ERemConCoreApiRewind, ERemConCoreApiButtonRelease);
|
|
174 |
QCOMPARE(CRemConCoreApiTarget::getSendResponseCount(), oldCount+1);
|
|
175 |
QCOMPARE(mTestPrivate->iMpEngine->iMediaCommandReceived, CmdStopSeeking);
|
|
176 |
}
|
|
177 |
|
|
178 |
void TestMpMediaKeyHandler::testCommandFastForwardKeyPress()
|
|
179 |
{
|
|
180 |
int oldCount = CRemConCoreApiTarget::getSendResponseCount();
|
|
181 |
mTestPrivate->MrccatoCommand(ERemConCoreApiFastForward, ERemConCoreApiButtonPress);
|
|
182 |
QCOMPARE(CRemConCoreApiTarget::getSendResponseCount(), oldCount+1);
|
|
183 |
QCOMPARE(mTestPrivate->iMpEngine->iMediaCommandReceived, CmdStartSeekForward);
|
|
184 |
}
|
|
185 |
|
|
186 |
void TestMpMediaKeyHandler::testCommandFastForwardKeyRelease()
|
|
187 |
{
|
|
188 |
int oldCount = CRemConCoreApiTarget::getSendResponseCount();
|
|
189 |
mTestPrivate->MrccatoCommand(ERemConCoreApiFastForward, ERemConCoreApiButtonRelease);
|
|
190 |
QCOMPARE(CRemConCoreApiTarget::getSendResponseCount(), oldCount+1);
|
|
191 |
QCOMPARE(mTestPrivate->iMpEngine->iMediaCommandReceived, CmdStopSeeking);
|
|
192 |
}
|
|
193 |
|
|
194 |
void TestMpMediaKeyHandler::testCommandBackwardKey()
|
|
195 |
{
|
|
196 |
int oldCount = CRemConCoreApiTarget::getSendResponseCount();
|
|
197 |
mTestPrivate->MrccatoCommand(ERemConCoreApiBackward, ERemConCoreApiButtonClick);
|
|
198 |
QCOMPARE(CRemConCoreApiTarget::getSendResponseCount(), oldCount+1);
|
|
199 |
QCOMPARE(mTestPrivate->iMpEngine->iMediaCommandReceived, CmdSkipBackward);
|
|
200 |
}
|
|
201 |
|
|
202 |
void TestMpMediaKeyHandler::testCommandForwardKey()
|
|
203 |
{
|
|
204 |
int oldCount = CRemConCoreApiTarget::getSendResponseCount();
|
|
205 |
mTestPrivate->MrccatoCommand(ERemConCoreApiForward, ERemConCoreApiButtonClick);
|
|
206 |
QCOMPARE(CRemConCoreApiTarget::getSendResponseCount(), oldCount+1);
|
|
207 |
QCOMPARE(mTestPrivate->iMpEngine->iMediaCommandReceived, CmdSkipForward);
|
|
208 |
}
|
|
209 |
|
|
210 |
void TestMpMediaKeyHandler::testCommandVolumeUpKey()
|
|
211 |
{
|
|
212 |
int oldCount = CRemConCoreApiTarget::getSendResponseCount();
|
|
213 |
|
|
214 |
// Simulate hardware side key clicked.
|
|
215 |
mTestPrivate->MrccatoCommand(ERemConCoreApiVolumeUp, ERemConCoreApiButtonClick);
|
|
216 |
QCOMPARE(CRemConCoreApiTarget::getSendResponseCount(), oldCount+1);
|
|
217 |
QCOMPARE( mTestPrivate->iMpEngine->iMediaCommandReceived, CmdIncreaseVolume );
|
|
218 |
QVERIFY( mTestPrivate->iSideKeyAlreadyClicked );
|
|
219 |
QTest::qWait(100);
|
|
220 |
|
|
221 |
// Simulate holding the hardware side key.
|
|
222 |
mTestPrivate->iMpEngine->iMediaCommandReceived = CmdNone;
|
|
223 |
mTestPrivate->MrccatoCommand(ERemConCoreApiVolumeUp, ERemConCoreApiButtonPress);
|
|
224 |
QCOMPARE(CRemConCoreApiTarget::getSendResponseCount(), oldCount+2);
|
|
225 |
QCOMPARE( mTestPrivate->iMpEngine->iMediaCommandReceived, CmdNone );
|
|
226 |
QVERIFY( mTestPrivate->iSideKeyAlreadyClicked );
|
|
227 |
QTest::qWait(100);
|
|
228 |
|
|
229 |
// Release hardware side key.
|
|
230 |
mTestPrivate->MrccatoCommand(ERemConCoreApiVolumeUp, ERemConCoreApiButtonRelease);
|
|
231 |
QCOMPARE(CRemConCoreApiTarget::getSendResponseCount(), oldCount+3);
|
|
232 |
QCOMPARE( mTestPrivate->iMpEngine->iMediaCommandReceived, CmdNone );
|
|
233 |
QVERIFY( !mTestPrivate->iSideKeyAlreadyClicked );
|
|
234 |
QTest::qWait(100);
|
|
235 |
|
|
236 |
// Simulate headset volume key pressed.
|
|
237 |
mTestPrivate->MrccatoCommand(ERemConCoreApiVolumeUp, ERemConCoreApiButtonPress);
|
|
238 |
QCOMPARE(CRemConCoreApiTarget::getSendResponseCount(), oldCount+4);
|
|
239 |
QCOMPARE( mTestPrivate->iMpEngine->iMediaCommandReceived, CmdIncreaseVolume );
|
|
240 |
QVERIFY( mTestPrivate->iSideKeyAlreadyClicked );
|
|
241 |
}
|
|
242 |
|
|
243 |
void TestMpMediaKeyHandler::testCommandVolumeDownKey()
|
|
244 |
{
|
|
245 |
int oldCount = CRemConCoreApiTarget::getSendResponseCount();
|
|
246 |
|
|
247 |
// Simulate hardware side key clicked.
|
|
248 |
mTestPrivate->MrccatoCommand(ERemConCoreApiVolumeDown, ERemConCoreApiButtonClick);
|
|
249 |
QCOMPARE(CRemConCoreApiTarget::getSendResponseCount(), oldCount+1);
|
|
250 |
QCOMPARE( mTestPrivate->iMpEngine->iMediaCommandReceived, CmdDecreaseVolume );
|
|
251 |
QVERIFY( mTestPrivate->iSideKeyAlreadyClicked );
|
|
252 |
QTest::qWait(100);
|
|
253 |
|
|
254 |
// Simulate holding the hardware side key.
|
|
255 |
mTestPrivate->iMpEngine->iMediaCommandReceived = CmdNone;
|
|
256 |
mTestPrivate->MrccatoCommand(ERemConCoreApiVolumeDown, ERemConCoreApiButtonPress);
|
|
257 |
QCOMPARE(CRemConCoreApiTarget::getSendResponseCount(), oldCount+2);
|
|
258 |
QCOMPARE( mTestPrivate->iMpEngine->iMediaCommandReceived, CmdNone );
|
|
259 |
QVERIFY( mTestPrivate->iSideKeyAlreadyClicked );
|
|
260 |
QTest::qWait(100);
|
|
261 |
|
|
262 |
// Release hardware side key.
|
|
263 |
mTestPrivate->MrccatoCommand(ERemConCoreApiVolumeDown, ERemConCoreApiButtonRelease);
|
|
264 |
QCOMPARE(CRemConCoreApiTarget::getSendResponseCount(), oldCount+3);
|
|
265 |
QCOMPARE( mTestPrivate->iMpEngine->iMediaCommandReceived, CmdNone );
|
|
266 |
QVERIFY( !mTestPrivate->iSideKeyAlreadyClicked );
|
|
267 |
QTest::qWait(100);
|
|
268 |
|
|
269 |
// Simulate headset volume key pressed.
|
|
270 |
mTestPrivate->MrccatoCommand(ERemConCoreApiVolumeDown, ERemConCoreApiButtonPress);
|
|
271 |
QCOMPARE(CRemConCoreApiTarget::getSendResponseCount(), oldCount+4);
|
|
272 |
QCOMPARE( mTestPrivate->iMpEngine->iMediaCommandReceived, CmdDecreaseVolume );
|
|
273 |
QVERIFY( mTestPrivate->iSideKeyAlreadyClicked );
|
|
274 |
}
|
|
275 |
|
|
276 |
void TestMpMediaKeyHandler::testPlay()
|
|
277 |
{
|
|
278 |
int oldCount = CRemConCoreApiTarget::getSendResponseCount();
|
|
279 |
mTestPrivate->MrccatoPlay(ERemConCoreApiPlaybackSpeedX1, ERemConCoreApiButtonClick);
|
|
280 |
QCOMPARE(CRemConCoreApiTarget::getSendResponseCount(), oldCount+1);
|
|
281 |
QCOMPARE( mTestPrivate->iMpEngine->iMediaCommandReceived, CmdPlay );
|
|
282 |
}
|
|
283 |
|
|
284 |
void TestMpMediaKeyHandler::testTuneFunction()
|
|
285 |
{
|
|
286 |
int oldCount = CRemConCoreApiTarget::getSendResponseCount();
|
|
287 |
mTestPrivate->MrccatoTuneFunction(ETrue, 0, 1, ERemConCoreApiButtonClick);
|
|
288 |
QCOMPARE(CRemConCoreApiTarget::getSendResponseCount(), oldCount+1);
|
|
289 |
QCOMPARE( mTestPrivate->iMpEngine->iMediaCommandReceived, CmdNone );
|
|
290 |
}
|
|
291 |
|
|
292 |
void TestMpMediaKeyHandler::testSelectDiskFunction()
|
|
293 |
{
|
|
294 |
int oldCount = CRemConCoreApiTarget::getSendResponseCount();
|
|
295 |
mTestPrivate->MrccatoSelectDiskFunction(0, ERemConCoreApiButtonClick);
|
|
296 |
QCOMPARE(CRemConCoreApiTarget::getSendResponseCount(), oldCount+1);
|
|
297 |
QCOMPARE( mTestPrivate->iMpEngine->iMediaCommandReceived, CmdNone );
|
|
298 |
}
|
|
299 |
|
|
300 |
void TestMpMediaKeyHandler::testAudioInputFunction()
|
|
301 |
{
|
|
302 |
int oldCount = CRemConCoreApiTarget::getSendResponseCount();
|
|
303 |
mTestPrivate->MrccatoSelectAudioInputFunction(0, ERemConCoreApiButtonClick);
|
|
304 |
QCOMPARE(CRemConCoreApiTarget::getSendResponseCount(), oldCount+1);
|
|
305 |
QCOMPARE( mTestPrivate->iMpEngine->iMediaCommandReceived, CmdNone );
|
|
306 |
}
|
|
307 |
|
|
308 |
void TestMpMediaKeyHandler::testSelectAvInputFunction()
|
|
309 |
{
|
|
310 |
int oldCount = CRemConCoreApiTarget::getSendResponseCount();
|
|
311 |
mTestPrivate->MrccatoSelectAvInputFunction(0, ERemConCoreApiButtonClick);
|
|
312 |
QCOMPARE(CRemConCoreApiTarget::getSendResponseCount(), oldCount+1);
|
|
313 |
QCOMPARE( mTestPrivate->iMpEngine->iMediaCommandReceived, CmdNone );
|
|
314 |
}
|
|
315 |
|
|
316 |
// End of file
|