os/security/crypto/weakcrypto/test/tasymmetric/tvectortest.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/crypto/weakcrypto/test/tasymmetric/tvectortest.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,139 @@
     1.4 +/*
     1.5 +* Copyright (c) 1998-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 +#include "tvectortest.h"
    1.23 +#include <e32twin.h>
    1.24 +#include "t_input.h"
    1.25 +#include <asymmetric.h>
    1.26 +#include <random.h>
    1.27 +#include <padding.h>
    1.28 +#include "tvectorutils.h"
    1.29 +#include "performancetest.h"
    1.30 +#include <securityerr.h>
    1.31 +
    1.32 +_LIT8(KKeyBitsStart, "<keybits>");
    1.33 +_LIT8(KKeyBitsEnd, "</keybits>");
    1.34 +_LIT8(KResultStart, "<result>");
    1.35 +_LIT8(KResultEnd, "</result>");
    1.36 +
    1.37 +////////////////////////////////////////////////////////////////////////////////
    1.38 +// CVectorTest 
    1.39 +////////////////////////////////////////////////////////////////////////////////
    1.40 +
    1.41 +CVectorTest::CVectorTest(CConsoleBase& aConsole, Output& aOut)
    1.42 +    : CTestAction(aConsole, aOut), iPerfTestIterations(100)
    1.43 +    {
    1.44 +    }
    1.45 +
    1.46 +CVectorTest::~CVectorTest()
    1.47 +    {
    1.48 +    }
    1.49 +
    1.50 +void CVectorTest::ConstructL(const TTestActionSpec& aTestActionSpec)
    1.51 +{
    1.52 +	CTestAction::ConstructL(aTestActionSpec);
    1.53 +
    1.54 +	if (CPerformance::PerformanceTester()->IsTestingPerformance())
    1.55 +	{//	Number of test iterations
    1.56 +		TPtrC8 itsPtr = Input::ParseElement(aTestActionSpec.iActionBody, KIterationsStart, KIterationsEnd);
    1.57 +		if (itsPtr!=KNullDesC8)
    1.58 +		{
    1.59 +			TLex8 lex;
    1.60 +			lex.Assign(itsPtr);
    1.61 +			User::LeaveIfError(lex.Val(iPerfTestIterations));
    1.62 +			if (iPerfTestIterations > KMaxIterations)
    1.63 +				User::Panic(_L("AsymmetricPerformance.exe"), KErrArgument);
    1.64 +		}
    1.65 +	}
    1.66 +
    1.67 +	TPtrC8 keyBitsPtr = Input::ParseElement(aTestActionSpec.iActionBody, KKeyBitsStart, KKeyBitsEnd); 
    1.68 +	if (keyBitsPtr!=KNullDesC8)
    1.69 +	{
    1.70 +		TLex8 lex;
    1.71 +		lex.Assign(keyBitsPtr);
    1.72 +		User::LeaveIfError(lex.Val(iKeyBits));
    1.73 +	}
    1.74 +
    1.75 +    TPtrC8 resultIn = Input::ParseElement(aTestActionSpec.iActionResult, KResultStart, KResultEnd);
    1.76 +    iExpectedResult = VectorUtils::ParseBoolL(resultIn);
    1.77 +}
    1.78 +
    1.79 +void CVectorTest::PerformAction(TRequestStatus& aStatus)
    1.80 +{
    1.81 +	TRequestStatus* status = &aStatus;
    1.82 +	
    1.83 +	if (CPerformance::PerformanceTester()->IsTestingPerformance())
    1.84 +	{
    1.85 +		iConsole.Printf(_L(">"));	//	Indicates start of test
    1.86 +		TRAP(iActionResult, DoPerformanceTestActionL());
    1.87 +	}
    1.88 +	else
    1.89 +	{
    1.90 +		TRAP(iActionResult, DoPerformActionL());
    1.91 +	}
    1.92 +	
    1.93 +	if (iActionResult==KErrNoMemory)
    1.94 +		{
    1.95 +		User::Leave(iActionResult);	//	For OOM testing
    1.96 +		}
    1.97 +	if (iActionResult==KErrKeyNotWeakEnough)
    1.98 +		{
    1.99 +		iResult = ETrue;
   1.100 +		iConsole.Printf(_L("Crypto libraries returned KErrKeyNotWeakEnough!  Passing test automatically.\n\r"));
   1.101 +		iOut.writeString(_L("Crypto libraries returned KErrKeyNotWeakEnough!  Passing test automatically.\n\r"));
   1.102 +		}
   1.103 +
   1.104 +	User::RequestComplete(status, iActionResult);
   1.105 +
   1.106 +	iActionState = CTestAction::EPostrequisite;
   1.107 +
   1.108 +}
   1.109 +
   1.110 +void CVectorTest::DoPerformPrerequisite(TRequestStatus& aStatus)
   1.111 +	{
   1.112 +	TRequestStatus* status = &aStatus;
   1.113 +	User::RequestComplete(status, KErrNone);
   1.114 +	iActionState = CTestAction::EAction;
   1.115 +	}
   1.116 +
   1.117 +void CVectorTest::DoPerformPostrequisite(TRequestStatus& aStatus)
   1.118 +	{
   1.119 +	TRequestStatus* status = &aStatus;
   1.120 +	iFinished = ETrue;
   1.121 +	User::RequestComplete(status, KErrNone);
   1.122 +	}
   1.123 +
   1.124 +void CVectorTest::DoReportAction(void)
   1.125 +	{
   1.126 +	}
   1.127 +
   1.128 +void CVectorTest::DoCheckResult(TInt /*aError*/)
   1.129 +	{
   1.130 +//	If using Keith's fixed up testframework for testing failures, iResult will 
   1.131 +//	have already been corrected for a deliberate fail result.
   1.132 +//	If not using Keith's testframework iResult is still a fail result at this
   1.133 +//	point, so now's the time to adjust for deliberate failure.
   1.134 +
   1.135 +	if (!iResult)
   1.136 +		iResult = (iResult && iExpectedResult) || (!iResult && !iExpectedResult);
   1.137 +
   1.138 +	if (iResult)
   1.139 +		iConsole.Printf(_L("."));
   1.140 +	else
   1.141 +		iConsole.Printf(_L("X"));
   1.142 +	}