mmlibs/mmfw/tsrc/mmfintegrationtest/ACLNT/OpenFileByHandle7905.cpp
changeset 0 40261b775718
equal deleted inserted replaced
-1:000000000000 0:40261b775718
       
     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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <mmf/plugin/mmfcontrollerimplementationuids.hrh>
       
    17 #include <caf/caf.h>
       
    18 #include "TestPlayerUtils.h"
       
    19 #include "OpenFileByHandle7905.h"
       
    20 
       
    21 /**
       
    22  * Constructor
       
    23  */
       
    24 CTestMmfAclntOpenFile7905::CTestMmfAclntOpenFile7905(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName, const TTestFormat aFormat, const TBool aCreateFile)
       
    25 
       
    26 	{
       
    27 	// store the name of this test case
       
    28 	// this is the name that is used by the script file
       
    29 	// Each test step initialises it's own name
       
    30 	iTestStepName = aTestName;
       
    31 	iHeapSize = 200000;		// playback part of test loads whole sound file into buffer, so need large heap
       
    32 	iSectName = aSectName;
       
    33 	iKeyName = aKeyName;
       
    34 	iTestFormat = aFormat;
       
    35 	iCreateFile = aCreateFile;
       
    36 	}
       
    37 
       
    38 CTestMmfAclntOpenFile7905* CTestMmfAclntOpenFile7905::NewL(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName, const TTestFormat aFormat, const TBool aCreateFile)
       
    39 	{
       
    40 	CTestMmfAclntOpenFile7905* self = new (ELeave) CTestMmfAclntOpenFile7905(aTestName,aSectName,aKeyName,aFormat,aCreateFile);
       
    41 	return self;
       
    42 	}
       
    43 
       
    44 CTestMmfAclntOpenFile7905* CTestMmfAclntOpenFile7905::NewLC(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName, const TTestFormat aFormat, const TBool aCreateFile)
       
    45 	{
       
    46 	CTestMmfAclntOpenFile7905* self = CTestMmfAclntOpenFile7905::NewLC(aTestName,aSectName,aKeyName,aFormat,aCreateFile);
       
    47 	CleanupStack::PushL(self);
       
    48 	return self;
       
    49 	}
       
    50 
       
    51 void CTestMmfAclntOpenFile7905::MoscoStateChangeEvent(CBase* /*aObject*/, TInt /*aPreviousState*/, TInt /*aCurrentState*/, TInt aErrorCode)
       
    52 	{
       
    53 	iError = aErrorCode;
       
    54 	INFO_PRINTF1( _L("CTestMmfAclntOpenFile7905 : MMdaObjectStateChangeObserver Callback for CMdaAudioRecorderUtility complete"));
       
    55 	INFO_PRINTF2( _L("iError %d "), iError);
       
    56 
       
    57 	CActiveScheduler::Stop();
       
    58 	}
       
    59 
       
    60 // Audio utility callbacks
       
    61 void CTestMmfAclntOpenFile7905::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& /*aDuration*/)
       
    62 	{
       
    63 	iError = aError;
       
    64 	CActiveScheduler::Stop();
       
    65 	}
       
    66 
       
    67 void CTestMmfAclntOpenFile7905::MapcPlayComplete(TInt aError)
       
    68 	{
       
    69 	iError = aError;
       
    70 	CActiveScheduler::Stop();
       
    71 	}
       
    72 
       
    73 // Audio output stream callbacks
       
    74 void CTestMmfAclntOpenFile7905::MaoscOpenComplete(TInt aError)
       
    75 	{
       
    76 	iError = aError;
       
    77 	CActiveScheduler::Stop();
       
    78 	}
       
    79 
       
    80 void CTestMmfAclntOpenFile7905::MaoscBufferCopied(TInt aError, const TDesC8& /*aBuffer*/)
       
    81 	{
       
    82 	iError = aError;
       
    83 	CActiveScheduler::Stop();
       
    84 	}
       
    85 
       
    86 void CTestMmfAclntOpenFile7905::MaoscPlayComplete(TInt aError)
       
    87 	{
       
    88 	iError = aError;
       
    89 	CActiveScheduler::Stop();
       
    90 	}
       
    91 
       
    92 
       
    93 TVerdict CTestMmfAclntOpenFile7905::DoTestStepPreambleL()
       
    94 	{
       
    95 	TVerdict ret = EPass;
       
    96 
       
    97 	SetupFormatL(iTestFormat);
       
    98 
       
    99 	if((ret == EInconclusive) || (ret == EFail))
       
   100 		return ret;	
       
   101 	
       
   102 	return CTestMmfAclntStep::DoTestStepPreambleL();
       
   103 	}
       
   104 
       
   105 /**
       
   106  * Open a file based clip and record
       
   107  */
       
   108 #define KInvalidAudioController		0xA0A0A0A0
       
   109 
       
   110 TVerdict CTestMmfAclntOpenFile7905::DoTestStepL()
       
   111 	{
       
   112 	INFO_PRINTF1( _L("TestRecorder : Record File"));
       
   113 	TVerdict ret = EFail;
       
   114 	iError = KErrTimedOut;
       
   115 
       
   116 	RFs fs;
       
   117 	RFile file;
       
   118 
       
   119 	User::LeaveIfError(fs.Connect());
       
   120 	CleanupClosePushL(fs);
       
   121 	User::LeaveIfError(fs.ShareProtected());
       
   122 
       
   123 	TPtrC			filename; 
       
   124 	if(!GetStringFromConfig(iSectName, iKeyName, filename))
       
   125 		{
       
   126 		return EInconclusive;
       
   127 		}
       
   128 
       
   129 	CMdaAudioRecorderUtility* recUtil = CMdaAudioRecorderUtility::NewL(*this);
       
   130 	CleanupStack::PushL(recUtil);
       
   131 
       
   132 	TUid invalidAudioController;
       
   133 	invalidAudioController.iUid = KInvalidAudioController;
       
   134 
       
   135 	User::LeaveIfError(file.Replace(fs,filename,EFileWrite));
       
   136 	CleanupClosePushL(file);
       
   137 
       
   138 	recUtil->OpenFileL(file, invalidAudioController, KNullUid, KNullUid, KFourCCNULL);
       
   139 
       
   140 	INFO_PRINTF1( _L("Initialise CMdaAudioRecorderUtility"));
       
   141 	CActiveScheduler::Start();
       
   142 
       
   143 	if( iError == KErrNotFound )
       
   144 		{
       
   145 		ret = EPass;
       
   146 		}
       
   147 
       
   148 	if(iError == KErrNone)
       
   149 		{
       
   150 		iError = KErrTimedOut;
       
   151 		recUtil->RecordL();
       
   152 		INFO_PRINTF1( _L("Record CMdaAudioRecorderUtility"));
       
   153 		CActiveScheduler::Start(); // open -> record
       
   154 
       
   155 		User::After(KFiveSeconds);
       
   156 		recUtil->Stop();
       
   157 		}
       
   158 
       
   159 	CleanupStack::PopAndDestroy(2, recUtil);
       
   160 	recUtil = NULL;
       
   161 
       
   162 	// Playback the file
       
   163 	if (iError == KErrNone)
       
   164 		{
       
   165 		if (filename.Right(4).Compare(_L(".wav"))==0)
       
   166 			{
       
   167 			// Wav file playback
       
   168 			CMdaAudioPlayerUtility* playUtil = CMdaAudioPlayerUtility::NewL(*this);
       
   169 			CleanupStack::PushL(playUtil);
       
   170 			TRAPD(err, playUtil->OpenFileL(filename));
       
   171 			if (err != KErrNone)
       
   172 				{
       
   173 				INFO_PRINTF2(_L("Error opening file for playback err = %d"), err);
       
   174 				ret = EFail;
       
   175 				}
       
   176 			CActiveScheduler::Start();
       
   177 			if (iError != KErrNone)
       
   178 				{
       
   179 				INFO_PRINTF2(_L("Error opening file for playback iError = %d"), iError);
       
   180 				ret = EFail;
       
   181 				}
       
   182 
       
   183 			playUtil->Play();
       
   184 			CActiveScheduler::Start();
       
   185 
       
   186 			CleanupStack::PopAndDestroy(playUtil);
       
   187 
       
   188 			if (iError != KErrNone)
       
   189 				{
       
   190 				INFO_PRINTF2(_L("Error during playback of recorded file iError=%d"), iError);
       
   191 				ret = EFail;
       
   192 				}
       
   193 			}
       
   194 		}
       
   195 
       
   196 	if( iError == KErrNone ) 
       
   197 		{
       
   198 		RFile file;
       
   199 		TInt size = 0;
       
   200 		User::LeaveIfError(file.Open(fs,filename,EFileRead));
       
   201 		CleanupClosePushL(file);
       
   202 		User::LeaveIfError(file.Size(size));
       
   203 
       
   204 		if(size > 0)
       
   205 			{
       
   206 			ret = EPass;
       
   207 			}
       
   208 		CleanupStack::PopAndDestroy(); //file
       
   209 		}
       
   210 
       
   211 	CleanupStack::PopAndDestroy();	// fs
       
   212 
       
   213 	ERR_PRINTF2( _L("CMdaAudioRecorderUtility completed with error %d"),iError );
       
   214 	User::After(KOneSecond);
       
   215 
       
   216 	return	ret;
       
   217 	}