示例#1
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;
	}
示例#2
0
LOCAL_C void AddFindRecordsL(CContactDatabase* aDb)
	{
	CContactItem* systemTemplate=ReadContactIncHiddenFieldsLC(aDb,aDb->TemplateId());
	for (TInt ii=0;ii<KTotalFindRecords;ii++)
		{
		CContactItem* item=CContactCard::NewLC(systemTemplate);
		TBuf<16> name;
		if (ii%2)
			{
			name.Format(_L("Bates %d"),ii);
			SetNameL(*item,KUidContactFieldJobTitle,name,EFalse);
   			//SetNameL(*item,KUidContactFieldFamilyName,name,EFalse);
   			SetNameL(*item,KUidContactFieldGivenName,_L("Norman"),EFalse);
			}
		else
			{
			name.Format(_L("Sod %d"),ii);
   			SetNameL(*item,KUidContactFieldFamilyName,name,EFalse);
   			SetNameL(*item,KUidContactFieldGivenName,_L("Silly"),EFalse);
			}
		if (ii%3)
			{
			CContactItemField* field=CContactItemField::NewLC(KStorageTypeDateTime,KUidContactFieldBirthday);
			field->DateTimeStorage()->SetTime(TDateTime(1990+ii,(TMonth)(ii%12),(ii*3)%28,1,2,3,4));
			item->AddFieldL(*field);
			CleanupStack::Pop(); // field
			}
		aDb->AddNewContactL(*item);
		CleanupStack::PopAndDestroy(); // item
		}
	CleanupStack::PopAndDestroy(); // systemTemplate
	}
示例#3
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));
	}
示例#4
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);
	}
示例#5
0
/**
@SYMTestCaseID PIM-AGENT-0002 
@SYMDEF DEF098709
@SYMTestType UT
@SYMTestPriority High
@SYMTestCaseDesc Check if Agent cards are merged with main contacts in database.

@SYMTestActions
1.Create contact items and add contact agents to them.
2.Export Main contact items.
3.Change properties of Agent contact items in database.
4.Import the exported vCard.

@SYMTestExpectedResults For the above tests:
1.vCard being imported should properly update the existing contact/Agent items
2.Updated contacts should be restored with old values.
3.No leaves or panics should occur
*/	
void CAgentTest::ImportAgentForMergeL()
	{
	iDb = iTest.CreateDatabaseL();
	//Adding 4 contacts (A,B,C,D)to database
	AddContactItemsL(4);
	//Make A an agent of B 
	MakeAgentL((*iIdArray)[1], (*iIdArray)[0]);

	//make C an Agent of D
	MakeAgentL((*iIdArray)[3], (*iIdArray)[2]);
	
	//storing Id's of agents A and C and removing them from array of Ids to be exported.
	TContactItemId idAgentA = (*iIdArray)[0];
	iIdArray->Remove(0);
	TContactItemId idAgentC = (*iIdArray)[1];
	iIdArray->Remove(1);

	//export Maincontacts B & D.
	ExportContactsL(KAgentTemp);
	
	_LIT(Kfn,"NewName");
	CContactItem* agentItem = NULL;

	//change familyname property of Agent contact A
	TBuf<20> agentAText;
	agentItem = iDb->OpenContactL(idAgentA);
	CleanupStack::PushL(agentItem);
	//storing name to cross check after import
	agentAText.Append(FieldText(*agentItem, KUidContactFieldFamilyName));
	TUid aid = {0};
	SetNameL(*agentItem, KUidContactFieldFamilyName, aid, Kfn, 0);
	iDb->CommitContactL(*agentItem);
	CleanupStack::PopAndDestroy();
	
	//change familyname property of Agent contact C
	TBuf<20> agentCText;
	agentItem = iDb->OpenContactL(idAgentC);
	CleanupStack::PushL(agentItem);
	//storing name to cross check after import
	agentCText.Append(FieldText(*agentItem, KUidContactFieldFamilyName));
	SetNameL(*agentItem, KUidContactFieldFamilyName, aid, Kfn, 0);
	iDb->CommitContactL(*agentItem);
	CleanupStack::PopAndDestroy();

	//All four contacts exist in database, 2 main and 2 agents so iIdArray will have only 2 Ids.
	ImportContactsL(KAgentTemp);
	
	//now check that names should have been restored to what it was before export
	agentItem = iDb->ReadContactLC(idAgentA);
	test(FieldText(*agentItem, KUidContactFieldFamilyName) == agentAText);
	CleanupStack::PopAndDestroy();

	agentItem = iDb->ReadContactLC(idAgentC);
	test(FieldText(*agentItem, KUidContactFieldFamilyName) == agentCText);
	CleanupStack::PopAndDestroy();	
	}
