os/security/crypto/weakcryptospi/test/tbigint/tprimevector.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 *
    16 */
    17 
    18 
    19 #include "tprimevector.h"
    20 #include "t_input.h"
    21 #include <bigint.h>
    22 
    23 CTestAction* CPrimeVector::NewL(RFs& aFs, CConsoleBase& aConsole, 
    24 	Output& aOut, const TTestActionSpec& aTestActionSpec)
    25 	{
    26 	CTestAction* self = CPrimeVector::NewLC(aFs, aConsole,
    27 		aOut, aTestActionSpec);
    28 	CleanupStack::Pop();
    29 	return self;
    30 	}
    31 
    32 CTestAction* CPrimeVector::NewLC(RFs& aFs, CConsoleBase& aConsole, 
    33 	Output& aOut, const TTestActionSpec& aTestActionSpec)
    34 	{
    35 	CPrimeVector* self = new(ELeave) CPrimeVector(aFs, aConsole, aOut);
    36 	CleanupStack::PushL(self);
    37 	self->ConstructL(aTestActionSpec);
    38 	return self;
    39 	}
    40 
    41 CPrimeVector::~CPrimeVector()
    42 	{
    43 	delete iBody;
    44 	delete iPrime;
    45 	}
    46 
    47 CPrimeVector::CPrimeVector(RFs& aFs, CConsoleBase& aConsole, 
    48 	Output& aOut) : CTestAction(aConsole, aOut), iFs(aFs)
    49 	{
    50 	}
    51 
    52 void CPrimeVector::ConstructL(const TTestActionSpec& aTestActionSpec)
    53 	{
    54 	CTestAction::ConstructL(aTestActionSpec);
    55 	iBody = HBufC8::NewL(aTestActionSpec.iActionBody.Length());
    56 	iBody->Des().Copy(aTestActionSpec.iActionBody);
    57 
    58 	iPrime = Input::ParseElementHexL(*iBody, _L8("<prime>"));
    59 	}
    60 
    61 void CPrimeVector::DoPerformPrerequisite(TRequestStatus& aStatus)
    62 	{
    63 	TRequestStatus* status = &aStatus;
    64 	User::RequestComplete(status, KErrNone);
    65 	iActionState = CTestAction::EAction;
    66 	}
    67 
    68 void CPrimeVector::DoPerformPostrequisite(TRequestStatus& aStatus)
    69 	{
    70 	TRequestStatus* status = &aStatus;
    71 	iFinished = ETrue;
    72 	User::RequestComplete(status, KErrNone);
    73 	}
    74 
    75 void CPrimeVector::DoReportAction(void)
    76 	{
    77 	}
    78 
    79 void CPrimeVector::DoCheckResult(TInt /*aError*/)
    80 	{
    81 	iResult = (iResult && iExpectedResult) || (!iResult && !iExpectedResult);
    82 	if (iResult)
    83 		iConsole.Printf(_L("."));
    84 	else
    85 		iConsole.Printf(_L("X"));
    86 	}
    87 
    88 
    89 void CPrimeVector::PerformAction(TRequestStatus& aStatus)
    90 	{
    91 	PerformActionL();
    92 	TRequestStatus* status = &aStatus;
    93 	User::RequestComplete(status, KErrNone);
    94 	iActionState = CTestAction::EPostrequisite;
    95 	}
    96 
    97 void CPrimeVector::PerformActionL(void)
    98 	{
    99 	__UHEAP_MARK;
   100 	iResult = ETrue;
   101 
   102 	RInteger prime = RInteger::NewL(*iPrime);
   103 	CleanupStack::PushL(prime);
   104 	iResult = prime.IsPrimeL();
   105 
   106 	CleanupStack::PopAndDestroy(&prime); 
   107 	__UHEAP_MARKEND;
   108 	}
   109