os/security/crypto/weakcryptospi/test/tbigint/tconstructionfb.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/crypto/weakcryptospi/test/tbigint/tconstructionfb.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,129 @@
     1.4 +/*
     1.5 +* Copyright (c) 2002-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 +* tconstruction.cpp
    1.19 +*
    1.20 +*/
    1.21 +
    1.22 +
    1.23 +#include "tconstructionfb.h"
    1.24 +#include "t_input.h"
    1.25 +#include <bigint.h>
    1.26 +#include <random.h>
    1.27 +
    1.28 +CTestAction* CConstructionFB::NewL(RFs& aFs, CConsoleBase& aConsole, 
    1.29 +	Output& aOut, const TTestActionSpec& aTestActionSpec)
    1.30 +	{
    1.31 +	CTestAction* self = CConstructionFB::NewLC(aFs, aConsole,
    1.32 +		aOut, aTestActionSpec);
    1.33 +	CleanupStack::Pop();
    1.34 +	return self;
    1.35 +	}
    1.36 +
    1.37 +CTestAction* CConstructionFB::NewLC(RFs& aFs, CConsoleBase& aConsole, 
    1.38 +	Output& aOut, const TTestActionSpec& aTestActionSpec)
    1.39 +	{
    1.40 +	CConstructionFB* self = new(ELeave) CConstructionFB(aFs, aConsole, aOut);
    1.41 +	CleanupStack::PushL(self);
    1.42 +	self->ConstructL(aTestActionSpec);
    1.43 +	return self;
    1.44 +	}
    1.45 +
    1.46 +CConstructionFB::~CConstructionFB()
    1.47 +	{
    1.48 +	}
    1.49 +
    1.50 +CConstructionFB::CConstructionFB(RFs& aFs, CConsoleBase& aConsole, Output& aOut)
    1.51 +	: CTestAction(aConsole, aOut), iFs(aFs)
    1.52 +	{
    1.53 +	}
    1.54 +
    1.55 +void CConstructionFB::ConstructL(const TTestActionSpec& aTestActionSpec)
    1.56 +	{
    1.57 +	CTestAction::ConstructL(aTestActionSpec);
    1.58 +	}
    1.59 +
    1.60 +void CConstructionFB::DoPerformPrerequisite(TRequestStatus& aStatus)
    1.61 +	{
    1.62 +	TRequestStatus* status = &aStatus;
    1.63 +	User::RequestComplete(status, KErrNone);
    1.64 +	iActionState = CTestAction::EAction;
    1.65 +	}
    1.66 +
    1.67 +void CConstructionFB::DoPerformPostrequisite(TRequestStatus& aStatus)
    1.68 +	{
    1.69 +	TRequestStatus* status = &aStatus;
    1.70 +	iFinished = ETrue;
    1.71 +	User::RequestComplete(status, KErrNone);
    1.72 +	}
    1.73 +
    1.74 +void CConstructionFB::DoReportAction(void)
    1.75 +	{
    1.76 +	}
    1.77 +
    1.78 +void CConstructionFB::DoCheckResult(TInt)
    1.79 +	{
    1.80 +	}
    1.81 +
    1.82 +void CConstructionFB::PerformAction(TRequestStatus& aStatus)
    1.83 +	{
    1.84 +	__UHEAP_MARK;
    1.85 +	TRequestStatus* status = &aStatus;
    1.86 +	iResult = ETrue;
    1.87 +
    1.88 +	//Generate 100 i*5 byte random sequences
    1.89 +	//This tests:
    1.90 +	// - NewLC(const TDesC8&)
    1.91 +	// - NewLC(const RInteger&)
    1.92 +	// - BufferLC()
    1.93 +	// By comparing the output of BufferLC we can have (some) assurance
    1.94 +	// that the internal integer code is intrepreting strings in the correct
    1.95 +	// order and endianess
    1.96 +	for(TUint i=0; i<100; i++)
    1.97 +		{ 
    1.98 +		HBufC8* buf = HBufC8::NewMaxLC(i*5);
    1.99 +		TPtr8 ptr = buf->Des();
   1.100 +		TRandom::RandomL(ptr);
   1.101 +
   1.102 +		RInteger a = RInteger::NewL(ptr);
   1.103 +		CleanupStack::PushL(a);
   1.104 +		HBufC8* out = a.BufferLC();
   1.105 +		if( *out != *buf )
   1.106 +			{
   1.107 +			iResult = EFalse;
   1.108 +			}
   1.109 +		CleanupStack::PopAndDestroy(out);
   1.110 +		
   1.111 +		RInteger b = RInteger::NewL(a);
   1.112 +		CleanupStack::PushL(b);
   1.113 +		if( a != b )
   1.114 +			{
   1.115 +			iResult = EFalse;
   1.116 +			}
   1.117 +		out = b.BufferLC();
   1.118 +		if( *out != *buf )
   1.119 +			{
   1.120 +			iResult = EFalse;
   1.121 +			}
   1.122 +		CleanupStack::PopAndDestroy(out);
   1.123 +		CleanupStack::PopAndDestroy(); //b
   1.124 +		CleanupStack::PopAndDestroy();//a
   1.125 +		CleanupStack::PopAndDestroy(buf);
   1.126 +		}
   1.127 +
   1.128 +	User::RequestComplete(status, KErrNone);
   1.129 +	iActionState = CTestAction::EPostrequisite;
   1.130 +	__UHEAP_MARKEND;
   1.131 +	}
   1.132 +