diff -r 9f5ae1728557 -r db3f5fa34ec7 messagingfw/msgtestfw/TestActions/Sms/src/CMtfTestActionReceiveSmsMessages.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/messagingfw/msgtestfw/TestActions/Sms/src/CMtfTestActionReceiveSmsMessages.cpp Wed Nov 03 22:41:46 2010 +0530 @@ -0,0 +1,127 @@ +// Copyright (c) 2003-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] +// ReceiveSmsMessages +// [Action Parameters] +// CMsvSession Session : Reference to the session. +// TInt Counter : Value of expected number of messages +// [Action Description] +// Receives a specified number of sms messages. It waits for a new +// message to appear in the inbox and decrements a count. It completes +// once the required number of messages has been received. +// [APIs Used] +// CMsvEntry::SetEntryL +// CMsvEntry::AddObserverL +// __ACTION_INFO_END__ +// +// + +/** + @file +*/ + + +#include +#include + +#include "CMtfTestActionReceiveSmsMessages.h" +#include "CMtfTestCase.h" +#include "CMtfTestActionParameters.h" + +CMtfTestAction* CMtfTestActionReceiveSmsMessages::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters) + { + CMtfTestActionReceiveSmsMessages* self = new (ELeave) CMtfTestActionReceiveSmsMessages(aTestCase); + CleanupStack::PushL(self); + self->ConstructL(aActionParameters); + CleanupStack::Pop(); + return self; + } + +CMtfTestActionReceiveSmsMessages::CMtfTestActionReceiveSmsMessages(CMtfTestCase& aTestCase) + : CMtfTestAction(aTestCase) + { + } + +CMtfTestActionReceiveSmsMessages::~CMtfTestActionReceiveSmsMessages() + { + Cancel(); + iMsventry->RemoveObserver(*this); + delete iMsventry; + } + +void CMtfTestActionReceiveSmsMessages::ExecuteActionL() + { + TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionReceiveSmsMessages); + CMsvSession* paramSession = ObtainParameterReferenceL(TestCase(),ActionParameters().Parameter(0)); + iNumberOfMessages = ObtainValueParameterL(TestCase(),ActionParameters().Parameter(1)); + iMsventry = CMsvEntry::NewL(*paramSession,KMsvGlobalInBoxIndexEntryId,TMsvSelectionOrdering()); + iMsventry->AddObserverL(*this); + iStatus = KRequestPending; + CActiveScheduler::Add(this); + SetActive(); + TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionReceiveSmsMessages); + } + +void CMtfTestActionReceiveSmsMessages::DoCancel() + { + TRequestStatus *status=&iStatus; + User::RequestComplete(status,KErrCancel); + } + + void CMtfTestActionReceiveSmsMessages::RunL() + { + TestCase().ActionCompletedL(*this); + } + +void CMtfTestActionReceiveSmsMessages::HandleEntryEventL(TMsvEntryEvent aEvent, TAny* aArg1, TAny* /* aArg2*/, TAny* /*aArg3*/) +/** + * Called by CMsvEntry when a messaging event has occurred. It is used here to find out if any new messages have been created. +*/ + { + CMsvEntrySelection* entries = NULL; + switch (aEvent) + { + case EMsvNewChildren: + if(aArg1 == NULL) + { + User::Leave(KErrGeneral); + } + else{ + entries = static_cast(aArg1); + } + break; + + default: + User::Leave(KErrGeneral); + } + + iNumberOfMessages-=entries->Count(); + if(iNumberOfMessages>0) + { + return; + } + else if(iNumberOfMessages == 0) + { + TRequestStatus *status=&iStatus; + User::RequestComplete(status,KErrNone); + } + else if(iNumberOfMessages<0) + { + User::Leave(KErrGeneral); + } + } + + +