phonebookengines/contactsmodel/tsrc/t_iccview.cpp
changeset 0 e686773b3f54
child 24 0ba2181d7c28
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 // Copyright (c) 2002-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 <e32test.h>
       
    17 #include <cntdb.h>
       
    18 #include <cntitem.h>
       
    19 #include <cntfield.h>
       
    20 #include <cntfldst.h>
       
    21 #include <e32math.h>
       
    22 #include <phbksync.h>
       
    23 
       
    24 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    25 #include "cntsyncecom.h"
       
    26 #endif
       
    27 
       
    28 #include "T_UTILS.H"
       
    29 #include "cntsyncchecker.h"
       
    30 #include "CContactViewEventQueue.h"
       
    31 #include "CContactDbEventQueue.h"
       
    32 #include <ecom/ecom.h>
       
    33 // include templates for CleanupResetAndDestroyPushL(T)
       
    34 #include "cntviewprivate.h"
       
    35 
       
    36 _LIT(KTestName,"@SYMTestCaseID:PIM-T-ICCVIEW-0001 t_iccview");
       
    37 
       
    38 _LIT(KTestDbName, "c:T_ICCView.cdb");
       
    39 _LIT(KPluginName,"phone book synchronizer Implementation");
       
    40 _LIT(KTestPluginName,"Test phone book synchronizer Implementation");
       
    41 
       
    42 LOCAL_D RTest test(KTestName);
       
    43 
       
    44 LOCAL_D CContactSyncChecker* syncChecker;
       
    45 
       
    46 class CICCViewTest : public CBase
       
    47 	{
       
    48 public:
       
    49 	static CICCViewTest* NewLC(const RArray<TUid>& aPhonebookList);
       
    50 	~CICCViewTest();
       
    51 
       
    52 	void TestOneOrFiveL(TBool aCreateViewBeforeSync);
       
    53 	void TestTwoL();
       
    54 	void TestThreeOrSixL(TBool aCreateViewBeforeSync);
       
    55 	void TestFourL();
       
    56 	void TestSevenL();
       
    57 	void TestConcurrenceL();
       
    58 	
       
    59 private:
       
    60 	enum TSyncStatus 
       
    61 		{
       
    62 		ENotSynchronised,
       
    63 		ESynchronised,
       
    64 		ESyncIccLocked,
       
    65 		};
       
    66 	CICCViewTest(const RArray<TUid>& aPhonebookList);
       
    67 	void ConstructL();
       
    68 
       
    69 	void CreateViewsL();
       
    70 	void CheckViewCreateAndSyncEventsL(TInt aSyncCompletionError, TInt aIsSyncError);
       
    71 	void CheckEventsForTestFourL();
       
    72 	void SyncThenCreateViewCheckEventsL(TInt aSyncCompletionError, TInt aIsSyncError);
       
    73 	void CheckEventsForTestSevenL();
       
    74 
       
    75 	void CreateEntriesL(TInt aNumberOfEntries, TBool aIsIccEntry=EFalse);
       
    76 	void CreateEntriesNoVerifyL(TInt aNumberOfEntries, TBool aIsIccEntry=EFalse);
       
    77 	void DeleteEntriesL(TInt aNumberOfEntries, TBool aIccEntry=EFalse);
       
    78 	void CreateEntryL(TBool aIsIccEntry=EFalse);
       
    79 	void VerifyNumberOfEntriesInEachViewL(TSyncStatus aSyncStatus);
       
    80 
       
    81 	void SetRandomAlphaString(TDes& aBuf,TInt aLength);
       
    82 	TText RandomCharCode(TText aLowerBound,TText aUpperBound,TText aException);
       
    83 	TText RandomCharCode(TText aLowerBound,TText aUpperBound);
       
    84 
       
    85 private:
       
    86 	const RArray<TUid>& iPhbkList;
       
    87 
       
    88 	CContactDatabase* iDb;
       
    89 	CContactItem* iEntry;
       
    90 	CContactViewEventQueue* iViewEventQueue;
       
    91 	RContactViewSortOrder iViewSortOrder;
       
    92 	CContactLocalView* iContactsView;
       
    93 	CContactLocalView* iIccView;
       
    94 	CContactLocalView* iContactsAndIccView;
       
    95 	CContactViewEventQueue* iFilteredViewEventQueue;
       
    96 	CContactItem* iTemplate;
       
    97 	RArray<TContactItemId>	iIccContacts;
       
    98 	RArray<TContactItemId>	iNonIccContacts;
       
    99 	TInt64 iRandSeed;
       
   100 
       
   101 	TInt iInitialIccCount;
       
   102 	};
       
   103 
       
   104 CICCViewTest* CICCViewTest::NewLC(const RArray<TUid>& aPhonebookList)
       
   105     {
       
   106     CICCViewTest* self = new(ELeave) CICCViewTest(aPhonebookList);
       
   107     CleanupStack::PushL(self);
       
   108     self->ConstructL();
       
   109     return self;
       
   110     }
       
   111 
       
   112 CICCViewTest::CICCViewTest(const RArray<TUid>& aPhonebookList) : iPhbkList(aPhonebookList)
       
   113 	{
       
   114 	}
       
   115 
       
   116 void CICCViewTest::ConstructL()
       
   117     {
       
   118 	// reset method call count & phonebook sync state
       
   119 	// Set-up responses from the phonebook plug-in 
       
   120 	syncChecker->ResetEverythingL();
       
   121 
       
   122 	// tell phonebook sync simulator what phonebooks to use
       
   123 	test(syncChecker->SetPhonebookListL(iPhbkList) == KErrNone);
       
   124 	// put one contact in the first ICC Phonebook
       
   125 	test(syncChecker->AddContactToPhonebookL(iPhbkList[0], _L("John Brown"), _L("1234")) == KErrNone);
       
   126 	// put one contact in the last ICC Phonebook
       
   127 	test(syncChecker->AddContactToPhonebookL(iPhbkList[iPhbkList.Count()-1], _L("Al Capone"), _L("9876")) == KErrNone);
       
   128 	// number of ICC contacts expected in Views after Synchronisation
       
   129 	iInitialIccCount = 2;
       
   130 
       
   131     // start test with empty database
       
   132 	iDb = CContactDatabase::ReplaceL(KTestDbName);
       
   133 
       
   134     iViewEventQueue = CContactViewEventQueue::NewL();
       
   135 
       
   136     iViewSortOrder.AppendL(KUidContactFieldFamilyName);
       
   137     iViewSortOrder.AppendL(KUidContactFieldGivenName);
       
   138     iViewSortOrder.AppendL(KUidContactFieldCompanyName);
       
   139 	}
       
   140 
       
   141 // Create 3 views: non-icc contacts, icc contacts, and both
       
   142 void CICCViewTest::CreateViewsL()
       
   143 	{
       
   144     iContactsView = CContactLocalView::NewL(*iViewEventQueue, *iDb, iViewSortOrder, EContactsOnly);
       
   145 	iIccView = CContactLocalView::NewL(*iViewEventQueue, *iDb, iViewSortOrder, EICCEntriesOnly);
       
   146 	iContactsAndIccView = CContactLocalView::NewL(*iViewEventQueue, *iDb, iViewSortOrder, EICCEntriesAndContacts);
       
   147 	}
       
   148 
       
   149 /**
       
   150  Test View notifications when Phonebook Synch finishes
       
   151  Takes parameters to stimulate error conditions in the synchronisation
       
   152 
       
   153  Method: Creates 3 views for Contacts, ICC Entries and Mixed Contacts & ICC Entries
       
   154  Count/check the View events.
       
   155  */
       
   156 void CICCViewTest::CheckViewCreateAndSyncEventsL(TInt aSyncCompletionError, TInt aIsSyncError)
       
   157 	{
       
   158     // Wait for local views to get ready
       
   159 	TInt readyCount(0);
       
   160 	TInt sortErrorCount(0);
       
   161     TContactViewEvent event;
       
   162 
       
   163 	// create the view to test
       
   164 	CreateViewsL();
       
   165 
       
   166 	// Contact only view should Ready
       
   167 	test(iViewEventQueue->ListenForEvent(10,event));
       
   168 
       
   169 	// Expecting EReady event
       
   170 	test.Printf(_L("Event received (%i)\n"), event.iEventType);
       
   171 	test(event.iEventType == TContactViewEvent::EReady);
       
   172 	readyCount++;
       
   173 
       
   174 	// there should be 1 Synch Change Notification request outstanding per phonebook
       
   175 	TInt notificationCount = syncChecker->TotalNotificationPendingCountL();
       
   176 	test(notificationCount == iPhbkList.Count());
       
   177 
       
   178 	// Phbk Watchers should be created when views were created - check number of plug-in calls
       
   179 	test(syncChecker->SyncMethodCallCountL() == (2 + 4 * iPhbkList.Count()));
       
   180 
       
   181 
       
   182 	// synchronise all phonebooks
       
   183 	test(syncChecker->SynchroniseIccAllPhonebooksL(*iDb, aSyncCompletionError, aIsSyncError) == KErrNone);
       
   184 
       
   185 
       
   186 	// views with ICC entries should become ready now
       
   187 	while (((readyCount + sortErrorCount) < 3) && iViewEventQueue->ListenForEvent(10,event))
       
   188 		{
       
   189 		// Expecting EReady events
       
   190 		switch (event.iEventType)
       
   191 			{
       
   192 		case TContactViewEvent::EItemAdded:
       
   193 			test.Printf(_L("Event received - EItemAdded\n"));
       
   194 			// ignore events from adding contacts
       
   195 			break;
       
   196 
       
   197 		case TContactViewEvent::EGroupChanged:
       
   198 			test.Printf(_L("Event received - EGroupChanged (group Id %i)\n"), event.iContactId);
       
   199 			// ignore events from adding contacts
       
   200 			break;
       
   201 
       
   202 		case TContactViewEvent::EReady:
       
   203 			test.Printf(_L("Event received - EReady\n"));
       
   204 			readyCount++;
       
   205 			break;
       
   206 
       
   207 		case TContactViewEvent::ESortError:
       
   208 			test.Printf(_L("Event received - ESortError\n"));
       
   209 			if (aSyncCompletionError != KErrNone)
       
   210 				{
       
   211 				test(event.iInt == aSyncCompletionError);
       
   212 				}
       
   213 			else
       
   214 				{
       
   215 				test(event.iInt == aIsSyncError);
       
   216 				}
       
   217 			sortErrorCount++;
       
   218 			break;
       
   219 
       
   220 		default:
       
   221 			test.Printf(_L("Unexpected event received (%i)\n"), event.iEventType);
       
   222 			test(0);
       
   223 			}
       
   224 		}
       
   225 
       
   226 	// either received all events or timed out waiting
       
   227 	if (aSyncCompletionError == KErrNone && aIsSyncError == KErrNone)
       
   228 		{
       
   229 		// all 3 views should be ready
       
   230 		test(readyCount == 3);
       
   231 
       
   232 		// check number of entries in views (ICC is synchronised)
       
   233 		VerifyNumberOfEntriesInEachViewL(ESynchronised);
       
   234 		}
       
   235 	else
       
   236 		{
       
   237 		// ICC views should have had sort errors
       
   238 		test(sortErrorCount == 2);
       
   239 
       
   240 		// check number of entries in views (ICC is not synchronised)
       
   241 		VerifyNumberOfEntriesInEachViewL(ENotSynchronised);
       
   242 		}
       
   243 
       
   244 
       
   245 	// there should be 1 Synch Change Notification request outstanding per phonebook
       
   246 	notificationCount = syncChecker->TotalNotificationPendingCountL();
       
   247 	test(notificationCount == iPhbkList.Count());
       
   248 
       
   249 	// Check the number of requests made to the plug-in
       
   250 	const TInt methodCount = syncChecker->SyncMethodCallCountL();
       
   251 	if (aSyncCompletionError == KErrNone)
       
   252 		{
       
   253 		// There should be 1 call plus 4 per phonebook to the Phonebook Sync plug-in
       
   254 		// PhonebookList + N * 2 * (NotifySyncStateChange, IsSynchronised)
       
   255 		test(methodCount == 2 + (8 * iPhbkList.Count()));  
       
   256 		}
       
   257 	else
       
   258 		{
       
   259 		// There should be 1 call plus 2 per phonebook to the Phonebook Sync plug-in
       
   260 		// PhonebookList + N * (NotifySyncStateChange, IsSynchronised, NotifySyncStateChange)
       
   261 		test(methodCount == 2 + (6 * iPhbkList.Count())); 
       
   262 		}
       
   263 
       
   264 
       
   265     // Flush all other events
       
   266 	iViewEventQueue->Flush();
       
   267 	}
       
   268 
       
   269 
       
   270 /**
       
   271  Test Objective: Test Phonebook Synch for SIM card that starts Locked and becomes Unlocked.
       
   272  - tests View events and number of contacts in views
       
   273 
       
   274  Method: Creates 3 views for Contacts, ICC Entries and Mixed Contacts & ICC Entries.
       
   275    Simulated Phonebook Synch fails with ICC card locked, subsequently card becomes unlocked
       
   276    and Phonebook Synch succeeds.
       
   277  
       
   278  Test steps:
       
   279  1. Create some non-ICC Contacts.
       
   280  2. Contacts only view becomes ready, while PhoneBook Synch waits to Synchronise.
       
   281  3. PhoneBook Synch then indicates an error due to SIM card (ICC) locked.
       
   282  4. The two ICC views become available without ICC entries.
       
   283  5. The PhoneBook Synch then indicates that the Cache is Valid.
       
   284  6. The two ICC views are updated (re-sorted) with the ICC entries.
       
   285  7. Cleanup (deletes all entries)
       
   286  */
       
   287 void CICCViewTest::CheckEventsForTestFourL()
       
   288 	{
       
   289     // Wait for local views to get ready
       
   290     TContactViewEvent event;
       
   291 	TInt readyCount(0);
       
   292 	TInt unavailableCount(0);
       
   293 	TInt sortOrderChangedCount(0);
       
   294 
       
   295 	// create the view to test
       
   296 	CreateViewsL();
       
   297 
       
   298 
       
   299 	// Test Step 1. Create some non-ICC Contacts.
       
   300 	test.Printf(_L("Creating 5 Contacts\n"));
       
   301 	CreateEntriesNoVerifyL(5);
       
   302 
       
   303 	// This While loop tests for steps:
       
   304 	// 2. Contacts only view becomes ready, while PhoneBook Synch waits to Synchronise.
       
   305 	// 3. PhoneBook Synch then indicates an error due to SIM card (ICC) locked.
       
   306 	// 4. The two ICC views become available without ICC entries.
       
   307 
       
   308 	/* Expected events:
       
   309 	 * a) EReady (1) => non-ICC Contacts view is ready
       
   310 	 * b) [listen times out] test must notify sync SIM lock error
       
   311 	 * c&d) EReady (1) => ICC Views become Ready empty or with contacts only
       
   312 	 */
       
   313 
       
   314 	// Contact only view should Ready
       
   315 	test(iViewEventQueue->ListenForEvent(10,event));
       
   316 
       
   317 	// Expecting EReady event
       
   318 	test.Printf(_L("Event received (%i)\n"), event.iEventType);
       
   319 	test(event.iEventType == TContactViewEvent::EReady);
       
   320 	readyCount++;
       
   321 
       
   322 	// there should be 1 Synch Change Notification request outstanding per phonebook
       
   323 	TInt notificationCount = syncChecker->TotalNotificationPendingCountL();
       
   324 	test(notificationCount == iPhbkList.Count());
       
   325 
       
   326 
       
   327 	// synchronise all phonebooks, with SIM card "access denied" condition
       
   328 	test(syncChecker->SynchroniseIccAllPhonebooksL(*iDb, KErrNone, KErrAccessDenied) == KErrNone);
       
   329 
       
   330 
       
   331 	// views with ICC entries should become ready now
       
   332 	while ((readyCount < 3) && iViewEventQueue->ListenForEvent(10,event))
       
   333 		{
       
   334 		// Expecting EReady events
       
   335 		switch (event.iEventType)
       
   336 			{
       
   337 		case TContactViewEvent::EItemAdded:
       
   338 			test.Printf(_L("Event received - EItemAdded\n"));
       
   339 			// ignore events from adding contacts
       
   340 			break;
       
   341 
       
   342 		case TContactViewEvent::EGroupChanged:
       
   343 			test.Printf(_L("Event received - EGroupChanged (group Id %i)\n"), event.iContactId);
       
   344 			// ignore events from adding contacts
       
   345 			break;
       
   346 
       
   347 		case TContactViewEvent::EReady:
       
   348 			test.Printf(_L("Event received - EReady\n"));
       
   349 			readyCount++;
       
   350 			break;
       
   351 
       
   352 		default:
       
   353 			test.Printf(_L("Unexpected event received (%i)\n"), event.iEventType);
       
   354 			test(0);
       
   355 			}
       
   356 		}
       
   357 
       
   358 
       
   359 	test(readyCount == 3);
       
   360 
       
   361 	// there should be 1 Synch Change Notification request outstanding per phonebook
       
   362 	notificationCount = syncChecker->TotalNotificationPendingCountL();
       
   363 	test(notificationCount == iPhbkList.Count());
       
   364 
       
   365 	// check number of entries in views (ICC locked)
       
   366 	VerifyNumberOfEntriesInEachViewL(ESyncIccLocked);
       
   367 
       
   368 	// Test Step 5. The PhoneBook Synch then indicates that the Cache is Valid.
       
   369 	test(syncChecker->SynchroniseIccAllPhonebooksL(*iDb, KErrNone, KErrNone) == KErrNone);
       
   370 	test.Printf(_L("PhoneBook Synch completed, cache now valid\n"));
       
   371 
       
   372 	// Test Step 6. The two ICC views are updated (re-sorted) with the ICC entries.
       
   373 
       
   374 	/* The 2 Views with ICC entries will each have 2 events:
       
   375 	 * a) EUnavailable (0) => view is unavailable
       
   376 	 * b) ESortOrderChanged (2) => view is Ready again
       
   377 	 *
       
   378 	 * For the 2 Views these can be interleaved
       
   379 	 */
       
   380 	while ((unavailableCount < 2) || (sortOrderChangedCount < 2))
       
   381 		{
       
   382 		TBool eventReceived = iViewEventQueue->ListenForEvent(1,event);
       
   383 
       
   384 		if (eventReceived)
       
   385 			{
       
   386 			switch(event.iEventType)
       
   387 				{
       
   388 				case TContactViewEvent::EItemAdded:
       
   389 					test.Printf(_L("Event received - EItemAdded (Id %i)\n"), event.iContactId);
       
   390 					// ignore events from adding contacts
       
   391 					break;
       
   392 
       
   393 				case TContactViewEvent::EGroupChanged:
       
   394 					test.Printf(_L("Event received - EGroupChanged (group Id %i)\n"), event.iContactId);
       
   395 					// ignore events from adding contacts
       
   396 					break;
       
   397 
       
   398 				case TContactViewEvent::ESortOrderChanged:
       
   399 					test.Printf(_L("Event received - ESortOrderChanged\n"));
       
   400 					sortOrderChangedCount++;
       
   401 					test(sortOrderChangedCount <= unavailableCount);
       
   402 					break;
       
   403 
       
   404 				case TContactViewEvent::EUnavailable:
       
   405 					test.Printf(_L("Event received - EUnavailable\n"));
       
   406 					unavailableCount++;
       
   407 					test(unavailableCount <= 2);
       
   408 					break;
       
   409 
       
   410 				default:
       
   411 					test.Printf(_L("Unexpected event received (%i)\n"), event.iEventType);
       
   412 					test(EFalse);
       
   413 					break;
       
   414 				}
       
   415 			}	
       
   416 		}
       
   417 
       
   418 	// there should be 1 Synch Change Notification request outstanding per phonebook
       
   419 	notificationCount = syncChecker->TotalNotificationPendingCountL();
       
   420 	test(notificationCount == iPhbkList.Count());
       
   421 
       
   422 	// check number of entries in views (ICC synchronised)
       
   423 	VerifyNumberOfEntriesInEachViewL(ESynchronised);
       
   424 
       
   425 	// Check the number of requests made to the plug-in
       
   426 	// Expecting 6 calls in total from PhbkSync Watcher
       
   427 	// (NotifySyncStateChange + IsSynchronised) * 3
       
   428 	//
       
   429 
       
   430 	// Test Step 7. Cleanup (deletes all entries)
       
   431 	// delete non-Icc entries
       
   432 	DeleteEntriesL(iNonIccContacts.Count());
       
   433 	// delete Icc entries
       
   434 	DeleteEntriesL(iIccContacts.Count(), ETrue);
       
   435 
       
   436 	// no entries left
       
   437 	test((iNonIccContacts.Count() == 0) && (iIccContacts.Count() == 0));
       
   438 
       
   439     // Flush all other events
       
   440 	iViewEventQueue->Flush();
       
   441 	}
       
   442 
       
   443 
       
   444 /**
       
   445  Test View notifications when Phonebook Synch finishes
       
   446  Takes parameters to stimulate error conditions in the synchronisation
       
   447 
       
   448  Method: Start synchronisation then creates 3 views for Contacts, ICC Entries and Mixed Contacts & ICC Entries
       
   449  Count/check the View events.
       
   450  */
       
   451 void CICCViewTest::SyncThenCreateViewCheckEventsL(TInt aSyncCompletionError, TInt aIsSyncError)
       
   452 	{
       
   453     // Wait for local views to get ready
       
   454 	TInt readyCount(0);
       
   455 	TInt sortErrorCount(0);
       
   456     TContactViewEvent event;
       
   457 
       
   458 	// synchronise all phonebooks
       
   459 	test(syncChecker->SynchroniseIccAllPhonebooksL(*iDb, aSyncCompletionError, aIsSyncError) == KErrNone);
       
   460 
       
   461 
       
   462 	// create the view to test
       
   463 	CreateViewsL();
       
   464 
       
   465 	// Contact only view should Ready
       
   466 	test(iViewEventQueue->ListenForEvent(10,event));
       
   467 
       
   468 	// Expecting EReady event
       
   469 	test.Printf(_L("Event received (%i)\n"), event.iEventType);
       
   470 	test(event.iEventType == TContactViewEvent::EReady);
       
   471 	readyCount++;
       
   472 
       
   473 	// there should be 1 Synch Change Notification request outstanding per phonebook
       
   474 	TInt notificationCount = syncChecker->TotalNotificationPendingCountL();
       
   475 	test(notificationCount == iPhbkList.Count());
       
   476 
       
   477 	// Phbk Watchers should be created when views were created - check number of plug-in calls
       
   478 	//test(syncChecker->SyncMethodCallCountL() == (1 + 2 * iPhbkList.Count())); Johan
       
   479 
       
   480 
       
   481 	// views with ICC entries should become ready now
       
   482 	while (((readyCount + sortErrorCount) < 3) && iViewEventQueue->ListenForEvent(10,event))
       
   483 		{
       
   484 		// Expecting EReady events
       
   485 		switch (event.iEventType)
       
   486 			{
       
   487 		case TContactViewEvent::EItemAdded:
       
   488 			test.Printf(_L("Event received - EItemAdded\n"));
       
   489 			// ignore events from adding contacts
       
   490 			break;
       
   491 
       
   492 		case TContactViewEvent::EGroupChanged:
       
   493 			test.Printf(_L("Event received - EGroupChanged (group Id %i)\n"), event.iContactId);
       
   494 			// ignore events from adding contacts
       
   495 			break;
       
   496 
       
   497 		case TContactViewEvent::EReady:
       
   498 			test.Printf(_L("Event received - EReady\n"));
       
   499 			readyCount++;
       
   500 			break;
       
   501 
       
   502 		case TContactViewEvent::ESortError:
       
   503 			test.Printf(_L("Event received - ESortError\n"));
       
   504 			if (aSyncCompletionError != KErrNone)
       
   505 				{
       
   506 				test(event.iInt == aSyncCompletionError);
       
   507 				}
       
   508 			else
       
   509 				{
       
   510 				test(event.iInt == aIsSyncError);
       
   511 				}
       
   512 			sortErrorCount++;
       
   513 			break;
       
   514 
       
   515 		default:
       
   516 			test.Printf(_L("Unexpected event received (%i)\n"), event.iEventType);
       
   517 			test(0);
       
   518 			}
       
   519 		}
       
   520 
       
   521 	// either received all events or timed out waiting
       
   522 	if (aSyncCompletionError == KErrNone && aIsSyncError == KErrNone)
       
   523 		{
       
   524 		// all 3 views should be ready
       
   525 		test(readyCount == 3);
       
   526 
       
   527 		// check number of entries in views (ICC is synchronised)
       
   528 		VerifyNumberOfEntriesInEachViewL(ESynchronised);
       
   529 		}
       
   530 	else
       
   531 		{
       
   532 		// ICC views should have had sort errors
       
   533 		test(sortErrorCount == 2);
       
   534 
       
   535 		// check number of entries in views (ICC is not synchronised)
       
   536 		VerifyNumberOfEntriesInEachViewL(ENotSynchronised);
       
   537 		}
       
   538 
       
   539 
       
   540 	// there should be 1 Synch Change Notification request outstanding per phonebook
       
   541 	notificationCount = syncChecker->TotalNotificationPendingCountL();
       
   542 	test(notificationCount == iPhbkList.Count());
       
   543 
       
   544 	// Check the number of requests made to the plug-in
       
   545 	const TInt methodCount = syncChecker->SyncMethodCallCountL();
       
   546 	if (aSyncCompletionError == KErrNone)
       
   547 		{
       
   548 		// There should be 1 call plus 2 per phonebook to the Phonebook Sync plug-in
       
   549 		// PhonebookList + N * (NotifySyncStateChange, IsSynchronised)
       
   550 		test(methodCount == 2 + (4 * iPhbkList.Count())); 
       
   551 		}
       
   552 	else
       
   553 		{
       
   554 		// There should be 1 call plus 2 per phonebook to the Phonebook Sync plug-in
       
   555 		// PhonebookList + N * NotifySyncStateChange + N * 2 * (IsSynchronised, NotifySyncStateChange)
       
   556 		test(methodCount == 1 + (5 * iPhbkList.Count())); 
       
   557 		}
       
   558 
       
   559 
       
   560     // Flush all other events
       
   561 	iViewEventQueue->Flush();
       
   562 	}
       
   563 
       
   564 
       
   565 /**
       
   566  Test Objective: Test Phonebook Synch for SIM card that starts Locked and becomes Unlocked.
       
   567  - tests View events and number of contacts in views
       
   568 
       
   569  Differs from test 4 in that the initial Phonebook Sync state (SIM locked) is indicated
       
   570  before the views are created.
       
   571 
       
   572  Method: Creates 3 views for Contacts, ICC Entries and Mixed Contacts & ICC Entries.
       
   573    Simulated Phonebook Synch fails with ICC card locked, subsequently card becomes unlocked
       
   574    and Phonebook Synch succeeds.
       
   575  
       
   576  Test steps:
       
   577  1. PhoneBook Synch fails with an error due to SIM card (ICC) locked.
       
   578  2. Create Views and some non-ICC Contacts.
       
   579  2. Contacts only view becomes ready
       
   580  4. The two ICC views become available without ICC entries.
       
   581  5. The PhoneBook Synch then indicates that the Cache is Valid.
       
   582  6. The two ICC views are updated (re-sorted) with the ICC entries.
       
   583  7. Cleanup (deletes all entries)
       
   584  */
       
   585 void CICCViewTest::CheckEventsForTestSevenL()
       
   586 	{
       
   587     // Wait for local views to get ready
       
   588     TContactViewEvent event;
       
   589 	TInt readyCount(0);
       
   590 	TInt unavailableCount(0);
       
   591 	TInt sortOrderChangedCount(0);
       
   592 
       
   593 	// Test step 1. synchronise all phonebooks, with SIM card "access denied" condition
       
   594 	test(syncChecker->SynchroniseIccAllPhonebooksL(*iDb, KErrNone, KErrAccessDenied) == KErrNone);
       
   595 
       
   596 
       
   597 	// Test Step 2. Create views and some non-ICC Contacts.
       
   598 	CreateViewsL();
       
   599 	test.Printf(_L("Creating 5 Contacts\n"));
       
   600 	CreateEntriesNoVerifyL(5);
       
   601 
       
   602 	// This While loop tests for steps:
       
   603 	// 2. Contacts only view becomes ready, and 
       
   604 	// 3. The two ICC views become available without ICC entries.
       
   605 
       
   606 	/* Expected events:
       
   607 	 * a) EReady (1) => non-ICC Contacts view is ready
       
   608 	 * b&c) EReady (1) => ICC Views become Ready empty or with contacts only
       
   609 	 */
       
   610 
       
   611 	// views with ICC entries should become ready now
       
   612 	while ((readyCount < 3) && iViewEventQueue->ListenForEvent(10,event))
       
   613 		{
       
   614 		// Expecting EReady events
       
   615 		switch (event.iEventType)
       
   616 			{
       
   617 		case TContactViewEvent::EItemAdded:
       
   618 			test.Printf(_L("Event received - EItemAdded\n"));
       
   619 			// ignore events from adding contacts
       
   620 			break;
       
   621 
       
   622 		case TContactViewEvent::EGroupChanged:
       
   623 			test.Printf(_L("Event received - EGroupChanged (group Id %i)\n"), event.iContactId);
       
   624 			// ignore events from adding contacts
       
   625 			break;
       
   626 
       
   627 		case TContactViewEvent::EReady:
       
   628 			test.Printf(_L("Event received - EReady\n"));
       
   629 			readyCount++;
       
   630 			break;
       
   631 
       
   632 		default:
       
   633 			test.Printf(_L("Unexpected event received (%i)\n"), event.iEventType);
       
   634 			test(0);
       
   635 			}
       
   636 		}
       
   637 
       
   638 	test(readyCount == 3);
       
   639 
       
   640 	// there should be 1 Synch Change Notification request outstanding per phonebook
       
   641 	TInt notificationCount = syncChecker->TotalNotificationPendingCountL();
       
   642 	test(notificationCount == iPhbkList.Count());
       
   643 
       
   644 	// check number of entries in views (ICC locked)
       
   645 	VerifyNumberOfEntriesInEachViewL(ESyncIccLocked);
       
   646 
       
   647 	// Test Step 5. The PhoneBook Synch then indicates that the Cache is Valid.
       
   648 	test(syncChecker->SynchroniseIccAllPhonebooksL(*iDb, KErrNone, KErrNone) == KErrNone);
       
   649 	test.Printf(_L("PhoneBook Synch completed, cache now valid\n"));
       
   650 
       
   651 	// Test Step 6. The two ICC views are updated (re-sorted) with the ICC entries.
       
   652 
       
   653 	/* The 2 Views with ICC entries will each have 2 events:
       
   654 	 * a) EUnavailable (0) => view is unavailable
       
   655 	 * b) ESortOrderChanged (2) => view is Ready again
       
   656 	 *
       
   657 	 * For the 2 Views these can be interleaved
       
   658 	 */
       
   659 	while ((unavailableCount < 2) || (sortOrderChangedCount < 2))
       
   660 		{
       
   661 		TBool eventReceived = iViewEventQueue->ListenForEvent(1,event);
       
   662 
       
   663 		if (eventReceived)
       
   664 			{
       
   665 			switch(event.iEventType)
       
   666 				{
       
   667 				case TContactViewEvent::EItemAdded:
       
   668 					test.Printf(_L("Event received - EItemAdded (Id %i)\n"), event.iContactId);
       
   669 					// ignore events from adding contacts
       
   670 					break;
       
   671 
       
   672 				case TContactViewEvent::EGroupChanged:
       
   673 					test.Printf(_L("Event received - EGroupChanged (group Id %i)\n"), event.iContactId);
       
   674 					// ignore events from adding contacts
       
   675 					break;
       
   676 
       
   677 				case TContactViewEvent::ESortOrderChanged:
       
   678 					test.Printf(_L("Event received - ESortOrderChanged\n"));
       
   679 					sortOrderChangedCount++;
       
   680 					test(sortOrderChangedCount <= unavailableCount);
       
   681 					break;
       
   682 
       
   683 				case TContactViewEvent::EUnavailable:
       
   684 					test.Printf(_L("Event received - EUnavailable\n"));
       
   685 					unavailableCount++;
       
   686 					test(unavailableCount <= 2);
       
   687 					break;
       
   688 
       
   689 				default:
       
   690 					test.Printf(_L("Unexpected event received (%i)\n"), event.iEventType);
       
   691 					test(EFalse);
       
   692 					break;
       
   693 				}
       
   694 			}	
       
   695 		}
       
   696 
       
   697 	// there should be 1 Synch Change Notification request outstanding per phonebook
       
   698 	notificationCount = syncChecker->TotalNotificationPendingCountL();
       
   699 	test(notificationCount == iPhbkList.Count());
       
   700 
       
   701 	// check number of entries in views (ICC synchronised)
       
   702 	VerifyNumberOfEntriesInEachViewL(ESynchronised);
       
   703 
       
   704 	// Check the number of requests made to the plug-in
       
   705 	// Expecting 6 calls in total from PhbkSync Watcher
       
   706 	// (NotifySyncStateChange + IsSynchronised) * 3
       
   707 	//
       
   708 	TInt methodCount = syncChecker->SyncMethodCallCountL();
       
   709 	// Number of expected calls to syncChecker->MethodCalledL()
       
   710 	test(methodCount = 6); 
       
   711 
       
   712 	// Test Step 7. Cleanup (deletes all entries)
       
   713 	// delete non-Icc entries
       
   714 	DeleteEntriesL(iNonIccContacts.Count());
       
   715 	// delete Icc entries
       
   716 	DeleteEntriesL(iIccContacts.Count(), ETrue);
       
   717 
       
   718 	// no entries left
       
   719 	test((iNonIccContacts.Count() == 0) && (iIccContacts.Count() == 0));
       
   720 
       
   721     // Flush all other events
       
   722 	iViewEventQueue->Flush();
       
   723 	}
       
   724 
       
   725 
       
   726 CICCViewTest::~CICCViewTest()
       
   727     {
       
   728 	iIccContacts.Reset();
       
   729 	iIccContacts.Close();
       
   730 	iNonIccContacts.Reset();
       
   731 	iNonIccContacts.Close();
       
   732     if (iContactsView)
       
   733 		iContactsView->Close(*iViewEventQueue);
       
   734     if (iIccView)
       
   735 		iIccView->Close(*iViewEventQueue);
       
   736     if (iContactsAndIccView)
       
   737 		iContactsAndIccView->Close(*iViewEventQueue);
       
   738 
       
   739 	delete iViewEventQueue;
       
   740     iViewSortOrder.Close();
       
   741 	delete iEntry;
       
   742 	delete iTemplate;
       
   743     delete iDb;
       
   744     TRAP_IGNORE(CContactDatabase::DeleteDatabaseL(KTestDbName));
       
   745     }
       
   746 
       
   747 void CICCViewTest::CreateEntriesL(TInt aNumberOfEntries, TBool aIsIccEntry)
       
   748 	{
       
   749 	iViewEventQueue->Flush();
       
   750 	for	(TInt i=0; i<aNumberOfEntries; i++)
       
   751 		{
       
   752 		CreateEntryL(aIsIccEntry);
       
   753 		}
       
   754 
       
   755 	// wait for views to be updated
       
   756 	TContactViewEvent event;
       
   757 	test(iViewEventQueue->ListenForEvent(10,event));
       
   758 	test((event.iEventType == TContactViewEvent::EItemAdded) || (event.iEventType == TContactViewEvent::EGroupChanged));
       
   759 
       
   760     // Eat away events
       
   761     do{}
       
   762 	while (iViewEventQueue->ListenForEvent(1,event));
       
   763 
       
   764 	// Check views
       
   765 	VerifyNumberOfEntriesInEachViewL(ESynchronised);
       
   766 	}
       
   767 
       
   768 void CICCViewTest::CreateEntriesNoVerifyL(TInt aNumberOfEntries, TBool aIsIccEntry)
       
   769 	{
       
   770 	// add Contacts entries, but don't verify now
       
   771 	for	(TInt i=0; i<aNumberOfEntries; i++)
       
   772 		{
       
   773 		if(aIsIccEntry)
       
   774 			{
       
   775 			test.Printf(_L("  Adding SIM contact - - -\n"));
       
   776 			}
       
   777 		CreateEntryL(aIsIccEntry);
       
   778 		}
       
   779 	}
       
   780 
       
   781 void CICCViewTest::CreateEntryL(TBool aIsIccEntry)
       
   782 	{
       
   783 	TBool iccEntry=EFalse;
       
   784 	if	(aIsIccEntry)
       
   785 		{
       
   786 		if (iTemplate == NULL)
       
   787 			{
       
   788 			TContactItemId templateId = iDb->ICCTemplateIdL(iPhbkList[0]);
       
   789 			iTemplate = iDb->ReadContactL(templateId);
       
   790 			}
       
   791 
       
   792 		iEntry=CContactICCEntry::NewL(*iTemplate);
       
   793 		iccEntry=ETrue;
       
   794 		}
       
   795 	else
       
   796 		{
       
   797 		iEntry=CContactCard::NewL();
       
   798 		}
       
   799 
       
   800 	HBufC* buf=HBufC::NewLC(32);
       
   801 	TPtr bufPtr=buf->Des();
       
   802 	SetRandomAlphaString(bufPtr,16);
       
   803 
       
   804 	CContactItemFieldSet& fieldSet=iEntry->CardFields();
       
   805 	const TInt pos=fieldSet.Find(KUidContactFieldGivenName);
       
   806 	if (pos!=KErrNotFound)
       
   807 		fieldSet[pos].TextStorage()->SetTextL(bufPtr);
       
   808 
       
   809 	iDb->AddNewContactL(*iEntry);
       
   810 	if(iccEntry)
       
   811 		{
       
   812 		iIccContacts.Append(iEntry->Id());
       
   813 		}
       
   814 	else
       
   815 		{
       
   816 		iNonIccContacts.Append(iEntry->Id());
       
   817 		}
       
   818 	CleanupStack::PopAndDestroy(buf);
       
   819 
       
   820 	delete iEntry;
       
   821 	iEntry=NULL;
       
   822 	}
       
   823 
       
   824 void CICCViewTest::DeleteEntriesL(TInt aNumberOfEntries, TBool aIccEntry)
       
   825 	{
       
   826 	if(aIccEntry)
       
   827 		{
       
   828 		const TInt max = iIccContacts.Count();
       
   829 		if(aNumberOfEntries > max)
       
   830 			{
       
   831 			aNumberOfEntries = max;
       
   832 			}
       
   833 
       
   834 		for(TInt i=0; i<aNumberOfEntries; i++)
       
   835 			{
       
   836 			iDb->DeleteContactL(iIccContacts[0]);
       
   837 			iIccContacts.Remove(0);
       
   838 			}
       
   839 		}
       
   840 	else
       
   841 		{
       
   842 		const TInt max = iNonIccContacts.Count();
       
   843 		if(aNumberOfEntries > max)
       
   844 			{
       
   845 			aNumberOfEntries = max;
       
   846 			}
       
   847 
       
   848 		for(TInt i=0; i<aNumberOfEntries; i++)
       
   849 			{
       
   850 			iDb->DeleteContactL(iNonIccContacts[0]);
       
   851 			iNonIccContacts.Remove(0);
       
   852 			}
       
   853 		}
       
   854 
       
   855     // Eat away events
       
   856 	TContactViewEvent event;
       
   857     do{}
       
   858 	while (iViewEventQueue->ListenForEvent(1,event));
       
   859 
       
   860 	// Check views
       
   861 	VerifyNumberOfEntriesInEachViewL(ESynchronised);
       
   862 	}
       
   863 
       
   864 void CICCViewTest::VerifyNumberOfEntriesInEachViewL(TSyncStatus aSyncStatus)
       
   865 	{
       
   866 	// any sync status -> check non Icc View
       
   867 	TInt nonIcc = iContactsView->CountL();
       
   868 	// number items in view matches the number of contacts added?
       
   869 	test(nonIcc == iNonIccContacts.Count());
       
   870 
       
   871 
       
   872 	// should ICC views be ready?
       
   873 	if (aSyncStatus == ESynchronised || aSyncStatus == ESyncIccLocked)
       
   874 		{
       
   875 		TInt Icc=iIccView->CountL();
       
   876 		TInt both=iContactsAndIccView->CountL();
       
   877 		
       
   878 		if (aSyncStatus == ESynchronised)
       
   879 			{
       
   880 			test(Icc == iInitialIccCount + iIccContacts.Count());
       
   881 			test(both == iInitialIccCount + iNonIccContacts.Count() + iIccContacts.Count());
       
   882 			}
       
   883 		else // ESyncIccLocked -> no sync of ICC entries
       
   884 			{
       
   885 			test(Icc == iIccContacts.Count());
       
   886 			test(both == iNonIccContacts.Count() + iIccContacts.Count());
       
   887 			}
       
   888 		}
       
   889 	}
       
   890 
       
   891 void CICCViewTest::SetRandomAlphaString(TDes& aBuf,TInt aLength)
       
   892 	{
       
   893 	aBuf.SetLength(aLength);
       
   894 
       
   895 	for (TInt ii=0;ii<aLength;++ii)
       
   896 		{
       
   897 		aBuf[ii]=RandomCharCode('A','z',' ');
       
   898 		}
       
   899 	}
       
   900 
       
   901 TText CICCViewTest::RandomCharCode(TText aLowerBound,TText aUpperBound,TText aException)
       
   902 	{
       
   903 	TText charCode=0;
       
   904 
       
   905 	do
       
   906 		{
       
   907 		charCode=RandomCharCode(aLowerBound,aUpperBound);
       
   908 		}
       
   909 		while (charCode==aException);
       
   910 
       
   911 	return charCode;
       
   912 	}
       
   913 
       
   914 TText CICCViewTest::RandomCharCode(TText aLowerBound,TText aUpperBound)
       
   915 	{
       
   916 	TText charCode=STATIC_CAST(TText,(Math::Rand(iRandSeed)%(aUpperBound-aLowerBound))+aLowerBound);
       
   917 	ASSERT(charCode>=aLowerBound && charCode<=aUpperBound);
       
   918 	return charCode;
       
   919 	}
       
   920 	
       
   921 void CheckForPhbkSyncPluginL()
       
   922 	{
       
   923 	test.Next(_L("Check for PhbkSync test plug-in"));
       
   924 
       
   925 	RImplInfoPtrArray	implInfoArray;
       
   926 	CleanupResetAndDestroyPushL(implInfoArray);
       
   927 	REComSession::ListImplementationsL(KUidEcomCntPhBkSyncInterface, implInfoArray);
       
   928 	//Find implementations of KUidEcomCntPhBkSyncInterface
       
   929 	TInt availCount = implInfoArray.Count(); 
       
   930 	TInt count;
       
   931 	for(count = 0; count < availCount; count++)
       
   932 		{
       
   933 		const TUid firstImplementationFound = implInfoArray[count]->ImplementationUid();
       
   934 		CImplementationInformation *info = implInfoArray[count];
       
   935 		test.Printf(_L("\n"));
       
   936 		test.Printf(_L("PhbkSync plugin #%i, Implementation UID 0x%08X version %i\n"),
       
   937 			count + 1, info->ImplementationUid(), info->Version());
       
   938 		test.Printf(_L("Plugin name = \"%S\"\n"), &(info->DisplayName()));
       
   939 		}
       
   940 
       
   941 	// is telephony's plug-in in the list?
       
   942 	for(count = 0; count < availCount; count++)
       
   943 		{
       
   944 		const TUid firstImplementationFound = implInfoArray[count]->ImplementationUid();
       
   945 		CImplementationInformation *info = implInfoArray[count];
       
   946 		if(info->DisplayName() == KTestPluginName)
       
   947 			{
       
   948 			test.Printf(_L("\n"));
       
   949 			test.Printf(_L("This test has now loaded the test plugin"));
       
   950 			test.Printf(_L("\n"));
       
   951 			availCount = 1;
       
   952 			break;
       
   953 			}		
       
   954 		
       
   955 		if(info->DisplayName() == KPluginName)
       
   956 			{
       
   957 			test.Printf(_L("\n"));
       
   958 			test.Printf(_L("This test only works with Contacts the test plugin and not the original phonebooksync plugin."));
       
   959 			test.Printf(_L("Depending on the build to removed the plugin in different ways:"));
       
   960 			test.Printf(_L("hardware - delete the line \"ECOM_PLUGIN(phbksyncplugin.dll,1020428C.rsc)\" from phbksync.iby"));
       
   961 			test.Printf(_L("winscw - delete phbksyncplugin.dll from %epocroot%/epoc32/release/winscw/udeb or similarly named directory"));
       
   962 			test.Printf(_L("\n"));
       
   963 			test(0);  // stop
       
   964 			break;
       
   965 			}
       
   966 		}
       
   967 
       
   968 	// only continue test if there is exactly one plug-in present
       
   969 	test(availCount == 1);	
       
   970 
       
   971 	CleanupStack::PopAndDestroy(&implInfoArray);
       
   972 
       
   973 	}
       
   974 
       
   975 	
       
   976 void CICCViewTest::TestOneOrFiveL(TBool aCreateViewBeforeSync)
       
   977     {	
       
   978 	// Tests succesful Phonebook Synchronisation
       
   979     if (aCreateViewBeforeSync)
       
   980     	{
       
   981 		CheckViewCreateAndSyncEventsL(KErrNone, KErrNone);
       
   982 
       
   983 
       
   984 		test.Next(_L("Test creation and deletion of ICC entries"));
       
   985 		// create some icc and non-icc entries
       
   986 		CreateEntriesL(5);
       
   987 		CreateEntriesL(4, ETrue);
       
   988 		CreateEntriesL(2);
       
   989 
       
   990 		// delete some icc and non-icc entries
       
   991 		DeleteEntriesL(3);
       
   992 		DeleteEntriesL(iIccContacts.Count(), ETrue);
       
   993 		DeleteEntriesL(iNonIccContacts.Count());
       
   994     	}
       
   995     else
       
   996     	{
       
   997     	SyncThenCreateViewCheckEventsL(KErrNone, KErrNone);
       
   998     	}
       
   999 	}
       
  1000 
       
  1001 void CICCViewTest::TestTwoL()
       
  1002     {
       
  1003     // NB test only valid for creating view before Sync happens
       
  1004     // test condition when notification request completes with an error
       
  1005 	CheckViewCreateAndSyncEventsL(KErrGeneral, KErrNone);
       
  1006 	}
       
  1007 
       
  1008 void CICCViewTest::TestThreeOrSixL(TBool aCreateViewBeforeSync)
       
  1009     {
       
  1010     // test condition where notification completes okay, but IsSynchronisedL() leaves with an error
       
  1011     if (aCreateViewBeforeSync)
       
  1012     	{
       
  1013 		CheckViewCreateAndSyncEventsL(KErrNone, KErrGeneral);
       
  1014     	}
       
  1015     else
       
  1016     	{
       
  1017     	SyncThenCreateViewCheckEventsL(KErrNone, KErrGeneral);
       
  1018     	}
       
  1019 	}
       
  1020 
       
  1021 void CICCViewTest::TestFourL()
       
  1022     {	
       
  1023 	CheckEventsForTestFourL();
       
  1024 	}
       
  1025 
       
  1026 void CICCViewTest::TestSevenL()
       
  1027     {	
       
  1028 	CheckEventsForTestSevenL();
       
  1029 	}
       
  1030 
       
  1031 void CICCViewTest::TestConcurrenceL()
       
  1032     {
       
  1033     test(syncChecker->SynchroniseIccAllPhonebooksL(*iDb, KErrNone, KErrNone) == KErrNone);
       
  1034     
       
  1035     CContactRemoteView* iccRemoteView = CContactRemoteView::NewL(*iViewEventQueue, *iDb, iViewSortOrder, EICCEntriesOnly);
       
  1036     
       
  1037     TContactViewEvent event;
       
  1038 	test(iViewEventQueue->ListenForEvent(10,event));
       
  1039 
       
  1040 	// Expecting EReady event
       
  1041 	test.Printf(_L("Event received (%i)\n"), event.iEventType);
       
  1042 	test(event.iEventType == TContactViewEvent::EReady);
       
  1043 	
       
  1044 	//Create and close another contact client session
       
  1045 	CContactDatabase* newDb = CContactDatabase::OpenL(KTestDbName);
       
  1046     delete newDb;    	
       
  1047     
       
  1048     //Close the view to see if there is concurrence resource conflication.
       
  1049     iccRemoteView->Close(*iViewEventQueue);
       
  1050 
       
  1051 	//delete all icc and non-icc entries
       
  1052 	DeleteEntriesL(iIccContacts.Count(), ETrue);
       
  1053     }
       
  1054 	
       
  1055 void RunTestOneL(const RArray<TUid> aPhonebookList)
       
  1056 	{
       
  1057 	test.Next(_L("Test view construction (create view before sync)"));
       
  1058 
       
  1059 	CICCViewTest* viewTest=CICCViewTest::NewLC(aPhonebookList);
       
  1060 	viewTest->TestOneOrFiveL(ETrue);
       
  1061 	
       
  1062 	CleanupStack::PopAndDestroy(viewTest); 
       
  1063 	}
       
  1064 
       
  1065 void RunTestTwoL(const RArray<TUid> aPhonebookList)
       
  1066 	{
       
  1067 	test.Next(_L("Test error handling: NotifySyncStateChange (create view before sync)"));
       
  1068 
       
  1069 	CICCViewTest* viewTest=CICCViewTest::NewLC(aPhonebookList);
       
  1070 	viewTest->TestTwoL();
       
  1071 	CleanupStack::PopAndDestroy(viewTest);
       
  1072 	}
       
  1073 
       
  1074 void RunTestThreeL(const RArray<TUid> aPhonebookList)
       
  1075 	{
       
  1076 	test.Next(_L("Test error handling: IsICCSynchronisedL (create view before sync)"));
       
  1077 
       
  1078 	CICCViewTest* viewTest=CICCViewTest::NewLC(aPhonebookList);
       
  1079 	viewTest->TestThreeOrSixL(ETrue);
       
  1080 	CleanupStack::PopAndDestroy(viewTest);
       
  1081 	}
       
  1082 
       
  1083 void RunTestFourL(const RArray<TUid> aPhonebookList)
       
  1084 	{
       
  1085 	test.Next(_L("Test error handling: SIM Locked and then Unlocked (create view before sync)"));
       
  1086 
       
  1087 	CICCViewTest* viewTest=CICCViewTest::NewLC(aPhonebookList);
       
  1088 	viewTest->TestFourL();
       
  1089 	CleanupStack::PopAndDestroy(viewTest);
       
  1090 	}
       
  1091 
       
  1092 void RunTestFiveL(const RArray<TUid> aPhonebookList)
       
  1093 	{
       
  1094 	test.Next(_L("Test view construction (sync before view creation)"));
       
  1095 
       
  1096 	CICCViewTest* viewTest=CICCViewTest::NewLC(aPhonebookList);
       
  1097 	viewTest->TestOneOrFiveL(EFalse);
       
  1098 	
       
  1099 	CleanupStack::PopAndDestroy(viewTest); 
       
  1100 	}
       
  1101 
       
  1102 void RunTestSixL(const RArray<TUid> aPhonebookList)
       
  1103 	{
       
  1104 	test.Next(_L("Test error handling: IsICCSynchronisedL (sync before view creation)"));
       
  1105 
       
  1106 	CICCViewTest* viewTest=CICCViewTest::NewLC(aPhonebookList);
       
  1107 	viewTest->TestThreeOrSixL(EFalse);
       
  1108 	CleanupStack::PopAndDestroy(viewTest);
       
  1109 	}
       
  1110 
       
  1111 void RunTestSevenL(const RArray<TUid> aPhonebookList)
       
  1112 	{
       
  1113 	test.Next(_L("Test error handling: SIM Locked and then Unlocked (sync before view creation)"));
       
  1114 
       
  1115 	CICCViewTest* viewTest=CICCViewTest::NewLC(aPhonebookList);
       
  1116 	viewTest->TestSevenL();
       
  1117 	CleanupStack::PopAndDestroy(viewTest);
       
  1118 	}
       
  1119 
       
  1120 void RunConcurrenceTestL(const RArray<TUid> aPhonebookList)
       
  1121 	{
       
  1122 	test.Next(_L("Test error handling: SIM Locked and then Unlocked (sync before view creation)"));
       
  1123 
       
  1124 	CICCViewTest* viewTest = CICCViewTest::NewLC(aPhonebookList);
       
  1125     viewTest->TestConcurrenceL();
       
  1126 	
       
  1127 	CleanupStack::PopAndDestroy(viewTest);
       
  1128 	}
       
  1129 
       
  1130 /**
       
  1131 
       
  1132 @SYMTestCaseID PIM-T-ICCVIEW-0001
       
  1133 
       
  1134 */
       
  1135 	
       
  1136 void DoTestsL()
       
  1137 	{
       
  1138 	test.Start(KTestName);
       
  1139 
       
  1140 	CheckForPhbkSyncPluginL();
       
  1141 
       
  1142 	syncChecker = CContactSyncChecker::NewL();
       
  1143 	syncChecker->ResetEverythingL();
       
  1144 	//syncChecker->EnableVerboseLoggingL();
       
  1145 
       
  1146 	RArray<TUid>	phbkList;
       
  1147 	CleanupClosePushL(phbkList);
       
  1148 
       
  1149 	for(TInt loop = 0; loop < 3; ++loop)
       
  1150 		{
       
  1151 		switch (loop)
       
  1152 			{
       
  1153 		case 0:
       
  1154 			phbkList.Reset();
       
  1155 			phbkList.AppendL(KUidIccGlobalAdnPhonebook);
       
  1156 			test.Next(_L("Test with GSM Global ADN phonebook"));
       
  1157 			break;
       
  1158 
       
  1159 		case 1:
       
  1160 			phbkList.Reset();
       
  1161 			phbkList.AppendL(KUidUsimAppAdnPhonebook);
       
  1162 			test.Next(_L("Test with USIM App ADN phonebook"));
       
  1163 			break;
       
  1164 
       
  1165 		case 2:
       
  1166 			phbkList.Reset();
       
  1167 			phbkList.AppendL(KUidIccGlobalAdnPhonebook);
       
  1168 			phbkList.AppendL(KUidUsimAppAdnPhonebook);
       
  1169 			test.Next(_L("Test with GSM Global and USIM App ADN phonebooks"));
       
  1170 			break;
       
  1171 
       
  1172 		default:
       
  1173 			test(0);
       
  1174 			}
       
  1175 
       
  1176 		test.Start(_L("Phonebook Sync tests"));
       
  1177 			// all tests work with any number of phonebooks
       
  1178 		RunTestOneL(phbkList);
       
  1179 		RunTestTwoL(phbkList);
       
  1180 		RunTestThreeL(phbkList);
       
  1181 		RunTestFourL(phbkList);
       
  1182 		
       
  1183 		RunTestFiveL(phbkList);
       
  1184 		RunTestSixL(phbkList);
       
  1185 		RunTestSevenL(phbkList);
       
  1186 
       
  1187 		test.End();
       
  1188 		}
       
  1189 	
       
  1190 #ifdef CNTTEST_ICCREMOTEVIEW
       
  1191 	//The concurrence test is marked off because currently the cntsyncchecker has
       
  1192 	//problem in remoteview which will block the contact server. -- See INC112963
       
  1193 	test.Next(_L("Phonebook Sync Concurrence Test"));
       
  1194 	phbkList.Reset();
       
  1195 	phbkList.AppendL(KUidUsimAppAdnPhonebook);
       
  1196 	RunConcurrenceTestL(phbkList);
       
  1197 #endif //CNTTEST_ICCREMOTEVIEW
       
  1198 	
       
  1199 	test.End();
       
  1200     test.Close();
       
  1201 
       
  1202 	CleanupStack::PopAndDestroy(); // phbkList
       
  1203 
       
  1204 	delete syncChecker;
       
  1205 	syncChecker = NULL;
       
  1206 	}
       
  1207 
       
  1208 GLDEF_C TInt E32Main()
       
  1209 	{
       
  1210 	RProcess().SetPriority(EPriorityBackground);
       
  1211     CTrapCleanup* cleanupStack = CTrapCleanup::New();
       
  1212     if (!cleanupStack)
       
  1213         {
       
  1214         return KErrNoMemory;
       
  1215         }
       
  1216 
       
  1217     CActiveScheduler* activeScheduler = new CActiveScheduler;
       
  1218     if (!activeScheduler)
       
  1219         {
       
  1220         return KErrNoMemory;
       
  1221         }
       
  1222     CActiveScheduler::Install(activeScheduler);
       
  1223 
       
  1224     // Run the tests
       
  1225     TRAPD(err, DoTestsL());
       
  1226 
       
  1227 	if (syncChecker)
       
  1228 		{
       
  1229 		delete syncChecker;
       
  1230 		syncChecker = NULL;
       
  1231 		}
       
  1232 
       
  1233 	test(err == KErrNone);
       
  1234 
       
  1235     // Cleanup
       
  1236     delete activeScheduler;
       
  1237     delete cleanupStack;
       
  1238 	return err;
       
  1239     }