void AssignSpeedDialL( TInt aContact, TInt aSpeedDialID, CContactDatabase& database )
	{
	CContactItem* item = NULL;
	item = database.OpenContactL( aContact );
	
	CleanupStack::PushL( item );

	if ( ContactIsASpeedDial( *item ) )
		{
		g_test.Printf( _L("Contact is a speed dial !!! \n") );
		}
	else
		{
		g_test.Printf( _L("Contact is NOT A SPEED DIAL \n") );
		}

	CContactItemFieldSet &fieldSet = item->CardFields();
    for(TInt index = fieldSet.Count() - 1; index > 0; --index)
        {
        if(fieldSet[index].StorageType() == KStorageTypeText)
            {
            //set the last text field from the fieldset as speeddial field.
        	database.SetFieldAsSpeedDialL(*item, index, aSpeedDialID );
            break;
            }
        }
        
	g_test.Next( _L("Contact changed to speed dial") );
	g_test(ContactIsASpeedDial( *item ));

	CleanupStack::PopAndDestroy( item );
	}
/**
 * Create an entry based on the template for this specific phonebook, and add
 * the entry to the contact database
 * @param aDb Contact database
 * @param aPhonebookUid The phonebook uid
 * @return TContactItemId Id of the newly created icc entry
 */
TContactItemId doAddIccEntryL(CContactDatabase& aDb,TUid aPhonebookUid)
	{
	syncChecker->ResetMethodCallCountsL();
	TContactItemId templateId = aDb.ICCTemplateIdL(aPhonebookUid);
	test(syncChecker->ValidateMethodCallCountL() == 1);
	CContactItem* iccTemplate = aDb.ReadContactLC(templateId);
	CContactICCEntry* entry = CContactICCEntry::NewL(*iccTemplate);
	CleanupStack::PopAndDestroy(iccTemplate);
	CleanupStack::PushL(entry);
	// Add to the database
	CheckPhonebookField(*entry,aPhonebookUid, EFalse);
	syncChecker->ResetMethodCallCountsL();
	TContactItemId id = aDb.AddNewContactL(*entry); 
	test(syncChecker->ValidateMethodCallCountL() == 3);
	CleanupStack::PopAndDestroy(entry);
	test(id!=KNullContactId);
	// Check group membership
	syncChecker->ResetMethodCallCountsL();
	CContactICCEntry* fetchedItem = static_cast<CContactICCEntry*>(aDb.ReadContactL(id));
	test(syncChecker->ValidateMethodCallCountL() == 1);
	CleanupStack::PushL(fetchedItem);	
	const CContactIdArray* owned = fetchedItem->GroupsJoined();
	test(owned!=NULL && owned->Count() == 1);
	test((*owned)[0]==syncChecker->GroupIdL(aPhonebookUid));
	test(fetchedItem->Type() == KUidContactICCEntry);
	// Verify that the phonebook field has been set
	CheckPhonebookField(*fetchedItem,aPhonebookUid, ETrue);
	CleanupStack::PopAndDestroy(fetchedItem);	

	return id;
	}
Example #3
0
/**
@SYMTestCaseID PIM-T-TEMPL-INC100029-0001
@SYMTestType UT
@SYMTestPriority Critical
@SYMDEF INC100029
@SYMTestCaseDesc Tests that if an attempt is made to commit the System template
with a field which contains data that the commit leaves with KErrNotSupported.

@SYMTestActions
1. Open the System template.
2. Add data to the field KUidContactFieldGivenName.
3. Commit the System template.
4. Check that step 3 leaves with error KErrNotSupported.
   
@SYMTestExpectedResults As per Test Action 4.
*/
LOCAL_C void TestTemplateFieldModificationL()
	{
	test.Next( _L("@SYMTestCaseID:PIM-T-TEMPL-INC100029-0001 Validate template field modification") );

	CContactDatabase* db = CntTest->OpenDatabaseL();

	//
	// 1. Open the System template.
	//
	CContactTemplate* contactTemplate = static_cast<CContactTemplate*>( db->OpenContactLX( db->TemplateId() ) );
	CleanupStack::PushL( contactTemplate );
	
	//
	// 2. Add data to the field KUidContactFieldGivenName.
	//
	SetNameL(*contactTemplate, KUidContactFieldGivenName, _L("Invalid"), EFalse );

	//
	// 3. Commit the System template.
	//
	TRAPD( err, db->CommitContactL( *contactTemplate ) );

	//
	// 4. Check that step 3 leaves with error KErrNotSupported.
	//
	test( err == KErrNotSupported );
	
	CleanupStack::PopAndDestroy(2); // contactTemplate and lock.
	CntTest->CloseDatabase();
	}
Example #4
0
void CAsyncTest::TestResultL()
	{
	CContactDatabase* db = iOpenOp->TakeDatabase();
	if(db == NULL)
		User::Leave(KErrNotFound);
	

	// Test adding a contact
	CContactItemViewDef* matchAll = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields,CContactItemViewDef::EIncludeHiddenFields);
	matchAll->AddL(KUidContactFieldMatchAll);
	CContactItem* cntTemplate = db->ReadContactL(0, *matchAll);
	CleanupStack::PopAndDestroy(matchAll);
	CleanupStack::PushL(cntTemplate);

	CCntItemBuilder* cntItemBldr = CCntItemBuilder::NewLC(static_cast<CContactTemplate&>(*cntTemplate));
	CContactItem* tempCntItem = cntItemBldr->GetCntItemLC();
	db->AddNewContactL(*tempCntItem);

	CleanupStack::PopAndDestroy(tempCntItem);
	CleanupStack::PopAndDestroy(cntItemBldr);
	CleanupStack::PopAndDestroy(cntTemplate);
	delete iOpenOp;
	delete db;
	iOpenOp = NULL;
	db 		= NULL;
	
	iTest->Next(_L("Read data from Database\n"));
	
	}
