crypto/weakcryptospi/test/tcryptospi/src/plugincharsrandomstep.cpp
changeset 8 35751d3474b7
equal deleted inserted replaced
2:675a964f4eb5 8:35751d3474b7
       
     1 /*
       
     2 * Copyright (c) 2007-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 /**
       
    20  @file
       
    21  @internalTechnology
       
    22 */
       
    23  
       
    24 #include "plugincharsrandomstep.h"
       
    25 #include "plugincharschecker.h"
       
    26 
       
    27 #include <cryptospi/cryptorandomapi.h>
       
    28 
       
    29 using namespace CryptoSpi;
       
    30 
       
    31 CPluginCharsRandomStep::~CPluginCharsRandomStep()
       
    32 	{
       
    33 	}
       
    34 
       
    35 CPluginCharsRandomStep::CPluginCharsRandomStep()
       
    36 	{
       
    37 	SetTestStepName(KPluginCharsRandomStep);
       
    38 	}
       
    39 
       
    40 TVerdict CPluginCharsRandomStep::doTestStepPreambleL()
       
    41 	{
       
    42 	SetTestStepResult(EPass);
       
    43 	return TestStepResult();
       
    44 	}
       
    45 				
       
    46 TVerdict CPluginCharsRandomStep::doTestStepL()
       
    47 	{
       
    48 	
       
    49 	INFO_PRINTF1(_L("Plugin Characteristics - Random Chracteristics"));
       
    50 	INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
       
    51 		
       
    52 	if (TestStepResult()==EPass)
       
    53 		{
       
    54 		
       
    55 		//Assume faliure, unless all is successful
       
    56 		SetTestStepResult(EFail);
       
    57 		
       
    58 		TVariantPtrC algorithmUid;
       
    59 					
       
    60 		//Each of the individual parameters required to create the Random object
       
    61 		//are read in from the specified INI configuration file	
       
    62 		if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid))
       
    63 			{
       
    64 			ERR_PRINTF1(_L("** .INI Error: Random Arguments Not Located **"));
       
    65 			SetTestStepResult(EFail);
       
    66 			}
       
    67 		else
       
    68 			{
       
    69 			CryptoSpi::CRandom* randomImpl = NULL; 
       
    70 			
       
    71 			TRAPD_LOG(err,CRandomFactory::CreateRandomL(randomImpl,
       
    72 												algorithmUid,
       
    73 												NULL));
       
    74 	
       
    75 			if(randomImpl && (err == KErrNone))
       
    76 				{
       
    77 				
       
    78 				CleanupStack::PushL(randomImpl);
       
    79 				
       
    80 				INFO_PRINTF1(_L("** Successfully Loaded Random Object **"));
       
    81 			
       
    82 				//Define a pointer of type TCharacteristics in order to store the random
       
    83 				//object's characterisctics	
       
    84 				const TCharacteristics* chars(NULL);
       
    85 							
       
    86 				//Retrieve the characteristics for the random implementation object
       
    87 				TRAP_LOG(err, randomImpl->GetCharacteristicsL(chars));
       
    88 				
       
    89 				//Static cast the characteristics to type TRandomCharacteristics
       
    90 				const TRandomCharacteristics* randomChars = static_cast<const TRandomCharacteristics*>(chars);
       
    91 				
       
    92 				//Retrieve all the Common characteristics that are required for all test cases
       
    93 				TVariantPtrC exInterfaceUid;
       
    94 				TVariantPtrC exAlgorithmUid;
       
    95 				TVariantPtrC exImplementationUid;
       
    96 				TVariantPtrC exCreatorName;
       
    97 				TBool exFIPSApproved;
       
    98 				TBool exHardwareSupported;
       
    99 				TInt exMaxConcurrencySupported;
       
   100 				TVariantPtrC exAlgorithmName;
       
   101 				TInt exLatency;
       
   102 				TInt exThroughput;
       
   103 				
       
   104 				//Retrieve all the Random characteristics that are required for all test cases
       
   105 				TInt exRandomBlockingMode;
       
   106 							
       
   107 				if(!GetStringFromConfig(ConfigSection(),KConfigExInterfaceUid,exInterfaceUid) ||
       
   108 					!GetStringFromConfig(ConfigSection(),KConfigExAlgorithmUid,exAlgorithmUid) ||
       
   109 					!GetStringFromConfig(ConfigSection(),KConfigExImplementationUid,exImplementationUid) ||
       
   110 					!GetStringFromConfig(ConfigSection(),KConfigExCreatorName,exCreatorName) ||
       
   111 					!GetBoolFromConfig(ConfigSection(),KConfigExFIPSApproved,exFIPSApproved) ||
       
   112 					!GetBoolFromConfig(ConfigSection(),KConfigExHardwareSupport,exHardwareSupported) ||
       
   113 					!GetIntFromConfig(ConfigSection(),KConfigExMaxConcurrency,exMaxConcurrencySupported) ||
       
   114 					!GetStringFromConfig(ConfigSection(),KConfigExAlgorithmName,exAlgorithmName) ||
       
   115 					!GetIntFromConfig(ConfigSection(),KConfigExLatency,exLatency) ||
       
   116 					!GetIntFromConfig(ConfigSection(),KConfigExThroughput,exThroughput) ||
       
   117 					!GetIntFromConfig(ConfigSection(),KConfigExBlockingMode,exRandomBlockingMode))
       
   118 					{
       
   119 					ERR_PRINTF1(_L("** .INI Error: Expected Random/Common Characteristic Arguments Not Located **"));
       
   120 					SetTestStepResult(EFail);
       
   121 					}
       
   122 				else
       
   123 					{
       
   124 					INFO_PRINTF1(_L("** Checking Random/Common Characteristics.... **"));
       
   125 					
       
   126 					CPluginCharsChecker* pluginCheck = CPluginCharsChecker::NewLC();
       
   127 					
       
   128 					//Retrieve the Common Characteristics from TRandomCharacteristics 
       
   129 					const TCommonCharacteristics* randomCommonChars = &randomChars->cmn;
       
   130 					
       
   131 					TPtrC errorMessage;
       
   132 
       
   133 					//Perform Random/Common Characteristic Checks
       
   134 					if(pluginCheck->checkCommonCharacteristics(randomCommonChars,
       
   135 																exInterfaceUid,
       
   136 																exAlgorithmUid,
       
   137 																exImplementationUid,
       
   138 																exCreatorName,
       
   139 																exFIPSApproved,
       
   140 																exHardwareSupported,
       
   141 																exMaxConcurrencySupported,
       
   142 																exAlgorithmName,
       
   143 																exLatency,
       
   144 																exThroughput,
       
   145 																errorMessage) &&
       
   146 						pluginCheck->checkRandomCharacteristics(randomChars,
       
   147 																exRandomBlockingMode,
       
   148 																errorMessage))
       
   149 						{
       
   150 						INFO_PRINTF1(_L("** PASS : Random/Common characteristics successfully match expected values **"));
       
   151 						SetTestStepResult(EPass);	
       
   152 						}
       
   153 					else
       
   154 						{
       
   155 						ERR_PRINTF2(_L("** FAIL: Characteristic Mismatch - %S **"),&errorMessage);	
       
   156 						}
       
   157 						
       
   158 					CleanupStack::PopAndDestroy(pluginCheck);	
       
   159 					}
       
   160 			
       
   161 				CleanupStack::PopAndDestroy(randomImpl);
       
   162 				}
       
   163 			else
       
   164 				{
       
   165 				ERR_PRINTF1(_L("** Error: Loading Random Object **"));
       
   166 				}
       
   167 			}
       
   168 
       
   169 		}
       
   170 		
       
   171 	INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());	
       
   172 	return TestStepResult();
       
   173 	
       
   174 	}
       
   175 
       
   176 TVerdict CPluginCharsRandomStep::doTestStepPostambleL()
       
   177 	{
       
   178 	return TestStepResult();
       
   179 	}