authenticationservices/authenticationserver/test/tAuthSvr/src/step_retrainplugin.cpp
changeset 102 deec7e509f66
parent 94 0e6c5a9328b5
child 108 ca9a0fc2f082
equal deleted inserted replaced
94:0e6c5a9328b5 102:deec7e509f66
     1 /*
       
     2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 * CTestStep derived implementation
       
    16 *
       
    17 */
       
    18 
       
    19  
       
    20 #include "tAuthSvrStep.h"
       
    21 
       
    22 #include "authserver/authclient.h"
       
    23 #include "authserver/authmgrclient.h"
       
    24 
       
    25 using namespace AuthServer;
       
    26 
       
    27 
       
    28 //====================================================================================================
       
    29 
       
    30 class CTrainActive : public CActive
       
    31     {
       
    32     public:    
       
    33     CTrainActive(RAuthMgrClient& aClient, TPluginId plugin1IdValue, TIdentityId iIdFromFile, TBool aStop = ETrue) : 
       
    34          CActive(EPriorityNormal),
       
    35          iClient(aClient),
       
    36 		 iResult(EFail),
       
    37          iRunCount(0),
       
    38          iStop(aStop),
       
    39          pluginIdVal(plugin1IdValue),         
       
    40          idToTrain (iIdFromFile)
       
    41         {
       
    42         CActiveScheduler::Add(this);
       
    43         }
       
    44     void doTrain() 
       
    45         {
       
    46 
       
    47         SetActive();		
       
    48 		TRequestStatus* status = &iStatus;		    
       
    49 		User::RequestComplete(status, KErrNone);
       
    50 		iRunCount = 0;
       
    51         }
       
    52         void DoCancel() 
       
    53         {
       
    54         }
       
    55      void RunL() 
       
    56         {
       
    57         iErr = iStatus.Int();
       
    58         if (iStatus.Int() != KErrNone)
       
    59             {
       
    60             }
       
    61 		switch (iRunCount)
       
    62 		  {
       
    63 		  case 0:
       
    64 				iStatus = KRequestPending;
       
    65 	            iClient.TrainPlugin(idToTrain, pluginIdVal, iStatus);
       
    66 				SetActive();
       
    67 			break;
       
    68 
       
    69    		  case 1:
       
    70 			iResult = iStatus.Int() == KErrNone ? EPass : EFail;
       
    71             iErr = iStatus.Int();
       
    72 			if (iStop)
       
    73                 {
       
    74                 CActiveScheduler::Stop();
       
    75                 }
       
    76 
       
    77 			break;
       
    78 
       
    79      	  default:
       
    80 			iResult = EFail;
       
    81 			
       
    82 			if (iStop)
       
    83 			    {
       
    84 			    CActiveScheduler::Stop();
       
    85 			    }
       
    86 		    }
       
    87 		  ++iRunCount;
       
    88           }
       
    89 	RAuthMgrClient& iClient;
       
    90 	TVerdict iResult;
       
    91 	TInt iRunCount;
       
    92     TBool iStop;
       
    93     TInt iErr;
       
    94     TPluginId pluginIdVal;
       
    95     TIdentityId idToTrain;
       
    96     };
       
    97     
       
    98 //====================================================================================================    
       
    99 CTRetrainPlugin::CTRetrainPlugin(CTAuthSvrServer& aParent): iParent(aParent)
       
   100 /**
       
   101   Constructor
       
   102  */
       
   103 	{
       
   104 	// Call base class method to set up the human readable name for logging
       
   105 	SetTestStepName(KTRetrainPlugin);
       
   106 	}
       
   107 
       
   108 CTRetrainPlugin::~CTRetrainPlugin()
       
   109 /**
       
   110   Destructor
       
   111  */
       
   112 	{}
       
   113 	
       
   114 TVerdict CTRetrainPlugin::doTestStepPreambleL()
       
   115 /**
       
   116   @return - TVerdict code
       
   117   Override of base class virtual
       
   118  */
       
   119 	{
       
   120 	//Call the parent class preamble, setting up the file server, etc
       
   121 	CTStepActSch::doTestStepPreambleL();
       
   122 	return TestStepResult();
       
   123 	}
       
   124 
       
   125 TVerdict CTRetrainPlugin::doTestStepL()
       
   126 /**
       
   127   @return - TVerdict code indicating the test step result    
       
   128  */
       
   129 	{
       
   130 	SetTestStepResult(EPass);
       
   131 
       
   132 __UHEAP_MARK;		// Check for memory leaks
       
   133 
       
   134 	//-----------------------------------------------------------------------------------------------------
       
   135 	InitAuthServerFromFileL();	// Set things like 'iSupportsDefaultData' and 'DefaultPlugin'
       
   136 	
       
   137 	CActiveScheduler::Install(iActSchd);
       
   138 	//Connect to the AuthServer	
       
   139 	AuthServer::RAuthMgrClient authMgrClient1;	
       
   140 	TInt connectVal = authMgrClient1.Connect();
       
   141 	if (KErrNotFound == connectVal)
       
   142 		{
       
   143 		//Retry after a delay
       
   144 		TTimeIntervalMicroSeconds32 timeInterval = 2000;	//2 Milliseconds
       
   145 		User::After(timeInterval);
       
   146 		connectVal = authMgrClient1.Connect();
       
   147 		}
       
   148 	if (KErrNone != connectVal)
       
   149 		{
       
   150 		ERR_PRINTF2(_L("Unable to start a session or other connection error. Err = %d"), connectVal);
       
   151 		User::LeaveIfError(connectVal);		
       
   152 		}	
       
   153 	
       
   154 	CleanupClosePushL(authMgrClient1);
       
   155 
       
   156 	//-----------------------------------------------------------------------------------------------------
       
   157 	//Check the username of the second identity and then attempt to set it.
       
   158 	//SetTestStepResult(checkAndSetUserNameL(ac, 0));
       
   159 
       
   160 	TBool statusAll = EFalse;
       
   161 	statusAll = CheckPluginStatusAllL(authMgrClient1);
       
   162 	
       
   163 	TRAPD(res2, RetrainPlugin(authMgrClient1) );
       
   164 	if(KErrNone != res2)
       
   165 		{
       
   166 		ERR_PRINTF2(_L("RetrainPluginL() performed a Leave with code %d"), res2 );
       
   167 		}
       
   168 		
       
   169 	TRAPD(res1, CheckSpecifiedPluginStatusL());
       
   170 	if(KErrNone != res1)
       
   171 		{
       
   172 		ERR_PRINTF2(_L("checkSpecifiedPluginStatusL() performed a Leave with code %d"), res1 );
       
   173 		}
       
   174 	
       
   175 	statusAll = CheckPluginStatusAllL(authMgrClient1);
       
   176 	if (!statusAll)
       
   177 		{
       
   178 		SetTestStepResult(EFail);
       
   179 		}
       
   180 	
       
   181 	CleanupStack::PopAndDestroy(&authMgrClient1);	// authClient1	
       
   182 	//Garbage collect the last previously destroyed implementation 
       
   183 	// and close the REComSession if no longer in use
       
   184 	REComSession::FinalClose(); 
       
   185 __UHEAP_MARKEND;
       
   186 	return TestStepResult();
       
   187 	}
       
   188 
       
   189 
       
   190 TVerdict CTRetrainPlugin::doTestStepPostambleL()
       
   191 /**
       
   192   @return - TVerdict code  
       
   193  */
       
   194 	{
       
   195 	//Call the parent postamble, releasing the file handle, etc
       
   196 	CTStepActSch::doTestStepPostambleL();	
       
   197 	return TestStepResult();
       
   198 	}
       
   199 
       
   200 /**
       
   201   Retrain the plugin and set the test step error value as required.
       
   202  */
       
   203 void CTRetrainPlugin::RetrainPlugin (RAuthMgrClient& mgc)
       
   204 	{	
       
   205 	
       
   206 	//If the pluginId is quoted in the ini file, check it's training status
       
   207 	TInt plugin1IdValue = 0;	
       
   208 	if (GetHexFromConfig(ConfigSection(),_L("plugin1Id"), plugin1IdValue) != EFalse) // the tag 'pluginId1' was present
       
   209 		{ 	
       
   210 	 	//Read the identityId to be trained
       
   211 	 	TIdentityId idToTrain = getLastAuthId();
       
   212 	 	INFO_PRINTF2(_L("Id to be (re)trained: %u"), idToTrain);
       
   213 	 	
       
   214 	 	//Train the plugin again with this identity. 	    
       
   215  	    CTrainActive active(mgc, plugin1IdValue, idToTrain);
       
   216 	    active.doTrain();		
       
   217 		CActiveScheduler::Start();		
       
   218 		
       
   219 		SetTestStepError(active.iErr);
       
   220 		
       
   221 		if (KErrAuthServPluginCancelled == active.iErr)
       
   222 			{
       
   223 			INFO_PRINTF1(_L("Training was cancelled."));
       
   224 			INFO_PRINTF1(_L("User entered trainingInput same as identifyingInput or an existing PIN."));
       
   225 			INFO_PRINTF1(_L("Or the Cancel code."));			
       
   226 			SetTestStepError(KErrAuthServPluginCancelled);
       
   227 			}
       
   228 		if (KErrAuthServPluginQuit == active.iErr)
       
   229 			{
       
   230 			INFO_PRINTF1(_L("Training was quit."));
       
   231 			INFO_PRINTF1(_L("User entered the Quit code as trainingInput."));						
       
   232 			SetTestStepError(KErrAuthServPluginQuit);
       
   233 			}
       
   234 		else if(EPass != active.iResult)
       
   235 			{
       
   236 			ERR_PRINTF3(_L("Training Result error = %d, iResult = %d\n"), active.iErr, active.iResult);			
       
   237 			SetTestStepError(active.iErr);
       
   238 			SetTestStepResult (EFail);
       
   239 			}
       
   240 		else if ((KErrNone == active.iErr) && (EPass == active.iResult))
       
   241 			{
       
   242 			INFO_PRINTF1(_L("(Re)train successful."));
       
   243 			SetTestStepResult (EPass);
       
   244 			}
       
   245 		else
       
   246 			{
       
   247 			ERR_PRINTF3(_L("Unexpected Training Result. error = %d, iResult = %d\n"), active.iErr, active.iResult);
       
   248 			SetTestStepError(active.iErr);
       
   249 			SetTestStepResult (EFail);
       
   250 			}		
       
   251 		}
       
   252 		
       
   253 	else
       
   254 		{
       
   255 		INFO_PRINTF1(_L("plugin1Id was not specified in the ini file"));
       
   256 		}
       
   257 	}