void CTestResources::CreateMoreTestContactsL()
	{
	CRandomContactGenerator* generator = CRandomContactGenerator::NewL();
	CleanupStack::PushL(generator);
	generator->SetDbL(*iDb);
	for (TInt i=0;i<KMaxNumContacts;i++)
		{
		generator->AddTypicalRandomContactL();
		if (i%100==0)
			{
			iDb->CompactL();
			test.Printf(_L("Added %d contacts\n"),i);
			}
		}
	CleanupStack::PopAndDestroy(generator);

	}
void CTestResources::ConstructL(TInt aNumberOfContactsToAddToExistingDatabase, TBool aCreateNewDatabase)
    {
	if (aCreateNewDatabase)
		iDb = CContactDatabase::ReplaceL(KTestDbName);
	else
		iDb = CContactDatabase::OpenL(KTestDbName);

	if(!iRandomGenerator)
		{
		iRandomGenerator=CRandomContactGenerator::NewL();
		}
	iRandomGenerator->SetDbL(*iDb);
		
	CreateContactsL(aNumberOfContactsToAddToExistingDatabase);

	// done adding everything to the database
	TCntProfile profile[1];

	CCntTest::ProfileReset(0,1);
	CCntTest::ProfileStart(0);
	iDb->CompactL();
	CCntTest::ProfileEnd(0);
	CCntTest::ProfileResult(&profile[0],0,1);
	TInt timeToCompact = profile[0].iTime/1000;
	
	CCntTest::ProfileReset(0,1);
	CCntTest::ProfileStart(0);
	delete iDb;
	iDb=NULL;
	CCntTest::ProfileEnd(0);
	CCntTest::ProfileResult(&profile[0],0,1);
	TInt timeToClose = profile[0].iTime; // in microseconds

	CCntTest::ProfileReset(0,1);
	CCntTest::ProfileStart(0);
	iDb = CContactDatabase::OpenL(KTestDbName);
	CCntTest::ProfileEnd(0);
	CCntTest::ProfileResult(&profile[0],0,1);

	iRandomGenerator->SetDbL(*iDb);
	TInt timeToOpen = profile[0].iTime/1000;
	TInt numberOfContactsInDb=iDb->CountL();
	

	iViewEventQueue = CContactViewEventQueue::NewL(NULL, numberOfContactsInDb*2);
	TInt i;
	for(i = 0; i< GNumberOfFieldsToSort; i++)
		{
		iViewSortOrder.AppendL(TUid::Uid(GFieldsToSort[i]));
		}
    
    iLocalView = CContactLocalView::NewL(*iViewEventQueue, *iDb, iViewSortOrder, EContactsOnly);

    // Wait 100 seconds for the view to get ready
    TContactViewEvent event;

	CCntTest::ProfileReset(0,1);
	CCntTest::ProfileStart(0);
	test(iViewEventQueue->ListenForEvent(100,event));
	CCntTest::ProfileEnd(0);
	CCntTest::ProfileResult(&profile[0],0,1);
	test(event.iEventType == TContactViewEvent::EReady);

	TBuf<128> result;

	result.Format(_L("*%C Contacts: %d\t"),static_cast<TUint>(GChar),numberOfContactsInDb);
	RDebug::Print(result);
	
	result.Format(_L("\tView ready: %d ms\t\tOpen: %d ms\t\tClose: %d us\t\tCompact: %d ms\t"),
		profile[0].iTime/1000, timeToOpen, timeToClose, timeToCompact);
	RDebug::Print(result);
	result.Format(_L("\tSize: %d bytes\n"),iDb->FileSize());
	RDebug::Print(result);
	
	iFindFields = new(ELeave)CContactItemFieldDef;
    }