Update contrib.
1 // Copyright (c) 2004-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 "rightsdatabase.h"
20 const TInt KDefaultRightsID = 1;
21 const TInt KDefaultRightsCount = 2;
23 const TInt KMaxMimeLength = 256;
27 CTestMmfAclntDRMPlayerNoRights::CTestMmfAclntDRMPlayerNoRights()
29 // store the name of this test case
30 // this is the name that is used by the script file
31 // Each test step initialises it's own name
32 iTestStepName = _L("MM-MMF-ACLNT-I-9000-LP");
36 CTestMmfAclntDRMPlayerNoRights* CTestMmfAclntDRMPlayerNoRights::NewL()
38 CTestMmfAclntDRMPlayerNoRights* self = new (ELeave) CTestMmfAclntDRMPlayerNoRights();
42 CTestMmfAclntDRMPlayerNoRights* CTestMmfAclntDRMPlayerNoRights::NewLC()
44 CTestMmfAclntDRMPlayerNoRights* self = CTestMmfAclntDRMPlayerNoRights::NewL();
45 CleanupStack::PushL(self);
49 void CTestMmfAclntDRMPlayerNoRights::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds &aDuration)
52 iDuration = aDuration;
53 INFO_PRINTF1( _L("MMdaAudioPlayerCallback Init Complete"));
54 CActiveScheduler::Stop();
57 void CTestMmfAclntDRMPlayerNoRights::MapcPlayComplete(TInt aError)
60 INFO_PRINTF1( _L("MMdaAudioPlayerCallback Play Complete"));
61 CActiveScheduler::Stop();
66 /** Load and initialise an audio file.
68 TVerdict CTestMmfAclntDRMPlayerNoRights::DoTestStepL( void )
70 INFO_PRINTF1( _L("TestPlayerUtils : File"));
73 iError = KErrTimedOut;
75 CRightsDatabase* rights = CRightsDatabase::NewL(EFalse); // create new database overwriting current one
76 delete rights; // the database will now be reset and have no entries in it
78 TBuf<KSizeBuf> filename;
80 if(!GetStringFromConfig(_L("SectionDRM"),_L("DRMWavFile"),filename1))
82 GetDriveName(filename);
83 filename.Append(filename1);
85 CMdaAudioPlayerUtility* player = NULL;
86 player = CMdaAudioPlayerUtility::NewFilePlayerL(filename, *this);
89 // Wait for initialisation callback
90 INFO_PRINTF1( _L("Initialise CMdaAudioPlayerUtility"));
91 CActiveScheduler::Start();
93 if (iError == KErrCANoRights)
99 User::After(KOneSecond); // wait for deletion to shut down devsound
102 //--------------------------------------------------------------------------------
107 CTestMmfAclntDRMPlayerRightsCount::CTestMmfAclntDRMPlayerRightsCount()
109 // store the name of this test case
110 // this is the name that is used by the script file
111 // Each test step initialises it's own name
112 iTestStepName = _L("MM-MMF-ACLNT-I-9001-LP");
116 CTestMmfAclntDRMPlayerRightsCount* CTestMmfAclntDRMPlayerRightsCount::NewL()
118 CTestMmfAclntDRMPlayerRightsCount* self = new (ELeave) CTestMmfAclntDRMPlayerRightsCount();
122 CTestMmfAclntDRMPlayerRightsCount* CTestMmfAclntDRMPlayerRightsCount::NewLC()
124 CTestMmfAclntDRMPlayerRightsCount* self = CTestMmfAclntDRMPlayerRightsCount::NewL();
125 CleanupStack::PushL(self);
129 void CTestMmfAclntDRMPlayerRightsCount::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds &aDuration)
132 iDuration = aDuration;
133 INFO_PRINTF1( _L("MMdaAudioPlayerCallback Init Complete"));
134 CActiveScheduler::Stop();
137 void CTestMmfAclntDRMPlayerRightsCount::MapcPlayComplete(TInt aError)
140 INFO_PRINTF1( _L("MMdaAudioPlayerCallback Play Complete"));
141 CActiveScheduler::Stop();
146 /** Load and initialise an audio file.
148 TVerdict CTestMmfAclntDRMPlayerRightsCount::DoTestStepL( void )
150 INFO_PRINTF1( _L("TestPlayerUtils : File"));
151 TVerdict ret = EFail;
153 iError = KErrTimedOut;
155 CRightsDatabase* rights = CRightsDatabase::NewL(EFalse); // create new database overwriting current one
156 CleanupStack::PushL(rights);
157 rights->AddRightsL(KDefaultRightsID,KDefaultRightsCount); // add rights count
158 CleanupStack::PopAndDestroy(rights); // cleanup rights object
160 TBuf<KSizeBuf> filename;
162 if(!GetStringFromConfig(_L("SectionDRM"),_L("DRMWavFile"),filename1))
163 return EInconclusive;
164 GetDriveName(filename);
165 filename.Append(filename1);
167 CMdaAudioPlayerUtility* player = NULL;
168 player = CMdaAudioPlayerUtility::NewFilePlayerL(filename, *this);
171 // Wait for initialisation callback
172 INFO_PRINTF1( _L("Initialise CMdaAudioPlayerUtility"));
173 CActiveScheduler::Start();
176 if (iError == KErrNone && player != NULL)
178 iError = KErrTimedOut;
180 for (TInt i=0;i<KDefaultRightsCount;i++)
184 // Wait for play callback
185 INFO_PRINTF2( _L("Play CMdaAudioPlayerUtility: DRM play number %d"),i);
186 CActiveScheduler::Start();
188 if (iError != KErrNone)
190 INFO_PRINTF2(_L("Unexpected error %d"),iError);
195 if (iError == KErrNone)
199 // Wait for play callback
200 INFO_PRINTF1( _L("Play CMdaAudioPlayerUtility with expired rights"));
201 CActiveScheduler::Start();
203 if (iError != KErrCANoPermission)
205 INFO_PRINTF3(_L("Unexpected error %d, expected %d"),iError,KErrCANoPermission);
209 INFO_PRINTF1(_L("Expected failure: rights denied"));
217 User::After(KOneSecond); // wait for deletion to shut down devsound
221 //----------------------------------------------------------------------------------------
226 CTestMmfAclntDRMRecorderNoRights::CTestMmfAclntDRMRecorderNoRights()
228 // store the name of this test case
229 // this is the name that is used by the script file
230 // Each test step initialises it's own name
231 iTestStepName = _L("MM-MMF-ACLNT-I-9002-LP");
235 CTestMmfAclntDRMRecorderNoRights* CTestMmfAclntDRMRecorderNoRights::NewL()
237 CTestMmfAclntDRMRecorderNoRights* self = new (ELeave) CTestMmfAclntDRMRecorderNoRights();
241 CTestMmfAclntDRMRecorderNoRights* CTestMmfAclntDRMRecorderNoRights::NewLC()
243 CTestMmfAclntDRMRecorderNoRights* self = CTestMmfAclntDRMRecorderNoRights::NewL();
244 CleanupStack::PushL(self);
249 /** Load and initialise an audio file.
251 TVerdict CTestMmfAclntDRMRecorderNoRights::DoTestStepL( void )
253 INFO_PRINTF1( _L("TestRecorderUtils : File"));
254 TVerdict ret = EFail;
256 iError = KErrTimedOut;
258 CRightsDatabase* rights = CRightsDatabase::NewL(EFalse); // create new database overwriting current one
259 delete rights; // the database will now be reset and have no entries in it
261 TBuf<KSizeBuf> filename;
263 if(!GetStringFromConfig(_L("SectionDRM"),_L("DRMWavFile"),filename1))
264 return EInconclusive;
265 GetDriveName(filename);
266 filename.Append(filename1);
268 CMdaAudioRecorderUtility* recorder = CMdaAudioRecorderUtility::NewL(*this);
269 CleanupStack::PushL(recorder);
271 recorder->OpenFileL(filename);
273 // Wait for initialisation callback
274 INFO_PRINTF1( _L("Initialise CMdaAudioRecorderUtility"));
275 CActiveScheduler::Start();
277 if (iError == KErrCANoRights)
282 CleanupStack::PopAndDestroy(recorder);
283 User::After(KOneSecond); // wait for deletion to shut down devsound
288 void CTestMmfAclntDRMRecorderNoRights::MoscoStateChangeEvent(CBase* /*aObject*/, TInt aPreviousState, TInt aCurrentState, TInt aErrorCode)
292 iPreviousState = aPreviousState;
293 iCurrentState = aCurrentState;
295 INFO_PRINTF1( _L("CTestMmfAclntRecord : MMdaObjectStateChangeObserver Callback for CMdaAudioRecorderUtility complete"));
296 INFO_PRINTF4( _L("iError %d iPreviousState %d iCurrentState %d"), iError, iPreviousState, iCurrentState);
297 CActiveScheduler::Stop();
300 //--------------------------------------------------------------------------------
305 CTestMmfAclntDRMRecorderRightsCount::CTestMmfAclntDRMRecorderRightsCount()
307 // store the name of this test case
308 // this is the name that is used by the script file
309 // Each test step initialises it's own name
310 iTestStepName = _L("MM-MMF-ACLNT-I-9003-LP");
314 CTestMmfAclntDRMRecorderRightsCount* CTestMmfAclntDRMRecorderRightsCount::NewL()
316 CTestMmfAclntDRMRecorderRightsCount* self = new (ELeave) CTestMmfAclntDRMRecorderRightsCount();
320 CTestMmfAclntDRMRecorderRightsCount* CTestMmfAclntDRMRecorderRightsCount::NewLC()
322 CTestMmfAclntDRMRecorderRightsCount* self = CTestMmfAclntDRMRecorderRightsCount::NewL();
323 CleanupStack::PushL(self);
327 /** Load and initialise an audio file.
329 TVerdict CTestMmfAclntDRMRecorderRightsCount::DoTestStepL( void )
331 INFO_PRINTF1( _L("TestRecorderUtils : File"));
332 TVerdict ret = EFail;
334 iError = KErrTimedOut;
336 CRightsDatabase* rights = CRightsDatabase::NewL(EFalse); // create new database overwriting current one
337 CleanupStack::PushL(rights);
338 rights->AddRightsL(KDefaultRightsID,KDefaultRightsCount); // add rights count
339 CleanupStack::PopAndDestroy(rights); // cleanup rights object
341 TBuf<KSizeBuf> filename;
343 if(!GetStringFromConfig(_L("SectionDRM"),_L("DRMWavFile"),filename1))
344 return EInconclusive;
345 GetDriveName(filename);
346 filename.Append(filename1);
348 CMdaAudioRecorderUtility* recorder = CMdaAudioRecorderUtility::NewL(*this);
349 CleanupStack::PushL(recorder);
351 recorder->OpenFileL(filename);
353 // Wait for initialisation callback
354 INFO_PRINTF1( _L("Initialise CMdaAudioRecorderUtility"));
355 CActiveScheduler::Start();
358 if (iError == KErrNone && recorder != NULL)
360 iError = KErrTimedOut;
362 for (TInt i=0;i<KDefaultRightsCount;i++)
366 // Wait for play callback
367 INFO_PRINTF2( _L("Play CMdaAudioRecorderUtility: DRM play number %d"),i);
368 CActiveScheduler::Start();
370 if (iError != KErrNone)
372 INFO_PRINTF2(_L("Unexpected error %d"),iError);
377 if (iError == KErrNone)
381 // Wait for play callback
382 INFO_PRINTF1( _L("Play CMdaAudioRecorderUtility with expired rights"));
383 CActiveScheduler::Start();
385 if (iError != KErrCANoPermission)
387 INFO_PRINTF3(_L("Unexpected error %d, expected %d"),iError,KErrCANoPermission);
391 INFO_PRINTF1(_L("Expected failure: rights denied"));
398 CleanupStack::PopAndDestroy(recorder);
399 User::After(KOneSecond); // wait for deletion to shut down devsound
406 void CTestMmfAclntDRMRecorderRightsCount::MoscoStateChangeEvent(CBase* /*aObject*/, TInt aPreviousState, TInt aCurrentState, TInt aErrorCode)
410 iPreviousState = aPreviousState;
411 iCurrentState = aCurrentState;
413 TBool busy = (iCurrentState == CMdaAudioClipUtility::ERecording || iCurrentState == CMdaAudioClipUtility::EPlaying);
414 if (!busy || iError!=KErrNone)
415 CActiveScheduler::Stop();
417 INFO_PRINTF1( _L("CTestMmfAclntRecord : MMdaObjectStateChangeObserver Callback for CMdaAudioRecorderUtility complete"));
418 INFO_PRINTF4( _L("iError %d iPreviousState %d iCurrentState %d"), iError, iPreviousState, iCurrentState);
422 //--------------------------------------------------------------------------------
427 CTestMmfAclntDRMPlayerOpen::CTestMmfAclntDRMPlayerOpen()
429 // store the name of this test case
430 // this is the name that is used by the script file
431 // Each test step initialises it's own name
432 iTestStepName = _L("MM-MMF-ACLNT-I-9004-LP");
436 CTestMmfAclntDRMPlayerOpen* CTestMmfAclntDRMPlayerOpen::NewL()
438 CTestMmfAclntDRMPlayerOpen* self = new (ELeave) CTestMmfAclntDRMPlayerOpen();
442 CTestMmfAclntDRMPlayerOpen* CTestMmfAclntDRMPlayerOpen::NewLC()
444 CTestMmfAclntDRMPlayerOpen* self = CTestMmfAclntDRMPlayerOpen::NewL();
445 CleanupStack::PushL(self);
449 void CTestMmfAclntDRMPlayerOpen::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds &aDuration)
452 iDuration = aDuration;
453 INFO_PRINTF1( _L("MMdaAudioPlayerCallback Init Complete"));
454 CActiveScheduler::Stop();
457 void CTestMmfAclntDRMPlayerOpen::MapcPlayComplete(TInt aError)
460 INFO_PRINTF1( _L("MMdaAudioPlayerCallback Play Complete"));
461 CActiveScheduler::Stop();
464 /** Load and initialise an audio file.
466 TVerdict CTestMmfAclntDRMPlayerOpen::DoTestStepL( void )
468 INFO_PRINTF1( _L("TestPlayerUtils : File"));
469 TVerdict ret = EFail;
471 iError = KErrTimedOut;
473 //fectch MIME type from config file
474 TBuf8<KMaxMimeLength> mimeType;
476 if(!GetStringFromConfig(_L("SectionDRM"),_L("DRMWavMime"),mimeTypePtr))
477 return EInconclusive;
478 mimeType.Copy(mimeTypePtr);
482 TBuf<KSizeBuf> filename;
484 if(!GetStringFromConfig(_L("SectionDRM"),_L("DRMWavFile"),filename1))
485 return EInconclusive;
486 GetDriveName(filename);
487 filename.Append(filename1);
490 CRightsDatabase* rights = CRightsDatabase::NewL(EFalse); // create new database overwriting current one
491 CleanupStack::PushL(rights);
492 rights->AddRightsL(KDefaultRightsID,KDefaultRightsCount,mimeType); // add rights count
493 CleanupStack::PopAndDestroy(rights); // cleanup rights object
495 //create instance of Audio Player, which should try open the file as well
496 CMdaAudioPlayerUtility* player = NULL;
497 TRAP(err, player = CMdaAudioPlayerUtility::NewFilePlayerL(filename, *this));
499 if (iError == KErrNone)//call back OK
501 // Wait for initialisation callback
502 INFO_PRINTF1( _L("Initialise CMdaAudioPlayerUtility"));
503 CActiveScheduler::Start();
507 INFO_PRINTF2(_L("Unexpected error %d"),iError);
513 INFO_PRINTF3(_L("Unexpected error %d, expected %d"),iError,KErrCANoPermission);
517 INFO_PRINTF1(_L("Expected: PASS"));
522 User::After(KOneSecond); // wait for deletion to shut down devsound
526 //--------------------------------------------------------------------------------
531 CTestMmfAclntDRMRecorderPlay::CTestMmfAclntDRMRecorderPlay()
533 // store the name of this test case
534 // this is the name that is used by the script file
535 // Each test step initialises it's own name
536 iTestStepName = _L("MM-MMF-ACLNT-I-9005-LP");
540 CTestMmfAclntDRMRecorderPlay* CTestMmfAclntDRMRecorderPlay::NewL()
542 CTestMmfAclntDRMRecorderPlay* self = new (ELeave) CTestMmfAclntDRMRecorderPlay();
546 CTestMmfAclntDRMRecorderPlay* CTestMmfAclntDRMRecorderPlay::NewLC()
548 CTestMmfAclntDRMRecorderPlay* self = CTestMmfAclntDRMRecorderPlay::NewL();
549 CleanupStack::PushL(self);
553 /** Load and initialise an audio file.
555 TVerdict CTestMmfAclntDRMRecorderPlay::DoTestStepL( void )
557 INFO_PRINTF1( _L("TestRecorderUtils : File"));
558 TVerdict ret = EFail;
560 iError = KErrTimedOut;
562 //fectch MIME type from config file
563 TBuf8<KMaxMimeLength> mimeType;
565 if(!GetStringFromConfig(_L("SectionDRM"),_L("DRMWavMime"),mimeTypePtr))
566 return EInconclusive;
567 mimeType.Copy(mimeTypePtr);
570 CRightsDatabase* rights = CRightsDatabase::NewL(EFalse); // create new database overwriting current one
571 CleanupStack::PushL(rights);
572 rights->AddRightsL(KDefaultRightsID,KDefaultRightsCount,mimeType); // add rights count
573 CleanupStack::PopAndDestroy(rights); // cleanup rights object
576 TBuf<KSizeBuf> filename;
578 if(!GetStringFromConfig(_L("SectionDRM"),_L("DRMWavFile"),filename1))
579 return EInconclusive;
580 GetDriveName(filename);
581 filename.Append(filename1);
583 CMdaAudioRecorderUtility* recorder = CMdaAudioRecorderUtility::NewL(*this);
584 CleanupStack::PushL(recorder);
586 recorder->OpenFileL(filename);
588 // Wait for initialisation callback
589 INFO_PRINTF1( _L("Initialise CMdaAudioRecorderUtility"));
590 CActiveScheduler::Start();
593 if (iError == KErrNone && recorder != NULL)
595 iError = KErrTimedOut;
599 // Wait for play callback
600 INFO_PRINTF1( _L("Play DRM protected file with CMdaAudioRecorderUtility(with sufficient permission)"));
601 CActiveScheduler::Start();
603 if (iError != KErrNone)
605 INFO_PRINTF2(_L("Unexpected error trying to play protected file %d"),iError);
609 INFO_PRINTF1(_L("DRM Protected file played successfully"));
614 CleanupStack::PopAndDestroy(recorder);
615 User::After(KOneSecond); // wait for deletion to shut down devsound
622 void CTestMmfAclntDRMRecorderPlay::MoscoStateChangeEvent(CBase* /*aObject*/, TInt aPreviousState, TInt aCurrentState, TInt aErrorCode)
626 iPreviousState = aPreviousState;
627 iCurrentState = aCurrentState;
629 TBool busy = (iCurrentState == CMdaAudioClipUtility::ERecording || iCurrentState == CMdaAudioClipUtility::EPlaying);
630 if (!busy || iError!=KErrNone)
631 CActiveScheduler::Stop();
633 INFO_PRINTF1( _L("CTestMmfAclntRecord : MMdaObjectStateChangeObserver Callback for CMdaAudioRecorderUtility complete"));
634 INFO_PRINTF4( _L("iError %d iPreviousState %d iCurrentState %d"), iError, iPreviousState, iCurrentState);
639 //--------------------------------------------------------------------------------
644 CTestMmfAclntDRMConverterFail::CTestMmfAclntDRMConverterFail()
646 // store the name of this test case
647 // this is the name that is used by the script file
648 // Each test step initialises it's own name
649 iTestStepName = _L("MM-MMF-ACLNT-I-9006-LP");
653 CTestMmfAclntDRMConverterFail* CTestMmfAclntDRMConverterFail::NewL()
655 CTestMmfAclntDRMConverterFail* self = new (ELeave) CTestMmfAclntDRMConverterFail();
659 CTestMmfAclntDRMConverterFail* CTestMmfAclntDRMConverterFail::NewLC()
661 CTestMmfAclntDRMConverterFail* self = CTestMmfAclntDRMConverterFail::NewL();
662 CleanupStack::PushL(self);
666 /** Load and initialise an audio file.
668 TVerdict CTestMmfAclntDRMConverterFail::DoTestStepL( void )
670 INFO_PRINTF1( _L("TestconverterUtils : File"));
671 TVerdict ret = EFail;
673 iError = KErrTimedOut;
675 //fectch MIME type from config file
676 TBuf8<KMaxMimeLength> mimeType;
678 if(!GetStringFromConfig(_L("SectionDRM"),_L("DRMWavMime"),mimeTypePtr))
679 return EInconclusive;
680 mimeType.Copy(mimeTypePtr);
683 CRightsDatabase* rights = CRightsDatabase::NewL(EFalse); // create new database overwriting current one
684 CleanupStack::PushL(rights);
685 rights->AddRightsL(KDefaultRightsID,KDefaultRightsCount,mimeType); // add rights count
686 CleanupStack::PopAndDestroy(rights); // cleanup rights object
689 TBuf<KSizeBuf> filename;
690 TBuf<KSizeBuf> destFilename;
693 if(!GetStringFromConfig(_L("SectionDRM"),_L("DRMWavFile"),filename1))
694 return EInconclusive;
695 if(!GetStringFromConfig(_L("SectionDRM"),_L("TestConvertFile"),filename2))
696 return EInconclusive;
697 GetDriveName(filename);
698 filename.Append(filename1);
699 GetDriveName(destFilename);
700 destFilename.Append(filename2);
704 theFs.Delete(destFilename);
708 iError = KErrTimedOut;
709 TMdaFileClipLocation location(destFilename);
710 TMdaWavClipFormat format;
711 TMdaPcmWavCodec codec;
713 CMdaAudioConvertUtility* converter = CMdaAudioConvertUtility::NewL(*this);
714 CleanupStack::PushL(converter);
716 converter->OpenL(filename, &location, &format, &codec);
718 // Wait for initialisation callback
719 INFO_PRINTF1( _L("Initialise CMdaAudioConvertUtility"));
720 CActiveScheduler::Start();
723 if (iError == KErrNone && converter != NULL)
725 iError = KErrTimedOut;
727 converter->ConvertL();
729 // Wait for convert callback
730 INFO_PRINTF1( _L("Convert CMdaAudioconverterUtility: DRM play number"));
731 CActiveScheduler::Start();
733 if (iError == KErrNotSupported)
735 INFO_PRINTF1(_L("Correctly received KErrNotSupported, for converting protected file"));
740 INFO_PRINTF3(_L("Unexpected error %d, expecting %d"),iError, KErrNotSupported);
744 CleanupStack::PopAndDestroy(converter);
745 User::After(KOneSecond); // wait for deletion to shut down devsound
752 void CTestMmfAclntDRMConverterFail::MoscoStateChangeEvent(CBase* /*aObject*/, TInt aPreviousState, TInt aCurrentState, TInt aErrorCode)
756 iPreviousState = aPreviousState;
757 iCurrentState = aCurrentState;
759 TBool busy = (iCurrentState == CMdaAudioClipUtility::ERecording || iCurrentState == CMdaAudioClipUtility::EPlaying);
760 if (!busy || iError!=KErrNone)
761 CActiveScheduler::Stop();
763 INFO_PRINTF1( _L("CTestMmfAclntRecord : MMdaObjectStateChangeObserver Callback for CMdaAudioconverterUtility complete"));
764 INFO_PRINTF4( _L("iError %d iPreviousState %d iCurrentState %d"), iError, iPreviousState, iCurrentState);