1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/mmlibs/mmfw/tsrc/mmfintegrationtest/ACLNT/OpenFileByHandle7908.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,355 @@
1.4 +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include "TestPlayerUtils.h"
1.20 +#include "OpenFileByHandle7908.h"
1.21 +
1.22 +#include <caf/caf.h>
1.23 +
1.24 +/**
1.25 + * Constructor
1.26 + */
1.27 +CTestMmfAclntOpenFile7908::CTestMmfAclntOpenFile7908(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName, const TTestFormat aFormat, const TBool aCreateFile)
1.28 + : CTestMmfAclntOpenFile7902(aTestName, aSectName, aKeyName, aFormat, aCreateFile), iRecUtil(NULL),iPlayUtil(NULL)
1.29 + {
1.30 + }
1.31 +
1.32 +CTestMmfAclntOpenFile7908* CTestMmfAclntOpenFile7908::NewL(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName, const TTestFormat aFormat, const TBool aCreateFile)
1.33 + {
1.34 + CTestMmfAclntOpenFile7908* self = new (ELeave) CTestMmfAclntOpenFile7908(aTestName,aSectName,aKeyName,aFormat,aCreateFile);
1.35 + return self;
1.36 + }
1.37 +
1.38 +CTestMmfAclntOpenFile7908* CTestMmfAclntOpenFile7908::NewLC(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName, const TTestFormat aFormat, const TBool aCreateFile)
1.39 + {
1.40 + CTestMmfAclntOpenFile7908* self = CTestMmfAclntOpenFile7908::NewL(aTestName,aSectName,aKeyName,aFormat,aCreateFile);
1.41 + CleanupStack::PushL(self);
1.42 + return self;
1.43 + }
1.44 +
1.45 +/**
1.46 + * Open a file based clip and record, and then playback
1.47 + * Performs alloc tests separately for each step in this test case
1.48 + * The 4 steps in this case are :
1.49 + * 1> Create CMdaAudioRecorderUtility
1.50 + * 2> Open CMdaAudioRecorderUtility and record a clip
1.51 + * 3> Create CMdaAudioPlayerUtility
1.52 + * 4> Open CMdaAudioRecorderUtility and playback the clip
1.53 + */
1.54 +TVerdict CTestMmfAclntOpenFile7908::DoTestStepL()
1.55 + {
1.56 + INFO_PRINTF1( _L("TestRecorder : Record File"));
1.57 + TInt err = KErrNone;
1.58 +
1.59 + //>>>>>>>>>>>>>>>>>>>>>>>>Test Method Call<<<<<<<<<<<<<<<<<<<<<<<<<<
1.60 + if( PerformTestStepL() != EPass )
1.61 + {
1.62 + err = iError;
1.63 + }
1.64 +
1.65 + if (err != KErrNone)
1.66 + {
1.67 + INFO_PRINTF2(_L("Test error, returned error code = %d"), err);
1.68 + User::Leave(err);
1.69 + }
1.70 +
1.71 + TInt failCount = 0;//total fail count for all the steps = sum of fail counts in each step
1.72 + TInt stepFailCount; //fail count in each step
1.73 + TVerdict iAllocTestStepResult = EPass; // XXX check?? assume pass
1.74 +
1.75 + err = PerformTestStep(1, stepFailCount);
1.76 + failCount += stepFailCount;
1.77 + if (err != KErrNone)
1.78 + {
1.79 + iAllocTestStepResult = EFail;
1.80 + TBuf<80> format;
1.81 + format.Format(_L(" Error(%d) with %d memory allocations tested\n"), err, failCount);
1.82 + Log(format);
1.83 + return iAllocTestStepResult;
1.84 + }
1.85 +
1.86 + TRAP(err, ExecuteStep1L());//Till step1 alloc tests are done, now keep the conditions ready
1.87 + //for performing alloc tests on step 2 i,e keep the iRecUtil
1.88 + //created and open for recording in this step
1.89 + if (err != KErrNone)
1.90 + {
1.91 + iAllocTestStepResult = EFail;
1.92 + TBuf<80> format;
1.93 + format.Format(_L(" Error(%d) with %d memory allocations tested\n"), err, failCount);
1.94 + Log(format);
1.95 + return iAllocTestStepResult;
1.96 + }
1.97 + err = PerformTestStep(2, stepFailCount);
1.98 + failCount += stepFailCount;
1.99 + delete iRecUtil;// Was created in ExecuteStep1L to be used for performing alloc tests in step 2
1.100 + if (err != KErrNone)
1.101 + {
1.102 + iAllocTestStepResult = EFail;
1.103 + TBuf<80> format;
1.104 + format.Format(_L(" Error(%d) with %d memory allocations tested\n"), err, failCount);
1.105 + Log(format);
1.106 + return iAllocTestStepResult;
1.107 + }
1.108 +
1.109 + err = PerformTestStep(3, stepFailCount);
1.110 + failCount += stepFailCount;
1.111 + if (err != KErrNone)
1.112 + {
1.113 + iAllocTestStepResult = EFail;
1.114 + TBuf<80> format;
1.115 + format.Format(_L(" Error(%d) with %d memory allocations tested\n"), err, failCount);
1.116 + Log(format);
1.117 + return iAllocTestStepResult;
1.118 + }
1.119 +
1.120 + TRAP(err, ExecuteStep3L());//Till step3 alloc tests are done, now keep the conditions ready
1.121 + //for performing alloc tests on step 4 i,e keep the iPlayUtil
1.122 + //created and open for playback in this step
1.123 + if(err != KErrNone)
1.124 + {
1.125 + iAllocTestStepResult = EFail;
1.126 + TBuf<80> format;
1.127 + format.Format(_L(" Error(%d) with %d memory allocations tested\n"), err, failCount);
1.128 + Log(format);
1.129 + return iAllocTestStepResult;
1.130 + }
1.131 + err = PerformTestStep(4, stepFailCount);
1.132 + failCount += stepFailCount;
1.133 + delete iPlayUtil; // Was created in ExecuteStep3L to be used for performing alloc tests in step 4
1.134 +
1.135 + stepFailCount -= 1; // Failcount of 1 equates to 0 successful allocs, etc
1.136 +
1.137 + if (err != KErrNone)
1.138 + {
1.139 + iAllocTestStepResult = EFail;
1.140 + TBuf<80> format;
1.141 + format.Format(_L(" Error(%d) with %d memory allocations tested\n"), err, failCount);
1.142 + Log(format);
1.143 + }
1.144 + else
1.145 + {
1.146 + TBuf<80> format;
1.147 + format.Format(_L(" Completed OK with %d memory allocations tested\n"), failCount);
1.148 + Log(format);
1.149 + }
1.150 +
1.151 + return iAllocTestStepResult;
1.152 + }
1.153 +/*
1.154 + * TVerdict CTestMmfAclntOpenFile7908::PerformTestStep(TInt aStepNo, TInt& aStepFailCount)
1.155 + * Performs alloc tests on the step aStepNo in this test case
1.156 + */
1.157 +TInt CTestMmfAclntOpenFile7908::PerformTestStep(TInt aStepNo, TInt& aStepFailCount)
1.158 + {
1.159 + TBool completed;
1.160 + TInt err;
1.161 + for(aStepFailCount = 1;;)
1.162 + {
1.163 + __UHEAP_SETFAIL(RHeap::EFailNext, aStepFailCount);
1.164 + __MM_HEAP_MARK;
1.165 +
1.166 +// INFO_PRINTF2(_L("CAudioRecorderUtility: Alloc Test Loop: %d"), failCount);
1.167 + //>>>>>>>>>>>>>>>>>>>>>>>>Test Method Call<<<<<<<<<<<<<<<<<<<<<<<<<<
1.168 + TVerdict verdict = EFail;
1.169 +
1.170 + switch( aStepNo )
1.171 + {
1.172 + case 1:
1.173 + TRAP(err, verdict = ExecuteStep1L());
1.174 + if(err == KErrNone)
1.175 + {
1.176 + delete iRecUtil; //Created in ExecuteStep1L. We dont need it open anymore
1.177 + }
1.178 + break;
1.179 + case 2:
1.180 + TRAP(err, verdict = ExecuteStep2L());
1.181 + break;
1.182 + case 3:
1.183 + TRAP(err, verdict = ExecuteStep3L());
1.184 + if(err == KErrNone)
1.185 + {
1.186 + delete iPlayUtil; //Created in ExecuteStep3L. We dont need it open anymore
1.187 + }
1.188 + break;
1.189 + case 4:
1.190 + TRAP(err, verdict = ExecuteStep4L());
1.191 + break;
1.192 + }
1.193 +
1.194 + if (err == KErrNone && verdict != EPass)
1.195 + {
1.196 + err = iError;
1.197 + }
1.198 +
1.199 + completed = EFalse;
1.200 + if (err == KErrNone)
1.201 + {
1.202 + TAny *testAlloc = User::Alloc(1); // when this fails, we passed through all allocs within test
1.203 + if (testAlloc == NULL)
1.204 + {
1.205 + completed = ETrue;
1.206 + aStepFailCount -= 1;
1.207 + }
1.208 + else
1.209 + {
1.210 + User::Free(testAlloc);
1.211 + }
1.212 +
1.213 + }
1.214 + else if (err != KErrNoMemory) // bad error code
1.215 + {
1.216 + completed = ETrue;
1.217 + }
1.218 +
1.219 + __MM_HEAP_MARKEND;
1.220 + __UHEAP_SETFAIL(RHeap::ENone, 0);
1.221 +
1.222 + if (completed)
1.223 + {
1.224 + break; // exit loop
1.225 + }
1.226 +
1.227 + aStepFailCount++;
1.228 + }//for
1.229 + return err;
1.230 + }
1.231 +/*
1.232 + * TVerdict CTestMmfAclntOpenFile7908::ExecuteStep1L()
1.233 + * Executes the statements for step 1 of this test case
1.234 + */
1.235 +TVerdict CTestMmfAclntOpenFile7908::ExecuteStep1L()
1.236 + {
1.237 + iError = KErrTimedOut;
1.238 +
1.239 + iRecUtil = CMdaAudioRecorderUtility::NewL(*this);
1.240 + iError = KErrNone;
1.241 + return EPass;
1.242 + }
1.243 +
1.244 +/*
1.245 + * TVerdict CTestMmfAclntOpenFile7908::ExecuteStep2L()
1.246 + * Executes the statements for step 2 of this test case
1.247 + */
1.248 +TVerdict CTestMmfAclntOpenFile7908::ExecuteStep2L()
1.249 + {
1.250 + TVerdict ret = EFail;
1.251 + iError = KErrTimedOut;
1.252 +
1.253 + User::LeaveIfError(iFs.Connect());
1.254 + CleanupClosePushL(iFs);
1.255 + User::LeaveIfError(iFs.ShareProtected());
1.256 +
1.257 + if(!GetStringFromConfig(iSectName, iKeyName, iFilename))
1.258 + {
1.259 + ret = EInconclusive;
1.260 + }
1.261 +
1.262 + User::LeaveIfError(iFile.Replace(iFs,iFilename,EFileWrite));
1.263 + CleanupClosePushL(iFile);
1.264 + iRecUtil->OpenFileL(iFile);
1.265 + CleanupClosePushL(*iRecUtil);
1.266 + CActiveScheduler::Start();
1.267 +
1.268 + if(iError == KErrNone)
1.269 + {
1.270 + iError = KErrTimedOut;
1.271 + iRecUtil->RecordL();
1.272 + CActiveScheduler::Start(); // open -> record
1.273 +
1.274 + User::After(500000); // 0.5 sec
1.275 + iRecUtil->Stop();
1.276 + }
1.277 + CleanupStack::PopAndDestroy(3, &iFs); //iFs, iFile, iRecUtil
1.278 + if(iError == KErrNone)
1.279 + {
1.280 + ret = EPass;
1.281 + }
1.282 + return ret;
1.283 + }
1.284 +
1.285 +/*
1.286 + * TVerdict CTestMmfAclntOpenFile7908::ExecuteStep3L()
1.287 + * Executes the statements for step 3 of this test case
1.288 + */
1.289 + TVerdict CTestMmfAclntOpenFile7908::ExecuteStep3L()
1.290 + {
1.291 + TVerdict ret = EFail;
1.292 + iError = KErrTimedOut;
1.293 +
1.294 + iPlayUtil = CMdaAudioPlayerUtility::NewL(*this);
1.295 + iError = KErrNone;
1.296 + ret = EPass;
1.297 + return ret;
1.298 + }
1.299 +
1.300 +/*
1.301 + * TVerdict CTestMmfAclntOpenFile7908::ExecuteStep4L()
1.302 + * Executes the statements for step 4 of this test case
1.303 + */
1.304 +TVerdict CTestMmfAclntOpenFile7908::ExecuteStep4L()
1.305 + {
1.306 + TVerdict ret = EFail;
1.307 + iError = KErrTimedOut;
1.308 +
1.309 + TRAPD(err, iPlayUtil->OpenFileL(iFilename));
1.310 + if (err != KErrNone)
1.311 + {
1.312 + INFO_PRINTF2(_L("Error opening file for playback err = %d"), err);
1.313 + ret = EFail;
1.314 + }
1.315 + CActiveScheduler::Start();
1.316 + if (iError != KErrNone)
1.317 + {
1.318 + INFO_PRINTF2(_L("Error opening file for playback iError = %d"), iError);
1.319 + ret = EFail;
1.320 + }
1.321 + if( iError == KErrNone )
1.322 + {
1.323 + iPlayUtil->Play();
1.324 + CActiveScheduler::Start();
1.325 + }
1.326 + iPlayUtil->Close();
1.327 + if (iError != KErrNone)
1.328 + {
1.329 + INFO_PRINTF2(_L("Error during playback of recorded file iError=%d"), iError);
1.330 + ret = EFail;
1.331 + }
1.332 + if( iError == KErrNone )
1.333 + {
1.334 + RFile file;
1.335 + TInt size = 0;
1.336 +
1.337 + User::LeaveIfError(iFs.Connect());
1.338 + CleanupClosePushL(iFs);
1.339 + User::LeaveIfError(iFs.ShareProtected());
1.340 + User::LeaveIfError(file.Open(iFs,iFilename,EFileRead));
1.341 + CleanupClosePushL(file);
1.342 + User::LeaveIfError(file.Size(size));
1.343 +
1.344 + if(size > 0)
1.345 + {
1.346 + ret = EPass;
1.347 + }
1.348 + CleanupStack::PopAndDestroy(2, &iFs); //iFile, iFs
1.349 + }
1.350 +
1.351 + ERR_PRINTF2( _L("CMdaAudioRecorderUtility completed with error %d"),iError );
1.352 + if(iError == KErrNone)
1.353 + {
1.354 + User::After(500000);
1.355 + }
1.356 +
1.357 + return ret;
1.358 + }