pimprotocols/phonebooksync/Test/TE_cntsync/te_cntsyncsync.cpp
changeset 0 e686773b3f54
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 
       
    18 #include "te_cntsyncbase.h"
       
    19 #include "te_cntsyncsync.h"
       
    20 
       
    21 _LIT(KSatNameInADN, "SATNotify Entry ADN");
       
    22 _LIT(KSatNameInSDN, "SATNotify Entry SDN");
       
    23 _LIT(KSatNameInLND, "SATNotify Entry LND");
       
    24 _LIT(KSatNameInUsim, "SATNotify Entry Usim");
       
    25 _LIT(KSatNameInFDN, "SATNotify Entry FDN");
       
    26 
       
    27  
       
    28 /** 
       
    29  * Factory construction method.
       
    30  * @return Pointer to CPhbkSyncAutomaticSameICCTest object
       
    31  */
       
    32 CPhbkSyncAutomaticSameICCTest* CPhbkSyncAutomaticSameICCTest::NewL()
       
    33 	{
       
    34 	CPhbkSyncAutomaticSameICCTest* self = new(ELeave) CPhbkSyncAutomaticSameICCTest();
       
    35 	return self;
       
    36 	}
       
    37 
       
    38 /**
       
    39  *  Default constructor.  Each test step initialises it's own name.
       
    40  */
       
    41 CPhbkSyncAutomaticSameICCTest::CPhbkSyncAutomaticSameICCTest()
       
    42 	{
       
    43 	SetTestStepName(_L("SyncAutomaticSameICCTest"));
       
    44 	}
       
    45 
       
    46 /** 
       
    47  * If we are unsynchronised and we set the mode to automatic same ICC, we wait until
       
    48  * the next client to connect before synchronising. 
       
    49  */
       
    50 enum TVerdict CPhbkSyncAutomaticSameICCTest::doTestStepL()
       
    51 	{
       
    52 	SetSimTsyTestNumberL(1);
       
    53 	DoSyncL(); // First do initial synchronisation
       
    54 
       
    55 	// Set sync mode to Automatic Same ICC for all phonebooks
       
    56 	SetSyncModeL(RPhoneBookSession::EAutoSameIcc);
       
    57 
       
    58 	// Check sync mode is set to Automatic Same ICC for all phonebooks
       
    59 	CheckSyncModeL(RPhoneBookSession::EAutoSameIcc);
       
    60  	delete iDb;
       
    61  	iDb=NULL;
       
    62 	iSession.Close();
       
    63 	ConfigurePhbkSyncToIdleL();
       
    64 	ConfigurePhbkSyncToFullL();
       
    65 	iDb = OpenOrCreateContactDatabaseL();
       
    66 	User::LeaveIfError(iSession.Connect()); // Re-connect again 
       
    67 	User::After(3000000); // 3 seconds to ensure server has chance to fully startup
       
    68 
       
    69 	// Check sync mode is still set to Automatic Same ICC for all phonebooks
       
    70 	CheckSyncModeL(RPhoneBookSession::EAutoSameIcc);
       
    71 	
       
    72 	// Wait until cache becomes usable
       
    73 	WaitForSyncToCompleteL();
       
    74 
       
    75 	// Verify cache is valid for all phonebooks
       
    76 	CheckCacheStateL(RPhoneBookSession::ECacheValid);
       
    77 
       
    78 	SetSimTsyTestNumberL(0); // This configuration has different IMSI number to previous one, so
       
    79 							 // this means that Auto Sync should NOT be started
       
    80 	CContactDatabase* db = NULL; // Start an instance of contacts model and do some 
       
    81 								 // operation to force a sync
       
    82 	TRAPD(err, db = OpenOrCreateContactDatabaseL());
       
    83 	TESTCHECKL(err, KErrNone);
       
    84 	TRAP(err, db->ICCTemplateIdL()); // Connects to the server
       
    85 
       
    86 	TESTCHECKL(err, KErrNone); // template ID can be retrieved
       
    87 	delete db;
       
    88 
       
    89 	// Verify cache is not valid for all phonebooks
       
    90 	CheckCacheStateL(RPhoneBookSession::EUnsynchronised);
       
    91 	User::After(5000000); // Wait 5s and then check that cache state has not changed
       
    92 	CheckCacheStateL(RPhoneBookSession::EUnsynchronised);
       
    93 
       
    94 	SetSimTsyTestNumberL(1); // Going back to last configuration with same IMSI number as previous
       
    95 							 // one, so this means that Auto Sync should be started as soon as we 
       
    96 							 // connect to the server
       
    97 
       
    98 	// Wait until cache becomes usable
       
    99 	WaitForSyncToCompleteL();
       
   100 
       
   101 	// Verify cache is valid for all phonebooks
       
   102 	CheckCacheStateL(RPhoneBookSession::ECacheValid);
       
   103 
       
   104 	return TestStepResult();
       
   105 	}
       
   106 
       
   107 
       
   108 /** 
       
   109  * Factory construction method.
       
   110  * @return Pointer to CPhbkSyncAutomaticCurrentICCTest object
       
   111  */
       
   112 CPhbkSyncAutomaticCurrentICCTest* CPhbkSyncAutomaticCurrentICCTest::NewL()
       
   113 	{
       
   114 	CPhbkSyncAutomaticCurrentICCTest* self = new(ELeave) CPhbkSyncAutomaticCurrentICCTest();
       
   115 	return self;
       
   116 	}
       
   117 
       
   118 /**
       
   119  *  Default constructor.  Each test step initialises it's own name.
       
   120  */
       
   121 CPhbkSyncAutomaticCurrentICCTest::CPhbkSyncAutomaticCurrentICCTest()
       
   122 	{
       
   123 	SetTestStepName(_L("SyncAutomaticCurrentICCTest"));
       
   124 	}
       
   125 
       
   126 /** 
       
   127  * If we are unsynchronised and we set the mode to automatic current, we wait until
       
   128  * the next client to connect before synchronising.
       
   129  */
       
   130 enum TVerdict CPhbkSyncAutomaticCurrentICCTest::doTestStepL()
       
   131 	{
       
   132 	// Set sync mode to Automatic Same ICC for all phonebooks
       
   133 	SetSyncModeL(RPhoneBookSession::EAutoCurrentIcc);
       
   134 
       
   135 	CheckSyncModeL(RPhoneBookSession::EAutoCurrentIcc);
       
   136 
       
   137 	delete iDb;
       
   138  	iDb=NULL;
       
   139 	iSession.Close();
       
   140 	ConfigurePhbkSyncToIdleL();
       
   141 	ConfigurePhbkSyncToFullL();
       
   142 	iDb = OpenOrCreateContactDatabaseL();
       
   143 	User::LeaveIfError(iSession.Connect()); // Re-connect again 
       
   144 	User::After(5000000); // 5 seconds to ensure server has chance to start up
       
   145 
       
   146 	CheckSyncModeL(RPhoneBookSession::EAutoCurrentIcc); // Check sync mode is still Automatic 
       
   147 	WaitForSyncToCompleteL();
       
   148 
       
   149 	// Verify cache is valid
       
   150 	CheckCacheStateL(RPhoneBookSession::ECacheValid);
       
   151 
       
   152 	// Start an instance of contacts model and do some operation to force a sync
       
   153 	CContactDatabase* db = NULL;
       
   154 	TRAPD(err, db = OpenOrCreateContactDatabaseL());
       
   155 	TESTCHECKL(err, KErrNone);
       
   156 	TContactItemId templateId(0);					  
       
   157 	TRAP(err, templateId = db->ICCTemplateIdL()); // Connects to the server
       
   158 	TESTCHECKCONDITIONL(templateId != KNullContactId);
       
   159 	delete db;
       
   160 
       
   161 	// Wait until cache becomes usable
       
   162 	WaitForSyncToCompleteL();
       
   163 
       
   164 	// Verify cache is valid for all phonebooks
       
   165 	CheckCacheStateL(RPhoneBookSession::ECacheValid);
       
   166 
       
   167 	return TestStepResult();
       
   168 	}
       
   169 
       
   170 
       
   171 /** 
       
   172  * Factory construction method.
       
   173  * @return Pointer to CPhbkSyncManualTest object
       
   174  */
       
   175 CPhbkSyncManualTest* CPhbkSyncManualTest::NewL()
       
   176 	{
       
   177 	CPhbkSyncManualTest* self = new(ELeave) CPhbkSyncManualTest();
       
   178 	return self;
       
   179 	}
       
   180 
       
   181 /**
       
   182  *  Default constructor.  Each test step initialises it's own name.
       
   183  */
       
   184 CPhbkSyncManualTest::CPhbkSyncManualTest()
       
   185 	{
       
   186 	SetTestStepName(_L("SyncManualTest"));
       
   187 	}
       
   188 
       
   189 /** Re-Synchronisation (Manual) */
       
   190 enum TVerdict CPhbkSyncManualTest::doTestStepL()
       
   191 	{
       
   192 	DoSyncL();
       
   193 	WaitForSyncToCompleteL();
       
   194 
       
   195 	RPhoneBookSession::TSyncState state; // First check that initial Synchronisation was successful 
       
   196 	iSession.GetPhoneBookCacheState(state); 
       
   197 	TESTCHECKL(state, RPhoneBookSession::ECacheValid);
       
   198 
       
   199 	// Set mode to Manual
       
   200 	SetSyncModeL(RPhoneBookSession::EManual);
       
   201 
       
   202 	CheckSyncModeL(RPhoneBookSession::EManual);
       
   203 	DoSyncL();
       
   204 
       
   205 	// Wait until cache becomes usable
       
   206 	WaitForSyncToCompleteL();
       
   207 
       
   208 	// Verify cache is valid for all phonebooks
       
   209 	CheckCacheStateL(RPhoneBookSession::ECacheValid);
       
   210 
       
   211 	return TestStepResult();
       
   212 	}
       
   213 
       
   214 
       
   215 /** 
       
   216  * Factory construction method.
       
   217  * @return Pointer to CPhbkSyncManualNotReadyTest object
       
   218  */
       
   219 CPhbkSyncManualNotReadyTest* CPhbkSyncManualNotReadyTest::NewL()
       
   220 	{
       
   221 	CPhbkSyncManualNotReadyTest* self = new(ELeave) CPhbkSyncManualNotReadyTest();
       
   222 	return self;
       
   223 	}
       
   224 
       
   225 /**
       
   226  *  Default constructor.  Each test step initialises it's own name.
       
   227  */
       
   228 CPhbkSyncManualNotReadyTest::CPhbkSyncManualNotReadyTest()
       
   229 	{
       
   230 	SetTestStepName(_L("SyncManualNotReadyTest"));
       
   231 	}
       
   232 
       
   233 /** Try to open a new session and attempt a manual sync before the device has time to 
       
   234     get the SubscriberId. The Server should wait untill the SubscriberID is known before continuing */
       
   235 enum TVerdict CPhbkSyncManualNotReadyTest::doTestStepL()
       
   236 	{
       
   237 	delete iDb;
       
   238  	iDb=NULL;
       
   239 	iSession.Close();
       
   240 	ConfigurePhbkSyncToIdleL();
       
   241 	ConfigurePhbkSyncToFullL();
       
   242 	iDb = OpenOrCreateContactDatabaseL();
       
   243 	User::LeaveIfError(iSession.Connect()); // Re-connect again 
       
   244 	
       
   245 	// Set mode to Manual
       
   246 	SetSyncModeL(RPhoneBookSession::EManual);
       
   247 
       
   248 	CheckSyncModeL(RPhoneBookSession::EManual);
       
   249 
       
   250 	User::After(3000000); // 3 seconds to ensure server has chance to fully startup
       
   251 	
       
   252 	TRAPD(err, DoSyncL()); // and try sync immediately (Timing window - when debugging, do not step through)
       
   253 	TESTCHECKL(err, KErrNone);	
       
   254 	
       
   255 	// Wait until cache becomes usable
       
   256 	WaitForSyncToCompleteL();
       
   257 
       
   258 	// Verify cache is valid for all phonebooks
       
   259 	CheckCacheStateL(RPhoneBookSession::ECacheValid);
       
   260 
       
   261 	return TestStepResult();
       
   262 	}
       
   263 
       
   264 
       
   265 /** 
       
   266  * Factory construction method.
       
   267  * @return Pointer to CPhbkSyncManualDiffSizeSIMTest object
       
   268  */
       
   269 CPhbkSyncManualDiffSizeSIMTest* CPhbkSyncManualDiffSizeSIMTest::NewL()
       
   270 	{
       
   271 	CPhbkSyncManualDiffSizeSIMTest* self = new(ELeave) CPhbkSyncManualDiffSizeSIMTest();
       
   272 	return self;
       
   273 	}
       
   274 
       
   275 /**
       
   276  *  Default constructor.  Each test step initialises it's own name.
       
   277  */
       
   278 CPhbkSyncManualDiffSizeSIMTest::CPhbkSyncManualDiffSizeSIMTest()
       
   279 	{
       
   280 	SetTestStepName(_L("SyncManualDiffSizeSIMTest"));
       
   281 	}
       
   282 
       
   283 /** 
       
   284  * Test synchronising a SIM with a different number of slots.
       
   285  */
       
   286 enum TVerdict CPhbkSyncManualDiffSizeSIMTest::doTestStepL()
       
   287 	{
       
   288 	//
       
   289 	// Sync with a SIM which has 22 entries used out of 25 for each of the 5 phonebooks...
       
   290 	//
       
   291 	SetSimTsyTestNumberL(24);	
       
   292 	User::LeaveIfError(iSession.SetSyncMode(RPhoneBookSession::EManual));
       
   293 	CheckSyncModeL(RPhoneBookSession::EManual);
       
   294 	DoSyncL();
       
   295 	WaitForSyncToCompleteL();
       
   296 	
       
   297 	iDb->SetDbViewContactType(KUidContactICCEntry);
       
   298 	const CContactIdArray* sortedItems = iDb->SortedItemsL();
       
   299 	TInt  count(sortedItems->Count());
       
   300 	TESTCHECKL(count, KTest24ICCSlotsUsed);
       
   301 
       
   302 	//
       
   303 	// Sync with a SIM which has 3 entries used out of 15 for each of the 5 phonebooks...//
       
   304 	//
       
   305 	SetSimTsyTestNumberL(25);
       
   306 	DoSyncL();
       
   307 	WaitForSyncToCompleteL();
       
   308 
       
   309 	iDb->SetDbViewContactType(KUidContactICCEntry);
       
   310 	sortedItems = iDb->SortedItemsL();
       
   311 	count = sortedItems->Count();
       
   312 	TESTCHECKL(count, KTest25ICCSlotsUsed);
       
   313 
       
   314 	//
       
   315 	// Check that all slots can be read successfully.  This used to leave in a defect case.
       
   316 	//
       
   317 	for (TInt index = 0;  index < count;  index++)
       
   318 		{ 
       
   319 		TContactItemId  id = (*sortedItems)[index];
       
   320 		CContactItemViewDef*  view = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields,
       
   321 			                                                    CContactItemViewDef::EMaskHiddenFields);
       
   322 		view->AddL(KUidContactFieldPhoneNumber); 
       
   323 		TESTCHECKL(view->Count(), 1);
       
   324 		CContactICCEntry* entry = static_cast<CContactICCEntry*>(iDb->ReadContactL(id, *view)); 
       
   325 		delete entry;
       
   326 		CleanupStack::PopAndDestroy(1, view);
       
   327 		} 
       
   328 
       
   329 	//
       
   330 	// Sync with a SIM which has 22 entries used out of 25 for each of the 5 phonebooks...
       
   331 	//
       
   332 	SetSimTsyTestNumberL(24);
       
   333 	DoSyncL();
       
   334 	WaitForSyncToCompleteL();
       
   335 
       
   336 	iDb->SetDbViewContactType(KUidContactICCEntry);
       
   337 	sortedItems = iDb->SortedItemsL();
       
   338 	count = sortedItems->Count();
       
   339 	TESTCHECKL(count, KTest24ICCSlotsUsed);
       
   340 
       
   341 	return TestStepResult();
       
   342 	}
       
   343 
       
   344 
       
   345 /** 
       
   346  * Factory construction method.
       
   347  * @return Pointer to CPhbkSyncSATUpdatesTestBase object
       
   348  */
       
   349 CPhbkSyncSATUpdatesTestBase* CPhbkSyncSATUpdatesTestBase::NewL()
       
   350 	{
       
   351 	CPhbkSyncSATUpdatesTestBase* self = new(ELeave) CPhbkSyncSATUpdatesTestBase();
       
   352 	return self;
       
   353 	}
       
   354 
       
   355 /**
       
   356  *  Default constructor.  Each test step initialises it's own name.
       
   357  */
       
   358 CPhbkSyncSATUpdatesTestBase::CPhbkSyncSATUpdatesTestBase()
       
   359 	{
       
   360 	SetTestStepName(_L("SyncSATUpdatesTest"));
       
   361 	}
       
   362 
       
   363 /** 
       
   364  * Re-Synchronisation (SIM Toolkit initiated).
       
   365  * SIM is OK. Synchronisation mode is "Auto Sync, Current ICC".
       
   366  * Test initial synchronisation is successful. Then test that
       
   367  * a subsequent "SIM toolkit refresh" notification leads to a 
       
   368  * second synchronisation.
       
   369  */
       
   370 enum TVerdict CPhbkSyncSATUpdatesTestBase::doTestStepL()
       
   371 	{
       
   372 	//
       
   373 	// Sync to a basic SIM to allow the following sync to complete quicky...
       
   374 	//
       
   375 	SetSyncModeL(RPhoneBookSession::EManual);
       
   376 	CheckSyncModeL(RPhoneBookSession::EManual);
       
   377 	SetSimTsyTestNumberL(0);
       
   378 	DoSyncL();
       
   379 	WaitForSyncToCompleteL();
       
   380 
       
   381 	SetSyncModeL(RPhoneBookSession::EAutoCurrentIcc);
       
   382 	CheckSyncModeL(RPhoneBookSession::EAutoCurrentIcc);
       
   383 
       
   384 	//
       
   385 	// Switch to a SIM TSY configuration which sends a "refresh" notification
       
   386 	// at some point in the future and sync all phonebooks.
       
   387 	//
       
   388 	SetSimTsyTestNumberL(7);
       
   389 	WaitForSyncToCompleteL();
       
   390 	CheckCacheStateL(RPhoneBookSession::ECacheValid);
       
   391 
       
   392 	TInt  numSlots, result;
       
   393 	TContactItemId  aId0, aId1, aId2, aId3, aId4, aId5, aId6;
       
   394 
       
   395 	result = iSession.GetNumSlots(numSlots, KUidIccGlobalAdnPhonebook);
       
   396 	TESTCHECK(result, KErrNone);
       
   397 	TESTCHECK(numSlots, 20);
       
   398 
       
   399 	result = iSession.GetSlotId(0, aId0, KUidIccGlobalAdnPhonebook);
       
   400 	TESTCHECK(result, KErrNotFound);
       
   401 	result = iSession.GetSlotId(1, aId1, KUidIccGlobalAdnPhonebook);
       
   402 	TESTCHECK(result, KErrNotFound);
       
   403 	result = iSession.GetSlotId(2, aId2, KUidIccGlobalAdnPhonebook);
       
   404 	TESTCHECK(result, KErrNotFound);
       
   405 	result = iSession.GetSlotId(3, aId3, KUidIccGlobalAdnPhonebook);
       
   406 	TESTCHECK(result, KErrNotFound);
       
   407 	result = iSession.GetSlotId(4, aId4, KUidIccGlobalAdnPhonebook);
       
   408 	TESTCHECK(result, KErrNone);
       
   409 	result = iSession.GetSlotId(5, aId5, KUidIccGlobalAdnPhonebook);
       
   410 	TESTCHECK(result, KErrNone);
       
   411 	result = iSession.GetSlotId(6, aId6, KUidIccGlobalAdnPhonebook);
       
   412 	TESTCHECK(result, KErrNone);
       
   413 
       
   414 	result = iSession.GetSlotId(0, aId0, KUidUsimAppAdnPhonebook);
       
   415 	TESTCHECK(result, KErrNotFound);
       
   416 	result = iSession.GetSlotId(1, aId1, KUidUsimAppAdnPhonebook);
       
   417 	TESTCHECK(result, KErrNone);
       
   418 	result = iSession.GetSlotId(2, aId2, KUidUsimAppAdnPhonebook);
       
   419 	TESTCHECK(result, KErrNone);
       
   420 	result = iSession.GetSlotId(3, aId3, KUidUsimAppAdnPhonebook);
       
   421 	TESTCHECK(result, KErrNotFound);
       
   422 	result = iSession.GetSlotId(4, aId4, KUidUsimAppAdnPhonebook);
       
   423 	TESTCHECK(result, KErrNotFound);
       
   424 	result = iSession.GetSlotId(5, aId5, KUidUsimAppAdnPhonebook);
       
   425 	TESTCHECK(result, KErrNotFound);
       
   426 	result = iSession.GetSlotId(6, aId6, KUidUsimAppAdnPhonebook);
       
   427 	TESTCHECK(result, KErrNotFound);
       
   428 
       
   429 	CheckNameInDBL(KSatNameInADN);
       
   430 	CheckNameInDBL(KSatNameInSDN);
       
   431 	CheckNameInDBL(KSatNameInLND);
       
   432 	CheckNameInDBL(KSatNameInUsim);
       
   433 	CheckNameInDBL(KSatNameInFDN);
       
   434 
       
   435 	//
       
   436 	// Wait for a notification that one of the phonebooks has changed state and
       
   437 	// that they are all now unsynchronised...
       
   438 	//
       
   439 	SignalSimTsyToReduceTimersL();
       
   440 	
       
   441 	TRequestStatus  status1;
       
   442 	iSession.NotifyPhBkCacheStateChange(status1, KUidIccGlobalAdnPhonebook);
       
   443 	User::WaitForRequest(status1);
       
   444 	TESTCHECK(status1.Int(), KErrNone);
       
   445 	
       
   446 	CheckCacheStateL(RPhoneBookSession::EUnsynchronised);//sat notification has been triggered
       
   447 	
       
   448 	//
       
   449 	// Wait for SAT notified sync to finish and check they are all now valid...
       
   450 	//
       
   451 	WaitForSyncToCompleteL();
       
   452 	CheckCacheStateL(RPhoneBookSession::ECacheValid);
       
   453 
       
   454 	CheckNameInDBL(KSatNameInADN);
       
   455 	CheckNameInDBL(KSatNameInSDN);
       
   456 	CheckNameInDBL(KSatNameInLND);
       
   457 	CheckNameInDBL(KSatNameInUsim);
       
   458 	CheckNameInDBL(KSatNameInFDN);
       
   459 
       
   460 	return TestStepResult();
       
   461 	}
       
   462 
       
   463 
       
   464 /** 
       
   465  * Factory construction method.
       
   466  * @return Pointer to CPhbkSyncICCLockedTestBase object
       
   467  */
       
   468 CPhbkSyncICCLockedTestBase* CPhbkSyncICCLockedTestBase::NewL()
       
   469 	{
       
   470 	CPhbkSyncICCLockedTestBase* self = new(ELeave) CPhbkSyncICCLockedTestBase();
       
   471 	return self;
       
   472 	}
       
   473 
       
   474 /**
       
   475  *  Default constructor.  Each test step initialises it's own name.
       
   476  */
       
   477 CPhbkSyncICCLockedTestBase::CPhbkSyncICCLockedTestBase()
       
   478 	{
       
   479 	SetTestStepName(_L("SyncICCLockedTest"));
       
   480 	}
       
   481 
       
   482 /**
       
   483  * Synchronisation when ICC is locked. Synchroniser is initially unable to perform 
       
   484  * synchronisation because ICC is locked, but when ICC becomes unlocked the synchronisation 
       
   485  * completes successfully.
       
   486  */
       
   487 enum TVerdict CPhbkSyncICCLockedTestBase::doTestStepL()
       
   488 	{
       
   489 	SetSimTsyTestNumberL(8); // ICC locked, so Synchronisation is not carried out 
       
   490 	SetSyncModeL(RPhoneBookSession::EManual);
       
   491 	CheckSyncModeL(RPhoneBookSession::EManual);
       
   492 
       
   493 	TRAPD(err, DoSyncFailL());
       
   494 	TESTCHECKL(err, KErrNone);
       
   495 
       
   496 	// Verify cache is not in valid state for all phonebooks
       
   497 	CheckCacheStateL(RPhoneBookSession::EErrorDuringSync);
       
   498 
       
   499 	// Save test time by prompting the SIMTSY...
       
   500 	SignalSimTsyToReduceTimersL();
       
   501 
       
   502 	TInt err1(KErrAccessDenied), err2(KErrAccessDenied), err3(KErrAccessDenied), 
       
   503 		err4(KErrAccessDenied), err5(KErrAccessDenied);
       
   504 	while (err1==KErrAccessDenied  ||  err1==KErrInUse  ||
       
   505 	       err2==KErrAccessDenied  ||  err2==KErrInUse  ||
       
   506 	       err3==KErrAccessDenied  ||  err3==KErrInUse  ||
       
   507 	       err4==KErrAccessDenied  ||  err4==KErrInUse  ||
       
   508 	       err5==KErrAccessDenied  ||  err5==KErrInUse)
       
   509 		{
       
   510 		// Global ADN Phonebook
       
   511 		TRequestStatus status1;
       
   512 		iSession.DoSynchronisation(status1);
       
   513 		User::WaitForRequest(status1);
       
   514 		err1 = status1.Int();
       
   515 
       
   516 		// Global SDN Phonebook
       
   517 		TRequestStatus status2;
       
   518 		iSession.DoSynchronisation(status2, KUidIccGlobalSdnPhonebook);
       
   519 		User::WaitForRequest(status2);
       
   520 		err2 = status2.Int();
       
   521 
       
   522 		// Global LND Phonebook
       
   523 		TRequestStatus status3;
       
   524 		iSession.DoSynchronisation(status3, KUidIccGlobalLndPhonebook);
       
   525 		User::WaitForRequest(status3);
       
   526 		err3 = status3.Int();
       
   527 
       
   528 		// Usim App ADN Phonebook
       
   529 		TRequestStatus status4;
       
   530 		iSession.DoSynchronisation(status4, KUidUsimAppAdnPhonebook);
       
   531 		User::WaitForRequest(status4);
       
   532 		err4 = status4.Int();
       
   533 
       
   534 		// Global FDN Phonebook
       
   535 		TRequestStatus status5;
       
   536 		iSession.DoSynchronisation(status5, KUidIccGlobalFdnPhonebook);
       
   537 		User::WaitForRequest(status5);
       
   538 		err5 = status5.Int();
       
   539 
       
   540 		// Allow the server sometime to run, otherwise it will be staved of CPU!
       
   541 		User::After(1);
       
   542 		}
       
   543 	TESTCHECKL(err1, KErrNone);
       
   544 	TESTCHECKL(err2, KErrNone);
       
   545 	TESTCHECKL(err3, KErrNone);
       
   546 	TESTCHECKL(err4, KErrNone);
       
   547 	TESTCHECKL(err5, KErrNone);
       
   548 
       
   549 	// Verify cache is valid for all phonebooks
       
   550 	CheckCacheStateL(RPhoneBookSession::ECacheValid);
       
   551 
       
   552 	return TestStepResult();
       
   553 	}
       
   554 
       
   555 
       
   556 /** 
       
   557  * Factory construction method.
       
   558  * @return Pointer to CPhbkSyncConsecutiveTestBase object
       
   559  */
       
   560 CPhbkSyncConsecutiveTestBase* CPhbkSyncConsecutiveTestBase::NewL()
       
   561 	{
       
   562 	CPhbkSyncConsecutiveTestBase* self = new(ELeave) CPhbkSyncConsecutiveTestBase();
       
   563 	return self;
       
   564 	}
       
   565 
       
   566 /**
       
   567  *  Default constructor.  Each test step initialises it's own name.
       
   568  */
       
   569 CPhbkSyncConsecutiveTestBase::CPhbkSyncConsecutiveTestBase()
       
   570 	{
       
   571 	SetTestStepName(_L("SyncConsecutiveTest"));
       
   572 	}
       
   573 
       
   574 /**
       
   575  * Consecutive calls to DoSync().
       
   576  */ 
       
   577 enum TVerdict CPhbkSyncConsecutiveTestBase::doTestStepL()
       
   578 	{
       
   579 	SetSimTsyTestNumberL(1); 
       
   580 
       
   581 	SetSyncModeL(RPhoneBookSession::EManual); // Make sure sync mode is set to Manual 
       
   582 
       
   583 	SetSimTsyTestNumberL(1); 
       
   584 	TRAPD(err, DoSyncL());
       
   585 	TRAP(err, DoSyncL());
       
   586 	TRAP(err, DoSyncL());
       
   587 	TRAP(err, DoSyncL());
       
   588 	TRAP(err, DoSyncL());
       
   589 
       
   590 	SetSyncModeL(RPhoneBookSession::EManual); // Set mode to manual for all phonebooks to avoid getting KErrInUse
       
   591 	CheckSyncModeL(RPhoneBookSession::EManual); // it might take some time to sync entries from this config 
       
   592 	SetSimTsyTestNumberL(0); 
       
   593 	TRAP(err, DoSyncL());
       
   594 
       
   595 	return TestStepResult();
       
   596 	}
       
   597 
       
   598 
       
   599 /** 
       
   600  * Factory construction method.
       
   601  * @return Pointer to CPhbkSyncFailureTestBase object
       
   602  */
       
   603 CPhbkSyncFailureTestBase* CPhbkSyncFailureTestBase::NewL()
       
   604 	{
       
   605 	CPhbkSyncFailureTestBase* self = new(ELeave) CPhbkSyncFailureTestBase();
       
   606 	return self;
       
   607 	}
       
   608 
       
   609 /**
       
   610  *  Default constructor.  Each test step initialises it's own name.
       
   611  */
       
   612 CPhbkSyncFailureTestBase::CPhbkSyncFailureTestBase()
       
   613 	{
       
   614 	SetTestStepName(_L("SyncFailureTest"));
       
   615 	}
       
   616 
       
   617 /** 
       
   618  * Synchronisation Failure.
       
   619  * SIM is wearing out. Synchronisation mode is "Auto Sync, Current ICC".
       
   620  * Synchronisation starts but one of the reads fails halfway through.
       
   621  */
       
   622 enum TVerdict CPhbkSyncFailureTestBase::doTestStepL()
       
   623 	{
       
   624 	RPhoneBookSession::TSyncState state;
       
   625 	TRequestStatus status;
       
   626 
       
   627 	SetSyncModeL(RPhoneBookSession::EAutoCurrentIcc);
       
   628 	CheckSyncModeL(RPhoneBookSession::EAutoCurrentIcc);
       
   629 
       
   630 	SetSimTsyTestNumberL(3); // This should kick off Auto Sync, please note that this config 
       
   631 							 // contains only Global/GSM ADN phonebook 
       
   632 	
       
   633 	User::After(10000000); // Wait 10s to ensure no Synchronisation has been done
       
   634 	iSession.GetPhoneBookCacheState(state); // Cache is unavailable
       
   635 	TESTCHECKL(state, RPhoneBookSession::EErrorDuringSync);
       
   636 
       
   637 	User::After(5000000); // Wait 5s e.g. for database to become unlocked or similar
       
   638 	   				      // just in case an error occured during synchronisation
       
   639 	iSession.DoSynchronisation(status); // Auto synchronisation failed so try manual sync
       
   640 	User::WaitForRequest(status);
       
   641 	TESTCHECKL(status.Int(), KErrNone);
       
   642 
       
   643 	iSession.GetPhoneBookCacheState(state);
       
   644 	while (state==RPhoneBookSession::EUnsynchronised) // Wait until cache becomes usable
       
   645 		{
       
   646 		iSession.GetPhoneBookCacheState(state);
       
   647 		User::After(1000000);
       
   648 		}
       
   649 	TESTCHECKL(state, RPhoneBookSession::ECacheValid); // Cache is now in valid state, 
       
   650 													   // but only for Global/GSM ADN phonebook
       
   651 	return TestStepResult();
       
   652 	}
       
   653 
       
   654 
       
   655 /** 
       
   656  * Factory construction method.
       
   657  * @return Pointer to CPhbkSyncSATUpdatesTestBase object
       
   658  */
       
   659 CPhbkSyncFailureAndCheckErrorTestBase* CPhbkSyncFailureAndCheckErrorTestBase::NewL()
       
   660 	{
       
   661 	CPhbkSyncFailureAndCheckErrorTestBase* self = new(ELeave) CPhbkSyncFailureAndCheckErrorTestBase();
       
   662 	return self;
       
   663 	}
       
   664 
       
   665 /**
       
   666  *  Default constructor.  Each test step initialises it's own name.
       
   667  */
       
   668 CPhbkSyncFailureAndCheckErrorTestBase::CPhbkSyncFailureAndCheckErrorTestBase()
       
   669 	{
       
   670 	SetTestStepName(_L("SyncFailureAndCheckErrorTest"));
       
   671 	}
       
   672 
       
   673 /** 
       
   674  * Synchronisation Failure.
       
   675  * SIM is wearing out. Synchronisation mode is "Auto Sync, Current ICC".
       
   676  * Synchronisation starts but one of the reads fails halfway through.
       
   677  */
       
   678 enum TVerdict CPhbkSyncFailureAndCheckErrorTestBase::doTestStepL()
       
   679 	{
       
   680 	RPhoneBookSession::TSyncState state;
       
   681 	TRequestStatus status, notifStatus;
       
   682 	
       
   683 	SetSyncModeL(RPhoneBookSession::EAutoCurrentIcc);
       
   684 	CheckSyncModeL(RPhoneBookSession::EAutoCurrentIcc);
       
   685 
       
   686 	SetSimTsyTestNumberL(3); // This should kick off Auto Sync
       
   687 	User::After(10000000); // Wait 10s to ensure no Synchronisation has been done
       
   688 	iSession.GetPhoneBookCacheState(state); // Cache is unavailable
       
   689 	TESTCHECKL(state, RPhoneBookSession::EErrorDuringSync);
       
   690 	TInt syncError;
       
   691 	iSession.GetLastSyncError(syncError);
       
   692 	TESTCHECKL(syncError, KErrBadHandle);
       
   693 
       
   694 	User::After(5000000); // Wait 5s e.g. for database to become unlocked or similar
       
   695 	   				      // just in case an error occured during synchronisation
       
   696 	iSession.NotifyPhBkCacheStateChange(notifStatus);
       
   697 	iSession.DoSynchronisation(status); // Auto synchronisation failed so try manual sync
       
   698 	User::WaitForRequest(status);
       
   699 	User::WaitForRequest(notifStatus);
       
   700 	TESTCHECKL(status.Int(), KErrNone);
       
   701 	TESTCHECKL(notifStatus.Int(), KErrNone);
       
   702 
       
   703 	iSession.GetPhoneBookCacheState(state);
       
   704 	while (state==RPhoneBookSession::EUnsynchronised) // Wait until cache becomes usable
       
   705 		{
       
   706 		iSession.GetPhoneBookCacheState(state);
       
   707 		User::After(1000000);
       
   708 		}
       
   709 	TESTCHECKL(state, RPhoneBookSession::ECacheValid); // Cache is now in valid state
       
   710 
       
   711 	return TestStepResult();
       
   712 	}
       
   713 
       
   714 
       
   715 /** 
       
   716  * Factory construction method.
       
   717  * @return Pointer to CPhbkSyncNotificationTestBase object
       
   718  */
       
   719 CPhbkSyncNotificationTestBase* CPhbkSyncNotificationTestBase::NewL()
       
   720 	{
       
   721 	CPhbkSyncNotificationTestBase* self = new(ELeave) CPhbkSyncNotificationTestBase();
       
   722 	return self;
       
   723 	}
       
   724 
       
   725 /**
       
   726  *  Default constructor.  Each test step initialises it's own name.
       
   727  */
       
   728 CPhbkSyncNotificationTestBase::CPhbkSyncNotificationTestBase()
       
   729 	{
       
   730 	SetTestStepName(_L("SyncNotificationTest"));
       
   731 	}
       
   732 
       
   733 enum TVerdict CPhbkSyncNotificationTestBase::doTestStepL()
       
   734 	{
       
   735 	RPhoneBookSession::TSyncState state; // First check that initial Synchronisation was successful 
       
   736 
       
   737 	SetSyncModeL(RPhoneBookSession::EManual);
       
   738 	CheckSyncModeL(RPhoneBookSession::EManual);
       
   739 	
       
   740 	SetSimTsyTestNumberL(0); // This should ensure no Auto Sync
       
   741 
       
   742 	TRequestStatus status, notifStatus;
       
   743 	TInt syncError;
       
   744 	iSession.NotifyPhBkCacheStateChange(notifStatus);
       
   745 	iSession.DoSynchronisation(status); // Auto synchronisation failed so try manual sync
       
   746 	iSession.CancelRequest(ESyncNotifyCacheStateChangeCancelClient);
       
   747 	User::WaitForRequest(notifStatus);
       
   748 	//notification can't be cancelled at this stage(server reset to unsybc before syncing)
       
   749 
       
   750 	iSession.NotifyPhBkCacheStateChange(notifStatus);
       
   751 	iSession.CancelRequest(ESyncNotifyCacheStateChangeCancelClient);
       
   752 	User::WaitForRequest(status);//sync has completed cache is valid
       
   753 	User::WaitForRequest(notifStatus);
       
   754 	TESTCHECKL(status.Int(), KErrNone);
       
   755 	TESTCHECKL(notifStatus.Int(), KErrCancel);//notification never completes
       
   756 	//notification has been cancelled.
       
   757 	iSession.GetPhoneBookCacheState(state); 
       
   758 	TESTCHECKL(state, RPhoneBookSession::ECacheValid); // Cache now in valid state 
       
   759 
       
   760 //sync will fail
       
   761 	SetSimTsyTestNumberL(3);
       
   762 	iSession.NotifyPhBkCacheStateChange(notifStatus);
       
   763 	iSession.DoSynchronisation(status); // Auto synchronisation failed so try manual sync
       
   764 	User::WaitForRequest(notifStatus);
       
   765 
       
   766 	iSession.NotifyPhBkCacheStateChange(notifStatus);
       
   767 	iSession.GetPhoneBookCacheState(state);
       
   768 
       
   769 	if(state==RPhoneBookSession::EErrorDuringSync)
       
   770 		{
       
   771 		iSession.CancelRequest(ESyncNotifyCacheStateChangeCancelClient);
       
   772 		User::WaitForRequest(notifStatus);
       
   773 		User::WaitForRequest(status);
       
   774 		iSession.GetLastSyncError(syncError);
       
   775 		TESTCHECKL(syncError, KErrBadHandle);//the sync has completed
       
   776 		}
       
   777 	if(state==RPhoneBookSession::EUnsynchronised)
       
   778 		{
       
   779 		User::WaitForRequest(notifStatus);
       
   780 		User::WaitForRequest(status);
       
   781 		iSession.GetPhoneBookCacheState(state);
       
   782 		TESTCHECKL(state, RPhoneBookSession::EErrorDuringSync); // Cache now in valid state 
       
   783 		iSession.GetLastSyncError(syncError);
       
   784 		TESTCHECKL(syncError, KErrBadHandle);//the sync has completed
       
   785 		}
       
   786 
       
   787 //sync will be successfull
       
   788 	SetSimTsyTestNumberL(1);
       
   789 	iSession.NotifyPhBkCacheStateChange(notifStatus);
       
   790 	iSession.DoSynchronisation(status); // Auto synchronisation failed so try manual sync
       
   791 	
       
   792 	User::WaitForRequest(notifStatus);
       
   793 
       
   794 	iSession.NotifyPhBkCacheStateChange(notifStatus);	
       
   795 	iSession.GetPhoneBookCacheState(state); 
       
   796 	
       
   797 	if(state==RPhoneBookSession::ECacheValid)
       
   798 		{
       
   799 		iSession.CancelRequest(ESyncNotifyCacheStateChangeCancelClient);
       
   800 		TESTCHECKL(status.Int(), KErrNone);//the sync has completed
       
   801 		User::WaitForRequest(notifStatus);
       
   802 		User::WaitForRequest(status);
       
   803 		}
       
   804 	if(state==RPhoneBookSession::EUnsynchronised)
       
   805 		{
       
   806 		User::WaitForRequest(notifStatus);
       
   807 		User::WaitForRequest(status);
       
   808 		iSession.GetPhoneBookCacheState(state);
       
   809 		TESTCHECKL(state, RPhoneBookSession::ECacheValid); // Cache now in valid state 
       
   810 		TESTCHECKL(status.Int(), KErrNone);//the sync has completed
       
   811 		}
       
   812 
       
   813 	return TestStepResult();
       
   814 	}
       
   815 
       
   816 
       
   817 /** 
       
   818  * Factory construction method.
       
   819  * @return Pointer to CPhbkSyncDeleteDBTestBase object
       
   820  */
       
   821 CPhbkSyncDeleteDBTestBase* CPhbkSyncDeleteDBTestBase::NewL()
       
   822 	{
       
   823 	CPhbkSyncDeleteDBTestBase* self = new(ELeave) CPhbkSyncDeleteDBTestBase();
       
   824 	return self;
       
   825 	}
       
   826 
       
   827 /**
       
   828  *  Default constructor.  Each test step initialises it's own name.
       
   829  */
       
   830 CPhbkSyncDeleteDBTestBase::CPhbkSyncDeleteDBTestBase()
       
   831 	{
       
   832 	SetTestStepName(_L("SyncDeleteDBTest"));
       
   833 	}
       
   834 
       
   835 /** 
       
   836  * Test deleting Contacts DB and requesting manual synchronisation. 
       
   837  */
       
   838 enum TVerdict CPhbkSyncDeleteDBTestBase::doTestStepL()
       
   839 	{
       
   840 	SetSyncModeL(RPhoneBookSession::EManual);
       
   841 
       
   842 	CheckSyncModeL(RPhoneBookSession::EManual);
       
   843 	// First reset all auto settings as they are not needed anymore
       
   844 	SetSimTsyTestNumberL(1);
       
   845 	DoSyncL();
       
   846 	SetSimTsyTestNumberL(0); // This method will close session, delete Contacts DB, 
       
   847 							// re-connect again and create Contacts database
       
   848 	DoSyncL(); // Do manual synchronisation
       
   849 
       
   850 	return TestStepResult();
       
   851 	}
       
   852 
       
   853 
       
   854 /** 
       
   855  * Factory construction method.
       
   856  * @return Pointer to CPhbkSyncEmptyICCTestBase object
       
   857  */
       
   858 CPhbkSyncEmptyICCTestBase* CPhbkSyncEmptyICCTestBase::NewL()
       
   859 	{
       
   860 	CPhbkSyncEmptyICCTestBase* self = new(ELeave) CPhbkSyncEmptyICCTestBase();
       
   861 	return self;
       
   862 	}
       
   863 
       
   864 /**
       
   865  *  Default constructor.  Each test step initialises it's own name.
       
   866  */
       
   867 CPhbkSyncEmptyICCTestBase::CPhbkSyncEmptyICCTestBase()
       
   868 	{
       
   869 	SetTestStepName(_L("SyncEmptyICCTest"));
       
   870 	}
       
   871 
       
   872 /**
       
   873  * Test syncing to Empty ICC
       
   874  */
       
   875 enum TVerdict CPhbkSyncEmptyICCTestBase::doTestStepL()
       
   876 	{
       
   877 	RPhoneBookSession::TSyncState state; // First check that initial Synchronisation was successful 
       
   878 	iSession.GetPhoneBookCacheState(state); 
       
   879 
       
   880 	SetSimTsyTestNumberL(14);
       
   881 
       
   882 	SetSyncModeL(RPhoneBookSession::EManual);
       
   883 
       
   884 	DoSyncL();
       
   885 
       
   886 	return TestStepResult();
       
   887 	}
       
   888 
       
   889 
       
   890 /** 
       
   891  * Factory construction method.
       
   892  * @return Pointer to CPhbkSyncICCSlotsManipulationTestBase object
       
   893  */
       
   894 CPhbkSyncICCSlotsManipulationTestBase* CPhbkSyncICCSlotsManipulationTestBase::NewL()
       
   895 	{
       
   896 	CPhbkSyncICCSlotsManipulationTestBase* self = new(ELeave) CPhbkSyncICCSlotsManipulationTestBase();
       
   897 	return self;
       
   898 	}
       
   899 
       
   900 /**
       
   901  *  Default constructor.  Each test step initialises it's own name.
       
   902  */
       
   903 CPhbkSyncICCSlotsManipulationTestBase::CPhbkSyncICCSlotsManipulationTestBase()
       
   904 	{
       
   905 	SetTestStepName(_L("SyncICCSlotsManipulationTest"));
       
   906 	}
       
   907 
       
   908 /**
       
   909  * Test syncing and condition of free slots
       
   910  */
       
   911 enum TVerdict CPhbkSyncICCSlotsManipulationTestBase::doTestStepL()
       
   912 	{
       
   913 	SetSimTsyTestNumberL(21);
       
   914 	DoSyncL();
       
   915 
       
   916 	CheckSlotManipulationL(KUidIccGlobalAdnPhonebook);
       
   917 	CheckSlotManipulationL(KUidIccGlobalSdnPhonebook);
       
   918 	CheckSlotManipulationL(KUidIccGlobalLndPhonebook);
       
   919 	CheckSlotManipulationL(KUidUsimAppAdnPhonebook);
       
   920 	CheckSlotManipulationL(KUidIccGlobalFdnPhonebook);
       
   921 
       
   922 	return TestStepResult();
       
   923 	}
       
   924 
       
   925 
       
   926 /** 
       
   927  * Factory construction method.
       
   928  * @return Pointer to CPhbkSyncICCSlotsManipulationAndWriteTestBase object
       
   929  */
       
   930 CPhbkSyncICCSlotsManipulationAndWriteTestBase* CPhbkSyncICCSlotsManipulationAndWriteTestBase::NewL()
       
   931 	{
       
   932 	CPhbkSyncICCSlotsManipulationAndWriteTestBase* self = new(ELeave) CPhbkSyncICCSlotsManipulationAndWriteTestBase();
       
   933 	return self;
       
   934 	}
       
   935 
       
   936 /**
       
   937  *  Default constructor.  Each test step initialises it's own name.
       
   938  */
       
   939 CPhbkSyncICCSlotsManipulationAndWriteTestBase::CPhbkSyncICCSlotsManipulationAndWriteTestBase()
       
   940 	{
       
   941 	SetTestStepName(_L("SyncICCSlotsManipulationAndWriteTest"));
       
   942 	}
       
   943 
       
   944 /**
       
   945  * Test syncing and writing to free slots
       
   946  */
       
   947 enum TVerdict CPhbkSyncICCSlotsManipulationAndWriteTestBase::doTestStepL()
       
   948 	{
       
   949 	SetSimTsyTestNumberL(21);
       
   950 	DoSyncL();
       
   951 
       
   952 	CheckSlotManipulationAndWriteL(KUidIccGlobalAdnPhonebook);
       
   953 	CheckSlotManipulationAndWriteL(KUidIccGlobalSdnPhonebook);
       
   954 	CheckSlotManipulationAndWriteL(KUidIccGlobalLndPhonebook);
       
   955 	CheckSlotManipulationAndWriteL(KUidUsimAppAdnPhonebook);
       
   956 	CheckSlotManipulationAndWriteL(KUidIccGlobalFdnPhonebook);
       
   957 
       
   958 	return TestStepResult();
       
   959 	}
       
   960 
       
   961 
       
   962 /**
       
   963  * Check whether this name exists in the Contact Model Database.
       
   964  */
       
   965 void CPhbkSyncIntegrationTestBase::CheckNameInDBL(const TDesC& aName)
       
   966 	{
       
   967 	CContactItemFieldDef* fieldDef=new(ELeave) CContactItemFieldDef;
       
   968 	CleanupStack::PushL(fieldDef);
       
   969 	fieldDef->AppendL(KUidContactFieldFamilyName); // define subset of fields to search
       
   970 	CContactIdArray* array = iDb->FindLC(aName,fieldDef);
       
   971 	TESTCHECKCONDITIONL(array->Count() != 0);
       
   972 	CleanupStack::PopAndDestroy(2,fieldDef);
       
   973 	}
       
   974 
       
   975 
       
   976 /**
       
   977  * Check free slots
       
   978  */
       
   979 void CPhbkSyncIntegrationTestBase::CheckSlotManipulationL(const TUid aPhonebook)
       
   980 	{
       
   981 	TInt err;
       
   982 	TInt aSlot;
       
   983 	TContactItemId aId=KNullContactId;
       
   984 	TInt numSlots; 
       
   985 	RArray<TInt> freeSlotArray;
       
   986 	CleanupClosePushL(freeSlotArray);
       
   987 	RArray<TInt> expectedFreeSlots; //create an array that contains the expected free slots
       
   988 	CleanupClosePushL(expectedFreeSlots);
       
   989 
       
   990 	expectedFreeSlots.Append(17);
       
   991 	expectedFreeSlots.Append(18);
       
   992 	expectedFreeSlots.Append(19);
       
   993 
       
   994 	// Usim App phonebook is smaller than others
       
   995 	if (aPhonebook != KUidUsimAppAdnPhonebook)
       
   996 		{
       
   997 		TInt i;
       
   998 		for (i=21;i<=38;i++)
       
   999 			expectedFreeSlots.Append(i);
       
  1000 		TInt ii;
       
  1001 		for (ii=42;ii<=50;ii++)
       
  1002 			expectedFreeSlots.Append(ii);
       
  1003 
       
  1004 		err = iSession.GetNumSlots(numSlots, aPhonebook);
       
  1005 		TESTCHECK(numSlots, 50);
       
  1006 		}
       
  1007 	else
       
  1008 		{
       
  1009 		err = iSession.GetNumSlots(numSlots, aPhonebook);
       
  1010 		TESTCHECK(numSlots, 20);
       
  1011 		}
       
  1012 
       
  1013 	iSession.GetFreeSlotsL(freeSlotArray, aPhonebook);
       
  1014 
       
  1015 	TESTCHECKL(freeSlotArray.Count(), expectedFreeSlots.Count());
       
  1016 	TInt j;
       
  1017 	for (j=0;j<freeSlotArray.Count();j++)
       
  1018 		{
       
  1019 		TESTCHECKL(expectedFreeSlots[j], freeSlotArray[j]);
       
  1020 		}
       
  1021 
       
  1022 	aSlot = freeSlotArray[0]-1;			// we know there are non empty slots before the empty ones
       
  1023 	err = iSession.GetSlotId(aSlot, aId, aPhonebook);
       
  1024 	TESTCHECKL(err, KErrNone);
       
  1025 	TESTCHECKCONDITIONL(aId > KNullContactId);
       
  1026 	
       
  1027 	aSlot = freeSlotArray[0];
       
  1028 	err = iSession.GetSlotId(aSlot, aId, aPhonebook);
       
  1029 	TESTCHECKL(err, KErrNotFound);
       
  1030 
       
  1031 	CleanupStack::PopAndDestroy(2); // freeSlotArray & expectedFreeSlots
       
  1032 	}
       
  1033 
       
  1034 
       
  1035 /**
       
  1036  * Check writing to free slots
       
  1037  */
       
  1038 void CPhbkSyncIntegrationTestBase::CheckSlotManipulationAndWriteL(const TUid aPhonebook)
       
  1039 	{
       
  1040 	TInt err;
       
  1041 	TInt aSlot;
       
  1042 	TContactItemId aId=KNullContactId;
       
  1043 	TInt numSlots; 
       
  1044 
       
  1045 	CPhbkIntegrationTestUtility* add = CPhbkIntegrationTestUtility::NewL();
       
  1046 	_LIT(Kslot17,"17");
       
  1047 	_LIT(Kslot18,"18");
       
  1048 
       
  1049 	// Usim App phonebook is smaller than others
       
  1050 	if (aPhonebook != KUidUsimAppAdnPhonebook)
       
  1051 		{
       
  1052 		err = iSession.GetNumSlots(numSlots, aPhonebook);
       
  1053 		TESTCHECK(numSlots, 50);
       
  1054 		}
       
  1055 	else
       
  1056 		{
       
  1057 		err = iSession.GetNumSlots(numSlots, aPhonebook);
       
  1058 		TESTCHECK(numSlots, 20);
       
  1059 		}
       
  1060 	
       
  1061 	//test add new contact at specified slot
       
  1062 	TInt matchingId;
       
  1063 	aSlot=17;
       
  1064 	err = iSession.GetSlotId(aSlot, aId, aPhonebook);
       
  1065 	TESTCHECKL(err, KErrNotFound);
       
  1066 
       
  1067 	add->AddContactL(KTestName, KTestNumber, Kslot17, aPhonebook, KTestEMail);
       
  1068 	err = iSession.GetSlotId(aSlot, aId, aPhonebook);
       
  1069 	TESTCHECKL(err, KErrNone);
       
  1070 	matchingId=aId;
       
  1071 
       
  1072 	//edit existing contact name
       
  1073 	iDb->SetDbViewContactType(KUidContactICCEntry);
       
  1074 	CContactICCEntry* entry = static_cast<CContactICCEntry*>(iDb->OpenContactLX(aId));
       
  1075 	CleanupStack::PushL(entry);
       
  1076 	add->ChangeNameFieldL(*entry,KModifiedName);
       
  1077 	iDb->CommitContactL(*entry);
       
  1078 	CleanupStack::PopAndDestroy(2);
       
  1079 	
       
  1080 	err = iSession.GetSlotId(aSlot, aId, aPhonebook);
       
  1081 	TESTCHECKL(err, KErrNone);
       
  1082 	TESTCHECKL(aId, matchingId);
       
  1083 
       
  1084 	//edit slot number
       
  1085 	iDb->SetDbViewContactType(KUidContactICCEntry);
       
  1086 	entry = static_cast<CContactICCEntry*>(iDb->OpenContactLX(aId));
       
  1087 	CleanupStack::PushL(entry);
       
  1088 
       
  1089 	CContactItemFieldSet& fieldset = entry->CardFields();
       
  1090 	const TInt pos(fieldset.Find(KUidContactFieldICCSlot));
       
  1091 	CContactItemField& field = fieldset[pos];
       
  1092 	CContactTextField* textfield = field.TextStorage();
       
  1093 	textfield->SetTextL(Kslot18);
       
  1094 	iDb->CommitContactL(*entry);
       
  1095 	CleanupStack::PopAndDestroy(2);
       
  1096 
       
  1097 	//check slot 17 is empty
       
  1098 	err = iSession.GetSlotId(aSlot, aId, aPhonebook);
       
  1099 	TESTCHECKL(err, KErrNotFound);
       
  1100 	
       
  1101 	//check slot 18 is not empty
       
  1102 	aSlot=18;
       
  1103 	err = iSession.GetSlotId(aSlot, aId, aPhonebook);
       
  1104 	TESTCHECKL(err, KErrNone);
       
  1105 	TESTCHECKL(aId, matchingId);
       
  1106 
       
  1107 	delete add;
       
  1108 	}
       
  1109 
       
  1110 /************************* STRESS TESTS ******************************/
       
  1111 
       
  1112 /** 
       
  1113  * Factory construction method.
       
  1114  * @return Pointer to CPhbkSyncMultipleRequestsTestBase object
       
  1115  */
       
  1116 CPhbkSyncMultipleRequestsTestBase* CPhbkSyncMultipleRequestsTestBase::NewL()
       
  1117 	{
       
  1118 	CPhbkSyncMultipleRequestsTestBase* self = new(ELeave) CPhbkSyncMultipleRequestsTestBase();
       
  1119 	return self;
       
  1120 	}
       
  1121 
       
  1122 /**
       
  1123  *  Default constructor.  Each test step initialises it's own name.
       
  1124  */
       
  1125 CPhbkSyncMultipleRequestsTestBase::CPhbkSyncMultipleRequestsTestBase()
       
  1126 	{
       
  1127 	SetTestStepName(_L("SyncMultipleRequestsTest"));
       
  1128 	}
       
  1129 
       
  1130 /**
       
  1131  * Test handling of the multiple phonebook synchronisation requests.
       
  1132  */
       
  1133 enum TVerdict CPhbkSyncMultipleRequestsTestBase::doTestStepL()
       
  1134 	{
       
  1135 	SetSimTsyTestNumberL(13);
       
  1136 	INFO_PRINTF1(_L("  First Sync"));
       
  1137 
       
  1138 	DoSyncL();
       
  1139 	RPhoneBookSession session;
       
  1140 	User::LeaveIfError(session.Connect()); // Second connection to the Phonebook Server
       
  1141 
       
  1142 	INFO_PRINTF1(_L("  Second Sync"));
       
  1143 	TRequestStatus status1, status2, status3;
       
  1144 	session.DoSynchronisation(status1); // Start first synchronisation
       
  1145 	session.DoSynchronisation(status2); // Start second synchronisation
       
  1146 	session.DoSynchronisation(status3); // Start third synchronisation
       
  1147 	User::WaitForRequest(status1);
       
  1148 	User::WaitForRequest(status2);
       
  1149 	User::WaitForRequest(status3);
       
  1150 	TESTCHECKL(status1.Int(), KErrNone);
       
  1151 	TESTCHECKL(status2.Int(), KErrInUse);
       
  1152 	TESTCHECKL(status3.Int(), KErrInUse);
       
  1153 
       
  1154 	INFO_PRINTF1(_L("  Third Sync"));
       
  1155 	TRequestStatus status4;
       
  1156 	session.DoSynchronisation(status4); // Now try to do another synchronisation
       
  1157 	User::WaitForRequest(status4);
       
  1158 	TESTCHECKL(status4.Int(), KErrNone); // This one should complete successfully
       
  1159 
       
  1160 	INFO_PRINTF1(_L("  Fourth Sync"));
       
  1161 	TRequestStatus status5, status6;
       
  1162 	session.DoSynchronisation(status5); // Now try multiple synchronisation requests again
       
  1163 	session.DoSynchronisation(status6); // Start second synchronisation
       
  1164 	User::WaitForRequest(status5);
       
  1165 	User::WaitForRequest(status6);
       
  1166 	TESTCHECKL(status5.Int(), KErrNone);
       
  1167 	TESTCHECKL(status6.Int(), KErrInUse);
       
  1168 
       
  1169 	INFO_PRINTF1(_L("  Fifth Sync"));
       
  1170 	TRequestStatus status7;
       
  1171 	session.DoSynchronisation(status7); // Now try to do another synchronisation
       
  1172 	User::WaitForRequest(status7);
       
  1173 	TESTCHECKL(status7.Int(), KErrNone); // This one should complete successfully
       
  1174 
       
  1175 	session.Close(); // Close second connection to the server
       
  1176 
       
  1177 	return TestStepResult();
       
  1178 	}
       
  1179 
       
  1180 
       
  1181 /** 
       
  1182  * Factory construction method.
       
  1183  * @return Pointer to CPhbkSyncGeneralResponseTestBase object
       
  1184  */
       
  1185 CPhbkSyncGeneralResponseTestBase* CPhbkSyncGeneralResponseTestBase::NewL()
       
  1186 	{
       
  1187 	CPhbkSyncGeneralResponseTestBase* self = new(ELeave) CPhbkSyncGeneralResponseTestBase();
       
  1188 	return self;
       
  1189 	}
       
  1190 
       
  1191 /**
       
  1192  *  Default constructor.  Each test step initialises it's own name.
       
  1193  */
       
  1194 CPhbkSyncGeneralResponseTestBase::CPhbkSyncGeneralResponseTestBase()
       
  1195 	{
       
  1196 	SetTestStepName(_L("SyncGeneralResponseTest"));
       
  1197 	}
       
  1198 
       
  1199 /**
       
  1200  *  Synchronises a phonebook.  The length of time to sync and optionally the
       
  1201  *  longest time taken to call GetPhoneBookCacheState() are measured.  The
       
  1202  *  function will fail the test if the longest call is greater than 15% of
       
  1203  *  the sync time (e.g. the server is unresponsive).
       
  1204  *
       
  1205  *  @param aPhonebookUid   Phonebook to synchronise.
       
  1206  *  @param aTestResponse   If true, the response time of the server will be measured.
       
  1207  *  @param aPhonebookName  Textual representation of the phonebook name.
       
  1208  */
       
  1209 void CPhbkSyncGeneralResponseTestBase::DoSyncAndTestServerResponceL(TUid aPhonebookUid,
       
  1210 																	TBool aTestResponse,
       
  1211 																	const TDesC& aPhonebookName)
       
  1212 	{
       
  1213 	RPhoneBookSession::TSyncState  state(RPhoneBookSession::EUnsynchronised);
       
  1214 	TRequestStatus  status; 
       
  1215 	TTime  startOfSync, endOfSync;
       
  1216 	TInt64  lengthOfSync(0), longestCall(0);
       
  1217 
       
  1218 	//
       
  1219 	// Request sync...
       
  1220 	//
       
  1221 	startOfSync.UniversalTime();
       
  1222 	iSession.DoSynchronisation(status, aPhonebookUid);
       
  1223 
       
  1224 	//
       
  1225 	// Either monitor the responsiveness or just wait for the sync to
       
  1226 	// complete...
       
  1227 	//
       
  1228 	if (aTestResponse != EFalse)
       
  1229 		{
       
  1230 		//
       
  1231 		// Wait if needed, checking every 0.1 seconds...
       
  1232 		//
       
  1233 		while (state == RPhoneBookSession::EUnsynchronised) 
       
  1234 			{
       
  1235 			TTime  start, end;
       
  1236 			TInt  result;
       
  1237 
       
  1238 			start.UniversalTime();
       
  1239 			result = iSession.GetPhoneBookCacheState(state, aPhonebookUid);
       
  1240 			end.UniversalTime();
       
  1241 			if (result != KErrNone)
       
  1242 				{
       
  1243 				state = RPhoneBookSession::EUnsynchronised;
       
  1244 				}
       
  1245 
       
  1246 			TInt64  lengthOfCall = end.MicroSecondsFrom(start).Int64();
       
  1247 
       
  1248 			if (lengthOfCall > longestCall)
       
  1249 				{
       
  1250 				longestCall = lengthOfCall;
       
  1251 				}
       
  1252 
       
  1253 			//
       
  1254 			// If not finished then wait a short amount of time.
       
  1255 			//
       
  1256 			if (state == RPhoneBookSession::EUnsynchronised)
       
  1257 				{
       
  1258 				User::After(1); // Will become the minimum time period on the device.
       
  1259 				}
       
  1260 			}
       
  1261 		}
       
  1262 
       
  1263 	//
       
  1264 	// Complete the sync request...
       
  1265 	//
       
  1266 	User::WaitForRequest(status);
       
  1267 	TESTCHECK(status.Int(), KErrNone);
       
  1268 
       
  1269 	endOfSync.UniversalTime();
       
  1270 	lengthOfSync = endOfSync.MicroSecondsFrom(startOfSync).Int64();
       
  1271 
       
  1272 	//
       
  1273 	// Check the sync was successful...
       
  1274 	//
       
  1275 	TInt  result;
       
  1276 	
       
  1277 	result = iSession.GetPhoneBookCacheState(state, aPhonebookUid);
       
  1278 	TESTCHECK(result, KErrNone);
       
  1279 	TESTCHECK(state, RPhoneBookSession::ECacheValid);
       
  1280 
       
  1281 	if (aTestResponse != EFalse)
       
  1282 		{
       
  1283 		//
       
  1284 		// Check that the longest time taken to call GetPhoneBookCacheState() (e.g. the
       
  1285 		// latency in the server handling new requests) is less than 25% of the total
       
  1286 		// time to sync.  On average the time to delete the unconfirmed contacts will be
       
  1287 		// at least 75% of the sync time.
       
  1288 		//
       
  1289 		TInt64  callLimit((lengthOfSync * 25) / 100);
       
  1290 		
       
  1291 		INFO_PRINTF4(_L("  Length of %S sync was %.3fs and the longest call was %.3fs."),
       
  1292 					 &aPhonebookName, I64REAL(lengthOfSync) / 1000000.0,
       
  1293 					 I64REAL(longestCall) / 1000000.0);
       
  1294 
       
  1295 		if (longestCall > callLimit)
       
  1296 			{
       
  1297 			INFO_PRINTF3(_L("    Longest call of %.3fs was not within the limit of %.3fs."),
       
  1298 						 I64REAL(longestCall) / 1000000.0,
       
  1299 						 I64REAL(callLimit) / 1000000.0);
       
  1300 			SetTestStepResult(EFail);		
       
  1301 			}
       
  1302 		}
       
  1303 	else
       
  1304 		{
       
  1305 		//
       
  1306 		// Just print the total sync time...
       
  1307 		//
       
  1308 		INFO_PRINTF3(_L("  Length of %S sync was %.3fs without response testing."),
       
  1309 					 &aPhonebookName, I64REAL(lengthOfSync) / 1000000.0);
       
  1310 		}
       
  1311 	}
       
  1312 
       
  1313 /** 
       
  1314  *  Test synchronising a SIM with a different number of slots such that the PBS Server uses a
       
  1315  *  CIdle object to complete the operation in the background.  It should be possible for the
       
  1316  *  PBS Server to handle requests frequently before the sync completes.
       
  1317  */
       
  1318 enum TVerdict CPhbkSyncGeneralResponseTestBase::doTestStepL()
       
  1319 	{
       
  1320 	//
       
  1321 	// Run this test at high priority to ensure that the timings are not affected
       
  1322 	// by other threads
       
  1323 	//
       
  1324 	RThread().SetPriority(EPriorityAbsoluteHigh);
       
  1325 
       
  1326 	//
       
  1327 	// Sync with a SIM which has 22 entries used out of 25 for each of the 5 phonebooks...
       
  1328 	//
       
  1329 	SetSyncModeL(RPhoneBookSession::EManual);
       
  1330 	CheckSyncModeL(RPhoneBookSession::EManual);
       
  1331 	SetSimTsyTestNumberL(24);
       
  1332 	DoSyncL();
       
  1333 	WaitForSyncToCompleteL();
       
  1334 
       
  1335 	iDb->SetDbViewContactType(KUidContactICCEntry);
       
  1336 	const CContactIdArray* sortedItems = iDb->SortedItemsL();
       
  1337 	TESTCHECK(sortedItems->Count(), KTest24ICCSlotsUsed);
       
  1338 
       
  1339 	//
       
  1340 	// Start sync'ing to a SIM which has 3 entries used out of 15 for each of the 5 phonebooks.
       
  1341 	// Wait for the synchronisation to complete, but monitor the maximum length of time that
       
  1342 	// it takes for the GetPhoneBookCacheState() to complete...
       
  1343 	//
       
  1344 	SetSimTsyTestNumberL(25);
       
  1345 	DoSyncAndTestServerResponceL(KUidIccGlobalAdnPhonebook, ETrue, _L("ADN"));
       
  1346 	DoSyncAndTestServerResponceL(KUidIccGlobalSdnPhonebook, ETrue, _L("SDN"));
       
  1347 	DoSyncAndTestServerResponceL(KUidIccGlobalLndPhonebook, ETrue, _L("LND"));
       
  1348 	DoSyncAndTestServerResponceL(KUidUsimAppAdnPhonebook, ETrue, _L("USIM ADN"));
       
  1349 	DoSyncAndTestServerResponceL(KUidIccGlobalFdnPhonebook, ETrue, _L("FDN"));
       
  1350 
       
  1351 	iDb->SetDbViewContactType(KUidContactICCEntry);
       
  1352 	sortedItems = iDb->SortedItemsL();
       
  1353 	TESTCHECK(sortedItems->Count(), KTest25ICCSlotsUsed);
       
  1354 
       
  1355 	//
       
  1356 	// Now perform the reverse case and start sync'ing to a SIM which has 22 entries used out
       
  1357 	// of 25 for each of the 5 phonebooks...
       
  1358 	//
       
  1359 	SetSimTsyTestNumberL(24);
       
  1360 	DoSyncAndTestServerResponceL(KUidIccGlobalAdnPhonebook, ETrue, _L("ADN"));
       
  1361 	DoSyncAndTestServerResponceL(KUidIccGlobalSdnPhonebook, ETrue, _L("SDN"));
       
  1362 	DoSyncAndTestServerResponceL(KUidIccGlobalLndPhonebook, ETrue, _L("LND"));
       
  1363 	DoSyncAndTestServerResponceL(KUidUsimAppAdnPhonebook, ETrue, _L("USIM ADN"));
       
  1364 	DoSyncAndTestServerResponceL(KUidIccGlobalFdnPhonebook, ETrue, _L("FDN"));
       
  1365 
       
  1366 	iDb->SetDbViewContactType(KUidContactICCEntry);
       
  1367 	sortedItems = iDb->SortedItemsL();
       
  1368 	TESTCHECK(sortedItems->Count(), KTest24ICCSlotsUsed);
       
  1369 
       
  1370 	//
       
  1371 	// Start sync'ing to a SIM which has 3 entries used out of 15 for each of the 5 phonebooks.
       
  1372 	// Time how long the sync takes.
       
  1373 	//
       
  1374 	SetSimTsyTestNumberL(25);
       
  1375 	DoSyncAndTestServerResponceL(KUidIccGlobalAdnPhonebook, EFalse, _L("ADN"));
       
  1376 	DoSyncAndTestServerResponceL(KUidIccGlobalSdnPhonebook, EFalse, _L("SDN"));
       
  1377 	DoSyncAndTestServerResponceL(KUidIccGlobalLndPhonebook, EFalse, _L("LND"));
       
  1378 	DoSyncAndTestServerResponceL(KUidUsimAppAdnPhonebook, EFalse, _L("USIM ADN"));
       
  1379 	DoSyncAndTestServerResponceL(KUidIccGlobalFdnPhonebook, EFalse, _L("FDN"));
       
  1380 
       
  1381 	iDb->SetDbViewContactType(KUidContactICCEntry);
       
  1382 	sortedItems = iDb->SortedItemsL();
       
  1383 	TESTCHECK(sortedItems->Count(), KTest25ICCSlotsUsed);
       
  1384 
       
  1385 	//
       
  1386 	// Now perform the reverse case and start sync'ing to a SIM which has 22 entries used out
       
  1387 	// of 25 for each of the 5 phonebooks...
       
  1388 	//
       
  1389 	SetSimTsyTestNumberL(24);
       
  1390 	DoSyncAndTestServerResponceL(KUidIccGlobalAdnPhonebook, EFalse, _L("ADN"));
       
  1391 	DoSyncAndTestServerResponceL(KUidIccGlobalSdnPhonebook, EFalse, _L("SDN"));
       
  1392 	DoSyncAndTestServerResponceL(KUidIccGlobalLndPhonebook, EFalse, _L("LND"));
       
  1393 	DoSyncAndTestServerResponceL(KUidUsimAppAdnPhonebook, EFalse, _L("USIM ADN"));
       
  1394 	DoSyncAndTestServerResponceL(KUidIccGlobalFdnPhonebook, EFalse, _L("FDN"));
       
  1395 
       
  1396 	iDb->SetDbViewContactType(KUidContactICCEntry);
       
  1397 	sortedItems = iDb->SortedItemsL();
       
  1398 	TESTCHECK(sortedItems->Count(), KTest24ICCSlotsUsed);
       
  1399 
       
  1400 	return TestStepResult();
       
  1401 	}
       
  1402 
       
  1403 
       
  1404 /** 
       
  1405  * Factory construction method.
       
  1406  * @return Pointer to CPhbkSyncGetAndContactFormatTestBase object
       
  1407  */
       
  1408 CPhbkSyncGetAndContactFormatTestBase* CPhbkSyncGetAndContactFormatTestBase::NewL()
       
  1409 	{
       
  1410 	CPhbkSyncGetAndContactFormatTestBase* self = new(ELeave) CPhbkSyncGetAndContactFormatTestBase();
       
  1411 	return self;
       
  1412 	}
       
  1413 
       
  1414 /**
       
  1415  *  Default constructor.  Each test step initialises it's own name.
       
  1416  */
       
  1417 CPhbkSyncGetAndContactFormatTestBase::CPhbkSyncGetAndContactFormatTestBase()
       
  1418 	{
       
  1419 	SetTestStepName(_L("SyncAndGetContactFormatTest"));
       
  1420 	}
       
  1421 
       
  1422 /**
       
  1423  *  Test GetContactFormat and GetNumSlots
       
  1424  */
       
  1425 enum TVerdict CPhbkSyncGetAndContactFormatTestBase::doTestStepL()
       
  1426 	{
       
  1427 	SetSimTsyTestNumberL(0);
       
  1428 
       
  1429 	RPhoneBookSession::TContactFieldsV1 fields;
       
  1430 	RPhoneBookSession::TContactFieldsV1Pckg fieldsPckg(fields);
       
  1431 	TInt  err, numSlots;
       
  1432 	
       
  1433 	err = iSession.GetContactFormat(fieldsPckg);
       
  1434 	TESTCHECK(err, KErrNone);
       
  1435 	err = iSession.GetNumSlots(numSlots);
       
  1436 	TESTCHECK(err, KErrNone);
       
  1437 
       
  1438 	return TestStepResult();
       
  1439 	}
       
  1440 
       
  1441 
       
  1442 /** 
       
  1443  * Factory construction method.
       
  1444  * @return Pointer to CPhbkSyncSetSyncModeAndAutoSyncTest object
       
  1445  */
       
  1446 CPhbkSyncSetSyncModeAndAutoSyncTest* CPhbkSyncSetSyncModeAndAutoSyncTest::NewL()
       
  1447 	{
       
  1448 	CPhbkSyncSetSyncModeAndAutoSyncTest* self = new(ELeave) CPhbkSyncSetSyncModeAndAutoSyncTest();
       
  1449 	return self;
       
  1450 	} // CPhbkSyncSetSyncModeAndAutoSyncTest::NewL
       
  1451 
       
  1452 /**
       
  1453  *  Default constructor.  Each test step initialises it's own name.
       
  1454  */
       
  1455 CPhbkSyncSetSyncModeAndAutoSyncTest::CPhbkSyncSetSyncModeAndAutoSyncTest()
       
  1456 	{
       
  1457 	SetTestStepName(_L("SetSyncModeAndAutoSyncTest"));
       
  1458 	} // CPhbkSyncSetSyncModeAndAutoSyncTest::CPhbkSyncSetSyncModeAndAutoSyncTest
       
  1459 
       
  1460 
       
  1461 /**
       
  1462  *  Test SetSyncMode for an auto-sync.
       
  1463  */
       
  1464 enum TVerdict CPhbkSyncSetSyncModeAndAutoSyncTest::doTestStepL()
       
  1465 	{
       
  1466 	//
       
  1467 	// First make sure sync mode is manual sync...
       
  1468 	//
       
  1469 	SetSyncModeL(RPhoneBookSession::EManual);
       
  1470 	CheckSyncModeL(RPhoneBookSession::EManual);
       
  1471 
       
  1472 	//
       
  1473 	// Now restart with config 0. No syncs will be performed...
       
  1474 	//
       
  1475 	SetSimTsyTestNumberL(0);
       
  1476 
       
  1477 	//
       
  1478 	// Set all phonebooks to Auto-sync...
       
  1479 	//
       
  1480 	SetSyncModeL(RPhoneBookSession::EAutoCurrentIcc);
       
  1481 	CheckSyncModeL(RPhoneBookSession::EAutoCurrentIcc);
       
  1482 
       
  1483 	//
       
  1484 	// Now wait for sync to be complete on all phonebooks...
       
  1485 	//
       
  1486 	WaitForSyncToCompleteL();
       
  1487 
       
  1488 	return TestStepResult();
       
  1489 	} // CPhbkSyncSetSyncModeAndAutoSyncTest::doTestStepL
       
  1490 
       
  1491 
       
  1492 /** 
       
  1493  * Factory construction method.
       
  1494  * @return Pointer to CPhbkSyncSyncUnsupportedPhonebook object
       
  1495  */
       
  1496 CPhbkSyncSyncUnsupportedPhonebook* CPhbkSyncSyncUnsupportedPhonebook::NewL()
       
  1497 	{
       
  1498 	CPhbkSyncSyncUnsupportedPhonebook* self = new(ELeave) CPhbkSyncSyncUnsupportedPhonebook();
       
  1499 	return self;
       
  1500 	} // CPhbkSyncSyncUnsupportedPhonebook::NewL
       
  1501 
       
  1502 
       
  1503 /**
       
  1504  *  Default constructor.  Each test step initialises it's own name.
       
  1505  */
       
  1506 CPhbkSyncSyncUnsupportedPhonebook::CPhbkSyncSyncUnsupportedPhonebook()
       
  1507 	{
       
  1508 	SetTestStepName(_L("SyncUnsupportedPhonebook"));
       
  1509 	} // CPhbkSyncSyncUnsupportedPhonebook::CPhbkSyncSyncUnsupportedPhonebook
       
  1510 
       
  1511 
       
  1512 /**
       
  1513  *  Test sync'ing when a phonebook is not supported.
       
  1514  */
       
  1515 enum TVerdict CPhbkSyncSyncUnsupportedPhonebook::doTestStepL()
       
  1516 	{
       
  1517 	//
       
  1518 	// Manual sync with a SIM which has a few entries on each phonebook...
       
  1519 	//
       
  1520 	SetSyncModeL(RPhoneBookSession::EManual);
       
  1521 	CheckSyncModeL(RPhoneBookSession::EManual);
       
  1522 	SetSimTsyTestNumberL(25);
       
  1523 	DoSyncL();
       
  1524 
       
  1525 	iDb->SetDbViewContactType(KUidContactICCEntry);
       
  1526 	const CContactIdArray* sortedItems = iDb->SortedItemsL();
       
  1527 	TESTCHECK(sortedItems->Count(), KTest25ICCSlotsUsed);
       
  1528 
       
  1529 	//
       
  1530 	// Now change to a SIM with just ADN. Total entries should be just the
       
  1531 	// number in the ADN phonebook (e.g. all the other phonebooks would have
       
  1532 	// cleared).
       
  1533 	//
       
  1534 	TRequestStatus status; 
       
  1535 	RPhoneBookSession::TSyncState state;
       
  1536 
       
  1537 	SetSimTsyTestNumberL(26);
       
  1538 	
       
  1539 	TInt  ret = iSession.GetPhoneBookCacheState(state);
       
  1540 	TESTCHECK(ret, KErrNone);
       
  1541 	iSession.DoSynchronisation(status);
       
  1542 	User::WaitForRequest(status);
       
  1543 	TESTCHECK(status.Int(), KErrNone);
       
  1544 
       
  1545 	ret = iSession.GetPhoneBookCacheState(state, KUidIccGlobalSdnPhonebook);
       
  1546 	TESTCHECK(ret, KErrNotFound);
       
  1547 	iSession.DoSynchronisation(status, KUidIccGlobalSdnPhonebook);
       
  1548 	User::WaitForRequest(status);
       
  1549 	TESTCHECK(status.Int(), KErrNotFound);
       
  1550 
       
  1551 	ret = iSession.GetPhoneBookCacheState(state, KUidIccGlobalLndPhonebook);
       
  1552 	TESTCHECK(ret, KErrNotFound);
       
  1553 	iSession.DoSynchronisation(status, KUidIccGlobalLndPhonebook);
       
  1554 	User::WaitForRequest(status);
       
  1555 	TESTCHECK(status.Int(), KErrNotFound);
       
  1556 
       
  1557 	ret = iSession.GetPhoneBookCacheState(state, KUidUsimAppAdnPhonebook);
       
  1558 	TESTCHECK(ret, KErrNotFound);
       
  1559 	iSession.DoSynchronisation(status, KUidUsimAppAdnPhonebook);
       
  1560 	User::WaitForRequest(status);
       
  1561 	TESTCHECK(status.Int(), KErrNotFound);
       
  1562 
       
  1563 	ret = iSession.GetPhoneBookCacheState(state, KUidIccGlobalFdnPhonebook);
       
  1564 	TESTCHECK(ret, KErrNotFound);
       
  1565 	iSession.DoSynchronisation(status, KUidIccGlobalFdnPhonebook);
       
  1566 	User::WaitForRequest(status);
       
  1567 	TESTCHECK(status.Int(), KErrNotFound);
       
  1568 	
       
  1569 	iDb->SetDbViewContactType(KUidContactICCEntry);
       
  1570 	sortedItems = iDb->SortedItemsL();
       
  1571 	TESTCHECK(sortedItems->Count(), KTest26ICCSlotsUsed);
       
  1572 
       
  1573 	//
       
  1574 	// Repeat the test with auto-sync on a SIM which has a few entries on
       
  1575 	// each phonebook. Need to swap to this SIM twice - once to set the auto-sync
       
  1576 	// mode and once to test it.
       
  1577 	//
       
  1578 	SetSyncModeL(RPhoneBookSession::EManual);
       
  1579 	CheckSyncModeL(RPhoneBookSession::EManual);
       
  1580 	SetSimTsyTestNumberL(25);
       
  1581 	SetSyncModeL(RPhoneBookSession::EAutoCurrentIcc);
       
  1582 	CheckSyncModeL(RPhoneBookSession::EAutoCurrentIcc);
       
  1583 	SetSimTsyTestNumberL(25);
       
  1584 	WaitForSyncToCompleteL();
       
  1585 
       
  1586 	iDb->SetDbViewContactType(KUidContactICCEntry);
       
  1587 	sortedItems = iDb->SortedItemsL();
       
  1588 	TESTCHECK(sortedItems->Count(), KTest25ICCSlotsUsed);
       
  1589 
       
  1590 	//
       
  1591 	// Now change to a SIM with just ADN. Total entries should be just the
       
  1592 	// number in the ADN phonebook (e.g. all the other phonebooks would have
       
  1593 	// cleared).
       
  1594 	//
       
  1595 	SetSimTsyTestNumberL(26);
       
  1596 	User::After(30*1000000); // Wait for silent sync of unknown phonebooks
       
  1597 	
       
  1598 	iDb->SetDbViewContactType(KUidContactICCEntry);
       
  1599 	sortedItems = iDb->SortedItemsL();
       
  1600 	TESTCHECK(sortedItems->Count(), KTest26ICCSlotsUsed);
       
  1601 
       
  1602 	return TestStepResult();
       
  1603 	} // CPhbkSyncSyncUnsupportedPhonebook::doTestStepL
       
  1604 
       
  1605 
       
  1606 /**
       
  1607  *  Perform repeated syncs of phonebooks which have number categories assigned.
       
  1608  *  A previous defect found that the UID list overflowed when frequently updated.
       
  1609  */ 
       
  1610 enum TVerdict CPhbkSyncSyncDiffNumberTypesRepeatedly::doTestStepL()
       
  1611 	{
       
  1612 	SetSyncModeL(RPhoneBookSession::EManual);
       
  1613 	SetSimTsyTestNumberL(23); 
       
  1614 
       
  1615 	for (TInt count = 0;  count < 10;  count++)
       
  1616 		{
       
  1617 		SetSimTsyTestNumberL(22); 
       
  1618 		DoSyncL();
       
  1619 		SetSimTsyTestNumberL(23); 
       
  1620 		DoSyncL();
       
  1621 		}
       
  1622 
       
  1623 	return TestStepResult();
       
  1624 	} // CPhbkSyncSyncDiffNumberTypesRepeatedly::doTestStepL
       
  1625 
       
  1626 
       
  1627 /**
       
  1628  *  Perform a sync of contacts with the plus symbol used in the international numbers.
       
  1629  */ 
       
  1630 enum TVerdict CPhbkSyncSyncInternationalNumbers::doTestStepL()
       
  1631 	{
       
  1632 	//
       
  1633 	// Setup the SIMTSY and sync all phonebooks...
       
  1634 	//
       
  1635 	SetSyncModeL(RPhoneBookSession::EManual);
       
  1636 	SetSimTsyTestNumberL(29); 
       
  1637 	DoSyncL();
       
  1638 
       
  1639 	//
       
  1640 	// Read all the numbers and ensure they start with a '+'...
       
  1641 	//
       
  1642 	iDb->SetDbViewContactType(KUidContactICCEntry);
       
  1643 	const CContactIdArray* sortedItems = iDb->SortedItemsL();
       
  1644 	TInt  count(sortedItems->Count());
       
  1645 	TESTCHECK(count, KTest29ICCSlotsUsed);
       
  1646 
       
  1647 	for (TInt index = 0;  index < count;  index++)
       
  1648 		{ 
       
  1649 		CContactICCEntry*  entry = static_cast<CContactICCEntry*>(iDb->ReadContactL((*sortedItems)[index])); 
       
  1650 
       
  1651 		TESTCHECKCONDITIONL(entry != NULL);
       
  1652 		CleanupStack::PushL(entry);
       
  1653 
       
  1654 		CContactItemFieldSet&  fieldSet = entry->CardFields();
       
  1655 		TInt  pos;
       
  1656 		
       
  1657 		pos = fieldSet.Find(KUidContactFieldVCardMapVOICE);
       
  1658 		TESTCHECKCONDITION(pos >= 0);
       
  1659 
       
  1660 		while (pos != KErrNotFound)
       
  1661 			{
       
  1662 			CContactTextField*  text = fieldSet[pos].TextStorage();
       
  1663 
       
  1664 			TESTCHECK(text->Text()[0], '+');
       
  1665 
       
  1666 			pos = fieldSet.FindNext(KUidContactFieldVCardMapVOICE, pos + 1);
       
  1667 			}
       
  1668 
       
  1669 		CleanupStack::PopAndDestroy(entry);
       
  1670 		}
       
  1671 
       
  1672 	return TestStepResult();
       
  1673 	} // CPhbkSyncSyncInternationalNumbers::doTestStepL
       
  1674 
       
  1675 
       
  1676 /**
       
  1677  *  Perform a sync of contacts with the plus symbol used in the international numbers.
       
  1678  */ 
       
  1679 enum TVerdict CPhbkSyncSyncAutomaticWithUnsupportedPhonebook::doTestStepL()
       
  1680 	{
       
  1681 	//
       
  1682 	// Set all settings to manual and setup the SIM to have only FDN...
       
  1683 	//
       
  1684 	SetSyncModeL(RPhoneBookSession::EManual);
       
  1685 	CheckSyncModeL(RPhoneBookSession::EManual);
       
  1686 
       
  1687 	SetSimTsyTestNumberL(31);
       
  1688 
       
  1689 	//
       
  1690 	// Setup notifications for all the phonebooks...
       
  1691 	//
       
  1692 	TRequestStatus  status1, status2, status3, status4, status5;
       
  1693 
       
  1694 	iSession.NotifyPhBkCacheStateChange(status1, KUidIccGlobalAdnPhonebook);
       
  1695 	iSession.NotifyPhBkCacheStateChange(status2, KUidIccGlobalSdnPhonebook);
       
  1696 	iSession.NotifyPhBkCacheStateChange(status3, KUidIccGlobalLndPhonebook);
       
  1697 	iSession.NotifyPhBkCacheStateChange(status4, KUidUsimAppAdnPhonebook);
       
  1698 	iSession.NotifyPhBkCacheStateChange(status5, KUidIccGlobalFdnPhonebook);
       
  1699 
       
  1700 	//
       
  1701 	// Set all the phonebooks to auto-sync...
       
  1702 	//
       
  1703 	SetSyncModeL(RPhoneBookSession::EAutoCurrentIcc);
       
  1704 	CheckSyncModeL(RPhoneBookSession::EAutoCurrentIcc);
       
  1705 
       
  1706 	//
       
  1707 	// Wait for the notifications to trigger...
       
  1708 	//
       
  1709 	User::WaitForRequest(status1);
       
  1710 	User::WaitForRequest(status2);
       
  1711 	User::WaitForRequest(status3);
       
  1712 	User::WaitForRequest(status4);
       
  1713 	User::WaitForRequest(status5);
       
  1714 
       
  1715 	TESTCHECK(status1.Int(), KErrNone);
       
  1716 	TESTCHECK(status2.Int(), KErrNone);
       
  1717 	TESTCHECK(status3.Int(), KErrNone);
       
  1718 	TESTCHECK(status4.Int(), KErrNone);
       
  1719 	TESTCHECK(status5.Int(), KErrNone);
       
  1720 
       
  1721 	//
       
  1722 	// Now check the final sync state and the Last Sync Error...
       
  1723 	// 
       
  1724 	RPhoneBookSession::TSyncState  state;
       
  1725 	TInt syncError;
       
  1726 
       
  1727 	User::LeaveIfError(iSession.GetPhoneBookCacheState(state, KUidIccGlobalFdnPhonebook));
       
  1728 	TESTCHECK(state, RPhoneBookSession::ECacheValid);
       
  1729 	User::LeaveIfError(iSession.GetLastSyncError(syncError, KUidIccGlobalFdnPhonebook));
       
  1730 	TESTCHECK(syncError, KErrNone);
       
  1731 
       
  1732 	return TestStepResult();
       
  1733 	} // CPhbkSyncSyncAutomaticWithUnsupportedPhonebook::doTestStepL
       
  1734 
       
  1735