os/security/crypto/weakcryptospi/test/tbigint/tconstructionfb.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2 * Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of the License "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 * tconstruction.cpp
    16 *
    17 */
    18 
    19 
    20 #include "tconstructionfb.h"
    21 #include "t_input.h"
    22 #include <bigint.h>
    23 #include <random.h>
    24 
    25 CTestAction* CConstructionFB::NewL(RFs& aFs, CConsoleBase& aConsole, 
    26 	Output& aOut, const TTestActionSpec& aTestActionSpec)
    27 	{
    28 	CTestAction* self = CConstructionFB::NewLC(aFs, aConsole,
    29 		aOut, aTestActionSpec);
    30 	CleanupStack::Pop();
    31 	return self;
    32 	}
    33 
    34 CTestAction* CConstructionFB::NewLC(RFs& aFs, CConsoleBase& aConsole, 
    35 	Output& aOut, const TTestActionSpec& aTestActionSpec)
    36 	{
    37 	CConstructionFB* self = new(ELeave) CConstructionFB(aFs, aConsole, aOut);
    38 	CleanupStack::PushL(self);
    39 	self->ConstructL(aTestActionSpec);
    40 	return self;
    41 	}
    42 
    43 CConstructionFB::~CConstructionFB()
    44 	{
    45 	}
    46 
    47 CConstructionFB::CConstructionFB(RFs& aFs, CConsoleBase& aConsole, Output& aOut)
    48 	: CTestAction(aConsole, aOut), iFs(aFs)
    49 	{
    50 	}
    51 
    52 void CConstructionFB::ConstructL(const TTestActionSpec& aTestActionSpec)
    53 	{
    54 	CTestAction::ConstructL(aTestActionSpec);
    55 	}
    56 
    57 void CConstructionFB::DoPerformPrerequisite(TRequestStatus& aStatus)
    58 	{
    59 	TRequestStatus* status = &aStatus;
    60 	User::RequestComplete(status, KErrNone);
    61 	iActionState = CTestAction::EAction;
    62 	}
    63 
    64 void CConstructionFB::DoPerformPostrequisite(TRequestStatus& aStatus)
    65 	{
    66 	TRequestStatus* status = &aStatus;
    67 	iFinished = ETrue;
    68 	User::RequestComplete(status, KErrNone);
    69 	}
    70 
    71 void CConstructionFB::DoReportAction(void)
    72 	{
    73 	}
    74 
    75 void CConstructionFB::DoCheckResult(TInt)
    76 	{
    77 	}
    78 
    79 void CConstructionFB::PerformAction(TRequestStatus& aStatus)
    80 	{
    81 	__UHEAP_MARK;
    82 	TRequestStatus* status = &aStatus;
    83 	iResult = ETrue;
    84 
    85 	//Generate 100 i*5 byte random sequences
    86 	//This tests:
    87 	// - NewLC(const TDesC8&)
    88 	// - NewLC(const RInteger&)
    89 	// - BufferLC()
    90 	// By comparing the output of BufferLC we can have (some) assurance
    91 	// that the internal integer code is intrepreting strings in the correct
    92 	// order and endianess
    93 	for(TUint i=0; i<100; i++)
    94 		{ 
    95 		HBufC8* buf = HBufC8::NewMaxLC(i*5);
    96 		TPtr8 ptr = buf->Des();
    97 		TRandom::RandomL(ptr);
    98 
    99 		RInteger a = RInteger::NewL(ptr);
   100 		CleanupStack::PushL(a);
   101 		HBufC8* out = a.BufferLC();
   102 		if( *out != *buf )
   103 			{
   104 			iResult = EFalse;
   105 			}
   106 		CleanupStack::PopAndDestroy(out);
   107 		
   108 		RInteger b = RInteger::NewL(a);
   109 		CleanupStack::PushL(b);
   110 		if( a != b )
   111 			{
   112 			iResult = EFalse;
   113 			}
   114 		out = b.BufferLC();
   115 		if( *out != *buf )
   116 			{
   117 			iResult = EFalse;
   118 			}
   119 		CleanupStack::PopAndDestroy(out);
   120 		CleanupStack::PopAndDestroy(); //b
   121 		CleanupStack::PopAndDestroy();//a
   122 		CleanupStack::PopAndDestroy(buf);
   123 		}
   124 
   125 	User::RequestComplete(status, KErrNone);
   126 	iActionState = CTestAction::EPostrequisite;
   127 	__UHEAP_MARKEND;
   128 	}
   129