Example #5
0
/**
 * Creates a new, nondamaged DB.
 */
void CTestResources::ConstructL(TBool aDamaged)
    {
    if (aDamaged)
        {
        // Create an empty DB...
        CContactDatabase* db = CContactDatabase::ReplaceL(KTestDbName);
        CleanupStack::PushL(db);
        // Damage the DB...
        db->DamageDatabaseL(0x666);
        // Close the DB.
        CleanupStack::PopAndDestroy(db);
        // Open the damaged database. CContactDatabase::OpenL() does recovery
        // by calling RecoverL().
		iDb = CContactDatabase::OpenL(KTestDbName);
        }
    else
        {
        // Just create an empty DB
        iDb = CContactDatabase::ReplaceL(KTestDbName);
        }

    iViewEventQueue = CContactViewEventQueue::NewL();

    iViewSortOrder.AppendL(KUidContactFieldFamilyName);
    iViewSortOrder.AppendL(KUidContactFieldGivenName);
    iViewSortOrder.AppendL(KUidContactFieldCompanyName);
    
    iLocalView = CContactLocalView::NewL
        (*iViewEventQueue, *iDb, iViewSortOrder, EContactsOnly);
    }
//===============================================================================================
// SEARCHING entries
//===============================================================================================
void TestFindLC(CContactDatabase& aDb, TContactItemId aIccId, TContactItemId aNonIccId)
	{
	test.Next(_L("Test FindLC"));
	// Successful find of icc entry
	CContactItemFieldDef* fieldDef=new(ELeave) CContactItemFieldDef;
	CleanupStack::PushL(fieldDef);
	fieldDef->AppendL(KUidContactFieldFamilyName);
	syncChecker->ResetMethodCallCountsL();
	CContactIdArray* array = aDb.FindLC(KIccName,fieldDef);
	test(syncChecker->ValidateMethodCallCountL() == 1);
	test(array!=NULL);
	test(array->Count() == 1);
	test((*array)[0]==aIccId);
	CleanupStack::PopAndDestroy(array);
	array=NULL;

	test.Next(_L("Test searching when ICC locked"));
	// Unsuccessful find of icc entry because icc locked
	syncChecker->SetValidateResponseL(MContactSynchroniser::ESearch,KErrLocked);
	syncChecker->ResetMethodCallCountsL();
	TRAPD(err,array = aDb.FindLC(KIccName,fieldDef));
	test(syncChecker->ValidateMethodCallCountL() == 1);
	test(err==KErrLocked);
	test(array==NULL);

	// successful find of non-icc entry, even though icc locked
	syncChecker->ResetMethodCallCountsL();
	array = aDb.FindLC(KNonIccName,fieldDef);
	test(syncChecker->ValidateMethodCallCountL() == 0);
	test(array!=NULL);
	test(array->Count() == 1);
	test((*array)[0]==aNonIccId);
	CleanupStack::PopAndDestroy(2,fieldDef); // array, fieldDef
	}
void TestOneL()
	{
	g_test.Start(_L("@SYMTestCaseID:PIM-T-SPEEDDIALTEST-0001 Create Database with Speed Dials then Delete and Create database"));

	TestDatabaseWithSpeedDialsL();

	g_test.Next(_L("Delete database"));
	CContactDatabase::DeleteDatabaseL(KDbFileName);
	
	g_test.Next( _L("open database should fail"));
	CContactDatabase* database = NULL;

	TRAPD(openError, database =  CContactDatabase::OpenL(KDbFileName));
	g_test(openError == KErrNotFound && database == NULL);
	

	g_test.Next( _L("create replacement database"));
	database =  CContactDatabase::CreateL(KDbFileName);
	CleanupStack::PushL(database);

	CreateContactsL(*database);

	CContactItem* item = database->ReadContactL(KSpeedDialContact);
	CleanupStack::PushL(item);
	
	g_test.Next( _L("Check that Speed dial is forgotten"));
	g_test(item->Id() == KSpeedDialContact);
	// retored item should not be a SpeedDial
	g_test(!ContactIsASpeedDial( *item ));

	CleanupStack::PopAndDestroy(item);
	CleanupStack::PopAndDestroy(database);

	g_test.End();
	}
void CContactsRamTest::AddContactsL(const TInt aNumber)
/**
Add number of contacts to db, using the system template.
@return None
@param aNumber number of contacts to be added
@pre None
@post database now contains aNumber of empty contacts
*/
	{
	

	//viewdef that loads all fields 	
	CContactItemViewDef *viewAll = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields,CContactItemViewDef::EIncludeHiddenFields);
	viewAll->AddL(KUidContactFieldMatchAll);
	CContactTemplate *ttemplate = static_cast< CContactTemplate* >(
	iContactsDatabase->ReadContactLC( iContactsDatabase->TemplateId(), *viewAll ) );

	CContactCard* contact = CContactCard::NewLC(ttemplate);
	SetManyFieldsL(KFieldValue, KManyFields, contact->CardFields());
	for(TInt k = 0; k<aNumber; k++)
		{		
		iContactsDatabase->AddNewContactL(*contact);
		}	
	CleanupStack::PopAndDestroy(contact);
	CleanupStack::PopAndDestroy(ttemplate);
	CleanupStack::PopAndDestroy(viewAll);
	}
/**
 * Set the phone number field of the contact with id aId to contain the number aNumber
 * @param aDb Contact database
 * @param aId Contact item id
 * @param aNumber A telephone number
 */
