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);
	}
TBool CPackagerCntComparator::DoCompareCContactItemViewDefArray(const CContactItemViewDef& anItemViewDefArray1, const CContactItemViewDef& anItemViewDefArray2) const
/** Compares two TUid arrays contained within their respective CContactItemViewDef parent.

@param anItemViewDefArray1 The first array to be compared.
@param anItemViewDefArray2 The second array to be compared.
@return ETrue if the two arrays are equal, EFalse otherwise. */
	{// Need to check for NULL  arrays first.
	if((!&anItemViewDefArray1) && (!&anItemViewDefArray2))
		{
		return ETrue;
		}

	if((!&anItemViewDefArray1) || (!&anItemViewDefArray2))
		{
		return EFalse;
		}
			
	// Check if arrays are same length to begin with.
	TInt maxCount = anItemViewDefArray1.Count();
	if(!DoCompareTInt(maxCount, anItemViewDefArray2.Count()))
		{
		return EFalse;
		}
		
	for(TInt i=0; i<maxCount; ++i)
		{
		if(!DoCompareTUid(anItemViewDefArray1[i], anItemViewDefArray2[i]))
			{
			return EFalse;
			}
		}
		
	return ETrue;
	}
Exemplo n.º 3
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"));
	
	}
/**
Utility method used to read text fields from blob and fill item field set,Provides a mechanism to restore a 
contact item field set from text blob field within contact database.
Blob informations are stored based on contact item field. At restore, a reference to a contact item field set
is provided. For every contact item field in the item field set, a text restore is made.

@param		aFieldSet Reference to CContactItemFieldSet. Item field set that has to be filled with informations from blob
@param		aHeaderStore Stream store containing the header informations
@param		aId Root id for the header stream store
@param		aValuesStore Read stream used to read text fields from text blob
@param		aViewDef View definition indicating which fields have to be read from blob
@param		aTemplate Template indicating if current field set should be filled based on a template
*/	
void TCntPersistenceUtility::RestoreTextL(CContactItemFieldSet& aFieldSet, CStreamStore& aHeaderStore, TStreamId aId, HBufC* textStream, const CContactItemViewDef& aViewDef, const CContactItem* aTemplate)
	{
	const TBool KIncludeFields = ( aViewDef.Use() == CContactItemViewDef::EIncludeFields );
	
	if (KIncludeFields && aViewDef.Count() == 0)
		{
		// If view definition does not contain any field we don't do anything (don't read from 
		// blob). We simply return from method without doing anything.
		// This is not an error condition
		return;	
		}
		
	RStoreReadStream stream;
	stream.OpenLC(aHeaderStore,aId);
	
	TCardinality fieldCount;
	stream>>fieldCount;
	
	TInt textFieldIndex=0;

	for (TInt ii = 0; ii < fieldCount; ++ii)
		{
		// Restore text for every CContactItemField in provided CContactItemFieldSet.
		CContactItemField* field = CContactItemField::NewLC();
		
		if(aTemplate)
		    {
    		field->RestoreFieldTypesL(stream, &(aTemplate->CardFields()));
		    }
		else
		    {
    		field->RestoreFieldTypesL(stream, NULL);
		    }    
		    
		ASSERT(field->StorageType() == KStorageTypeText);

		TBool fieldDefined = ETrue;
		if(!aViewDef.MatchesAll())
			{
			fieldDefined = (aViewDef.Find(field->ContentType()) != KErrNotFound);
			}

		if ((!((fieldDefined && KIncludeFields) || (!fieldDefined && !KIncludeFields))) || 
			(field->IsHidden() && aViewDef.Mode() == CContactItemViewDef::EMaskHiddenFields))
			{
    		CleanupStack::PopAndDestroy(field); 	
			}
		else
		    {
    		field->RestoreTextL(textStream, textFieldIndex);
			aFieldSet.AddL(*field);
    		CleanupStack::Pop(field); 	
		    }	
		    
        ++textFieldIndex;
		}
	CleanupStack::PopAndDestroy(&stream);	
	}
