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(); }
LOCAL_C void TestRecoverWhenViewReadyL() { test.Next(_L("Recover database when view is ready")); CTestResources* res = CTestResources::NewLC(EFalse); //Creating a contact to test recovery _LIT(KPhoneNumLabel,"Phone Number"); _LIT(KPhoneNum, "+440000000000"); CContactCard* contact = CContactCard::NewLC(); CContactItemField* field = CContactItemField::NewLC(KStorageTypeText,KUidContactFieldPhoneNumber); field->SetLabelL(KPhoneNumLabel()); field->TextStorage()->SetTextL(KPhoneNum()); contact->AddFieldL(*field); TContactItemId aContactId = res->iDb->AddNewContactL(*contact); CleanupStack::Pop(field); // Wait 5 seconds for the view to get ready TContactViewEvent event; test(res->iViewEventQueue->ListenForEvent(5,event)); test(event.iEventType == TContactViewEvent::EReady); // Damage the DB test.Next(_L("Damage the open database")); res->iDb->DamageDatabaseL(0x666); test(res->iDb->IsDamaged()); // Damaging should not send view events test(!res->iViewEventQueue->ListenForEvent(5,event)); //Attempt to read contact from the damaged database - this should fail with KErrNotReady test.Next(_L("Attempting to read from damaged database")); CContactItem* testCard = NULL; TRAPD(ret,testCard = res->iDb->ReadContactLC(aContactId)); test(ret == KErrNotReady); // Recover the DB test.Next(_L("Recover the damaged database")); res->iDb->RecoverL(); // View should be unavailable here test(res->iViewEventQueue->ListenForEvent(5,event)); test(event.iEventType == TContactViewEvent::EUnavailable); //View should now be ready for use again test(res->iViewEventQueue->ListenForEvent(5,event)); test(event.iEventType == TContactViewEvent::EReady); //Line below included to fix ARMV5 minor build warnings. testCard = res->iDb->ReadContactLC(aContactId); test(testCard != NULL); CleanupStack::PopAndDestroy(testCard); CleanupStack::PopAndDestroy(contact); CleanupStack::PopAndDestroy(res); }