void SetPhoneNumberField(CContactDatabase& aDb,TContactItemId aId,const TDesC& aNumber)
	{
	syncChecker->ResetMethodCallCountsL();
	CContactItem* item = aDb.OpenContactLX(aId);
	CleanupStack::PushL(item);
	if (item->Type() == KUidContactICCEntry)
		{
		test(syncChecker->ValidateMethodCallCountL() == 2);
		}
	else
		{
		test(syncChecker->ValidateMethodCallCountL() == 0);
		}
	CContactItemFieldSet& fieldset = item->CardFields();
	TInt pos = fieldset.Find(KUidContactFieldPhoneNumber);
	test(pos!=KErrNotFound);
	
	CContactItemField& field = fieldset[pos];
	CContactTextField* textfield = field.TextStorage();
	textfield->SetTextL(aNumber);

	syncChecker->ResetMethodCallCountsL();
	aDb.CommitContactL(*item);
	if (item->Type() == KUidContactICCEntry)
		{
		test(syncChecker->ValidateMethodCallCountL() == 2);
		}
	else
		{
		test(syncChecker->ValidateMethodCallCountL() == 0);
		}
	CleanupStack::PopAndDestroy(2); // item, lock record
	}
Example #10
0
//Creates a contact item. Then adds it to the default contacts database.
LOCAL_D TLogContactItemId CreateContactL(const TDesC& aGivenName, 
									 const TDesC& aFamilyName, 
									 const TDesC& aPhoneNumber)
	{
	CContactItem* item=CContactCard::NewLC();

	if (aFamilyName.Length())
		SetNameL(*item, KUidContactFieldFamilyName, aFamilyName, ETrue);

	if (aGivenName.Length())
		SetNameL(*item, KUidContactFieldGivenName, aGivenName, ETrue);

	if (aPhoneNumber.Length())
		SetNameL(*item, KUidContactFieldPhoneNumber, aPhoneNumber, ETrue);

	CContactItemFieldSet& fieldSet= item->CardFields();

	TLogContactItemId id = KLogNullContactId;
	
	if (fieldSet.Count())
		{
		// Open the DB for writing
		CContactDatabase* TheContacts = CContactDatabase::OpenL();
		CleanupStack::PushL(TheContacts);
		id = TheContacts->AddNewContactL(*item);
		CleanupStack::PopAndDestroy(); // TheContacts,
		}
	else
		User::Leave(KErrNotSupported);
	CleanupStack::PopAndDestroy(item);
	return id;
	}
void TestReadContactL(CContactDatabase& aDb, TContactItemId aIccId, TContactItemId aNonIccId)
	{
	test.Next(_L("Test ReadContactL"));
	// Successful read of icc entry
	syncChecker->SetValidateResponseL(MContactSynchroniser::ERead,KErrNone);
	syncChecker->ResetMethodCallCountsL();
	test(syncChecker->ValidateMethodCallCountL() == 0);	
	CContactItem* item=aDb.ReadContactLC(aIccId);
	test(syncChecker->ValidateMethodCallCountL() == 1);
	test(item!=NULL);
	CleanupStack::PopAndDestroy(item);
	item=NULL;

	// Unsuccessful read of icc entry because icc locked
	syncChecker->SetValidateResponseL(MContactSynchroniser::ERead,KErrAccessDenied);
	syncChecker->ResetMethodCallCountsL();
	test(syncChecker->ValidateMethodCallCountL() == 0);
	TRAPD(err,item=aDb.ReadContactL(aIccId));
	test(item==NULL);
	test(err==KErrAccessDenied);
	test(syncChecker->ValidateMethodCallCountL() == 1);
	
	// successful read of non-icc entry, even though icc locked
	syncChecker->ResetMethodCallCountsL();
	test(syncChecker->ValidateMethodCallCountL() == 0);	
	item=aDb.ReadContactLC(aNonIccId);
	test(syncChecker->ValidateMethodCallCountL() == 0);
	test(item!=NULL);
	CleanupStack::PopAndDestroy(item);
	item=NULL;
	}
/**
 * Create a new template and add it to the database
 * @param aDb Contact database
 * @param aTemplateName Name for the template
 * @param aFieldSet Array of fields which should are added to the template
 * @return TContactItemId Id of the newly created template
 */
TContactItemId CreatePhonebookTemplateL(CContactDatabase& aDb, const TDesC& aTemplateName, RArray<TFieldEntry>& aFieldSet)
	{
	CContactItem* temp = aDb.CreateContactCardTemplateLC(aTemplateName);
	TContactItemId templateId = temp->Id();
	CleanupStack::PopAndDestroy(temp);
	temp=NULL;

	//Remove all the unnecessary fields
	temp = aDb.OpenContactLX(templateId);
	CleanupStack::PushL(temp);	
	const TInt fieldCount = temp->CardFields().Count();
	for(TInt i=fieldCount-1;i>=0;i--)
		temp->RemoveField(i);

	// Add each of the required fields to the template
	for (TInt j=0; j<aFieldSet.Count(); ++j)
		{
		TFieldEntry fieldEntry=aFieldSet[j];

		CContactItemField* field = CContactItemField::NewLC(KStorageTypeText,fieldEntry.iField);
		if (fieldEntry.iFieldType!=KNullUid)
			field->AddFieldTypeL(fieldEntry.iFieldType);
		temp->AddFieldL(*field);
		CleanupStack::Pop(field);
		}

	aDb.CommitContactL(*temp);
	CleanupStack::PopAndDestroy(2); // temp, close template
	
	return templateId;
	}
