os/mm/mmlibs/mmfw/tsrc/mmfintegrationtest/ACLNT/TestCapabilities0014.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 
     2 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 // All rights reserved.
     4 // This component and the accompanying materials are made available
     5 // under the terms of "Eclipse Public License v1.0"
     6 // which accompanies this distribution, and is available
     7 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 //
     9 // Initial Contributors:
    10 // Nokia Corporation - initial contribution.
    11 //
    12 // Contributors:
    13 //
    14 // Description:
    15 // TestCapabilities.CPP
    16 // This program is designed the test of the MMF_ACLNT.
    17 // 
    18 //
    19 
    20 /**
    21  @file TestPlayerUtils.cpp
    22 */
    23 
    24 #include <simulprocclient.h>
    25 #include "TestPlayerCaps.h"
    26 #include "TestPlayerCaps0014.h"
    27 
    28 
    29 
    30 /**
    31  * Constructor
    32  */
    33 CTestMmfAclntCaps0014::CTestMmfAclntCaps0014(const TDesC& aTestName, const TDesC& aSectName, const TDesC& aKeyName)
    34 	{
    35 	// store the name of this test case
    36 	// this is the name that is used by the script file
    37 	// Each test step initialises it's own name
    38 	iTestStepName = aTestName;
    39 	iSectName = aSectName;
    40 	iKeyName = aKeyName;
    41 	}
    42 
    43 CTestMmfAclntCaps0014* CTestMmfAclntCaps0014::NewL(const TDesC& aTestName, const TDesC& aSectName, const TDesC& aKeyName)
    44 	{
    45 	CTestMmfAclntCaps0014* self = new (ELeave) CTestMmfAclntCaps0014(aTestName, aSectName, aKeyName);
    46 	return self;
    47 	}
    48 
    49 CTestMmfAclntCaps0014* CTestMmfAclntCaps0014::NewLC(const TDesC& aTestName, const TDesC& aSectName, const TDesC& aKeyName)
    50 	{
    51 	CTestMmfAclntCaps0014* self = NewL(aTestName, aSectName, aKeyName);
    52 	CleanupStack::PushL(self);
    53 	return self;
    54 	}
    55 
    56 //void CTestMmfAclntCaps0014::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& /*aDuration*/)
    57 //	{
    58 //	INFO_PRINTF1( _L("MMdaAudioPlayerCallback Init Complete"));
    59 //	DoProcess(aError);
    60 //	}
    61 
    62 //void CTestMmfAclntCaps0014::MapcPlayComplete(TInt aError)
    63 //	{
    64 //	INFO_PRINTF1( _L("MMdaAudioPlayerCallback Play Complete"));
    65 //	DoProcess(aError);
    66 //	}
    67 
    68 void CTestMmfAclntCaps0014::MoscoStateChangeEvent(CBase* /*aObject*/, TInt aPreviousState, TInt aCurrentState, TInt aErrorCode)
    69 	{
    70 	if (aErrorCode == KErrNone)
    71 		{
    72 		if (aPreviousState == CMdaAudioClipUtility::ENotReady && aCurrentState==CMdaAudioClipUtility::EOpen)
    73 			{
    74 			iPlayer->RecordL();
    75 			}
    76 		else if (aPreviousState == CMdaAudioClipUtility::EOpen && aCurrentState==CMdaAudioClipUtility::ERecording)
    77 			{
    78 			User::After( 1000000 );		// record for this long
    79 			iPlayer->Stop();
    80 			iVerdict = EPass;
    81 			CActiveScheduler::Stop();
    82 			}
    83 		else if (aPreviousState == CMdaAudioClipUtility::ERecording && aCurrentState==CMdaAudioClipUtility::EOpen)
    84 			{
    85 			// this shouldn't happen as record will continue until interrupted
    86 			iVerdict = EPass;
    87 			CActiveScheduler::Stop();
    88 			}
    89 		}
    90 	else if (aErrorCode == KErrInUse)
    91 		{
    92 		// double check state to ensure behaviour is correct
    93 		if (aPreviousState == CMdaAudioClipUtility::ERecording && aCurrentState==CMdaAudioClipUtility::EOpen)
    94 			{
    95 			iVerdict = EPass;
    96 			CActiveScheduler::Stop();
    97 			}
    98 		}
    99 
   100 	else 
   101 		{
   102 		iVerdict = EFail;
   103 		CActiveScheduler::Stop();
   104 		}
   105 
   106 	}
   107 
   108 /** Load and initialise an audio file.
   109  */
   110 TVerdict CTestMmfAclntCaps0014::DoTestStepL( void )
   111 	{
   112 	INFO_PRINTF1( _L("TestPlayerUtils : Caps"));
   113 	iVerdict = EFail;
   114 
   115 	iServerMonitor = CServerMonitor::NewL(this);
   116 	
   117 	// TSI_MMF_SDEVSOUND, MM-MMF-SDEVSOUND-I-0010-HP runs before this 
   118 	// this step does, I-0010-HP creates and uses 
   119 	// rectest1.wav and rectest2.wav 
   120 	// So we need to delete these to avoid errors In this test.
   121 	RFs fsSession;
   122 	fsSession.Connect();
   123 	TRAPD(err,fsSession.Delete(_L("c:\\rectest1.wav")));
   124 	TRAP(err,fsSession.Delete(_L("c:\\rectest2.wav")));
   125 	fsSession.Close();
   126 	
   127 	// Start Server to play back from another process
   128 	RTestServ server;
   129 	User::LeaveIfError(server.Connect(_L("CapTestServer")));
   130 	CleanupClosePushL(server);
   131 	RTestSession session1;
   132 	User::LeaveIfError(session1.Open(server,_L("CapTestStep0014")));
   133 	TRequestStatus* status = &iServerMonitor->ActiveStatus();
   134 	// Start Server playback. The RunL of the CServerMonitor class will be called by the server when
   135 	// playback has started
   136 	session1.StartProcessing(*status);
   137 	// Begin activescheduler loop. This will only exit when the whole test is complete 
   138 	CActiveScheduler::Start();
   139 	
   140 	// The test is complete. Now shut down the server and get any errors /messages from the server
   141 	TBuf8<256> message;
   142 	TVerdict verdict = session1.EndProcessingAndReturnResult(message);
   143 	if (verdict != EPass)
   144 		iVerdict = verdict;
   145 	TBuf16<256> copymess;
   146 	copymess.Copy(message);
   147 	INFO_PRINTF2(_L("end processing and return result: %S"),&copymess);
   148 
   149 	CleanupStack::PopAndDestroy(&server);
   150 	return iVerdict;
   151 	}
   152 	
   153 void CTestMmfAclntCaps0014::CreatePlayer() 
   154 	{
   155 	// Get the test filename from the configuration file
   156 	TBuf<KSizeBuf> filename;
   157 	TPtrC filename1; 
   158 	if(!GetStringFromConfig(iSectName,iKeyName,filename1))
   159 		{
   160 		iVerdict = EFail;
   161 		CActiveScheduler::Stop();
   162 		}
   163 	GetDriveName(filename);
   164 	filename.Append(filename1);
   165 	
   166 	iPlayer = CMdaAudioRecorderUtility::NewL(*this, NULL, EMdaPriorityNormal);
   167 	iPlayer->OpenFileL(_L("c:\\rectest2.wav"));
   168 	}
   169 	
   170 void CTestMmfAclntCaps0014::BeginPlayback()
   171 	{
   172 	iPlayer->RecordL();
   173 	}
   174 	
   175 	
   176 void CTestMmfAclntCaps0014::DoProcess(TInt aError)
   177 	{
   178 	if (aError == KErrNone)
   179 		{
   180 		InternalState nextState = iState;
   181 		switch (iState)
   182 			{
   183 		case EWaitingForServer:
   184 			CreatePlayer();
   185 			nextState = EInitPlayer;
   186 			break;
   187 		case EInitPlayer : 
   188 			BeginPlayback();
   189 			nextState = EPlaying;
   190 			break;
   191 		case EPlaying :
   192 			iVerdict = EPass;
   193 			CActiveScheduler::Stop();
   194 			break;
   195 			}
   196 		iState = nextState;
   197 		}
   198 	else 
   199 		{
   200 		iVerdict = EFail;
   201 		INFO_PRINTF2(_L("Unexpected failure in test, error code %d"), aError);
   202 		CActiveScheduler::Stop();
   203 		}
   204 	}
   205 
   206 CTestMmfAclntCaps0014::CServerMonitor::CServerMonitor(CTestMmfAclntCaps0014* aParent)
   207 	:CActive(EPriorityNormal), iParent(aParent)
   208 	{
   209 	}
   210 
   211 	
   212 CTestMmfAclntCaps0014::CServerMonitor* CTestMmfAclntCaps0014::CServerMonitor::NewL(CTestMmfAclntCaps0014* aParent) 
   213 	{
   214 	CServerMonitor* self = new (ELeave) CServerMonitor(aParent);
   215 	CleanupStack::PushL(self);
   216 	self->ConstructL();
   217 	CleanupStack::Pop(self);
   218 	return self;
   219 	}
   220 
   221 void CTestMmfAclntCaps0014::CServerMonitor::ConstructL() 
   222 	{
   223 	CActiveScheduler::Add(this);
   224 	}
   225 
   226 void CTestMmfAclntCaps0014::CServerMonitor::DoCancel() 
   227 	{
   228 	Cancel();
   229 	}
   230 
   231 void CTestMmfAclntCaps0014::CServerMonitor::RunL() 
   232 	{
   233 	// start the client state machine
   234 	iParent->DoProcess(iStatus.Int());
   235 	}
   236 	
   237 TRequestStatus& CTestMmfAclntCaps0014::CServerMonitor::ActiveStatus() 
   238 	{
   239 	SetActive();
   240 	return iStatus;
   241 	}
   242 
   243 
   244 CTestMmfAclntCaps0014::~CTestMmfAclntCaps0014()
   245 	{
   246 	}
   247 	
   248 void CTestMmfAclntCaps0014::Close()
   249 	{
   250 	delete iPlayer;
   251 	delete iServerMonitor;
   252 	}
   253 
   254