TBool CPackagerCntComparator::Compare(const CContactItemViewDef& anItem1, const CContactItemViewDef& anItem2) const
/** Compares two CContactItemViewDef items. 

@param anItem1 The first CContactItemViewDef to be compared.
@param anItem2 The second CContactItemViewDef to be compared.
@return ETrue if the two items are equal, EFalse otherwise. */
	{
	return (DoCompareTInt(anItem1.Mode(),anItem2.Mode()) 	&
		DoCompareTInt(anItem1.Use(),anItem2.Use())			&
		DoCompareCContactItemViewDefArray(anItem1, anItem2));
	
	}
LOCAL_C void TestUpdateContactL()
{
    test.Next(_L("TestUpdateContactL"));

    SETUP;

    CContactItem* contact = CContactItem::NewLC(KUidContactCard);

    TContactItemId id = cntClient.CreateContactL(*contact);
    CleanupStack::PopAndDestroy(contact);

    // View definition to read image field
    CContactItemViewDef* imageViewDef = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields, CContactItemViewDef::EMaskHiddenFields);
    imageViewDef->AddL(KUidContactFieldMatchAll);

    contact = cntClient.OpenContactLX(imageViewDef ,id);
    CleanupStack::PushL(contact);

    CContactItemField* newField = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldCodImage);
    newField->SetMapping(KUidContactFieldVCardMapUnknown);
    newField->TextStorage()->SetTextL(KSrcImage());
    contact->AddFieldL(*newField); // Takes ownership
    CleanupStack::Pop(newField);

    cntClient.CommitContactL(*contact, EFalse);
    CleanupStack::PopAndDestroy(2);  //  contact, imageViewDef

    // View definition to read image field
    imageViewDef = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields, CContactItemViewDef::EMaskHiddenFields);
    imageViewDef->AddL(KUidContactFieldCodImage);

    contact = cntClient.ReadContactL(imageViewDef ,id);

    TInt index = contact->CardFields().Find(KUidContactFieldCodImage, KUidContactFieldVCardMapUnknown);

    // Test image field found
    test(index != KErrNotFound);

    CContactItemField& field = contact->CardFields()[index];
    TPtrC imagePtr = field.TextStorage()->Text();

    // Image should exist
    test(BaflUtils::FileExists(fs, imagePtr));

    // Test for GUID
    TPtrC guid = contact->Guid();
    test(imagePtr.Find(guid));

    cntClient.CloseContact(id);
    CleanupStack::PopAndDestroy(2);  //  contact, imageViewDef

    TEAR_DOWN;
}
Exemplo n.º 7
0
void CPackagerTests::EmptyContactItemTestL()
	{
	CCntPackager* thePackage = CCntPackager::NewL();
	CleanupStack::PushL(thePackage);
	
	test.Next(_L("EmptyContactItemTestL"));


	CPersistenceLayer* iPersistLayer = CPersistenceLayer::NewLC(iFs);
	CContactItemViewDef* cntItemVdef = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields, CContactItemViewDef::EMaskHiddenFields);
	cntItemVdef->AddL(KUidContactFieldMatchAll);
	
	MLplContactsFile& cntFile = iPersistLayer->ContactsFileL();

	TRAPD(err, cntFile.CreateL(KCreatePlPerform, true ? MLplContactsFile::EPlOverwrite : MLplContactsFile::EPlLeaveIfExist));
	User::LeaveIfError(err);
	TRAP(err, while(cntFile.OpenStepL(KCreatePlPerform)){});