示例#6
0
GLDEF_C TContactItemId AddContactWithAddressL(const TDesC& aName, const TDesC& anAddress)
	{
	CContactItem* item=CContactCard::NewLC();
	item->SetTemplateRefId(KGoldenTemplateId);
	SetNameL(*item,KUidContactFieldGivenName,KUidContactFieldVCardMapUnusedN,aName,ETrue);	
	SetNameL(*item,KUidContactFieldAddress,  KUidContactFieldVCardMapUnusedN,anAddress,ETrue);	
	TContactItemId id=CntTest->Db()->AddNewContactL(*item);
	CleanupStack::PopAndDestroy(item); 
	return id;
	}
示例#7
0
LOCAL_C TContactItemId CreateFaxSMSContactL(const TDesC& aFirstName, const TDesC& aFamilyName, const TDesC& aFaxNo, const TDesC& aSMSNo)
{
    CContactItem* item=CContactCard::NewLC();
    SetNameL(*item,KUidContactFieldGivenName,KUidContactFieldVCardMapUnusedN,aFirstName,ETrue);
    SetNameL(*item,KUidContactFieldFamilyName,KUidContactFieldVCardMapUnusedN,aFamilyName,ETrue);
    SetNameL(*item,KUidContactFieldFax,KUidContactFieldVCardMapFAX,aFaxNo,ETrue);
    SetNameL(*item,KUidContactFieldSms,KUidContactFieldVCardMapTEL,aSMSNo,ETrue);
    item->SetTemplateRefId(KGoldenTemplateId);
    TContactItemId id=CntTest->Db()->AddNewContactL(*item);
    CleanupStack::PopAndDestroy(item);
    return id;
}
示例#8
0
LOCAL_C TContactItemId CreateContactL(const TDesC& aFirstName, const TDesC& aFamilyName, const TDesC& aPhoneNo, const TDesC& aMobileNo)
{
    test.Printf(_L("\tCreating contact %S %S, phone: %S mobile: %S\n"), &aFirstName, &aFamilyName, &aPhoneNo, &aMobileNo);
    CContactItem* item=CContactCard::NewLC();
    SetNameL(*item,KUidContactFieldGivenName,KUidContactFieldVCardMapUnusedN,aFirstName,ETrue);
    SetNameL(*item,KUidContactFieldFamilyName,KUidContactFieldVCardMapUnusedN,aFamilyName,ETrue);
    SetNameL(*item,KUidContactFieldPhoneNumber,KUidContactFieldVCardMapTEL,aPhoneNo,ETrue);
    SetNameL(*item,KUidContactFieldPhoneNumber,KUidContactFieldVCardMapCELL,aMobileNo,ETrue);
    item->SetTemplateRefId(KGoldenTemplateId);
    TContactItemId id=CntTest->Db()->AddNewContactL(*item);
    CleanupStack::PopAndDestroy(item);
    return id;
}
示例#9
0
LOCAL_C TContactItemId AddFindRecordL(const TDesC &aFirstName, const TDesC &aLastName, const TDesC &aCompanyName, const TDesC &aAddress)
	{
	CContactItem *item=CContactCard::NewLC();
	if (aFirstName.Length()>0)
		SetNameL(*item,KUidContactFieldGivenName,KUidContactFieldVCardMapUnusedN,aFirstName,ETrue);
	if (aLastName.Length()>0)
		SetNameL(*item,KUidContactFieldFamilyName,KUidContactFieldVCardMapUnusedN,aLastName,ETrue);
	if (aCompanyName.Length()>0)
		SetNameL(*item,KUidContactFieldCompanyName,KUidContactFieldVCardMapORG,aCompanyName,ETrue);
	if (aAddress.Length()>0)
		SetNameL(*item,KUidContactFieldAddress,KUidContactFieldVCardMapADR,aAddress,ETrue);
	TContactItemId id=CntTest->Db()->AddNewContactL(*item);
	CleanupStack::PopAndDestroy();	// item
	return(id);
	}
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;
	}
