messagingfw/msgtestfw/TestActions/Email/Smtp/src/CMtfTestActionSmtpGetAttachmentInfoById.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 // SmtpGetAttachmentInfoById
       
    17 // [Action Parameters]
       
    18 // Session        <input>: Reference to the session.
       
    19 // MsgId		  <input>: Value of the message Id.
       
    20 // AttachmentId   <input>: Value of the attachment id.
       
    21 // AttachmentInfo <output>: Reference to the created attachment info
       
    22 // ErrorCode	  <output>: (Optional) Returned error code, if not requested then code will
       
    23 // leave if not KErrNone
       
    24 // [Action Description]
       
    25 // Creates an attachment info object with the specified attachment id for the
       
    26 // supplied message entry. Will fail if the entry or attachment does not exist.
       
    27 // [APIs Used]
       
    28 // CMsvSession::GetEntryL
       
    29 // CImEmailMessage::AttachmentManagerL
       
    30 // MMsvAttachmentManager::GetAttachmentInfoL
       
    31 // __ACTION_INFO_END__
       
    32 // 
       
    33 //
       
    34 
       
    35 
       
    36 #include "CMtfTestActionSmtpGetAttachmentInfoById.h"
       
    37 #include "CMtfTestCase.h"
       
    38 #include "CMtfTestActionParameters.h"
       
    39 #include "MtfTestActionUtilsUser.h"
       
    40 
       
    41 #include <miutset.h>
       
    42 #include <cmsvattachment.h>
       
    43 #include <mmsvattachmentmanager.h>
       
    44 #include <miutmsg.h>
       
    45 
       
    46 const TInt KMimeTypeLength = 50;
       
    47 
       
    48 CMtfTestAction* CMtfTestActionSmtpGetAttachmentInfoById::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters)
       
    49 	{
       
    50 	CMtfTestActionSmtpGetAttachmentInfoById* self = new(ELeave) CMtfTestActionSmtpGetAttachmentInfoById(aTestCase);
       
    51 	CleanupStack::PushL(self);
       
    52 	self->ConstructL(aActionParameters);
       
    53 	CleanupStack::Pop();
       
    54 	return self;
       
    55 	}
       
    56 	
       
    57 
       
    58 CMtfTestActionSmtpGetAttachmentInfoById::CMtfTestActionSmtpGetAttachmentInfoById(CMtfTestCase& aTestCase)
       
    59 	: CMtfSynchronousTestAction(aTestCase)
       
    60 	{
       
    61 	}
       
    62 
       
    63 
       
    64 CMtfTestActionSmtpGetAttachmentInfoById::~CMtfTestActionSmtpGetAttachmentInfoById()
       
    65 	{
       
    66 	}
       
    67 
       
    68 void CMtfTestActionSmtpGetAttachmentInfoById::ExecuteActionL()
       
    69 	{
       
    70 	TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionSmtpGetAttachmentInfoById);
       
    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."), &KTestActionSmtpGetAttachmentInfoById);
       
    83 	TestCase().ActionCompletedL(*this); 
       
    84 	}
       
    85 
       
    86 void CMtfTestActionSmtpGetAttachmentInfoById::RunTestL()
       
    87 	{
       
    88 	CMsvSession* paramSession = ObtainParameterReferenceL<CMsvSession>(TestCase(),ActionParameters().Parameter(0));
       
    89 	TMsvId messageEntry = ObtainValueParameterL<TMsvId>(TestCase(),ActionParameters().Parameter(1));
       
    90 	TMsvAttachmentId attachId = ObtainValueParameterL<TMsvAttachmentId>(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 	MMsvAttachmentManager& manager = emailMsg->AttachmentManager();
       
    99 	CMsvAttachment* attachInfo = manager.GetAttachmentInfoL(attachId);
       
   100 	CleanupStack::PushL(attachInfo);
       
   101 	
       
   102 	PrintAttachmentInfo(*attachInfo);
       
   103 	
       
   104 	StoreParameterL<CMsvAttachment>(TestCase(),*attachInfo,ActionParameters().Parameter(3));
       
   105 	CleanupStack::Pop(attachInfo);
       
   106 	CleanupStack::PopAndDestroy(2, entry); // emailMsg, entry
       
   107 	}
       
   108 
       
   109 void CMtfTestActionSmtpGetAttachmentInfoById::PrintAttachmentInfo(CMsvAttachment& aInfo)
       
   110 	{
       
   111 	TestCase().INFO_PRINTF1(_L("CMsvAttachment Info..."));
       
   112 	TestCase().INFO_PRINTF2(_L("ID - %d"), aInfo.Id() );
       
   113 	switch(aInfo.Type())
       
   114 		{
       
   115 		case CMsvAttachment::EMsvFile:
       
   116 			TestCase().INFO_PRINTF1(_L("Type - EMsvFile"));
       
   117 			TestCase().INFO_PRINTF2(_L("Filename - %S"), &aInfo.AttachmentName());
       
   118 			break;
       
   119 		case CMsvAttachment::EMsvLinkedFile:
       
   120 			TestCase().INFO_PRINTF1(_L("Type - EMsvLinkedFile"));
       
   121 			TestCase().INFO_PRINTF2(_L("Filename - %S"), &aInfo.AttachmentName());
       
   122 			break;
       
   123 		case CMsvAttachment::EMsvMessageEntry:
       
   124 			TestCase().INFO_PRINTF1(_L("Type - EMsvMessageEntry"));
       
   125 			TestCase().INFO_PRINTF2(_L("EntryId - %d"), aInfo.EntryAttachmentId());
       
   126 			break;
       
   127 		default:
       
   128 			User::Invariant();
       
   129 			break;
       
   130 		}
       
   131 	
       
   132 	TestCase().INFO_PRINTF2(_L("Size - %d"), aInfo.Size());
       
   133 	
       
   134 	TBuf<KMimeTypeLength> mimeType;
       
   135 	mimeType.Copy(aInfo.MimeType());
       
   136 	TestCase().INFO_PRINTF2(_L("MimeType - %S"), &mimeType);
       
   137 	
       
   138 	}