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