os/mm/mmlibs/mmfw/tsrc/mmfunittest/MidiClnt/TSU_MMFMIDICLNT.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 // This program is designed the test of the TSU_MMFMIDICLNT.cpp.
    16 // 
    17 //
    18 
    19 /**
    20  @file TSU_MMFMIDICLNT.cpp
    21 */
    22 
    23 #include "TSU_MMFMIDICLNT.h"
    24 
    25 
    26 /**
    27  * Timeout function
    28  */
    29 void CTestMmfMidiClntStep::WaitWithTimeout(TRequestStatus& aStatus, TInt aNumberOfMicroSeconds)
    30 	{
    31 	TRequestStatus timerStatus;
    32 	RTimer timer;
    33 	timer.CreateLocal() ;
    34 	timer.After(timerStatus,aNumberOfMicroSeconds);
    35 
    36 	User::WaitForRequest(aStatus, timerStatus);
    37 	if (timerStatus == KRequestPending)
    38 		{
    39 		timer.Cancel();
    40 		User::WaitForRequest(timerStatus);
    41 		}
    42 	else
    43 		{
    44 		INFO_PRINTF1(_L("CTestMmfMidiClntStep wait timed out")) ;
    45 		}
    46 	timer.Close() ;
    47 	}
    48 
    49 /**
    50  * Time comparison utility function
    51  *
    52  * @param	"const TUint aActual"
    53  *			The actual timer value produced
    54  * @param	"const TUint aExpected"
    55  *			Expected timer value
    56  * @param	"const TUint aDeviation"
    57  *			Allowed deviation of the expected value
    58  *			from the actual value.
    59  * @return	"TBool"
    60  *			Did actual timed value fall within deviation limits
    61  */ 
    62 TBool CTestMmfMidiClntStep::TimeComparison(const TUint aActual, const TUint aExpected, const TUint aDeviation)
    63 	{
    64 	// save unnessary conditions
    65 	if(aActual == aExpected)
    66 		return ETrue;	
    67 
    68 	// Prevent unsigned wrapping errors 
    69 	TUint difference;
    70 	if(aActual > aExpected)
    71 		difference = aActual - aExpected;
    72 	else
    73 		difference = aExpected - aActual;
    74 
    75 	// compare
    76 	if(difference < aDeviation)
    77 		return ETrue;
    78 	return EFalse;
    79 	}
    80 
    81 /**
    82  * Test Preamble routines.
    83  *
    84  * Creates our own Active Scheduler.
    85  *
    86  * @return	"TVerdict"
    87  *			Did Preamble complete.
    88  */
    89 TVerdict CTestMmfMidiClntStep::DoTestStepPreambleL()
    90 	{
    91 	iActiveScheduler = new(ELeave) CActiveScheduler;
    92     //[ push the scheduler on the stack ]
    93 	CleanupStack::PushL( iActiveScheduler );
    94 	
    95 	//[install the active scheduler ]
    96 	CActiveScheduler::Install(iActiveScheduler);
    97 
    98 	// Pop the element from the stack
    99 	CleanupStack::Pop();
   100 
   101 	return EPass;
   102 	}
   103 
   104 /**
   105  * Test Postamble routines.
   106  *
   107  * Destroys our Active Scheduler.
   108  *
   109  * @return	"TVerdict"
   110  *			Did Postamble complete.
   111  */
   112 TVerdict CTestMmfMidiClntStep::DoTestStepPostambleL()
   113 	{
   114 	delete iActiveScheduler;
   115 	iActiveScheduler = NULL;
   116 	
   117 	delete iScreen;
   118 	delete iWindow;
   119 	iWs.Close();
   120 	
   121 
   122 	return EPass;
   123 	}
   124 
   125 /**
   126  * CTestMMFVCLNTStep Implementation
   127  */
   128 CTestMmfMidiClntStep::CTestMmfMidiClntStep(const TDesC& aTestName, const TTestStepType aTestType)
   129 	:CTestStep(),
   130 	 iActiveScheduler( NULL )
   131 	{
   132 	// store the name of this test step
   133 	// this is the name that is used by the script file
   134 	// Each test step initialises it's own name
   135 	iTestStepName = aTestName;
   136 	iTestType = aTestType;
   137 	}
   138 
   139 CTestMmfMidiClntStep::CTestMmfMidiClntStep()
   140 	:iActiveScheduler( NULL )
   141 	// for test step that sets its own name
   142 	{
   143 	iTestType = ETestValid;
   144 	}
   145 
   146 CTestMmfMidiClntStep::~CTestMmfMidiClntStep()
   147 	{
   148 	}
   149 
   150 /*void CTestMmfMidiClntStep::Close()
   151 	{
   152 	delete iScreen;
   153 	delete iWindow;
   154 	iWs.Close();
   155 	}*/
   156 
   157 /**
   158  * DoTestStepL : same as CTestMidiClientOpenFile::DoTestStepL() but with no file opening
   159  * routines.
   160  *
   161  * Generally, test steps should NOT override this, but put their processing in DoTestL()
   162  *
   163  */
   164 TVerdict CTestMmfMidiClntStep::DoTestStepL()
   165 	{
   166 	__MM_HEAP_MARK;
   167 	CMidiClientUtility* player = CMidiClientUtility::NewL(*this, EMdaPriorityNormal, EMdaPriorityPreferenceTimeAndQuality);
   168 	if (!player)
   169 		{
   170 		ERR_PRINTF1(_L("Could not create a CMidiClientUtility"));
   171 		return EInconclusive;
   172 		}
   173 	
   174 	CleanupStack::PushL(player);
   175  
   176 	TMMFMessageDestinationPckg dummyPckg;
   177 	TInt dummyFunc = 0;		//EDevMidiOff;
   178 	TBuf8<8> dummyBuff;
   179 	player->CustomCommandSyncL(dummyPckg, dummyFunc, dummyBuff, dummyBuff, dummyBuff);
   180 
   181 	TVerdict ret = DoTestL(player);
   182 		
   183 	INFO_PRINTF1(_L("CMidiClientUtility: Destroying"));
   184 	CleanupStack::PopAndDestroy(player);
   185 
   186 	if(iError != KErrNone)
   187 		ERR_PRINTF2( _L("CMidiClientUtility failed with error %d"),iError );
   188 	
   189 	__MM_HEAP_MARKEND;
   190 	return	ret;
   191 	}
   192 
   193 TVerdict CTestMmfMidiClntStep::DoTestL(CMidiClientUtility* /*aMidi*/)
   194 	{
   195 	return EPass;
   196 	}
   197 
   198 void CTestMmfMidiClntStep::InitWservL()
   199 	{
   200 	TInt err = iWs.Connect();
   201 	if (err != KErrNone)
   202 		{
   203 		// Access violation if ws is null
   204 		INFO_PRINTF1(_L("Cannot test, no window server available"));
   205 		User::Leave(err);
   206 		}
   207 
   208 	iScreen = new (ELeave) CWsScreenDevice(iWs); // make device for this session
   209 	User::LeaveIfError(iScreen->Construct()); // and complete its construction
   210 
   211 	RWindowGroup rootWindow = RWindowGroup(iWs);
   212 	User::LeaveIfError(rootWindow.Construct((TUint32)this, ETrue));
   213 
   214 	iWindow = new(ELeave) RWindow(iWs);
   215 	User::LeaveIfError(((RWindow*)iWindow)->Construct(rootWindow,((TUint32)(this)) + 1));
   216 	iWindow->SetExtent(TPoint(0,0), TSize(100,100));
   217 	iWindow->SetVisible(ETrue);
   218 	iWindow->Activate();
   219 	iWs.Flush();
   220 	}
   221 
   222 // MMidiClientUtilityObserver
   223 
   224 void CTestMmfMidiClntStep::MmcuoStateChanged(TMidiState aOldState, TMidiState aNewState, 
   225 											  const TTimeIntervalMicroSeconds& /* aTime */, TInt aError)
   226 	{
   227 	INFO_PRINTF3(_L("MmcuoStateChanged callback, oldState = %d, newState = %d"), aOldState, aNewState);
   228 
   229 	iError = aError;
   230 	iCurrentState = aNewState;
   231 	CActiveScheduler::Stop(); // check if asynchronous
   232 	}
   233 
   234 void CTestMmfMidiClntStep::MmcuoTempoChanged(TInt /* aMicroBeatsPerMinute */)
   235 	{
   236 	INFO_PRINTF1(_L("MmcuoTempoChanged callback"));
   237 	}
   238 
   239 void CTestMmfMidiClntStep::MmcuoVolumeChanged(TInt /*aChannel*/,TReal32 /*aVolumeInDecibels*/)
   240 	{
   241 	INFO_PRINTF1(_L("MmcuoVolumeChanged callback"));
   242 	}
   243 
   244 void CTestMmfMidiClntStep::MmcuoMuteChanged(TInt /* aChannel */, TBool /* aMuted */)
   245 	{
   246 	INFO_PRINTF1(_L("MmcuoMuteChanged callback"));
   247 	}
   248 
   249 void CTestMmfMidiClntStep::MmcuoSyncUpdate(const TTimeIntervalMicroSeconds& /* aMicroSeconds */, TInt64 /* aMicroBeats */)
   250 	{
   251 	INFO_PRINTF1(_L("MmcuoSyncUpdate callback"));
   252 	}
   253 
   254 void CTestMmfMidiClntStep::MmcuoMetaDataEntryFound(const TInt /*aMetaDataEntryId*/,const TTimeIntervalMicroSeconds& /*aPosition*/)
   255 	{
   256 	INFO_PRINTF1(_L("MmcuoSmfMetaDataEntryFound callback"));
   257 	}
   258 
   259 void CTestMmfMidiClntStep::MmcuoMipMessageReceived(const RArray<TMipMessageEntry>& /* aEntry */)
   260 	{
   261 	INFO_PRINTF1(_L("MmcuoMipMessageReceived callback"));
   262 	}
   263 
   264 void CTestMmfMidiClntStep::MmcuoPolyphonyChanged(TInt /* aNewPolyphony */)
   265 	{
   266 	INFO_PRINTF1(_L("MmcuoPolyphonyChanged callback"));
   267 	}
   268 
   269 void CTestMmfMidiClntStep::MmcuoInstrumentChanged(TInt /* aChannel */, TInt /* aBankId */, TInt /* aInstrumentId */)
   270 	{
   271 	INFO_PRINTF1(_L("MmcuoInstrumentChanged callback"));
   272 	}
   273