Update contrib.
1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // TSIMmfCtlfrmStep.cpp
21 // Test system includes
22 #include <testframework.h>
23 #include "TSI_MmfCtlfrmStep.h"
24 #include "TSI_MmfCtlfrmSuite.h"
25 #include "TSI_MmfCodes.h"
26 #include "TSI_MmfEventIds.h"
27 #include "ActrlTestUids.h"
29 #include <mmf/common/mmfcontroller.h>
30 #include <mmf/plugin/mmfcontrollerimplementationuids.hrh>
32 const TUid KTestControllerUid = {KTSIMmfControllerUid};
33 const TUid KTestController2Uid = {KTSIMmfController2Uid};
34 //const TUid KTestDataSourceUid = {KTSIMmfDataSourceUid};
35 //const TUid KTestDataSinkUid = {KTSIMmfDataSinkUid};
37 // audio controller, from mmfControllerImplementationUIDs.hrh
38 //const TUid KTestAudioControllerUid = {KMmfUidControllerAudio};
40 // event values for audio controller testing
41 const TInt KDelay = 1000000;
42 const TInt KMaxRetries = 12;
45 // ---------------------------
49 RTestStepMmfCtlfrm::RTestStepMmfCtlfrm()
53 // ---------------------------
54 // RTestStepMmfCtlfrmTest1
55 // base class with preamble / postamble to open and close the test controller
57 TVerdict RTestStepMmfCtlfrmTest1::OpenL()
59 TInt error = KErrNone;
61 iSettings.iPriority = ETSIMmfPriorityLow;
62 iSettings.iPref = EMdaPriorityPreferenceTime;
63 iSettings.iState = EMMFStateIdle;
66 error = iController.Open(KTestControllerUid, iSettings);
69 ERR_PRINTF2(_L("controller failed to open, error %d"), error);
70 return iTestStepResult = EInconclusive;
73 return iTestStepResult = EPass;
76 void RTestStepMmfCtlfrmTest1::Close()
80 // close controller delay - ensure it has time to finish
81 // (so we don't get access violation from something trying to dequeue it before it's closed)
82 const TTimeIntervalMicroSeconds32 KCloseControllerDelay = 500000L;
83 User::After(KCloseControllerDelay);
86 // ---------------------------
87 // RTestStepMmfCtlfrmTest2
88 // base class with preamble / postamble to open and close the test controller 2
90 TVerdict RTestStepMmfCtlfrmTest2::OpenL()
92 TInt error = KErrNone;
94 iSettings.iPriority = ETSIMmfPriorityLow;
95 iSettings.iPref = EMdaPriorityPreferenceTime;
96 iSettings.iState = EMMFStateIdle;
99 error = iController.Open(KTestController2Uid, iSettings);
102 ERR_PRINTF2(_L("controller failed to open, error %d"), error);
103 return iTestStepResult = EInconclusive;
106 return iTestStepResult = EPass;
109 void RTestStepMmfCtlfrmTest2::Close()
112 // close controller delay - ensure it has time to finish
113 // (so we don't get access violation from something trying to dequeue it before it's closed)
114 const TTimeIntervalMicroSeconds32 KCloseControllerDelay = 500000L;
115 User::After(KCloseControllerDelay);
118 // ---------------------------
119 // RTestStepMmfCtlfrmAudio
120 // base class with preamble / postamble to open and close the audio controller
122 TVerdict RTestStepMmfCtlfrmAudio::OpenL()
124 TInt error = KErrNone;
126 iSettings.iPriority = ETSIMmfPriorityHigh;
127 iSettings.iPref = EMdaPriorityPreferenceQuality;
128 iSettings.iState = EMMFStateIdle;
131 error = iController.Open(KUidCustomTestAudioPlugin, iSettings);
132 // error = iController.Open(KTestAudioControllerUid, iSettings);
135 ERR_PRINTF2(_L("controller failed to open, error %d"), error);
136 return iTestStepResult = EInconclusive;
139 INFO_PRINTF2(_L("Opened Custom Audio Controller, UID 0x%8x"), KUidCustomTestAudioPlugin);
140 // Add a source and sink
141 _LIT(KTestWavFile, "c:\\TsiMmfCtlfrmData\\test.wav");
142 iFileConfig().iPath = KTestWavFile;
143 error = iController.AddDataSource(KUidMmfFileSource, iFileConfig);
146 ERR_PRINTF2(_L("failed to add a data source, error %d"), error);
148 return iTestStepResult = EInconclusive;
150 error = iController.AddDataSink(KUidMmfAudioOutput, KNullDesC8);
153 ERR_PRINTF2(_L("failed to add a data sink, error %d"), error);
155 return iTestStepResult = EInconclusive;
158 return iTestStepResult = EPass;
161 void RTestStepMmfCtlfrmAudio::Close()
166 // close controller delay - ensure it has time to finish
167 // (so we don't get access violation from something trying to dequeue it before it's closed)
168 const TTimeIntervalMicroSeconds32 KCloseControllerDelay = 500000L;
169 User::After(KCloseControllerDelay);
172 // Searches for an event
173 TVerdict RTestStepMmfCtlfrmAudio::SearchForEvent( TMMFEvent& aEvent )
175 #ifdef EVENT_SEARCH_DISABLED
176 WARN_PRINTF1(_L("Warning : SearchForEvent disabled"));
177 TMMFEvent dummyEvent; // JS
178 aEvent = dummyEvent; // to get rid of compiler warning
182 TVerdict result = EFail;
185 TRequestStatus timerStatus;
186 TRequestStatus eventStatus;
188 // due to problems with the timer as a member variable
189 // added a local timer here
191 myTimer.CreateLocal();
193 // create an event and initialise with unknown marker
195 TMMFEventPckg receivedEvent;
197 // for KMaxRetries attempt to find the event
198 for( TInt retries = 0; retries < KMaxRetries; retries++ )
200 // post receive event to controller
201 iController.ReceiveEvents( receivedEvent, eventStatus );
202 // start breakout timer to escape
203 myTimer.After(timerStatus, KDelay);
205 // wait for an event to mature
206 User::WaitForRequest( eventStatus, timerStatus );
208 // check if the command is the event
209 // and that a timeout did not occur
210 if( IsTimeOut( eventStatus ))
212 // cancel the receive events
213 CancelReceivedEvents();
215 else if( IsSoughtEvent( aEvent, receivedEvent ) )
217 // cancel the outstanding timer
220 // set status to pass since we have found the event
226 // We rx'd an event other than expected
231 #endif // EVENT_SEARCH_DISABLED
234 TBool RTestStepMmfCtlfrmAudio::IsTimeOut( TRequestStatus& aEventStatus )
236 return ( aEventStatus == KRequestPending);
239 TBool RTestStepMmfCtlfrmAudio::IsSoughtEvent( TMMFEvent& aExpectedEvent, TMMFEventPckg& aReceivedEvent )
242 TInt expectedUid = aExpectedEvent.iEventType.iUid;
243 TInt receivedUid = aReceivedEvent().iEventType.iUid;
245 // display any events we get
246 INFO_PRINTF3(_L("Event received : 0x%08x %d"),
247 aReceivedEvent().iEventType.iUid, aReceivedEvent().iErrorCode);
249 return ((expectedUid == receivedUid) &&
250 (aExpectedEvent.iErrorCode == aReceivedEvent().iErrorCode));
253 void RTestStepMmfCtlfrmAudio::CancelReceivedEvents()
255 iController.CancelReceiveEvents();
258 // ---------------------------
259 // RTestStepMmfCtlfrmAudioPrimed
260 // as above, with source / sink handles, primed in preamble
262 TVerdict RTestStepMmfCtlfrmAudioPrimed::OpenL()
264 // initialise the controller, including adding source and sink; prime it.
265 // retain handles to the source and sink so we can verify them after reset
266 TInt error = KErrNone;
267 TVerdict result = EPass;
269 iSourceHandlePtr = NULL;
270 iSinkHandlePtr = NULL;
272 iSettings.iPriority = ETSIMmfPriorityHigh;
273 iSettings.iPref = EMdaPriorityPreferenceQuality;
274 iSettings.iState = EMMFStateIdle;
277 error = iController.Open(KUidCustomTestAudioPlugin, iSettings);
280 ERR_PRINTF2(_L("controller failed to open, error %d"), error);
281 return iTestStepResult = EInconclusive;
284 INFO_PRINTF2(_L("Opened Custom Audio Controller, UID 0x%8x"), KUidCustomTestAudioPlugin);
285 // Add a source and sink
286 _LIT(KTestWavFile, "c:\\TsiMmfCtlfrmData\\test.wav");
287 iFileConfig().iPath = KTestWavFile;
289 // add a data source with a handle
290 iSourceHandlePtr = new (ELeave) TMMFMessageDestination();
291 TMMFMessageDestination& sourceHandle = *iSourceHandlePtr;
292 error = iController.AddDataSource(KUidMmfFileSource, iFileConfig, sourceHandle);
295 ERR_PRINTF2(_L("AddDataSource failed, error %d"), error);
297 return iTestStepResult = EInconclusive;
300 // add a data sink with a handle
301 iSinkHandlePtr = new (ELeave) TMMFMessageDestination();
302 TMMFMessageDestination& sinkHandle = *iSinkHandlePtr;
304 error = iController.AddDataSink(KUidMmfAudioOutput, KNullDesC8, sinkHandle);
307 ERR_PRINTF2(_L("AddDataSink failed, error %d"), error);
309 return iTestStepResult = EInconclusive;
313 error = iController.Prime();
316 ERR_PRINTF2(_L("Prime failed, error %d"), error);
318 return iTestStepResult = EInconclusive;
321 // wait for and process the return event from the custom audio controller
322 TMMFEvent primeEvent( KPrimeTestId, KErrNone);
323 result = SearchForEvent( primeEvent );
324 if( result == EFail )
326 ERR_PRINTF1(_L("Custom audio controller did not return a prime event"));
328 return iTestStepResult = EInconclusive;
331 return iTestStepResult = EPass;
334 void RTestStepMmfCtlfrmAudioPrimed::Close()
338 delete iSinkHandlePtr;
339 delete iSourceHandlePtr;
341 // close controller delay - ensure it has time to finish
342 // (so we don't get access violation from something trying to dequeue it before it's closed)
343 const TTimeIntervalMicroSeconds32 KCloseControllerDelay = 500000L;
344 User::After(KCloseControllerDelay);
348 // ---------------------------
349 // RTestStepMmfCtlfrmAudioNoSource
350 // same as RTestStepMmfCtlfrmAudio, but has no source or sink loaded yet
351 TVerdict RTestStepMmfCtlfrmAudioNoSource::OpenL()
353 // preamble - load a controller but give it no data source
354 TInt error = KErrNone;
356 iSettings.iPriority = ETSIMmfPriorityHigh;
357 iSettings.iPref = EMdaPriorityPreferenceQuality;
358 iSettings.iState = EMMFStateIdle;
361 error = iController.Open(KUidCustomTestAudioPlugin, iSettings);
364 ERR_PRINTF2(_L("controller failed to open, error %d"), error);
365 return iTestStepResult = EInconclusive;
368 INFO_PRINTF2(_L("Opened Custom Audio Controller, UID 0x%8x"), KUidCustomTestAudioPlugin);
369 return iTestStepResult = EPass;
372 // ---------------------------
373 // RTestStepMmfCtlfrmDualAudio
374 // same as RTestStepMmfCtlfrmAudio, with 2 identical controllers
376 TVerdict RTestStepMmfCtlfrmDualAudio::OpenL()
378 TInt error = KErrNone;
380 iSettings.iPriority = ETSIMmfPriorityHigh;
381 iSettings.iPref = EMdaPriorityPreferenceTime;
382 iSettings.iState = EMMFStateIdle;
384 // Open both controllers
385 error = iController1.Open(KUidCustomTestAudioPlugin, iSettings);
388 ERR_PRINTF2(_L("iController1 failed to open, error %d"), error);
389 return iTestStepResult = EInconclusive;
391 INFO_PRINTF2(_L("Controller 1 : Opened Custom Audio Controller, UID 0x%8x"), KUidCustomTestAudioPlugin);
392 error = iController2.Open(KUidCustomTestAudioPlugin, iSettings);
395 ERR_PRINTF2(_L("iController2 failed to open, error %d"), error);
397 return iTestStepResult = EInconclusive;
399 INFO_PRINTF2(_L("Controller 2 : Opened Custom Audio Controller, UID 0x%8x"), KUidCustomTestAudioPlugin);
401 // Add source and sink
402 // Use two different files to avoid conflict
403 _LIT(KTestWavFile1, "c:\\TsiMmfCtlfrmData\\test.wav");
404 _LIT(KTestWavFile2, "c:\\TsiMmfCtlfrmData\\test2.wav");
405 iFileConfig1().iPath = KTestWavFile1;
406 iFileConfig2().iPath = KTestWavFile2;
407 error = iController1.AddDataSource(KUidMmfFileSource, iFileConfig1);
410 ERR_PRINTF2(_L("iController1 failed to add a data source, error %d"), error);
411 return iTestStepResult = EInconclusive;
413 error = iController1.AddDataSink(KUidMmfAudioOutput, KNullDesC8);
416 ERR_PRINTF2(_L("iController1 failed to add a data sink, error %d"), error);
418 return iTestStepResult = EInconclusive;
420 error = iController2.AddDataSource(KUidMmfFileSource, iFileConfig2);
423 ERR_PRINTF2(_L("iController2 failed to add a data source, error %d"), error);
425 return iTestStepResult = EInconclusive;
427 error = iController2.AddDataSink(KUidMmfAudioOutput, KNullDesC8);
430 ERR_PRINTF2(_L("iController2 failed to add a data sink, error %d"), error);
432 return iTestStepResult = EInconclusive;
435 return iTestStepResult = EPass;
438 void RTestStepMmfCtlfrmDualAudio::Close()
441 iController1.Reset();
442 iController1.Close();
445 iController2.Reset();
446 iController2.Close();
448 // close controller delay - ensure it has time to finish
449 // (so we don't get access violation from something trying to dequeue it before it's closed)
450 const TTimeIntervalMicroSeconds32 KCloseControllerDelay = 500000L;
451 User::After(KCloseControllerDelay);
454 // Searches for an event
455 TVerdict RTestStepMmfCtlfrmDualAudio::SearchForEvent( TMMFEvent& aEvent, TInt aWhichController )
457 // NB don't worry about EVENT_SEARCH_DISABLED here,
458 // as generally we'll be looking for events from the Controller Framework here,
459 // not from the custom Audio Controller
461 TVerdict result = EFail;
464 TRequestStatus timerStatus ;
465 TRequestStatus eventStatus ;
467 RMMFController* theController;
468 // which controller are we searching on?
469 if(aWhichController == 1)
470 theController = &iController1;
471 else if(aWhichController == 2)
472 theController = &iController2;
475 ERR_PRINTF1(_L("SearchForEvent error : controller must be 1 or 2"));
476 return result = EFail;
479 // due to problems with the timer as a member variable
480 // added a local timer here
482 myTimer.CreateLocal();
484 // create an event and initialise with unknown marker
486 TMMFEventPckg receivedEvent;
488 // for KMaxRetries attempt to find the event
489 for( TInt retries = 0; retries < KMaxRetries; retries++ )
491 // post receive event to controller
492 (*theController).ReceiveEvents( receivedEvent, eventStatus );
493 // start breakout timer to escape
494 myTimer.After( timerStatus, KDelay );
496 // wait for an event to mature
497 User::WaitForRequest( eventStatus, timerStatus );
499 // check if the command is the event
500 // and that a timeout did not occur
501 if( IsTimeOut( eventStatus ))
503 // cancel the receive events
504 CancelReceivedEvents(aWhichController);
506 else if( IsSoughtEvent( aEvent, receivedEvent ) )
508 // cancel the outstanding timer
511 // set status to pass since we have found the event
517 // We rx'd an event other than expected
524 TBool RTestStepMmfCtlfrmDualAudio::IsTimeOut( TRequestStatus& aEventStatus )
526 return (aEventStatus == KRequestPending);
529 TBool RTestStepMmfCtlfrmDualAudio::IsSoughtEvent( TMMFEvent& aExpectedEvent, TMMFEventPckg& aReceivedEvent )
532 TInt expectedUid = aExpectedEvent.iEventType.iUid;
533 TInt receivedUid = aReceivedEvent().iEventType.iUid;
535 // display any events we get
536 INFO_PRINTF3(_L("Event expected : 0x%08x %d"),
537 expectedUid, aExpectedEvent.iErrorCode);
538 INFO_PRINTF3(_L("Event received : 0x%08x %d"),
539 aReceivedEvent().iEventType.iUid, aReceivedEvent().iErrorCode);
541 return ((expectedUid == receivedUid) &&
542 (aExpectedEvent.iErrorCode == aReceivedEvent().iErrorCode));
545 void RTestStepMmfCtlfrmDualAudio::CancelReceivedEvents(TInt aWhichController)
547 RMMFController* theController;
548 // which controller are we searching on?
549 if(aWhichController == 1)
550 theController = &iController1;
551 else if(aWhichController == 2)
552 theController = &iController2;
555 ERR_PRINTF1(_L("CancelReceivedEvents error : controller must be 1 or 2"));
558 (*theController).CancelReceiveEvents();
561 // ---------------------------
562 // RTestStepMmfCtlfrmVideo
563 // base class with preamble / postamble to open and close the video controller
564 // NB we're only actually using this to test custom commands
566 TVerdict RTestStepMmfCtlfrmVideo::OpenL()
568 TInt error = KErrNone;
570 iSettings.iPriority = ETSIMmfPriorityHigh;
571 iSettings.iPref = EMdaPriorityPreferenceQuality;
572 iSettings.iState = EMMFStateIdle;
575 error = iController.Open(KMmfVideoTestControllerUid, iSettings);
578 ERR_PRINTF2(_L("controller failed to open, error %d"), error);
579 return iTestStepResult = EInconclusive;
582 INFO_PRINTF2(_L("Opened Custom Video Controller, UID 0x%8x"), KMmfVideoTestControllerUid);
583 // Add a source and sink
584 _LIT(KTestAviFile, "c:\\VclntITestData\\LongVideo.avi");
585 iFileConfig().iPath = KTestAviFile;
586 error = iController.AddDataSource(KUidMmfFileSource, iFileConfig);
589 ERR_PRINTF2(_L("failed to add a data source, error %d"), error);
591 return iTestStepResult = EInconclusive;
593 error = iController.AddDataSink(KUidMmfAudioOutput, KNullDesC8);
596 ERR_PRINTF2(_L("failed to add a data sink, error %d"), error);
598 return iTestStepResult = EInconclusive;
601 return iTestStepResult = EPass;
604 void RTestStepMmfCtlfrmVideo::Close()
609 // close controller delay - ensure it has time to finish
610 // (so we don't get access violation from something trying to dequeue it before it's closed)
611 const TTimeIntervalMicroSeconds32 KCloseControllerDelay = 500000L;
612 User::After(KCloseControllerDelay);