void CntThumbnailCreator::initializeThumbnailFieldL()
{
    // Assume the golden template is not changed run-time and fetch it only
    // when initializeThumbnailFieldL is called for the first time during the
    // life-time of the CntThumbnailCreator object (requires the instance to
    // live longer than one thumbnail create operation to be effective,
    // otherwise we would end up opening contact database and reading the
    // system template every time a thumbnail is stored for a contact).
    if(!m_thumbnailFieldFromTemplate) {
        CContactDatabase *contactDatabase = CContactDatabase::OpenL();
        CleanupStack::PushL(contactDatabase);
        CContactItem *goldenTemplate = contactDatabase->ReadContactLC(KGoldenTemplateId);
        const CContactItemFieldSet& cardFields = goldenTemplate->CardFields();

        // Check if thumbnail field type is KUidContactFieldPictureValue
        TInt pictureFieldIndex = cardFields.Find(KUidContactFieldPicture, KUidContactFieldVCardMapPHOTO);

        // Check if thumbnail field type is KUidContactFieldVCardMapJPEG
        if(pictureFieldIndex == KErrNotFound) {
            pictureFieldIndex = cardFields.Find(KUidContactFieldVCardMapJPEG, KUidContactFieldVCardMapPHOTO);
        }

        if(pictureFieldIndex == KErrNotFound) {
            // Either KUidContactFieldPictureValue or KUidContactFieldVCardMapJPEG
            // thumbnail field types should be in the template
            User::Leave(KErrNotFound);
        }

        m_thumbnailFieldFromTemplate = CContactItemField::NewL(cardFields[pictureFieldIndex]);
        CleanupStack::PopAndDestroy(goldenTemplate);
        CleanupStack::PopAndDestroy(contactDatabase);
    }
}
void TestReadTextDefinitionL(CContactDatabase& aDb, TContactItemId aIccId, TContactItemId aNonIccId)
	{
	test.Next(_L("Test ReadTextDefinitionL"));
	// Successful read of icc entry
	CContactTextDef* textDef=CContactTextDef::NewLC();
	textDef->AppendL(TContactTextDefItem(KUidContactFieldFamilyName));
	TBuf<64> result;
	syncChecker->SetValidateResponseL(MContactSynchroniser::ERead,KErrNone);
	syncChecker->ResetMethodCallCountsL();
	aDb.ReadContactTextDefL(aIccId,result,textDef);
	test(syncChecker->ValidateMethodCallCountL() == 1);
	test(result==KIccName);
	result.Zero();

	// Unsuccessful read of icc entry because icc locked
	syncChecker->SetValidateResponseL(MContactSynchroniser::ERead,KErrAccessDenied);
	syncChecker->ResetMethodCallCountsL();
	TRAPD(err, aDb.ReadContactTextDefL(aIccId,result,textDef));
	test(err==KErrAccessDenied);
	test(result.Length() == 0);
	test(syncChecker->ValidateMethodCallCountL() == 1);

	// successful read of non-icc entry, even though icc locked
	syncChecker->ResetMethodCallCountsL();
	TRAP(err, aDb.ReadContactTextDefL(aNonIccId,result,textDef));
	test(err==KErrNone);
	test(result==KNonIccName);
	test(syncChecker->ValidateMethodCallCountL() == 0);
	CleanupStack::PopAndDestroy(textDef);
	}
/**
 * To return a valid contact item id.
 */
TContactItemId CSyncTestStep::GetValidUIDFromContactsDbL()
	{
	TContactItemId firstId(KNullContactId);

	CContactDatabase *iDb = NULL;
	TRAPD(err,iDb = CContactDatabase::OpenL()); // open existing database
	CleanupStack::PushL(iDb);
	if (err != KErrNone)
		{
		CleanupStack::PopAndDestroy(); // iDb
		return firstId;
		}

	iDb->SetDbViewContactType(KUidContactICCEntry);    
    
	// to get the unique groupId for the phonebook
	TContactItemId groupId(KNullContactId);
	User::LeaveIfError(iSession.GetPhoneBookId(groupId, RPhoneBookSession::ESyncGroupId));
	TESTCHECKCONDITIONL(groupId != KNullContactId);
  
	// based on the groupId, get an item belonging to the phonebook
	CContactGroup* group = static_cast<CContactGroup*>(iDb->ReadContactLC(groupId));
	const CContactIdArray* array = group->ItemsContained();
	TInt count(array->Count());
	if (count > 0)
		firstId = (*array)[0];

	CleanupStack::PopAndDestroy(group);	
	CleanupStack::PopAndDestroy(); // iDb
	return firstId;
	}
Example #16
0
/** 
 * Test addition to database without adding to a group
 * @param aDb Contact database
 */
void TestAddingWithoutGroupL(CContactDatabase& aDb)
	{
	TContactItemId templateId = aDb.ICCTemplateIdL(KUidIccGlobalAdnPhonebook);
	CContactItem* iccTemplate = aDb.ReadContactLC(templateId);
	CContactICCEntry* entry = CContactICCEntry::NewL(*iccTemplate);
	CleanupStack::PopAndDestroy(iccTemplate);
	CleanupStack::PushL(entry);
	SetNameL(*entry,KUidContactFieldFamilyName,KUidContactFieldVCardMapUnusedN,KGivenName,EFalse);
	SetNameL(*entry,KUidContactFieldPhoneNumber,KUidContactFieldVCardMapTEL,KTelephoneNum,EFalse);

	syncChecker->ResetMethodCallCountsL();
	syncChecker->SetValidateWriteResponseL(KErrNone);
	TInt oldGroupId = syncChecker->GroupIdL(KUidIccGlobalAdnPhonebook);
	test(KErrNone == syncChecker->UpdatePhonebookGroupIdL(KUidIccGlobalAdnPhonebook, KNullContactId));
	TContactItemId id = aDb.AddNewContactL(*entry); 	
	test(syncChecker->ValidateMethodCallCountL() == 3);
	CleanupStack::PopAndDestroy(entry);

	CContactICCEntry* fetchedItem = static_cast<CContactICCEntry*>(aDb.ReadContactL(id));
	CleanupStack::PushL(fetchedItem);
	//Check group membership	
	const CContactIdArray* owned = fetchedItem->GroupsJoined();
	test(owned==NULL || owned->Count() == 0);
	CleanupStack::PopAndDestroy(fetchedItem);
		
	test(KErrNone == syncChecker->UpdatePhonebookGroupIdL(KUidIccGlobalAdnPhonebook, oldGroupId));
	}