// ---------------------------------------------------------------------------
// CFriendlyNameAppUi::HandleCommandL(TInt aCommand)
// Takes care of command handling.
// ---------------------------------------------------------------------------
//
void CFriendlyNameAppUi::HandleCommandL(TInt aCommand)
    {
    switch (aCommand)
        {
        case EAknSoftkeyExit:
        case EEikCmdExit:
            {
            Exit();
            break;
            }
            
        case EFriendlyNameCmdChangeName:
            {
            THostName name(iAppContainer->CurrentName());
            CAknTextQueryDialog* dialog = 
                CAknTextQueryDialog::NewL(name);
            if (dialog->ExecuteLD(R_FRIENDLYNAME_DEVICE_NAME_QUERY)) 
                {
                SetNameL(name);
                }
            break;
            }
            
        default:
            break;      
        }
    }
示例#12
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();
	}
示例#13
0
LOCAL_C void TestSystemTemplateRestorationL()
	{
//	Any field values present in the template are stripped out when the template is
//	added to the database.  However, it is still possible to store default values in
//	a template if the template is first added, and then updated with default data present.

	CContactDatabase* db=CntTest->OpenDatabaseL();
	
	// create a new contact template
	CContactItem* contactTemplate=db->CreateContactCardTemplateLC(_L("fieldDataNotRestoredTemplate"));
	TContactItemId id=contactTemplate->Id();
	CleanupStack::PopAndDestroy(contactTemplate);
	// add some data to one of the template fields
	CContactTemplate *openTemplate=(CContactTemplate *)db->OpenContactLX(id);
	CleanupStack::PushL(openTemplate);
	CContactItemFieldSet& fieldSet=openTemplate->CardFields();
	TInt pos=fieldSet.Find(KUidContactFieldGivenName);
	test(fieldSet[pos].TextStorage()->Text() == KNullDesC);
	TBuf<12> givenName = _L("a given name");
	SetNameL(*openTemplate,KUidContactFieldGivenName,givenName,EFalse);
	// check the field value is set
	CContactItemFieldSet& fieldSet2=openTemplate->CardFields();
	pos=fieldSet2.Find(KUidContactFieldGivenName);
	test(fieldSet2[pos].TextStorage()->Text() == givenName);
	db->CommitContactL(*openTemplate);
	CleanupStack::PopAndDestroy(2); // openTemplate, openTemplate.Close()
	// the field value should still be set
	CContactItem* contactTemplate2=db->ReadContactLC(id);
	CContactItemFieldSet& fieldSet3=contactTemplate2->CardFields();
	pos=fieldSet3.Find(KUidContactFieldGivenName);
	test(fieldSet3[pos].TextStorage()->Text() == givenName);
	CleanupStack::PopAndDestroy(contactTemplate2);

	CntTest->CloseDatabase();
	}
示例#14
0
/** 
 * Test an unsuccessful addition to the database
 * @param aDb Contact database
 */
void TestUnsuccessfulAddL(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(KErrAccessDenied);
	TRAPD(error, aDb.AddNewContactL(*entry)); 	
	test(error==KErrAccessDenied);
	test(syncChecker->ValidateMethodCallCountL() == 1);
	CleanupStack::PopAndDestroy(entry);
	}
示例#15
0
/** 
 * Create example ICC Entry 
 * @param aDb Contact database
 */
