authenticationservices/authenticationserver/test/tauthplugins/step_interface.cpp
branchRCL_3
changeset 95 641f389e9157
equal deleted inserted replaced
92:f18401adf8e1 95:641f389e9157
       
     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 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "tauthpluginsstep.h"
       
    20 #include "consts.h"
       
    21 
       
    22 #include <test/testexecutelog.h>
       
    23 #include "authserver/authplugininterface.h"
       
    24 #include <e32std.h>
       
    25 #include <s32file.h>
       
    26 #include <ecom/implementationinformation.h>
       
    27 #include <ecom/ecom.h>
       
    28 #include <authserver/authpatchdata.h>
       
    29 #include <authserver/auth_srv_errs.h>
       
    30 #include <u32hal.h> 
       
    31 #include <e32svr.h>
       
    32 
       
    33 using namespace AuthServer;
       
    34 
       
    35 CTStepInterface::CTStepInterface()
       
    36 	{
       
    37 	SetTestStepName(KTStepInterface);
       
    38 	}
       
    39 
       
    40 CTStepInterface::~CTStepInterface()
       
    41 	{}
       
    42 
       
    43 TInt HexString2Num(const TDesC8& aStr)
       
    44   {
       
    45   	TInt data = 0;
       
    46 	TInt char2hex = 0;
       
    47 	TInt c = 0;
       
    48 	for (TInt i = 0 ; i < aStr.Length() ; ++i)
       
    49 	  {
       
    50 	  c = aStr[i];
       
    51 	  
       
    52 	  if (c < 'A')
       
    53 	    {
       
    54 	    char2hex='0';
       
    55 	    }
       
    56 	  else if (c < 'a')
       
    57 	    {
       
    58 	    char2hex=('A'-10);
       
    59 	    }
       
    60 	  else
       
    61 	    {
       
    62 	    char2hex=('a'-10);
       
    63 	    }
       
    64 	  data = data << 4;      
       
    65 	  data += aStr[i]-char2hex; 
       
    66 	  }
       
    67 	return data;
       
    68   }
       
    69 
       
    70 TVerdict CTStepInterface::doTestStepPreambleL()
       
    71 	{
       
    72 	TVerdict verdict = CTAuthPluginsStepBase::doTestStepPreambleL();
       
    73 	iActiveScheduler = new(ELeave) CActiveScheduler();
       
    74 	CActiveScheduler::Install(iActiveScheduler);
       
    75 	return verdict;
       
    76 	}
       
    77 
       
    78 TVerdict CTStepInterface::doTestStepPostambleL()
       
    79 	{
       
    80 	TVerdict verdict = CTAuthPluginsStepBase::doTestStepPostambleL();
       
    81 	delete iActiveScheduler;
       
    82 	return verdict;
       
    83 	}
       
    84 	
       
    85 TVerdict CTStepInterface::doTestStepL()
       
    86 	{
       
    87 	if (TestStepResult() != EPass)
       
    88 		{
       
    89 		return TestStepResult();
       
    90 		}
       
    91 __UHEAP_MARK;		// Check for memory leaks
       
    92 	
       
    93     TBool res = ETrue; 
       
    94     TBool tmp = ETrue; 
       
    95 	TInt  err = KErrNone;
       
    96 
       
    97 	RImplInfoPtrArray impl;
       
    98 	CleanupClosePushL(impl);
       
    99 	REComSession::ListImplementationsL(KCAuthPluginInterfaceUid, impl);
       
   100 	
       
   101 	TEST(tmp = impl.Count() > 0);
       
   102 	res = tmp && res;
       
   103 
       
   104 	
       
   105 	TInt data = HexString2Num(impl[0]->DataType());
       
   106 
       
   107     INFO_PRINTF2(_L("Implementation Id: 0x%x"),impl[0]->ImplementationUid().iUid);
       
   108     INFO_PRINTF2(_L("Display Name: %S"),&impl[0]->DisplayName());
       
   109     INFO_PRINTF2(_L("Default Data: %x"),data);
       
   110     INFO_PRINTF2(_L("Rom Only: %d"),impl[0]->RomOnly());
       
   111     INFO_PRINTF2(_L("Rom Based: %d"),impl[0]->RomBased());
       
   112 
       
   113 	CAuthPluginInterface* plugin = 0;
       
   114 
       
   115 	TEComResolverParams resolverParams;
       
   116 	TBufC8<16> pluginIdTxt;
       
   117 			  
       
   118 	pluginIdTxt.Des().Format(_L8("%x"), impl[0]->ImplementationUid().iUid);
       
   119 				  
       
   120 	resolverParams.SetDataType(pluginIdTxt);
       
   121 				  
       
   122 	TAny* tempPlugin = 0; 
       
   123 	TUid Dtor_ID_Key = TUid::Null();
       
   124   	TRAP(err, tempPlugin = 
       
   125 	REComSession::CreateImplementationL(KCAuthPluginInterfaceUid,
       
   126 										Dtor_ID_Key,
       
   127 										resolverParams));
       
   128   	
       
   129   	plugin = reinterpret_cast<CAuthPluginInterface*>(tempPlugin);	
       
   130 	if (plugin != 0)
       
   131 	    {
       
   132 	    
       
   133 	    	
       
   134 
       
   135 	    TRequestStatus t;
       
   136 	    TIdentityId id;
       
   137 
       
   138 	    HBufC8* data = 0; 
       
   139 	    plugin->Identify(id, KNullDesC(), data,t);
       
   140         CleanupStack::PushL(data);
       
   141         
       
   142 	    TEST(tmp = id == 22);
       
   143     	res = tmp && res;
       
   144 	    
       
   145 	    TEST(tmp = *data == KIdentifyData);
       
   146     	res = tmp && res;
       
   147 
       
   148 	    HBufC8* data2 = 0; 
       
   149         plugin->Train(id,data2,t);
       
   150         CleanupStack::PushL(data2);
       
   151         
       
   152         TEST(tmp = *data2 == KTrainData);
       
   153     	res = tmp && res;
       
   154     	
       
   155 	    HBufC8* data4 = 0; 
       
   156         TEST(tmp = plugin->DefaultData(0, data4) == KErrNotSupported);
       
   157     	res = tmp && res;
       
   158 
       
   159         TEST(tmp = plugin->Name() == KPluginName);
       
   160     	res = tmp && res;		
       
   161 
       
   162         TEST(tmp = plugin->Description() == KPluginDescription);
       
   163     	res = tmp && res;
       
   164 
       
   165         TEST(tmp = plugin->MinEntropy() == KEntropy);
       
   166     	res = tmp && res;
       
   167 
       
   168         TEST(tmp = plugin->FalsePositiveRate() == KFalsePos);
       
   169     	res = tmp && res;
       
   170 
       
   171         TEST(tmp = plugin->FalseNegativeRate() == KFalseNeg);
       
   172     	res = tmp && res;
       
   173 		
       
   174 	    CleanupStack::PopAndDestroy(2);
       
   175 	    delete plugin;
       
   176 	    REComSession::DestroyedImplementation(Dtor_ID_Key);
       
   177 	    }
       
   178 	else
       
   179 	    {
       
   180 	    ERR_PRINTF1(_L("Failed to load plugin"));
       
   181 	        
       
   182 	    res = false;
       
   183 	    }
       
   184 	    
       
   185 	 
       
   186 	TInt count = impl.Count();		
       
   187 	for (TInt i = 0; i < count; i++)
       
   188 		{
       
   189 
       
   190 		TEComResolverParams resolverParams;
       
   191 		TBufC8<16> pluginIdTxt;
       
   192 			  
       
   193 		pluginIdTxt.Des().Format(_L8("%x"), impl[i]->ImplementationUid().iUid);
       
   194 		//paste begin
       
   195 
       
   196     	pluginIdTxt.Des().UpperCase();
       
   197 		resolverParams.SetDataType(pluginIdTxt);
       
   198 			  
       
   199 		//To load plugins from sources other than ROM the patch 
       
   200 		// data KEnablePostMarketAuthenticationPlugins must be set to True.
       
   201 		TUint32 enablePostMarketPlugin = KEnablePostMarketAuthenticationPlugins;
       
   202 
       
   203 #ifdef __WINS__
       
   204     
       
   205 		// Default SymbianOS behavior is to only load auth plugins from ROM.
       
   206 		enablePostMarketPlugin = 0;
       
   207 
       
   208 		// For the emulator allow the constant to be patched via epoc.ini
       
   209 		UserSvr::HalFunction(EHalGroupEmulator, EEmulatorHalIntProperty,
       
   210        (TAny*)"KEnablePostMarketAuthenticationPlugins", &enablePostMarketPlugin); // read emulator property (if present)
       
   211 
       
   212 #endif
       
   213 
       
   214     	  TAny* tempPlugin = 0;
       
   215 		  TInt err = 0;
       
   216 		  TUid Dtor_ID_Key = TUid::Null();
       
   217 			  
       
   218 		 if(enablePostMarketPlugin == 0) 
       
   219 		  	{
       
   220 		  	TRAP(err, tempPlugin = 
       
   221 			REComSession::CreateImplementationL(KCAuthPluginInterfaceUid,
       
   222 												Dtor_ID_Key,
       
   223 												resolverParams,
       
   224 												KRomOnlyResolverUid));
       
   225 		  	}
       
   226 		  
       
   227 		  else
       
   228 		  	{
       
   229 		  	TRAP(err, tempPlugin = 
       
   230 			REComSession::CreateImplementationL(KCAuthPluginInterfaceUid,
       
   231 												Dtor_ID_Key,
       
   232 												resolverParams));
       
   233 		  	}
       
   234 		  
       
   235 		 if (err == KErrNotFound)
       
   236 		    {
       
   237 		    err = KErrAuthServNoSuchPlugin;  
       
   238 		    }
       
   239 		  User::LeaveIfError(err);
       
   240 		    						  	  	
       
   241 		plugin = reinterpret_cast<CAuthPluginInterface*>(tempPlugin);	
       
   242 
       
   243 	    INFO_PRINTF2(_L("ID:           0x%x"),plugin->Id());
       
   244 	    INFO_PRINTF2(_L("Name:         %S"),&plugin->Name());
       
   245 	    INFO_PRINTF2(_L("Description:  %S"),&plugin->Description());
       
   246 	    INFO_PRINTF2(_L("Type          %x"),plugin->Type());
       
   247 	    INFO_PRINTF2(_L("MinEntropy:   %d"),plugin->MinEntropy());
       
   248 	    INFO_PRINTF2(_L("FPR           %d"),plugin->FalsePositiveRate());
       
   249 	    INFO_PRINTF2(_L("FNR           %d"),plugin->FalseNegativeRate());
       
   250 	    INFO_PRINTF2(_L("IsActive      %d"),plugin->IsActive());
       
   251 		HBufC8* buf = 0;
       
   252 		INFO_PRINTF2(_L("DefaultData   %d"),plugin->DefaultData(0,buf));
       
   253 		if (buf) { delete buf; }
       
   254 		
       
   255 	    delete plugin;
       
   256 		delete impl[i];
       
   257 		REComSession::DestroyedImplementation(Dtor_ID_Key);
       
   258 		}
       
   259 	
       
   260 	CleanupStack::PopAndDestroy(&impl);
       
   261 	
       
   262 	REComSession::FinalClose();
       
   263 
       
   264 	SetTestStepResult(res ? EPass : EFail);
       
   265 	
       
   266 __UHEAP_MARKEND;	
       
   267 	return TestStepResult();
       
   268 	}
       
   269