/**
 * Verify that the synchroniser is called when deleting an icc entry, and that the 
 * deletion of an icc entry fails if the icc is locked.
 * @param aDb Contact database
 */
void TestDeleteL(CContactDatabase& aDb)
	{
	test.Next(_L("Test delete when ICC locked"));
	syncChecker->SetDeleteContactResponseL(KErrLocked);
	TContactItemId iccId=AddIccEntryL(aDb,KUidIccGlobalAdnPhonebook);
	syncChecker->ResetMethodCallCountsL();
	TRAPD(err,aDb.DeleteContactL(iccId));
	test(err==KErrLocked);
	test(syncChecker->ValidateMethodCallCountL() == 2);
	syncChecker->ResetMethodCallCountsL();
	CContactItem* item=aDb.ReadContactLC(iccId);
	test(syncChecker->ValidateMethodCallCountL() == 1);
	test(item!=NULL);
	CleanupStack::PopAndDestroy(item);
	item=NULL;

	test.Next(_L("Test successful delete of non-icc entry when ICC locked"));
	TContactItemId nonIccId=AddContactCardL(aDb);
	syncChecker->ResetMethodCallCountsL();
	TRAP(err,aDb.DeleteContactL(nonIccId));
	test(err==KErrNone);
	test(syncChecker->ValidateMethodCallCountL() == 0);

	test.Next(_L("Test successful delete"));
	syncChecker->SetDeleteContactResponseL(KErrNone);
	syncChecker->ResetMethodCallCountsL();
	TRAP(err,aDb.DeleteContactL(iccId));
	test(syncChecker->ValidateMethodCallCountL() == 2);
	test(err==KErrNone);
	syncChecker->ResetMethodCallCountsL();
	TRAP(err,aDb.ReadContactLC(iccId));
	test(syncChecker->ValidateMethodCallCountL() == 0);
	test(err==KErrNotFound);
	}
Example #18
0
/** 
 * Test successful addition to database.
 * @param aDb Contact database
 */
void TestSuccessfulAddL(CContactDatabase& aDb)
	{
	//Create group 
	TContactItemId groupId = CreatePhonebookGroupL(aDb);
	test(KErrNone == syncChecker->UpdatePhonebookGroupIdL(KUidIccGlobalAdnPhonebook, groupId));
	//Create item and add fields
	TContactItemId templateId = aDb.ICCTemplateIdL(KUidIccGlobalAdnPhonebook);
	CContactItem* iccTemplate = aDb.ReadContactLC(templateId);
	CContactICCEntry* entry = CContactICCEntry::NewL(*iccTemplate);
	CleanupStack::PopAndDestroy(iccTemplate);
	CleanupStack::PushL(entry);
	SetNameL(*entry,KUidContactFieldFamilyName,KUidContactFieldVCardMapUnusedN,KGivenName,EFalse);
	SetNameL(*entry,KUidContactFieldPhoneNumber,KUidContactFieldVCardMapTEL,KTelephoneNum,EFalse);

	//Add to database
	syncChecker->ResetMethodCallCountsL();
	syncChecker->SetValidateWriteResponseL(KErrNone);
	syncChecker->SetValidateResponseL(MContactSynchroniser::ERead,KErrNone);

	test(syncChecker->ValidateMethodCallCountL() == 0);
	TContactItemId id = aDb.AddNewContactL(*entry); 
	CleanupStack::PopAndDestroy(entry);	
	test(syncChecker->ValidateMethodCallCountL() == 3);
	test(id!=KNullContactId);

	CContactICCEntry* fetchedItem = static_cast<CContactICCEntry*>(aDb.ReadContactL(id));
	CleanupStack::PushL(fetchedItem);
	//Check group membership	
	const CContactIdArray* owned = fetchedItem->GroupsJoined();
	test(owned!=NULL && owned->Count() == 1);
	test((*owned)[0]==groupId);
	
	//Check number of fields and content
	
	CContactItemFieldSet& fieldset = fetchedItem->CardFields();
	TInt pos = fieldset.Find(KUidContactFieldTemplateLabel);
	test(pos==KErrNotFound);
	
//	test(fieldset.Count() == 3); 
	
/*	for (TInt i=0; i<fieldset.Count(); i++)
		{
		CContactItemField& field = fieldset[i];
		TInt count = field.ContentType().FieldTypeCount();
		for (TInt j=0; j<count; j++)
			{
			TFieldType ft= field.ContentType().FieldType(j);
			}


		TUid mapping = field.ContentType().Mapping();
		}
*/	
	CheckFieldContentL(fieldset,KUidContactFieldFamilyName,KGivenName);
//	CheckFieldContentL(fieldset,KUidContactFieldPhoneNumber,KTelephoneNum);

	CleanupStack::PopAndDestroy(fetchedItem);
	}