TContactItemId CreateTestICCEntryL(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);

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

	TContactItemId id = aDb.AddNewContactL(*entry); 

	CleanupStack::PopAndDestroy(entry);	
	test(id!=KNullContactId);
	return id;
	}
示例#16
0
/** Populate the database */
LOCAL_C void PopulateDatabaseL(TInt aNumberToPopulate)
{
    for (TInt i=0; i<aNumberToPopulate; i++)
    {
        CContactItem* item=CContactCard::NewLC();
        TBuf<20> name;
        name.Format(KCntContactName,i);
        SetNameL(*item,KUidContactFieldGivenName,name);
        CntTest->Db()->AddNewContactL(*item);
        CleanupStack::PopAndDestroy(item);
    }
    CntTest->Db()->CompactL();
}
// ---------------------------------------------------------
// RFavouritesSrvTable::WriteItemDataL
// ---------------------------------------------------------
//
void RFavouritesSrvTable::WriteItemDataL( const CFavouritesItemImpl& aItem )
{
    // Fill standard attributes.
    __ASSERT_DEBUG( !ReadOnly(), FavouritesPanic( EFavouritesInternal ) );
    // Uid is *NOT* set. We update the current row.
    SetParentFolderL( aItem.ParentFolder() );
    SetTypeL( aItem.Type() );
    SetNameL( aItem.Name() );
    SetUrlL( aItem.Url() );
    SetUsernameL( aItem.UserName() );
    SetPasswordL( aItem.Password() );
    SetWapApL( aItem.WapAp() );
    // Note: read-only flag is *NOT* set. Setting that is accessible via
    // SetReadOnlyL.
    // Note: factory item flag is *NOT* set. Setting that is accessible via
    // SetFactoryItemL.
    SetContextIdL( aItem.ContextId() );
    // Note: last modification time is *NOT* set; PutL will do it.
    // Manual setting (override) is accessible via SetModifiedL.
    SetHiddenL( aItem.IsHidden() );
}
示例#18
0
LOCAL_C void AddNewContactsL()
//
// Add 20 new contacts 
//
	{

	for (TInt ii=0;ii<20;ii++)
		{
		CContactCard* card=CContactCard::NewL();
		CleanupStack::PushL(card);
		TBuf<16> name;
		name.Format(_L("NAME #%d"),ii);
		SetNameL(*card,KUidContactFieldVCardMapUnusedN,name);
		CContactItemField* field=CContactItemField::NewLC(KStorageTypeText,KUidContactFieldPhoneNumber);
		field->SetMapping(KUidContactFieldVCardMapTEL);
		field->TextStorage()->SetTextL(_L("123"));
		card->AddFieldL(*field);
		CleanupStack::Pop(); // field
		CntTest->Db()->AddNewContactL(*card);
		CleanupStack::PopAndDestroy(); // card
		}
	
	}	
