pimappservices/calendar/tsrc/tcal_observer_manager.cpp
changeset 0 f979ecb2b13e
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     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 "tcal_observer_manager.h"
       
    17 #include "tcal_observer_modifier.h"
       
    18 	
       
    19 GLDEF_D TInt RunTestThread(TAny* /*aArgs*/);
       
    20 
       
    21 LOCAL_D const TTimeIntervalMicroSeconds32 KWait1second(1000000); // 1 second
       
    22 LOCAL_D const TInt KMaxHeapSize = 0x40000;
       
    23 
       
    24 LOCAL_D RTest test(_L("tcal_observer"));
       
    25 	
       
    26 CTestAppManager* CTestAppManager::NewLC()
       
    27 	{
       
    28 	CTestAppManager* self = new(ELeave) CTestAppManager();
       
    29 	
       
    30 	CleanupStack::PushL(self);
       
    31 	self->ConstructL();
       
    32 
       
    33 	return (self);
       
    34 	}
       
    35 	
       
    36 void CTestAppManager::ConstructL()
       
    37 	{
       
    38 	CTestApp::ConstructL();
       
    39 	iCalTestLibrary = CCalTestLibrary::NewL();
       
    40 	iCalTestLibrary->ReplaceFileL(KCalendarFile());
       
    41 	iCalTestLibrary->OpenFileL(KCalendarFile());
       
    42 	iTimer = CPeriodic::NewL(CActive::EPriorityStandard);
       
    43 	User::LeaveIfError(iThread.Create(KThreadName(), RunTestThread, KDefaultStackSize, KMinHeapSize, KMaxHeapSize, NULL, EOwnerProcess));
       
    44 	iChunk.CreateGlobal(KChunkName(), sizeof(TInt) + (sizeof(TCalChangeEntry) * 6000), sizeof(TInt) + (sizeof(TCalChangeEntry) * 6000));	
       
    45 	iChunk.OpenGlobal(KChunkName(), ETrue);
       
    46 	iNumExpectedChanges = reinterpret_cast<TInt*>(iChunk.Base());
       
    47 	iExpectedChanges = sizeof(TInt) + reinterpret_cast<TCalChangeEntry*>(iChunk.Base());
       
    48 	}
       
    49 	
       
    50 CTestAppManager::~CTestAppManager()
       
    51 	{
       
    52 	delete iCalTestLibrary;
       
    53 	iThread.Close();
       
    54 	}
       
    55 	
       
    56 TInt CTestAppManager::StopWaitingForNotification(TAny* aPtr)
       
    57 	{
       
    58 	CTestAppManager* manager = static_cast<CTestAppManager*>(aPtr);
       
    59 	if (manager)
       
    60 		{
       
    61 		manager->DoStopWaitingForNotification();
       
    62 		}
       
    63 	CActiveScheduler::Stop();
       
    64 	return KErrNone;
       
    65 	}
       
    66 
       
    67 void CTestAppManager::DoStopWaitingForNotification()
       
    68 	{
       
    69 	test.Printf(_L("No notification received\n"));
       
    70 	iTimer->Cancel();
       
    71 	}
       
    72 	
       
    73 // callback function for change notification
       
    74 void CTestAppManager::CalChangeNotification(RArray<TCalChangeEntry>& aChangeItems)
       
    75 	{
       
    76 	test.Printf(_L("%d notifications received\n"), aChangeItems.Count());
       
    77 
       
    78 	iNotified = ETrue;	
       
    79 	iTimer->Cancel();
       
    80 	CActiveScheduler::Stop();
       
    81 	
       
    82 	// Test that the total number of notifications so far
       
    83 	// is not greater than the amount that we are expecting
       
    84 	test( aChangeItems.Count() + iNumChangesFound <= *iNumExpectedChanges );
       
    85 	TInt count = aChangeItems.Count();
       
    86 	if(aChangeItems[0].iChangeType != MCalChangeCallBack2::EChangeUndefined)
       
    87 		{
       
    88 		for (TInt i(0) ; i < count ; ++i)
       
    89 			{
       
    90 			const TCalChangeEntry KActualChange = aChangeItems[i];
       
    91 			test.Printf(_L("Change From CallBack ==> Entry LocalUid = %d; Entry type = %d; Change type = %d\n"), KActualChange.iEntryId, KActualChange.iEntryType, KActualChange.iChangeType);
       
    92 			TBool changeTypeCorrect(EFalse);
       
    93 			
       
    94 			// for each notification we have received
       
    95 			// make sure the correct details are in our expected changes  
       
    96 			for (TInt j(0) ; j < *iNumExpectedChanges ; ++j)
       
    97 				{
       
    98 				const TCalChangeEntry KExpectedChange = iExpectedChanges[j];
       
    99 				
       
   100 				if (KExpectedChange.iEntryId == KActualChange.iEntryId ||
       
   101 					KExpectedChange.iEntryId == 0)
       
   102 					{
       
   103 					if (KActualChange.iChangeType == KExpectedChange.iChangeType &&
       
   104 						KActualChange.iEntryType == KExpectedChange.iEntryType)
       
   105 						{
       
   106 						test.Printf(_L("Change Found ==> Entry Id = %d; Entry type = %d; Change type = %d\n"), KExpectedChange.iEntryId, KExpectedChange.iEntryType, KExpectedChange.iChangeType);
       
   107 						changeTypeCorrect = ETrue;
       
   108 						test(KExpectedChange.iEntryType == KActualChange.iEntryType);
       
   109 						
       
   110 						if(KActualChange.iChangeType == MCalChangeCallBack2::EChangeAdd || 
       
   111 						   KActualChange.iChangeType == MCalChangeCallBack2::EChangeModify)
       
   112 							{
       
   113 							TRAPD(err, TestFetchEntryByGuidL(KActualChange.iEntryId));
       
   114 							test(err==KErrNone);
       
   115 							}
       
   116 						}
       
   117 					}
       
   118 				}
       
   119 			test(changeTypeCorrect);
       
   120 			}
       
   121 		}
       
   122 	// Pause the thread to simulate some extra processing that would occur on a real device
       
   123 	// this will allow the modifying thread to add more than one entry between notifications
       
   124 	User::After(18750);
       
   125 
       
   126 	iNumChangesFound += aChangeItems.Count();
       
   127 	}
       
   128 	
       
   129 void CTestAppManager::TestFetchEntryByGuidL(TCalLocalUid localId)
       
   130 	{
       
   131 	CCalEntry* entry = iCalTestLibrary->SynCGetEntryViewL().FetchL(localId);
       
   132 	CleanupStack::PushL(entry);
       
   133 	const TDesC8& uid = entry->UidL();
       
   134 						
       
   135 	HBufC8* guid= uid.AllocLC();
       
   136 	RPointerArray<CCalEntry> entries;
       
   137 	CleanupResetAndDestroyPushL(entries);
       
   138 	iCalTestLibrary->SynCGetEntryViewL().FetchL(*guid, entries);
       
   139 		
       
   140 	CCalEntry* entryFetchen = entries[0];
       
   141 	test(entries.Count()>0);
       
   142 	test(entryFetchen!=NULL);
       
   143 	CleanupStack::PopAndDestroy(&entries);
       
   144 	CleanupStack::PopAndDestroy(guid);
       
   145 	CleanupStack::PopAndDestroy(entry);
       
   146 	}
       
   147 	
       
   148 void CTestAppManager::RunTestL()
       
   149 	{
       
   150 	// Set up notification filter (all entries in 2005)	
       
   151 	TCalTime calStartTime;
       
   152 	calStartTime.SetTimeLocalL(KRangeStartTime);// 1 Jan 05
       
   153 	TCalTime calEndTime;
       
   154 	calEndTime.SetTimeLocalL(KRangeEndTime);// 1 Jan 06
       
   155 	CCalChangeNotificationFilter* filter = CCalChangeNotificationFilter::NewL(MCalChangeCallBack2::EChangeEntryAll, ETrue, CalCommon::TCalTimeRange(calStartTime, calEndTime));
       
   156 	CleanupStack::PushL(filter);
       
   157 	iCalTestLibrary->GetSession().StartChangeNotification(*this, *filter);
       
   158 	CleanupStack::PopAndDestroy(filter);
       
   159 	
       
   160 	for (*iTestCase = 0; *iTestCase < EAmount ; ++*iTestCase)
       
   161 		{
       
   162 		TBool notified(EFalse);
       
   163 		iNumChangesFound = 0;
       
   164 		
       
   165 		// Allow the modifier to start preparing for the next test		
       
   166 		iThread.Resume(); 
       
   167 		
       
   168 		NextTestL();
       
   169 
       
   170 		// Wait until the modifier has prepared for the next test
       
   171 		iSemaphore.Wait(); 			
       
   172 		
       
   173 		do	{
       
   174 			iTimer->Start(KWait1second, KWait1second, TCallBack(StopWaitingForNotification, this));
       
   175 			iNotified = EFalse;
       
   176 			CActiveScheduler::Start(); // wait for notification
       
   177 			if (iNotified)
       
   178 				{
       
   179 				notified = ETrue;
       
   180 				}
       
   181 			}
       
   182 		while (iNotified);			
       
   183 		
       
   184 		test(notified || !iExpectingNotification); // only test that we were notified if we are expecting to be
       
   185 		test(iNumChangesFound == *iNumExpectedChanges);
       
   186 		
       
   187 		*iNumExpectedChanges = 0;
       
   188 		}
       
   189 		
       
   190 	iThread.Resume(); // allow the thread to tidy up;
       
   191 	iSemaphore.Wait();
       
   192 	iCalTestLibrary->GetSession().StopChangeNotification();
       
   193 	}
       
   194 
       
   195 
       
   196 void CTestAppManager::NextTestL()
       
   197 	{
       
   198 	// CTestAppManager::RunTestL hands over execution to the function 
       
   199 	// CTestAppModifier::RunTestL in the other thread for it to make 
       
   200 	// changes. The manager waits until the modifier has done what it 
       
   201 	// needs to and then signals the manager.
       
   202 	switch (*iTestCase)
       
   203 		{
       
   204 		case EEntryOutOfRange:
       
   205 			{
       
   206 			test.Next(_L("1 Create entry that is out of range"));
       
   207 
       
   208 			iExpectingNotification = EFalse;
       
   209 			}
       
   210 			break;
       
   211 		case EEntryOutOfRange1:
       
   212 			{
       
   213 			test.Next(_L("2 Create child entry that is out of range"));
       
   214 
       
   215 			iExpectingNotification = EFalse;
       
   216 			}
       
   217 			break;
       
   218 		case EApptInsideRange1:
       
   219 			{
       
   220 			// add appt within time range
       
   221 
       
   222 			test.Next(_L("3 Add, update and delete an appointment within the notification time range"));
       
   223 
       
   224 			iExpectingNotification = ETrue;
       
   225 			}
       
   226 			break;
       
   227 		case EApptInsideRange2:
       
   228 			{
       
   229 			test.Printf(_L("4 Update this appointment\n"));
       
   230 			iExpectingNotification = ETrue;
       
   231 			}
       
   232 			break;
       
   233 		case EApptInsideRange3:
       
   234 			{
       
   235 			test.Printf(_L("5 Delete this appointment\n"));
       
   236 			iExpectingNotification = ETrue;
       
   237 			}
       
   238 			break;
       
   239 		case EApptOutsideRange1:
       
   240 			{
       
   241 			// add appt outside time range
       
   242 
       
   243 			test.Next(_L("6 Add an appointment outside the notification time range"));
       
   244 
       
   245 			iExpectingNotification = EFalse;
       
   246 			}
       
   247 			break;
       
   248 		case EApptOutsideRange2:
       
   249 			{
       
   250 			// update appt outside time range
       
   251 			test.Printf(_L("7 Update this appointment\n"));
       
   252 			iExpectingNotification = EFalse; // check callback notification was NOT received for adding appt
       
   253 			}
       
   254 			break;
       
   255 		case EApptOutsideRange3:
       
   256 			{
       
   257 			// delete apppointment outside range
       
   258 			test.Printf(_L("8 Delete this appointment\n"));
       
   259 			iExpectingNotification = EFalse; // check callback notification was NOT received for delete
       
   260 			}
       
   261 			break;
       
   262 		case ENotifyNonResponsive:
       
   263 			{
       
   264 			// notification is disabled by the modifying thread
       
   265 			// add todo
       
   266 
       
   267 			test.Next(_L("9 Disable change notification to check change notification from nonresponsive client (wait for 16 seconds)"));
       
   268 
       
   269             //The timer which enbles the broadcast added in 9.3 is not implemented here
       
   270 			iExpectingNotification = EFalse;
       
   271 			//iExpectingNotification = ETrue;			
       
   272             //
       
   273 			// The Modifier thread disabled the notifications, but due to the
       
   274 			// self startup mechanism in the Server, the notifications
       
   275 			// will be dispatched when waiting for 15 seconds.
       
   276             // User::After(16 * KWait1second.Int());
       
   277 			}
       
   278 			break;						
       
   279 		case ENotifyNonResponsive1:
       
   280 			{
       
   281 			test.Printf(_L("10 Delete this todo (wait for 16 seconds)\n"));
       
   282             //The timer which enbles the broadcast added in 9.3 is not implemented here
       
   283 			iExpectingNotification = EFalse;
       
   284 			//iExpectingNotification = ETrue;			
       
   285             //
       
   286 			// The Modifier thread disabled the notifications, but due to the
       
   287 			// self startup mechanism in the Server, the notifications
       
   288 			// will be dispatched when waiting for 15 seconds.
       
   289             // User::After(16 * KWait1second.Int());
       
   290 			}
       
   291 			break;
       
   292 		case ETodoInsideRange1:
       
   293 			{
       
   294 			// notification is disabled by the modifying thread
       
   295 			// add todo within time range
       
   296 
       
   297 			test.Next(_L("11 Disable change notification then add a todo within the notification time range"));
       
   298 
       
   299 			iExpectingNotification = EFalse; // check callback notification was NOT received (disabled notification)
       
   300 			}
       
   301 			break;
       
   302 		case ETodoInsideRange2:
       
   303 			{
       
   304 			// notification should now be re-enabled by the other thread
       
   305 			test.Printf(_L("12 Re-enable change notification\n"));
       
   306 			iExpectingNotification = ETrue; // check callback notification was received for todo added during disable
       
   307 			}
       
   308 			break;
       
   309 		case ETodoInsideRange3:
       
   310 			{
       
   311 			test.Printf(_L("13 Update this todo\n"));
       
   312 			iExpectingNotification = ETrue; // check callback notification was received for update
       
   313 			}
       
   314 			break;
       
   315 		case ETodoInsideRange4:
       
   316 			{
       
   317 			test.Printf(_L("14 Delete this todo\n"));
       
   318 			iExpectingNotification = ETrue; // check callback notification was received for delete
       
   319 			}
       
   320 			break;
       
   321 		case ETodoOutsideRange1:
       
   322 			{
       
   323 			// add todo out of time range
       
   324 
       
   325 			test.Next(_L("15 Add a todo entry outside the notification time range"));
       
   326 
       
   327 			iExpectingNotification = EFalse; // check callback notification was NOT received for adding todo
       
   328 			}
       
   329 			break;
       
   330 		case ETodoOutsideRange2:
       
   331 			{
       
   332 			test.Printf(_L("16 Update this todo\n"));
       
   333 			iExpectingNotification = EFalse; // check callback notification was received for update
       
   334 			}
       
   335 			break;
       
   336 		case ETodoOutsideRange3:
       
   337 			{
       
   338 			test.Printf(_L("17 Delete this todo\n"));
       
   339 			iExpectingNotification = EFalse; // check callback notification was NOT received for delete
       
   340 			}
       
   341 			break;
       
   342 		case EAddUndatedTodo:
       
   343 			{
       
   344 			test.Next(_L("18 Adding Undated Todo\n"));
       
   345 
       
   346 			iExpectingNotification = ETrue;			
       
   347 			}
       
   348 			break;
       
   349 		case EUpdateUndatedTodo:
       
   350 			{
       
   351 
       
   352 			test.Next(_L("19 Updating Undated Todo\n"));
       
   353 
       
   354 			iExpectingNotification = ETrue;			
       
   355 			}
       
   356 			break;
       
   357 		case EClearUndatedTodo:
       
   358 			{
       
   359 			test.Printf(_L("20 Deleting undated todo\n"));
       
   360 			iExpectingNotification = ETrue; 
       
   361 			}
       
   362 			break;		
       
   363 		case EMultipleInAndOutside1:
       
   364 			{
       
   365 
       
   366 			test.Next(_L("21 Add multiple events inside and outside the time range"));
       
   367 
       
   368 			iExpectingNotification = ETrue; // check callback notification was received for delete
       
   369 			}
       
   370 			break;
       
   371 		case EMultipleInAndOutside2:
       
   372 			{
       
   373 			test.Printf(_L("22 Delete these events\n"));
       
   374 			iExpectingNotification = ETrue; // check callback notification was received for delete
       
   375 			}
       
   376 			break;
       
   377 		case EBulkAdd:
       
   378 			{
       
   379 
       
   380 			test.Next(_L("23 Make lots of changes\n"));
       
   381 
       
   382 			iExpectingNotification = ETrue;
       
   383 			}
       
   384 			break;
       
   385 		case EBulkDelete:
       
   386 			{
       
   387 			test.Printf(_L("24 Clear the entries\n"));
       
   388 			iExpectingNotification = ETrue;
       
   389 			}
       
   390 			break;
       
   391 		case EBulkAddToOverflowNotificationBuffer:
       
   392 			{
       
   393 
       
   394 			test.Next(_L("25 Make lots of changes and overflow the notification buffer\n"));
       
   395 
       
   396 			test.Printf(_L("Expecting only a single 'Undefined Change' notification\n"));
       
   397 			iExpectingNotification = ETrue;		
       
   398 			}
       
   399 			break;
       
   400 		case EBulkDeleteToOverflowNotificationBuffer:
       
   401 			{
       
   402 			test.Printf(_L("26 Clear the entries and overflow the notification buffer\n"));
       
   403 			test.Printf(_L("Expecting only a single 'Undefined Change' notification\n"));
       
   404 			iExpectingNotification = ETrue;		
       
   405 			}
       
   406 			break;
       
   407 		case ERepeatingEitherSideOfRange1:
       
   408 			{
       
   409 
       
   410 			test.Next(_L("27 Add a repeating entry across range but not in it"));
       
   411 
       
   412 			iExpectingNotification = EFalse;
       
   413 			}
       
   414 			break;
       
   415 		case ERepeatingEitherSideOfRange2:
       
   416 			{
       
   417 			test.Printf(_L("28 Update it\n"));
       
   418 			iExpectingNotification = EFalse;
       
   419 			}
       
   420 			break;
       
   421 		case ERepeatingEitherSideOfRange3:
       
   422 			{
       
   423 			test.Printf(_L("29 Clear it\n"));
       
   424 			iExpectingNotification = EFalse;
       
   425 			}
       
   426 			break;
       
   427 		case ERepeatingAcrossStartBoundary1:
       
   428 			{
       
   429 
       
   430 			test.Next(_L("30 Moving repeating entries (1)"));
       
   431 
       
   432 			test.Printf(_L("Create repeating entry across the range start boundary\n"));
       
   433 			iExpectingNotification = ETrue;
       
   434 			}
       
   435 			break;
       
   436 		case ERepeatingAcrossStartBoundary2:
       
   437 			{
       
   438 			test.Printf(_L("31 Move repeating entry to outside the range\n"));
       
   439 			iExpectingNotification = ETrue;
       
   440 			}
       
   441 			break;
       
   442 		case ERepeatingAcrossStartBoundary3:
       
   443 			{
       
   444 			test.Printf(_L("32 Clear the entries"));
       
   445 			iExpectingNotification = EFalse;
       
   446 			}
       
   447 			break;
       
   448 		case ERepeatingAcrossStartBoundary4:
       
   449 			{
       
   450 
       
   451 			test.Next(_L("33 Moving repeating entries (2)"));
       
   452 
       
   453 			test.Printf(_L("Create repeating entry outside the range\n"));
       
   454 			iExpectingNotification = EFalse;
       
   455 			}
       
   456 			break;
       
   457 		case ERepeatingAcrossStartBoundary5:
       
   458 			{
       
   459 			test.Printf(_L("34 Move repeating entry across the range start boundary\n"));
       
   460 			iExpectingNotification = ETrue;
       
   461 			}
       
   462 			break;
       
   463 		case ERepeatingAcrossStartBoundary6:
       
   464 			{
       
   465 			test.Printf(_L("35 Clear the entries\n"));
       
   466 			iExpectingNotification = ETrue;
       
   467 			}
       
   468 			break;
       
   469 		case ERepeatingAcrossEndBoundary1:
       
   470 			{
       
   471 
       
   472 			test.Next(_L("36 Moving repeating entries (3)"));
       
   473 
       
   474 			test.Printf(_L("Create repeating entry across the range end boundary\n"));
       
   475 			iExpectingNotification = ETrue;
       
   476 			}
       
   477 			break;
       
   478 		case ERepeatingAcrossEndBoundary2:
       
   479 			{
       
   480 			test.Printf(_L("37 Move repeating entry to outside the range\n"));
       
   481 			iExpectingNotification = ETrue;
       
   482 			}
       
   483 			break;
       
   484 		case ERepeatingAcrossEndBoundary3:
       
   485 			{
       
   486 			test.Printf(_L("38 Clear the entries\n"));
       
   487 			iExpectingNotification = EFalse;
       
   488 			}
       
   489 			break;
       
   490 		case ERepeatingAcrossEndBoundary4:
       
   491 			{
       
   492 
       
   493 			test.Next(_L("39 Moving repeating entries (4)"));
       
   494 
       
   495 			test.Printf(_L("Create repeating entry outside the range\n"));
       
   496 			iExpectingNotification = EFalse;
       
   497 			}
       
   498 			break;
       
   499 		case ERepeatingAcrossEndBoundary5:
       
   500 			{
       
   501 			test.Printf(_L("40 Move repeating entry across the range end boundary\n"));
       
   502 			iExpectingNotification = ETrue;
       
   503 			}
       
   504 			break;
       
   505 		case ERepeatingAcrossEndBoundary6:
       
   506 			{
       
   507 			test.Printf(_L("41 Clear the entries\n"));
       
   508 			iExpectingNotification = ETrue;
       
   509 			}
       
   510 			break;
       
   511 		case EFilterOnlyEventEntries1:
       
   512 			{
       
   513 			
       
   514 			test.Next(_L("42 Filter for only event entries"));
       
   515 
       
   516 			// change the filter so that we are only interested in event entries 
       
   517 			TCalTime calStartTime;
       
   518 			calStartTime.SetTimeLocalL(KRangeStartTime);// 1 Jan 05
       
   519 			TCalTime calEndTime;
       
   520 			calEndTime.SetTimeLocalL(KRangeEndTime);// 1 Jan 06
       
   521 			iCalTestLibrary->GetSession().StopChangeNotification();
       
   522 			CCalChangeNotificationFilter* filter = CCalChangeNotificationFilter::NewL(MCalChangeCallBack2::EChangeEntryEvent, ETrue, CalCommon::TCalTimeRange(calStartTime, calEndTime));
       
   523 			CleanupStack::PushL(filter);
       
   524 			iCalTestLibrary->GetSession().StartChangeNotification(*this, *filter);
       
   525 			CleanupStack::PopAndDestroy(filter);
       
   526 			iExpectingNotification = EFalse;
       
   527 			}
       
   528 			break;
       
   529 		case EFilterOnlyEventEntries2:
       
   530 			{
       
   531 			test.Printf(_L("43 Todo added"));
       
   532 			iExpectingNotification = EFalse;
       
   533 			}
       
   534 			break;
       
   535 		case EFilterOnlyEventEntries3:
       
   536 			{
       
   537 			test.Printf(_L("44 Event added"));
       
   538 			iExpectingNotification = ETrue;
       
   539 			}
       
   540 			break;
       
   541 		case EFilterOnlyEventEntries4:
       
   542 			{
       
   543 			test.Printf(_L("45 Clear the entries"));
       
   544 			iExpectingNotification = ETrue;
       
   545 			}
       
   546 			break;
       
   547 		case EFilterOnlyTodoEntries1:
       
   548 			{
       
   549 
       
   550 			test.Next(_L("46 Filter for only todo entries"));
       
   551 
       
   552 			// change the filter so that we are only interested in todo entries 
       
   553 			TCalTime calStartTime;
       
   554 			calStartTime.SetTimeLocalL(KRangeStartTime);// 1 Jan 05
       
   555 			TCalTime calEndTime;
       
   556 			calEndTime.SetTimeLocalL(KRangeEndTime);// 1 Jan 06
       
   557 			iCalTestLibrary->GetSession().StopChangeNotification();
       
   558 			CCalChangeNotificationFilter* filter = CCalChangeNotificationFilter::NewL(MCalChangeCallBack2::EChangeEntryTodo, ETrue, CalCommon::TCalTimeRange(calStartTime, calEndTime));
       
   559 			CleanupStack::PushL(filter);
       
   560 			iCalTestLibrary->GetSession().StartChangeNotification(*this, *filter);
       
   561 			CleanupStack::PopAndDestroy(filter);
       
   562 			iExpectingNotification = EFalse;
       
   563 			}
       
   564 			break;
       
   565 		case EFilterOnlyTodoEntries2:
       
   566 			{
       
   567 			test.Printf(_L("47 Todo added"));
       
   568 			iExpectingNotification = ETrue;
       
   569 			}
       
   570 			break;
       
   571 		case EFilterOnlyTodoEntries3:
       
   572 			{
       
   573 			test.Printf(_L("48 Event added"));
       
   574 			iExpectingNotification = EFalse;
       
   575 			}
       
   576 			break;
       
   577 		case EFilterOnlyTodoEntries4:
       
   578 			{
       
   579 			test.Printf(_L("49 Clear the entries"));
       
   580 			iExpectingNotification = ETrue;
       
   581 			}
       
   582 			break;
       
   583 		case EFilterOnlyTodoEntries5:
       
   584 			{
       
   585 			test.Printf(_L("50 Restore filter to all entries"));
       
   586 			// change the filter so that we are only interested in todo entries 
       
   587 			TCalTime calStartTime;
       
   588 			calStartTime.SetTimeLocalL(KRangeStartTime);// 1 Jan 05
       
   589 			TCalTime calEndTime;
       
   590 			calEndTime.SetTimeLocalL(KRangeEndTime);// 1 Jan 06
       
   591 			iCalTestLibrary->GetSession().StopChangeNotification();
       
   592 			CCalChangeNotificationFilter* filter = CCalChangeNotificationFilter::NewL(MCalChangeCallBack2::EChangeEntryAll, ETrue, CalCommon::TCalTimeRange(calStartTime, calEndTime));
       
   593 			CleanupStack::PushL(filter);
       
   594 			iCalTestLibrary->GetSession().StartChangeNotification(*this, *filter);
       
   595 			CleanupStack::PopAndDestroy(filter);
       
   596 			iExpectingNotification = EFalse;
       
   597 			}
       
   598 			break;
       
   599 		case EAddAndUpdateParentAndChild1:
       
   600 			{
       
   601 
       
   602 			test.Next(_L("51 Add and update parent and child entries"));
       
   603 
       
   604 			test.Printf(_L("add the parent entry"));
       
   605 			iExpectingNotification = ETrue;
       
   606 			}
       
   607 			break;
       
   608 		case EAddAndUpdateParentAndChild2:
       
   609 			{
       
   610 			test.Printf(_L("52 Update the parent entry"));
       
   611 			iExpectingNotification = ETrue;
       
   612 			}
       
   613 			break;
       
   614 		case EAddAndUpdateParentAndChild3:
       
   615 			{
       
   616 			test.Printf(_L("53 add a child to the parent entry"));
       
   617 			iExpectingNotification = ETrue;			
       
   618 			}
       
   619 			break;
       
   620 		case EAddAndUpdateParentAndChild4:
       
   621 			{
       
   622 			test.Printf(_L("54 update the child entry"));
       
   623 			iExpectingNotification = ETrue;
       
   624 			}
       
   625 			break;
       
   626 		case EAddAndUpdateParentAndChild5:
       
   627 			{
       
   628 			test.Printf(_L("55 store the parent again"));
       
   629 			iExpectingNotification = ETrue;		
       
   630 			}
       
   631 			break;
       
   632 		case EAddAndUpdateParentAndChild6:
       
   633 			{
       
   634 			test.Printf(_L("56 add the child again"));
       
   635 			iExpectingNotification = ETrue;		
       
   636 			}
       
   637 			break;
       
   638 		case EAddAndUpdateParentAndChild7:
       
   639 			{
       
   640 			test.Printf(_L("57 delete the child"));
       
   641 			iExpectingNotification = ETrue;
       
   642 			}
       
   643 			break;
       
   644 		case EAddAndUpdateParentAndChild8:
       
   645 			{
       
   646 			test.Printf(_L("58 add the child again"));
       
   647 			iExpectingNotification = ETrue;			
       
   648 			}
       
   649 			break;
       
   650 		case EAddAndUpdateParentAndChild9:
       
   651 			{
       
   652 			test.Printf(_L("59 delete the parent"));
       
   653 			iExpectingNotification = ETrue;
       
   654 			}
       
   655 			break;
       
   656 
       
   657 		case EDeleteMultipleEntriesSetup:
       
   658 			{
       
   659 
       
   660 			test.Next(_L("60 Setup delete fail test - Create one entry"));
       
   661 
       
   662 			iExpectingNotification = EFalse;
       
   663 			}
       
   664 			break;
       
   665 
       
   666 		case EDeleteMultipleEntriesFail:
       
   667 			{
       
   668 
       
   669 			test.Next(_L("61 Test deleting multiple entries where the second delete fails"));
       
   670 
       
   671 			iExpectingNotification = EFalse;
       
   672 			}
       
   673 			break;
       
   674 			
       
   675 		case EChangesToOtherFile:
       
   676 			{
       
   677 
       
   678 			test.Next(_L("62 Make changes to a different file and make sure we are not notified"));
       
   679 
       
   680 			iExpectingNotification = EFalse;
       
   681 			}
       
   682 			break;
       
   683 
       
   684 		default:
       
   685 			{
       
   686 			User::Panic(_L("63 A case statement for this test has not been added"), *iTestCase);
       
   687 			}
       
   688 			break;
       
   689 		}
       
   690 	}
       
   691 
       
   692 
       
   693 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
       
   694  * DoTestL()
       
   695  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
       
   696 	
       
   697 static void DoTestL()
       
   698 	{
       
   699 	CTestAppManager* testManager = CTestAppManager::NewLC();
       
   700 	
       
   701 
       
   702 	TPerformanceTimer timer(test);
       
   703 	timer.Start();
       
   704 
       
   705 
       
   706 	// Run the test suite
       
   707 
       
   708 	testManager->RunTestL();
       
   709 	
       
   710 	
       
   711 	timer.Stop();
       
   712 	test.Printf(_L("Done\n"));
       
   713 	// printout performance time
       
   714 	timer.PrintOut();
       
   715 	
       
   716 
       
   717 	CleanupStack::PopAndDestroy(testManager);
       
   718 	}
       
   719 
       
   720 
       
   721 /**
       
   722 
       
   723 @SYMTestCaseID     PIM-TCAL-OBSERVER-MANAGER-0001
       
   724 
       
   725 */
       
   726 
       
   727 TInt E32Main()
       
   728     {
       
   729 	__UHEAP_MARK;
       
   730 
       
   731 	test.Start(_L("@SYMTESTCaseID:PIM-TCAL-OBSERVER-MANAGER-0001 Calendar Interim API Observer test suite"));
       
   732 
       
   733 	test.Title();
       
   734 
       
   735 	CTrapCleanup* trapCleanup = CTrapCleanup::New();
       
   736 	if (!trapCleanup)
       
   737 		{
       
   738 		return KErrNoMemory;
       
   739 		}
       
   740 
       
   741 	CActiveScheduler* scheduler = new CActiveScheduler();
       
   742 	if (!scheduler)
       
   743 		{
       
   744 		delete trapCleanup;
       
   745 		return KErrNoMemory;
       
   746 		}
       
   747 	CActiveScheduler::Install(scheduler);	
       
   748 
       
   749 	TRAPD(ret, DoTestL());
       
   750 	test(ret == KErrNone);
       
   751 	
       
   752 	delete scheduler;
       
   753 	delete trapCleanup;	
       
   754 
       
   755 	test.End();
       
   756 	test.Close();
       
   757 
       
   758 	__UHEAP_MARKEND;
       
   759 
       
   760 	return (KErrNone);
       
   761     }