diff -r 000000000000 -r 8e480a14352b messagingfw/msgtestfw/TestActions/Base/Attachments/src/CMtfTestActionCompareAttachment.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/messagingfw/msgtestfw/TestActions/Base/Attachments/src/CMtfTestActionCompareAttachment.cpp Mon Jan 18 20:36:02 2010 +0200 @@ -0,0 +1,116 @@ +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// __ACTION_INFO_BEGIN__ +// [Action Name] +// CompareAttachment +// [Action Parameters] +// Session : Reference to the session. +// MsgId : Value of the message Id. +// AttachmentId : Attachment ID to compare. +// DataFilePath : File path of data to compare attachment to. +// [Action Description] +// Compares the data from a file attachment against a file. +// [APIs Used] +// CMsvSession::GetEntryL +// CMsvStore::ReadStoreL +// CMsvStore::AttachmentManagerL +// __ACTION_INFO_END__ +// +// + + +#include "CMtfTestActionCompareAttachment.h" +#include "CMtfTestCase.h" +#include "CMtfTestActionParameters.h" +#include "MtfTestActionUtilsUser.h" + +#include +#include + +CMtfTestAction* CMtfTestActionCompareAttachment::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters) + { + CMtfTestActionCompareAttachment* self = new(ELeave) CMtfTestActionCompareAttachment(aTestCase); + CleanupStack::PushL(self); + self->ConstructL(aActionParameters); + CleanupStack::Pop(); + return self; + } + + +CMtfTestActionCompareAttachment::CMtfTestActionCompareAttachment(CMtfTestCase& aTestCase) + : CMtfSynchronousTestAction(aTestCase) + { + } + + +CMtfTestActionCompareAttachment::~CMtfTestActionCompareAttachment() + { + } + + +void CMtfTestActionCompareAttachment::ExecuteActionL() + { + TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionCompareAttachment); + CMsvSession* paramSession = ObtainParameterReferenceL(TestCase(),ActionParameters().Parameter(0)); + TMsvId messageEntry = ObtainValueParameterL(TestCase(),ActionParameters().Parameter(1)); + TMsvAttachmentId attachId = ObtainValueParameterL(TestCase(),ActionParameters().Parameter(2)); + HBufC* dataFilePath = ObtainParameterReferenceL(TestCase(),ActionParameters().Parameter(3)); + + CMsvEntry* entry = paramSession->GetEntryL(messageEntry); + CleanupStack::PushL(entry); + + CMsvStore* store = entry->ReadStoreL(); + CleanupStack::PushL(store); + + MMsvAttachmentManager& manager = store->AttachmentManagerL(); + + RFile fileAttachment = manager.GetAttachmentFileL(attachId); + CleanupClosePushL(fileAttachment); + + CompareFileL(fileAttachment, *dataFilePath); + + CleanupStack::PopAndDestroy(&fileAttachment); + + CleanupStack::PopAndDestroy(2, entry); // store, entry + TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionCompareAttachment); + TestCase().ActionCompletedL(*this); + } + +void CMtfTestActionCompareAttachment::CompareFileL(RFile& aAttachment, const TDesC& aDataFilePath) + { + RFs fs; + User::LeaveIfError(fs.Connect()); + CleanupClosePushL(fs); + + RFile dataFile; + User::LeaveIfError(dataFile.Open(fs, aDataFilePath, EFileRead|EFileShareReadersOnly)); + CleanupClosePushL(fs); + + TInt fileSize = 0; + + User::LeaveIfError(dataFile.Size(fileSize)); + HBufC8* dataBuffer = HBufC8::NewLC(fileSize); + TPtr8 bufferPtr(dataBuffer->Des()); + + User::LeaveIfError(aAttachment.Size(fileSize)); + HBufC8* attachmentData = HBufC8::NewLC(fileSize); + TPtr8 attachmentPtr(attachmentData->Des()); + + TInt compare = attachmentPtr.Compare(bufferPtr); + if( compare != 0 ) + User::Leave(KErrCorrupt); + + CleanupStack::PopAndDestroy(4, &fs); // attachmentData, dataBuffer, dataFile, fs + } +