示例#19
0
LOCAL_C void ExportImportTestL()
	{
	CDirectFileStore *store=CDirectFileStore::ReplaceLC(CntTest->Fs(),_L("c:\\ttVersitout"),EFileWrite);
  	store->SetTypeL(KDirectFileStoreLayoutUid);
	RStoreWriteStream outStream;
	TStreamId streamId=outStream.CreateLC(*store);
//
	CContactDatabase* db=CntTest->Db();
	CContactIdArray *idList=CContactIdArray::NewLC();
	CContactCard *card=CContactCard::NewLC();
	SetNameL(*card,KUidContactFieldNote,KUidContactFieldVCardMapNOTE,_L("ABCDE"),EFalse);
	SetNameL(*card,KUidContactFieldEMail,KUidContactFieldVCardMapEMAILINTERNET,_L("One"),EFalse);
	idList->AddL(db->AddNewContactL(*card));
//zzz hits a Versit bug
//	SetNameL(*card,KUidContactFieldFax,KUidContactFieldVCardMapFAX,_L("ZYX"),EFalse);
	SetNameL(*card,KUidContactFieldFax,KUidContactFieldVCardMapTEL,_L("ZYX"),EFalse);
	SetNameL(*card,KUidContactFieldEMail,KUidContactFieldVCardMapEMAILINTERNET,_L("Two"),EFalse);
	idList->AddL(db->AddNewContactL(*card));
	SetNameL(*card,KUidContactFieldSms,KUidContactFieldVCardMapTEL,_L("QQQQ"),EFalse);
	SetNameL(*card,KUidContactFieldEMail,KUidContactFieldVCardMapEMAILINTERNET,_L("Three"),EFalse);
	idList->AddL(db->AddNewContactL(*card));
	CleanupStack::PopAndDestroy();	// card
//
   	db->ExportSelectedContactsL(TUid::Uid(KUidVCardConvDefaultImpl),*idList,outStream,CContactDatabase::ETTFormat);
	TInt targetCount=db->CountL();
	for(TInt loop3=0;loop3<idList->Count();loop3++)
		{
		CContactItem *delFieldContact=db->OpenContactLX((*idList)[loop3]);
		CleanupStack::PushL(delFieldContact);
		delFieldContact->CardFields().Remove(0);
		db->CommitContactL(*delFieldContact);
		CleanupStack::PopAndDestroy(2);	// OpenContact, delFieldContact
		}
	CleanupStack::PopAndDestroy();	// idList
	outStream.CommitL();
	store->SetRootL(streamId);
	store->CommitL();  	
	CleanupStack::PopAndDestroy();	// outStream
//
	RStoreReadStream inStream;
	inStream.OpenLC(*store,streamId);
	TBool success=EFalse;
	CArrayPtr<CContactItem>* importedContacts=db->ImportContactsL(TUid::Uid(KUidVCardConvDefaultImpl),inStream,success,CContactDatabase::ETTFormat);
	CleanupStack::PushL(importedContacts);
	test(success);
	test(importedContacts->Count()==3);
	test(targetCount==db->CountL());
//
	const CContactIdArray *sortList=db->SortedItemsL();
	for(TInt loop2=0;loop2<sortList->Count();loop2++)
		{
		CContactItem *contact=db->ReadContactLC((*sortList)[loop2]);
		TPtrC fieldTxt=FieldText(*contact,KUidContactFieldGivenName);
		if (fieldTxt==_L("One"))
			test(FieldText(*contact,KUidContactFieldNote)==_L("ABCDE"));
		else if (fieldTxt==_L("Two"))
			test(FieldText(*contact,KUidContactFieldFax)==_L("ZYX"));
		else if (fieldTxt==_L("Three"))
			test(FieldText(*contact,KUidContactFieldPhoneNumber)==_L("QQQQ"));
		CleanupStack::PopAndDestroy();	// contact
		}
//
	for(TInt loop=0;loop<importedContacts->Count();loop++)
		db->DeleteContactL((*importedContacts)[loop]->Id());
	importedContacts->ResetAndDestroy();
	CleanupStack::PopAndDestroy(2);	// importedContacts, inStream
//
	CleanupStack::PopAndDestroy();	// store
	}