Example #19
0
LOCAL_D void TestFirstL(RTest& aTest)
    {
    aTest.Next(_L("@SYMTestCaseID:PIM-T-OWNCARDDELETE-0001 -- First Owncard Test --"));

    aTest.Printf(_L("Replacing database \n"));
    CContactDatabase* db = CContactDatabase::ReplaceL(KDatabaseFileName);
    CleanupStack::PushL(db); 
    
    CContactDatabase* dbAnother = CContactDatabase::OpenL(KDatabaseFileName);
    CleanupStack::PushL(dbAnother);
        
    PopulateDatabaseL(db, KTotalContacts);        
    WaitForNotificationsL(db);        
                    
    TestSetOwnCardL(db);                
    WaitForNotificationsL(db);        
    
    aTest.Printf(_L("Checking the count value \n"));
    TInt count = dbAnother->CountL();    
    aTest.Printf(_L("Count: %d \n"), count);
    aTest(count == KTotalContacts, __LINE__);
      
    aTest.Printf(_L("Checking the id \n"));    
    TContactItemId id = dbAnother->OwnCardId();    
    aTest.Printf(_L("id: %d \n"), id);
    aTest(id != KNullContactId, __LINE__);
    
    TContactIter iter(*db); //Test that the iterator is updated
    TContactItemId firstContactId;
    firstContactId = iter.FirstL(); //should be own contactId
    
    DeleteOwnContactL(dbAnother);
    WaitForNotificationsL(dbAnother);
    
    TContactItemId secondContactId;
    TRAPD (err,  secondContactId = iter.FirstL());
    aTest(err == KErrNone && firstContactId != secondContactId, __LINE__);
    
    
    DeleteMultipleContactsL(db);    
    WaitForNotificationsL(db); 
    
    aTest.Printf(_L("Checking the deleted count value \n"));
    count = dbAnother->CountL();    
    aTest.Printf(_L("Count: %d \n"), count);
    aTest(count == 0, __LINE__);
      
    aTest.Printf(_L("Checking the deleted id \n"));    
    id = dbAnother->OwnCardId();    
    aTest.Printf(_L("id: %d \n"), id);
    aTest(id == KNullContactId, __LINE__);     
    
    aTest(gEventCounter == KMaxNumOfEvents, __LINE__);
    aTest(gUnknownEventCounter == KMaxUnknownEvents, __LINE__);                             
    
    CleanupStack::PopAndDestroy(2,db);    
    } 
void TestFindInTextDefLC(CContactDatabase& aDb, TContactItemId aIccId, TContactItemId aNonIccId)
	{
	test.Next(_L("Test FindInTextDefLC"));
	// Successful find of icc entry
	syncChecker->SetValidateResponseL(MContactSynchroniser::ESearch,KErrNone);
	syncChecker->SetValidateResponseL(MContactSynchroniser::ERead,KErrNone);

	TCallBack callBack(findWordSplitterL);
	CContactTextDef* textDef=CContactTextDef::NewLC();
	textDef->AppendL(TContactTextDefItem(KUidContactFieldFamilyName));
	CDesCArray* desArray = new(ELeave) CDesCArrayFlat(5);
	desArray->AppendL(_L("icc"));
	syncChecker->ResetMethodCallCountsL();
	CContactIdArray* array = aDb.FindInTextDefLC(*desArray,textDef,callBack);
	//test(syncChecker->ValidateMethodCallCountL() == 3);
	test(array!=NULL);
	test(array->Count() == 1);
	test((*array)[0]==aIccId);
	CleanupStack::PopAndDestroy(array);
	array=NULL;

	test.Next(_L("Test searching when ICC locked"));
	// Unsuccessful find of icc entry because icc locked
	syncChecker->SetValidateResponseL(MContactSynchroniser::ESearch,KErrLocked);
	syncChecker->ResetMethodCallCountsL();
	TRAPD(err,array = aDb.FindInTextDefLC(*desArray,textDef,callBack));
	test(syncChecker->ValidateMethodCallCountL() == 1);
	test(err==KErrLocked);
	test(array==NULL);
	desArray->Delete(0);
	delete desArray;

	// successful find of non-icc entry, even though icc locked
	CDesCArray* desArray2 = new(ELeave) CDesCArrayFlat(5);
	desArray2->AppendL(_L("non-icc"));
	syncChecker->ResetMethodCallCountsL();
	array = aDb.FindInTextDefLC(*desArray2,textDef,callBack);
	test(syncChecker->ValidateMethodCallCountL() == 0);
	test(array!=NULL);
	test(array->Count() == 1);
	test((*array)[0]==aNonIccId);

	// both the icc and non-icc entry should match the search criteria, but only the
	// non-icc entry should be returned since icc is locked
	SetNameField(aDb,aIccId,KNonIccName);
	syncChecker->ResetMethodCallCountsL();
	TRAP(err,array = aDb.FindInTextDefLC(*desArray2,textDef,callBack));
	test(syncChecker->ValidateMethodCallCountL() == 1);
	test(err==KErrLocked);
	test(array!=NULL);
	test(array->Count() == 1);
	test((*array)[0]==aNonIccId);
	desArray2->Delete(0);
	delete desArray2;
	SetNameField(aDb,aIccId,KIccName);
	CleanupStack::PopAndDestroy(2,textDef); // array, textDef
	}
Example #21
0
void TestFourL()
	{
	g_test.Start(_L("Check that Settings are saved - killing ContactLockSrv"));
	
    g_test.Next(_L("Setting up..."));
	CLockServerTester* lockSrvTester = CLockServerTester::NewL();
	CleanupStack::PushL(lockSrvTester);
	CContactDatabase* database = SetupLC();
	
	g_test.Next( _L("Assign Speed Dial"));
	TInt error = KErrNone;
	TRAP(error, AssignSpeedDialL( KSpeedDialContact, KSpeedDialPositionOne, *database ) );
	g_test(error == KErrNone);
	
	g_test.Next( _L("Update Speed Dial"));
	error = KErrNone;
	TRAP(error, UpdateSpeedDialL( KSpeedDialContact, KSpeedDialPositionTwo, *database ) );
	g_test(error == KErrNone);
	
	g_test.Next( _L("Change Database Drive"));
	CContactDatabase::SetDatabaseDriveL(TDriveUnit(EDriveD),EFalse);
	
	CleanupStack::PopAndDestroy(database);
	
	// Kill ContactLockServer process
	g_test.Next( _L("Kill CntServer"));
	lockSrvTester->FindServerAndKillItL();
	CleanupStack::PopAndDestroy( lockSrvTester );

	g_test.Next( _L("Open Database"));
	database =  CContactDatabase::OpenL(KDbFileName);
	CleanupStack::PushL(database);
		
	TDriveUnit driveUnit;
	CContactDatabase::DatabaseDrive(driveUnit);
	g_test.Next( _L("Check that Database Drive is changed"));
	g_test(driveUnit==TDriveUnit(EDriveD));
	
	CContactItem* item = database->ReadContactL(KSpeedDialContact);
	CleanupStack::PushL(item);
	
	g_test.Next( _L("Check that Speed Dial is remembered"));
	g_test(item->Id() == KSpeedDialContact);
	// retored item should be a SpeedDial
	g_test(ContactIsASpeedDial( *item ));
	
	// reset Database Drive
	g_test.Next( _L("Reset Database Drive setting"));
	CContactDatabase::SetDatabaseDriveL(TDriveUnit(EDriveC),EFalse);

	CleanupStack::PopAndDestroy(item);
	CleanupStack::PopAndDestroy(database);
	
	g_test.End();		
	}