LOCAL_C void TestDeleteContactL()
{
    test.Next(_L("TestDeleteContactL"));

    SETUP;

    CContactItem* contact = CContactItem::NewLC(KUidContactCard);

    CContactItemField* newField = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldCodImage);
    newField->SetMapping(KUidContactFieldVCardMapUnknown);
    newField->TextStorage()->SetTextL(KSrcImage());
    contact->AddFieldL(*newField); // Takes ownership
    CleanupStack::Pop(newField);

    TContactItemId id = cntClient.CreateContactL(*contact);
    CleanupStack::PopAndDestroy(contact);

    // View definition to read image field
    CContactItemViewDef* imageViewDef = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields, CContactItemViewDef::EMaskHiddenFields);
    imageViewDef->AddL(KUidContactFieldCodImage);

    contact = cntClient.ReadContactL(imageViewDef ,id);
    CleanupStack::PopAndDestroy(imageViewDef);  //  imageViewDef

    TInt index = contact->CardFields().Find(KUidContactFieldCodImage, KUidContactFieldVCardMapUnknown);

    // Test image field found
    test(index != KErrNotFound);

    CContactItemField& field = contact->CardFields()[index];
    TPtrC imagePtr = field.TextStorage()->Text();

    test(BaflUtils::FileExists(fs, imagePtr));

    cntClient.DeleteContactL(id, EDeferEvent, ETrue);

    test(!BaflUtils::FileExists(fs, imagePtr));

    cntClient.CloseContact(id);
    delete contact;

    TEAR_DOWN;
}
TBool CViewDefAnyFieldsTest::FieldCountCompL(	const TContactItemId &aCid,
												CContactItemViewDef &aView, 
												const TBool aExcludeN, 
												const TBool aExcludeH,
												const TBool aZeroH,
												const TBool aMultiple)
	{
	TBool SingleTestResult = EFalse;
	TBool OverallTestResult = EFalse;
	
	TInt countM = 0;
	TInt countR = 0;
	TInt fieldsIV = 0;
	TInt emptyfsM = 0;
	TInt emptyfsR = 0;
	TInt hcountM = 0;
	TInt hcountR = 0;
	TInt hfieldsIV = 0;
	
	TInt length = 0;
	
	length = iExistingUidsArray->Count();
	
	for(TInt i = 0, j = 0; i < length;)
		{
		OverallTestResult = EFalse;
		if( (*iExistingUidsArray)[i] == 0 )
			{
			++i;
			continue;
			}
		aView.AddL(TUid::Uid((*iExistingUidsArray)[i]));
		
		ReadL(aCid,*iViewAll,EFalse);
		FieldsInView(aView, fieldsIV, hfieldsIV);
		countR = iFields->Count();
		hcountR = CountHiddenFields(*iFields);
		emptyfsR = CountEmpty(*iFields);
		Close();
		
		ReadMinimalL(aCid, aView, *iDefView,EFalse);
		countM = iFields->Count();
		hcountM = CountHiddenFields(*iFields);
		emptyfsM = CountEmpty(*iFields);
		Close();
		
		SingleTestResult = INTCOMPARE( 0 , ==,  emptyfsM, i, 0 );
		OverallTestResult = SingleTestResult;
		
		SingleTestResult = INTCOMPARE( 0 , ==,  emptyfsR, i, 0 );
		OverallTestResult = OverallTestResult && SingleTestResult;
		
		SingleTestResult = INTCOMPARE( hcountR , >,  0 , i, 0 );
		OverallTestResult = OverallTestResult && SingleTestResult;
		
		
		if(aExcludeN)
			{
			SingleTestResult = INTCOMPARE( ( (countR - fieldsIV) - hcountR ) , ==,  (countM - hcountM) , i, 0 );
			OverallTestResult = OverallTestResult && SingleTestResult;
			}
		else
			{
			SingleTestResult = INTCOMPARE( fieldsIV  , ==,  (countM - hcountM) , i, 0 );
			OverallTestResult = OverallTestResult && SingleTestResult;
			}
		if(aExcludeH)
			{
			if( aZeroH)
				{
				SingleTestResult = INTCOMPARE( 0 , ==,  hcountM, i, 0 );
				OverallTestResult = OverallTestResult && SingleTestResult;	
				}
			else
				{
				SingleTestResult = INTCOMPARE( ( hcountR - hfieldsIV) , ==,  hcountM , i, 0 );
				OverallTestResult = OverallTestResult && SingleTestResult;
				}
			}
LOCAL_C void TestCreateContactWithoutImagesFoldeL()
{
    test.Next(_L("TestCreateContactWithoutImagesFoldeL"));

    SETUP;

    // Delete the images folder and all contents
    TInt drive;

#ifdef __WINS__
    TInt err = DriveInfo::GetDefaultDrive(DriveInfo::EDefaultPhoneMemory, drive);
#else
    TInt err = DriveInfo::GetDefaultDrive(DriveInfo::EDefaultMassStorage, drive);
#endif

    // Do not leave with this error. The phone does not have to have this support
    if (err == KErrNone)
    {
        // Get the root path in this drive to create
        // to create the images directory
        TPath dir;
        User::LeaveIfError(PathInfo::GetRootPath(dir, drive));
        dir.Append(KImagesFolder);

        CFileMan* fileMan = CFileMan::NewL(fs);
        err = fileMan->RmDir(dir); // err not used
        delete fileMan;
    }
    else
    {
        test.Printf(_L("Could not remove the images folder\n"));
        return;
    }

    // Create an image and store an image without the images dir available
    CContactItem *contact = CContactItem::NewLC(KUidContactCard);

    CContactItemField *newField = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldCodImage);
    newField->SetMapping(KUidContactFieldVCardMapUnknown);
    newField->TextStorage()->SetTextL(KSrcImage());
    contact->AddFieldL(*newField); // Takes ownership
    CleanupStack::Pop(newField);

    TContactItemId id = cntClient.CreateContactL(*contact);
    CleanupStack::PopAndDestroy(contact);

    // View definition to read image field
    CContactItemViewDef *imageViewDef = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields, CContactItemViewDef::EMaskHiddenFields);
    imageViewDef->AddL(KUidContactFieldCodImage);

    contact = cntClient.ReadContactL(imageViewDef ,id);
    CleanupStack::PopAndDestroy(imageViewDef);  //  imageViewDef

    TInt index = contact->CardFields().Find(KUidContactFieldCodImage, KUidContactFieldVCardMapUnknown);

    // Test image field found
    test(index != KErrNotFound);

    CContactItemField& field = contact->CardFields()[index];
    TPtrC imagePtr = field.TextStorage()->Text();

    // Image path should not change
    test(imagePtr.Compare(KSrcImage()) == 0);

    cntClient.CloseContact(id);
    delete contact;

    TEAR_DOWN;
}
Exemplo n.º 11
0
/**
Add the given contact item to the database. Forward the call to CPplTableBase
based classes representing the tables in the contact database.

@param 	aItem The contact item to be added to the database. 
@param 	aSessionId The ID of the session that issued the request.  Used to
		prevent Phonebook Synchroniser deadlock.

@return Contact item ID of the contact added to the database.
*/
TContactItemId CPplContactItemManager::CreateL(CContactItem& aItem, TUint aSessionId)
	{
	TBool controlTransaction = !(iTransactionManager.IsTransactionActive());
	
	TBool compressedGuid=EFalse;

	// If needed generate a gui for the current contact item
	if (aItem.Guid() == TPtrC(KNullDesC))
		{
		iPreferencePersistor->SetGuidL(aItem, compressedGuid);
		}

	if (compressedGuid)
		{
		aItem.SetHasCompressedGuid(compressedGuid);
		}

	if (aItem.Type() == KUidContactICCEntry) 
		{
		const TInt ret = iContactProperties.ContactSynchroniserL(aSessionId).ValidateWriteContact(static_cast<CContactICCEntry&>(aItem));
		User::LeaveIfError(ret);	
		}
	
	if(controlTransaction)
		{
		StartTransactionL(aSessionId);
		}
		
	iContactTable->CreateInDbL(aItem);	
	iGroupTable->CreateInDbL(aItem);	
	iCommAddrTable->CreateInDbL(aItem);

   	TContactItemId groupId = iIccContactStore.CreateInDbL(aItem, aSessionId);
   	if(groupId != KNullContactId)
   	    {
   	    //Every ICC entry is added to a special group, created by the Phonebook
        //Synchroniser server during the initial synchronisation with the Contacts Model.
		CContactItemViewDef* itemDef = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields,CContactItemViewDef::EMaskHiddenFields);
		itemDef->AddL(KUidContactFieldMatchAll);

		// Add ICC entry to the group.
		CContactGroup* grp = static_cast<CContactGroup*>(ReadLC(groupId, *itemDef, EPlAllInfo, aSessionId));
		
		grp->AddContactL(aItem.Id());
		UpdateL(*grp, aSessionId);

		CleanupStack::PopAndDestroy(2, itemDef); // grp
   	    }

	if(controlTransaction)
		{
		CommitTransactionL();
		}
	
	// Assuming success if no leaves at this point, so update
	// the metadata search store for this entry
	//CCntMetadataOperation* op = CCntMetadataOperation::NewLC(iColSession);
	//TRAP_IGNORE(op->SaveContactLD(aItem));
	//CleanupStack::Pop(op); // Do not destroy - called LD function
	
	return aItem.Id();	
	}