void CTestImpExvCardSuiteStepBase::ExportItemL(TBuf<80> aPath, TBool aAddBDay)
	{
	OpenDBL();
	
	TContactItemId itemId;
	RFs fsSession;
	RFileWriteStream fileStream;

	CContactIdArray* idArray = NULL;
	CContactCard* contactAdded = NULL;
	TTime now;
	
	User::LeaveIfError(fsSession.Connect());
	CleanupClosePushL(fsSession);
	
	idArray = CContactIdArray::NewL();

	CleanupStack::PushL(idArray);   // idArray

	fsSession.MkDirAll(aPath);
	User::LeaveIfError(fileStream.Replace(fsSession, aPath, EFileWrite));

	contactAdded = CContactCard::NewL();

	CleanupStack::PushL(contactAdded);   // contactAdded
	
	contactAdded->IncAccessCount();
	
	// ADD BDAY
	if (aAddBDay)
		{
		CContactItemFieldSet& fieldSet=contactAdded->CardFields();
		const TInt pos=fieldSet.Find(KUidContactFieldBirthday);
	
		if (pos!=KErrNotFound)
			{
			fieldSet[pos].DateTimeStorage()->SetTime(iBDayLocal);
			}
		else
			{
			CContactItemField* field=CContactItemField::NewLC(KStorageTypeDateTime,KUidContactFieldBirthday);
   			field->SetMapping(KUidContactFieldVCardMapBDAY);
			field->DateTimeStorage()->SetTime(iBDayLocal);
			contactAdded->AddFieldL(*field);
	
			CleanupStack::Pop(); // field
			}
		}
	
	SetNameL(*contactAdded, KUidContactFieldGivenName, _L("toby"), ETrue);
	SetNameL(*contactAdded, KUidContactFieldPhoneNumber, _L("6041233214"), ETrue);

	User::After(3000000);

	// There is no need to call SetLastModifed because
	// That function will be call by ExportSelectedContactsL below
	now.UniversalTime();
	iRecordedTime = now;
	
	INFO_PRINTF1(_L("Adding contact to Database....."));
	itemId = iDb->AddNewContactL(*contactAdded);
	INFO_PRINTF1(_L("Contact Added to Database"));
	CleanupStack::PopAndDestroy(contactAdded);  // contactAdded
	contactAdded = NULL;

	idArray->InsertL(0, itemId);

	INFO_PRINTF1(_L("Exporting Contact....."));
	iDb->ExportSelectedContactsL(TUid::Uid(KUidVCardConvDefaultImpl), *idArray, fileStream, CContactVCardConverter::EDefault, ETrue);
	INFO_PRINTF1(_L("Exported Contact"));
	fileStream.CommitL();
	fileStream.Close();
	
	CleanupStack::PopAndDestroy(idArray);  // idArray
	fsSession.Close();
	CleanupStack::PopAndDestroy();  // fsSession
	CloseDB();
	}
