messagingfw/msgtestfw/TestActions/Capabilities/src/CMtfTestActionSendEMsvMtmCommand.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 //
       
    15 
       
    16 #include "CMtfTestActionSendEMsvMtmCommand.h"
       
    17 
       
    18 #include <e32std.h>
       
    19 #include <e32base.h>
       
    20 
       
    21 #include <msvipc.h>
       
    22 
       
    23 #include <smtpcmds.h>
       
    24 	// for KSMTPMTMIsConnected
       
    25 #include <mtclbase.h>
       
    26 	// For MTM's
       
    27 
       
    28 #include <smscmds.h>
       
    29 	// for ESmsMtmCommandReadSimParams
       
    30 
       
    31 #include "MCLIENT.H"
       
    32 #include "MSERVER.H"
       
    33 
       
    34 
       
    35 
       
    36 #include "CMtfTestCase.h"
       
    37 #include "CMtfTestActionParameters.h"
       
    38 
       
    39 #include "IPCCommandForCapsPermissions.h"
       
    40 #include "SendProxyClient.h"
       
    41 #include "SendProxyserver.h"
       
    42 
       
    43 
       
    44 /**
       
    45   Function : NewL
       
    46   Description : 
       
    47   @internalTechnology
       
    48   @param : aTestCase - CMtfTestCase for the CMtfTestAction base class
       
    49   @param : aActionParams - CMtfTestActionParameters 
       
    50   @return : CMtfTestAction* - a base class pointer to the newly created CMtfTestActionSendEMsvMtmCommand object
       
    51   @pre none
       
    52   @post none
       
    53 */
       
    54 CMtfTestAction* CMtfTestActionSendEMsvMtmCommand::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters)
       
    55 	{
       
    56 	CMtfTestActionSendEMsvMtmCommand* self = new (ELeave) CMtfTestActionSendEMsvMtmCommand(aTestCase);
       
    57 	CleanupStack::PushL(self);
       
    58 	self->ConstructL(aActionParameters);
       
    59 	CleanupStack::Pop(self);
       
    60 	return self;
       
    61 	}
       
    62 
       
    63 /**
       
    64   Function : CMtfTestActionSendEMsvMtmCommand
       
    65   Description : Constructor
       
    66   @internalTechnology
       
    67   @param : aTestCase - CMtfTestCase for the CMtfTestAction base class
       
    68   @return : N/A
       
    69   @pre none
       
    70   @post none
       
    71 */
       
    72 CMtfTestActionSendEMsvMtmCommand::CMtfTestActionSendEMsvMtmCommand(CMtfTestCase& aTestCase) : CMtfSynchronousTestAction(aTestCase)
       
    73 	{
       
    74 	}
       
    75 	
       
    76 /**
       
    77   Function : ~CMtfTestActionSendEMsvMtmCommand
       
    78   Description : Destructor
       
    79   @internalTechnology
       
    80   @param :
       
    81   @return : 
       
    82   @pre 
       
    83   @post 
       
    84 */
       
    85 CMtfTestActionSendEMsvMtmCommand::~CMtfTestActionSendEMsvMtmCommand()
       
    86 	{
       
    87 	}
       
    88 
       
    89 /**
       
    90   Function : ExecuteActionL
       
    91   Description : Entry point for the this test action in the test framework
       
    92   @internalTechnology
       
    93   @param : none
       
    94   @return : void
       
    95   @pre none 
       
    96   @post none
       
    97 */
       
    98 
       
    99 void MTMCommandReportPassOrFailForCapsPermissions( CMtfTestCase& aTestCase, const TDesC& aTestName, TInt aError ,TInt aPass )
       
   100 	{
       
   101 	
       
   102 	if ( aError == KErrDisconnected )
       
   103 		{
       
   104 		if (aPass==1)
       
   105 			{			
       
   106 			aTestCase.INFO_PRINTF2(_L("%S :: PASS :: Test Expected to Pass and Passes") , &aTestName );
       
   107 			aTestCase.SetTestStepResult(EPass);
       
   108 			}
       
   109 		else if (aPass==0)
       
   110 			{
       
   111 				
       
   112 			aTestCase.ERR_PRINTF2(_L("%S ::  FAIL :: Test Expected to Fail but Passes") , &aTestName  );
       
   113 			aTestCase.SetTestStepResult(EFail);
       
   114 			}
       
   115 		else
       
   116 			{
       
   117 			aTestCase.ERR_PRINTF2(_L("%S :: FAIL :: Should Specify PASS/FAIL") , &aTestName );
       
   118 			aTestCase.SetTestStepResult(EFail);						
       
   119 			}
       
   120 		}
       
   121 	else if ( aError == KErrPermissionDenied )
       
   122 		{
       
   123 		if (aPass==1)
       
   124 			{			
       
   125 			aTestCase.ERR_PRINTF2(_L("%S ::  FAIL :: Test Expected to Pass but Fails") , &aTestName  );
       
   126 			aTestCase.SetTestStepResult(EFail);
       
   127 			}
       
   128 		else if (aPass==0)
       
   129 			{
       
   130 			aTestCase.INFO_PRINTF2(_L("%S :: PASS :: Test Expected to Fail and Passes") , &aTestName );
       
   131 			aTestCase.SetTestStepResult(EPass);				
       
   132 			}
       
   133 		else
       
   134 			{
       
   135 			aTestCase.ERR_PRINTF2(_L("%S :: FAIL :: Should Specify PASS/FAIL") , &aTestName );
       
   136 			aTestCase.SetTestStepResult(EFail);						
       
   137 			}
       
   138 		}
       
   139 	else
       
   140 		{			
       
   141 		aTestCase.ERR_PRINTF3(_L("%S :: FAIL Unknown error (%d) ") ,  &aTestName , aError );
       
   142 		aTestCase.SetTestStepResult(EFail);						
       
   143 		}
       
   144 	
       
   145 	}
       
   146 
       
   147 void CdmaSmsMTMCommandReportPassOrFailForCapsPermissions( CMtfTestCase& aTestCase, const TDesC& aTestName, TInt aError ,TInt aPass )
       
   148 	{
       
   149 	
       
   150 	if ( aError == KErrNotSupported )
       
   151 		{
       
   152 		if (aPass==1)
       
   153 			{			
       
   154 			aTestCase.INFO_PRINTF2(_L("%S :: PASS :: Test Expected to Pass and Passes") , &aTestName );
       
   155 			aTestCase.SetTestStepResult(EPass);
       
   156 			}
       
   157 		else if (aPass==0)
       
   158 			{
       
   159 				
       
   160 			aTestCase.ERR_PRINTF2(_L("%S ::  FAIL :: Test Expected to Fail but Passes") , &aTestName  );
       
   161 			aTestCase.SetTestStepResult(EFail);
       
   162 			}
       
   163 		else
       
   164 			{
       
   165 			aTestCase.ERR_PRINTF2(_L("%S :: FAIL :: Should Specify PASS/FAIL") , &aTestName );
       
   166 			aTestCase.SetTestStepResult(EFail);						
       
   167 			}
       
   168 		}
       
   169 	else if ( aError == KErrPermissionDenied )
       
   170 		{
       
   171 		if (aPass==1)
       
   172 			{			
       
   173 			aTestCase.ERR_PRINTF2(_L("%S ::  FAIL :: Test Expected to Pass but Fails") , &aTestName  );
       
   174 			aTestCase.SetTestStepResult(EFail);
       
   175 			}
       
   176 		else if (aPass==0)
       
   177 			{
       
   178 			aTestCase.INFO_PRINTF2(_L("%S :: PASS :: Test Expected to Fail and Passes") , &aTestName );
       
   179 			aTestCase.SetTestStepResult(EPass);				
       
   180 			}
       
   181 		else
       
   182 			{
       
   183 			aTestCase.ERR_PRINTF2(_L("%S :: FAIL :: Should Specify PASS/FAIL") , &aTestName );
       
   184 			aTestCase.SetTestStepResult(EFail);						
       
   185 			}
       
   186 		}
       
   187 	else
       
   188 		{			
       
   189 		aTestCase.ERR_PRINTF3(_L("%S :: FAIL Unknown error (%d) ") ,  &aTestName , aError );
       
   190 		aTestCase.SetTestStepResult(EFail);						
       
   191 		}
       
   192 	}
       
   193 
       
   194 void CMtfTestActionSendEMsvMtmCommand::ExecuteActionL()
       
   195 	{
       
   196 	TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionSendEMsvMtmCommand);
       
   197 	// input params
       
   198 	
       
   199 	CBaseMtm* paramMtm = ObtainParameterReferenceL<CBaseMtm>(TestCase(),ActionParameters().Parameter(0));
       
   200 	TInt pass = ObtainValueParameterL<TInt>(TestCase(),ActionParameters().Parameter(1) );
       
   201 
       
   202 
       
   203 	RProxyServerSession RPSS;
       
   204 	TInt error = RPSS.Connect();
       
   205 	// Will auto start the server if not started.
       
   206 	
       
   207 	if (error!=KErrNone)
       
   208 		{
       
   209 		TestCase().ERR_PRINTF2(_L("%S :: FAIL :: Unable to start proxy server. !"), &KTestActionSendEMsvMtmCommand);
       
   210 		TestCase().SetTestStepResult(EFail);
       
   211 		}
       
   212 	else
       
   213 		{
       
   214 		TInt32 serverCaps;
       
   215 		RPSS.GetServerCapabilities(serverCaps);
       
   216 		TestCase().INFO_PRINTF2(_L("Proxy Server has capabilities: %x"), serverCaps);
       
   217 				
       
   218 		TInt error = 0;
       
   219 		CleanupClosePushL(RPSS);
       
   220 		
       
   221 		
       
   222 		HBufC8* buffer = HBufC8::NewLC(KMsvSessionBufferLength);
       
   223 
       
   224 		CMsvEntrySelection* entrySelection =  new (ELeave) (CMsvEntrySelection);
       
   225 		CleanupDeletePushL(entrySelection);
       
   226 		
       
   227 		entrySelection->SetReserveL(1);
       
   228 		
       
   229 		CMsvEntry& entry = paramMtm->Entry();
       
   230 		entrySelection->AppendL(entry.EntryId());			
       
   231 					
       
   232 		TMsvPackedOperation packedOperation(buffer);
       
   233 
       
   234 		if (paramMtm->Type() != KUidMsgTypeSMS)
       
   235 			{
       
   236 			error = packedOperation.Pack(*entrySelection, KSMTPMTMIsConnected);
       
   237 			}
       
   238 		else
       
   239 			{
       
   240 			error = packedOperation.Pack(*entrySelection, ESmsMtmCommandReadSimParams);
       
   241 			}
       
   242 
       
   243 		if (error)
       
   244 			{	
       
   245 			TestCase().ERR_PRINTF2(_L("%S :: FAIL :: Unable to pack the message") , &KTestActionSendEMsvMtmCommand );
       
   246 			TestCase().SetTestStepResult(EFail);						
       
   247 			User::LeaveIfError(error);			
       
   248 			}
       
   249 		
       
   250 		TMsvOp operationId=1;
       
   251 		TBuf8<32> param;
       
   252 		
       
   253 		
       
   254 		error=RPSS.SendReceive(EMsvCommandData, TIpcArgs(operationId, buffer, &param));
       
   255 		if (error)
       
   256 			{	
       
   257 			TestCase().ERR_PRINTF2(_L("%S :: FAIL :: Unable to send the message data") , &KTestActionSendEMsvMtmCommand );
       
   258 			TestCase().SetTestStepResult(EFail);						
       
   259 			User::LeaveIfError(error);			
       
   260 			}
       
   261 				
       
   262 		error=RPSS.SendReceive(EMsvMtmCommand , TIpcArgs(operationId) );
       
   263 			// We always expect 
       
   264 			//		KErrDisconnected (-36) as we have never made a connection to the SMTP server.
       
   265 			//   or KErrPermissionDenied if the caps checking finds problems.
       
   266 			
       
   267 				
       
   268 		if (paramMtm->Type() != KUidMsgTypeSMS)
       
   269 			{						
       
   270 			MTMCommandReportPassOrFailForCapsPermissions( TestCase(), KTestActionSendEMsvMtmCommand, error , pass );		
       
   271 
       
   272 			if ( (pass==0) && (error!=KErrDisconnected) )	
       
   273 				{ // expected to fail and does fail should not cancel.							
       
   274 				}
       
   275 			else
       
   276 				{					
       
   277 				TBuf8<64> complete;	
       
   278 				TInt ret =RPSS.SendReceive(EMsvCancelOperation , 
       
   279 								TIpcArgs(operationId,  &complete ) );
       
   280 					// Now lets cancel to stop any panic. We will have data in buffers etc that needs to cleaned out.
       
   281 					
       
   282 				if (ret>=0)
       
   283 					{ // We are happy some sort of length returned.
       
   284 					}
       
   285 				else if (ret<0)
       
   286 					{	
       
   287 					TestCase().ERR_PRINTF2(_L("%S :: FAIL :: Unable to cancel command") , &KTestActionSendEMsvMtmCommand );
       
   288 					TestCase().SetTestStepResult(EFail);						
       
   289 					User::LeaveIfError(error);			
       
   290 					}			
       
   291 				}
       
   292 			}
       
   293 		else
       
   294 			{ // Cdma Sms Mtm is used
       
   295 			CdmaSmsMTMCommandReportPassOrFailForCapsPermissions( TestCase(), KTestActionSendEMsvMtmCommand, error , pass );		
       
   296 
       
   297 			if (error == KErrNone)
       
   298 				{
       
   299 				// Now lets cancel to stop any panic, KErrNone is not expected
       
   300 				TBuf8<64> complete;	
       
   301 				TInt ret =RPSS.SendReceive(EMsvCancelOperation , 
       
   302 								TIpcArgs(operationId,  &complete ) );
       
   303 					
       
   304 				TestCase().ERR_PRINTF2(_L("%S :: FAIL :: Unable to cancel command") , &KTestActionSendEMsvMtmCommand );
       
   305 				TestCase().SetTestStepResult(EFail);						
       
   306 				}
       
   307 			}
       
   308 			
       
   309 		CleanupStack::Check(entrySelection);
       
   310 		CleanupStack::PopAndDestroy();		
       
   311 
       
   312 		CleanupStack::Check(buffer);
       
   313 		CleanupStack::PopAndDestroy();
       
   314 		
       
   315 		CleanupStack::Check(&RPSS);
       
   316 		CleanupStack::PopAndDestroy();			
       
   317 		}
       
   318 			
       
   319 		
       
   320 	TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionSendEMsvMtmCommand);
       
   321 	TestCase().ActionCompletedL(*this);
       
   322 			
       
   323 	}