os/security/crypto/weakcrypto/test/tasymmetric/tvectortest.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
#include "tvectortest.h"
sl@0
    20
#include <e32twin.h>
sl@0
    21
#include "t_input.h"
sl@0
    22
#include <asymmetric.h>
sl@0
    23
#include <random.h>
sl@0
    24
#include <padding.h>
sl@0
    25
#include "tvectorutils.h"
sl@0
    26
#include "performancetest.h"
sl@0
    27
#include <securityerr.h>
sl@0
    28
sl@0
    29
_LIT8(KKeyBitsStart, "<keybits>");
sl@0
    30
_LIT8(KKeyBitsEnd, "</keybits>");
sl@0
    31
_LIT8(KResultStart, "<result>");
sl@0
    32
_LIT8(KResultEnd, "</result>");
sl@0
    33
sl@0
    34
////////////////////////////////////////////////////////////////////////////////
sl@0
    35
// CVectorTest 
sl@0
    36
////////////////////////////////////////////////////////////////////////////////
sl@0
    37
sl@0
    38
CVectorTest::CVectorTest(CConsoleBase& aConsole, Output& aOut)
sl@0
    39
    : CTestAction(aConsole, aOut), iPerfTestIterations(100)
sl@0
    40
    {
sl@0
    41
    }
sl@0
    42
sl@0
    43
CVectorTest::~CVectorTest()
sl@0
    44
    {
sl@0
    45
    }
sl@0
    46
sl@0
    47
void CVectorTest::ConstructL(const TTestActionSpec& aTestActionSpec)
sl@0
    48
{
sl@0
    49
	CTestAction::ConstructL(aTestActionSpec);
sl@0
    50
sl@0
    51
	if (CPerformance::PerformanceTester()->IsTestingPerformance())
sl@0
    52
	{//	Number of test iterations
sl@0
    53
		TPtrC8 itsPtr = Input::ParseElement(aTestActionSpec.iActionBody, KIterationsStart, KIterationsEnd);
sl@0
    54
		if (itsPtr!=KNullDesC8)
sl@0
    55
		{
sl@0
    56
			TLex8 lex;
sl@0
    57
			lex.Assign(itsPtr);
sl@0
    58
			User::LeaveIfError(lex.Val(iPerfTestIterations));
sl@0
    59
			if (iPerfTestIterations > KMaxIterations)
sl@0
    60
				User::Panic(_L("AsymmetricPerformance.exe"), KErrArgument);
sl@0
    61
		}
sl@0
    62
	}
sl@0
    63
sl@0
    64
	TPtrC8 keyBitsPtr = Input::ParseElement(aTestActionSpec.iActionBody, KKeyBitsStart, KKeyBitsEnd); 
sl@0
    65
	if (keyBitsPtr!=KNullDesC8)
sl@0
    66
	{
sl@0
    67
		TLex8 lex;
sl@0
    68
		lex.Assign(keyBitsPtr);
sl@0
    69
		User::LeaveIfError(lex.Val(iKeyBits));
sl@0
    70
	}
sl@0
    71
sl@0
    72
    TPtrC8 resultIn = Input::ParseElement(aTestActionSpec.iActionResult, KResultStart, KResultEnd);
sl@0
    73
    iExpectedResult = VectorUtils::ParseBoolL(resultIn);
sl@0
    74
}
sl@0
    75
sl@0
    76
void CVectorTest::PerformAction(TRequestStatus& aStatus)
sl@0
    77
{
sl@0
    78
	TRequestStatus* status = &aStatus;
sl@0
    79
	
sl@0
    80
	if (CPerformance::PerformanceTester()->IsTestingPerformance())
sl@0
    81
	{
sl@0
    82
		iConsole.Printf(_L(">"));	//	Indicates start of test
sl@0
    83
		TRAP(iActionResult, DoPerformanceTestActionL());
sl@0
    84
	}
sl@0
    85
	else
sl@0
    86
	{
sl@0
    87
		TRAP(iActionResult, DoPerformActionL());
sl@0
    88
	}
sl@0
    89
	
sl@0
    90
	if (iActionResult==KErrNoMemory)
sl@0
    91
		{
sl@0
    92
		User::Leave(iActionResult);	//	For OOM testing
sl@0
    93
		}
sl@0
    94
	if (iActionResult==KErrKeyNotWeakEnough)
sl@0
    95
		{
sl@0
    96
		iResult = ETrue;
sl@0
    97
		iConsole.Printf(_L("Crypto libraries returned KErrKeyNotWeakEnough!  Passing test automatically.\n\r"));
sl@0
    98
		iOut.writeString(_L("Crypto libraries returned KErrKeyNotWeakEnough!  Passing test automatically.\n\r"));
sl@0
    99
		}
sl@0
   100
sl@0
   101
	User::RequestComplete(status, iActionResult);
sl@0
   102
sl@0
   103
	iActionState = CTestAction::EPostrequisite;
sl@0
   104
sl@0
   105
}
sl@0
   106
sl@0
   107
void CVectorTest::DoPerformPrerequisite(TRequestStatus& aStatus)
sl@0
   108
	{
sl@0
   109
	TRequestStatus* status = &aStatus;
sl@0
   110
	User::RequestComplete(status, KErrNone);
sl@0
   111
	iActionState = CTestAction::EAction;
sl@0
   112
	}
sl@0
   113
sl@0
   114
void CVectorTest::DoPerformPostrequisite(TRequestStatus& aStatus)
sl@0
   115
	{
sl@0
   116
	TRequestStatus* status = &aStatus;
sl@0
   117
	iFinished = ETrue;
sl@0
   118
	User::RequestComplete(status, KErrNone);
sl@0
   119
	}
sl@0
   120
sl@0
   121
void CVectorTest::DoReportAction(void)
sl@0
   122
	{
sl@0
   123
	}
sl@0
   124
sl@0
   125
void CVectorTest::DoCheckResult(TInt /*aError*/)
sl@0
   126
	{
sl@0
   127
//	If using Keith's fixed up testframework for testing failures, iResult will 
sl@0
   128
//	have already been corrected for a deliberate fail result.
sl@0
   129
//	If not using Keith's testframework iResult is still a fail result at this
sl@0
   130
//	point, so now's the time to adjust for deliberate failure.
sl@0
   131
sl@0
   132
	if (!iResult)
sl@0
   133
		iResult = (iResult && iExpectedResult) || (!iResult && !iExpectedResult);
sl@0
   134
sl@0
   135
	if (iResult)
sl@0
   136
		iConsole.Printf(_L("."));
sl@0
   137
	else
sl@0
   138
		iConsole.Printf(_L("X"));
sl@0
   139
	}