commonappservices/alarmserver/Test/unit/src/TEAlarmTestStepBase.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 // Copyright (c) 2005-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 "TEAlarmTestStepBase.h"
       
    17 #include <asclisoundplay.h>
       
    18 #include <asshdalarm.h>
       
    19 #include "AlarmServer.hrh"
       
    20 
       
    21 
       
    22 _LIT(KAlarm, "Alarm");
       
    23 _LIT(KAlarmTimeout, "Timeout");
       
    24 _LIT(KAlarmMessage, "Message");
       
    25 _LIT(KIntervalRepeat, "Repeat");
       
    26 _LIT(KIntervalCount, "IntervalCount");
       
    27 _LIT(KTimerContingency, "TimerContingency");
       
    28 _LIT(KMaxAlarms, "MaxAlarms");
       
    29 _LIT(KDoTestStepPreambleLCAASMaxAlarmsSetToD, \
       
    30 				"::doTestStepPreambleL(): ConsoleAAS.MAXALARMS SET TO %d");
       
    31 
       
    32 CTEAlarmTestStepBase::~CTEAlarmTestStepBase()
       
    33 	{
       
    34 
       
    35 	iSession.Close();
       
    36 #ifdef __WINS__
       
    37 	iCAASClient.Close();
       
    38 	StopConsoleAlarmAlertServer();
       
    39 #endif //  __WINS__	
       
    40 
       
    41 	}
       
    42 
       
    43 TVerdict CTEAlarmTestStepBase::doTestStepPreambleL()
       
    44 	{
       
    45 
       
    46 #ifdef __WINS__ 
       
    47 	TEST(StartConsoleAlarmAlertServerL());
       
    48 
       
    49 	User::After(500000);
       
    50 	TESTL(iCAASClient.Connect()==KErrNone);
       
    51 #endif //  __WINS__ 		
       
    52 
       
    53 	// read MaxAlarms setting from config and,
       
    54 	// if found, set CAAS to Extended mode and SetMaxAlarms 
       
    55 	if (GetIntFromConfig(ConfigSection(), KMaxAlarms, iMaxAlarms))
       
    56 		{
       
    57 		iCAASClient.SetExtendedMode();
       
    58 		iCAASClient.SetMaxAlarms(iMaxAlarms);
       
    59 		INFO_PRINTF2(KDoTestStepPreambleLCAASMaxAlarmsSetToD, iMaxAlarms);		
       
    60 		} 
       
    61 
       
    62 	// now can connect to Alarm Server
       
    63 	TESTL(iSession.Connect()==KErrNone);
       
    64 	
       
    65 	return TestStepResult();
       
    66 	
       
    67 	}
       
    68 
       
    69 /*
       
    70 Starts the ConsoleAlarmAlertServer, which is an integral component in the
       
    71 AlarmServer testing environment.
       
    72 
       
    73 @internalComponent
       
    74 */
       
    75 TBool CTEAlarmTestStepBase::StartConsoleAlarmAlertServerL()
       
    76 	{
       
    77 	INFO_PRINTF2(_L("AlarmTestStep[%X]: Starting ConsoleAlarmAlertServer"), this);
       
    78 
       
    79 	const TUid KServerUid2={0x1000008D};
       
    80 	const TUid KServerUid3={0x101F502A};
       
    81 	const TUidType serverUid(KNullUid,KServerUid2,KServerUid3);
       
    82 		
       
    83 	_LIT(KConsoleAlarmAlertServerImg,"ConsoleAlarmAlertServer");
       
    84 	TESTL((iAlertServerProcess.Create(KConsoleAlarmAlertServerImg,KNullDesC,serverUid))==KErrNone);
       
    85 
       
    86 	iAlertServerProcess.Resume();	// logon OK - start the server
       
    87 	
       
    88 	return ETrue;
       
    89 	}
       
    90 
       
    91 /*
       
    92 Stops the ConsoleAlarmAlertServer.
       
    93 
       
    94 @internalComponent
       
    95 */
       
    96 void CTEAlarmTestStepBase::StopConsoleAlarmAlertServer()
       
    97 	{
       
    98 	INFO_PRINTF2(_L("AlarmTestStep[%X]: Terminating ConsoleAlarmAlertServer "), this);
       
    99 
       
   100 	iAlertServerProcess.Terminate(0);
       
   101 	INFO_PRINTF2(_L("AlarmTestStep[%X]: Terminated ConsoleAlarmAlertServer"), this);
       
   102 	}
       
   103 
       
   104 
       
   105 /*
       
   106 Gets a specified integer from config, and converts to TTimeIntervalMinutes.
       
   107 
       
   108 @internalComponent
       
   109 @return ETrue when Section/Key was found and aResult was set, EFalse otherwise.
       
   110 @param aSectName The config section name.
       
   111 @param aKeyName  The key's name, ie the left side of the equation 'key = value'
       
   112 @param aResult The value is returned in this referenced variable
       
   113 */
       
   114 TBool CTEAlarmTestStepBase::GetOffsetFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TTimeIntervalMinutes& aResult)
       
   115 	{
       
   116 	TInt interval;	
       
   117 		
       
   118 	if(!GetIntFromConfig(aSectName, aKeyName, interval)) 
       
   119 		{
       
   120 		return EFalse;
       
   121 		}
       
   122 		
       
   123 	aResult = interval;
       
   124 	return ETrue;	
       
   125 	}
       
   126 
       
   127 /*
       
   128 Gets a specified integer from config, and converts to TTimeIntervalSeconds.
       
   129 
       
   130 @internalComponent
       
   131 @return ETrue when Section/Key was found and aResult was set, EFalse otherwise.
       
   132 @param aSectName The config section name.
       
   133 @param aKeyName  The key's name, ie the left side of the equation 'key = value'
       
   134 @param aResult The value is returned in this referenced variable
       
   135 */
       
   136 TBool CTEAlarmTestStepBase::GetOffsetFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TTimeIntervalSeconds& aResult)
       
   137 	{
       
   138 	TInt interval;	
       
   139 		
       
   140 	if(!GetIntFromConfig(aSectName, aKeyName, interval)) 
       
   141 		{
       
   142 		return EFalse;
       
   143 		}
       
   144 		
       
   145 	aResult = interval * 60;
       
   146 	return ETrue;	
       
   147 	}
       
   148 
       
   149 /*
       
   150 Gets a specified TTime value from config, from the form '<aKeyName> = HH:MM'
       
   151 
       
   152 @internalComponent
       
   153 @return ETrue when Section/Key was found and aResult was set, EFalse otherwise.
       
   154 @param aSectName The config section name.
       
   155 @param aKeyName  The key's name, ie the left side of the equation 'key = value'
       
   156 @param aResult The value is returned in this referenced variable
       
   157 */
       
   158 TBool CTEAlarmTestStepBase::GetTimeFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TTime& aResult)
       
   159 	{
       
   160 	TPtrC ptrBuf;
       
   161 
       
   162 	if (!GetStringFromConfig(aSectName, aKeyName, ptrBuf)) 
       
   163 		{
       
   164 		return EFalse;
       
   165 		}
       
   166 
       
   167 	TLex lex(ptrBuf);
       
   168 
       
   169 	TInt hour;
       
   170 	TInt min;
       
   171 
       
   172 	// HH:MM
       
   173 
       
   174 	if (lex.Val(hour) != KErrNone) 
       
   175 		{
       
   176 		return EFalse;
       
   177 		}
       
   178 
       
   179 	lex.Inc();
       
   180 		 
       
   181 	if(lex.Val(min) != KErrNone)
       
   182 		{
       
   183 		return EFalse;
       
   184 		}
       
   185 		
       
   186 	TDateTime dt;
       
   187 	dt.SetHour(hour);
       
   188 	dt.SetMinute(min);
       
   189 
       
   190 	aResult = dt;
       
   191 	return ETrue;
       
   192 	}
       
   193 
       
   194 /*
       
   195 Gets Sound Play Intervals from config, with the syntax:
       
   196 IntervalCount = <TInt>
       
   197 IntervalNN = <Offset from timer expiry(min)> <Duration of Sound (sec)>'
       
   198 
       
   199 @internalComponent
       
   200 @return ETrue when Section was found and aResult was set, EFalse otherwise.
       
   201 @param aSectName The config section name.
       
   202 @param aResult The value is returned in this referenced variable
       
   203 @leave KErrNoMemory under low memory conditions.
       
   204 */
       
   205 TBool CTEAlarmTestStepBase::GetIntervalsFromConfigL(const TDesC& aSectName, CArrayFixFlat<TASCliSoundPlayDefinition>& aResult)
       
   206 	{
       
   207 	// Get Interval info from Config
       
   208 	TInt intervalCount = 0;
       
   209 	if(!GetIntervalCountFromConfig(aSectName,intervalCount))
       
   210 		{
       
   211 		SetTestStepResult(ETestSuiteError);
       
   212 		return EFalse;
       
   213 		}
       
   214 	INFO_PRINTF2(_L("AlarmPlayConfig: NumIntervals from Config=%d"), intervalCount);
       
   215 	if (intervalCount < 0 || intervalCount > 99)
       
   216 		{
       
   217 		return EFalse;
       
   218 		}
       
   219 
       
   220 	TInt intervalIterator;
       
   221 	for (intervalIterator = 0; intervalIterator < intervalCount; intervalIterator++)
       
   222 		{
       
   223 		TTimeIntervalMinutes offset;
       
   224 		TTimeIntervalSeconds duration;
       
   225 		if (!GetIntervalFromConfig(aSectName, intervalIterator, offset, duration))
       
   226 			{
       
   227 			INFO_PRINTF2(_L("AlarmPlayConfig: Failed to load Interval #%d"), intervalIterator);
       
   228 			SetTestStepResult(ETestSuiteError);
       
   229 			return EFalse;
       
   230 			}
       
   231 		TASCliSoundPlayDefinition item(offset, duration);
       
   232 		aResult.AppendL(item);
       
   233 		}
       
   234 
       
   235 	return ETrue;
       
   236 	}
       
   237 
       
   238 /*
       
   239 Gets Sound Play Interval from config, from the form
       
   240  'IntervalNN = <Offset from timer expiry(min)> <Duration of Sound (sec)>'
       
   241 
       
   242 @internalComponent
       
   243 @return EFalse if aIntervalNumber not [0 .. 99], or the Section/Key is not found.
       
   244 @param aSectName The config section name.
       
   245 @param aIntervalNumber The numbered interval to get.
       
   246 @param aOffset The offset in minutes is returned in this referenced variable.
       
   247 @param aDuration The duration in seconds is returned in this reference variable.
       
   248 */
       
   249 TBool CTEAlarmTestStepBase::GetIntervalFromConfig(const TDesC& aSectName, const TInt aIntervalNumber, TTimeIntervalMinutes& aOffset, TTimeIntervalSeconds& aDuration)
       
   250 	{
       
   251 	TBuf<10> intervalNN;
       
   252 	intervalNN.Format(_L("Interval%02d"),aIntervalNumber);
       
   253 	TPtrC intervalLine;
       
   254 	if(!GetStringFromConfig(aSectName, intervalNN, intervalLine))
       
   255 		{
       
   256 		return EFalse;
       
   257 		}
       
   258 
       
   259 	TInt intValue;
       
   260 
       
   261 	TLex intervalLex(intervalLine);
       
   262 	TPtrC offsetPtr = intervalLex.NextToken();
       
   263 	TLex lex(offsetPtr);
       
   264 	lex.Val(intValue);
       
   265 	aOffset = intValue;
       
   266 
       
   267 	TPtrC durationPtr = intervalLex.NextToken();
       
   268 	lex.Assign(durationPtr);
       
   269 	lex.Val(intValue);
       
   270 	aDuration = intValue;
       
   271 
       
   272 	return ETrue;
       
   273 	}
       
   274 
       
   275 /*
       
   276 Gets Sound Play Interval Count from config, from the form
       
   277  'IntervalCount = <TInt>'
       
   278 
       
   279 @internalComponent
       
   280 @return ETrue when Section/Key was found and aResult was set, EFalse otherwise.
       
   281 @param aSectName The config section name.
       
   282 @param aDuration The interval count is returned in this reference variable.
       
   283 */
       
   284 TBool CTEAlarmTestStepBase::GetIntervalCountFromConfig(const TDesC& aSectName, TInt& aResult)
       
   285 	{
       
   286 	return GetIntFromConfig(aSectName,KIntervalCount,aResult);
       
   287 	}
       
   288 
       
   289 /*
       
   290 Appends TASShdAlarm's to the supplied array. It does not add the alarm.
       
   291 Alarms are specific in their own section, and are referenced from
       
   292 the testcase's section, following the following syntax:
       
   293 [<TestCase Section Name>]
       
   294 Alarm = 1 5
       
   295 
       
   296 [Alarm01]
       
   297 Message = This is the message for Alarm #1
       
   298 Timeout = <Offset from 'UTC::now' in seconds>
       
   299 
       
   300 [Alarm05]
       
   301 Message = And this is the message for Alarm #5
       
   302 Timeout = <Offset from 'UTC::now' in seconds>
       
   303 
       
   304 
       
   305 @internalComponent
       
   306 @return ETrue when Section/Key was found and all indexed alarms were found, EFalse otherwise.
       
   307 @param aSectName The config section name.
       
   308 @param aAlarmArray The alarms are appended to this referenced array.
       
   309 @leave KErrNoMemory under low memory conditions.
       
   310 */
       
   311 TBool CTEAlarmTestStepBase::GetAlarmsFromConfigL(const TDesC& aSectName, CArrayFixFlat<TASShdAlarm>& aAlarmArray)
       
   312 	{
       
   313 	TPtrC alarmLine;
       
   314 
       
   315 	if(!GetStringFromConfig(aSectName, KAlarm, alarmLine))
       
   316 		{
       
   317 		return EFalse;
       
   318 		}
       
   319 
       
   320 	TLex alarmLineLex(alarmLine);
       
   321 	TPtrC currentAlarmPtr = alarmLineLex.NextToken();
       
   322 	while(currentAlarmPtr.Length() > 0)
       
   323 		{
       
   324 		TLex alarmLex(currentAlarmPtr);
       
   325 		TInt alarmNum;
       
   326 		alarmLex.Val(alarmNum);
       
   327 		TASShdAlarm alarm;
       
   328 		if(!GetAlarmFromConfig(alarmNum, alarm))
       
   329 			{
       
   330 			return EFalse;
       
   331 			}
       
   332 		aAlarmArray.AppendL(alarm);
       
   333 		currentAlarmPtr.Set(alarmLineLex.NextToken());
       
   334 		}
       
   335 
       
   336 	return ETrue;
       
   337 	}
       
   338 
       
   339 /*
       
   340 Gets Alarm info from config, and set's the alarms internal data. It does not add the alarm.
       
   341 
       
   342 @internalComponent
       
   343 @return ETrue when Section/Keys were found and aAlarm was set, EFalse otherwise.
       
   344 @param aSectName Used to build the config section name 'AlarmNN'. It must be [0..99].
       
   345 @param aAlarm The interval count is returned in this reference variable. The next due time
       
   346       is set in UTC time.
       
   347 @see CTEAlarmTestStepBase::GetAlarmsFromConfigL
       
   348 */
       
   349 TBool CTEAlarmTestStepBase::GetAlarmFromConfig(const TInt aAlarmNumber, TASShdAlarm& aAlarm)
       
   350 	{
       
   351 	if (aAlarmNumber < 0 || aAlarmNumber > 99)
       
   352 		{
       
   353 		return EFalse;
       
   354 		}
       
   355 
       
   356 	// Compose section heading
       
   357 	TBuf<7> alarmNN;
       
   358 	alarmNN.Format(_L("Alarm%02d"), aAlarmNumber);
       
   359 
       
   360 	// Get the Message
       
   361 	TPtrC message;
       
   362 	if (!GetStringFromConfig(alarmNN, KAlarmMessage, message))
       
   363 		{
       
   364 		return EFalse;
       
   365 		}
       
   366 
       
   367 	// Get the Timeout
       
   368 	TInt interval;
       
   369 	if (!GetIntFromConfig(alarmNN, KAlarmTimeout, interval))
       
   370 		{
       
   371 		return EFalse;
       
   372 		}
       
   373 	aAlarm.Message() = message;
       
   374 
       
   375 	TTime uni;
       
   376 	uni.UniversalTime();
       
   377 	uni += TTimeIntervalSeconds(interval);
       
   378 	aAlarm.SetUtcNextDueTime(uni);
       
   379 	return ETrue;
       
   380 	}
       
   381 
       
   382 /*
       
   383 Gets Sound Play Repeat Setting from config, from the form
       
   384  'Repeat = Loop', 'Repeat = RepeatLast', or 'Repeat = Stop'
       
   385 
       
   386 @internalComponent
       
   387 @return ETrue when Section/Key was found and aResult was set, EFalse otherwise.
       
   388 @param aSectName The config section name.
       
   389 @param aResult The repeat setting is returned in this reference variable.
       
   390 */
       
   391 TBool CTEAlarmTestStepBase::GetIntervalRepeatFromConfig(const TDesC& aSectName, TAlarmSoundRepeatSetting& aResult)
       
   392 	{
       
   393 	TPtrC setting;
       
   394 	if(!GetStringFromConfig(aSectName, KIntervalRepeat, setting))
       
   395 		return EFalse;
       
   396 	if ( setting == _L("Loop") )
       
   397 		{
       
   398 		aResult = EAlarmSoundRepeatSettingLoop;
       
   399 		}
       
   400 	else if ( setting == _L("RepeatLast") )
       
   401 		{
       
   402 		aResult = EAlarmSoundRepeatSettingRepeatLast;
       
   403 		}
       
   404 	else if ( setting == _L("Stop") )
       
   405 		{
       
   406 		aResult = EAlarmSoundRepeatSettingStop;
       
   407 		}
       
   408 	else
       
   409 		{
       
   410 		return EFalse;
       
   411 		}
       
   412 	INFO_PRINTF2(_L("GetIntervalRepeatFromConfig: RepeatSetting = %d"), aResult);
       
   413 	return ETrue;
       
   414 	}
       
   415 
       
   416 /*
       
   417 Gets Sound Play Contingency from config, from the form
       
   418  'TimerContingency = <TInt>'
       
   419 
       
   420 Suggested contingency is 3 seconds, as this allows for some delay as the
       
   421 ConsoleAlarmAlertServer has to forward the events to the test steps, but
       
   422 still bounds sound events sufficiently to distinguish between occurences.
       
   423 
       
   424 @internalComponent
       
   425 @return ETrue when Section/Key was found and aResult was set, EFalse otherwise.
       
   426 @param aSectName The config section name.
       
   427 @param aResult The contingency is returned in this reference variable.
       
   428 */
       
   429 TBool CTEAlarmTestStepBase::GetTimerContingencyFromConfig(const TDesC& aSectName, TTimeIntervalSeconds& aResult)
       
   430 	{
       
   431 	TInt contingency;
       
   432 	if(!GetIntFromConfig(aSectName, KTimerContingency, contingency))
       
   433 		return EFalse;
       
   434 	aResult = contingency;
       
   435 	INFO_PRINTF2(_L("GetTimerContingencyFromConfig: Contingency = %d"), contingency);
       
   436 
       
   437 	return ETrue;
       
   438 	}
       
   439 
       
   440 /*
       
   441 Compares the two supplied arrays of Sound Play Definitions (Sound Intervals).
       
   442 
       
   443 @internalComponent
       
   444 @return aFirst==aSecond, including count and ordered entries.
       
   445 @param aFirst The first set of Sound Intervals
       
   446 @param aSecond The second set of Sound Intervals
       
   447 */
       
   448 TBool CTEAlarmTestStepBase::CompareAlarmPlayIntervals(CArrayFixFlat<TASCliSoundPlayDefinition>& aFirst, CArrayFixFlat<TASCliSoundPlayDefinition>& aSecond)
       
   449 	{
       
   450 	if ( aFirst.Count() != aSecond.Count() )
       
   451 		{
       
   452 		INFO_PRINTF3(_L("SoundPlay array sizes differ: %d != %d"), aFirst.Count(), aSecond.Count());
       
   453 		return EFalse;
       
   454 		}
       
   455 
       
   456 	TInt count = aFirst.Count();
       
   457 	for(TInt i=0; i < count; i++)
       
   458 		{
       
   459 		if ( (aFirst.At(i).Offset().Int() != aSecond.At(i).Offset().Int()) ||
       
   460 		     (aFirst.At(i).Duration().Int() != aSecond.At(i).Duration().Int()) )
       
   461 			{
       
   462 			INFO_PRINTF6(_L("SoundPlay Element[%d] differ, (%d,%d) != (%d,%d)"),
       
   463 					count, aSecond.At(i).Offset().Int(), aSecond.At(i).Duration().Int(),
       
   464 					aFirst.At(i).Offset().Int(), aFirst.At(i).Duration().Int());
       
   465 			return EFalse;
       
   466 			}
       
   467 		}
       
   468 	return ETrue;
       
   469 	}