Beispiel #1
0
void TestPhoneMatchingL(CContactDatabase& aDb)
	{
	test.Next(_L("Test phone match"));

	CContactIdArray* array = aDb.MatchPhoneNumberL(KTelephoneNum,KMaxPhoneMatchLength);	
	test(array->Count() == 4);
	delete array;

	syncChecker->SetValidateResponseL(MContactSynchroniser::ERead,KErrNone);
	syncChecker->SetValidateResponseL(MContactSynchroniser::EEdit, KErrNone);
	syncChecker->SetValidateWriteResponseL(KErrNone);
	aDb.SetDbViewContactType(KUidContactICCEntry);
	TContactItemId id = (*aDb.SortedItemsL())[0];
	CContactItem* item = aDb.OpenContactLX(id);
	CleanupStack::PushL(item);
	CContactItemFieldSet& fieldset = item->CardFields();
	const TInt pos = fieldset.Find(KUidContactFieldPhoneNumber);	
	CContactItemField& field = fieldset[pos];
	CContactTextField* textfield = field.TextStorage();
	textfield->SetTextL(KTelephoneNumModified);
	aDb.CommitContactL(*item);
	CleanupStack::PopAndDestroy(2); //item, lock record

	CContactIdArray* array2 = aDb.MatchPhoneNumberL(KTelephoneNumModified,KMaxPhoneMatchLength);	
	test(array2->Count() == 1);
	delete array2;
	}
Beispiel #2
0
LOCAL_C void DoTestsL()
    {
	test.Start(_L("@SYMTESTCaseID:PIM-T-DB-SORTL-TEST-0001 T_DB_SortL_test"));


	// create default, empty database
	CContactDatabase* db = CContactDatabase::ReplaceL(KDbName);
	CleanupStack::PushL(db);
	
	// create contact 1 and add it to the db
	CContactCard* contact1 = CContactCard::NewLC();
	CContactItemField* fname1 = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldGivenName);
	_LIT(KFname1, "Aaron");
	fname1->TextStorage()->SetTextL(KFname1() );
	contact1->AddFieldL(*fname1);
	CleanupStack::Pop(fname1);
	CContactItemField* lname1 = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldFamilyName);
	_LIT(KLname1, "Zimmerman");
	lname1->TextStorage()->SetTextL(KLname1() );
	contact1->AddFieldL(*lname1);
	CleanupStack::Pop(lname1);
	db->AddNewContactL(*contact1);
	
	// create contact 2 and add it to the db
	CContactCard* contact2 = CContactCard::NewLC();
	CContactItemField* fname2 = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldGivenName);
	_LIT(KFname2, "Zachary");
	fname2->TextStorage()->SetTextL(KFname2() );
	contact2->AddFieldL(*fname2);
	CleanupStack::Pop(fname2);
	CContactItemField* lname2 = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldFamilyName);
	_LIT(KLname2, "Abrahams");
	lname2->TextStorage()->SetTextL(KLname2() );
	contact2->AddFieldL(*lname2);
	CleanupStack::Pop(lname2);
	db->AddNewContactL(*contact2);

	// fetch and print contact IDs. Expected order: 1, 2
	const CContactIdArray* items = db->SortedItemsL(); // doesn't take ownership
	_LIT(KFormattedIdList1, "Contact IDs *before* sorting: %d, %d\n");
	test.Printf(KFormattedIdList1, (*items)[0], (*items)[1]);
	TInt item1BeforeSort = (*items)[0];
	TInt item2BeforeSort = (*items)[1];
	
	// create sort order array
	CArrayFix<CContactDatabase::TSortPref>* sortOrder = new (ELeave) CArrayFixFlat<CContactDatabase::TSortPref>(2);
	CleanupStack::PushL(sortOrder);
	sortOrder->AppendL(CContactDatabase::TSortPref(KUidContactFieldFamilyName) );
	sortOrder->AppendL(CContactDatabase::TSortPref(KUidContactFieldGivenName) );

	// sort db and measure differences in heap allocations as a proxy for 
	// whether sortOrder has been deleted by SortL() or not.
	TInt totalAllocSize(0);
	TInt heapCellsDifference = User::AllocSize(totalAllocSize);
	db->SortL(sortOrder);
	heapCellsDifference -= User::AllocSize(totalAllocSize);
	CleanupStack::Pop(sortOrder);
	
	// fetch and print contact IDs. Expected order: 2, 1
	items = db->SortedItemsL(); // doesn't take ownership
	_LIT(KFormattedIdList2, "Contact IDs *after* sorting:  %d, %d\n");
	test.Printf(KFormattedIdList2, (*items)[0], (*items)[1]);
	TInt item1AfterSort = (*items)[0];
	TInt item2AfterSort = (*items)[1];
	
	//check the sort order to make sure
	test(item1BeforeSort == item2AfterSort);
	test(item2BeforeSort == item1AfterSort);
	
	// check to see if sortOrder is still usable
	if (heapCellsDifference == 0)
		{
		// attempt to re-use sortOrder -- should be allowed after workaround
		CContactDatabase::TSortPref sortPref( (*sortOrder)[0]);
		_LIT(KSortOrderInfo, "The first sort order preference's field type is: %d.\n");
		test.Printf(KSortOrderInfo, sortPref.iFieldType);
		_LIT(KYesSame, "Yes, have successfully re-used sortOrder.\n");
		test.Printf(KYesSame);
		}
	else
		{
		// looks like sortOrder has been deleted so don't try to use it
		_LIT(KNoDifferent, "No, have not reused sortOrder as it has probably been deleted.\n");
		test.Printf(KNoDifferent);
		}
	
	// cleanup
	CleanupStack::PopAndDestroy(3, db);	// and contact1, contact2
	CContactDatabase::DeleteDatabaseL(KDbName);
	
    test.End();
    test.Close();
    }