示例#21
0
LOCAL_C void PopulateDatabaseL(TInt aNumberToPopulate)
//
// Create and populate the database
//
{
    CContactItem* templ = CntTest->Db()->ReadContactL(0);
    CleanupStack::PushL(templ);

    for (TInt ii=0; ii<aNumberToPopulate; ii++)
    {
        CContactItem* item=CContactCard::NewLC(templ);
        TBuf<20> name;
        name.Format(KTestName,ii);
        SetNameL(*item,KUidContactFieldGivenName,name,EFalse);
        TBuf<20> number;
        switch(ii%3)
        {
        case 0:
            number.Format(_L("0171-%03d %04d"),(ii*9)%1000,((ii+11)*23)%10000);
            break;
        case 1:
            number.Format(_L("%04d:%04d:%04d:%04d"),(ii*123)%10000,(ii*666)%10000,(ii*234)%10000);
            break;
        case 2:
            number.Format(_L("+00%d-%03d %04d"),(ii*123)%100,(ii*13)%1000,((ii+13)*17)%10000);
            break;
        }
        SetNameL(*item,KUidContactFieldPhoneNumber,_L("11111"),EFalse);
        if (!(ii%2))
        {
            number.Format(_L("0181-%03d %04d"),(ii*8)%1000,((ii+11)*22)%10000);
            SetNameL(*item,KUidContactFieldPhoneNumber,_L("111"),EFalse);
            number.Format(_L("01734-%06d"),(ii*123456)%1000000);
            SetNameL(*item,KUidContactFieldPhoneNumber,_L("1111"),EFalse);
            CContactItemFieldSet& itemFields = item->CardFields();
            for (TInt ii=0; ii<itemFields.Count(); ii++)
            {
                CContactItemField& field = (itemFields)[ii];
                if (!itemFields[ii].Storage()->IsFull() && itemFields[ii].StorageType()==KStorageTypeText &&
                        field.ContentType().ContainsFieldType(KUidContactFieldPhoneNumber))
                    itemFields[ii].TextStorage()->SetTextL(_L("111111"));
            }
        }
        TBuf<32> address;
        address.Format(KTestAddress,ii);
        SetNameL(*item,KUidContactFieldAddress,address,EFalse);
//
        TBuf<32> familyName;
        familyName.Format(KTestFamilyName,ii);
        SetNameL(*item,KUidContactFieldFamilyName,familyName,EFalse);
//
        TBuf<32> email;
        email.Format(KTestEmail,ii);
        SetNameL(*item,KUidContactFieldEMail,email,EFalse);
//
        TBuf<32> country;
        country.Format(KTestCountry,ii);
        SetNameL(*item,KUidContactFieldCountry,country,EFalse);
//
        TBuf<32> company;
        company.Format(KTestCompany,ii);
        SetNameL(*item,KUidContactFieldCompanyName,company,EFalse);
//
        CntTest->Db()->AddNewContactL(*item);
        CleanupStack::PopAndDestroy(item);

        test.Printf(_L("."));	// Just to show some life
    }
    CleanupStack::PopAndDestroy(templ);
    CntTest->Db()->CompactL();
}
示例#22
0
LOCAL_C void PopulateDatabaseL(TInt aNumberToPopulate, TBool aPhoneNumbers)
//
// Create and populate the database
//
	{
	TTime before;
	before.UniversalTime();
	CContactItem* templ = CntTest->Db()->ReadContactL(0);
	CleanupStack::PushL(templ);
	for (TInt ii=0;ii<aNumberToPopulate;ii++)
		{
		CContactItem* item=CContactCard::NewLC(templ);
		TBuf<16> name;
		name.Format(KTestName,ii);
   		SetNameL(*item,KUidContactFieldGivenName,name);
		if (aPhoneNumbers)
			{
			TBuf<20> number;
			switch(ii%3)
				{
				case 0:
					number.Format(_L("0171-%03d %04d"),(ii*9)%1000,((ii+11)*23)%10000);
					break;
				case 1:
					number.Format(_L("%04d:%04d:%04d:%04d"),(ii*123)%10000,(ii*666)%10000,(ii*234)%10000);
					break;
				case 2:
					number.Format(_L("+00%d-%03d %04d"),(ii*123)%100,(ii*13)%1000,((ii+13)*17)%10000);
					break;
				}
   			SetNameL(*item,KUidContactFieldPhoneNumber,number);
			if (!(ii%2))
				{
				number.Format(_L("0181-%03d %04d"),(ii*8)%1000,((ii+11)*22)%10000);
	   			SetNameL(*item,KUidContactFieldPhoneNumber,number);
				number.Format(_L("01734-%06d"),(ii*123456)%1000000);
	   			SetNameL(*item,KUidContactFieldPhoneNumber,number);
				}
			}
		TBuf<32> address;
		address.Format(KTestAddress,ii);
		SetNameL(*item,KUidContactFieldAddress,address);
//
		TBuf<32> familyName;
		familyName.Format(KTestFamilyName,ii);
		SetNameL(*item,KUidContactFieldFamilyName,familyName);
//
		TBuf<32> email;
		email.Format(KTestEmail,ii);
		SetNameL(*item,KUidContactFieldEMail,email);
//
		TBuf<32> country;
		country.Format(KTestCountry,ii);
		SetNameL(*item,KUidContactFieldCountry,country);
//	
		TBuf<32> company;
		company.Format(KTestCompany,ii);
		SetNameL(*item,KUidContactFieldCompanyName,company);
//	
		CntTest->Db()->AddNewContactL(*item); //templ
		CleanupStack::PopAndDestroy(); // item
//	
		if (ii%100==0)
			{
			test.Printf(_L("."));	// Just to show some life
			CntTest->Db()->CompactL();
			}

		}
	CleanupStack::PopAndDestroy();
	CntTest->Db()->SetDateFormatTextL(_L("%E%D%X%N%Y %1 %2 %3"));
	CntTest->Db()->CompactL();
	TTime after;
	after.UniversalTime();
	TTimeIntervalSeconds secondsTaken;
	after.SecondsFrom(before,secondsTaken);
	test.Printf(_L(" TIME: %d  Secs"),secondsTaken.Int());
	test.Printf(_L("\n"));	
	//test.Getch();
	}