os/mm/mmlibs/mmfw/tsrc/mmfintegrationtest/SDevSound/SDSCapTestServer/src/CapTestStep.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #include "CapTestStep.h"
    17 
    18 #ifdef Required
    19 CTestStep1* CTestStep1::NewL()
    20 	{
    21 	CTestStep1* self = new (ELeave) CTestStep1;
    22 	CleanupStack::PushL(self);
    23 	self->ConstructL();
    24 	CleanupStack::Pop();
    25 	return self;
    26 	}
    27 	
    28 void CTestStep1::ConstructL()
    29 	{
    30 	iIsFirstPlayed = EFalse;
    31 	}
    32 	
    33 
    34 void CTestStep1::StartProcessing(TRequestStatus& aStatus)
    35 	{
    36 	iStatus = &aStatus;
    37 
    38 	iVerdict = EFail;
    39 	
    40 	iVerdictDS = DoTestStepPreambleL();
    41 	iVerdictDS = DoPlaySimpleTone();
    42 	}
    43 		
    44 		
    45 TVerdict CTestStep1::EndProcessingAndReturnResult(TDes8& aMessage)
    46 	{
    47 	aMessage.Copy(_L("Done"));
    48 	return EPass;
    49 	}
    50 	
    51 CTestStep1::~CTestStep1()
    52 	{
    53 	}
    54 
    55 /******************************************************************************
    56  *
    57  * DevSound methods
    58  *
    59  *****************************************************************************/
    60  
    61 /**
    62  *
    63  * DoTestStepL
    64  * @result TVerdict
    65  *
    66  */
    67 
    68 TVerdict CTestStep1::DoPlaySimpleTone()
    69 	{
    70 //	INFO_PRINTF1(_L("Testing Simple Tone Playback"));
    71 	TInt freq = 1000;
    72 	TTimeIntervalMicroSeconds dur(10000000);
    73 
    74 	//Initialize
    75 	TVerdict initOK = TestInitialize(EMMFStateTonePlaying);
    76 	if (initOK != EPass)
    77 		{
    78 		return EInconclusive;
    79 		}
    80 
    81 	TestSetPriority(0);
    82 
    83 	TestSetVolume(iMMFDevSound->MaxVolume());
    84 	iExpectedValue = KErrUnderflow;
    85 	TestPlayTone(freq, dur);
    86 	return TestPlayTone(freq, dur);
    87 	}
    88 
    89 /**
    90  *
    91  * TestInitialize
    92  * @param aMode
    93  * @result TVerdict
    94  *
    95  */
    96 
    97 TVerdict CTestStep1::TestInitialize(TMMFState aMode)
    98 	{
    99 	iCallbackError = KErrNone;
   100 	iExpectedValue = KErrNone;
   101 //	INFO_PRINTF1(_L("Initializing DevSound"));
   102 
   103 	ResetCallbacks();
   104 
   105 	// Initialize
   106 	TRAPD(err, iMMFDevSound->InitializeL(*this, aMode));
   107 	if (err)
   108 		{
   109 //		WARN_PRINTF2 (_L("DevSound InitializeL left with error = %d"), err);
   110 		return EInconclusive;
   111 		}
   112 	else
   113 		{
   114 		if (iCallbackError != iExpectedValue)
   115 			{
   116 //			ERR_PRINTF3 (_L("DevSound InitializeComplete returned %d, expected %d"), iCallbackError, iExpectedValue);
   117 			return EFail;
   118 			}
   119 		if (iCallbackArray[EInitComplete] != 1)
   120 			{
   121 //			ERR_PRINTF2 (_L("DevSound InitializeComplete was called %d times, expected 1"), iCallbackArray[EInitComplete]);
   122 			return EFail;
   123 			}
   124 		}
   125 	return EPass;
   126 	}
   127 
   128 /**
   129  *
   130  * TestPlayTone
   131  * @param aFreq
   132  * @param aDur
   133  * @result TVerdict
   134  *
   135  */
   136 TVerdict CTestStep1::TestPlayTone(TInt aFreq, TTimeIntervalMicroSeconds aDur)
   137 	{
   138 	iCallbackError = KErrNone;
   139 	//iExpectedValue = KErrUnderflow;
   140 
   141 	ResetCallbacks();
   142 
   143 //	INFO_PRINTF1(_L("Playing Simple Tone"));
   144 	TRAPD(err, iMMFDevSound->PlayToneL(aFreq, aDur));
   145 	if (err)
   146 		{
   147 //		WARN_PRINTF2 (_L("DevSound PlayToneL left with error = %d"), err);
   148 		iCallbackError = err;
   149 		return EFail;
   150 		}
   151 	else
   152 		{
   153 //		iAL->InitialiseActiveListener();
   154 		// Start the active scheduler and catch the callback
   155  		CActiveScheduler::Start();
   156 		if (iCallbackError != iExpectedValue)
   157 			{
   158 //			ERR_PRINTF3 (_L("DevSound ToneFinished returned %d, expected %d"), iCallbackError, iExpectedValue);
   159 			return EFail;
   160 			}
   161 		if (iCallbackArray[EToneFinished] != 1)
   162 			{
   163 //			ERR_PRINTF2 (_L("DevSound ToneFinished was called %d times, expected 1"), iCallbackArray[EToneFinished]);
   164 			return EFail;
   165 			}
   166 		TInt tot = GetCallbackTotal();
   167 		if (tot > 1)
   168 			{
   169 //			ERR_PRINTF2 (_L("DevSound called %d callbacks, expected 1"), tot);
   170 			return EFail;
   171 			}
   172 		}
   173 	return EPass;
   174 	}
   175 
   176 /******************************************************************************
   177  *
   178  * DevSound mixin methods
   179  *
   180  *****************************************************************************/
   181  
   182 /**
   183  *
   184  * InitializeComplete
   185  * @param aError
   186  *
   187  */
   188 void CTestStep1::InitializeComplete (TInt aError)
   189 	{
   190 //	INFO_PRINTF2(_L("DevSound called InitializeComplete with aError = %d"), aError);
   191 	iCallbackArray[EInitComplete] ++;
   192 	iCallbackError = aError;
   193 	}
   194 
   195 /**
   196  *
   197  * ToneFinished
   198  * @param aError
   199  *
   200  */
   201 void CTestStep1::ToneFinished (TInt aError)
   202 	{
   203 //	INFO_PRINTF2(_L("DevSound called ToneFinished with aError = %d"), aError);
   204 //	TRequestStatus* stat = &(iAL->iStatus);
   205 //	User::RequestComplete(stat, aError);
   206 
   207 	if( !iIsFirstPlayed )
   208 		{
   209 		// after first tone played inform client so we can be interrupted during second play
   210 		iIsFirstPlayed = ETrue;
   211 		User::RequestComplete(iStatus, aError);
   212 		}
   213 	iCallbackArray[EToneFinished] ++;
   214 	iCallbackError = aError;
   215 	CActiveScheduler::Stop();
   216 	}
   217 #endif // Required
   218