mmlibs/mmfw/tsrc/mmfintegrationtest/ACLNT/OpenFileByHandle7902.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 "TestPlayerUtils.h"
       
    17 #include "OpenFileByHandle7902.h"
       
    18 
       
    19 #include <caf/caf.h>
       
    20 
       
    21 /**
       
    22  * Constructor
       
    23  */
       
    24 CTestMmfAclntOpenFile7902::CTestMmfAclntOpenFile7902(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 CTestMmfAclntOpenFile7902* CTestMmfAclntOpenFile7902::NewL(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName, const TTestFormat aFormat, const TBool aCreateFile)
       
    39 	{
       
    40 	CTestMmfAclntOpenFile7902* self = new (ELeave) CTestMmfAclntOpenFile7902(aTestName,aSectName,aKeyName,aFormat,aCreateFile);
       
    41 	return self;
       
    42 	}
       
    43 
       
    44 CTestMmfAclntOpenFile7902* CTestMmfAclntOpenFile7902::NewLC(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName, const TTestFormat aFormat, const TBool aCreateFile)
       
    45 	{
       
    46 	CTestMmfAclntOpenFile7902* self = CTestMmfAclntOpenFile7902::NewLC(aTestName,aSectName,aKeyName,aFormat,aCreateFile);
       
    47 	CleanupStack::PushL(self);
       
    48 	return self;
       
    49 	}
       
    50 
       
    51 void CTestMmfAclntOpenFile7902::MoscoStateChangeEvent(CBase* /*aObject*/, TInt /*aPreviousState*/, TInt /*aCurrentState*/, TInt aErrorCode)
       
    52 	{
       
    53 	iError = aErrorCode;
       
    54 	INFO_PRINTF2( _L("iError %d "), iError);
       
    55 	CActiveScheduler::Stop();
       
    56 	}
       
    57 
       
    58 // Audio utility callbacks
       
    59 void CTestMmfAclntOpenFile7902::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& /*aDuration*/)
       
    60 	{
       
    61 	iError = aError;
       
    62 	CActiveScheduler::Stop();
       
    63 	}
       
    64 
       
    65 void CTestMmfAclntOpenFile7902::MapcPlayComplete(TInt aError)
       
    66 	{
       
    67 	iError = aError;
       
    68 	CActiveScheduler::Stop();
       
    69 	}
       
    70 
       
    71 // Audio output stream callbacks
       
    72 void CTestMmfAclntOpenFile7902::MaoscOpenComplete(TInt aError)
       
    73 	{
       
    74 	iError = aError;
       
    75 	CActiveScheduler::Stop();
       
    76 	}
       
    77 
       
    78 void CTestMmfAclntOpenFile7902::MaoscBufferCopied(TInt aError, const TDesC8& /*aBuffer*/)
       
    79 	{
       
    80 	iError = aError;
       
    81 	CActiveScheduler::Stop();
       
    82 	}
       
    83 
       
    84 void CTestMmfAclntOpenFile7902::MaoscPlayComplete(TInt aError)
       
    85 	{
       
    86 	iError = aError;
       
    87 	CActiveScheduler::Stop();
       
    88 	}
       
    89 
       
    90 
       
    91 TVerdict CTestMmfAclntOpenFile7902::DoTestStepPreambleL()
       
    92 	{
       
    93 	SetupFormatL(iTestFormat);
       
    94 
       
    95 	return CTestMmfAclntStep::DoTestStepPreambleL();
       
    96 	}
       
    97 
       
    98 /**
       
    99  * Open a file based clip and record
       
   100  */
       
   101 TVerdict CTestMmfAclntOpenFile7902::DoTestStepL()
       
   102 	{
       
   103 	return( PerformTestStepL() );
       
   104 	}
       
   105 
       
   106 /*
       
   107  * TVerdict CTestMmfAclntOpenFile7902::PerformTestStepL()
       
   108  *
       
   109  */
       
   110 TVerdict CTestMmfAclntOpenFile7902::PerformTestStepL()
       
   111 	{
       
   112 	TVerdict ret = EFail;
       
   113 	iError = KErrTimedOut;
       
   114 
       
   115 	RFs fs;
       
   116 	RFile file;
       
   117 
       
   118 	User::LeaveIfError(fs.Connect());
       
   119 	CleanupClosePushL(fs);
       
   120 	User::LeaveIfError(fs.ShareProtected());
       
   121 
       
   122 	TPtrC			filename; 
       
   123 	if(!GetStringFromConfig(iSectName, iKeyName, filename))
       
   124 		{
       
   125 		ret = EInconclusive;
       
   126 		}
       
   127 
       
   128 	CMdaAudioRecorderUtility* recUtil = CMdaAudioRecorderUtility::NewL(*this);
       
   129 	CleanupStack::PushL(recUtil);
       
   130 
       
   131 	User::LeaveIfError(file.Replace(fs,filename,EFileWrite));
       
   132 	CleanupClosePushL(file);
       
   133 	
       
   134 	recUtil->OpenFileL(file);
       
   135 
       
   136 	CActiveScheduler::Start();
       
   137 
       
   138 	if(iError == KErrNone)
       
   139 		{
       
   140 		iError = KErrTimedOut;
       
   141 		recUtil->RecordL();
       
   142 		CActiveScheduler::Start(); // open -> record
       
   143 
       
   144 		User::After(500000);	// 0.5 sec
       
   145 		recUtil->Stop();
       
   146 		}
       
   147 
       
   148 	CleanupStack::PopAndDestroy(2, recUtil);	// file, recUtil
       
   149 	recUtil = NULL;
       
   150 
       
   151 	// Playback the file
       
   152 	if (iError == KErrNone)
       
   153 		{
       
   154 		// Wav file playback
       
   155 		CMdaAudioPlayerUtility* playUtil = CMdaAudioPlayerUtility::NewL(*this);
       
   156 		CleanupStack::PushL(playUtil);
       
   157 		TRAPD(err, playUtil->OpenFileL(filename));
       
   158 		if (err != KErrNone)
       
   159 			{
       
   160 			INFO_PRINTF2(_L("Error opening file for playback err = %d"), err);
       
   161 			ret = EFail;
       
   162 			}
       
   163 		CActiveScheduler::Start();
       
   164 		if (iError != KErrNone)
       
   165 			{
       
   166 			INFO_PRINTF2(_L("Error opening file for playback iError = %d"), iError);
       
   167 			ret = EFail;
       
   168 			}
       
   169 
       
   170 		if( iError == KErrNone )
       
   171 			{
       
   172 			playUtil->Play();
       
   173 			CActiveScheduler::Start();
       
   174 			}
       
   175 		CleanupStack::PopAndDestroy(playUtil);
       
   176 		if (iError != KErrNone)
       
   177 			{
       
   178 			INFO_PRINTF2(_L("Error during playback of recorded file iError=%d"), iError);
       
   179 			ret = EFail;
       
   180 			}
       
   181 		}
       
   182 
       
   183 	if( iError == KErrNone ) 
       
   184 		{
       
   185 		RFile file;
       
   186 		TInt size = 0;
       
   187 		User::LeaveIfError(file.Open(fs,filename,EFileRead));
       
   188 		CleanupClosePushL(file);
       
   189 		User::LeaveIfError(file.Size(size));
       
   190 
       
   191 		if(size > 0)
       
   192 			{
       
   193 			ret = EPass;
       
   194 			}
       
   195 		CleanupStack::PopAndDestroy(); //file
       
   196 		}
       
   197 
       
   198 	CleanupStack::PopAndDestroy(&fs);	// fs
       
   199 
       
   200 	ERR_PRINTF2( _L("CMdaAudioRecorderUtility completed with error %d"),iError );
       
   201 	User::After(500000);
       
   202 
       
   203 	return	ret;
       
   204 	}