authenticationservices/authenticationserver/test/tAuthSvr/src/step_IdentifyMultiple.cpp
changeset 29 ece3df019add
equal deleted inserted replaced
19:cd501b96611d 29:ece3df019add
       
     1 /*
       
     2 * Copyright (c) 2005-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 
       
    23 using namespace AuthServer;
       
    24 
       
    25 
       
    26 CTIdentifyMultiple::CTIdentifyMultiple()
       
    27 /**
       
    28  * Constructor
       
    29  */
       
    30 	{
       
    31 	// Call base class method to set up the human readable name for logging
       
    32 	SetTestStepName(KTIdentifyMultiple);
       
    33 	}
       
    34 
       
    35 CTIdentifyMultiple::~CTIdentifyMultiple()
       
    36 /**
       
    37  * Destructor
       
    38  */
       
    39 	{
       
    40 	 TInt i = iPluginIds.Count();
       
    41 	  while (i)
       
    42 		{
       
    43 		 REComSession::DestroyedImplementation(iPluginIds[--i]);
       
    44 		}
       
    45 	}
       
    46 	
       
    47 TVerdict CTIdentifyMultiple::doTestStepPreambleL()
       
    48 /**
       
    49  * @return - TVerdict code
       
    50  * Override of base class virtual
       
    51  */
       
    52 	{
       
    53 	SetTestStepResult(EPass);
       
    54 	
       
    55 	//Put in an initial value for the userResult (PIN) that will be used as input during the Identify() function
       
    56 	TPtrC userResultValue;
       
    57 	if(GetStringFromConfig(ConfigSection(),_L("userResult"), userResultValue) != EFalse) // the tag 'userResult ' was present
       
    58 		{
       
    59 		TDriveUnit sysDrive (RFs::GetSystemDrive());
       
    60 		TBuf<128> authSvrPolicyFile (sysDrive.Name());
       
    61 		authSvrPolicyFile.Append(KAuthSvrPolicyFile);
       
    62 		
       
    63 		CIniData* policyFile=NULL;
       
    64 		policyFile=CIniData::NewL(authSvrPolicyFile);
       
    65 		CleanupStack::PushL(policyFile);
       
    66 		//Update AuthSvrPolicy.ini, section: SectionOne, value:EnteredPinValue
       
    67 		writeToNamedConfig(policyFile, _L("SectionOne"), _L("EnteredPinValue"), userResultValue);
       
    68 		policyFile->WriteToFileL();
       
    69 
       
    70 		CleanupStack::PopAndDestroy(policyFile);
       
    71 
       
    72 		}
       
    73 	return TestStepResult();
       
    74 	}
       
    75 	
       
    76  
       
    77 TVerdict CTIdentifyMultiple::doTestStepL()
       
    78 /**
       
    79  * @return - TVerdict code
       
    80  * Override of base class pure virtual
       
    81  * 
       
    82  */
       
    83 	{	
       
    84 	//INFO_PRINTF1(_L("In IdentifyMultiple Step"));
       
    85 	SetTestStepResult(EPass);
       
    86 	
       
    87 	//If any test step leaves or panics, the test step thread exits and no further calls are made. 
       
    88 	if (TestStepResult() != EPass)
       
    89 		{
       
    90 		return TestStepResult();
       
    91 		}
       
    92 
       
    93 __UHEAP_MARK;		// Check for memory leaks
       
    94 
       
    95 	//-----------------------------------------------------------------------------------------------------
       
    96 	//Connect to the AuthServer
       
    97 	
       
    98 	
       
    99 	AuthServer::RAuthClient authClient1;
       
   100 	TInt connectVal = authClient1.Connect();
       
   101 	if (KErrNotFound == connectVal)
       
   102 		{
       
   103 		//Retry after a delay
       
   104 		TTimeIntervalMicroSeconds32 timeInterval = 2000;	//2 Milliseconds
       
   105 		User::After(timeInterval);
       
   106 		connectVal = authClient1.Connect();
       
   107 		}
       
   108 	if (KErrNone != connectVal)
       
   109 		{
       
   110 		ERR_PRINTF2(_L("Unable to start a session or other connection error. Err = %d"), connectVal);
       
   111 		User::LeaveIfError(connectVal);		
       
   112 		}	
       
   113 	CleanupClosePushL(authClient1);
       
   114 
       
   115 
       
   116 /*
       
   117 	//Call the Enumerate Identities API
       
   118 	TInt ret = KErrNone;
       
   119 	AuthServer::RIdentityIdArray idArray;	//Initialisation
       
   120 	TRAP(ret, authClient1.IdentitiesL(idArray));		// This will need to be updated if the function returns errors like KErrServerTerminated, etc 
       
   121 			
       
   122 	//Retrieve the expected information from the ini file
       
   123 	TInt expNumIdentities = 0;	
       
   124 	if(GetIntFromConfig(ConfigSection(),_L("NumIdentities"), expNumIdentities) != EFalse) // the tag 'NumIdentities' was present
       
   125 		{//Do the compare
       
   126 		if (idArray.Count() != expNumIdentities)
       
   127 			{
       
   128 			ERR_PRINTF2(_L("expNumIdentities differs from expected, Number of Identities = %d"), idArray.Count());			
       
   129 			SetTestStepResult(EFail);
       
   130 			}
       
   131 		}
       
   132 */
       
   133 ///*
       
   134 	//Run through the list of plugins and call the Identify function on each
       
   135 	//Get all implementations using  CAuthPluginInterface::ListImplementationsL()	
       
   136 	RImplInfoPtrArray infoArray;
       
   137 	// Note that a special cleanup function is required to reset and destroy
       
   138 	// all items in the array, and then close it.
       
   139 	TCleanupItem cleanup(CleanupEComArray, &infoArray);
       
   140 	CleanupStack::PushL(cleanup);
       
   141 	REComSession::ListImplementationsL(KCAuthPluginInterfaceUid, infoArray);
       
   142 	
       
   143 	TInt numPlugins = infoArray.Count();
       
   144 	INFO_PRINTF2(_L("Number of plugins: %d"), numPlugins);	
       
   145 	for (TInt i = 0;  i < numPlugins; i++)
       
   146 		{
       
   147 		//Retrieves default data for each
       
   148 		//TPtrC8 dataType = infoArray[i] ->DataType();
       
   149 		//TDesC displayName = infoArray[i] ->DisplayName();
       
   150 		
       
   151 		TInt data = HexString2Num(infoArray[i]->DataType());
       
   152 		INFO_PRINTF2(_L("Implementation Id: 0x%x"),infoArray[i]->ImplementationUid().iUid);
       
   153 		INFO_PRINTF2(_L("Display Name: %S"),&infoArray[i]->DisplayName());
       
   154 		INFO_PRINTF2(_L("Default Data: %x"),data);
       
   155 	    //INFO_PRINTF2(_L("Rom Only: %d"),impl[i]->RomOnly());
       
   156 		//INFO_PRINTF2(_L("Rom Based: %d"),impl[i]->RomBased());
       
   157 		   
       
   158 		//....
       
   159 		}	
       
   160 	// Clean up
       
   161 	CleanupStack::PopAndDestroy(&infoArray); //infoArray, results in a call to CleanupEComArray
       
   162 //*/
       
   163 
       
   164 	
       
   165 	//Read a cue from the ini file. A specific one in each section; the expected data is the same as the cue, so this minimizes
       
   166 	// the number of times the file is read
       
   167 	TInt fileCuePluginIdValue = 0;
       
   168 	TPluginId cuePluginIdValue = 0;
       
   169 	
       
   170 	//User::SetJustInTime(ETrue);
       
   171 		
       
   172 	if(GetHexFromConfig(ConfigSection(),_L("pluginId"), fileCuePluginIdValue) != EFalse) // the tag 'pluginId' was present
       
   173 		{
       
   174 		cuePluginIdValue = fileCuePluginIdValue;
       
   175 			
       
   176 		CAuthPluginInterface* plugin = 0;
       
   177 		TEComResolverParams resolverParams;
       
   178 		TBufC8<16> pluginIdTxt;
       
   179 			  
       
   180 		pluginIdTxt.Des().Format(_L8("%x"), cuePluginIdValue);
       
   181 			  
       
   182 		resolverParams.SetDataType(pluginIdTxt);
       
   183 			  
       
   184 		TAny* tempPlugin = 0; 
       
   185 		TUid Dtor_ID_Key = TUid::Null();
       
   186 		tempPlugin = 
       
   187 		REComSession::CreateImplementationL(KCAuthPluginInterfaceUid,
       
   188 		    							  	Dtor_ID_Key,
       
   189 											resolverParams,
       
   190 											KRomOnlyResolverUid);	
       
   191 		
       
   192 		plugin = reinterpret_cast<CAuthPluginInterface*>(tempPlugin);
       
   193 		CleanupStack::PushL(plugin);
       
   194 		iPluginIds.Append(Dtor_ID_Key);
       
   195 		//Call the identify function for this plugin
       
   196 		HBufC8* result1 = 0;
       
   197 
       
   198 		TRequestStatus reqStatus1 = KErrNone;
       
   199 		TIdentityId userId = 0;
       
   200 		
       
   201 		plugin->Identify(userId, KNullDesC(), result1, reqStatus1);
       
   202 		CleanupStack::PushL(result1);
       
   203 		
       
   204 		//if (reqStatus1.Int() == CAuthPluginInterface::KIdSuccess)
       
   205 		if (reqStatus1.Int() == KErrNone)
       
   206 			{
       
   207 			//Check that this is what was expected		
       
   208 			TBuf8<32> cueValue;		
       
   209 			_LIT8(KFormatValue2, "%x");
       
   210 			cueValue.Format(KFormatValue2, cuePluginIdValue);		
       
   211 			
       
   212 			TInt userIdValue = 0;
       
   213 			//Check to see if there was a value in the testExecute 'ini' file to compare with						
       
   214 			if(GetHexFromConfig(ConfigSection(),_L("userId"), userIdValue) != EFalse) // the tag 'userId' was present
       
   215 				{	
       
   216 				if(userId != userIdValue)
       
   217 					{
       
   218 					ERR_PRINTF3(_L("Id value returned differs from expected, Returned userId value= %d, Expected Id value = %d"), userId, userIdValue);
       
   219 					SetTestStepResult(EFail);				
       
   220 					}
       
   221 				}
       
   222 
       
   223 			TInt userResultValue = 0;				
       
   224 			if(GetIntFromConfig(ConfigSection(),_L("userResult"), userResultValue) != EFalse) // the tag 'userId' was present
       
   225 			
       
   226 				{
       
   227 				//Convert result1 to an integer
       
   228 				TPtr8 ptr = result1->Des();		// Convert the HBufC8 to a TPtr8				
       
   229 				TUint32 result2;
       
   230 				TLex8 input (ptr);
       
   231 				TRadix aRadix = EDecimal;
       
   232 				input.Val(result2, aRadix);
       
   233 				RDebug::Print(_L("Integer representation of result1 = %d, result1 itself = %S"), result2, result1);
       
   234 								
       
   235 				if(result2 != userResultValue)
       
   236 					{
       
   237 					_LIT(KErrMsg1, "result value returned differs from expected, Returned userId value= %d, \n Returned data value = %d. Expected data value = %d");						
       
   238 					ERR_PRINTF4(KErrMsg1, userId, result2, userResultValue);					
       
   239 					SetTestStepResult(EFail);				
       
   240 					}
       
   241 				}	
       
   242 			//In this case, we're expecting the 'data' returned to be the same as the pluginId value (cueValue)
       
   243 			else if (result1->Compare(cueValue) != 0)
       
   244 				{
       
   245 				TPtr8 ptr = result1->Des();		// Convert the HBufC8 to a TPtr8				
       
   246 				TUint32 result2;
       
   247 				TLex8 input (ptr);
       
   248 				TRadix aRadix = EDecimal;
       
   249 				input.Val(result2, aRadix);
       
   250 				
       
   251 				ERR_PRINTF3(_L("result value returned differs from expected, Returned userId value= %d, Returned data value = %d"), userId, result2);
       
   252 				SetTestStepResult(EFail);		
       
   253 				}
       
   254 			else
       
   255 				{
       
   256 				//No errors returned. The process was successful
       
   257 				SetTestStepResult(EPass);
       
   258 				}				
       
   259 			}		
       
   260 		else
       
   261 			{
       
   262 			ERR_PRINTF2(_L("An error occurred in the Identity function. RequestStatus = %d"), reqStatus1.Int());
       
   263 			SetTestStepResult(EFail);		
       
   264 			}
       
   265 		
       
   266 		CleanupStack::PopAndDestroy(result1);
       
   267 		CleanupStack::PopAndDestroy(plugin);
       
   268 		}			
       
   269 	
       
   270 	CleanupStack::PopAndDestroy(&authClient1);	// authClient1	
       
   271 	
       
   272 	REComSession::FinalClose(); 	//garbage collect the last previously destroyed implementation and close the REComSession if no longer in use
       
   273 	
       
   274  	__UHEAP_MARKEND;
       
   275 	return TestStepResult();	
       
   276 	}
       
   277