mmlibs/mmfw/tsrc/mmfintegrationtest/SDevSound/src/TestCapabilities0014.cpp
changeset 0 b8ed18f6c07b
equal deleted inserted replaced
-1:000000000000 0:b8ed18f6c07b
       
     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 	// Start Server to play back from another process
       
   118 	RTestServ server;
       
   119 	User::LeaveIfError(server.Connect(_L("CapTestServer")));
       
   120 	CleanupClosePushL(server);
       
   121 	
       
   122 	RTestSession session1;
       
   123 	User::LeaveIfError(session1.Open(server,_L("CapTestStep0014")));
       
   124 	TRequestStatus* status = &iServerMonitor->ActiveStatus();
       
   125 	// Start Server playback. The RunL of the CServerMonitor class will be called by the server when
       
   126 	// playback has started
       
   127 	session1.StartProcessing(*status);
       
   128 	// Begin activescheduler loop. This will only exit when the whole test is complete 
       
   129 	CActiveScheduler::Start();
       
   130 	
       
   131 	// The test is complete. Now shut down the server and get any errors /messages from the server
       
   132 	TBuf8<256> message;
       
   133 	TVerdict verdict = session1.EndProcessingAndReturnResult(message);
       
   134 	if (verdict != EPass)
       
   135 		iVerdict = verdict;
       
   136 	TBuf16<256> copymess;
       
   137 	copymess.Copy(message);
       
   138 	INFO_PRINTF2(_L("end processing and return result: %S"),&copymess);
       
   139 
       
   140 	CleanupStack::PopAndDestroy(&server);
       
   141 	return iVerdict;
       
   142 	}
       
   143 	
       
   144 void CTestMmfAclntCaps0014::CreatePlayer() 
       
   145 	{
       
   146 	// Get the test filename from the configuration file
       
   147 	TBuf<KSizeBuf> filename;
       
   148 	TPtrC filename1; 
       
   149 	if(!GetStringFromConfig(iSectName,iKeyName,filename1))
       
   150 		{
       
   151 		iVerdict = EFail;
       
   152 		CActiveScheduler::Stop();
       
   153 		}
       
   154 	GetDriveName(filename);
       
   155 	filename.Append(filename1);
       
   156 
       
   157 	iPlayer = CMdaAudioRecorderUtility::NewL(*this, NULL, EMdaPriorityNormal);
       
   158 	iPlayer->OpenFileL(_L("c:\\rectest2.wav"));
       
   159 	}
       
   160 	
       
   161 void CTestMmfAclntCaps0014::BeginPlayback()
       
   162 	{
       
   163 	iPlayer->RecordL();
       
   164 	}
       
   165 	
       
   166 	
       
   167 void CTestMmfAclntCaps0014::DoProcess(TInt aError)
       
   168 	{
       
   169 	if (aError == KErrNone)
       
   170 		{
       
   171 		InternalState nextState = iState;
       
   172 		switch (iState)
       
   173 			{
       
   174 		case EWaitingForServer:
       
   175 			CreatePlayer();
       
   176 			nextState = EInitPlayer;
       
   177 			break;
       
   178 		case EInitPlayer : 
       
   179 			BeginPlayback();
       
   180 			nextState = EPlaying;
       
   181 			break;
       
   182 		case EPlaying :
       
   183 			iVerdict = EPass;
       
   184 			CActiveScheduler::Stop();
       
   185 			break;
       
   186 			}
       
   187 		iState = nextState;
       
   188 		}
       
   189 	else 
       
   190 		{
       
   191 		iVerdict = EFail;
       
   192 		INFO_PRINTF2(_L("Unexpected failure in test, error code %d"), aError);
       
   193 		CActiveScheduler::Stop();
       
   194 		}
       
   195 	}
       
   196 
       
   197 CTestMmfAclntCaps0014::CServerMonitor::CServerMonitor(CTestMmfAclntCaps0014* aParent)
       
   198 	:CActive(EPriorityNormal), iParent(aParent)
       
   199 	{
       
   200 	}
       
   201 
       
   202 	
       
   203 CTestMmfAclntCaps0014::CServerMonitor* CTestMmfAclntCaps0014::CServerMonitor::NewL(CTestMmfAclntCaps0014* aParent) 
       
   204 	{
       
   205 	CServerMonitor* self = new (ELeave) CServerMonitor(aParent);
       
   206 	CleanupStack::PushL(self);
       
   207 	self->ConstructL();
       
   208 	CleanupStack::Pop(self);
       
   209 	return self;
       
   210 	}
       
   211 
       
   212 void CTestMmfAclntCaps0014::CServerMonitor::ConstructL() 
       
   213 	{
       
   214 	CActiveScheduler::Add(this);
       
   215 	}
       
   216 
       
   217 void CTestMmfAclntCaps0014::CServerMonitor::DoCancel() 
       
   218 	{
       
   219 	Cancel();
       
   220 	}
       
   221 
       
   222 void CTestMmfAclntCaps0014::CServerMonitor::RunL() 
       
   223 	{
       
   224 	// start the client state machine
       
   225 	iParent->DoProcess(iStatus.Int());
       
   226 	}
       
   227 	
       
   228 TRequestStatus& CTestMmfAclntCaps0014::CServerMonitor::ActiveStatus() 
       
   229 	{
       
   230 	SetActive();
       
   231 	return iStatus;
       
   232 	}
       
   233 
       
   234 
       
   235 CTestMmfAclntCaps0014::~CTestMmfAclntCaps0014()
       
   236 	{
       
   237 	delete iPlayer;
       
   238 	delete iServerMonitor;
       
   239 	}