pimprotocols/phonebooksync/Test/TE_cntsync/te_cntsyncfind.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_cntsyncfind.h"
       
    20 
       
    21 _LIT(KFindName,"001");
       
    22 _LIT(KFindNameInAdnOnly,"AAAA");
       
    23 _LIT(KFindNameInSdnOnly,"BBBB");
       
    24 _LIT(KFindNameInLndOnly,"CCCC");
       
    25 _LIT(KFindNameInUsimOnly,"DDDD");
       
    26 _LIT(KFindNameInFdnOnly,"EEEE");
       
    27 _LIT(KFindSecondNameInUsimOnly,"Andy D");
       
    28 _LIT(KFindNameAsync,"003");
       
    29 _LIT(KFindNumber,"00004");
       
    30 _LIT(KFindNumberInAdnOnly,"1000000");
       
    31 _LIT(KFindNumberInSdnOnly,"2000000");
       
    32 _LIT(KFindNumberInLndOnly,"3000000");
       
    33 _LIT(KFindNumberInUsimOnly,"4000000");
       
    34 _LIT(KFindNumberInFdnOnly,"5000000");
       
    35 _LIT(KFindAddNumberInUsimOnly,"020812");
       
    36 _LIT(KFindInternationalPrefix,"+");
       
    37 _LIT(KFindInternationalPrefixInADN,"+44");
       
    38 _LIT(KFindInternationalPrefixInSDN,"+55");
       
    39 _LIT(KFindInternationalPrefixInLND,"+66");
       
    40 _LIT(KFindInternationalPrefixInUsim,"+77");
       
    41 _LIT(KFindInternationalPrefixInFDN,"+88");
       
    42 _LIT(KFindNonExistingNumber,"101010101010");
       
    43 
       
    44 
       
    45 /** 
       
    46  * Factory construction method.
       
    47  * @return Pointer to CPhbkFindByNameTest object
       
    48  */
       
    49 CPhbkFindByNameTest* CPhbkFindByNameTest::NewL()
       
    50 	{
       
    51 	CPhbkFindByNameTest* self = new(ELeave) CPhbkFindByNameTest();
       
    52 	return self;
       
    53 	}
       
    54 
       
    55 /**
       
    56  *  Default constructor.  Each test step initialises it's own name.
       
    57  */
       
    58 CPhbkFindByNameTest::CPhbkFindByNameTest()
       
    59 	{
       
    60 	SetTestStepName(_L("FindByNameTest"));
       
    61 	}
       
    62 
       
    63 /** Find an ICC entry by name - normal case */
       
    64 enum TVerdict CPhbkFindByNameTest::doTestStepL()
       
    65 	{
       
    66 	SetSimTsyTestNumberL(1);
       
    67 	DoSyncL();
       
    68 
       
    69 	FindContactsL(KFindName, KUidContactFieldFamilyName, 5);
       
    70 	FindContactsL(KFindNameInAdnOnly, KUidContactFieldFamilyName, 5, KUidIccGlobalAdnPhonebook);
       
    71 	FindContactsL(KFindNameInSdnOnly, KUidContactFieldFamilyName, 5, KUidIccGlobalSdnPhonebook);
       
    72 	FindContactsL(KFindNameInLndOnly, KUidContactFieldFamilyName, 5, KUidIccGlobalLndPhonebook);
       
    73 	FindContactsL(KFindNameInUsimOnly, KUidContactFieldFamilyName, 5, KUidUsimAppAdnPhonebook);
       
    74 	FindContactsL(KFindSecondNameInUsimOnly, KUidContactFieldSecondName, 5, KUidUsimAppAdnPhonebook);
       
    75 	FindContactsL(KFindNameInFdnOnly, KUidContactFieldFamilyName, 5, KUidIccGlobalFdnPhonebook);
       
    76 
       
    77 	return TestStepResult();
       
    78 	}
       
    79 
       
    80 
       
    81 /** 
       
    82  * Factory construction method.
       
    83  * @return Pointer to CPhbkFindByNumberTest object
       
    84  */
       
    85 CPhbkFindByNumberTest* CPhbkFindByNumberTest::NewL()
       
    86 	{
       
    87 	CPhbkFindByNumberTest* self = new(ELeave) CPhbkFindByNumberTest();
       
    88 	return self;
       
    89 	}
       
    90 
       
    91 /**
       
    92  *  Default constructor.  Each test step initialises it's own name.
       
    93  */
       
    94 CPhbkFindByNumberTest::CPhbkFindByNumberTest()
       
    95 	{
       
    96 	SetTestStepName(_L("FindByNumberTest"));
       
    97 	}
       
    98 
       
    99 /** Find an ICC entry by number - normal case */
       
   100 enum TVerdict CPhbkFindByNumberTest::doTestStepL()
       
   101 	{
       
   102 	SetSimTsyTestNumberL(1);
       
   103 	DoSyncL();
       
   104 
       
   105 	FindContactsL(KFindNumber, KUidContactFieldPhoneNumber, 5);
       
   106 	FindContactsL(KFindNumberInAdnOnly, KUidContactFieldPhoneNumber, 1, KUidIccGlobalAdnPhonebook);
       
   107 	FindContactsL(KFindNumberInSdnOnly, KUidContactFieldPhoneNumber, 1, KUidIccGlobalSdnPhonebook);
       
   108 	FindContactsL(KFindNumberInLndOnly, KUidContactFieldPhoneNumber, 1, KUidIccGlobalLndPhonebook);
       
   109 	FindContactsL(KFindNumberInUsimOnly, KUidContactFieldPhoneNumber, 1, KUidUsimAppAdnPhonebook);
       
   110 	FindContactsL(KFindAddNumberInUsimOnly, KUidContactFieldPhoneNumber, 5, KUidUsimAppAdnPhonebook);
       
   111 	FindContactsL(KFindNumberInFdnOnly, KUidContactFieldPhoneNumber, 1, KUidIccGlobalFdnPhonebook);
       
   112 
       
   113 	return TestStepResult();
       
   114 	}
       
   115 
       
   116 
       
   117 /** 
       
   118  * Factory construction method.
       
   119  * @return Pointer to CPhbkFindByNonExistingNameTest object
       
   120  */
       
   121 CPhbkFindByNonExistingNameTest* CPhbkFindByNonExistingNameTest::NewL()
       
   122 	{
       
   123 	CPhbkFindByNonExistingNameTest* self = new(ELeave) CPhbkFindByNonExistingNameTest();
       
   124 	return self;
       
   125 	}
       
   126 
       
   127 /**
       
   128  *  Default constructor.  Each test step initialises it's own name.
       
   129  */
       
   130 CPhbkFindByNonExistingNameTest::CPhbkFindByNonExistingNameTest()
       
   131 	{
       
   132 	SetTestStepName(_L("FindByNonExistingNameTest"));
       
   133 	}
       
   134 
       
   135 /** Find an ICC entry by name - name does not exist */
       
   136 enum TVerdict CPhbkFindByNonExistingNameTest::doTestStepL()
       
   137 	{
       
   138 	CContactItemFieldDef* fieldDef=new(ELeave) CContactItemFieldDef;
       
   139 	CleanupStack::PushL(fieldDef);
       
   140 	fieldDef->AppendL(KUidContactFieldFamilyName); // define subset of fields to search
       
   141 
       
   142 	CContactIdArray* array= iDb->FindLC(KFindNonExistingNumber,fieldDef);
       
   143 	TESTCHECKL(array->Count(), 0); // Nothing found 
       
   144 	CleanupStack::PopAndDestroy(2); // array and fieldDef
       
   145 
       
   146 	return TestStepResult();
       
   147 	}
       
   148 
       
   149 
       
   150 /** 
       
   151  * Factory construction method.
       
   152  * @return Pointer to CPhbkFindByNonExistingNumberTest object
       
   153  */
       
   154 CPhbkFindByNonExistingNumberTest* CPhbkFindByNonExistingNumberTest::NewL()
       
   155 	{
       
   156 	CPhbkFindByNonExistingNumberTest* self = new(ELeave) CPhbkFindByNonExistingNumberTest();
       
   157 	return self;
       
   158 	}
       
   159 
       
   160 /**
       
   161  *  Default constructor.  Each test step initialises it's own name.
       
   162  */
       
   163 CPhbkFindByNonExistingNumberTest::CPhbkFindByNonExistingNumberTest()
       
   164 	{
       
   165 	SetTestStepName(_L("FindByNonExistingNumberTest"));
       
   166 	}
       
   167 
       
   168 /** Find an ICC entry by number - number does not exist */
       
   169 enum TVerdict CPhbkFindByNonExistingNumberTest::doTestStepL()
       
   170 	{
       
   171 	CContactItemFieldDef* fieldDef=new(ELeave) CContactItemFieldDef;
       
   172 	CleanupStack::PushL(fieldDef);
       
   173 	fieldDef->AppendL(KUidContactFieldPhoneNumber); // define subset of fields to search
       
   174 
       
   175 	CContactIdArray* array= iDb->FindLC(KFindNonExistingNumber,fieldDef);
       
   176 	TESTCHECKL(array->Count(), 0); // Nothing found 
       
   177 	CleanupStack::PopAndDestroy(2); // array and fieldDef
       
   178 
       
   179 	return TestStepResult();
       
   180 	}
       
   181 
       
   182 
       
   183 CAsyncFinder::CAsyncFinder()
       
   184 	{
       
   185 	}
       
   186 
       
   187 CAsyncFinder::~CAsyncFinder()
       
   188 	{
       
   189 	delete iFinder;
       
   190 	}
       
   191 
       
   192 /** Asynchronous find observer constructor */
       
   193 void CAsyncFinder::ConstructL(CContactDatabase *aContactDatabase, const TDesC& aText,const CContactItemFieldDef *aFieldDef)
       
   194 	{
       
   195 	iFinder=aContactDatabase->FindAsyncL(aText, aFieldDef, this);
       
   196 	}
       
   197 
       
   198 /** Asynchronous find observer callback */
       
   199 void CAsyncFinder::IdleFindCallback()
       
   200 	{
       
   201 	if (iFinder->IsComplete())
       
   202 		CActiveScheduler::Stop();
       
   203 	}
       
   204 
       
   205 /** 
       
   206  * Factory construction method.
       
   207  * @return Pointer to CPhbkFindByNumberAsyncSearchTest object
       
   208  */
       
   209 CPhbkFindByNumberAsyncSearchTest* CPhbkFindByNumberAsyncSearchTest::NewL()
       
   210 	{
       
   211 	CPhbkFindByNumberAsyncSearchTest* self = new(ELeave) CPhbkFindByNumberAsyncSearchTest();
       
   212 	return self;
       
   213 	}
       
   214 
       
   215 /**
       
   216  *  Default constructor.  Each test step initialises it's own name.
       
   217  */
       
   218 CPhbkFindByNumberAsyncSearchTest::CPhbkFindByNumberAsyncSearchTest()
       
   219 	{
       
   220 	SetTestStepName(_L("FindByNumberAsyncSearchTest"));
       
   221 	}
       
   222 
       
   223 /** Find an ICC entry by number - asynchronous search */
       
   224 enum TVerdict CPhbkFindByNumberAsyncSearchTest::doTestStepL()
       
   225 	{
       
   226 	SetSimTsyTestNumberL(1);
       
   227 	DoSyncL();
       
   228 
       
   229 	FindContactAsyncSearchL(KFindNumber, KUidContactFieldPhoneNumber, 5);
       
   230 	FindContactAsyncSearchL(KFindNumberInAdnOnly, KUidContactFieldPhoneNumber, 1);
       
   231 	FindContactAsyncSearchL(KFindNumberInSdnOnly, KUidContactFieldPhoneNumber, 1);
       
   232 	FindContactAsyncSearchL(KFindNumberInLndOnly, KUidContactFieldPhoneNumber, 1);
       
   233 	FindContactAsyncSearchL(KFindNumberInUsimOnly, KUidContactFieldPhoneNumber, 1);
       
   234 	FindContactAsyncSearchL(KFindAddNumberInUsimOnly, KUidContactFieldPhoneNumber, 5);
       
   235 	FindContactAsyncSearchL(KFindNumberInFdnOnly, KUidContactFieldPhoneNumber, 1);
       
   236 
       
   237 	return TestStepResult();
       
   238 	}
       
   239 
       
   240 
       
   241 /** 
       
   242  * Factory construction method.
       
   243  * @return Pointer to CPhbkFindByNameAsyncSearchTest object
       
   244  */
       
   245 CPhbkFindByNameAsyncSearchTest* CPhbkFindByNameAsyncSearchTest::NewL()
       
   246 	{
       
   247 	CPhbkFindByNameAsyncSearchTest* self = new(ELeave) CPhbkFindByNameAsyncSearchTest();
       
   248 	return self;
       
   249 	}
       
   250 
       
   251 /**
       
   252  *  Default constructor.  Each test step initialises it's own name.
       
   253  */
       
   254 CPhbkFindByNameAsyncSearchTest::CPhbkFindByNameAsyncSearchTest()
       
   255 	{
       
   256 	SetTestStepName(_L("FindByNameAsyncSearchTest"));
       
   257 	}
       
   258 
       
   259 /** Find an ICC entry by name - asynchronous search */
       
   260 enum TVerdict CPhbkFindByNameAsyncSearchTest::doTestStepL()
       
   261 	{
       
   262 	SetSimTsyTestNumberL(1);
       
   263 	DoSyncL();
       
   264 
       
   265 	FindContactAsyncSearchL(KFindNameAsync, KUidContactFieldFamilyName, 5);
       
   266 	FindContactAsyncSearchL(KFindNameInAdnOnly, KUidContactFieldFamilyName, 5);
       
   267 	FindContactAsyncSearchL(KFindNameInSdnOnly, KUidContactFieldFamilyName, 5);
       
   268 	FindContactAsyncSearchL(KFindNameInLndOnly, KUidContactFieldFamilyName, 5);
       
   269 	FindContactAsyncSearchL(KFindNameInUsimOnly, KUidContactFieldFamilyName, 5);
       
   270 	FindContactAsyncSearchL(KFindSecondNameInUsimOnly, KUidContactFieldSecondName, 5);
       
   271 	FindContactAsyncSearchL(KFindNameInFdnOnly, KUidContactFieldFamilyName, 5);
       
   272 
       
   273 	return TestStepResult();
       
   274 	}
       
   275 
       
   276 
       
   277 /** 
       
   278  * Factory construction method.
       
   279  * @return Pointer to CPhbkFindByNonExistNumAsyncSearchTest object
       
   280  */
       
   281 CPhbkFindByNonExistNumAsyncSearchTest* CPhbkFindByNonExistNumAsyncSearchTest::NewL()
       
   282 	{
       
   283 	CPhbkFindByNonExistNumAsyncSearchTest* self = new(ELeave) CPhbkFindByNonExistNumAsyncSearchTest();
       
   284 	return self;
       
   285 	}
       
   286 
       
   287 /**
       
   288  *  Default constructor.  Each test step initialises it's own name.
       
   289  */
       
   290 CPhbkFindByNonExistNumAsyncSearchTest::CPhbkFindByNonExistNumAsyncSearchTest()
       
   291 	{
       
   292 	SetTestStepName(_L("FindByNonExistNumAsyncSearchTest"));
       
   293 	}
       
   294 
       
   295 /** Find an ICC entry by number - asynchronous search for number that does not exist */
       
   296 enum TVerdict CPhbkFindByNonExistNumAsyncSearchTest::doTestStepL()
       
   297 	{
       
   298 	CContactItemFieldDef* fieldDef=new(ELeave) CContactItemFieldDef;
       
   299 	CleanupStack::PushL(fieldDef);
       
   300 	fieldDef->AppendL(KUidContactFieldPhoneNumber); // define subset of fields to search
       
   301 	CAsyncFinder* asyncFinder = new (ELeave) CAsyncFinder();
       
   302 	CleanupStack::PushL(asyncFinder);
       
   303 	asyncFinder->ConstructL(iDb, KFindNonExistingNumber, fieldDef); // create async finder and do async find
       
   304 	
       
   305 	CActiveScheduler::Start();
       
   306 	CContactIdArray* array=asyncFinder->TakeContactIds(); // get array of UIDs
       
   307 	TESTCHECKL(array->Count(), 0); // Nothing found 
       
   308 	delete array;
       
   309 	CleanupStack::PopAndDestroy(2); // fieldDef, asyncFinder
       
   310 
       
   311 	return TestStepResult();
       
   312 	}
       
   313 
       
   314 
       
   315 /** 
       
   316  * Factory construction method.
       
   317  * @return Pointer to CPhbkFindByNameICCLockedTest object
       
   318  */
       
   319 CPhbkFindByNameICCLockedTest* CPhbkFindByNameICCLockedTest::NewL()
       
   320 	{
       
   321 	CPhbkFindByNameICCLockedTest* self = new(ELeave) CPhbkFindByNameICCLockedTest();
       
   322 	return self;
       
   323 	}
       
   324 
       
   325 /**
       
   326  *  Default constructor.  Each test step initialises it's own name.
       
   327  */
       
   328 CPhbkFindByNameICCLockedTest::CPhbkFindByNameICCLockedTest()
       
   329 	{
       
   330 	SetTestStepName(_L("FindByNameICCLockedTest"));
       
   331 	}
       
   332 
       
   333 /** Find an ICC entry by name - ICC locked */
       
   334 enum TVerdict CPhbkFindByNameICCLockedTest::doTestStepL()
       
   335 	{
       
   336 	SetSimTsyTestNumberL(2);
       
   337 	DoSyncL();
       
   338 	SignalSimTsyToReduceTimersL();
       
   339 
       
   340 	TInt err(KErrNone);
       
   341 	TInt err1(KErrNone);
       
   342 	TInt err2(KErrNone);
       
   343 	TInt err3(KErrNone);
       
   344 	TInt err4(KErrNone);
       
   345 	TInt err5(KErrNone);
       
   346 	TInt err6(KErrNone);
       
   347 	do // Wait for ICC to become locked
       
   348 		{
       
   349 		User::After(1000000);
       
   350 		TRAP(err, FindContactsL(KFindName, KUidContactFieldFamilyName, 5));
       
   351 		} while(err==KErrNone);
       
   352 
       
   353 	TRAP(err1, FindContactsL(KFindNameInAdnOnly, KUidContactFieldFamilyName, 1, KUidIccGlobalAdnPhonebook));
       
   354 	TRAP(err2, FindContactsL(KFindNameInSdnOnly, KUidContactFieldFamilyName, 1, KUidIccGlobalSdnPhonebook));
       
   355 	TRAP(err3, FindContactsL(KFindNameInLndOnly, KUidContactFieldFamilyName, 1, KUidIccGlobalLndPhonebook));
       
   356 	TRAP(err4, FindContactsL(KFindNameInUsimOnly, KUidContactFieldFamilyName, 1, KUidUsimAppAdnPhonebook));
       
   357 	TRAP(err5, FindContactsL(KFindSecondNameInUsimOnly, KUidContactFieldSecondName, 5, KUidUsimAppAdnPhonebook));
       
   358 	TRAP(err6, FindContactsL(KFindNameInFdnOnly, KUidContactFieldFamilyName, 1, KUidIccGlobalFdnPhonebook));
       
   359 	TESTCHECKL(err, KErrAccessDenied);
       
   360 	TESTCHECKL(err1, KErrAccessDenied);
       
   361 	TESTCHECKL(err2, KErrAccessDenied);
       
   362 	TESTCHECKL(err3, KErrAccessDenied);
       
   363 	TESTCHECKL(err4, KErrAccessDenied);
       
   364 	TESTCHECKL(err5, KErrAccessDenied);
       
   365 	TESTCHECKL(err6, KErrAccessDenied);
       
   366 
       
   367 	return TestStepResult();
       
   368 	}
       
   369 
       
   370 
       
   371 /** 
       
   372  * Factory construction method.
       
   373  * @return Pointer to CPhbkFindByNumberICCLockedTest object
       
   374  */
       
   375 CPhbkFindByNumberICCLockedTest* CPhbkFindByNumberICCLockedTest::NewL()
       
   376 	{
       
   377 	CPhbkFindByNumberICCLockedTest* self = new(ELeave) CPhbkFindByNumberICCLockedTest();
       
   378 	return self;
       
   379 	}
       
   380 
       
   381 /**
       
   382  *  Default constructor.  Each test step initialises it's own name.
       
   383  */
       
   384 CPhbkFindByNumberICCLockedTest::CPhbkFindByNumberICCLockedTest()
       
   385 	{
       
   386 	SetTestStepName(_L("FindByNumberICCLockedTest"));
       
   387 	}
       
   388 
       
   389 /** Find an ICC entry by number - ICC locked */
       
   390 enum TVerdict CPhbkFindByNumberICCLockedTest::doTestStepL()
       
   391 	{
       
   392 	SetSimTsyTestNumberL(2);
       
   393 	DoSyncL();
       
   394 	SignalSimTsyToReduceTimersL();
       
   395 
       
   396 	TInt err(KErrNone);
       
   397 	TInt err1(KErrNone);
       
   398 	TInt err2(KErrNone);
       
   399 	TInt err3(KErrNone);
       
   400 	TInt err4(KErrNone);
       
   401 	TInt err5(KErrNone);
       
   402 	TInt err6(KErrNone);
       
   403 	do // Wait for ICC to become locked
       
   404 		{
       
   405 		User::After(1000000);
       
   406 		TRAP(err, FindContactsL(KFindNumber, KUidContactFieldPhoneNumber, 5));
       
   407 		} while(err==KErrNone);
       
   408 
       
   409 	TRAP(err1, FindContactsL(KFindNumberInAdnOnly, KUidContactFieldPhoneNumber, 1, KUidIccGlobalAdnPhonebook));
       
   410 	TRAP(err2, FindContactsL(KFindNumberInSdnOnly, KUidContactFieldPhoneNumber, 1, KUidIccGlobalSdnPhonebook));
       
   411 	TRAP(err3, FindContactsL(KFindNumberInLndOnly, KUidContactFieldPhoneNumber, 1, KUidIccGlobalLndPhonebook));
       
   412 	TRAP(err4, FindContactsL(KFindNumberInUsimOnly, KUidContactFieldPhoneNumber, 1, KUidUsimAppAdnPhonebook));
       
   413 	TRAP(err5, FindContactsL(KFindAddNumberInUsimOnly, KUidContactFieldPhoneNumber, 1, KUidUsimAppAdnPhonebook));
       
   414 	TRAP(err6, FindContactsL(KFindNumberInFdnOnly, KUidContactFieldPhoneNumber, 1, KUidIccGlobalFdnPhonebook));
       
   415 	TESTCHECKL(err, KErrAccessDenied);
       
   416 	TESTCHECKL(err1, KErrAccessDenied);
       
   417 	TESTCHECKL(err2, KErrAccessDenied);
       
   418 	TESTCHECKL(err3, KErrAccessDenied);
       
   419 	TESTCHECKL(err4, KErrAccessDenied);
       
   420 	TESTCHECKL(err5, KErrAccessDenied);
       
   421 	TESTCHECKL(err6, KErrAccessDenied);
       
   422 
       
   423 	return TestStepResult();
       
   424 	}
       
   425 
       
   426 
       
   427 /** 
       
   428  * Factory construction method.
       
   429  * @return Pointer to CPhbkFindByNumICCLockedAsyncSearchTest object
       
   430  */
       
   431 CPhbkFindByNumICCLockedAsyncSearchTest* CPhbkFindByNumICCLockedAsyncSearchTest::NewL()
       
   432 	{
       
   433 	CPhbkFindByNumICCLockedAsyncSearchTest* self = new(ELeave) CPhbkFindByNumICCLockedAsyncSearchTest();
       
   434 	return self;
       
   435 	}
       
   436 
       
   437 /**
       
   438  *  Default constructor.  Each test step initialises it's own name.
       
   439  */
       
   440 CPhbkFindByNumICCLockedAsyncSearchTest::CPhbkFindByNumICCLockedAsyncSearchTest()
       
   441 	{
       
   442 	SetTestStepName(_L("FindByNumICCLockedAsyncSearchTest"));
       
   443 	}
       
   444 
       
   445 /** Find an ICC entry by number - asynchronous search when ICC is locked */
       
   446 enum TVerdict CPhbkFindByNumICCLockedAsyncSearchTest::doTestStepL()
       
   447 	{
       
   448 	SetSimTsyTestNumberL(2);
       
   449 	DoSyncL();
       
   450 
       
   451 	SignalSimTsyToReduceTimersL();
       
   452 	TInt err(KErrNone);
       
   453 	do // Wait for ICC to become locked
       
   454 		{
       
   455 		User::After(1000000);
       
   456 		TRAP(err, FindContactsL(KFindNumber, KUidContactFieldPhoneNumber, 5));
       
   457 		} while(err==KErrNone);
       
   458 
       
   459 	TESTCHECKL(err, KErrAccessDenied);
       
   460 
       
   461 	CContactItemFieldDef* fieldDef = new(ELeave) CContactItemFieldDef;
       
   462 	CleanupStack::PushL(fieldDef);
       
   463 	fieldDef->AppendL(KUidContactFieldPhoneNumber); // define subset of fields to search
       
   464 
       
   465 	CAsyncFinder* asyncFinder = new (ELeave) CAsyncFinder();
       
   466 	CleanupStack::PushL(asyncFinder);
       
   467 	err = KErrNone;
       
   468 	TRAP(err, asyncFinder->ConstructL(iDb, KFindNumber, fieldDef)); // create async finder and do async find
       
   469 	TESTCHECKL(err, KErrNone);
       
   470 
       
   471 	CActiveScheduler::Start();
       
   472 	CContactIdArray* array = asyncFinder->TakeContactIds(); // get array of UIDs
       
   473 	TESTCHECKL(array->Count(), 0); // Nothing found
       
   474 	delete array;
       
   475 	CleanupStack::PopAndDestroy(2); // fieldDef, asyncFinder
       
   476 
       
   477 	return TestStepResult();
       
   478 	}
       
   479 
       
   480 
       
   481 /** 
       
   482  * Factory construction method.
       
   483  * @return Pointer to CPhbkFindByInternationalPrefixTest object
       
   484  */
       
   485 CPhbkFindByInternationalPrefixTest* CPhbkFindByInternationalPrefixTest::NewL()
       
   486 	{
       
   487 	CPhbkFindByInternationalPrefixTest* self = new(ELeave) CPhbkFindByInternationalPrefixTest();
       
   488 	return self;
       
   489 	}
       
   490 
       
   491 /**
       
   492  *  Default constructor.  Each test step initialises it's own name.
       
   493  */
       
   494 CPhbkFindByInternationalPrefixTest::CPhbkFindByInternationalPrefixTest()
       
   495 	{
       
   496 	SetTestStepName(_L("FindByInternationalPrefixTest"));
       
   497 	}
       
   498 
       
   499 /** Find an ICC entry by number - international format */
       
   500 enum TVerdict CPhbkFindByInternationalPrefixTest::doTestStepL()
       
   501 	{
       
   502 	SetSimTsyTestNumberL(12);
       
   503 	DoSyncL();
       
   504 
       
   505 	FindContactsL(KFindInternationalPrefix, KUidContactFieldPhoneNumber, 5);
       
   506 	FindContactsL(KFindInternationalPrefixInADN, KUidContactFieldPhoneNumber, 1, KUidIccGlobalAdnPhonebook);
       
   507 	FindContactsL(KFindInternationalPrefixInSDN, KUidContactFieldPhoneNumber, 1, KUidIccGlobalSdnPhonebook);
       
   508 	FindContactsL(KFindInternationalPrefixInLND, KUidContactFieldPhoneNumber, 1, KUidIccGlobalLndPhonebook);
       
   509 	FindContactsL(KFindInternationalPrefixInUsim, KUidContactFieldPhoneNumber, 1, KUidUsimAppAdnPhonebook);
       
   510 	FindContactsL(KFindInternationalPrefixInFDN, KUidContactFieldPhoneNumber, 1, KUidIccGlobalFdnPhonebook);
       
   511 
       
   512 	return TestStepResult();
       
   513 	}
       
   514 
       
   515 
       
   516 /** 
       
   517  * Factory construction method.
       
   518  * @return Pointer to CPhbkFindByInterPrefixAsyncSearchTest object
       
   519  */
       
   520 CPhbkFindByInterPrefixAsyncSearchTest* CPhbkFindByInterPrefixAsyncSearchTest::NewL()
       
   521 	{
       
   522 	CPhbkFindByInterPrefixAsyncSearchTest* self = new(ELeave) CPhbkFindByInterPrefixAsyncSearchTest();
       
   523 	return self;
       
   524 	}
       
   525 
       
   526 /**
       
   527  *  Default constructor.  Each test step initialises it's own name.
       
   528  */
       
   529 CPhbkFindByInterPrefixAsyncSearchTest::CPhbkFindByInterPrefixAsyncSearchTest()
       
   530 	{
       
   531 	SetTestStepName(_L("FindByInterPrefixAsyncSearchTest"));
       
   532 	}
       
   533 
       
   534 /** Find an ICC entry by number - asynchronous search of international format */
       
   535 enum TVerdict CPhbkFindByInterPrefixAsyncSearchTest::doTestStepL()
       
   536 	{
       
   537 	SetSimTsyTestNumberL(12);
       
   538 	DoSyncL();
       
   539 
       
   540 	FindContactAsyncSearchL(KFindInternationalPrefix, KUidContactFieldPhoneNumber, 5);
       
   541 	FindContactAsyncSearchL(KFindInternationalPrefixInADN, KUidContactFieldPhoneNumber, 1);
       
   542 	FindContactAsyncSearchL(KFindInternationalPrefixInSDN, KUidContactFieldPhoneNumber, 1);
       
   543 	FindContactAsyncSearchL(KFindInternationalPrefixInLND, KUidContactFieldPhoneNumber, 1);
       
   544 	FindContactAsyncSearchL(KFindInternationalPrefixInUsim, KUidContactFieldPhoneNumber, 1);
       
   545 	FindContactAsyncSearchL(KFindInternationalPrefixInFDN, KUidContactFieldPhoneNumber, 1);
       
   546 
       
   547 	return TestStepResult();
       
   548 	}
       
   549 
       
   550 
       
   551 /** 
       
   552  * Find contact IDs that match aFindString in the field specified by aFieldToSearch.
       
   553  * @param aFindString Text to search for
       
   554  * @param aFieldToSearch Field to search
       
   555  * @param aExpectedMatches Expected number of matching contacts
       
   556  * @param aExpectedPhonebook Phonebook that the entries are expected to be in
       
   557  */
       
   558 void CPhbkFindIntegrationTestBase::FindContactsL(const TDesC& aFindString, TFieldType aFieldToSearch, TInt aExpectedMatches, const TUid aExpectedPhonebook)
       
   559 	{
       
   560 	iDb->SetDbViewContactType(KUidContactICCEntry);
       
   561 	CContactItemFieldDef* fieldDef=new(ELeave) CContactItemFieldDef;
       
   562 	CleanupStack::PushL(fieldDef);
       
   563 	fieldDef->AppendL(aFieldToSearch);
       
   564 	CContactIdArray* array = iDb->FindLC(aFindString,fieldDef);
       
   565 
       
   566 	TInt count = array->Count();
       
   567 	TESTCHECKL(count, aExpectedMatches);
       
   568 
       
   569 	if (aExpectedPhonebook != KUidIccPhonebookNotSpecified)
       
   570 		{
       
   571 		// check that all matched entries belong to the phonebook aPhonebook by checking the
       
   572 		// value of the phonebook field
       
   573 		for (TInt i=0; i<count; ++i)
       
   574 			{
       
   575 			CContactICCEntry* entry = static_cast<CContactICCEntry*>(iDb->ReadContactLC((*array)[i]));
       
   576 			const CContactItemFieldSet& fieldset = entry->CardFields();
       
   577 			const TInt n = fieldset.Find(KUidContactFieldICCPhonebook);
       
   578 			if(n!=KErrNotFound)
       
   579 				{
       
   580 				TPtrC phonebookField = fieldset[n].TextStorage()->Text();
       
   581 				TLex lex(phonebookField);
       
   582 				TUid phonebookUid;
       
   583 				/*TInt ignore  = */ lex.Val(phonebookUid.iUid);
       
   584 				TESTCHECKL(phonebookUid, aExpectedPhonebook);
       
   585 				}
       
   586 			CleanupStack::PopAndDestroy(entry);
       
   587 			}
       
   588 		}
       
   589 
       
   590 	CleanupStack::PopAndDestroy(2); // array & fieldDef
       
   591 	}
       
   592 
       
   593 
       
   594 /** Asynchronous search for field content */
       
   595 void CPhbkFindIntegrationTestBase::FindContactAsyncSearchL(const TDesC& aContent, TFieldType aFieldToSearch, TInt aExpectedMatches)
       
   596 	{
       
   597 	CContactItemFieldDef* fieldDef=new(ELeave) CContactItemFieldDef;
       
   598 	CleanupStack::PushL(fieldDef);
       
   599 	fieldDef->AppendL(aFieldToSearch); // define subset of fields to search
       
   600 	
       
   601 	CAsyncFinder* asyncFinder = new (ELeave) CAsyncFinder();
       
   602 	CleanupStack::PushL(asyncFinder);
       
   603 	asyncFinder->ConstructL(iDb, aContent, fieldDef); // create async finder and do async find
       
   604 	
       
   605 	CActiveScheduler::Start();
       
   606 	CContactIdArray* array=asyncFinder->TakeContactIds(); // get array of UIDs
       
   607 	CleanupStack::PushL(array);
       
   608 	TESTCHECK(array->Count(), aExpectedMatches); // compare number of UIDs
       
   609 	CleanupStack::PopAndDestroy(array);
       
   610 	CleanupStack::PopAndDestroy(asyncFinder);
       
   611 	CleanupStack::PopAndDestroy(fieldDef);
       
   612 	}
       
   613