commonappservices/alarmserver/Test/unit/src/TEAlarmTestMultipleAlarmsStep.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 "TEAlarmTestMultipleAlarmsStep.h"
       
    17 #include "TEAlarmTestMANEventObserver.h"
       
    18 
       
    19 
       
    20 // Config Parameter names
       
    21 _LIT(KAlarmNN,"Alarm%02d");
       
    22 _LIT(KEventNN,"Event%02d");
       
    23 _LIT(KActionNN,"Action%02d");
       
    24 
       
    25 // Config subparameter values
       
    26 _LIT(KStateInPreparation,	"InPreparation");
       
    27 _LIT(KStateQueued,			"Queued");
       
    28 _LIT(KStateNotifying,		"Notifying");
       
    29 _LIT(KStateWaitingToNotify,	"WaitingToNotify");
       
    30 _LIT(KStateSnoozed,			"Snoozed");
       
    31 _LIT(KStateNotified,		"Notified");
       
    32 _LIT(KVisible,				"Visible");
       
    33 _LIT(KNotVisible,			"NotVisible");
       
    34 _LIT(KSoundOn,				"Playing");
       
    35 _LIT(KSoundOff,				"NotPlaying");
       
    36 
       
    37 _LIT(KTimeFormatPattern, "%H:%T:%S.%*C3");
       
    38 _LIT(KZeroTime,"20050601:130000.000000");
       
    39 
       
    40 // Message strings
       
    41 _LIT(KExpiresInDSeconds, " expires in %d seconds");
       
    42 _LIT(KExpiresNow, " expires NOW");
       
    43 _LIT(KObserverDying, "Observer is dying (%S)");
       
    44 _LIT(KErrorDS, "ERROR (%d)     %S");
       
    45 _LIT(KErrorUnexpectedEvent, "ERROR Unexpected event %d");
       
    46 _LIT(KLitSS, "%S: %S");
       
    47 _LIT(KLitSSIgnoringEvent, "%S: %S       Ignoring the event because of UserWait mode.");
       
    48 _LIT(KLitSSExpectedS, "%S: %S       Expected %S");
       
    49 _LIT(KLitAlarmStateDSSS, "A%02d   state=%S   visible=%S   sound playing=%S");
       
    50 
       
    51 _LIT(KAlarmStateCheckPassedOK, "Alarm State check PASSED OK.");
       
    52 _LIT(KAlarmStateOnlyCheckPassedOK, "Alarm StateOnly check PASSED OK.");
       
    53 _LIT(KDoDelayedActionReconnectToCAASSuccess, \
       
    54 				"::DoDelayedActionL(): Reconnected to ConsoleAAS successfully");		
       
    55 _LIT(KDoDelayedActionReconnectToASSuccess, \
       
    56 				"::DoDelayedActionL(): Reconnected to AlarmServer successfully");
       
    57 _LIT(KDoDelayedActionCAASMaxAlarmsSetToD, \
       
    58 				"::DoDelayedActionL(): ConsoleAAS.MAXALARMS SET TO %d");
       
    59 
       
    60 _LIT(KUnexpectedAlarmState, "TEST FAILED: State of an Alarm is not as expected");
       
    61 _LIT(KUnexpectedEvent, "TEST FAILED: SEQUENCE OF EVENTS IS NOT AS EXPECTED");
       
    62 _LIT(KUnknownFailure, "TEST FAILED: Don't know what's actually happened");
       
    63 _LIT(KAlarmStateSummaryStart, "* * * ALARM STATE SUMMARY * * *");
       
    64 _LIT(KAlarmStateSummaryEnd, "* * * SUMMARY ENDS        * * *");
       
    65 				
       
    66 _LIT(KLoadedDAlarms, "GetAlarmsFromConfigL: Loaded %d Alarms");
       
    67 _LIT(KLoadedDEvents, "GetEventsFromConfigL: Loaded %d Events");
       
    68 				
       
    69 // //
       
    70 //
       
    71 // CTestStep inherited methods
       
    72 //
       
    73 // //
       
    74 
       
    75 CTEAlarmTestMultipleAlarmsStep::CTEAlarmTestMultipleAlarmsStep()
       
    76 	{
       
    77 	SetTestStepName(KTEAlarmTestMultipleAlarmsStep);
       
    78 	iInUserWaitMode = EFalse;
       
    79 	iStarted = Time::NullTTime();
       
    80 	}
       
    81 
       
    82 
       
    83 CTEAlarmTestMultipleAlarmsStep::~CTEAlarmTestMultipleAlarmsStep()
       
    84 	{
       
    85 	iCAASClient.CancelNotifications();
       
    86 	iBunchOfObservers.ResetAndDestroy();	// RPointerArray<CMANEventObserver>
       
    87 	iBunchOfDelayedHandlers.ResetAndDestroy(); // RPointerArray<CMANDelayedActionHandler>
       
    88 
       
    89 	delete iAlarmListPtr;					// CArrayFixFlat<TAlarmEntry>*
       
    90 	
       
    91 	iEventList.Close();						// RArray<TEventEntry>
       
    92 	
       
    93 	CActiveScheduler* sched = CActiveScheduler::Current();
       
    94 	delete sched;
       
    95 	CActiveScheduler::Install(NULL);
       
    96 	}
       
    97 
       
    98 
       
    99 TVerdict CTEAlarmTestMultipleAlarmsStep::doTestStepPreambleL()
       
   100 	{
       
   101 	// Need to call base class doTestPreambleL() to start AS and CAAS
       
   102 	TESTL(CTEAlarmTestStepBase::doTestStepPreambleL()==EPass);
       
   103 	
       
   104 	// Alarm list
       
   105 	iAlarmListPtr = new (ELeave) CArrayFixFlat<TAlarmEntry>(KGranularity);
       
   106 
       
   107 	// Active Scheduler
       
   108 	CActiveScheduler* sched = new (ELeave) CActiveScheduler;
       
   109 	CActiveScheduler::Install(sched);
       
   110 	
       
   111 	// Read config from ini file	
       
   112 	TESTL(GetAlarmsFromConfigL(ConfigSection(), *iAlarmListPtr));
       
   113 	TESTL(GetEventsFromConfigL(ConfigSection(), iEventList));
       
   114 	
       
   115 	// Fine
       
   116 	return TestStepResult();
       
   117 	}
       
   118 
       
   119 TVerdict CTEAlarmTestMultipleAlarmsStep::doTestStepL()
       
   120 	{
       
   121 	StartEventObserversL();
       
   122 	User::After(500000);
       
   123 	
       
   124 	iStarted.UniversalTime();
       
   125 
       
   126 	RegisterAlarmsL();
       
   127 
       
   128 	// Process Sequence of Events
       
   129 	CActiveScheduler::Start();
       
   130 
       
   131 	// Finish
       
   132 	return TestStepResult();			
       
   133 	}
       
   134 	
       
   135 	 
       
   136 
       
   137 // //
       
   138 //
       
   139 // CTEAlarmTestMultipleAlarmsStep own methods HANDLE EVENTS and DO ACTIONS
       
   140 //
       
   141 // //
       
   142 
       
   143 void CTEAlarmTestMultipleAlarmsStep::HandleEventL(TEventEntry aCurrentEvent)
       
   144 	{
       
   145 	GetAlarmListIdxbyAlarmId(aCurrentEvent);
       
   146 	
       
   147 	LogEventL(aCurrentEvent);
       
   148 	
       
   149 	if (aCurrentEvent.iError!=KErrNone)
       
   150 		{
       
   151 		return;
       
   152 		}
       
   153 
       
   154 	if (aCurrentEvent.IsAction())
       
   155 		{
       
   156 		DoDelayedActionL(aCurrentEvent);
       
   157 		if (iInUserWaitMode)
       
   158 			{
       
   159 			return;
       
   160 			}
       
   161 		}
       
   162 
       
   163 	if (aCurrentEvent.IsEvent())
       
   164 		{
       
   165 		// an Event
       
   166 		DoProcessEventL(aCurrentEvent);
       
   167 		if (iInUserWaitMode)
       
   168 			{
       
   169 			return;
       
   170 			}
       
   171 		if (!DidWeExpectThisEvent(aCurrentEvent))
       
   172 			{
       
   173 			// Test Failed: Unexpected Event
       
   174 			ReportFailureAndStopL(EUnexpectedEvent);
       
   175 			return;
       
   176 			}
       
   177 		}
       
   178 
       
   179 	// check what's next on the EventList
       
   180 	TEventEntry nextEvent = aCurrentEvent;
       
   181 
       
   182 	if (aCurrentEvent.IsEvent())
       
   183 		{
       
   184 		// if we've just processed an event, then get next event from EventList
       
   185 		if (!GetNextEvent(nextEvent))
       
   186 			{
       
   187 			// if it's the last item on the list
       
   188 			return;
       
   189 			}
       
   190 		}
       
   191 	else
       
   192 		{
       
   193 		// if we've just did an action, then have
       
   194 		// to deal with current item on the EventList
       
   195 		nextEvent = iEventList[iCurrentEventIdx];
       
   196 		}
       
   197 		
       
   198 	// as long as next item is action, do it immediately
       
   199 	// if next item is an event, then break and wait for next event
       
   200 	do	{
       
   201 		if (nextEvent.IsEvent())  
       
   202 			{
       
   203 			// go wait for next event
       
   204 			break;
       
   205 			}
       
   206 		LogEventL(nextEvent);
       
   207 		if (!DoImmediateActionL(nextEvent))
       
   208 			{
       
   209 			// needs asynchronous handling (like UserWait or failure)
       
   210 			if (iCurrentEventIdx < iEventList.Count()-1 )
       
   211 				{
       
   212 				GetNextEvent(nextEvent);
       
   213 				}
       
   214 			return; 
       
   215 			}
       
   216 	} while (GetNextEvent(nextEvent));
       
   217 
       
   218 	}
       
   219 
       
   220 
       
   221 TBool CTEAlarmTestMultipleAlarmsStep::GetNextEvent(TEventEntry& aEvent)
       
   222 	{
       
   223 	if ( iCurrentEventIdx >= iEventList.Count()-1 )
       
   224 		{
       
   225 		CActiveScheduler::Stop();
       
   226 		return EFalse;
       
   227 		}	
       
   228 	aEvent = iEventList[++iCurrentEventIdx];
       
   229 	return ETrue;
       
   230 	}
       
   231 
       
   232 
       
   233 TBool CTEAlarmTestMultipleAlarmsStep::DidWeExpectThisEvent(const TEventEntry& aEvent)
       
   234 	{
       
   235 	return (iEventList[iCurrentEventIdx]==aEvent);
       
   236 	}
       
   237 
       
   238 
       
   239 void CTEAlarmTestMultipleAlarmsStep::DoProcessEventL(const TEventEntry& aEvent)
       
   240 	{
       
   241 	switch (aEvent.iType)
       
   242 		{
       
   243 	case EEventSetAlarm:
       
   244 		AlarmAt(aEvent.iAlarmIdx).iNotifying = ETrue;
       
   245 		break;
       
   246 	case EEventVisible:
       
   247 		AlarmAt(aEvent.iAlarmIdx).iVisible = aEvent.iVisible;
       
   248 		break;
       
   249 	case EEventSoundStart:
       
   250 		AlarmAt(aEvent.iAlarmIdx).iSoundPlaying = ETrue;
       
   251 		break;
       
   252 	case EEventSoundStop:
       
   253 		AlarmAt(aEvent.iAlarmIdx).iSoundPlaying = EFalse;
       
   254 		break;
       
   255 	case EEventDelete:
       
   256 		if (aEvent.iAlarmIdx != KBogusAlarmIdx)
       
   257 			{
       
   258 			AlarmAt(aEvent.iAlarmIdx).iNotifying = EFalse;
       
   259 			}
       
   260 		else // this is a DeleteAll command
       
   261 			{
       
   262 			for (TInt i = iAlarmListPtr->Count()-1; i >= 0; i--)
       
   263 				{
       
   264 				AlarmAt(i).iNotifying = EFalse;
       
   265 				}
       
   266 			}
       
   267 		break;
       
   268 				
       
   269 	case EEventSetState:
       
   270 		// Do nothing
       
   271 		break;
       
   272 	default:	
       
   273 		ERR_PRINTF2(KErrorUnexpectedEvent, aEvent.iType);
       
   274 		User::Leave(KErrArgument);
       
   275 		break;
       
   276 		}
       
   277 	}
       
   278 
       
   279 
       
   280 TBool CTEAlarmTestMultipleAlarmsStep::DoImmediateActionL(const TEventEntry& aEvent)
       
   281 	{
       
   282 
       
   283 	switch (aEvent.iType)
       
   284 		{
       
   285 		case EActionCheckState:
       
   286 			UpdateAlarmDetails(aEvent.iAlarmIdx);
       
   287 			LogAlarmStateL(aEvent.iAlarmIdx);
       
   288 			if ( !CheckAlarmState(aEvent) )
       
   289 				{
       
   290 				// Test Failed: Alarm is in an unexpected state
       
   291 				ReportFailureAndStopL(EUnexpectedAlarmState);
       
   292 				return EFalse;
       
   293 				}
       
   294 			else
       
   295 				{
       
   296 				INFO_PRINTF1(KAlarmStateCheckPassedOK);
       
   297 				}
       
   298 			break;
       
   299 
       
   300 		case EActionCheckStateOnly:
       
   301 			UpdateAlarmDetails(aEvent.iAlarmIdx);
       
   302 			LogAlarmStateL(aEvent.iAlarmIdx);
       
   303 			if ( !CheckAlarmStateOnly(aEvent) )
       
   304 				{
       
   305 				// Test Failed: Alarm is in an unexpected state
       
   306 				ReportFailureAndStopL(EUnexpectedAlarmState);
       
   307 				return EFalse;
       
   308 				}
       
   309 			else
       
   310 				{
       
   311 				INFO_PRINTF1(KAlarmStateOnlyCheckPassedOK);
       
   312 				}
       
   313 			break;
       
   314 
       
   315 		case EActionSnooze:
       
   316 			{
       
   317 			TASShdAlarm& shdAlarm = ShdAlarmAt(aEvent.iAlarmIdx);				
       
   318 			TTime snoozeTime;
       
   319 			snoozeTime.UniversalTime();
       
   320 			snoozeTime += TTimeIntervalSeconds(aEvent.iPeriod);
       
   321 			iCAASClient.SnoozeAlarm(shdAlarm.Id(), snoozeTime);
       
   322 			}
       
   323 			break;
       
   324 
       
   325 		case EActionPauseSound:
       
   326 			{
       
   327 			TASShdAlarm& shdAlarm = ShdAlarmAt(aEvent.iAlarmIdx);				
       
   328 			TTime pauseTime;
       
   329 			pauseTime.UniversalTime();
       
   330 			pauseTime += TTimeIntervalSeconds(aEvent.iPeriod);
       
   331 			iCAASClient.PauseSoundForAlarm(shdAlarm.Id(), pauseTime);
       
   332 			}
       
   333 			break;
       
   334 
       
   335 		case EActionSilence:
       
   336 			{
       
   337 			TAlarmId alarmId = ShdAlarmAt(aEvent.iAlarmIdx).Id();
       
   338 			iCAASClient.SilenceAlarm(alarmId);
       
   339 			}
       
   340 			break;
       
   341 
       
   342 		case EActionClear:
       
   343 			if (aEvent.iAlarmIdx==KAllAlarms)
       
   344 				{
       
   345 				iCAASClient.AcknowledgeAll();
       
   346 				}
       
   347 			else 
       
   348 				{
       
   349 				TAlarmId alarmId = ShdAlarmAt(aEvent.iAlarmIdx).Id();
       
   350 				iCAASClient.AcknowledgeAlarm(alarmId);
       
   351 				}
       
   352 			break;
       
   353 
       
   354 		case EActionUserWait:
       
   355 			if (!iInUserWaitMode)
       
   356 				{
       
   357 				UserWaitL(aEvent.iPeriod);
       
   358 				return EFalse;
       
   359 				}
       
   360 			break;
       
   361 
       
   362 		case EActionReconnectToAS:
       
   363 			if (!iInUserWaitMode)
       
   364 				{
       
   365 				ReconnectToASL();
       
   366 				return EFalse;
       
   367 				}
       
   368 			break;
       
   369 
       
   370 		case EActionAddAlarm:
       
   371 			AddAlarm(aEvent.iAlarmIdx);
       
   372 			break;
       
   373 
       
   374 		case EActionDeleteAlarm:
       
   375 			{
       
   376 			TAlarmId alarmId = ShdAlarmAt(aEvent.iAlarmIdx).Id();
       
   377 			iSession.AlarmDelete(alarmId);
       
   378 			}
       
   379 			break;
       
   380 	
       
   381 		case EException:	// ...fall through
       
   382 		case EUnknown:		// ...fall through
       
   383 		default:
       
   384 				{
       
   385 				ReportFailureAndStopL(EUnexpectedAlarmState);
       
   386 				return EFalse;
       
   387 				}
       
   388 		}
       
   389 	return ETrue;
       
   390 	}
       
   391 
       
   392 
       
   393 TBool CTEAlarmTestMultipleAlarmsStep::DoDelayedActionL(const TEventEntry& aEvent)
       
   394 	{
       
   395 	switch (aEvent.iType)
       
   396 		{
       
   397 		case EActionUserWait:
       
   398 					// UserWait period completed
       
   399 					if (iInUserWaitMode)
       
   400 						{
       
   401 						iInUserWaitMode = EFalse;
       
   402 						}
       
   403 					else
       
   404 						{
       
   405 						TESTL(EFalse);
       
   406 						}
       
   407 					break;
       
   408 
       
   409 		case EActionReconnectToAS:
       
   410 					// time to reconnect to Alarm Server
       
   411 					if (iInUserWaitMode)
       
   412 						{
       
   413 						iInUserWaitMode = EFalse;
       
   414 						// connect to Alarm Server
       
   415 						TESTL(iSession.Connect()==KErrNone);
       
   416 						
       
   417 						// connect to ConsoleAlarmAlertServer
       
   418 						TESTL(iCAASClient.Connect()==KErrNone);
       
   419 						INFO_PRINTF1(KDoDelayedActionReconnectToCAASSuccess);
       
   420 						if (iMaxAlarms>0)
       
   421 							{
       
   422 							iCAASClient.SetExtendedMode();
       
   423 							iCAASClient.SetMaxAlarms(iMaxAlarms);
       
   424 							INFO_PRINTF2(KDoDelayedActionCAASMaxAlarmsSetToD, iMaxAlarms);		
       
   425 							} 
       
   426 						// connect to Alarm Server
       
   427 						TESTL(iSession.Connect()==KErrNone);
       
   428 						INFO_PRINTF1(KDoDelayedActionReconnectToASSuccess);
       
   429 						// restore observers
       
   430 						StartEventObserversL();
       
   431 						}
       
   432 					else
       
   433 						{
       
   434 						TESTL(EFalse);
       
   435 						}
       
   436 					break;
       
   437 
       
   438 		case EActionAddAlarm:
       
   439 					AddAlarm(aEvent.iAlarmIdx);
       
   440 					return EFalse;
       
   441 					
       
   442 		case EActionCheckState:		// ...fall through
       
   443 		case EActionCheckStateOnly:	// ...fall through
       
   444 		case EActionSnooze:			// ...fall through
       
   445 		case EActionClear:			// ...fall through
       
   446 		case EActionPauseSound:		// ...fall through
       
   447 		case EActionSilence:		// ...fall through
       
   448 		case EActionDeleteAlarm:	// ...fall through
       
   449 		case EException:			// ...fall through
       
   450 		case EUnknown:				// ...fall through
       
   451 		default:	
       
   452 					TESTL(EFalse);
       
   453 		}
       
   454 	return ETrue;
       
   455 	}
       
   456 
       
   457 
       
   458 
       
   459 // //
       
   460 //
       
   461 // CTEAlarmTestMultipleAlarmsStep -> ALARMS and OBSERVERS
       
   462 //
       
   463 // //
       
   464 
       
   465 
       
   466 TInt CTEAlarmTestMultipleAlarmsStep::GetAlarmListIdxbyAlarmId(TEventEntry& aEvent)
       
   467 	{
       
   468 	if (aEvent.iAlarmId==KNullAlarmId) 
       
   469 		{
       
   470 		return KBogusAlarmIdx;
       
   471 		}
       
   472 	
       
   473 	TInt nofAlarms = iAlarmListPtr->Count();
       
   474 	for (TInt idx=0; idx<nofAlarms; idx++)
       
   475 		{
       
   476 		if ( ShdAlarmAt(idx).Id() == aEvent.iAlarmId )
       
   477 			{
       
   478 			return aEvent.iAlarmIdx = idx;
       
   479 			}
       
   480 		}
       
   481 		
       
   482 	return KBogusAlarmIdx;
       
   483 	}
       
   484 
       
   485 
       
   486 void CTEAlarmTestMultipleAlarmsStep::AddObserverL(const TEventEntry& aEvent)
       
   487 	{
       
   488 	CMANEventObserver* pObserver = CMANEventObserver::NewL(aEvent, iCAASClient, *this);
       
   489 	CleanupStack::PushL(pObserver);
       
   490 	iBunchOfObservers.AppendL(pObserver);
       
   491 	CleanupStack::Pop();
       
   492 	}
       
   493 
       
   494 
       
   495 void CTEAlarmTestMultipleAlarmsStep::AddDelayedHandlerL(const TEventEntry& anAction)
       
   496 	{
       
   497 	CMANDelayedActionHandler* pHandler = 
       
   498 					CMANDelayedActionHandler::NewL(anAction, *this);
       
   499 	CleanupStack::PushL(pHandler);
       
   500 	iBunchOfDelayedHandlers.AppendL(pHandler);
       
   501 	CleanupStack::Pop();
       
   502 	}
       
   503 
       
   504 
       
   505 void CTEAlarmTestMultipleAlarmsStep::StartEventObserversL()
       
   506 	{
       
   507 	for (TEventType eventType=EEventSetAlarm; 
       
   508 				eventType<=EEventDelete; 
       
   509 					eventType=TEventType(eventType+1))
       
   510 		{
       
   511 		TEventEntry event(eventType);
       
   512 		AddObserverL(event);
       
   513 		}
       
   514 	}
       
   515 	
       
   516 	
       
   517 void CTEAlarmTestMultipleAlarmsStep::RegisterAlarmsL()
       
   518 	{
       
   519 	TEventEntry	event(EActionAddAlarm);
       
   520 	TInt nofAlarms = iAlarmListPtr->Count();
       
   521 	for (TInt idx=0; idx<nofAlarms; idx++)
       
   522 		{
       
   523 		event.iAlarmIdx = idx;
       
   524 		event.iPeriod = AlarmAt(idx).iDelay;
       
   525 		AddDelayedHandlerL(event);
       
   526 		}
       
   527 	}
       
   528 	
       
   529 
       
   530 void CTEAlarmTestMultipleAlarmsStep::UserWaitL(TInt aSeconds)
       
   531 	{
       
   532 	if (aSeconds > 0) 
       
   533 		{
       
   534 		TEventEntry	event(EActionUserWait);
       
   535 		event.iPeriod = aSeconds;
       
   536 		AddDelayedHandlerL(event);	
       
   537 		iInUserWaitMode = ETrue;
       
   538 		}
       
   539 	}
       
   540 	
       
   541 	
       
   542 void CTEAlarmTestMultipleAlarmsStep::ReconnectToASL()
       
   543 	{
       
   544 	if (KReconnectTimeout > 0) 
       
   545 		{
       
   546 		// remove observers and disconnect from ConsoleAlarmAlertServer
       
   547 		iCAASClient.CancelNotifications();
       
   548 		iBunchOfObservers.ResetAndDestroy();	// RPointerArray<CMANEventObserver>		
       
   549 		iCAASClient.Close();
       
   550 
       
   551 		// disconnect from Alarm Server
       
   552 		iSession.Close();
       
   553 		
       
   554 		// set delayed action handler for reconnect after a timeout
       
   555 		TEventEntry	event(EActionReconnectToAS);
       
   556 		event.iPeriod = KReconnectTimeout;
       
   557 		AddDelayedHandlerL(event);	
       
   558 		iInUserWaitMode = ETrue;
       
   559 		}
       
   560 	}	
       
   561 	
       
   562 	
       
   563 void CTEAlarmTestMultipleAlarmsStep::AddAlarm(TInt aAlarmIdx)
       
   564 	{
       
   565 	TAlarmEntry& alarmEntry = AlarmAt(aAlarmIdx);	
       
   566 	TASShdAlarm& shdAlarm = alarmEntry.iASShdAlarm;
       
   567 	
       
   568 	alarmEntry.iNotifying = EFalse;
       
   569 	alarmEntry.iVisible = EFalse;
       
   570 	alarmEntry.iSoundPlaying = EFalse;
       
   571 
       
   572 	// assumed that this method is called after the delay
       
   573 	TInt timeShift = alarmEntry.iOffset - alarmEntry.iDelay;
       
   574 
       
   575 	TTime now, then;
       
   576 	now.UniversalTime();
       
   577 	then = now + TTimeIntervalSeconds(timeShift);
       
   578 	shdAlarm.SetUtcNextDueTime(then);
       
   579 	shdAlarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatOnce;
       
   580 
       
   581 	iSession.AlarmAdd(shdAlarm);
       
   582 	}
       
   583 
       
   584 
       
   585 void CTEAlarmTestMultipleAlarmsStep::RemoveAlarms()
       
   586 	{
       
   587 	TInt nofAlarms = iAlarmListPtr->Count();
       
   588 	for (TInt idx=0; idx<nofAlarms; idx++)	
       
   589 		{
       
   590 		TAlarmId alarmId = ShdAlarmAt(idx).Id();
       
   591 		if (alarmId!=KNullAlarmId)
       
   592 			{
       
   593 			iSession.AlarmDelete(alarmId);
       
   594 			}
       
   595 		}
       
   596 	}
       
   597 
       
   598 
       
   599 void CTEAlarmTestMultipleAlarmsStep::UpdateAlarmDetails(TInt aAlarmIdx)
       
   600 	{
       
   601 	TASShdAlarm& shdAlarm = ShdAlarmAt(aAlarmIdx);
       
   602 	iSession.GetAlarmDetails(shdAlarm.Id(), shdAlarm);
       
   603 	}
       
   604 
       
   605 
       
   606 TBool CTEAlarmTestMultipleAlarmsStep::CheckAlarmState(const TEventEntry& aEvent)
       
   607 	{
       
   608 	TAlarmEntry& alarmEntry = AlarmAt(aEvent.iAlarmIdx);
       
   609 
       
   610 	if ( alarmEntry.iASShdAlarm.State()!=aEvent.iAlarmState ||
       
   611 					alarmEntry.iVisible!=aEvent.iVisible ||
       
   612 						alarmEntry.iSoundPlaying!=aEvent.iPlaying )
       
   613 		{
       
   614 		return EFalse;
       
   615 		}
       
   616 	
       
   617 	return ETrue;	
       
   618 	}
       
   619 	
       
   620 	
       
   621 TBool CTEAlarmTestMultipleAlarmsStep::CheckAlarmStateOnly(const TEventEntry& aEvent)
       
   622 	{
       
   623 	TAlarmEntry& alarmEntry = AlarmAt(aEvent.iAlarmIdx);
       
   624 
       
   625 	if ( alarmEntry.iASShdAlarm.State()!=aEvent.iAlarmState )
       
   626 		{
       
   627 		return EFalse;
       
   628 		}
       
   629 	
       
   630 	return ETrue;	
       
   631 	}
       
   632 
       
   633 
       
   634 // //
       
   635 //
       
   636 // CTEAlarmTestMultipleAlarmsStep -> EVENT LOGGING and stuff
       
   637 //
       
   638 // //
       
   639 
       
   640 const TDesC& CTEAlarmTestMultipleAlarmsStep::AlarmStateToStrL(TAlarmState aState)
       
   641 	{
       
   642 	switch (aState)
       
   643 		{
       
   644 		case EAlarmStateInPreparation:
       
   645 				return KStateInPreparation;
       
   646 		case EAlarmStateQueued:
       
   647 				return KStateQueued;	
       
   648 		case EAlarmStateSnoozed:
       
   649 				return KStateSnoozed;
       
   650 		case EAlarmStateWaitingToNotify:
       
   651 				return KStateWaitingToNotify;
       
   652 		case EAlarmStateNotifying:
       
   653 				return KStateNotifying;
       
   654 		case EAlarmStateNotified:
       
   655 		  		return KStateNotified;
       
   656 		default: // only those alarm states above from ASShdDefs.h are valid
       
   657 				TESTL(EFalse);
       
   658 		}
       
   659 	return KStateInPreparation;
       
   660 	}
       
   661 
       
   662 
       
   663 void CTEAlarmTestMultipleAlarmsStep::LogEventL(TEventEntry aEvent)
       
   664 	{
       
   665 	// calc relative time since start
       
   666 	TTime zeroTime(KZeroTime);
       
   667 	
       
   668 	TTime relTime;
       
   669 	TBuf<24> strRelTime;
       
   670 	relTime.UniversalTime();
       
   671 	relTime -= TTimeIntervalMicroSeconds(iStarted.Int64());
       
   672 	relTime += TTimeIntervalMicroSeconds(zeroTime.Int64());
       
   673 	relTime.FormatL(strRelTime, KTimeFormatPattern);
       
   674 	
       
   675 	TBuf<64> strThisEvent, strExpectedEvent;
       
   676 	aEvent.ToStr(strThisEvent);
       
   677 	
       
   678 	if (aEvent.iType==EActionAddAlarm)
       
   679 		{
       
   680 		TAlarmEntry& alarmEntry = AlarmAt(aEvent.iAlarmIdx);
       
   681 		TInt timeShift = alarmEntry.iOffset - alarmEntry.iDelay;
       
   682 		if (timeShift!=0)
       
   683 			{
       
   684 			strThisEvent.AppendFormat(KExpiresInDSeconds, timeShift);
       
   685 			}
       
   686 		else
       
   687 			{
       
   688 			strThisEvent.Append(KExpiresNow);
       
   689 			}
       
   690 		}
       
   691 	
       
   692 	if (aEvent.iError!=KErrNone)
       
   693 		{
       
   694 		if (aEvent.iError==KErrDied)
       
   695 			{
       
   696 			INFO_PRINTF2(KObserverDying, &strThisEvent);
       
   697 			}
       
   698 		else
       
   699 			{
       
   700 			ERR_PRINTF3(KErrorDS, aEvent.iError, &strThisEvent);
       
   701 			}
       
   702 		return;	
       
   703 		}
       
   704 
       
   705 	if (!aEvent.IsEvent())
       
   706 		{
       
   707 		INFO_PRINTF3(KLitSS, &strRelTime, &strThisEvent);
       
   708 		} 
       
   709 	else if (iInUserWaitMode)
       
   710 		{
       
   711 		INFO_PRINTF3(KLitSSIgnoringEvent, &strRelTime, &strThisEvent);
       
   712 		}
       
   713 	else 
       
   714 		{
       
   715 		iEventList[iCurrentEventIdx].ToStr(strExpectedEvent);
       
   716 		INFO_PRINTF4(KLitSSExpectedS, &strRelTime, 
       
   717 				&strThisEvent, &strExpectedEvent);
       
   718 		} 
       
   719 	}
       
   720 
       
   721 	
       
   722 void CTEAlarmTestMultipleAlarmsStep::LogAlarmStateL(TInt aAlarmIdx)
       
   723 	{
       
   724 	TAlarmEntry& alarmEntry = AlarmAt(aAlarmIdx);
       
   725 
       
   726 	INFO_PRINTF5(KLitAlarmStateDSSS,
       
   727 			aAlarmIdx, &AlarmStateToStrL(alarmEntry.iASShdAlarm.State()), 
       
   728 			&BoolToStr(alarmEntry.iVisible), &BoolToStr(alarmEntry.iSoundPlaying));
       
   729 	}
       
   730 
       
   731 
       
   732 void CTEAlarmTestMultipleAlarmsStep::ReportFailureAndStopL(TTestFailureCode aCode)
       
   733 	{
       
   734 	switch(aCode)
       
   735 		{
       
   736 		case EUnexpectedAlarmState:
       
   737 				ERR_PRINTF1(KUnexpectedAlarmState);
       
   738 				break;
       
   739 		case EUnexpectedEvent:
       
   740 				ERR_PRINTF1(KUnexpectedEvent);
       
   741 				break;
       
   742 		default: 
       
   743 				ERR_PRINTF1(KUnknownFailure);
       
   744 				break;
       
   745 		}
       
   746 
       
   747 	// Log state of alarms	
       
   748 	INFO_PRINTF1(KAlarmStateSummaryStart);
       
   749 	TInt nofAlarms = iAlarmListPtr->Count();
       
   750 	for (TInt idx=0; idx<nofAlarms; idx++)
       
   751 		{
       
   752 		UpdateAlarmDetails(idx);
       
   753 		LogAlarmStateL(idx);
       
   754 		}
       
   755 	INFO_PRINTF1(KAlarmStateSummaryEnd);
       
   756 
       
   757 	// Set test result to FAIL and stop scheduler	
       
   758 	SetTestStepResult(EFail);
       
   759 	CActiveScheduler::Stop();
       
   760 	}
       
   761 
       
   762 
       
   763 // //
       
   764 //
       
   765 // CTEAlarmTestMultipleAlarmsStep Utility methods for reading from config
       
   766 //
       
   767 // //
       
   768 
       
   769 TBool CTEAlarmTestMultipleAlarmsStep::GetAlarmsFromConfigL(const TDesC& aSectName, CArrayFixFlat<TAlarmEntry>& aResult)
       
   770 	{
       
   771 	for(TInt i=0; i <= 99; i++)
       
   772 		{
       
   773 		TAlarmEntry entry;
       
   774 		if(!GetAlarmFromConfig(aSectName, i, entry))
       
   775 			{
       
   776 			break;
       
   777 			}
       
   778 		aResult.AppendL(entry);
       
   779 		}
       
   780 
       
   781 	INFO_PRINTF2(KLoadedDAlarms, aResult.Count());
       
   782 	if (aResult.Count() <= 0)
       
   783 		{
       
   784 		return EFalse;
       
   785 		}
       
   786 
       
   787 	return ETrue;
       
   788 	}
       
   789 
       
   790 TBool CTEAlarmTestMultipleAlarmsStep::GetAlarmFromConfig(const TDesC& aSectName, TInt aAlarmIdx, TAlarmEntry& aResult)
       
   791 	{
       
   792 	TBuf<10> alarmNN;
       
   793 	alarmNN.Format(KAlarmNN, aAlarmIdx);
       
   794 	TPtrC alarmLine;
       
   795 	if(!GetStringFromConfig(aSectName, alarmNN, alarmLine))
       
   796 		{
       
   797 		return EFalse;
       
   798 		}
       
   799 
       
   800 	TInt offset;
       
   801 	TLex alarmLex(alarmLine);
       
   802 	TLex lex(alarmLex.NextToken());
       
   803 	lex.Val(offset);
       
   804 
       
   805 	TInt delay;
       
   806 	lex.Assign(alarmLex.NextToken());
       
   807 	lex.Val(delay);
       
   808 
       
   809 	aResult.iAlarmIdx = aAlarmIdx;
       
   810 	aResult.iOffset = offset;
       
   811 	aResult.iDelay = delay;
       
   812 	aResult.iSoundPlaying = EFalse;
       
   813 	aResult.iVisible = EFalse;
       
   814 
       
   815 	return ETrue;
       
   816 	}
       
   817 
       
   818 TBool CTEAlarmTestMultipleAlarmsStep::GetEventsFromConfigL(const TDesC& aSectName, RArray<TEventEntry>& aResult)
       
   819 	{
       
   820 	for(TInt i=0; i <= 99; i++)
       
   821 		{
       
   822 		TEventEntry entry;
       
   823 		if(!GetEventFromConfigL(aSectName, i, entry))
       
   824 			{
       
   825 			break;
       
   826 			}
       
   827 		aResult.AppendL(entry);
       
   828 		}
       
   829 
       
   830 	INFO_PRINTF2(KLoadedDEvents, aResult.Count());
       
   831 	if (aResult.Count() <= 0)
       
   832 		{
       
   833 		return EFalse;
       
   834 		}
       
   835 
       
   836 	return ETrue;
       
   837 	}
       
   838 
       
   839 TBool CTEAlarmTestMultipleAlarmsStep::GetEventFromConfigL(const TDesC& aSectName, TInt aEventIdx, TEventEntry& aResult)
       
   840 	{
       
   841 	TBuf<10> eventNN;
       
   842 	eventNN.Format(KEventNN, aEventIdx);
       
   843 
       
   844 	TBuf<10> actionNN;
       
   845 	actionNN.Format(KActionNN, aEventIdx);
       
   846 
       
   847 	TPtrC line;
       
   848 	if( (!GetStringFromConfig(aSectName, eventNN, line) ) &&
       
   849 		(!GetStringFromConfig(aSectName, actionNN, line)) )
       
   850 		{
       
   851 		return EFalse;
       
   852 		}
       
   853 
       
   854 	aResult.iSequenceNumber = aEventIdx;
       
   855 
       
   856 	TLex lineLex(line);
       
   857 	TLex lex(lineLex.NextToken());
       
   858 	lex.Val(aResult.iAlarmIdx);
       
   859 	TESTL(aResult.iAlarmIdx >= KAllAlarms && aResult.iAlarmIdx <= KBogusAlarmIdx);
       
   860 
       
   861 	TPtrC typeName = lineLex.NextToken();
       
   862 	aResult.iType = GetEventTypeFromString(typeName);
       
   863 	TESTL(aResult.iType != EException);
       
   864 
       
   865 
       
   866 	switch ( aResult.iType )
       
   867 		{
       
   868 	case EEventSetAlarm:		// Fall through...
       
   869 	case EEventSoundStart:		// Fall through...
       
   870 	case EEventSoundStop:		// Fall through...
       
   871 	case EEventDelete:			// Fall through...
       
   872 	case EActionSilence:		// Fall through...
       
   873 	case EActionClear:			// Fall through...
       
   874 	case EActionReconnectToAS:	// Fall through...
       
   875 	case EActionAddAlarm:		// Fall through...
       
   876 	case EActionDeleteAlarm:	// Fall through...
       
   877 	case EException:			// Fall through...
       
   878 	case EUnknown:
       
   879 		// We've read all the values for these events.
       
   880 		break;
       
   881 	case EEventSetState:
       
   882 		{
       
   883 		TLex lex(lineLex.NextToken());
       
   884 		TInt64 value;
       
   885 		lex.Val(value, EHex);
       
   886 		aResult.iAltSFlags = value;
       
   887 		}
       
   888 		break;
       
   889 	case EEventVisible:
       
   890 		// We still have the visible bool to read:
       
   891 		{
       
   892 		TPtrC visibility = lineLex.NextToken();
       
   893 		aResult.iVisible = GetBoolFromStringL(visibility);
       
   894 		}
       
   895 		break;
       
   896 	case EActionCheckState:
       
   897 		// We still have values to read:
       
   898 		{
       
   899 		// <expected state>
       
   900 		TPtrC state = lineLex.NextToken();
       
   901 		aResult.iAlarmState  = GetAlarmStateFromStringL(state);
       
   902 
       
   903 		// <sound playing>
       
   904 		TPtrC playing = lineLex.NextToken();
       
   905 		aResult.iPlaying = GetSoundPlayingFromStringL(playing);
       
   906 
       
   907 		// <visible>
       
   908 		TPtrC visibility = lineLex.NextToken();
       
   909 		aResult.iVisible = GetVisibilityFromStringL(visibility);
       
   910 		}
       
   911 		break;
       
   912 	case EActionCheckStateOnly:
       
   913 		// We still have values to read:
       
   914 		{
       
   915 		// <expected state>
       
   916 		TPtrC state = lineLex.NextToken();
       
   917 		aResult.iAlarmState  = GetAlarmStateFromStringL(state);
       
   918 		}
       
   919 		break;
       
   920 
       
   921 	case EActionSnooze:		// Fall through...
       
   922 	case EActionPauseSound:	// Fall through...
       
   923 		{
       
   924 		// <snooze period> or <pausesound period>
       
   925 		TLex lex(lineLex.NextToken());
       
   926 		lex.Val(aResult.iPeriod);	// value specified in minutes
       
   927 		aResult.iPeriod *= 60;	
       
   928 		}
       
   929 		break;
       
   930 
       
   931 	case EActionUserWait:
       
   932 		{
       
   933 		// <wait period>
       
   934 		TLex lex(lineLex.NextToken());
       
   935 		lex.Val(aResult.iPeriod);	// value specified in seconds
       
   936 		}
       
   937 		break;
       
   938 		}
       
   939 	
       
   940 	return ETrue;
       
   941 	}
       
   942 
       
   943 TEventType CTEAlarmTestMultipleAlarmsStep::GetEventTypeFromString(const TDesC& aEventString)
       
   944 	{
       
   945 	if(aEventString == KEventSetAlarm) return EEventSetAlarm;
       
   946 	if(aEventString == KEventSetState) return EEventSetState;
       
   947 	if(aEventString == KEventVisible) return EEventVisible;
       
   948 	if(aEventString == KEventSoundStart) return EEventSoundStart;
       
   949 	if(aEventString == KEventSoundStop) return EEventSoundStop;
       
   950 	if(aEventString == KEventDelete) return EEventDelete;
       
   951 	if(aEventString == KActionCheckState) return EActionCheckState;
       
   952 	if(aEventString == KActionCheckStateOnly) return EActionCheckStateOnly;	
       
   953 	if(aEventString == KActionSnooze) return EActionSnooze;
       
   954 	if(aEventString == KActionClear) return EActionClear;
       
   955 	if(aEventString == KActionPauseSound) return EActionPauseSound;	
       
   956 	if(aEventString == KActionSilence) return EActionSilence;
       
   957 	if(aEventString == KActionDeleteAlarm) return EActionDeleteAlarm;		
       
   958 	if(aEventString == KActionUserWait) return EActionUserWait;
       
   959 	if(aEventString == KActionReconnectToAS) return EActionReconnectToAS;	
       
   960 	return EException;
       
   961 	}
       
   962 
       
   963 TAlarmState CTEAlarmTestMultipleAlarmsStep::GetAlarmStateFromStringL(TPtrC& aStateString)
       
   964 	{
       
   965 	if(aStateString == KStateQueued) return EAlarmStateQueued;
       
   966 	if(aStateString == KStateNotifying) return EAlarmStateNotifying;
       
   967 	if(aStateString == KStateWaitingToNotify) return EAlarmStateWaitingToNotify;
       
   968 	if(aStateString == KStateSnoozed) return EAlarmStateSnoozed;
       
   969 	if(aStateString == KStateNotified) return EAlarmStateNotified;
       
   970 	if(aStateString == KStateInPreparation) return EAlarmStateInPreparation;
       
   971 	TESTL(EFalse); // Only the above states are valid.
       
   972 	return EAlarmStateInPreparation;
       
   973 	}
       
   974 
       
   975 TBool CTEAlarmTestMultipleAlarmsStep::GetVisibilityFromStringL(TPtrC& aVisibilityString)
       
   976 	{
       
   977 	if(aVisibilityString == KVisible) return ETrue;
       
   978 	if(aVisibilityString == KNotVisible) return EFalse;
       
   979 	TESTL(EFalse); // Only the above 2 strings are valid.
       
   980 	return EFalse;
       
   981 	}
       
   982 
       
   983 TBool CTEAlarmTestMultipleAlarmsStep::GetBoolFromStringL(TPtrC& aBoolString)
       
   984 	{
       
   985 	if(aBoolString == KTrue) return ETrue;
       
   986 	if(aBoolString == KFalse) return EFalse;
       
   987 	TESTL(EFalse); // Only the above 2 strings are valid.
       
   988 	return EFalse;
       
   989 	}
       
   990 	
       
   991 TBool CTEAlarmTestMultipleAlarmsStep::GetSoundPlayingFromStringL(TPtrC& aPlayingString)
       
   992 	{
       
   993 	if(aPlayingString == KSoundOn) return ETrue;
       
   994 	if(aPlayingString == KSoundOff) return EFalse;
       
   995 	TESTL(EFalse); // Only the above 2 strings are valid.
       
   996 	return EFalse;
       
   997 	}
       
   998