phonebookengines_old/contactsmodel/tsrc/t_viewsoom.cpp
changeset 40 b46a585f6909
equal deleted inserted replaced
37:fd64c38c277d 40:b46a585f6909
       
     1 // Copyright (c) 2000-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 <e32std.h>
       
    17 #include <e32test.h>
       
    18 #include <collate.h>
       
    19 #include <cntdb.h>
       
    20 #include <cntitem.h>
       
    21 #include <cntfldst.h>
       
    22 #include "t_utils2.h"
       
    23 #include "T_UTILS.H"
       
    24 #include "t_viewsoom.h"
       
    25 #include <badesca.h>
       
    26 #include "CContactDbEventQueue.h"
       
    27 
       
    28 _LIT(KTestName,"T_ViewsOOM");
       
    29 LOCAL_D RFs TheFs;
       
    30 //
       
    31 // Constants.
       
    32 //
       
    33 
       
    34 _LIT8(KSortPlugin, "application.vnd.symbian.com/contacts-reverse-sort"); //SimpleSortPlugin DLL Unique name
       
    35 
       
    36 _LIT(KLogFileName,"t_viewsoom.log");
       
    37 
       
    38 _LIT(KDbFileName,"c:t_view2.cdb");
       
    39 
       
    40 _LIT(KTextDefSeparator,"");
       
    41 _LIT8(KUnicodeLineEnd,"\x0D\x00\x0a\x00");
       
    42 
       
    43 _LIT(KContactsFile, "z:\\t_view2\\t_view2_initial_contacts_small.txt");
       
    44 
       
    45 const TInt KMaxNumRequests(1000);
       
    46 
       
    47 //
       
    48 // CTestConductor.
       
    49 //
       
    50 
       
    51 CTestConductor* CTestConductor::NewL()
       
    52 	{
       
    53 	CTestConductor* self=new(ELeave) CTestConductor();
       
    54 	CleanupStack::PushL(self);
       
    55 	self->ConstructL();
       
    56 	CleanupStack::Pop();
       
    57 	return self;
       
    58 	}
       
    59 
       
    60 CTestConductor::~CTestConductor()
       
    61 	{
       
    62 	delete iGroupOne;
       
    63 	iLocalView->Close(*this);
       
    64 	iRemoteView_1->Close(*this);
       
    65 	iSortOrder_1.Close();
       
    66 	iSortOrder_2.Close();
       
    67 
       
    68 	delete iSortChecker;
       
    69 	delete iViewCreator;
       
    70 	delete iContactAdder;
       
    71 	delete iContactRemover;
       
    72 	delete iViewExerciser;
       
    73 	delete iSortOrderChanger;
       
    74 	delete iLog;
       
    75     delete iDb;
       
    76 	iTest.Close();
       
    77     TRAP_IGNORE(CContactDatabase::DeleteDatabaseL(KDbFileName));
       
    78 	iFs.Close();
       
    79 	}
       
    80 
       
    81 CTestConductor::CTestConductor() : CActive(EPriorityIdle),iTest(KTestName),iCurrentTestNumber(-1)
       
    82 	{
       
    83 	CActiveScheduler::Add(this);
       
    84 	}
       
    85 
       
    86 /**
       
    87 
       
    88 @SYMTestCaseID     PIM-T-VIEWSOOM-0001
       
    89 
       
    90 */
       
    91 
       
    92 void CTestConductor::ConstructL()
       
    93 	{
       
    94 	iGroupId=-1;
       
    95 	iGnoreNotifications=EFalse;
       
    96 	iSortOrder_1.AppendL(KUidContactFieldGivenName);
       
    97 	iSortOrder_1.AppendL(KUidContactFieldFamilyName);
       
    98 	iSortOrder_1.AppendL(KUidContactFieldCompanyName);
       
    99 
       
   100 	iSortOrder_2.AppendL(KUidContactFieldFamilyName);
       
   101 	iSortOrder_2.AppendL(KUidContactFieldGivenName);
       
   102 	iSortOrder_2.AppendL(KUidContactFieldCompanyName);
       
   103 
       
   104 	User::LeaveIfError(iFs.Connect());
       
   105 	iLog=CLog::NewL(iTest,KLogFileName);
       
   106 	iDb=CContactDatabase::ReplaceL(KDbFileName);
       
   107 
       
   108 	iSortChecker=CSortChecker::NewL(*this);
       
   109 	iViewCreator=CViewCreator::NewL(*this);
       
   110 	iContactAdder=CContactAdder::NewL(*this);
       
   111 	iContactRemover=CContactRemover::NewL(*this);
       
   112 	iViewExerciser=CViewExerciser::NewL(*this);
       
   113 	iSortOrderChanger=CSortOrderChanger::NewL(*this);
       
   114 
       
   115 	iTestError = KErrNone;
       
   116 
       
   117 	NextTest();
       
   118 	iTest.Start(_L("@SYMTESTCaseID:PIM-T-VIEWSOOM-0001 --- Contact Views OOM tests---"));
       
   119 
       
   120 	CActiveScheduler::Start();
       
   121 
       
   122 	User::LeaveIfError(iTestError);
       
   123 	iTest.End();
       
   124 	}
       
   125 
       
   126 void CTestConductor::NextTest()
       
   127 	{
       
   128 	++iCurrentTestNumber;
       
   129 	TRequestStatus *pS=&iStatus;
       
   130 	User::RequestComplete(pS,KErrNone);
       
   131 	SetActive();
       
   132 	}
       
   133 
       
   134 void CTestConductor::RunL()
       
   135 	{
       
   136 	switch (iCurrentTestNumber)
       
   137 		{
       
   138 		case ECreateLocalView:
       
   139 			iLog->LogLine(_L("=== Create local view"));
       
   140 			iCurrentTestObject=iViewCreator;
       
   141 			iLocalView=iViewCreator->CreateLocalViewL(iSortOrder_1);
       
   142 			break;
       
   143 		case EAddInitialContacts:
       
   144 			{
       
   145 			iLog->LogLine(_L("=== Add initial contacts"));
       
   146 			iCurrentTestObject=iContactAdder;
       
   147 //			iContactAdder->AddContactsL(_L("c:\\t_view2\\t_view2_initial_contacts.txt"),1);
       
   148 			iContactAdder->AddContactsL(KContactsFile,1);
       
   149 			}
       
   150 			break;
       
   151 		case EAddGroup:
       
   152 			{
       
   153 			//Create Test Group
       
   154 			iGroupOne = STATIC_CAST(CContactGroup*,iDb->CreateContactGroupL(KGroupOneName));
       
   155 			for (TInt ii=1;ii<=KNumContactsInGroupOne;++ii)
       
   156 				{
       
   157 				iDb->AddContactToGroupL(ii,iGroupOne->Id());
       
   158 				}
       
   159 			iGroupId = iGroupOne->Id();
       
   160 			NextTest();
       
   161 			}
       
   162 			break;
       
   163 		case ECreateRemoteView:
       
   164 			iLog->LogLine(_L("=== Create remote view"));
       
   165 			iCurrentTestObject=iViewCreator;
       
   166 			iRemoteView_1=iViewCreator->CreateRemoteViewL(iSortOrder_1);
       
   167 			break;
       
   168 		case EDoOOMTests:
       
   169 			{
       
   170 			iGnoreNotifications=ETrue;
       
   171 			COomTest *oomTest=new(ELeave) COomTest(iDb,iLocalView,iRemoteView_1,iGroupOne,*this);
       
   172 			CleanupStack::PushL(oomTest);
       
   173 			oomTest->TestsL();
       
   174 			CleanupStack::PopAndDestroy();	// oomTest
       
   175 			NextTest();
       
   176 			}
       
   177 			break;
       
   178 		case ENumTests:
       
   179 			{
       
   180 			RThread thread;
       
   181 			iTest(thread.RequestCount()==0);
       
   182 			CActiveScheduler::Stop();
       
   183 			}
       
   184 			break;
       
   185 		default:
       
   186 			ASSERT(EFalse);
       
   187 			break;
       
   188 		}
       
   189 	}
       
   190 
       
   191 
       
   192 TInt CTestConductor::RunError(TInt aError)
       
   193 	{
       
   194 	// quick code to report the test step and leave error
       
   195 	// allows test to exit neatly with message about where the failure occurred
       
   196 	iTestError = aError;
       
   197 
       
   198 	switch (iCurrentTestNumber)
       
   199 		{
       
   200 		case ECreateLocalView: iTest.Printf(_L("RunL left in step CreateLocalView (%i) with error %i"), iCurrentTestNumber, aError); break;
       
   201 		case EAddInitialContacts: iTest.Printf(_L("RunL left in step AddInitialContacts (%i) with error %i"), iCurrentTestNumber, aError); break;
       
   202 		case EAddGroup: iTest.Printf(_L("RunL left in step AddGroup (%i) with error %i"), iCurrentTestNumber, aError); break;
       
   203 		case ECreateRemoteView: iTest.Printf(_L("RunL left in step CreateRemoteView (%i) with error %i"), iCurrentTestNumber, aError); break;
       
   204 		case EDoOOMTests: iTest.Printf(_L("RunL left in step DoOOMTestL (%i) with error %i"), iCurrentTestNumber, aError); break;
       
   205 
       
   206 		case ENumTests: iTest.Printf(_L("RunL left in step NumTests (%i) with error %i"), iCurrentTestNumber, aError); break;
       
   207 
       
   208 		default: iTest.Printf(_L("RunL left in step %i with error %i"), iCurrentTestNumber, aError); break;
       
   209 		}
       
   210 
       
   211 	// stop test
       
   212 	CActiveScheduler::Stop();
       
   213 	return KErrNone;
       
   214 	}
       
   215 
       
   216 
       
   217 void CTestConductor::HandleContactViewEvent(const CContactViewBase& aView, const TContactViewEvent& aEvent)
       
   218 	{
       
   219 	if(iGnoreNotifications)
       
   220 		{
       
   221 		return;
       
   222 		}
       
   223 
       
   224 	if(aEvent.iContactId ==  iGroupId )
       
   225 		{
       
   226 		return;//ignore
       
   227 		}
       
   228 
       
   229 	TRAPD(err, iCurrentTestObject->HandleNotificationL(aView, aEvent) );
       
   230 	iTest(err == KErrNone);
       
   231 	}
       
   232 
       
   233 void CTestConductor::DoCancel()
       
   234 	{
       
   235 	}
       
   236 
       
   237 
       
   238 //
       
   239 // CSortChecker.
       
   240 //
       
   241 
       
   242 CSortChecker* CSortChecker::NewL(CTestConductor& aConductor)
       
   243 	{
       
   244 	CSortChecker* self=new(ELeave) CSortChecker(aConductor);
       
   245 	CleanupStack::PushL(self);
       
   246 	self->ConstructL();
       
   247 	CleanupStack::Pop(); // self.
       
   248 	return self;
       
   249 	}
       
   250 
       
   251 CSortChecker::CSortChecker(CTestConductor& aConductor) : iConductor(aConductor)
       
   252 	{
       
   253 	}
       
   254 
       
   255 void CSortChecker::ConstructL()
       
   256 	{
       
   257 	iCollateMethod=new(ELeave) TCollationMethod;
       
   258 	*iCollateMethod=*Mem::CollationMethodByIndex(0);
       
   259 	iCollateMethod->iFlags|=TCollationMethod::EIgnoreNone;
       
   260 	}
       
   261 
       
   262 CSortChecker::~CSortChecker()
       
   263 	{
       
   264 	iSortedFirstLast.ResetAndDestroy();
       
   265 	iSortedLastFirst.ResetAndDestroy();
       
   266 	delete iCollateMethod;
       
   267 	}
       
   268 
       
   269 void CSortChecker::AddContactL(const TDesC& aFirstName,const TDesC& aLastName)
       
   270 	{
       
   271 	HBufC* buf=HBufC::NewLC(aFirstName.Length()+aLastName.Length());
       
   272 	TPtr bufPtr(buf->Des());
       
   273 	bufPtr.Append(aFirstName);
       
   274 	bufPtr.Append(aLastName);
       
   275 	User::LeaveIfError(iSortedFirstLast.Append(buf));
       
   276 	CleanupStack::Pop(); // buf.
       
   277 
       
   278 	buf=HBufC::NewLC(aFirstName.Length()+aLastName.Length());
       
   279 	TPtr bufPtr2(buf->Des());
       
   280 	bufPtr2.Append(aLastName);
       
   281 	bufPtr2.Append(aFirstName);
       
   282 	User::LeaveIfError(iSortedLastFirst.Append(buf));
       
   283 	CleanupStack::Pop(); // buf.
       
   284 	}
       
   285 
       
   286 void CSortChecker::RemoveContactL(const TDesC& aFirstName,const TDesC& aLastName)
       
   287 	{
       
   288 	HBufC* buf=HBufC::NewLC(aFirstName.Length()+aLastName.Length());
       
   289 	TPtr bufPtr(buf->Des());
       
   290 	bufPtr.Append(aFirstName);
       
   291 	bufPtr.Append(aLastName);
       
   292 	TInt index=iSortedFirstLast.Find(buf,TIdentityRelation<HBufC>(Match));
       
   293 	ASSERT(index!=KErrNotFound);
       
   294 	delete iSortedFirstLast[index];
       
   295 	iSortedFirstLast.Remove(index);
       
   296 	CleanupStack::PopAndDestroy(); // buf.
       
   297 
       
   298 	buf=HBufC::NewLC(aFirstName.Length()+aLastName.Length());
       
   299 	TPtr bufPtr2(buf->Des());
       
   300 	bufPtr2.Append(aLastName);
       
   301 	bufPtr2.Append(aFirstName);
       
   302 	index=iSortedLastFirst.Find(buf,TIdentityRelation<HBufC>(Match));
       
   303 	ASSERT(index!=KErrNotFound);
       
   304 	delete iSortedLastFirst[index];
       
   305 	iSortedLastFirst.Remove(index);
       
   306 	CleanupStack::PopAndDestroy(); // buf.
       
   307 	}
       
   308 
       
   309 TBool CSortChecker::Match(const HBufC& aFirst,const HBufC& aSecond)
       
   310 	{
       
   311 	if (aFirst.Compare(aSecond)==0)
       
   312 		{
       
   313 		return ETrue;
       
   314 		}
       
   315 	return EFalse;
       
   316 	}
       
   317 
       
   318 TPtrC CSortChecker::ContactAt(TSortOrder aOrder,TInt aIndex) const
       
   319 	{
       
   320 	const RPointerArray<HBufC>& sortedList=(aOrder==ELastNameFirstName) ? iSortedLastFirst : iSortedFirstLast;
       
   321 	return TPtrC(*sortedList[aIndex]);
       
   322 	}
       
   323 
       
   324 TInt CSortChecker::Count() const
       
   325 	{
       
   326 	return iSortedFirstLast.Count();
       
   327 	}
       
   328 
       
   329 TInt CSortChecker::Count(TSortOrder aOrder,const TDesC& aLowBoundary,const TDesC& aHighBoundary) const
       
   330 	{
       
   331 	const TInt low=FindIndex(aOrder,aLowBoundary,CSortChecker::EGreaterThanOrEqualTo);
       
   332 	const TInt high=FindIndex(aOrder,aHighBoundary,CSortChecker::EGreaterThanOrEqualTo);
       
   333 	if (low==KErrNotFound)
       
   334 		{
       
   335 		iConductor.iTest(high==KErrNotFound);
       
   336 		return 0;
       
   337 		}
       
   338 	return high-low;
       
   339 	}
       
   340 
       
   341 TInt CSortChecker::CountLow(TSortOrder aOrder,const TDesC& aHighBoundary) const
       
   342 	{
       
   343 	const TInt high=FindIndex(aOrder,aHighBoundary,CSortChecker::EGreaterThanOrEqualTo);
       
   344 	if (high==KErrNotFound)
       
   345 		{
       
   346 		return 0;
       
   347 		}
       
   348 	return high;
       
   349 	}
       
   350 
       
   351 TInt CSortChecker::CountHigh(TSortOrder aOrder,const TDesC& aLowBoundary) const
       
   352 	{
       
   353 	const TInt low=FindIndex(aOrder,aLowBoundary,CSortChecker::EGreaterThanOrEqualTo);
       
   354 	if (low==KErrNotFound)
       
   355 		{
       
   356 		return 0;
       
   357 		}
       
   358 	return Count()-low;
       
   359 	}
       
   360 
       
   361 void CSortChecker::Sort()
       
   362 	{
       
   363 	iSortedFirstLast.Sort(TLinearOrder<HBufC>(Compare));
       
   364 	iSortedLastFirst.Sort(TLinearOrder<HBufC>(Compare));
       
   365 
       
   366 	const TInt numContacts=iSortedFirstLast.Count();
       
   367 	__ASSERT_ALWAYS(numContacts==iSortedLastFirst.Count(),User::Invariant());
       
   368 	}
       
   369 
       
   370 void CSortChecker::CheckSort(TSortOrder aOrder,const TDesC& aName,TInt aIndex) const
       
   371 	{
       
   372 	const RPointerArray<HBufC>& sortedList=(aOrder==ELastNameFirstName) ? iSortedLastFirst : iSortedFirstLast;
       
   373 	iConductor.iLog->LogLineNoEcho(_L("Checking - %S against %S"),&aName,sortedList[aIndex]);
       
   374 	iConductor.iTest(sortedList[aIndex]->Compare(aName)==0);
       
   375 	}
       
   376 
       
   377 void CSortChecker::CheckSortLowSubView(TSortOrder aOrder,const TDesC& aName,TInt aIndex,const TDesC& aHighBoundary) const
       
   378 	{
       
   379 	const RPointerArray<HBufC>& sortedList=(aOrder==ELastNameFirstName) ? iSortedLastFirst : iSortedFirstLast;
       
   380 	const HBufC* name=sortedList[aIndex];
       
   381 	iConductor.iLog->LogLineNoEcho(_L("Checking - %S against %S"),&aName,name);
       
   382 	iConductor.iTest(name->CompareC(aHighBoundary,3,iCollateMethod)<0);
       
   383 	iConductor.iTest(name->Compare(aName)==0);
       
   384 	}
       
   385 
       
   386 void CSortChecker::CheckSortHighSubView(TSortOrder aOrder,const TDesC& aName,TInt aIndex,const TDesC& aLowBoundary) const
       
   387 	{
       
   388 	const RPointerArray<HBufC>& sortedList=(aOrder==ELastNameFirstName) ? iSortedLastFirst : iSortedFirstLast;
       
   389 	const TInt lowIndex=FindIndex(aOrder,aLowBoundary,CSortChecker::EGreaterThanOrEqualTo);
       
   390 	if (lowIndex!=KErrNotFound)
       
   391 		{
       
   392 		iConductor.iLog->LogLineNoEcho(_L("Checking - %S against %S"),&aName,sortedList[lowIndex+aIndex]);
       
   393 		iConductor.iTest(sortedList[lowIndex+aIndex]->Compare(aName)==0);
       
   394 		}
       
   395 	}
       
   396 
       
   397 void CSortChecker::CheckSortSubView(TSortOrder aOrder,const TDesC& aName,TInt aIndex,const TDesC& aLowBoundary,const TDesC& aHighBoundary) const
       
   398 	{
       
   399 	const RPointerArray<HBufC>& sortedList=(aOrder==ELastNameFirstName) ? iSortedLastFirst : iSortedFirstLast;
       
   400 	const TInt lowIndex=FindIndex(aOrder,aLowBoundary,CSortChecker::EGreaterThanOrEqualTo);
       
   401 	if (lowIndex!=KErrNotFound)
       
   402 		{
       
   403 		const HBufC* name=sortedList[lowIndex+aIndex];
       
   404 		iConductor.iLog->LogLineNoEcho(_L("Checking - %S against %S"),&aName,name);
       
   405 		iConductor.iTest(name->CompareC(aHighBoundary,3,iCollateMethod)<0);
       
   406 		iConductor.iTest(name->Compare(aName)==0);
       
   407 		}
       
   408 	}
       
   409 
       
   410 TInt CSortChecker::FindIndex(TSortOrder aOrder,const TDesC& aBoundary,TCriteria aCriteria) const
       
   411 	{
       
   412 	const RPointerArray<HBufC>& sortedList=(aOrder==ELastNameFirstName) ? iSortedLastFirst : iSortedFirstLast;
       
   413 	const TInt numContacts=sortedList.Count();
       
   414 	for (TInt ii=0;ii<numContacts;++ii)
       
   415 		{
       
   416 		switch (aCriteria)
       
   417 			{
       
   418 			case ELessThan:
       
   419 				if (sortedList[ii]->CompareC(aBoundary,3,iCollateMethod)<0)
       
   420 					{
       
   421 					return ii;
       
   422 					}
       
   423 				break;
       
   424 			case ELessThanOrEqualTo:
       
   425 				if (sortedList[ii]->CompareC(aBoundary,3,iCollateMethod)<=0)
       
   426 					{
       
   427 					return ii;
       
   428 					}
       
   429 				break;
       
   430 			case EGreaterThan:
       
   431 				if (sortedList[ii]->CompareC(aBoundary,3,iCollateMethod)>0)
       
   432 					{
       
   433 					return ii;
       
   434 					}
       
   435 				break;
       
   436 			case EGreaterThanOrEqualTo:
       
   437 				if (sortedList[ii]->CompareC(aBoundary,3,iCollateMethod)>=0)
       
   438 					{
       
   439 					return ii;
       
   440 					}
       
   441 				break;
       
   442 			default:
       
   443 				ASSERT(EFalse);
       
   444 			}
       
   445 		}
       
   446 	return KErrNotFound;
       
   447 	}
       
   448 
       
   449 TInt CSortChecker::Compare(const HBufC& aFirst, const HBufC& aSecond)
       
   450 	{
       
   451 	TCollationMethod collateMethod;
       
   452 	collateMethod = *Mem::CollationMethodByIndex(0);
       
   453 	collateMethod.iFlags|=TCollationMethod::EIgnoreNone;
       
   454 	return aFirst.CompareC(aSecond,3,&collateMethod);
       
   455 	}
       
   456 
       
   457 
       
   458 //
       
   459 // CTestBase.
       
   460 //
       
   461 
       
   462 CTestBase::CTestBase(CTestConductor& aConductor) : iConductor(aConductor)
       
   463 	{
       
   464 	}
       
   465 
       
   466 
       
   467 //
       
   468 // CViewCreator.
       
   469 //
       
   470 
       
   471 CViewCreator* CViewCreator::NewL(CTestConductor& aConductor)
       
   472 	{
       
   473 	CViewCreator* self=new(ELeave) CViewCreator(aConductor);
       
   474 	return self;
       
   475 	}
       
   476 
       
   477 CContactLocalView* CViewCreator::CreateLocalViewL(const RContactViewSortOrder& aSortOrder)
       
   478 	{
       
   479 	TInt32 viewPrefs=0;
       
   480 	viewPrefs|=EContactAndGroups;
       
   481 	iView=CContactLocalView::NewL(iConductor,*iConductor.iDb,aSortOrder,TContactViewPreferences(viewPrefs));
       
   482 	return STATIC_CAST(CContactLocalView*,iView);
       
   483 	}
       
   484 
       
   485 CContactNamedLocalView* CViewCreator::CreateNamedLocalViewL(const TDesC& aName,const RContactViewSortOrder& aSortOrder)
       
   486 	{
       
   487 	TInt32 viewPrefs=0;
       
   488 	viewPrefs|=EContactAndGroups;
       
   489 	iView=CContactNamedLocalView::NewL(iConductor,aName,*iConductor.iDb,aSortOrder,TContactViewPreferences(viewPrefs));
       
   490 	return STATIC_CAST(CContactNamedLocalView*,iView);
       
   491 	}
       
   492 
       
   493 CContactRemoteView* CViewCreator::CreateRemoteViewL(const RContactViewSortOrder& aSortOrder)
       
   494 	{
       
   495 	TInt32 viewPrefs=0;
       
   496 	viewPrefs|=EContactAndGroups;
       
   497 	iView=CContactRemoteView::NewL(iConductor,*iConductor.iDb,aSortOrder,TContactViewPreferences(viewPrefs));
       
   498 	return STATIC_CAST(CContactRemoteView*,iView);
       
   499 	}
       
   500 
       
   501 CContactNamedRemoteView* CViewCreator::CreateNamedRemoteViewL(const TDesC& aName,const RContactViewSortOrder& aSortOrder)
       
   502 	{
       
   503 	TInt32 viewPrefs=0;
       
   504 	viewPrefs|=EContactAndGroups;
       
   505 	iView=CContactNamedRemoteView::NewL(iConductor,aName,*iConductor.iDb,aSortOrder,TContactViewPreferences(viewPrefs));
       
   506 	return STATIC_CAST(CContactNamedRemoteView*,iView);
       
   507 	}
       
   508 
       
   509 CContactSubView* CViewCreator::CreateSubViewL(CContactViewBase& aUnderlyingView,const TDesC& aBoundary)
       
   510 	{
       
   511 	iView=CContactSubView::NewL(iConductor,*iConductor.iDb,aUnderlyingView,aBoundary);
       
   512 	return STATIC_CAST(CContactSubView*,iView);
       
   513 	}
       
   514 
       
   515 CContactSubView* CViewCreator::CreateSubViewL(CContactViewBase& aUnderlyingView,const TDesC& aLowBoundary,const TDesC& aHighBoundary)
       
   516 	{
       
   517 	iView=CContactSubView::NewL(iConductor,*iConductor.iDb,aUnderlyingView,aLowBoundary,aHighBoundary);
       
   518 	return STATIC_CAST(CContactSubView*,iView);
       
   519 	}
       
   520 
       
   521 CContactConcatenatedView* CViewCreator::CreateConcatenatedViewL(RPointerArray<CContactViewBase>& aComponentViews)
       
   522 	{
       
   523 	iView=CContactConcatenatedView::NewL(iConductor,*iConductor.iDb,aComponentViews);
       
   524 	return STATIC_CAST(CContactConcatenatedView*,iView);
       
   525 	}
       
   526 
       
   527 void CViewCreator::HandleNotificationL(const CContactViewBase& aView,const TContactViewEvent& aEvent)
       
   528 	{
       
   529  	if(&aView==iView)
       
   530 	 		{
       
   531 	 		iConductor.iTest(aEvent.iEventType==TContactViewEvent::EReady);
       
   532 	 		iConductor.NextTest();
       
   533 	 		}
       
   534 	}
       
   535 
       
   536 CViewCreator::CViewCreator(CTestConductor& aConductor) : CTestBase(aConductor)
       
   537 	{
       
   538 	}
       
   539 
       
   540 
       
   541 //
       
   542 // CContactAdder.
       
   543 //
       
   544 
       
   545 CContactAdder* CContactAdder::NewL(CTestConductor& aConductor)
       
   546 	{
       
   547 	CContactAdder* self=new(ELeave) CContactAdder(aConductor);
       
   548 	CleanupStack::PushL(self);
       
   549 	self->ConstructL();
       
   550 	CleanupStack::Pop(); // self.
       
   551 	return self;
       
   552 	}
       
   553 
       
   554 CContactAdder::~CContactAdder()
       
   555 	{
       
   556 	delete iRandomGenerator;
       
   557 	delete iTemplate;
       
   558 	iFile.Close();
       
   559 	iFs.Close();
       
   560 	}
       
   561 
       
   562 void CContactAdder::AddContactsL(const TDesC& aFileName,TInt aNumViews)
       
   563 	{
       
   564 	User::LeaveIfError(iFile.Open(iFs,aFileName,EFileShareAny|EFileStreamText));
       
   565 	iNumViews=aNumViews;
       
   566 	TInt pos=2;
       
   567 	iFile.Seek(ESeekStart,pos); // Ignore Unicode header.
       
   568 	iConductor.iTest.Printf(_L("Adding contact "));
       
   569 	AddOneContactL();
       
   570 	}
       
   571 
       
   572 void CContactAdder::HandleNotificationL(const CContactViewBase&,const TContactViewEvent& aEvent)
       
   573 	{
       
   574 	if (++iNumNotifications==iNumViews)
       
   575 		{
       
   576 		if (iFinished)
       
   577 			{
       
   578 			iConductor.NextTest();
       
   579 			}
       
   580 		else
       
   581 			{
       
   582 			AddOneContactL();
       
   583 			}
       
   584 		}
       
   585 	else
       
   586 		{
       
   587 		iConductor.iTest(aEvent.iEventType==TContactViewEvent::EItemAdded);
       
   588 		}
       
   589 	}
       
   590 
       
   591 CContactAdder::CContactAdder(CTestConductor& aConductor) : CTestBase(aConductor)
       
   592 	{
       
   593 	}
       
   594 
       
   595 void CContactAdder::ConstructL()
       
   596 	{
       
   597 	User::LeaveIfError(iFs.Connect());
       
   598 	iTemplate=STATIC_CAST(CContactTemplate*,iConductor.iDb->ReadContactL(iConductor.iDb->TemplateId()));
       
   599 	iRandomGenerator=CRandomContactGenerator::NewL();
       
   600 	iRandomGenerator->SetDbL(*iConductor.iDb);
       
   601 	}
       
   602 
       
   603 void CContactAdder::AddOneContactL()
       
   604 	{
       
   605 	iRandomGenerator->AddTypicalRandomContactL();
       
   606 	iConductor.iLog->IncVisualCounter();
       
   607 	iNumNotifications=0;
       
   608 	TBuf<64> firstName;
       
   609 	TBuf<64> lastName;
       
   610 	iConductor.iLog->IncVisualCounter();
       
   611 	iFinished=!ReadNamePairL(iFile,firstName,lastName);
       
   612 	iConductor.iLog->LogLineNoEcho(_L("Adding %S %S"),&firstName,&lastName);
       
   613 	CTestContact* contact=CTestContact::NewLC(*iTemplate);
       
   614 	contact->SetFirstNameL(firstName);
       
   615 	contact->SetLastNameL(lastName);
       
   616 	iConductor.iDb->AddNewContactL(contact->ContactItem());
       
   617 	CleanupStack::PopAndDestroy(); // contact.
       
   618 	iConductor.iDb->CompactL();
       
   619 	iConductor.iSortChecker->AddContactL(firstName,lastName);
       
   620 	if (iFinished)
       
   621 		{
       
   622 		iConductor.iLog->EndVisualCounter();
       
   623 		iConductor.iSortChecker->Sort();
       
   624 		}
       
   625 	}
       
   626 
       
   627 TBool CContactAdder::ReadNamePairL(RFile aFile,TDes& aFirstName,TDes& aLastName)
       
   628 	{
       
   629 	TBuf8<2> character=_L8("  ");
       
   630 	TBuf8<4> lineEndTestBuf=_L8("    ");
       
   631 
       
   632 	aFirstName.SetLength(0);
       
   633 	aLastName.SetLength(0);
       
   634 	TBool readingLastName=ETrue;
       
   635 	while (lineEndTestBuf!=KUnicodeLineEnd)
       
   636 		{
       
   637 		User::LeaveIfError(aFile.Read(character,2));
       
   638 		if (character.Length()>0)
       
   639 			{
       
   640 			lineEndTestBuf[0]=lineEndTestBuf[2];
       
   641 			lineEndTestBuf[1]=lineEndTestBuf[3];
       
   642 			lineEndTestBuf[2]=character[0];
       
   643 			lineEndTestBuf[3]=character[1];
       
   644 
       
   645 			const TPtrC16 widePtr((TUint16*)character.Ptr(),1);
       
   646 			if (widePtr[0]==';')
       
   647 				{
       
   648 				readingLastName=EFalse;
       
   649 				}
       
   650 			else if (readingLastName)
       
   651 				{
       
   652 				aLastName.Append(widePtr);
       
   653 				}
       
   654 			else
       
   655 				{
       
   656 				aFirstName.Append(widePtr);
       
   657 				}
       
   658 			}
       
   659 		else
       
   660 			{
       
   661 			return EFalse;
       
   662 			}
       
   663 		}
       
   664 
       
   665 	aFirstName.Delete(aFirstName.Length()-2,2); // Strip off \n\r.
       
   666 	return ETrue;
       
   667 	}
       
   668 
       
   669 
       
   670 //
       
   671 // CContactRemover.
       
   672 //
       
   673 
       
   674 CContactRemover* CContactRemover::NewL(CTestConductor& aConductor)
       
   675 	{
       
   676 	CContactRemover* self=new(ELeave) CContactRemover(aConductor);
       
   677 	CleanupStack::PushL(self);
       
   678 	self->ConstructL();
       
   679 	CleanupStack::Pop(); // self.
       
   680 	return self;
       
   681 	}
       
   682 
       
   683 CContactRemover::~CContactRemover()
       
   684 	{
       
   685 	iFile.Close();
       
   686 	iFs.Close();
       
   687 	}
       
   688 
       
   689 void CContactRemover::RemoveContactsL(const TDesC& aFileName,TInt aNumViews)
       
   690 	{
       
   691 	User::LeaveIfError(iFile.Open(iFs,aFileName,EFileShareAny|EFileStreamText));
       
   692 	iNumViews=aNumViews;
       
   693 	TInt pos=2;
       
   694 	iFile.Seek(ESeekStart,pos); // Ignore Unicode header.
       
   695 	iConductor.iTest.Printf(_L("Removing contact "));
       
   696 	RemoveOneContactL();
       
   697 	}
       
   698 
       
   699 void CContactRemover::HandleNotificationL(const CContactViewBase&,const TContactViewEvent& aEvent)
       
   700 	{
       
   701 	if (++iNumNotifications==iNumViews)
       
   702 		{
       
   703 		if (iFinished)
       
   704 			{
       
   705 			iConductor.NextTest();
       
   706 			}
       
   707 		else
       
   708 			{
       
   709 			RemoveOneContactL();
       
   710 			}
       
   711 		}
       
   712 	else
       
   713 		{
       
   714 		iConductor.iTest(aEvent.iEventType==TContactViewEvent::EItemRemoved);
       
   715 		}
       
   716 	}
       
   717 
       
   718 CContactRemover::CContactRemover(CTestConductor& aConductor) : CTestBase(aConductor)
       
   719 	{
       
   720 	}
       
   721 
       
   722 void CContactRemover::ConstructL()
       
   723 	{
       
   724 	User::LeaveIfError(iFs.Connect());
       
   725 	}
       
   726 
       
   727 void CContactRemover::RemoveOneContactL()
       
   728 	{
       
   729 	iNumNotifications=0;
       
   730 	TBuf<64> firstName;
       
   731 	TBuf<64> lastName;
       
   732 	iConductor.iLog->IncVisualCounter();
       
   733 	iFinished=!CContactAdder::ReadNamePairL(iFile,firstName,lastName);
       
   734 	iConductor.iLog->LogLineNoEcho(_L("Removing %S %S"),&firstName,&lastName);
       
   735 	CContactItemFieldDef* def=new(ELeave) CContactItemFieldDef();
       
   736 	CleanupStack::PushL(def);
       
   737 	def->AppendL(KUidContactFieldGivenName);
       
   738 	def->AppendL(KUidContactFieldFamilyName);
       
   739 	CContactIdArray* matchList1=iConductor.iDb->FindLC(lastName,def);
       
   740 	CContactIdArray* matchList2=iConductor.iDb->FindLC(firstName,def);
       
   741 
       
   742 	for (TInt ii=matchList1->Count()-1;ii>=0;--ii)
       
   743 		{
       
   744 		TContactItemId thisId=(*matchList1)[ii];
       
   745 		for (TInt jj=matchList2->Count()-1;jj>=0;--jj)
       
   746 			{
       
   747 			if (thisId==(*matchList2)[jj])
       
   748 				{
       
   749 				iConductor.iDb->DeleteContactL(thisId);
       
   750 				goto carry_on;
       
   751 				}
       
   752 			}
       
   753 		}
       
   754 	ASSERT(EFalse);
       
   755 
       
   756 carry_on:
       
   757 	CleanupStack::PopAndDestroy(3); // matchList2, matchList1, def.
       
   758 	iConductor.iDb->CompactL();
       
   759 	iConductor.iSortChecker->RemoveContactL(firstName,lastName);
       
   760 	if (iFinished)
       
   761 		{
       
   762 		iConductor.iLog->EndVisualCounter();
       
   763 		iConductor.iSortChecker->Sort();
       
   764 		}
       
   765 	}
       
   766 
       
   767 
       
   768 //
       
   769 // CViewExerciser.
       
   770 //
       
   771 
       
   772 CViewExerciser* CViewExerciser::NewL(CTestConductor& aConductor)
       
   773 	{
       
   774 	CViewExerciser* self=new(ELeave) CViewExerciser(aConductor);
       
   775 	CleanupStack::PushL(self);
       
   776 	self->ConstructL();
       
   777 	CleanupStack::Pop(); // self.
       
   778 	return self;
       
   779 	}
       
   780 
       
   781 /*void CViewExerciser::ProfileViewL(CContactViewBase& aView)
       
   782 	{
       
   783 	TInt viewCount = aView.CountL();
       
   784 	RDebug::Print(_L("Profile view Count: %d"),viewCount);
       
   785 	CCntTest::ProfileReset(0,1);
       
   786 	CCntTest::ProfileStart(0);
       
   787 	for (TInt ii=0;ii<viewCount;++ii)
       
   788 		{
       
   789 		aView.ContactAtL(ii);
       
   790 		}
       
   791 	CCntTest::ProfileEnd(0);
       
   792 	TCntProfile profile[1];
       
   793 	CCntTest::ProfileResult(profile,0,1);
       
   794 	TReal result = profile[0].iTime;//1000000.0;
       
   795 	RDebug::Print(_L("Profile ContactAt Time Taken: %g"),result);
       
   796 	}*/
       
   797 
       
   798 void CViewExerciser::ExerciseViewL(CSortChecker::TSortOrder aSortOrder,CContactViewBase& aView)
       
   799 	{
       
   800 	TBuf<128> scratchBuf;
       
   801 	TContactItemId lastId=0;
       
   802 	const TInt numItems=aView.CountL();
       
   803 	iConductor.iTest(iConductor.iSortChecker->Count()==numItems);
       
   804 	CContactTextDef* textDef=(aSortOrder==CSortChecker::EFirstNameLastName) ? iTextDef_FirstLast : iTextDef_LastFirst;
       
   805 
       
   806 	for (TInt ii=0;ii<numItems;++ii)
       
   807 		{
       
   808 		TContactItemId thisId=aView.AtL(ii);
       
   809 		if (ii==numItems-1)
       
   810 			{
       
   811 			lastId=thisId;
       
   812 			}
       
   813 
       
   814 		iConductor.iDb->ReadContactTextDefL(thisId,scratchBuf,textDef);
       
   815 		iConductor.iSortChecker->CheckSort(aSortOrder,scratchBuf,ii);
       
   816 		scratchBuf.SetLength(0);
       
   817 		}
       
   818 
       
   819 	iConductor.iTest(aView.FindL(lastId)==numItems-1);
       
   820 
       
   821 	if (iQueue)
       
   822 		{
       
   823 		iConductor.NextTest();
       
   824 		}
       
   825 	}
       
   826 
       
   827 void CViewExerciser::ExerciseSubViewL(CSortChecker::TSortOrder aSortOrder,CContactViewBase& aView,const TDesC& aLowBoundary,const TDesC& aHighBoundary)
       
   828 	{
       
   829 	TBuf<128> scratchBuf;
       
   830 	TContactItemId lastId=0;
       
   831 	const TInt numItems=aView.CountL();
       
   832 	iConductor.iTest(iConductor.iSortChecker->Count(aSortOrder,aLowBoundary,aHighBoundary)==numItems);
       
   833 
       
   834 	for (TInt ii=0;ii<numItems;++ii)
       
   835 		{
       
   836 		TContactItemId thisId=aView.AtL(ii);
       
   837 		if (ii==numItems-1)
       
   838 			{
       
   839 			lastId=thisId;
       
   840 			}
       
   841 		CContactTextDef* textDef=(aSortOrder==CSortChecker::EFirstNameLastName) ? iTextDef_FirstLast : iTextDef_LastFirst;
       
   842 		iConductor.iDb->ReadContactTextDefL(thisId,scratchBuf,textDef);
       
   843 		iConductor.iSortChecker->CheckSortSubView(aSortOrder,scratchBuf,ii,aLowBoundary,aHighBoundary);
       
   844 		scratchBuf.SetLength(0);
       
   845 		}
       
   846 
       
   847 	iConductor.iTest(aView.FindL(lastId)==numItems-1);
       
   848 
       
   849 	if (iQueue)
       
   850 		{
       
   851 		iConductor.NextTest();
       
   852 		}
       
   853 	}
       
   854 
       
   855 void CViewExerciser::ExerciseLowSubViewL(CSortChecker::TSortOrder aSortOrder,CContactViewBase& aView,const TDesC& aLowBoundary)
       
   856 	{
       
   857 	TBuf<128> scratchBuf;
       
   858 	TContactItemId lastId=0;
       
   859 	const TInt numItems=aView.CountL();
       
   860 	iConductor.iTest(iConductor.iSortChecker->CountLow(aSortOrder,aLowBoundary)==numItems);
       
   861 
       
   862 	for (TInt ii=0;ii<numItems;++ii)
       
   863 		{
       
   864 		TContactItemId thisId=aView.AtL(ii);
       
   865 		if (ii==numItems-1)
       
   866 			{
       
   867 			lastId=thisId;
       
   868 			}
       
   869 		CContactTextDef* textDef=(aSortOrder==CSortChecker::EFirstNameLastName) ? iTextDef_FirstLast : iTextDef_LastFirst;
       
   870 		iConductor.iDb->ReadContactTextDefL(thisId,scratchBuf,textDef);
       
   871 		iConductor.iSortChecker->CheckSortLowSubView(aSortOrder,scratchBuf,ii,aLowBoundary);
       
   872 		scratchBuf.SetLength(0);
       
   873 		}
       
   874 
       
   875 	iConductor.iTest(aView.FindL(lastId)==numItems-1);
       
   876 
       
   877 	if (iQueue)
       
   878 		{
       
   879 		iConductor.NextTest();
       
   880 		}
       
   881 	}
       
   882 
       
   883 void CViewExerciser::ExerciseHighSubViewL(CSortChecker::TSortOrder aSortOrder,CContactViewBase& aView,const TDesC& aHighBoundary)
       
   884 	{
       
   885 	TBuf<128> scratchBuf;
       
   886 	TContactItemId lastId=0;
       
   887 	const TInt numItems=aView.CountL();
       
   888 	iConductor.iTest(iConductor.iSortChecker->CountHigh(aSortOrder,aHighBoundary)==numItems);
       
   889 
       
   890 	for (TInt ii=0;ii<numItems;++ii)
       
   891 		{
       
   892 		TContactItemId thisId=aView.AtL(ii);
       
   893 		if (ii==numItems-1)
       
   894 			{
       
   895 			lastId=thisId;
       
   896 			}
       
   897 		CContactTextDef* textDef=(aSortOrder==CSortChecker::EFirstNameLastName) ? iTextDef_FirstLast : iTextDef_LastFirst;
       
   898 		iConductor.iDb->ReadContactTextDefL(thisId,scratchBuf,textDef);
       
   899 		iConductor.iSortChecker->CheckSortHighSubView(aSortOrder,scratchBuf,ii,aHighBoundary);
       
   900 		scratchBuf.SetLength(0);
       
   901 		}
       
   902 
       
   903 	iConductor.iTest(aView.FindL(lastId)==numItems-1);
       
   904 
       
   905 	if (iQueue)
       
   906 		{
       
   907 		iConductor.NextTest();
       
   908 		}
       
   909 	}
       
   910 
       
   911 CViewExerciser::~CViewExerciser()
       
   912 	{
       
   913 	delete iTextDef_FirstLast;
       
   914 	delete iTextDef_LastFirst;
       
   915 	}
       
   916 
       
   917 void CViewExerciser::HandleNotificationL(const CContactViewBase&,const TContactViewEvent&)
       
   918 	{
       
   919 	iConductor.iTest(EFalse);
       
   920 	}
       
   921 
       
   922 CViewExerciser::CViewExerciser(CTestConductor& aConductor) : CTestBase(aConductor),iQueue(ETrue)
       
   923 	{
       
   924 	}
       
   925 
       
   926 void CViewExerciser::ConstructL()
       
   927 	{
       
   928 	iTextDef_FirstLast=CContactTextDef::NewL();
       
   929 	iTextDef_FirstLast->AppendL(TContactTextDefItem(KUidContactFieldGivenName,KTextDefSeparator));
       
   930 	iTextDef_FirstLast->AppendL(TContactTextDefItem(KUidContactFieldFamilyName,KTextDefSeparator));
       
   931 	iTextDef_FirstLast->AppendL(TContactTextDefItem(KUidContactFieldCompanyName,KTextDefSeparator));
       
   932 
       
   933 	iTextDef_LastFirst=CContactTextDef::NewL();
       
   934 	iTextDef_LastFirst->AppendL(TContactTextDefItem(KUidContactFieldFamilyName,KTextDefSeparator));
       
   935 	iTextDef_LastFirst->AppendL(TContactTextDefItem(KUidContactFieldGivenName,KTextDefSeparator));
       
   936 	iTextDef_LastFirst->AppendL(TContactTextDefItem(KUidContactFieldCompanyName,KTextDefSeparator));
       
   937 	}
       
   938 
       
   939 void CViewExerciser::QueueNextTestWhenComplete(TBool aQueue)
       
   940 	{
       
   941 	iQueue=aQueue;
       
   942 	}
       
   943 
       
   944 
       
   945 //
       
   946 // CSortOrderChanger.
       
   947 //
       
   948 
       
   949 CSortOrderChanger* CSortOrderChanger::NewL(CTestConductor& aConductor)
       
   950 	{
       
   951 	CSortOrderChanger* self=new(ELeave) CSortOrderChanger(aConductor);
       
   952 	return self;
       
   953 	}
       
   954 
       
   955 void CSortOrderChanger::ChangeSortOrderL(RContactViewSortOrder& aSortOrder,CContactNamedLocalView& aView,TInt aNumViews)
       
   956 	{
       
   957 	aView.ChangeSortOrderL(aSortOrder);
       
   958 	iNumViews=aNumViews;
       
   959 	iNumNotifications=0;
       
   960 	}
       
   961 
       
   962 void CSortOrderChanger::ChangeSortOrderL(RContactViewSortOrder& aSortOrder,CContactNamedRemoteView& aView,TInt aNumViews)
       
   963 	{
       
   964 	aView.ChangeSortOrderL(aSortOrder);
       
   965 	iNumViews=aNumViews;
       
   966 	iNumNotifications=0;
       
   967 	}
       
   968 
       
   969 CSortOrderChanger::~CSortOrderChanger()
       
   970 	{
       
   971 	}
       
   972 
       
   973 void CSortOrderChanger::HandleNotificationL(const CContactViewBase&,const TContactViewEvent& aEvent)
       
   974 	{
       
   975 	iConductor.iTest(aEvent.iEventType==TContactViewEvent::EUnavailable || aEvent.iEventType==TContactViewEvent::ESortOrderChanged || aEvent.iEventType==TContactViewEvent::EReady);
       
   976 //	if (++iNumNotifications==iNumViews*3) // 3 because there will be EUnavailable, ESortOrderChanged, and EReady notifications for each view.
       
   977 	if (++iNumNotifications==iNumViews*2) // 3 because there will be EUnavailable, ESortOrderChanged, and EReady notifications for each view.		
       
   978 		{
       
   979 		iConductor.NextTest();
       
   980 		}
       
   981 	}
       
   982 
       
   983 CSortOrderChanger::CSortOrderChanger(CTestConductor& aConductor) : CTestBase(aConductor)
       
   984 	{
       
   985 	}
       
   986 
       
   987 
       
   988 
       
   989 //	
       
   990 //
       
   991 // COomFailBase
       
   992 //
       
   993 
       
   994 COomFailBase::COomFailBase(COomTest *aOomTest,CContactDatabase* aDb,CContactViewBase* aUnderlyingView)
       
   995  : iOomTest(aOomTest),iDb(aDb),iUnderlyingView(aUnderlyingView)
       
   996 	{}
       
   997 
       
   998 COomFailBase::~COomFailBase()
       
   999 	{
       
  1000 	}
       
  1001 
       
  1002 void COomFailBase::ConstructL()
       
  1003 	{}
       
  1004 
       
  1005 void COomFailBase::PreFailL()
       
  1006 	{}
       
  1007 
       
  1008 void COomFailBase::ClearUp()
       
  1009 	{}
       
  1010 
       
  1011 TBool COomFailBase::Skip(TInt , TOomFailureModes ) const
       
  1012 	{
       
  1013 	return(EFalse);
       
  1014 	}
       
  1015 
       
  1016 void COomFailBase::ClearEventQueueL()
       
  1017 	{
       
  1018 	_LIT(KLoggingFormat, "(%d) Database Event Consumed. Type: %d\n");
       
  1019 	
       
  1020 	CContactDbEventQueue* eventQueue = CContactDbEventQueue::NewL(iDb, KMaxNumRequests);
       
  1021 	CleanupStack::PushL(eventQueue);
       
  1022 	
       
  1023 	// Clear the view of all outstanding events before continuing
       
  1024 	TContactDbObserverEvent  event;
       
  1025 	TBool expectingEvent = ETrue;
       
  1026 	const TInt KTimeOutInSeconds = 1;
       
  1027 	for(TInt i = 0; expectingEvent; ++i)
       
  1028 		{
       
  1029 		expectingEvent = eventQueue->ListenForEvent(KTimeOutInSeconds, event);
       
  1030 		if (expectingEvent) // meaning if we've just received one
       
  1031 			{
       
  1032 			iOomTest->Conductor().iTest.Printf(KLoggingFormat, i, event.iType);
       
  1033 			}
       
  1034 		}
       
  1035 	
       
  1036 	CleanupStack::PopAndDestroy(eventQueue);
       
  1037 	}
       
  1038 
       
  1039 //
       
  1040 // COomTest
       
  1041 //
       
  1042 
       
  1043 COomTest::COomTest(CContactDatabase* aDb,CContactLocalView* aLocalView,CContactRemoteView* aRemoteView,CContactGroup* aGroup,CTestConductor& aConductor)
       
  1044  : iDb (aDb),iLocalView(aLocalView),iRemoteView (aRemoteView),iGroupOne(aGroup),iConductor(aConductor)
       
  1045 	{}
       
  1046 	
       
  1047 void COomTest::Test(TBool aMustBeTrue)
       
  1048 	{
       
  1049 	iConductor.iTest(aMustBeTrue);
       
  1050 	}
       
  1051 	
       
  1052 CTestConductor& COomTest::Conductor() const
       
  1053 	{
       
  1054 	return iConductor;
       
  1055 	}
       
  1056 
       
  1057 void COomTest::DoOomTestL(COomFailBase *aOomTest, TOomFailureModes aMode)
       
  1058 	{
       
  1059 	Test(aOomTest!=NULL);
       
  1060 	iConductor.iTest.Next(_L(""));
       
  1061 
       
  1062 
       
  1063 	__UHEAP_MARK;
       
  1064 	TInt oldFsCount=TheFs.ResourceCount();
       
  1065 //
       
  1066 	CleanupStack::PushL(aOomTest);
       
  1067 	TRAPD(ret1,aOomTest->ConstructL());
       
  1068 	Test(ret1==KErrNone);
       
  1069 	CContactDatabase *lockDb=NULL;
       
  1070 	if (aMode==KOomFailContactServer)	// contact server failure tests
       
  1071 		{
       
  1072 		lockDb=CContactDatabase::OpenL(KDbFileName);
       
  1073 		CleanupStack::PushL(lockDb);
       
  1074 		}
       
  1075 	TInt successCount=0;
       
  1076 	TInt skipCount=0;
       
  1077 	for(TInt count=0;;count++)
       
  1078 		{//
       
  1079 		TRAPD(preFailErr,aOomTest->PreFailL());
       
  1080 		iConductor.iTest(preFailErr==KErrNone);
       
  1081 		switch(aMode)
       
  1082 			{
       
  1083 			case KOomFailNormal:
       
  1084 				__UHEAP_SETFAIL(RHeap::EDeterministic,count);
       
  1085 				break;
       
  1086 			case KOomFailContactServer:
       
  1087 				lockDb->SetCntServerHeapFailure(RHeap::EDeterministic,count);
       
  1088 				break;
       
  1089 			case KOomFailFileServerOom:
       
  1090 				TheFs.SetErrorCondition(KErrNoMemory,count);
       
  1091 				break;
       
  1092 			case KOomFailFileServerGeneral:
       
  1093 				TheFs.SetErrorCondition(KErrGeneral,count);
       
  1094 				break;
       
  1095 			default:;
       
  1096 			}
       
  1097 		TInt ret=KErrNone;
       
  1098 		if (aOomTest->Skip(count,aMode))
       
  1099 			skipCount++;
       
  1100 		else
       
  1101 			{
       
  1102 			__UHEAP_MARK;
       
  1103 			TRAP(ret,aOomTest->FailL());
       
  1104 			__UHEAP_MARKEND;
       
  1105 			}
       
  1106 		switch(aMode)
       
  1107 			{
       
  1108 			case KOomFailNormal:
       
  1109 				__UHEAP_RESET;
       
  1110 				break;
       
  1111 			case KOomFailContactServer:
       
  1112 				lockDb->SetCntServerHeapFailure(RHeap::ENone,0);
       
  1113 				break;
       
  1114 			case KOomFailFileServerOom:
       
  1115 			case KOomFailFileServerGeneral:
       
  1116 				TheFs.SetErrorCondition(KErrNone);
       
  1117 				break;
       
  1118 			default:;
       
  1119 			}
       
  1120 		TRAPD(clearUpErr,aOomTest->ClearUp());
       
  1121 		iConductor.iTest(clearUpErr==KErrNone);
       
  1122 		if (ret==KErrNone)
       
  1123 			{
       
  1124 			if (successCount==8)
       
  1125 				{
       
  1126 				iConductor.iTest.Printf(_L("Count=%d"),count);
       
  1127 				if (skipCount>0)
       
  1128 					iConductor.iTest.Printf(_L(", skipped=%d"),skipCount);
       
  1129 				iConductor.iTest.Printf(_L("\n"));
       
  1130 				break;
       
  1131 				}
       
  1132 			successCount++;
       
  1133 			}
       
  1134 		else
       
  1135 			{
       
  1136 			successCount=0;
       
  1137 			if (aMode==KOomFailFileServerGeneral)
       
  1138 				Test(ret==KErrGeneral || ret==KErrNotFound);
       
  1139 			else if (aMode==KOomFailFileServerOom)
       
  1140 				Test(ret==KErrNoMemory || ret==KErrNotFound);
       
  1141 			else
       
  1142 				Test(ret==KErrNoMemory);
       
  1143 			}
       
  1144 		}//
       
  1145 
       
  1146 	if (aMode==KOomFailContactServer)
       
  1147 		CleanupStack::PopAndDestroy();	// lockDb
       
  1148 	CleanupStack::PopAndDestroy();	// aOomTest
       
  1149 	Test(oldFsCount==TheFs.ResourceCount());
       
  1150 	__UHEAP_MARKEND;
       
  1151 
       
  1152 	}
       
  1153 
       
  1154 COomTest::~COomTest()
       
  1155 	{}
       
  1156 
       
  1157 TBool COomTest::TestsL()
       
  1158 	{
       
  1159     //__UHEAP_MARK;
       
  1160 	for(TInt loop=0;loop<KOomNumFailModes;loop++)
       
  1161 		{
       
  1162 		if (loop > 0)
       
  1163 			{ // increment the RTest number XXX
       
  1164 			iConductor.iTest.Next(_L("--- Next Error case ---"));
       
  1165 
       
  1166 			}
       
  1167 
       
  1168 		TOomFailureModes mode=(TOomFailureModes)loop;
       
  1169 		switch(mode)
       
  1170 			{
       
  1171 			case KOomFailNormal: // RTest 001.01
       
  1172 				iConductor.iTest.Start(_L("===Test Out Of Memory==="));
       
  1173 
       
  1174 				break;
       
  1175 			case KOomFailFileServerGeneral: // RTest 002.01
       
  1176 				iConductor.iTest.Start(_L("===Test File server general failure==="));
       
  1177 
       
  1178 				break;
       
  1179 			case KOomFailFileServerOom: // RTest 003.01
       
  1180 				iConductor.iTest.Start(_L("===Test File server Oom failure==="));
       
  1181 
       
  1182 				break;
       
  1183 			case KOomFailContactServer: // RTest 004.01
       
  1184 				iConductor.iTest.Start(_L("===Test Contact Server Oom failure==="));
       
  1185 
       
  1186 				break;
       
  1187 			default:;
       
  1188 			}
       
  1189 		User::LeaveIfError(TheFs.Connect());
       
  1190 
       
  1191 		//OOM TEST VIEWS//
       
  1192 		DoOomTestL(new(ELeave) COomLocalView(this, iDb, NULL), mode); //Pass
       
  1193 		DoOomTestL(new(ELeave) COomLocalView(this, iDb, NULL, KSortPlugin), mode); //Pass
       
  1194 		DoOomTestL(new(ELeave) COomRemoteView(this, iDb, NULL), mode); //Pass
       
  1195 		DoOomTestL(new(ELeave) COomRemoteView(this, iDb, NULL, KSortPlugin), mode); //Pass
       
  1196 		
       
  1197 		if(iLocalView)
       
  1198 		    {
       
  1199 		    for(TInt ii = 0; ii < iLocalView->CountL(); ++ii)
       
  1200 		        {
       
  1201 		        const CViewContact& temp = iLocalView->ContactAtL(ii);
       
  1202 		        }
       
  1203 		    }
       
  1204 		
       
  1205 		DoOomTestL(new(ELeave) COomFilteredView(this, iDb, iLocalView), mode);//Pass
       
  1206 		DoOomTestL(new(ELeave) COomSubView(this, iDb, iLocalView), mode); //Pass
       
  1207 		DoOomTestL(new(ELeave) COomSubView(this, iDb, iRemoteView), mode); //Pass
       
  1208 		DoOomTestL(new(ELeave) COomGroupView(this, iDb, iLocalView, iGroupOne), mode); //Pass
       
  1209 		DoOomTestL(new(ELeave) COomMatchingCriteria(this, iDb, iLocalView), mode);
       
  1210 		DoOomTestL(new(ELeave) COomMatchingCriteria(this, iDb, iRemoteView), mode);
       
  1211 		//
       
  1212 		iConductor.iTest(TheFs.ResourceCount()==0);
       
  1213 		TheFs.Close();
       
  1214 		iConductor.iTest.End();
       
  1215 		}
       
  1216     //__UHEAP_MARKEND;
       
  1217 	return(ETrue);
       
  1218 	}
       
  1219 
       
  1220 
       
  1221 //
       
  1222 // COomLocalView
       
  1223 //
       
  1224 
       
  1225 void COomLocalView::HandleContactViewEvent(const CContactViewBase& aView, const TContactViewEvent& /*aEvent*/)
       
  1226 	{
       
  1227 	if(&aView == iLocalView)
       
  1228 		{
       
  1229 		CActiveScheduler::Stop();
       
  1230 		}
       
  1231 	}
       
  1232 
       
  1233 
       
  1234 void COomLocalView::PreFailL()
       
  1235 	{
       
  1236 	iSortOrder.AppendL(KUidContactFieldGivenName);
       
  1237 	iSortOrder.AppendL(KUidContactFieldFamilyName);
       
  1238 	iSortOrder.AppendL(KUidContactFieldCompanyName);
       
  1239 	}
       
  1240 
       
  1241 void COomLocalView::FailL()
       
  1242 	{
       
  1243 	TInt32 viewPrefs=0; 
       
  1244 	viewPrefs|=EIgnoreUnSorted;
       
  1245 	if(iSortPluginName.Length() == 0)
       
  1246 		{
       
  1247 		iLocalView=CContactLocalView::NewL(*this,*iDb,iSortOrder,TContactViewPreferences(viewPrefs));
       
  1248 		}
       
  1249 	else
       
  1250 		{
       
  1251 		iLocalView=CContactLocalView::NewL(*this,*iDb,iSortOrder,TContactViewPreferences(viewPrefs),iSortPluginName);
       
  1252 		}
       
  1253 	CActiveScheduler::Start();
       
  1254 	iLocalView->Close(*this);
       
  1255 	ClearEventQueueL();
       
  1256 	}
       
  1257 
       
  1258 void COomLocalView::ClearUp()
       
  1259 	{
       
  1260 	iSortOrder.Close();
       
  1261 	}
       
  1262 
       
  1263 
       
  1264 
       
  1265 //
       
  1266 // COomRemoteView
       
  1267 //
       
  1268 
       
  1269 void COomRemoteView::HandleContactViewEvent(const CContactViewBase& /*aView*/,const TContactViewEvent& /*aEvent*/)
       
  1270 	{
       
  1271 	CActiveScheduler::Stop();
       
  1272 	}	
       
  1273 
       
  1274 void COomRemoteView::PreFailL()
       
  1275 	{
       
  1276 	iSortOrder.AppendL(KUidContactFieldGivenName);
       
  1277 	iSortOrder.AppendL(KUidContactFieldFamilyName);
       
  1278 	iSortOrder.AppendL(KUidContactFieldCompanyName);
       
  1279 	}
       
  1280 
       
  1281 void COomRemoteView::FailL()
       
  1282 	{
       
  1283 	TInt32 viewPrefs=0;
       
  1284 	viewPrefs|=EIgnoreUnSorted;
       
  1285 	if(iSortPluginName.Length() == 0)
       
  1286 		{
       
  1287 		iRemoteView=CContactRemoteView::NewL(*this,*iDb,iSortOrder,TContactViewPreferences(viewPrefs));
       
  1288 		}
       
  1289 	else
       
  1290 		{
       
  1291 		iRemoteView=CContactRemoteView::NewL(*this,*iDb,iSortOrder,TContactViewPreferences(viewPrefs),iSortPluginName);
       
  1292 		}
       
  1293 	CActiveScheduler::Start();
       
  1294 	iOomTest->Conductor().iTest(iRemoteView->Close(*this));
       
  1295 	ClearEventQueueL();
       
  1296 	}
       
  1297 
       
  1298 void COomRemoteView::ClearUp()
       
  1299 	{
       
  1300 	iSortOrder.Close();
       
  1301 	}
       
  1302 
       
  1303 //
       
  1304 // COomSubView
       
  1305 //
       
  1306 void COomSubView::HandleContactViewEvent(const CContactViewBase& /*aView*/, const TContactViewEvent& /*aEvent*/)
       
  1307 	{	
       
  1308 	CActiveScheduler::Stop();
       
  1309 	}	
       
  1310 
       
  1311 void COomSubView::PreFailL()
       
  1312 	{
       
  1313 	}
       
  1314 
       
  1315 void COomSubView::FailL()
       
  1316 	{
       
  1317 	iSubViewAbc=CContactSubView::NewL(*this,*iDb,*iUnderlyingView,_L(">=a"),_L("<d"));
       
  1318 	CActiveScheduler::Start();
       
  1319 	iSubViewAbc->Close(*this);
       
  1320 	ClearEventQueueL();
       
  1321 	}
       
  1322 
       
  1323 TBool COomSubView::Skip(TInt /*aCount*/, TOomFailureModes /*aMode*/) const
       
  1324 	{
       
  1325 	return EFalse;
       
  1326 	}
       
  1327 
       
  1328 void COomSubView::ClearUp()
       
  1329 	{}
       
  1330 
       
  1331 // COomFilteredView
       
  1332 //
       
  1333 void COomFilteredView::HandleContactViewEvent(const CContactViewBase& /*aView*/,const TContactViewEvent& /*aEvent*/)
       
  1334 	{
       
  1335 	CActiveScheduler::Stop();
       
  1336 	}	
       
  1337 
       
  1338 void COomFilteredView::PreFailL()
       
  1339 	{
       
  1340 	}
       
  1341 
       
  1342 void COomFilteredView::FailL()
       
  1343 	{
       
  1344 	TInt filter=0;
       
  1345 	filter|=CContactDatabase::EPhonable;
       
  1346 	iPhonableFilterView=CContactFilteredView::NewL(*this,*iDb,*iUnderlyingView,filter);
       
  1347 	CActiveScheduler::Start();
       
  1348 	iPhonableFilterView->Close(*this);
       
  1349 	ClearEventQueueL();
       
  1350 	}
       
  1351 
       
  1352 void COomFilteredView::ClearUp()
       
  1353 	{}
       
  1354 
       
  1355 // COomGroupView
       
  1356 //
       
  1357 
       
  1358 void COomGroupView::HandleContactViewEvent(const CContactViewBase& /*aView*/,const TContactViewEvent& /*aEvent*/)
       
  1359 	{
       
  1360 	if(iAsStarted)
       
  1361 		{
       
  1362 		CActiveScheduler::Stop();
       
  1363 		iAsStarted=EFalse;
       
  1364 		}
       
  1365 	}
       
  1366 
       
  1367 void COomGroupView::PreFailL()
       
  1368 	{
       
  1369 	}
       
  1370 
       
  1371 void COomGroupView::FailL()
       
  1372 	{
       
  1373 	iGroupView=CContactGroupView::NewL(*iDb,*iUnderlyingView,*this,iGroupOne->Id(),CContactGroupView::EShowContactsInGroup);
       
  1374 	iAsStarted=ETrue;
       
  1375 	CActiveScheduler::Start();
       
  1376 	iGroupView->Close(*this);
       
  1377 	ClearEventQueueL();
       
  1378 	}
       
  1379 
       
  1380 void COomGroupView::ClearUp()
       
  1381 	{
       
  1382 	if(iAsStarted)
       
  1383 		{
       
  1384 		CActiveScheduler::Stop();
       
  1385 		iAsStarted=EFalse;
       
  1386 		}
       
  1387 	}
       
  1388 
       
  1389 TBool COomGroupView::Skip(TInt aCount, TOomFailureModes aMode) const
       
  1390 	{
       
  1391 	if(aMode==KOomFailNormal)return aCount == 5;
       
  1392 	return EFalse;
       
  1393 	}
       
  1394 
       
  1395 
       
  1396 void COomMatchingCriteria::CleanupContactArray(TAny* aArray)	
       
  1397 	{
       
  1398 	RPointerArray<CViewContact>* array=REINTERPRET_CAST(RPointerArray<CViewContact>*,aArray);
       
  1399 	if (array)
       
  1400 		array->ResetAndDestroy();
       
  1401 	array->Close();
       
  1402 	}
       
  1403 
       
  1404 void COomMatchingCriteria::FailL()
       
  1405 	{
       
  1406 	_LIT(KFindString1,"C");
       
  1407 	CPtrCArray* array =new(ELeave)CPtrC16Array(1);
       
  1408 	CleanupStack::PushL(array);
       
  1409 	array->AppendL(KFindString1());
       
  1410 	
       
  1411 	RPointerArray<CViewContact> contactArray;
       
  1412 	CleanupStack::PushL(TCleanupItem(COomMatchingCriteria::CleanupContactArray,&contactArray));
       
  1413 
       
  1414 	iUnderlyingView->ContactsMatchingCriteriaL(*array, contactArray);
       
  1415 	
       
  1416 	CleanupStack::PopAndDestroy(2);
       
  1417 	}
       
  1418 
       
  1419 void COomMatchingCriteria::HandleContactViewEvent(const CContactViewBase& /*aView*/,const TContactViewEvent& /*aEvent*/)
       
  1420 	{
       
  1421 	CActiveScheduler::Stop();
       
  1422 	}
       
  1423 
       
  1424 
       
  1425 
       
  1426 //
       
  1427 // Main.
       
  1428 //
       
  1429 
       
  1430 GLDEF_C TInt E32Main()
       
  1431 	{
       
  1432 	__UHEAP_MARK;
       
  1433 	RProcess().SetPriority(EPriorityBackground);
       
  1434 	CActiveScheduler* scheduler=new CActiveScheduler;
       
  1435 	if (scheduler)
       
  1436 		{
       
  1437 		CActiveScheduler::Install(scheduler);
       
  1438 		CTrapCleanup* cleanup=CTrapCleanup::New();
       
  1439 		if (cleanup)
       
  1440 			{
       
  1441 			CTestConductor* tester=NULL;
       
  1442 			TRAPD(err,tester=CTestConductor::NewL());
       
  1443 			__ASSERT_ALWAYS(err==KErrNone,User::Invariant());
       
  1444 			delete tester;
       
  1445 			delete cleanup;
       
  1446 			}
       
  1447 		delete scheduler;
       
  1448 		}
       
  1449 	__UHEAP_MARKEND;
       
  1450 	return KErrNone;
       
  1451     }