messagingfw/msgtestfw/TestActions/Email/Smtp/src/CMtfTestActionSmtpAddEntryAttachment.cpp
changeset 0 8e480a14352b
equal deleted inserted replaced
-1:000000000000 0:8e480a14352b
       
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // __ACTION_INFO_BEGIN__ 
       
    15 // [Action Name]
       
    16 // SmtpAddEntryAttachment
       
    17 // [Action Parameters]
       
    18 // Session        <input>: Reference to the session.
       
    19 // MsgId		  <input>: Value of the message Id.
       
    20 // EntryId        <input>: Entry Id of message to add as an attachment.
       
    21 // AttachmentId   <output>: Value of the created attachment id.
       
    22 // ErrorCode	  <output>: (Optional) Returned error code, if not requested then code will
       
    23 // leave if not KErrNone
       
    24 // [Action Description]
       
    25 // Adds the specified message entry as an attachment to the specified message
       
    26 // entry.
       
    27 // [APIs Used]
       
    28 // CMsvSession::GetEntryL
       
    29 // CImEmailMessage::AttachmentManagerL
       
    30 // CMsvAttachment::NewL
       
    31 // MMsvAttachmentManager::AddEntryAsAttachmentL
       
    32 // __ACTION_INFO_END__
       
    33 // 
       
    34 //
       
    35 
       
    36 
       
    37 #include "CMtfTestActionSmtpAddEntryAttachment.h"
       
    38 #include "CMtfAsyncWaiter.h"
       
    39 #include "CMtfTestCase.h"
       
    40 #include "CMtfTestActionParameters.h"
       
    41 #include "MtfTestActionUtilsUser.h"
       
    42 
       
    43 #include <miutset.h>
       
    44 #include <cmsvattachment.h>
       
    45 #include <mmsvattachmentmanager.h>
       
    46 #include <miutmsg.h>
       
    47 
       
    48 CMtfTestAction* CMtfTestActionSmtpAddEntryAttachment::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters)
       
    49 	{
       
    50 	CMtfTestActionSmtpAddEntryAttachment* self = new(ELeave) CMtfTestActionSmtpAddEntryAttachment(aTestCase);
       
    51 	CleanupStack::PushL(self);
       
    52 	self->ConstructL(aActionParameters);
       
    53 	CleanupStack::Pop();
       
    54 	return self;
       
    55 	}
       
    56 	
       
    57 
       
    58 CMtfTestActionSmtpAddEntryAttachment::CMtfTestActionSmtpAddEntryAttachment(CMtfTestCase& aTestCase)
       
    59 	: CMtfSynchronousTestAction(aTestCase)
       
    60 	{
       
    61 	}
       
    62 
       
    63 
       
    64 CMtfTestActionSmtpAddEntryAttachment::~CMtfTestActionSmtpAddEntryAttachment()
       
    65 	{
       
    66 	}
       
    67 
       
    68 void CMtfTestActionSmtpAddEntryAttachment::ExecuteActionL()
       
    69 	{
       
    70 	TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionSmtpAddEntryAttachment);
       
    71 	TRAPD(err, RunTestL());
       
    72 	
       
    73 	if( ActionParameters().Count() < 5 )
       
    74 		{
       
    75 		User::LeaveIfError(err);
       
    76 		}
       
    77 	else
       
    78 		{
       
    79 		StoreParameterL<TInt>(TestCase(),err,ActionParameters().Parameter(4));
       
    80 		}
       
    81 		
       
    82 	TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionSmtpAddEntryAttachment);
       
    83 	TestCase().ActionCompletedL(*this); 
       
    84 	}
       
    85 
       
    86 void CMtfTestActionSmtpAddEntryAttachment::RunTestL()
       
    87 	{
       
    88 	CMsvSession* paramSession = ObtainParameterReferenceL<CMsvSession>(TestCase(),ActionParameters().Parameter(0));
       
    89 	TMsvId messageEntry = ObtainValueParameterL<TMsvId>(TestCase(),ActionParameters().Parameter(1));
       
    90 	TMsvId attachmentMessageEntry = ObtainValueParameterL<TMsvId>(TestCase(),ActionParameters().Parameter(2));
       
    91 
       
    92 	CMsvEntry* entry = paramSession->GetEntryL(messageEntry);
       
    93 	CleanupStack::PushL(entry);
       
    94 	
       
    95 	CImEmailMessage* emailMsg = CImEmailMessage::NewL(*entry);
       
    96 	CleanupStack::PushL(emailMsg);
       
    97 	
       
    98 	CMtfAsyncWaiter* waiter = CMtfAsyncWaiter::NewL();
       
    99 	CleanupStack::PushL(waiter);
       
   100 	
       
   101 	CMsvAttachment* attachment = CMsvAttachment::NewL(CMsvAttachment::EMsvMessageEntry);
       
   102 	CleanupStack::PushL(attachment);
       
   103 	
       
   104 	TMsvEntry attachmentEntry;
       
   105 	TMsvId attachmentServiceEntry;
       
   106 	User::LeaveIfError(paramSession->GetEntry(attachmentMessageEntry, attachmentServiceEntry, attachmentEntry));
       
   107 	attachment->SetSize(attachmentEntry.iSize);
       
   108 
       
   109 	MMsvAttachmentManager& manager = emailMsg->AttachmentManager();
       
   110 	
       
   111 	manager.AddEntryAsAttachmentL(attachmentMessageEntry, attachment, waiter->iStatus);
       
   112 	CleanupStack::Pop(attachment); // ownership passed to manager
       
   113 	waiter->StartAndWait();
       
   114 	User::LeaveIfError(waiter->Result());
       
   115 	CleanupStack::PopAndDestroy(waiter);
       
   116 	
       
   117 	attachment = NULL;
       
   118 	
       
   119 	TInt attachmentCount = manager.AttachmentCount();
       
   120 	attachment = manager.GetAttachmentInfoL(attachmentCount - 1);
       
   121 	CleanupStack::PushL(attachment);
       
   122 	
       
   123 	TMsvAttachmentId attachmentId = attachment->Id();
       
   124 	
       
   125 	CleanupStack::PopAndDestroy(3, entry); // emailMsg, entry
       
   126 	
       
   127 	StoreParameterL<TMsvAttachmentId>(TestCase(),attachmentId,ActionParameters().Parameter(3));
       
   128 	}
       
   129