1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/crypto/weakcryptospi/test/tbigint/tconstructionvector.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,126 @@
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 +*
1.19 +*/
1.20 +
1.21 +
1.22 +#include "tconstructionvector.h"
1.23 +#include "t_input.h"
1.24 +#include <bigint.h>
1.25 +
1.26 +class RIntegerTest : public RInteger
1.27 + {
1.28 + public:
1.29 + RIntegerTest(void) {}
1.30 + RIntegerTest(const RInteger& aInteger) {iSize = *((TUint*)&aInteger); iPtr = *(((TUint*)(&aInteger)+1)); }
1.31 + TUint* Ptr(void) {return RInteger::Ptr();}
1.32 + };
1.33 +
1.34 +CTestAction* CConstructionVector::NewL(RFs& aFs, CConsoleBase& aConsole,
1.35 + Output& aOut, const TTestActionSpec& aTestActionSpec)
1.36 + {
1.37 + CTestAction* self = CConstructionVector::NewLC(aFs, aConsole,
1.38 + aOut, aTestActionSpec);
1.39 + CleanupStack::Pop();
1.40 + return self;
1.41 + }
1.42 +
1.43 +CTestAction* CConstructionVector::NewLC(RFs& aFs, CConsoleBase& aConsole,
1.44 + Output& aOut, const TTestActionSpec& aTestActionSpec)
1.45 + {
1.46 + CConstructionVector* self = new(ELeave) CConstructionVector(aFs, aConsole, aOut);
1.47 + CleanupStack::PushL(self);
1.48 + self->ConstructL(aTestActionSpec);
1.49 + return self;
1.50 + }
1.51 +
1.52 +CConstructionVector::~CConstructionVector()
1.53 + {
1.54 + delete iBody;
1.55 + delete iString;
1.56 + delete iMemoryLayout;
1.57 + }
1.58 +
1.59 +CConstructionVector::CConstructionVector(RFs& aFs, CConsoleBase& aConsole, Output& aOut)
1.60 + : CTestAction(aConsole, aOut), iFs(aFs)
1.61 + {
1.62 + }
1.63 +
1.64 +void CConstructionVector::ConstructL(const TTestActionSpec& aTestActionSpec)
1.65 + {
1.66 + CTestAction::ConstructL(aTestActionSpec);
1.67 + iBody = HBufC8::NewL(aTestActionSpec.iActionBody.Length());
1.68 + iBody->Des().Copy(aTestActionSpec.iActionBody);
1.69 +
1.70 + iString = Input::ParseElementHexL(*iBody, _L8("<input>"));
1.71 + iMemoryLayout = Input::ParseElementHexL(*iBody, _L8("<memorylayout>"));
1.72 + }
1.73 +
1.74 +void CConstructionVector::DoPerformPrerequisite(TRequestStatus& aStatus)
1.75 + {
1.76 + TRequestStatus* status = &aStatus;
1.77 + User::RequestComplete(status, KErrNone);
1.78 + iActionState = CTestAction::EAction;
1.79 + }
1.80 +
1.81 +void CConstructionVector::DoPerformPostrequisite(TRequestStatus& aStatus)
1.82 + {
1.83 + TRequestStatus* status = &aStatus;
1.84 + iFinished = ETrue;
1.85 + User::RequestComplete(status, KErrNone);
1.86 + }
1.87 +
1.88 +void CConstructionVector::DoReportAction(void)
1.89 + {
1.90 + }
1.91 +
1.92 +void CConstructionVector::DoCheckResult(TInt)
1.93 + {
1.94 + }
1.95 +
1.96 +void CConstructionVector::PerformAction(TRequestStatus& aStatus)
1.97 + {
1.98 + __UHEAP_MARK;
1.99 + TRequestStatus* status = &aStatus;
1.100 + iResult = ETrue;
1.101 +
1.102 + //This is just a derived class to get around the fact that iReg is
1.103 + //protected in RInteger. See top of file for definition
1.104 + RIntegerTest a;
1.105 + //a = (RIntegerTest)(RInteger::NewL(*iString));
1.106 + a = static_cast<RIntegerTest>(RIntegerTest::NewL(*iString));
1.107 + CleanupStack::PushL(a);
1.108 +
1.109 + //This test ensures that the internal memory layout of a number is correct
1.110 + TUint compare = Mem::Compare((TUint8*)(a.Ptr()), a.ByteCount(),
1.111 + iMemoryLayout->Ptr(), iMemoryLayout->Size());
1.112 + if( compare != 0 )
1.113 + {
1.114 + iResult = EFalse;
1.115 + }
1.116 +
1.117 + HBufC8* out = a.BufferLC();
1.118 + if( *out != *iString )
1.119 + {
1.120 + iResult = EFalse;
1.121 + }
1.122 + CleanupStack::PopAndDestroy(out);
1.123 + CleanupStack::PopAndDestroy(&a);
1.124 +
1.125 + User::RequestComplete(status, KErrNone);
1.126 + iActionState = CTestAction::EPostrequisite;
1.127 + __UHEAP_MARKEND;
1.128 + }
1.129 +