Example #22
0
/** Delete the surname field of the contact indicated by the index. Will Leave if the contact has no surname 
@leave	KErrNotFound	contact has no surname
@param		aDb		The contact database
@param		aIndex	The index of the contact whose surname will be removed
*/
LOCAL_C void TestDeleteNameL(CContactDatabase& aDb, TInt aIndex) 
	{
	CContactItem* item=aDb.OpenContactL(aIndex);
	CleanupStack::PushL(item);
	CContactItemFieldSet& fields=item->CardFields();
	TInt i = fields.Find(KUidContactFieldFamilyName);
	User::LeaveIfError(i);
	fields[i].TextStorage()->SetTextL(KNullDesC);
	aDb.CommitContactL(*item);
	CleanupStack::PopAndDestroy(item);
	}
Example #23
0
void TestThreeL()
	{
	g_test.Start(_L("Check that Settings are saved - normal shutdown"));
	
    g_test.Next(_L("Setting up..."));
	CContactDatabase* database = SetupLC();

	g_test.Next( _L("Assign Speed Dial"));
	TInt error = KErrNone;
	TRAP(error, AssignSpeedDialL( KSpeedDialContact, KSpeedDialPositionOne, *database ) );
	g_test(error == KErrNone);
	
	g_test.Next( _L("Update Speed Dial"));
	error = KErrNone;
	TRAP(error, UpdateSpeedDialL( KSpeedDialContact, KSpeedDialPositionTwo, *database ) );
	g_test(error == KErrNone);
	
	g_test.Next( _L("Change Database Drive"));
	CContactDatabase::SetDatabaseDriveL(TDriveUnit(EDriveD),EFalse);
	
	CleanupStack::PopAndDestroy( database );

	g_test.Next(_L("Wait for Contact Server to shutdown"));
	// wait until Contacts Lock Server shuts down
	// applicabale only in the case of transient server.
	User::After(6000000);
	
	g_test.Next( _L("Try to open Database again"));

	database =  CContactDatabase::OpenL(KDbFileName);
	CleanupStack::PushL(database);
		
	TDriveUnit driveUnit;
	CContactDatabase::DatabaseDrive(driveUnit);
	g_test.Next( _L("Check that Database Drive is changed"));
	g_test(driveUnit==TDriveUnit(EDriveD));
	
	CContactItem* item = database->ReadContactL(KSpeedDialContact);
	CleanupStack::PushL(item);
	
	g_test.Next( _L("Check that Speed Dial is remembered"));
	g_test(item->Id() == KSpeedDialContact);
	// retored item should be a SpeedDial
	g_test(ContactIsASpeedDial( *item ));
	
	// reset Database Drive
	g_test.Next( _L("Reset Database Drive setting"));
	CContactDatabase::SetDatabaseDriveL(TDriveUnit(EDriveC),EFalse);

	CleanupStack::PopAndDestroy(item);
	CleanupStack::PopAndDestroy(database);
	
	g_test.End();
	}
/**
 * Verify that the template id returned by CContactDatabase::ICCTemplateIdL is the
 * same as that returned directly from the plugin
 * @param aDb Contact database
 */
void VerifyPhonebookTemplateIdsL(CContactDatabase& aDb)
	{
	test.Next(_L("Verify template ids"));
	syncChecker->ResetMethodCallCountsL();
	test(aDb.ICCTemplateIdL() == syncChecker->ICCTemplateIdL(KUidIccGlobalAdnPhonebook));
	test(aDb.ICCTemplateIdL(KUidIccGlobalAdnPhonebook) == syncChecker->ICCTemplateIdL(KUidIccGlobalAdnPhonebook));
	test(aDb.ICCTemplateIdL(KUidIccGlobalSdnPhonebook) == syncChecker->ICCTemplateIdL(KUidIccGlobalSdnPhonebook));
	test(aDb.ICCTemplateIdL(KUidIccGlobalLndPhonebook) == syncChecker->ICCTemplateIdL(KUidIccGlobalLndPhonebook));
	test(aDb.ICCTemplateIdL(KUidUsimAppAdnPhonebook) == syncChecker->ICCTemplateIdL(KUidUsimAppAdnPhonebook));
	test(aDb.ICCTemplateIdL(KNullUid) == KNullContactId);
	test(syncChecker->ValidateMethodCallCountL() == 6);
	}
Example #25
0
GLDEF_C void DoSortL(CContactDatabase& aDb)
	{
	CContactTextDef* textDef=CContactTextDef::NewLC();
	textDef->AppendL(TContactTextDefItem(KUidContactFieldGivenName));
	textDef->AppendL(TContactTextDefItem(KUidContactFieldFamilyName));
	textDef->AppendL(TContactTextDefItem(KUidContactFieldCompanyName));
	aDb.SetTextDefinitionL(textDef); // Takes ownership.
	CleanupStack::Pop(); // textDef.
	CArrayFix<CContactDatabase::TSortPref>* sortOrder=new(ELeave)CArrayFixFlat<CContactDatabase::TSortPref>(2);
	CleanupStack::PushL(sortOrder);
	sortOrder->AppendL(CContactDatabase::TSortPref(KUidContactFieldDefinedText));
	aDb.SortL(sortOrder); // Takes ownership.
	CleanupStack::Pop(); // sortOrder
	}
