void CMtfTestActionSmtpRemoveEntryAttachmentById::RunTestL() { CMsvSession* paramSession = ObtainParameterReferenceL<CMsvSession>(TestCase(),ActionParameters().Parameter(0)); TMsvId messageEntry = ObtainValueParameterL<TMsvId>(TestCase(),ActionParameters().Parameter(1)); TMsvAttachmentId attachId = ObtainValueParameterL<TMsvAttachmentId>(TestCase(),ActionParameters().Parameter(2)); CMsvEntry* entry = paramSession->GetEntryL(messageEntry); CleanupStack::PushL(entry); CImEmailMessage* emailMsg = CImEmailMessage::NewL(*entry); CleanupStack::PushL(emailMsg); MMsvAttachmentManager& manager = emailMsg->AttachmentManager(); CMsvAttachment* attachInfo = manager.GetAttachmentInfoL(attachId); CleanupStack::PushL(attachInfo); // First ensure that the attachment is a file attachment if( attachInfo->Type() != CMsvAttachment::EMsvMessageEntry ) { User::Leave(KErrGeneral); } // Get the linked file TMsvId msgId = attachInfo->EntryAttachmentId(); CleanupStack::PopAndDestroy(attachInfo); // Remove the attachment CMtfAsyncWaiter* waiter = CMtfAsyncWaiter::NewL(); CleanupStack::PushL(waiter); manager.RemoveAttachmentL(attachId, waiter->iStatus); waiter->StartAndWait(); User::LeaveIfError(waiter->Result()); CleanupStack::PopAndDestroy(waiter); CleanupStack::PopAndDestroy(2, entry); // email msg, entry // Ensure that the message entry still exists CMsvEntry* checkEntry = paramSession->GetEntryL(msgId); delete checkEntry; checkEntry = NULL; }
void CMtfTestActionRemoveFileAttachmentWithDestroy::ExecuteActionL() { TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionRemoveFileAttachmentWithDestroy); CMsvSession* paramSession = ObtainParameterReferenceL<CMsvSession>(TestCase(),ActionParameters().Parameter(0)); TMsvId messageEntry = ObtainValueParameterL<TMsvId>(TestCase(),ActionParameters().Parameter(1)); TMsvAttachmentId attachId = ObtainValueParameterL<TMsvAttachmentId>(TestCase(),ActionParameters().Parameter(2)); CMsvEntry* entry = paramSession->GetEntryL(messageEntry); CleanupStack::PushL(entry); CMsvStore* store = entry->EditStoreL(); CleanupStack::PushL(store); MMsvAttachmentManager& manager = store->AttachmentManagerL(); CMsvAttachment* attachInfo = manager.GetAttachmentInfoL(attachId); CleanupStack::PushL(attachInfo); // First ensure that the attachment is a file attachment if( attachInfo->Type() != CMsvAttachment::EMsvFile ) { User::Leave(KErrGeneral); } CleanupStack::PopAndDestroy(attachInfo); CMtfAsyncWaiter* waiter = CMtfAsyncWaiter::NewL(); CleanupStack::PushL(waiter); manager.RemoveAttachmentL(attachId, waiter->iStatus); waiter->StartAndWait(); User::LeaveIfError(waiter->Result()); CleanupStack::PopAndDestroy(waiter); // destroy the store without commit CleanupStack::PopAndDestroy(2, entry); // store, entry TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionRemoveFileAttachmentWithDestroy); TestCase().ActionCompletedL(*this); }
void CheckNewAttachmentL(const TDesC& aFileName, TInt aFileSize, const TDesC8& aMimeType, TUint aCharset, TBool aLinkedAttachment) { // Check that file exists in the store and it matches our control file. CDummyObserver* ob1 = new(ELeave) CDummyObserver; CleanupStack::PushL(ob1); CMsvSession* session = CMsvSession::OpenSyncL(*ob1); CleanupStack::PushL(session); CMsvEntry* cEntry = CMsvEntry::NewL(*session, KMsvDraftEntryId, TMsvSelectionOrdering(KMsvNoGrouping,EMsvSortByNone,ETrue)); CleanupStack::PushL(cEntry); CMsvEntrySelection* selection = cEntry->ChildrenL(); CleanupStack::PushL(selection); test(selection->Count() == 1); cEntry->SetEntryL((*selection)[0]); CMsvStore* store = cEntry->ReadStoreL(); CleanupStack::PushL(store); MMsvAttachmentManager& attachmentMgr = store->AttachmentManagerL(); TInt count = attachmentMgr.AttachmentCount(); test(count > 0); TBool found = EFalse; while( count-- > 0 && !found ) { CMsvAttachment* attachmentInfo = attachmentMgr.GetAttachmentInfoL(count); CleanupStack::PushL(attachmentInfo); // Check the attachment info is what we expect. TParse parser1; TParse parser2; parser1.Set(attachmentInfo->FilePath(), NULL, NULL); parser2.Set(aFileName, NULL, NULL); found = ETrue; if (aLinkedAttachment) { found = found && (attachmentInfo->Type() == CMsvAttachment::EMsvLinkedFile); // Check it's a linked file. found = found && (parser1.DriveAndPath() == parser2.DriveAndPath()); } else { found = found && (attachmentInfo->Type() == CMsvAttachment::EMsvFile); // Check it's a file. found = found && (parser1.DriveAndPath() != parser2.DriveAndPath()); } found = found && (attachmentInfo->MimeType().Match(aMimeType) == 0); // Check mime type matches. found = found && (parser1.NameAndExt() == parser2.NameAndExt()); // This necessarily correct? found = found && (attachmentInfo->Size() == aFileSize); // Check size matches. // check charset matches CMsvMimeHeaders* mimeHeaders = CMsvMimeHeaders::NewLC(); mimeHeaders->RestoreL(*attachmentInfo); found = found && (mimeHeaders->MimeCharset() == aCharset); CleanupStack::PopAndDestroy(2, attachmentInfo); // mimeHeaders, attachmentInfo } test(found); CleanupStack::PopAndDestroy(5, ob1); // store, selection, cEntry, sesion, ob1 }