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