os/mm/mmlibs/mmfw/tsrc/mmfunittest/MidiClnt/TSU_MMFMIDICLNT.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/mmlibs/mmfw/tsrc/mmfunittest/MidiClnt/TSU_MMFMIDICLNT.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,273 @@
     1.4 +
     1.5 +// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +// All rights reserved.
     1.7 +// This component and the accompanying materials are made available
     1.8 +// under the terms of "Eclipse Public License v1.0"
     1.9 +// which accompanies this distribution, and is available
    1.10 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +//
    1.12 +// Initial Contributors:
    1.13 +// Nokia Corporation - initial contribution.
    1.14 +//
    1.15 +// Contributors:
    1.16 +//
    1.17 +// Description:
    1.18 +// This program is designed the test of the TSU_MMFMIDICLNT.cpp.
    1.19 +// 
    1.20 +//
    1.21 +
    1.22 +/**
    1.23 + @file TSU_MMFMIDICLNT.cpp
    1.24 +*/
    1.25 +
    1.26 +#include "TSU_MMFMIDICLNT.h"
    1.27 +
    1.28 +
    1.29 +/**
    1.30 + * Timeout function
    1.31 + */
    1.32 +void CTestMmfMidiClntStep::WaitWithTimeout(TRequestStatus& aStatus, TInt aNumberOfMicroSeconds)
    1.33 +	{
    1.34 +	TRequestStatus timerStatus;
    1.35 +	RTimer timer;
    1.36 +	timer.CreateLocal() ;
    1.37 +	timer.After(timerStatus,aNumberOfMicroSeconds);
    1.38 +
    1.39 +	User::WaitForRequest(aStatus, timerStatus);
    1.40 +	if (timerStatus == KRequestPending)
    1.41 +		{
    1.42 +		timer.Cancel();
    1.43 +		User::WaitForRequest(timerStatus);
    1.44 +		}
    1.45 +	else
    1.46 +		{
    1.47 +		INFO_PRINTF1(_L("CTestMmfMidiClntStep wait timed out")) ;
    1.48 +		}
    1.49 +	timer.Close() ;
    1.50 +	}
    1.51 +
    1.52 +/**
    1.53 + * Time comparison utility function
    1.54 + *
    1.55 + * @param	"const TUint aActual"
    1.56 + *			The actual timer value produced
    1.57 + * @param	"const TUint aExpected"
    1.58 + *			Expected timer value
    1.59 + * @param	"const TUint aDeviation"
    1.60 + *			Allowed deviation of the expected value
    1.61 + *			from the actual value.
    1.62 + * @return	"TBool"
    1.63 + *			Did actual timed value fall within deviation limits
    1.64 + */ 
    1.65 +TBool CTestMmfMidiClntStep::TimeComparison(const TUint aActual, const TUint aExpected, const TUint aDeviation)
    1.66 +	{
    1.67 +	// save unnessary conditions
    1.68 +	if(aActual == aExpected)
    1.69 +		return ETrue;	
    1.70 +
    1.71 +	// Prevent unsigned wrapping errors 
    1.72 +	TUint difference;
    1.73 +	if(aActual > aExpected)
    1.74 +		difference = aActual - aExpected;
    1.75 +	else
    1.76 +		difference = aExpected - aActual;
    1.77 +
    1.78 +	// compare
    1.79 +	if(difference < aDeviation)
    1.80 +		return ETrue;
    1.81 +	return EFalse;
    1.82 +	}
    1.83 +
    1.84 +/**
    1.85 + * Test Preamble routines.
    1.86 + *
    1.87 + * Creates our own Active Scheduler.
    1.88 + *
    1.89 + * @return	"TVerdict"
    1.90 + *			Did Preamble complete.
    1.91 + */
    1.92 +TVerdict CTestMmfMidiClntStep::DoTestStepPreambleL()
    1.93 +	{
    1.94 +	iActiveScheduler = new(ELeave) CActiveScheduler;
    1.95 +    //[ push the scheduler on the stack ]
    1.96 +	CleanupStack::PushL( iActiveScheduler );
    1.97 +	
    1.98 +	//[install the active scheduler ]
    1.99 +	CActiveScheduler::Install(iActiveScheduler);
   1.100 +
   1.101 +	// Pop the element from the stack
   1.102 +	CleanupStack::Pop();
   1.103 +
   1.104 +	return EPass;
   1.105 +	}
   1.106 +
   1.107 +/**
   1.108 + * Test Postamble routines.
   1.109 + *
   1.110 + * Destroys our Active Scheduler.
   1.111 + *
   1.112 + * @return	"TVerdict"
   1.113 + *			Did Postamble complete.
   1.114 + */
   1.115 +TVerdict CTestMmfMidiClntStep::DoTestStepPostambleL()
   1.116 +	{
   1.117 +	delete iActiveScheduler;
   1.118 +	iActiveScheduler = NULL;
   1.119 +	
   1.120 +	delete iScreen;
   1.121 +	delete iWindow;
   1.122 +	iWs.Close();
   1.123 +	
   1.124 +
   1.125 +	return EPass;
   1.126 +	}
   1.127 +
   1.128 +/**
   1.129 + * CTestMMFVCLNTStep Implementation
   1.130 + */
   1.131 +CTestMmfMidiClntStep::CTestMmfMidiClntStep(const TDesC& aTestName, const TTestStepType aTestType)
   1.132 +	:CTestStep(),
   1.133 +	 iActiveScheduler( NULL )
   1.134 +	{
   1.135 +	// store the name of this test step
   1.136 +	// this is the name that is used by the script file
   1.137 +	// Each test step initialises it's own name
   1.138 +	iTestStepName = aTestName;
   1.139 +	iTestType = aTestType;
   1.140 +	}
   1.141 +
   1.142 +CTestMmfMidiClntStep::CTestMmfMidiClntStep()
   1.143 +	:iActiveScheduler( NULL )
   1.144 +	// for test step that sets its own name
   1.145 +	{
   1.146 +	iTestType = ETestValid;
   1.147 +	}
   1.148 +
   1.149 +CTestMmfMidiClntStep::~CTestMmfMidiClntStep()
   1.150 +	{
   1.151 +	}
   1.152 +
   1.153 +/*void CTestMmfMidiClntStep::Close()
   1.154 +	{
   1.155 +	delete iScreen;
   1.156 +	delete iWindow;
   1.157 +	iWs.Close();
   1.158 +	}*/
   1.159 +
   1.160 +/**
   1.161 + * DoTestStepL : same as CTestMidiClientOpenFile::DoTestStepL() but with no file opening
   1.162 + * routines.
   1.163 + *
   1.164 + * Generally, test steps should NOT override this, but put their processing in DoTestL()
   1.165 + *
   1.166 + */
   1.167 +TVerdict CTestMmfMidiClntStep::DoTestStepL()
   1.168 +	{
   1.169 +	__MM_HEAP_MARK;
   1.170 +	CMidiClientUtility* player = CMidiClientUtility::NewL(*this, EMdaPriorityNormal, EMdaPriorityPreferenceTimeAndQuality);
   1.171 +	if (!player)
   1.172 +		{
   1.173 +		ERR_PRINTF1(_L("Could not create a CMidiClientUtility"));
   1.174 +		return EInconclusive;
   1.175 +		}
   1.176 +	
   1.177 +	CleanupStack::PushL(player);
   1.178 + 
   1.179 +	TMMFMessageDestinationPckg dummyPckg;
   1.180 +	TInt dummyFunc = 0;		//EDevMidiOff;
   1.181 +	TBuf8<8> dummyBuff;
   1.182 +	player->CustomCommandSyncL(dummyPckg, dummyFunc, dummyBuff, dummyBuff, dummyBuff);
   1.183 +
   1.184 +	TVerdict ret = DoTestL(player);
   1.185 +		
   1.186 +	INFO_PRINTF1(_L("CMidiClientUtility: Destroying"));
   1.187 +	CleanupStack::PopAndDestroy(player);
   1.188 +
   1.189 +	if(iError != KErrNone)
   1.190 +		ERR_PRINTF2( _L("CMidiClientUtility failed with error %d"),iError );
   1.191 +	
   1.192 +	__MM_HEAP_MARKEND;
   1.193 +	return	ret;
   1.194 +	}
   1.195 +
   1.196 +TVerdict CTestMmfMidiClntStep::DoTestL(CMidiClientUtility* /*aMidi*/)
   1.197 +	{
   1.198 +	return EPass;
   1.199 +	}
   1.200 +
   1.201 +void CTestMmfMidiClntStep::InitWservL()
   1.202 +	{
   1.203 +	TInt err = iWs.Connect();
   1.204 +	if (err != KErrNone)
   1.205 +		{
   1.206 +		// Access violation if ws is null
   1.207 +		INFO_PRINTF1(_L("Cannot test, no window server available"));
   1.208 +		User::Leave(err);
   1.209 +		}
   1.210 +
   1.211 +	iScreen = new (ELeave) CWsScreenDevice(iWs); // make device for this session
   1.212 +	User::LeaveIfError(iScreen->Construct()); // and complete its construction
   1.213 +
   1.214 +	RWindowGroup rootWindow = RWindowGroup(iWs);
   1.215 +	User::LeaveIfError(rootWindow.Construct((TUint32)this, ETrue));
   1.216 +
   1.217 +	iWindow = new(ELeave) RWindow(iWs);
   1.218 +	User::LeaveIfError(((RWindow*)iWindow)->Construct(rootWindow,((TUint32)(this)) + 1));
   1.219 +	iWindow->SetExtent(TPoint(0,0), TSize(100,100));
   1.220 +	iWindow->SetVisible(ETrue);
   1.221 +	iWindow->Activate();
   1.222 +	iWs.Flush();
   1.223 +	}
   1.224 +
   1.225 +// MMidiClientUtilityObserver
   1.226 +
   1.227 +void CTestMmfMidiClntStep::MmcuoStateChanged(TMidiState aOldState, TMidiState aNewState, 
   1.228 +											  const TTimeIntervalMicroSeconds& /* aTime */, TInt aError)
   1.229 +	{
   1.230 +	INFO_PRINTF3(_L("MmcuoStateChanged callback, oldState = %d, newState = %d"), aOldState, aNewState);
   1.231 +
   1.232 +	iError = aError;
   1.233 +	iCurrentState = aNewState;
   1.234 +	CActiveScheduler::Stop(); // check if asynchronous
   1.235 +	}
   1.236 +
   1.237 +void CTestMmfMidiClntStep::MmcuoTempoChanged(TInt /* aMicroBeatsPerMinute */)
   1.238 +	{
   1.239 +	INFO_PRINTF1(_L("MmcuoTempoChanged callback"));
   1.240 +	}
   1.241 +
   1.242 +void CTestMmfMidiClntStep::MmcuoVolumeChanged(TInt /*aChannel*/,TReal32 /*aVolumeInDecibels*/)
   1.243 +	{
   1.244 +	INFO_PRINTF1(_L("MmcuoVolumeChanged callback"));
   1.245 +	}
   1.246 +
   1.247 +void CTestMmfMidiClntStep::MmcuoMuteChanged(TInt /* aChannel */, TBool /* aMuted */)
   1.248 +	{
   1.249 +	INFO_PRINTF1(_L("MmcuoMuteChanged callback"));
   1.250 +	}
   1.251 +
   1.252 +void CTestMmfMidiClntStep::MmcuoSyncUpdate(const TTimeIntervalMicroSeconds& /* aMicroSeconds */, TInt64 /* aMicroBeats */)
   1.253 +	{
   1.254 +	INFO_PRINTF1(_L("MmcuoSyncUpdate callback"));
   1.255 +	}
   1.256 +
   1.257 +void CTestMmfMidiClntStep::MmcuoMetaDataEntryFound(const TInt /*aMetaDataEntryId*/,const TTimeIntervalMicroSeconds& /*aPosition*/)
   1.258 +	{
   1.259 +	INFO_PRINTF1(_L("MmcuoSmfMetaDataEntryFound callback"));
   1.260 +	}
   1.261 +
   1.262 +void CTestMmfMidiClntStep::MmcuoMipMessageReceived(const RArray<TMipMessageEntry>& /* aEntry */)
   1.263 +	{
   1.264 +	INFO_PRINTF1(_L("MmcuoMipMessageReceived callback"));
   1.265 +	}
   1.266 +
   1.267 +void CTestMmfMidiClntStep::MmcuoPolyphonyChanged(TInt /* aNewPolyphony */)
   1.268 +	{
   1.269 +	INFO_PRINTF1(_L("MmcuoPolyphonyChanged callback"));
   1.270 +	}
   1.271 +
   1.272 +void CTestMmfMidiClntStep::MmcuoInstrumentChanged(TInt /* aChannel */, TInt /* aBankId */, TInt /* aInstrumentId */)
   1.273 +	{
   1.274 +	INFO_PRINTF1(_L("MmcuoInstrumentChanged callback"));
   1.275 +	}
   1.276 +