phonebookengines/contactsmodel/tsrc/Integration/PerfFuncSuite/src/NotificationStep.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 // Copyright (c) 2006-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 // These tests attempt to overload the transaction / event queue
       
    15 // by calling many operations before the active scheduler is started
       
    16 // or by calling the operations within the active scheduler.
       
    17 // Unknownchanges event should be generated when queue is overloaded
       
    18 // 
       
    19 //
       
    20 
       
    21 /**
       
    22  @file 
       
    23  @publishedAll
       
    24  @released
       
    25 */
       
    26 #include "NotificationStep.h"
       
    27 #include "PerformanceFunctionalityDefs.h"
       
    28 #include "CCntEventQueue.h"
       
    29 
       
    30 _LIT(KRun1,"UnkownChange");
       
    31 _LIT(KRun2,"TransactionUnkown");
       
    32 _LIT(KRun3,"TransactionUnkownPlus");
       
    33 _LIT(KRun4,"RevertTransactionUnkown");
       
    34 _LIT(KRun5,"RevertTransactionUnkownPlus");
       
    35 
       
    36 _LIT(KTest1, "unknown changes notification test");
       
    37 _LIT(KTest2, "Transaction unknown changes notification test");
       
    38 _LIT(KTest3, "Transaction unknown changes plus additional changes notification test");
       
    39 
       
    40 const TInt KTimeout = 5000000;//5 seconds timeout
       
    41 const TInt KPlusContacts = 10;
       
    42 const TInt KInitialCount = -1;
       
    43 
       
    44 #define KNumberOfContacts 10
       
    45 
       
    46 CNotificationStep::CNotificationStep() 
       
    47 					: 	CPerformanceFunctionalityBase( KNumberOfContacts ),
       
    48 						iMessageCount( KInitialCount )
       
    49 	{
       
    50 	SetTestStepName(KNotificationStep);
       
    51 	}
       
    52 	
       
    53 void CNotificationStep::PreTestL()
       
    54 	{
       
    55 	iMyActive = new (ELeave) CNotificationStep::CNotificationActive( this );
       
    56 	}
       
    57 	
       
    58 CNotificationStep::~CNotificationStep()
       
    59 	{
       
    60 	CLEAR(iMyActive);
       
    61 	}
       
    62 /**
       
    63 checks notifications are received and makes sure that they're correct,
       
    64 times out if notification is not received after timeout period
       
    65 */	
       
    66 void CNotificationStep::CNotificationActive::RunL()
       
    67 	{
       
    68 	_LIT(KDatabaseGenerated,"Database Generated");
       
    69 	_LIT(KExpected,"Expected");
       
    70 	iStep->iEnd.UniversalTime();
       
    71 
       
    72 	
       
    73 	if( iStep->iEnd.MicroSecondsFrom( iStep->iStart ).Int64() > KTimeout ) //test has timed out
       
    74 		{
       
    75 		 _LIT(KTimedOut,"CNotificationStep listener has timed out");
       
    76 		iStep->ERR_PRINTF1(KTimedOut );
       
    77 		iStep->PrintNotifications(KDatabaseGenerated, *iStep->iDBEvents, *iStep->iDBContacts);
       
    78 		iStep->PrintNotifications(KExpected, *iStep->iSharedEvents, *iStep->iSharedContacts);
       
    79 		iStep->TEST1( EFalse, ETrue );//fail test
       
    80 		iStep->ResetArrays();
       
    81 		iStep->iMessageCount = KInitialCount;
       
    82 		iStep->iStart.UniversalTime();
       
    83 		CActiveScheduler::Stop();
       
    84 		}
       
    85 	else if( iStep->iMessageCount > KInitialCount )// if zero or more notifications are expected
       
    86 		{
       
    87 		//all expected messages have been received
       
    88 		if( iStep->iMessageCount == iStep->iSharedEvents->Count() 
       
    89 			&& iStep->iMessageCount == iStep->iSharedContacts->Count()
       
    90 			&& iStep->iMessageCount == iStep->iDBEvents->Count() 
       
    91 			&& iStep->iMessageCount == iStep->iDBContacts->Count() )
       
    92 			{
       
    93 			const TBool chk = (iStep->*iCheck)();
       
    94 			iStep->TEST1( chk  , ETrue );
       
    95 			//if test fails
       
    96 			if(!chk)
       
    97 				{
       
    98 				iStep->PrintNotifications(KDatabaseGenerated, *iStep->iDBEvents, *iStep->iDBContacts);
       
    99 				iStep->PrintNotifications(KExpected, *iStep->iSharedEvents, *iStep->iSharedContacts);
       
   100 				}
       
   101 			iStep->iMessageCount = KInitialCount;
       
   102 			iStep->ResetArrays();
       
   103 			iStep->iStart.UniversalTime();
       
   104 			CActiveScheduler::Stop();	
       
   105 			}
       
   106 		else//wait for rest of db message to be propogated
       
   107 			{
       
   108 			Activate();
       
   109 			}
       
   110 		}
       
   111 	else //test hasnt timed out and no notifications are expected
       
   112 		{
       
   113 		if( !iClear )//not expecting to receive notifications for contacts added in preamble, fail test.
       
   114 			{			
       
   115 			_LIT(KEmptyTestError,"CNotificationStep::CNotificationActive::RunL: Notifications have not been queued up");
       
   116 			iStep->ERR_PRINTF1(KEmptyTestError );
       
   117 			iStep->TEST1( EFalse, ETrue );//fail test
       
   118 			iStep->ResetArrays();
       
   119 			iStep->iMessageCount = KInitialCount;
       
   120 			CActiveScheduler::Stop();
       
   121 			}
       
   122 		//expecting to receive notifications for contacts added in preamble, have received all expected notifications
       
   123 		else if( iStep->iDBContacts->Count() >= KNumberOfContacts )
       
   124 			{
       
   125 			iStep->ResetArrays();
       
   126 			iStep->iMessageCount = KInitialCount;
       
   127 			CActiveScheduler::Stop();
       
   128 			}
       
   129 		else//have not received all expected notifications from contacts added in preamble
       
   130 			{
       
   131 			Activate();
       
   132 			}
       
   133 		}
       
   134 	}
       
   135 	
       
   136 void CNotificationStep::CNotificationActive::DoCancel()
       
   137 	{
       
   138 	}
       
   139 
       
   140 TInt CNotificationStep::CNotificationActive::RunError(TInt aError)
       
   141 	{
       
   142 	 _LIT(KActiveError,"CNotificationStep:: Error in doTest runL: %d");
       
   143 	iStep->ERR_PRINTF2(KActiveError, aError );
       
   144 	return aError;
       
   145 	}
       
   146 
       
   147 void CNotificationStep::CNotificationActive::Activate()
       
   148 	{
       
   149 	if(!IsActive())
       
   150 		{
       
   151 		TRequestStatus *pS=&iStatus;
       
   152 		User::RequestComplete(pS,KErrNone);
       
   153 		SetActive();
       
   154 		}
       
   155 	}
       
   156 	
       
   157 //receives notificaiton from database
       
   158 void CNotificationStep::CNotificationActive::HandleDatabaseEventL(TContactDbObserverEvent aEvent)
       
   159 	{  
       
   160 	iStep->iDBContacts->Append(aEvent.iContactId);
       
   161 	iStep->iDBEvents->Append(aEvent.iType);
       
   162 	Activate();
       
   163 
       
   164 	}
       
   165 
       
   166 void CNotificationStep::InitializeL()
       
   167 	{
       
   168 	CPerformanceFunctionalityBase::InitializeL();
       
   169 	iNotifier = CContactChangeNotifier::NewL(*iContactsDatabase, iMyActive);
       
   170 	iSharedContacts = new (ELeave)RArray<TInt>();
       
   171 	iSharedEvents = new (ELeave)RArray<TInt>();
       
   172 	iDBContacts = new (ELeave)RArray<TInt>();
       
   173 	iDBEvents = new (ELeave)RArray<TInt>();
       
   174 	}
       
   175 
       
   176 void CNotificationStep::Cleanup()
       
   177 	{
       
   178 	if( iSharedEvents )
       
   179 		{
       
   180 		iSharedEvents->Reset();
       
   181 		CLEAR(iSharedEvents);
       
   182 		}
       
   183 	if( iSharedContacts )
       
   184 		{
       
   185 		iSharedContacts->Reset();
       
   186 		CLEAR(iSharedContacts);
       
   187 		}
       
   188 	if( iDBEvents )
       
   189 		{
       
   190 		iDBEvents->Reset();
       
   191 		CLEAR(iDBEvents);
       
   192 		}
       
   193 	if( iDBContacts )
       
   194 		{
       
   195 		iDBContacts->Reset();
       
   196 		CLEAR(iDBContacts);
       
   197 		}
       
   198 	CLEAR( iNotifier );
       
   199 	CPerformanceFunctionalityBase::Cleanup();
       
   200 	}
       
   201 
       
   202 TVerdict CNotificationStep::doTestStepL()
       
   203 	{
       
   204 	__UHEAP_MARK;
       
   205 	InitializeL();
       
   206 	
       
   207 	_LIT(KDoStepPrint,"CNotificationStep::doTestStepL()");
       
   208 	INFO_PRINTF1(KDoStepPrint);  //Block start 
       
   209 	iIterate->Reset();
       
   210 	
       
   211 	CActiveScheduler::Add(iMyActive);
       
   212 	ClearNotifications();
       
   213 	
       
   214 	const TDesC &run = ConfigSection();
       
   215 	
       
   216 	if( run == KRun1 )
       
   217 		{
       
   218 		UnkownChangeTestL();
       
   219 		}
       
   220 	else if( run == KRun2 )
       
   221 		{
       
   222 		TransactionUnkownChangeTestL( EFalse );
       
   223 		}
       
   224 	else if( run == KRun3 )
       
   225 		{
       
   226 		PlusTransactionUnkownChangeTestL( EFalse );
       
   227 		}
       
   228 	else if( run == KRun4 )
       
   229 		{
       
   230 		TransactionUnkownChangeTestL( ETrue );
       
   231 		}
       
   232 	else if( run == KRun5 )
       
   233 		{
       
   234 		PlusTransactionUnkownChangeTestL( ETrue );
       
   235 		}
       
   236 	else
       
   237 		{
       
   238 		MissingTestPanic();
       
   239 		}
       
   240 
       
   241 	Cleanup();
       
   242 	__UHEAP_MARKEND;
       
   243 
       
   244 	return TestStepResult();
       
   245 	}
       
   246 	
       
   247 void CNotificationStep::ClearNotifications()
       
   248 	{
       
   249 	//clear any prior notifications, due to adding contacts...
       
   250 	iMyActive->iClear = ETrue;
       
   251 	iMyActive->iCheck = &CNotificationStep::UnkownChangeCheck;
       
   252 	iMyActive->Activate();
       
   253 	iStart.UniversalTime();
       
   254 	CActiveScheduler::Start();
       
   255 	iMyActive->iClear = EFalse;
       
   256 	}
       
   257 
       
   258 void CNotificationStep::ResetArrays()
       
   259 	{		
       
   260 	iSharedEvents->Reset();
       
   261 	iSharedContacts->Reset(); 
       
   262 	iDBContacts->Reset();
       
   263 	iDBEvents->Reset();
       
   264 	}
       
   265 /**
       
   266 add event to array and increment message count
       
   267 */
       
   268 void CNotificationStep::AddEventL(const TInt aEvent)
       
   269 	{
       
   270 	iSharedEvents->AppendL(aEvent);
       
   271 	//increment message count, if message count uninitialized, set to 1.
       
   272 	( ( iMessageCount < 0 ) ? ( iMessageCount=1 ) : ++iMessageCount );
       
   273 	}
       
   274 	
       
   275 /**
       
   276 add contact to array
       
   277 */
       
   278 void CNotificationStep::AddContactL(const TInt aCid)
       
   279 	{
       
   280 	iSharedContacts->AppendL( aCid );
       
   281 	//message count will be incremented in addevent
       
   282 	}
       
   283 
       
   284 /**
       
   285 commit or rollback transaction as necessary, recover database if damage by rollback
       
   286 */
       
   287 void CNotificationStep::EndTransactionL(const TBool aRevert)
       
   288 	{
       
   289 	if(aRevert)
       
   290 		{
       
   291 		iContactsDatabase->DatabaseRollback();
       
   292 		AddEventL( EContactDbObserverEventRollback );
       
   293 		AddContactL( KNullContactId );
       
   294 		CleanupStack::Pop();
       
   295 		if( iContactsDatabase->IsDamaged() )
       
   296 			{
       
   297 			iContactsDatabase->RecoverL();
       
   298 			AddEventL( EContactDbObserverEventTablesClosed );
       
   299 			AddContactL( 0 );
       
   300 			AddEventL( EContactDbObserverEventTablesOpened );
       
   301 			AddContactL( 0 );
       
   302 			}
       
   303 		}
       
   304 	else
       
   305 		{
       
   306 		iContactsDatabase->DatabaseCommitLP(EFalse);
       
   307 		}
       
   308 	}
       
   309 	
       
   310 void CNotificationStep::UnkownChangeTestL()
       
   311 	{
       
   312 	INFO_PRINTF1(KTest1);
       
   313 	TContactItemId cid = iIterate->NextL();
       
   314 	TInt i = 0;
       
   315 	for( ; i < KMaxNumberOfEventsInEventQueue + 10; ++i )
       
   316 		{
       
   317 		OpenL( cid );
       
   318 		CommitL( EFalse );
       
   319 		}
       
   320 	AddEventL( EContactDbObserverEventContactChanged );
       
   321 	AddContactL( cid );
       
   322 	AddEventL( EContactDbObserverEventUnknownChanges );
       
   323 	AddContactL( -1 );
       
   324 	iMyActive->iCheck = &CNotificationStep::UnkownChangeCheck;
       
   325 	iMyActive->Activate();
       
   326 	iStart.UniversalTime();
       
   327 	CActiveScheduler::Start();
       
   328 	}	
       
   329 				
       
   330 /**
       
   331 check for unkownchange notification cause by the session queue being overloaded
       
   332 */	
       
   333 TBool CNotificationStep::UnkownChangeCheck()
       
   334 	{
       
   335 	TBool SingleCheck = EFalse;
       
   336 	TBool OverallResult = ETrue;
       
   337 	
       
   338 	TESTPRINT( SingleCheck = ( iSharedContacts->Count() == iDBContacts->Count()) );
       
   339 	OverallResult = OverallResult && SingleCheck;
       
   340 	
       
   341 	TESTPRINT( SingleCheck = ( iSharedEvents->Count() == iDBEvents->Count() ) );
       
   342 	OverallResult = OverallResult && SingleCheck;
       
   343 	
       
   344 	TESTPRINT( SingleCheck = ( iSharedEvents->Count() == iSharedContacts->Count() ) );
       
   345 	OverallResult = OverallResult && SingleCheck;
       
   346 	
       
   347 	TInt length = iSharedContacts->Count();
       
   348 	TInt i = 0;
       
   349 	for(; i < length; ++i )
       
   350 		{
       
   351 		TESTPRINTI( SingleCheck = ( iSharedContacts->Find( (*iDBContacts)[i] ) > KErrNotFound ), i );
       
   352 		OverallResult = OverallResult && SingleCheck;
       
   353 		
       
   354 		TESTPRINTI( SingleCheck = ( iSharedEvents->Find( (*iDBEvents)[i] ) > KErrNotFound ) , i );
       
   355 		OverallResult = OverallResult && SingleCheck;
       
   356 		}
       
   357 	
       
   358 	return OverallResult;
       
   359 	}
       
   360 
       
   361 /**
       
   362 check for unknownchange notification cause by the transaction queue being overloaded
       
   363 */	
       
   364 void CNotificationStep::TransactionUnkownChangeTestL(const TBool aRevert)
       
   365 	{
       
   366 	INFO_PRINTF1(KTest2);
       
   367 	
       
   368 	TContactItemId cid = iIterate->NextL();
       
   369 	TInt i = 0;
       
   370 	iContactsDatabase->DatabaseBeginLC(EFalse);
       
   371 	for( ; i < KMaxNumberOfEventsInEventQueue + 1; ++i )
       
   372 		{
       
   373 		OpenL( cid );
       
   374 		CommitL( ETrue );
       
   375 		}
       
   376 	EndTransactionL( aRevert );
       
   377 	
       
   378 	if( !aRevert )
       
   379 		{
       
   380 		AddEventL( EContactDbObserverEventUnknownChanges );
       
   381 		AddContactL( -1 );
       
   382 		}
       
   383 	iMyActive->iCheck = &CNotificationStep::TransactionUnkownChangeCheck;
       
   384 	iMyActive->Activate();
       
   385 	iStart.UniversalTime();
       
   386 	CActiveScheduler::Start();
       
   387 	}					
       
   388 	
       
   389 TBool CNotificationStep::TransactionUnkownChangeCheck()
       
   390 	{
       
   391 	TBool SingleCheck = EFalse;
       
   392 	TBool OverallResult = ETrue;
       
   393 	
       
   394 	TESTPRINT( SingleCheck = ( iMessageCount == iDBContacts->Count() ) );
       
   395 	OverallResult = OverallResult && SingleCheck;
       
   396 	
       
   397 	TESTPRINT( SingleCheck = ( iMessageCount == iDBEvents->Count() ) );
       
   398 	OverallResult = OverallResult && SingleCheck;
       
   399 	
       
   400 	TInt length = iSharedContacts->Count();
       
   401 	TInt i = 0;
       
   402 	for(; i < length; ++i )
       
   403 		{
       
   404 		TESTPRINTI( SingleCheck = ( iSharedContacts->Find( (*iDBContacts)[i] ) > KErrNotFound ), i );
       
   405 		OverallResult = OverallResult && SingleCheck;
       
   406 	
       
   407 		TESTPRINTI( SingleCheck = ( iSharedEvents->Find( (*iDBEvents)[i] ) > KErrNotFound ), i );
       
   408 		OverallResult = OverallResult && SingleCheck;	
       
   409 		}
       
   410 
       
   411 	return OverallResult;
       
   412 	}	
       
   413 
       
   414 void CNotificationStep::PlusTransactionUnkownChangeTestL(const TBool aRevert)
       
   415 	{
       
   416 	INFO_PRINTF1(KTest3);
       
   417 	
       
   418 	TContactItemId cid = iIterate->NextL();
       
   419 	TInt i = 0;
       
   420 	for( ; i < KPlusContacts; ++i )
       
   421 		{
       
   422 		OpenL( cid );
       
   423 		CommitL( EFalse );
       
   424 		}
       
   425 		
       
   426 	TInt many = aRevert ? KPlusContacts : 1;
       
   427 	for( i = 0; i < many; ++i )
       
   428 		{
       
   429 		AddEventL( EContactDbObserverEventContactChanged );
       
   430 		AddContactL( cid );
       
   431 		}
       
   432 	
       
   433 	cid = iIterate->NextL();
       
   434 	iContactsDatabase->DatabaseBeginLC(EFalse);
       
   435 	for( i = 0; i < KMaxNumberOfEventsInEventQueue + 1; ++i )
       
   436 		{
       
   437 		OpenL( cid );
       
   438 		CommitL( ETrue );
       
   439 		}
       
   440 	EndTransactionL( aRevert );
       
   441 	
       
   442 	if( !aRevert )
       
   443 		{
       
   444 		AddEventL( EContactDbObserverEventUnknownChanges );
       
   445 		AddContactL( -1 );
       
   446 		iMyActive->iCheck = &CNotificationStep::UnkownChangeCheck;
       
   447 		}
       
   448 	else
       
   449 		{
       
   450 		iMyActive->iCheck = &CNotificationStep::TransactionUnkownChangeCheck;
       
   451 		}
       
   452 	iMyActive->Activate();
       
   453 	iStart.UniversalTime();
       
   454 	CActiveScheduler::Start();
       
   455 	}					
       
   456 	
       
   457 
       
   458