Update contrib.
1 // Copyright (c) 2005-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.
16 #include <testframework.h>
18 #include "TSU_MMFMIDICLNT.h"
19 #include "TS_MMFMIDICLNTsuite.h"
21 #include "TestMidiClientUtility.h"
23 _LIT(KDrmSectName, "SectionDRM");
24 _LIT(KDrmFileKey, "MidiDrmContent");
26 const TInt K1Second =1000000;
27 const TInt K5Seconds = 5 * K1Second;
28 const TInt K30Seconds =30 * K1Second;
30 class CCallbackTimer : public CTimer
33 static CCallbackTimer* NewL();
35 void SetCb(TCallBack aCallback)
37 iCallback = aCallback;
39 void After(TTimeIntervalMicroSeconds32 aCancelDelay)
41 CTimer::After(aCancelDelay);
43 void After(TTimeIntervalMicroSeconds32 aCancelDelay, TCallBack aCallback);
54 CCallbackTimer* CCallbackTimer::NewL()
56 CCallbackTimer* self=new (ELeave) CCallbackTimer();
57 CleanupStack::PushL(self);
63 CCallbackTimer::CCallbackTimer():CTimer(EPriorityHigh)
65 CActiveScheduler::Add(this);
68 CCallbackTimer::~CCallbackTimer()
74 void CCallbackTimer::After(TTimeIntervalMicroSeconds32 aCancelDelay, TCallBack aCallback)
76 iCallback = aCallback;
77 CTimer::After(aCancelDelay);
85 void CCallbackTimer::RunL()
92 CTestStepDrm::CTestStepDrm(const TDesC& aTestName, const TTestStepType aTestType, const TDrmTestParams& aDrmParams):
93 CTestMmfMidiClntStep(aTestName, aTestType),
94 iDrmParams(aDrmParams)
98 TVerdict CTestStepDrm::DoTestStepPreambleL()
100 if (EPass==CTestMmfMidiClntStep::DoTestStepPreambleL())
102 iTimer = CCallbackTimer::NewL();
103 iTimer->SetCb(TCallBack(TimerGate, this));
104 User::LeaveIfError( iFs.Connect() );
110 TVerdict CTestStepDrm::DoTestStepPostambleL()
117 return CTestMmfMidiClntStep::DoTestStepPostambleL();
120 TVerdict CTestStepDrm::DoTestStepL()
122 if (iDrmParams.iTestMode != TDrmTestParams::EAlloc)
124 return CTestMmfMidiClntStep::DoTestStepL();
126 TVerdict result=EPass;
128 TBool completed = EFalse;
129 CMidiClientUtility* midiClnt = NULL;
134 __UHEAP_SETFAIL(RHeap::EFailNext ,failCount);
138 midiClnt = CMidiClientUtility::NewL(*this);
139 result=DoTestL(midiClnt);
146 TAny *testAlloc = User::Alloc(1); // when this fails, we passed through all allocs within test
154 User::Free(testAlloc);
157 else if (err != KErrNoMemory) // bad error code
177 TInt CTestStepDrm::TimerGate(TAny* aPtr)
179 reinterpret_cast<CTestStepDrm*>(aPtr)->OnTimer();
183 void CTestStepDrm::OnTimer()
186 CActiveScheduler::Stop();
187 iError = KErrTimedOut;
190 TVerdict CTestStepDrm::OpenFileL(CMidiClientUtility* aMidi)
193 if (iDrmParams.iFileNameKey==NULL)
195 if(!GetStringFromConfig(KDrmSectName,KDrmFileKey,fileName))
197 return EInconclusive;
202 if(!GetStringFromConfig(KDrmSectName,TPtrC(iDrmParams.iFileNameKey), fileName))
204 return EInconclusive;
207 if (iDrmParams.iSourceType==TDrmTestParams::EFileName)
209 TPtrC uniqueId(ContentAccess::KDefaultContentObject);
210 if (iDrmParams.iUniqueId)
212 uniqueId.Set(TPtrC(iDrmParams.iUniqueId));
214 if (iDrmParams.iUniqueId==NULL && iDrmParams.iIntent==TDrmTestParams::KNoIntent)
216 aMidi->OpenFile(TMMFileSource(fileName));
218 else if (iDrmParams.iIntent==TDrmTestParams::KNoIntent)
220 aMidi->OpenFile(TMMFileSource(fileName, uniqueId));
224 aMidi->OpenFile(TMMFileSource(fileName, uniqueId, iDrmParams.iIntent));
230 User::LeaveIfError( iFs.ShareProtected() );
231 User::LeaveIfError( iFile.Open(iFs, fileName, EFileRead | EFileShareExclusive) );
233 TPtrC uniqueId(ContentAccess::KDefaultContentObject);
234 if (iDrmParams.iUniqueId)
236 uniqueId.Set(TPtrC(iDrmParams.iUniqueId));
238 if (iDrmParams.iUniqueId==NULL && iDrmParams.iIntent==TDrmTestParams::KNoIntent)
240 aMidi->OpenFile(TMMFileHandleSource(iFile));
242 else if (iDrmParams.iIntent==TDrmTestParams::KNoIntent)
244 aMidi->OpenFile(TMMFileHandleSource(iFile, uniqueId));
248 aMidi->OpenFile(TMMFileHandleSource(iFile, uniqueId, iDrmParams.iIntent));
257 CTestDrmNegative* CTestDrmNegative::NewL(const TDesC& aTestName, const TTestStepType aTestType, const TDrmTestParams& aDrmParams)
259 return new (ELeave) CTestDrmNegative(aTestName, aTestType, aDrmParams);
262 CTestDrmNegative::CTestDrmNegative(const TDesC& aTestName, const TTestStepType aTestType, const TDrmTestParams& aDrmParams):
263 CTestStepDrm(aTestName, aTestType, aDrmParams)
267 void CTestDrmNegative::MmcuoStateChanged(TMidiState /*aOldState*/,TMidiState /*aNewState*/, const TTimeIntervalMicroSeconds& /*aTime*/,TInt aError)
270 CActiveScheduler::Stop();
273 TVerdict CTestDrmNegative::DoTestL(CMidiClientUtility* aMidi)
275 iTimer->After( TTimeIntervalMicroSeconds32(K5Seconds) );
276 TVerdict result=OpenFileL(aMidi);
282 CActiveScheduler::Start();
284 if (iError!=iDrmParams.iExpectedError)
287 ERR_PRINTF3(_L("Open() gave error %d (expected %d)"),iError, iDrmParams.iExpectedError);
295 CTestDrmPlay* CTestDrmPlay::NewL(const TDesC& aTestName, const TTestStepType aTestType, const TDrmTestParams& aDrmParams)
297 return new (ELeave) CTestDrmPlay(aTestName, aTestType, aDrmParams);
300 CTestDrmPlay::CTestDrmPlay(const TDesC& aTestName, const TTestStepType aTestType, const TDrmTestParams& aDrmParams):
301 CTestStepDrm(aTestName, aTestType, aDrmParams)
305 void CTestDrmPlay::MmcuoStateChanged(TMidiState /*aOldState*/,TMidiState aNewState, const TTimeIntervalMicroSeconds& /*aTime*/,TInt aError)
308 iLatestState= aNewState;
309 CActiveScheduler::Stop();
312 TVerdict CTestDrmPlay::PlayL(CMidiClientUtility* aMidi, TTimeIntervalMicroSeconds32 aStopAfter)
315 iTimer->After(aStopAfter);
317 TVerdict result=OpenFileL(aMidi);
323 CActiveScheduler::Start();
324 User::LeaveIfError(iError);
327 CActiveScheduler::Start();
328 User::LeaveIfError(iError);
329 if (iLatestState != EMidiStateOpenPlaying)
332 ERR_PRINTF3(_L("Play() got state %d (expected %d)"),iLatestState, EMidiStateOpenPlaying);
336 CActiveScheduler::Start();
339 if (iError==KErrNoMemory && iDrmParams.iTestMode==TDrmTestParams::EAlloc)
347 TVerdict CTestDrmPlay::DoTestL(CMidiClientUtility* aMidi)
350 TInt i=iDrmParams.iNumPlayLoops > 0 ? iDrmParams.iNumPlayLoops : 1;
351 for (; i && res==EPass && iError==KErrNone; --i)
354 res=PlayL(aMidi, TTimeIntervalMicroSeconds32(K30Seconds));
357 if (iError==KErrNoMemory && iDrmParams.iTestMode==TDrmTestParams::EAlloc)
363 res=(i==0 && iDrmParams.iExpectedError==iError)? EPass : EFail;
366 if (iError!=iDrmParams.iExpectedError)
368 ERR_PRINTF4(_L("Play() gave error %d (expected %d) loops left=%d"),iError, iDrmParams.iExpectedError, i);
374 ***** Play() -> Stop()
376 CTestDrmPlayStop* CTestDrmPlayStop::NewL(const TDesC& aTestName, const TTestStepType aTestType, const TDrmTestParams& aDrmParams)
378 return new (ELeave) CTestDrmPlayStop(aTestName, aTestType, aDrmParams);
382 CTestDrmPlayStop::CTestDrmPlayStop(const TDesC& aTestName, const TTestStepType aTestType, const TDrmTestParams& aDrmParams):
383 CTestDrmPlay(aTestName, aTestType, aDrmParams)
387 void CTestDrmPlayStop::OnTimer()
389 if (iLatestState != EMidiStateOpenPlaying || iStopping)
391 iError = KErrGeneral;
392 CActiveScheduler::Stop();
393 ERR_PRINTF3(_L("CTestDrmPlayStop::OnTimer() got err %d stopping %d"),iError, iStopping);
397 iMidi->Stop(TTimeIntervalMicroSeconds(100000));
399 iTimer->After(K5Seconds);
403 TVerdict CTestDrmPlayStop::DoTestL(CMidiClientUtility* aMidi)
406 TVerdict res=PlayL(aMidi, TTimeIntervalMicroSeconds32(K5Seconds));
412 return iError==iDrmParams.iExpectedError ? EPass : EFail;
416 ***** Play() -> Stop()
420 CTestDrmPlayWithUI* CTestDrmPlayWithUI::NewL(const TDesC& aTestName, const TTestStepType aTestType, const TDrmTestParams& aDrmParams)
422 return new (ELeave) CTestDrmPlayWithUI(aTestName, aTestType, aDrmParams);
425 CTestDrmPlayWithUI::CTestDrmPlayWithUI(const TDesC& aTestName, const TTestStepType aTestType, const TDrmTestParams& aDrmParams):
426 CTestStepDrm(aTestName, aTestType, aDrmParams)
430 void CTestDrmPlayWithUI::MmcuoStateChanged(TMidiState /*aOldState*/,TMidiState aNewState, const TTimeIntervalMicroSeconds& /*aTime*/,TInt aError)
433 iLatestState= aNewState;
434 CActiveScheduler::Stop();
437 TVerdict CTestDrmPlayWithUI::PlayL(CMidiClientUtility* aMidi, TTimeIntervalMicroSeconds32 aStopAfter)
440 iTimer->After(aStopAfter);
442 TVerdict result=OpenFileL(aMidi);
448 CActiveScheduler::Start();
449 User::LeaveIfError(iError);
451 MMMFDRMCustomCommand* cmd=aMidi->GetDRMCustomCommand();
454 ERR_PRINTF1(_L("GetDRMCustomCommand() returned NULL"));
457 iError=cmd->SetAgentProperty(ContentAccess::EAgentPropertyAgentUI, ETrue);
458 // The test agent should return KErrCANotSupported...
459 if (iError != KErrCANotSupported)
461 ERR_PRINTF2(_L("SetAgentProperty() Error=%d"),iError);
466 // ..it has, so flag that there's no error!
469 User::LeaveIfError(iError);
472 CActiveScheduler::Start();
473 User::LeaveIfError(iError);
475 if (iLatestState != EMidiStateOpenPlaying)
478 ERR_PRINTF3(_L("Play() got state %d (expected %d)"),iLatestState, EMidiStateOpenPlaying);
482 CActiveScheduler::Start();
485 if (iError==KErrNoMemory && iDrmParams.iTestMode==TDrmTestParams::EAlloc)
493 TVerdict CTestDrmPlayWithUI::DoTestL(CMidiClientUtility* aMidi)
496 TInt i=iDrmParams.iNumPlayLoops > 0 ? iDrmParams.iNumPlayLoops : 1;
497 for (; i && res==EPass; --i)
499 res=PlayL(aMidi, TTimeIntervalMicroSeconds32(K30Seconds));
505 if (iError!=iDrmParams.iExpectedError)
508 ERR_PRINTF3(_L("Play() gave error %d (expected %d)"),iError, iDrmParams.iExpectedError);