messagingfw/msgtestfw/TestActions/Base/Attachments/src/CMtfTestActionAddFileAttachmentWithDestroy.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 // AddFileAttachmentWithDestroy
       
    17 // [Action Parameters]
       
    18 // Session        <input>: Reference to the session.
       
    19 // MsgId		  <input>: Value of the message Id.
       
    20 // FilePath       <input>: File path of the attachment file.
       
    21 // MimeType		  <input>: Mime-type of the attachment.
       
    22 // [Action Description]
       
    23 // Synchrounously creates a file attachment on the specified message entry located
       
    24 // using a specified file. The store is then destroyed and the attachment should not exist.
       
    25 // [APIs Used]
       
    26 // CMsvSession::GetEntryL
       
    27 // CMsvStore::EditStoreL
       
    28 // CMsvStore::AttachmentManagerL
       
    29 // CMsvAttachment::NewL
       
    30 // CMsvAttachment::SetMimeType
       
    31 // MMsvAttachmentManager::AddAttachmentL
       
    32 // __ACTION_INFO_END__
       
    33 // 
       
    34 //
       
    35 
       
    36 
       
    37 #include "CMtfTestActionAddFileAttachmentWithDestroy.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 
       
    47 CMtfTestAction* CMtfTestActionAddFileAttachmentWithDestroy::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters)
       
    48 	{
       
    49 	CMtfTestActionAddFileAttachmentWithDestroy* self = new(ELeave) CMtfTestActionAddFileAttachmentWithDestroy(aTestCase);
       
    50 	CleanupStack::PushL(self);
       
    51 	self->ConstructL(aActionParameters);
       
    52 	CleanupStack::Pop();
       
    53 	return self;
       
    54 	}
       
    55 	
       
    56 
       
    57 CMtfTestActionAddFileAttachmentWithDestroy::CMtfTestActionAddFileAttachmentWithDestroy(CMtfTestCase& aTestCase)
       
    58 	: CMtfSynchronousTestAction(aTestCase)
       
    59 	{
       
    60 	}
       
    61 
       
    62 
       
    63 CMtfTestActionAddFileAttachmentWithDestroy::~CMtfTestActionAddFileAttachmentWithDestroy()
       
    64 	{
       
    65 	}
       
    66 
       
    67 void CMtfTestActionAddFileAttachmentWithDestroy::ExecuteActionL()
       
    68 	{
       
    69 	TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionAddFileAttachmentWithDestroy);
       
    70 	CMsvSession* paramSession = ObtainParameterReferenceL<CMsvSession>(TestCase(),ActionParameters().Parameter(0));
       
    71 	TMsvId messageEntry = ObtainValueParameterL<TMsvId>(TestCase(),ActionParameters().Parameter(1));
       
    72 	HBufC* paramFilePath   = ObtainParameterReferenceL<HBufC>(TestCase(),ActionParameters().Parameter(2));
       
    73 	HBufC8* paramMimeType = ObtainParameterReferenceL<HBufC8>(TestCase(),ActionParameters().Parameter(3));
       
    74 
       
    75 	CMsvEntry* entry = paramSession->GetEntryL(messageEntry);
       
    76 	CleanupStack::PushL(entry);
       
    77 	
       
    78 	CMsvStore* store = entry->EditStoreL();
       
    79 	CleanupStack::PushL(store);
       
    80 	
       
    81 	CMtfAsyncWaiter* waiter = CMtfAsyncWaiter::NewL();
       
    82 	CleanupStack::PushL(waiter);
       
    83 	
       
    84 	CMsvAttachment* attachment = CMsvAttachment::NewL(CMsvAttachment::EMsvFile);
       
    85 	CleanupStack::PushL(attachment);
       
    86 
       
    87 	attachment->SetMimeTypeL(*paramMimeType);
       
    88 	TParse fileNameParser;
       
    89 	User::LeaveIfError(fileNameParser.Set(*paramFilePath, NULL, NULL));
       
    90 	attachment->SetAttachmentNameL(fileNameParser.NameAndExt());
       
    91 
       
    92 	MMsvAttachmentManager& manager = store->AttachmentManagerL();
       
    93 	
       
    94 	manager.AddAttachmentL(*paramFilePath, attachment, waiter->iStatus);
       
    95 	CleanupStack::Pop(attachment); // ownership passed to manager
       
    96 	waiter->StartAndWait();
       
    97 	User::LeaveIfError(waiter->Result());
       
    98 	CleanupStack::PopAndDestroy(waiter);
       
    99 	
       
   100 	TMsvAttachmentId attachmentId = attachment->Id();
       
   101 	
       
   102 	// Destroy the store without Commit or Revert...
       
   103 	CleanupStack::PopAndDestroy(2, entry); // store, entry
       
   104 	TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionAddFileAttachmentWithDestroy);
       
   105 	TestCase().ActionCompletedL(*this);
       
   106 	}
       
   107 
       
   108 
       
   109