messagingfw/msgtestfw/TestActions/Capabilities/src/CMtfTestActionSendEMsvChangeDrive.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 "CMtfTestActionSendEMsvChangeDrive.h"
       
    17 
       
    18 #include <e32std.h>
       
    19 #include <e32base.h>
       
    20 
       
    21 #include <msvipc.h>
       
    22 #include "MCLIENT.H"
       
    23 #include "MSERVER.H"
       
    24 
       
    25 
       
    26 #include "CMtfTestCase.h"
       
    27 #include "CMtfTestActionParameters.h"
       
    28 
       
    29 #include "IPCCommandForCapsPermissions.h"
       
    30 #include "SendProxyClient.h"
       
    31 #include "SendProxyserver.h"
       
    32 
       
    33 
       
    34 /**
       
    35   Function : NewL
       
    36   Description : 
       
    37   @internalTechnology
       
    38   @param : aTestCase - CMtfTestCase for the CMtfTestAction base class
       
    39   @param : aActionParams - CMtfTestActionParameters 
       
    40   @return : CMtfTestAction* - a base class pointer to the newly created CMtfTestActionSendEMsvChangeDrive object
       
    41   @pre none
       
    42   @post none
       
    43 */
       
    44 CMtfTestAction* CMtfTestActionSendEMsvChangeDrive::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters)
       
    45 	{
       
    46 	CMtfTestActionSendEMsvChangeDrive* self = new (ELeave) CMtfTestActionSendEMsvChangeDrive(aTestCase);
       
    47 	CleanupStack::PushL(self);
       
    48 	self->ConstructL(aActionParameters);
       
    49 	CleanupStack::Pop(self);
       
    50 	return self;
       
    51 	}
       
    52 
       
    53 /**
       
    54   Function : CMtfTestActionSendEMsvChangeDrive
       
    55   Description : Constructor
       
    56   @internalTechnology
       
    57   @param : aTestCase - CMtfTestCase for the CMtfTestAction base class
       
    58   @return : N/A
       
    59   @pre none
       
    60   @post none
       
    61 */
       
    62 CMtfTestActionSendEMsvChangeDrive::CMtfTestActionSendEMsvChangeDrive(CMtfTestCase& aTestCase) : CMtfSynchronousTestAction(aTestCase)
       
    63 	{
       
    64 	}
       
    65 	
       
    66 /**
       
    67   Function : ~CMtfTestActionSendEMsvChangeDrive
       
    68   Description : Destructor
       
    69   @internalTechnology
       
    70   @param :
       
    71   @return : 
       
    72   @pre 
       
    73   @post 
       
    74 */
       
    75 CMtfTestActionSendEMsvChangeDrive::~CMtfTestActionSendEMsvChangeDrive()
       
    76 	{
       
    77 	}
       
    78 
       
    79 /**
       
    80   Function : ExecuteActionL
       
    81   Description : Entry point for the this test action in the test framework
       
    82   @internalTechnology
       
    83   @param : none
       
    84   @return : void
       
    85   @pre none 
       
    86   @post none
       
    87 */
       
    88 
       
    89 
       
    90 
       
    91 TBool Swap( CMtfTestCase& aTestCase, RProxyServerSession& RPSS, TMsvOp operationId , TInt drive  )
       
    92 	{
       
    93 	
       
    94 	TInt error = 0;				
       
    95 	error = RPSS.SendReceiveProxyAsync(EMsvChangeDrive , TIpcArgs(operationId, drive));
       
    96 
       
    97 	if (error)
       
    98 		{
       
    99 		aTestCase.ERR_PRINTF2(_L("%S :: FAIL :: Unable to to swap drive. Potential all following tests broken.!!!!!! ") , &KTestActionSendEMsvChangeDrive );				
       
   100 		return EFalse;
       
   101 		}
       
   102 	
       
   103 	TMsvLocalOperationProgress progress;
       
   104 	TPckg<TMsvLocalOperationProgress> progressPack(progress);
       
   105 	TInt ret=RPSS.SendReceive(EMsvOperationCompletion , TIpcArgs(operationId, &progressPack));
       
   106 		// Clean up to stop panic.
       
   107 				
       
   108 	if (ret < 0)
       
   109 		{ // Should prbably never happen.
       
   110 		aTestCase.ERR_PRINTF2(_L("%S :: FAIL :: Problem with swap drive. Potential all following tests broken.!!!!!! ") , &KTestActionSendEMsvChangeDrive );				
       
   111 		return EFalse;
       
   112 		}
       
   113 		
       
   114 	return ETrue;
       
   115 	}
       
   116 
       
   117 
       
   118 
       
   119 TInt SwapTest(CMtfTestCase& aTestCase, RProxyServerSession& RPSS, TMsvOp operationId , TInt drive , TInt pass )
       
   120 	{
       
   121 
       
   122 	
       
   123 	TInt swapped=EFalse;
       
   124 	
       
   125 	TInt error = 0;				
       
   126 	error = RPSS.SendReceiveProxyAsync(EMsvChangeDrive , TIpcArgs(operationId, drive));
       
   127 		// This will have completed by now. 
       
   128 		// IMPORTANT 
       
   129 		// Uses the E drive to switch to so need to ensure one is set up. 
       
   130 		// And it must be read/write.
       
   131 	IPCCommandReportPassOrFailForCapsPermissions( aTestCase, KTestActionSendEMsvChangeDrive, error , pass );
       
   132 	
       
   133 	
       
   134 	if ( (pass == 0) && (error!=KErrNone ) )
       
   135 		{ // We expected it to fail and it did so do nothing else basically ignore the error. 
       
   136 		  // Appears to be no need to do EMsvOperationCompletion.
       
   137 		swapped=EFalse;
       
   138 		}
       
   139 	else
       
   140 		{
       
   141 
       
   142 		TMsvLocalOperationProgress progress;
       
   143 		TPckg<TMsvLocalOperationProgress> progressPack(progress);
       
   144 		TInt ret=RPSS.SendReceive(EMsvOperationCompletion , TIpcArgs(operationId, &progressPack));
       
   145 			// We need to indicate that we have finished and clean up otherwise we will get 
       
   146 			// a panic.
       
   147 			
       
   148 		if (ret>0)
       
   149 			{ // We are happy some sort of length returned.
       
   150 		  	swapped=ETrue;
       
   151 			}
       
   152 		else if (ret<0)
       
   153 			{	
       
   154 			aTestCase.ERR_PRINTF2(_L("%S :: FAIL :: Unable to finish sending the message") , &KTestActionSendEMsvChangeDrive );
       
   155 			aTestCase.SetTestStepResult(EFail);						
       
   156 		  	swapped=EFalse;
       
   157 			}
       
   158 		else 
       
   159 			{
       
   160 		  	swapped=ETrue;
       
   161 			}
       
   162 		}			
       
   163 			
       
   164 	return swapped;
       
   165 	}
       
   166 
       
   167 
       
   168 void CMtfTestActionSendEMsvChangeDrive::ExecuteActionL()
       
   169 	{
       
   170 	TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionSendEMsvChangeDrive);
       
   171 	// input params
       
   172 	TInt drive_start = ObtainValueParameterL<TInt>(TestCase(),ActionParameters().Parameter(0) );
       
   173 	TInt drive_end = ObtainValueParameterL<TInt>(TestCase(),ActionParameters().Parameter(1) );
       
   174 	TInt pass = ObtainValueParameterL<TInt>(TestCase(),ActionParameters().Parameter(2) );
       
   175 
       
   176 	TestCase().SetTestStepResult(EFail);
       
   177 		// Assume failure.
       
   178 
       
   179 	RProxyServerSession RPSS;
       
   180 	TInt error = RPSS.Connect();
       
   181 	// Will auto start the server if not started.
       
   182 	
       
   183 	TInt swapped=0;
       
   184 	
       
   185 	if (error!=KErrNone)
       
   186 		{
       
   187 		TestCase().ERR_PRINTF1(_L("CMtfTestActionSendEMsvChangeDrive :: Unable to start proxy server. !"));
       
   188 		TestCase().SetTestStepResult(EFail);
       
   189 		}
       
   190 	else
       
   191 		{
       
   192 		TInt32 serverCaps;
       
   193 		RPSS.GetServerCapabilities(serverCaps);
       
   194 		TestCase().INFO_PRINTF2(_L("Proxy Server has capabilities: %x"), serverCaps);
       
   195 		
       
   196 				
       
   197 		TMsvOp operationId=1;
       
   198 						
       
   199 		TInt initial_drive = RPSS.SendReceive(EMsvGetMessageDrive, TIpcArgs() );		
       
   200 		if (initial_drive==drive_start)
       
   201 			{ // On the drive we want to start from.
       
   202 			
       
   203 			operationId++;
       
   204 			swapped=SwapTest(TestCase() , RPSS, operationId, drive_end, pass);
       
   205 				// Now do the test.
       
   206 			}				
       
   207 		else
       
   208 			{ // We are on a different drive than the one we want to start from.
       
   209 			
       
   210 			operationId++;
       
   211 			swapped=SwapTest(TestCase() , RPSS, operationId, drive_start, pass); 
       
   212 			
       
   213 			if (swapped)
       
   214 				{ 				
       
   215 				operationId++;
       
   216 				SwapTest(TestCase() , RPSS, operationId, drive_end, pass); // Now do the switch.
       
   217 					// Just in case something strange.
       
   218 				}
       
   219 			}
       
   220 			
       
   221 
       
   222 		TInt current_drive = RPSS.SendReceive(EMsvGetMessageDrive, TIpcArgs() );
       
   223 
       
   224 		if ( (swapped) && (initial_drive!=current_drive) )
       
   225 			{ // Swap back. Try not to disturb the environment othewise this will break all the other tests.
       
   226 			operationId++;
       
   227 			Swap( TestCase(), RPSS, operationId, initial_drive);
       
   228 			}			
       
   229 		}
       
   230 		
       
   231 	TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionSendEMsvChangeDrive);
       
   232 	TestCase().ActionCompletedL(*this);
       
   233 	}