messagingfw/msgtestfw/TestActions/Base/Attachments/src/CMtfTestActionAddEntryAttachment.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 // AddEntryAttachment
       
    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 // CMsvStore::EditStoreL
       
    30 // CMsvStore::AttachmentManagerL
       
    31 // CMsvAttachment::NewL
       
    32 // MMsvAttachmentManager::AddEntryAsAttachmentL
       
    33 // __ACTION_INFO_END__
       
    34 // 
       
    35 //
       
    36 
       
    37 
       
    38 #include "CMtfTestActionAddEntryAttachment.h"
       
    39 #include "CMtfAsyncWaiter.h"
       
    40 #include "CMtfTestCase.h"
       
    41 #include "CMtfTestActionParameters.h"
       
    42 #include "MtfTestActionUtilsUser.h"
       
    43 
       
    44 #include <miutset.h>
       
    45 #include <cmsvattachment.h>
       
    46 #include <mmsvattachmentmanager.h>
       
    47 
       
    48 CMtfTestAction* CMtfTestActionAddEntryAttachment::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters)
       
    49 	{
       
    50 	CMtfTestActionAddEntryAttachment* self = new(ELeave) CMtfTestActionAddEntryAttachment(aTestCase);
       
    51 	CleanupStack::PushL(self);
       
    52 	self->ConstructL(aActionParameters);
       
    53 	CleanupStack::Pop();
       
    54 	return self;
       
    55 	}
       
    56 	
       
    57 
       
    58 CMtfTestActionAddEntryAttachment::CMtfTestActionAddEntryAttachment(CMtfTestCase& aTestCase)
       
    59 	: CMtfSynchronousTestAction(aTestCase)
       
    60 	{
       
    61 	}
       
    62 
       
    63 
       
    64 CMtfTestActionAddEntryAttachment::~CMtfTestActionAddEntryAttachment()
       
    65 	{
       
    66 	}
       
    67 
       
    68 void CMtfTestActionAddEntryAttachment::ExecuteActionL()
       
    69 	{
       
    70 	TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionAddEntryAttachment);
       
    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 	TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionAddEntryAttachment);	
       
    82 	TestCase().ActionCompletedL(*this); 
       
    83 	}
       
    84 
       
    85 void CMtfTestActionAddEntryAttachment::RunTestL()
       
    86 	{
       
    87 	CMsvSession* paramSession = ObtainParameterReferenceL<CMsvSession>(TestCase(),ActionParameters().Parameter(0));
       
    88 	TMsvId messageEntry = ObtainValueParameterL<TMsvId>(TestCase(),ActionParameters().Parameter(1));
       
    89 	TMsvId attachmentMessageEntry = ObtainValueParameterL<TMsvId>(TestCase(),ActionParameters().Parameter(2));
       
    90 
       
    91 	CMsvEntry* entry = paramSession->GetEntryL(messageEntry);
       
    92 	CleanupStack::PushL(entry);
       
    93 	
       
    94 	CMsvStore* store = entry->EditStoreL();
       
    95 	CleanupStack::PushL(store);
       
    96 	
       
    97 	CMtfAsyncWaiter* waiter = CMtfAsyncWaiter::NewL();
       
    98 	CleanupStack::PushL(waiter);
       
    99 	
       
   100 	CMsvAttachment* attachment = CMsvAttachment::NewL(CMsvAttachment::EMsvMessageEntry);
       
   101 	CleanupStack::PushL(attachment);
       
   102 	
       
   103 	TMsvEntry attachmentEntry;
       
   104 	TMsvId attachmentServiceEntry;
       
   105 	User::LeaveIfError(paramSession->GetEntry(attachmentMessageEntry, attachmentServiceEntry, attachmentEntry));
       
   106 	attachment->SetSize(attachmentEntry.iSize);
       
   107 	
       
   108 	MMsvAttachmentManager& manager = store->AttachmentManagerL();
       
   109 	
       
   110 	manager.AddEntryAsAttachmentL(attachmentMessageEntry, attachment, waiter->iStatus);
       
   111 	CleanupStack::Pop(attachment); // ownership passed to manager
       
   112 	waiter->StartAndWait();
       
   113 	User::LeaveIfError(waiter->Result());
       
   114 	CleanupStack::PopAndDestroy(waiter);
       
   115 
       
   116 	TMsvAttachmentId attachmentId = attachment->Id();
       
   117 	
       
   118 	store->CommitL();
       
   119 	
       
   120 	CleanupStack::PopAndDestroy(2, entry); // store, entry
       
   121 	
       
   122 	StoreParameterL<TMsvAttachmentId>(TestCase(),attachmentId,ActionParameters().Parameter(3));
       
   123 	}
       
   124 
       
   125 
       
   126