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