messagingfw/msgtestfw/TestActions/Sms/src/CMtfTestActionCheckMessageSendingState.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 // CheckMessageSendingState
       
    17 // [Action Parameters]
       
    18 // CMsvSession  Session							<input>: Reference to the session.
       
    19 // TMsvId		Message							<input>: Message entry ID to check the sending state
       
    20 // TInt		    ExpectedSendingState  		 	<input>: Expected sending state of the message
       
    21 // TInt		    ExpectedPendingConditionMet   	<input>: Expected pending condition met state of the message
       
    22 // TInt		    ExpectedScheduled   			<input>: Expected scheduled state of the message
       
    23 // TInt		    ExpectedFailed   				<input>: Expected failed state of the message
       
    24 // TInt			TimeOut							<input>: Time out value in seconds
       
    25 // [Action Description]
       
    26 // Wait for an expected entry state (Sent, Rescheduled, Failed, etc.).  
       
    27 // If a state does not happen within the time out period, this action will fail.
       
    28 // [APIs Used]
       
    29 // CMsvSession::GetEntryL
       
    30 // CMsvEntry::Entry
       
    31 // TMsvEntry::SendingState
       
    32 // TMsvEntry::PendingConditionMet
       
    33 // TMsvEntry::Failed
       
    34 // TMsvEntry::Scheduled
       
    35 // __ACTION_INFO_END__
       
    36 // 
       
    37 //
       
    38 
       
    39 
       
    40 #include <msvapi.h>
       
    41 #include <msvstd.h>
       
    42 
       
    43 #include "CMtfTestActionCheckMessageSendingState.h"
       
    44 #include "CMtfTestCase.h"
       
    45 #include "CMtfTestActionParameters.h"
       
    46 
       
    47 const TInt KOneSecond = 1000000;
       
    48 CMtfTestAction* CMtfTestActionCheckMessageSendingState::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters)
       
    49 	{
       
    50  	CMtfTestActionCheckMessageSendingState* self = new (ELeave) CMtfTestActionCheckMessageSendingState(aTestCase);
       
    51 	CleanupStack::PushL(self);
       
    52 	self->ConstructL(aActionParameters);
       
    53 	CleanupStack::Pop(self);
       
    54 	return self;
       
    55 	}
       
    56 
       
    57 CMtfTestActionCheckMessageSendingState::CMtfTestActionCheckMessageSendingState(CMtfTestCase& aTestCase)
       
    58 	: CMtfTestAction(aTestCase)
       
    59 	{
       
    60 	}
       
    61 
       
    62 CMtfTestActionCheckMessageSendingState::~CMtfTestActionCheckMessageSendingState()
       
    63 	{
       
    64 	Cancel();
       
    65 	iExpireTimer.Close();
       
    66 	//Note: CMsvSession has already been destroyed at this point by the framework,
       
    67 	//so, we could not delete the iMsvEntry here.  
       
    68 	}
       
    69 
       
    70 void CMtfTestActionCheckMessageSendingState::ExecuteActionL()
       
    71 	{
       
    72 	TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionCheckMessageSendingState);
       
    73 	if(ActionParameters().Count() != 7)
       
    74 		{
       
    75 		TestCase().ERR_PRINTF1( _L("CMtfTestActionCheckMessageSendingState param count error !") );
       
    76 		User::Leave(KErrArgument);
       
    77 		}
       
    78 		
       
    79     CMsvSession* paramSession = ObtainParameterReferenceL<CMsvSession>(TestCase(),ActionParameters().Parameter(0));
       
    80 	TMsvId message= ObtainValueParameterL<TMsvId>(TestCase(),ActionParameters().Parameter(1));
       
    81 	iMsvEntry = CMsvEntry::NewL(*paramSession,message,TMsvSelectionOrdering());
       
    82 		
       
    83 	iExpectedSendingState = ObtainValueParameterL<TInt>(TestCase(),ActionParameters().Parameter(2));
       
    84 	iExpectedPendingConditionMet = ObtainValueParameterL<TBool>(TestCase(),ActionParameters().Parameter(3));
       
    85 	iExpectedScheduled = ObtainValueParameterL<TBool>(TestCase(),ActionParameters().Parameter(4));
       
    86 	iExpectedFailed = ObtainValueParameterL<TBool>(TestCase(),ActionParameters().Parameter(5));
       
    87 											
       
    88 	TestCase().INFO_PRINTF5(_L("CMtfTestActionCheckMessageSendingState::expected states: %d, %d, %d, %d"), 
       
    89 									iExpectedSendingState, 
       
    90 									iExpectedScheduled, 
       
    91 									iExpectedPendingConditionMet, 
       
    92 									iExpectedFailed);
       
    93 									
       
    94 	TTimeIntervalMicroSeconds32 timeout = ObtainValueParameterL<TInt>(TestCase(),ActionParameters().Parameter(6)) * KOneSecond;
       
    95 	
       
    96 	if(IsMessageStateMet())
       
    97 		{
       
    98 		TestCase().ActionCompletedL(*this);
       
    99 		}
       
   100 	else
       
   101 		{
       
   102 		iMsvEntry->AddObserverL(*this);
       
   103 		User::LeaveIfError(iExpireTimer.CreateLocal());
       
   104 		iExpireTimer.After(iStatus, timeout);
       
   105 		CActiveScheduler::Add(this);
       
   106 		SetActive();	
       
   107 		}	
       
   108 		
       
   109 	TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionCheckMessageSendingState);
       
   110 	}
       
   111 
       
   112 void CMtfTestActionCheckMessageSendingState::DoCancel()
       
   113 	{
       
   114 	iExpireTimer.Cancel();
       
   115 	delete iMsvEntry;
       
   116 	iMsvEntry = NULL;
       
   117 	}
       
   118 
       
   119  void CMtfTestActionCheckMessageSendingState::RunL()
       
   120 	{
       
   121 	TestCase().ERR_PRINTF1( _L("CMtfTestActionCheckMessageSendingState timed out !") );
       
   122 	User::Leave(KErrTimedOut);
       
   123 	}
       
   124 
       
   125 /**
       
   126 Called by CMsvEntry when a messaging event has occurred. It is used here 
       
   127 to check the message sending state
       
   128 */
       
   129 void CMtfTestActionCheckMessageSendingState::HandleEntryEventL(TMsvEntryEvent aEvent, TAny* /* aArg1*/, TAny* /* aArg2*/, TAny* /*aArg3*/)
       
   130 	{
       
   131 	if(aEvent == EMsvEntryChanged)
       
   132 		{
       
   133 		if(IsMessageStateMet())
       
   134 			{
       
   135 			Cancel();
       
   136 			TestCase().ActionCompletedL(*this);
       
   137 			}
       
   138 		}
       
   139 	}
       
   140 
       
   141 
       
   142 TBool CMtfTestActionCheckMessageSendingState::IsMessageStateMet()
       
   143 	{
       
   144 	TMsvEntry entry = iMsvEntry->Entry();
       
   145 	TInt sendingState = entry.SendingState();
       
   146 	TInt scheduled = entry.Scheduled() ? 1:0;
       
   147 	TInt failed = entry.Failed() ? 1: 0;
       
   148 		
       
   149 	TInt pendingConditionMet = entry.PendingConditions() ? 1:0;
       
   150 	TestCase().Logger().WriteFormat(_L("CMtfTestActionCheckMessageSendingState::IsMessageStateMet state: %d, %d, %d, %d"), sendingState, scheduled, pendingConditionMet, failed);
       
   151 	if(pendingConditionMet != iExpectedPendingConditionMet)
       
   152 		{
       
   153 		return EFalse;
       
   154 		}
       
   155 	if(sendingState == iExpectedSendingState &&
       
   156 		scheduled == iExpectedScheduled && 
       
   157 		failed == iExpectedFailed)
       
   158 		{
       
   159 		TestCase().Logger().Write(_L("CMtfTestActionCheckMessageSendingState::IsMessageStateMet Message state met"));
       
   160 		return ETrue;
       
   161 		}
       
   162 	return EFalse;			
       
   163 	}