1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/crypto/weakcryptospi/test/tcryptospi/src/plugincharsrandomstep.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,179 @@
1.4 +/*
1.5 +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +/**
1.23 + @file
1.24 + @internalTechnology
1.25 +*/
1.26 +
1.27 +#include "plugincharsrandomstep.h"
1.28 +#include "plugincharschecker.h"
1.29 +
1.30 +#include <cryptospi/cryptorandomapi.h>
1.31 +
1.32 +using namespace CryptoSpi;
1.33 +
1.34 +CPluginCharsRandomStep::~CPluginCharsRandomStep()
1.35 + {
1.36 + }
1.37 +
1.38 +CPluginCharsRandomStep::CPluginCharsRandomStep()
1.39 + {
1.40 + SetTestStepName(KPluginCharsRandomStep);
1.41 + }
1.42 +
1.43 +TVerdict CPluginCharsRandomStep::doTestStepPreambleL()
1.44 + {
1.45 + SetTestStepResult(EPass);
1.46 + return TestStepResult();
1.47 + }
1.48 +
1.49 +TVerdict CPluginCharsRandomStep::doTestStepL()
1.50 + {
1.51 +
1.52 + INFO_PRINTF1(_L("Plugin Characteristics - Random Chracteristics"));
1.53 + INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
1.54 +
1.55 + if (TestStepResult()==EPass)
1.56 + {
1.57 +
1.58 + //Assume faliure, unless all is successful
1.59 + SetTestStepResult(EFail);
1.60 +
1.61 + TVariantPtrC algorithmUid;
1.62 +
1.63 + //Each of the individual parameters required to create the Random object
1.64 + //are read in from the specified INI configuration file
1.65 + if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid))
1.66 + {
1.67 + ERR_PRINTF1(_L("** .INI Error: Random Arguments Not Located **"));
1.68 + SetTestStepResult(EFail);
1.69 + }
1.70 + else
1.71 + {
1.72 + CryptoSpi::CRandom* randomImpl = NULL;
1.73 +
1.74 + TRAPD_LOG(err,CRandomFactory::CreateRandomL(randomImpl,
1.75 + algorithmUid,
1.76 + NULL));
1.77 +
1.78 + if(randomImpl && (err == KErrNone))
1.79 + {
1.80 +
1.81 + CleanupStack::PushL(randomImpl);
1.82 +
1.83 + INFO_PRINTF1(_L("** Successfully Loaded Random Object **"));
1.84 +
1.85 + //Define a pointer of type TCharacteristics in order to store the random
1.86 + //object's characterisctics
1.87 + const TCharacteristics* chars(NULL);
1.88 +
1.89 + //Retrieve the characteristics for the random implementation object
1.90 + TRAP_LOG(err, randomImpl->GetCharacteristicsL(chars));
1.91 +
1.92 + //Static cast the characteristics to type TRandomCharacteristics
1.93 + const TRandomCharacteristics* randomChars = static_cast<const TRandomCharacteristics*>(chars);
1.94 +
1.95 + //Retrieve all the Common characteristics that are required for all test cases
1.96 + TVariantPtrC exInterfaceUid;
1.97 + TVariantPtrC exAlgorithmUid;
1.98 + TVariantPtrC exImplementationUid;
1.99 + TVariantPtrC exCreatorName;
1.100 + TBool exFIPSApproved;
1.101 + TBool exHardwareSupported;
1.102 + TInt exMaxConcurrencySupported;
1.103 + TVariantPtrC exAlgorithmName;
1.104 + TInt exLatency;
1.105 + TInt exThroughput;
1.106 +
1.107 + //Retrieve all the Random characteristics that are required for all test cases
1.108 + TInt exRandomBlockingMode;
1.109 +
1.110 + if(!GetStringFromConfig(ConfigSection(),KConfigExInterfaceUid,exInterfaceUid) ||
1.111 + !GetStringFromConfig(ConfigSection(),KConfigExAlgorithmUid,exAlgorithmUid) ||
1.112 + !GetStringFromConfig(ConfigSection(),KConfigExImplementationUid,exImplementationUid) ||
1.113 + !GetStringFromConfig(ConfigSection(),KConfigExCreatorName,exCreatorName) ||
1.114 + !GetBoolFromConfig(ConfigSection(),KConfigExFIPSApproved,exFIPSApproved) ||
1.115 + !GetBoolFromConfig(ConfigSection(),KConfigExHardwareSupport,exHardwareSupported) ||
1.116 + !GetIntFromConfig(ConfigSection(),KConfigExMaxConcurrency,exMaxConcurrencySupported) ||
1.117 + !GetStringFromConfig(ConfigSection(),KConfigExAlgorithmName,exAlgorithmName) ||
1.118 + !GetIntFromConfig(ConfigSection(),KConfigExLatency,exLatency) ||
1.119 + !GetIntFromConfig(ConfigSection(),KConfigExThroughput,exThroughput) ||
1.120 + !GetIntFromConfig(ConfigSection(),KConfigExBlockingMode,exRandomBlockingMode))
1.121 + {
1.122 + ERR_PRINTF1(_L("** .INI Error: Expected Random/Common Characteristic Arguments Not Located **"));
1.123 + SetTestStepResult(EFail);
1.124 + }
1.125 + else
1.126 + {
1.127 + INFO_PRINTF1(_L("** Checking Random/Common Characteristics.... **"));
1.128 +
1.129 + CPluginCharsChecker* pluginCheck = CPluginCharsChecker::NewLC();
1.130 +
1.131 + //Retrieve the Common Characteristics from TRandomCharacteristics
1.132 + const TCommonCharacteristics* randomCommonChars = &randomChars->cmn;
1.133 +
1.134 + TPtrC errorMessage;
1.135 +
1.136 + //Perform Random/Common Characteristic Checks
1.137 + if(pluginCheck->checkCommonCharacteristics(randomCommonChars,
1.138 + exInterfaceUid,
1.139 + exAlgorithmUid,
1.140 + exImplementationUid,
1.141 + exCreatorName,
1.142 + exFIPSApproved,
1.143 + exHardwareSupported,
1.144 + exMaxConcurrencySupported,
1.145 + exAlgorithmName,
1.146 + exLatency,
1.147 + exThroughput,
1.148 + errorMessage) &&
1.149 + pluginCheck->checkRandomCharacteristics(randomChars,
1.150 + exRandomBlockingMode,
1.151 + errorMessage))
1.152 + {
1.153 + INFO_PRINTF1(_L("** PASS : Random/Common characteristics successfully match expected values **"));
1.154 + SetTestStepResult(EPass);
1.155 + }
1.156 + else
1.157 + {
1.158 + ERR_PRINTF2(_L("** FAIL: Characteristic Mismatch - %S **"),&errorMessage);
1.159 + }
1.160 +
1.161 + CleanupStack::PopAndDestroy(pluginCheck);
1.162 + }
1.163 +
1.164 + CleanupStack::PopAndDestroy(randomImpl);
1.165 + }
1.166 + else
1.167 + {
1.168 + ERR_PRINTF1(_L("** Error: Loading Random Object **"));
1.169 + }
1.170 + }
1.171 +
1.172 + }
1.173 +
1.174 + INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
1.175 + return TestStepResult();
1.176 +
1.177 + }
1.178 +
1.179 +TVerdict CPluginCharsRandomStep::doTestStepPostambleL()
1.180 + {
1.181 + return TestStepResult();
1.182 + }