/** 
 * Verify that adding contact cards doesn't call the synchroniser interface
 * @param aDb Contact database
 */
TContactItemId AddContactCardL(CContactDatabase& aDb)
	{
	_LIT(KTemplateName,"contact card template");
	RArray<TFieldEntry> entries=fieldSetForPhonebook(KUidIccGlobalAdnPhonebook);
	TContactItemId templateId=CreatePhonebookTemplateL(aDb,KTemplateName,entries);
	entries.Close();
	CContactItem* iccTemplate = aDb.ReadContactLC(templateId);
	CContactCard* card = CContactCard::NewLC(iccTemplate);
	syncChecker->ResetMethodCallCountsL();
	TContactItemId id=aDb.AddNewContactL(*card);
	test(syncChecker->ValidateMethodCallCountL() == 0);
	CleanupStack::PopAndDestroy(2,iccTemplate);
	return id;
	}
void CTestResources::CreateTestContactsL()
    {

    // Create a few test contacts in the db
	// - Creating 'prefix' results for 'an'
    CContactCard* card;
    CContactItemField* field;
    card = CContactCard::NewLC();
    field = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldGivenName);
    field->TextStorage()->SetTextL(_L("Annie"));
    card->AddFieldL(*field);
    CleanupStack::Pop(field);
    iDb->AddNewContactL(*card);
    CleanupStack::PopAndDestroy(card);

    card = CContactCard::NewLC();
    field = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldGivenName);
    field->TextStorage()->SetTextL(_L("Anne"));
    card->AddFieldL(*field);
    CleanupStack::Pop(field);
    iDb->AddNewContactL(*card);
    CleanupStack::PopAndDestroy(card);

    card = CContactCard::NewLC();
    field = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldGivenName);
    field->TextStorage()->SetTextL(_L("Andrew"));
    card->AddFieldL(*field);
    CleanupStack::Pop(field);
    iDb->AddNewContactL(*card);
    CleanupStack::PopAndDestroy(card);

	// - Creating 'fullsearch' results for 'an'
    card = CContactCard::NewLC();
    field = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldGivenName);
    field->TextStorage()->SetTextL(_L("Christan"));
    card->AddFieldL(*field);
    CleanupStack::Pop(field);
    iDb->AddNewContactL(*card);
    CleanupStack::PopAndDestroy(card);

    card = CContactCard::NewLC();
    field = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldGivenName);
    field->TextStorage()->SetTextL(_L("Adan"));
    card->AddFieldL(*field);
    CleanupStack::Pop(field);
    iDb->AddNewContactL(*card);
    CleanupStack::PopAndDestroy(card);

    }
Example #28
0
void TestDatabaseIterationL(CContactDatabase& aDb)
	{
	test.Next(_L("Test database iteration"));

	aDb.SetDbViewContactType(KUidContactICCEntry);
	TContactIter iterator(aDb);
	TContactItemId id = iterator.FirstL();
	while (id!=KNullContactId)
		{
		CContactItem* item = aDb.ReadContactLC(id);
		test(item->Type() == KUidContactICCEntry);
		CleanupStack::PopAndDestroy(item);
		id = iterator.NextL();
		}
	}
/**
 * Verify that the synchroniser is called when reading an icc entry
 * @param aDb Contact database
 */
void TestReadL(CContactDatabase& aDb)
	{
	TContactItemId iccId=AddIccEntryL(aDb,KUidIccGlobalAdnPhonebook);
	SetNameField(aDb,iccId,KIccName);
	TContactItemId nonIccId = AddContactCardL(aDb);
	SetNameField(aDb,nonIccId,KNonIccName);
	TestReadMinimalContactL(aDb,iccId,nonIccId);
	TestReadContactL(aDb,iccId,nonIccId);
	TestReadTextDefinitionL(aDb,iccId,nonIccId);
	syncChecker->SetValidateResponseL(MContactSynchroniser::ERead,KErrNone);
	syncChecker->ResetMethodCallCountsL();
	aDb.DeleteContactL(iccId);
	aDb.DeleteContactL(nonIccId);
	test(syncChecker->ValidateMethodCallCountL() == 2);
	}
EXPORT_C TContactItemId CTestUtils::CreateContactL(const TDesC& aGivenName, const TDesC& aFamilyName, const TDesC& aPhoneNumber, const TDesC& aEmailAddress, TBool aReplaceContactsDb)
	{
	CContactDatabase* db = NULL;

	if (aReplaceContactsDb)
		{
		db = CContactDatabase::ReplaceL();
		}
	else
		{
		TRAPD(err, db = CContactDatabase::OpenL());
		
		if (err == KErrNotFound)
			{
			TRAP(err, db = CContactDatabase::CreateL());
			}

		User::LeaveIfError(err);
		}

	CleanupStack::PushL(db);

	CContactItem* item=CContactCard::NewLC();

	if (aFamilyName.Length())
		SetNameL(*item, KUidContactFieldFamilyName, aFamilyName, ETrue);

	if (aGivenName.Length())
		SetNameL(*item, KUidContactFieldGivenName, aGivenName, ETrue);

	if (aPhoneNumber.Length())
		SetNameL(*item, KUidContactFieldPhoneNumber, aPhoneNumber, ETrue);

	if (aEmailAddress.Length())
		SetNameL(*item, KUidContactFieldEMail, aEmailAddress, ETrue);

	CContactItemFieldSet& fieldSet= item->CardFields();

	TContactItemId id = KNullContactId;
	
	if (fieldSet.Count())
		id = db->AddNewContactL(*item);
	else
		User::Leave(KErrNotSupported);

	CleanupStack::PopAndDestroy(2); // item, db
	return id;
	}