os/mm/mmlibs/mmfw/tsrc/mmfintegrationtest/ACLNT/OpenFileByHandle7906.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     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 "TestPlayerUtils.h"
    18 #include "OpenFileByHandle7906.h"
    19 
    20 #include <caf/caf.h>
    21 
    22 /**
    23  * Constructor
    24  */
    25 CTestMmfAclntOpenFile7906::CTestMmfAclntOpenFile7906(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName, const TTestFormat aFormat, const TBool aCreateFile)
    26 
    27 	{
    28 	// store the name of this test case
    29 	// this is the name that is used by the script file
    30 	// Each test step initialises it's own name
    31 	iTestStepName = aTestName;
    32 	iHeapSize = 200000;		// playback part of test loads whole sound file into buffer, so need large heap
    33 	iSectName = aSectName;
    34 	iKeyName = aKeyName;
    35 	iTestFormat = aFormat;
    36 	iCreateFile = aCreateFile;
    37 	}
    38 
    39 CTestMmfAclntOpenFile7906* CTestMmfAclntOpenFile7906::NewL(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName, const TTestFormat aFormat, const TBool aCreateFile)
    40 	{
    41 	CTestMmfAclntOpenFile7906* self = new (ELeave) CTestMmfAclntOpenFile7906(aTestName,aSectName,aKeyName,aFormat,aCreateFile);
    42 	return self;
    43 	}
    44 
    45 CTestMmfAclntOpenFile7906* CTestMmfAclntOpenFile7906::NewLC(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName, const TTestFormat aFormat, const TBool aCreateFile)
    46 	{
    47 	CTestMmfAclntOpenFile7906* self = CTestMmfAclntOpenFile7906::NewLC(aTestName,aSectName,aKeyName,aFormat,aCreateFile);
    48 	CleanupStack::PushL(self);
    49 	return self;
    50 	}
    51 
    52 void CTestMmfAclntOpenFile7906::MoscoStateChangeEvent(CBase* /*aObject*/, TInt /*aPreviousState*/, TInt /*aCurrentState*/, TInt aErrorCode)
    53 	{
    54 	iError = aErrorCode;
    55 	INFO_PRINTF1( _L("CTestMmfAclntOpenFile7906 : MMdaObjectStateChangeObserver Callback for CMdaAudioRecorderUtility complete"));
    56 	INFO_PRINTF2( _L("iError %d "), iError);
    57 
    58 	CActiveScheduler::Stop();
    59 	}
    60 
    61 // Audio utility callbacks
    62 void CTestMmfAclntOpenFile7906::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& /*aDuration*/)
    63 	{
    64 	iError = aError;
    65 	CActiveScheduler::Stop();
    66 	}
    67 
    68 void CTestMmfAclntOpenFile7906::MapcPlayComplete(TInt aError)
    69 	{
    70 	iError = aError;
    71 	CActiveScheduler::Stop();
    72 	}
    73 
    74 // Audio output stream callbacks
    75 void CTestMmfAclntOpenFile7906::MaoscOpenComplete(TInt aError)
    76 	{
    77 	iError = aError;
    78 	CActiveScheduler::Stop();
    79 	}
    80 
    81 void CTestMmfAclntOpenFile7906::MaoscBufferCopied(TInt aError, const TDesC8& /*aBuffer*/)
    82 	{
    83 	iError = aError;
    84 	CActiveScheduler::Stop();
    85 	}
    86 
    87 void CTestMmfAclntOpenFile7906::MaoscPlayComplete(TInt aError)
    88 	{
    89 	iError = aError;
    90 	CActiveScheduler::Stop();
    91 	}
    92 
    93 
    94 TVerdict CTestMmfAclntOpenFile7906::DoTestStepPreambleL()
    95 	{
    96 	TVerdict ret = EPass;
    97 
    98 	SetupFormatL(iTestFormat);
    99 
   100 	if((ret == EInconclusive) || (ret == EFail))
   101 		{
   102 		return ret;
   103 		}
   104 	
   105 	return CTestMmfAclntStep::DoTestStepPreambleL();
   106 	}
   107 
   108 /**
   109  * Open a file based clip and record
   110  */
   111 TVerdict CTestMmfAclntOpenFile7906::DoTestStepL()
   112 	{
   113 	INFO_PRINTF1( _L("TestRecorder : Record File"));
   114 	TVerdict ret = EFail;
   115 	iError = KErrTimedOut;
   116 
   117 	RFs fs;
   118 	RFile file;
   119 
   120 	User::LeaveIfError(fs.Connect());
   121 	CleanupClosePushL(fs);
   122 	User::LeaveIfError(fs.ShareProtected());
   123 
   124 	TPtrC			filename; 
   125 	if(!GetStringFromConfig(iSectName, iKeyName, filename))
   126 		{
   127 		return EInconclusive;
   128 		}
   129 
   130 	CMdaAudioRecorderUtility* recUtil = CMdaAudioRecorderUtility::NewL(*this);
   131 	CleanupStack::PushL(recUtil);
   132 
   133 	TUid audioController = TUid::Uid(KMmfUidControllerAudio);
   134 
   135 	TFourCC invalidDataType(0xAA, 0xAA, 0xAA, 0xAA);
   136 
   137 	User::LeaveIfError(file.Replace(fs,filename,EFileWrite));
   138 	CleanupClosePushL(file);
   139 
   140 	recUtil->OpenFileL(file, audioController, KNullUid, KNullUid, invalidDataType);
   141 
   142 	INFO_PRINTF1( _L("Initialise CMdaAudioRecorderUtility"));
   143 	CActiveScheduler::Start();
   144 
   145 	if( iError == KErrNotSupported )
   146 		{
   147 		ret = EPass;
   148 		}
   149 
   150 	if(iError == KErrNone)
   151 		{
   152 		iError = KErrTimedOut;
   153 		recUtil->RecordL();
   154 		INFO_PRINTF1( _L("Record CMdaAudioRecorderUtility"));
   155 		CActiveScheduler::Start(); // open -> record
   156 
   157 		User::After(500000);
   158 
   159 		recUtil->Stop();
   160 		}
   161 
   162 	CleanupStack::PopAndDestroy(2, recUtil);	// file, recUtil
   163 	recUtil = NULL;
   164 
   165 	// Playback the file
   166 	if (iError == KErrNone)
   167 		{
   168 		if (filename.Right(4).Compare(_L(".wav"))==0)
   169 			{
   170 			// Wav file playback
   171 			CMdaAudioPlayerUtility* playUtil = CMdaAudioPlayerUtility::NewL(*this);
   172 			CleanupStack::PushL(playUtil);
   173 			TRAPD(err, playUtil->OpenFileL(filename));
   174 			if (err != KErrNone)
   175 				{
   176 				INFO_PRINTF2(_L("Error opening file for playback err = %d"), err);
   177 				ret = EFail;
   178 				}
   179 			CActiveScheduler::Start();
   180 			if (iError != KErrNone)
   181 				{
   182 				INFO_PRINTF2(_L("Error opening file for playback iError = %d"), iError);
   183 				ret = EFail;
   184 				}
   185 			playUtil->Play();
   186 			CActiveScheduler::Start();
   187 			CleanupStack::PopAndDestroy(playUtil);
   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 	}