messagingfw/msgtestfw/TestActions/Base/Attachments/src/CMtfTestActionCompareAttachment.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 // CompareAttachment
       
    17 // [Action Parameters]
       
    18 // Session        <input>: Reference to the session.
       
    19 // MsgId		  <input>: Value of the message Id.
       
    20 // AttachmentId	  <input>: Attachment ID to compare.
       
    21 // DataFilePath   <input>: File path of data to compare attachment to.
       
    22 // [Action Description]
       
    23 // Compares the data from a file attachment against a file.
       
    24 // [APIs Used]
       
    25 // CMsvSession::GetEntryL
       
    26 // CMsvStore::ReadStoreL
       
    27 // CMsvStore::AttachmentManagerL
       
    28 // __ACTION_INFO_END__
       
    29 // 
       
    30 //
       
    31 
       
    32 
       
    33 #include "CMtfTestActionCompareAttachment.h"
       
    34 #include "CMtfTestCase.h"
       
    35 #include "CMtfTestActionParameters.h"
       
    36 #include "MtfTestActionUtilsUser.h"
       
    37 
       
    38 #include <miutset.h>
       
    39 #include <mmsvattachmentmanager.h>
       
    40 
       
    41 CMtfTestAction* CMtfTestActionCompareAttachment::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters)
       
    42 	{
       
    43 	CMtfTestActionCompareAttachment* self = new(ELeave) CMtfTestActionCompareAttachment(aTestCase);
       
    44 	CleanupStack::PushL(self);
       
    45 	self->ConstructL(aActionParameters);
       
    46 	CleanupStack::Pop();
       
    47 	return self;
       
    48 	}
       
    49 	
       
    50 
       
    51 CMtfTestActionCompareAttachment::CMtfTestActionCompareAttachment(CMtfTestCase& aTestCase)
       
    52 	: CMtfSynchronousTestAction(aTestCase)
       
    53 	{
       
    54 	}
       
    55 
       
    56 
       
    57 CMtfTestActionCompareAttachment::~CMtfTestActionCompareAttachment()
       
    58 	{
       
    59 	}
       
    60 
       
    61 
       
    62 void CMtfTestActionCompareAttachment::ExecuteActionL()
       
    63 	{
       
    64 	TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionCompareAttachment);
       
    65 	CMsvSession* paramSession = ObtainParameterReferenceL<CMsvSession>(TestCase(),ActionParameters().Parameter(0));
       
    66 	TMsvId messageEntry = ObtainValueParameterL<TMsvId>(TestCase(),ActionParameters().Parameter(1));
       
    67 	TMsvAttachmentId attachId = ObtainValueParameterL<TMsvAttachmentId>(TestCase(),ActionParameters().Parameter(2));
       
    68 	HBufC* dataFilePath   = ObtainParameterReferenceL<HBufC>(TestCase(),ActionParameters().Parameter(3));
       
    69 
       
    70 	CMsvEntry* entry = paramSession->GetEntryL(messageEntry);
       
    71 	CleanupStack::PushL(entry);
       
    72 	
       
    73 	CMsvStore* store = entry->ReadStoreL();
       
    74 	CleanupStack::PushL(store);
       
    75 	
       
    76 	MMsvAttachmentManager& manager = store->AttachmentManagerL();
       
    77 	
       
    78 	RFile fileAttachment = manager.GetAttachmentFileL(attachId);
       
    79 	CleanupClosePushL(fileAttachment);
       
    80 	
       
    81 	CompareFileL(fileAttachment, *dataFilePath);
       
    82 	
       
    83 	CleanupStack::PopAndDestroy(&fileAttachment);
       
    84 	
       
    85 	CleanupStack::PopAndDestroy(2, entry); // store, entry
       
    86 	TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionCompareAttachment);
       
    87 	TestCase().ActionCompletedL(*this);
       
    88 	}
       
    89 
       
    90 void CMtfTestActionCompareAttachment::CompareFileL(RFile& aAttachment, const TDesC& aDataFilePath)
       
    91 	{
       
    92 	RFs fs;
       
    93 	User::LeaveIfError(fs.Connect());
       
    94 	CleanupClosePushL(fs);
       
    95 	
       
    96 	RFile dataFile;
       
    97 	User::LeaveIfError(dataFile.Open(fs, aDataFilePath, EFileRead|EFileShareReadersOnly));
       
    98 	CleanupClosePushL(fs);
       
    99 	
       
   100 	TInt fileSize = 0;
       
   101 	
       
   102 	User::LeaveIfError(dataFile.Size(fileSize));
       
   103 	HBufC8* dataBuffer = HBufC8::NewLC(fileSize);
       
   104 	TPtr8 bufferPtr(dataBuffer->Des());
       
   105 	
       
   106 	User::LeaveIfError(aAttachment.Size(fileSize));
       
   107 	HBufC8* attachmentData = HBufC8::NewLC(fileSize);
       
   108 	TPtr8 attachmentPtr(attachmentData->Des());
       
   109 	
       
   110 	TInt compare = attachmentPtr.Compare(bufferPtr);
       
   111 	if( compare != 0 )
       
   112 		User::Leave(KErrCorrupt);
       
   113 	
       
   114 	CleanupStack::PopAndDestroy(4, &fs); // attachmentData, dataBuffer, dataFile, fs
       
   115 	}
       
   116