Update contrib.
2 * Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
22 #include "tprimegenvector.h"
26 #include "../../source/bigint/mont.h"
28 CTestAction* CPrimeGenVector::NewL(RFs& aFs, CConsoleBase& aConsole,
29 Output& aOut, const TTestActionSpec& aTestActionSpec)
31 CTestAction* self = CPrimeGenVector::NewLC(aFs, aConsole,
32 aOut, aTestActionSpec);
37 CTestAction* CPrimeGenVector::NewLC(RFs& aFs, CConsoleBase& aConsole,
38 Output& aOut, const TTestActionSpec& aTestActionSpec)
40 CPrimeGenVector* self = new(ELeave) CPrimeGenVector(aFs, aConsole, aOut);
41 CleanupStack::PushL(self);
42 self->ConstructL(aTestActionSpec);
46 CPrimeGenVector::~CPrimeGenVector()
55 CPrimeGenVector::CPrimeGenVector(RFs& aFs, CConsoleBase& aConsole, Output& aOut)
56 : CTestAction(aConsole, aOut), iFs(aFs)
60 void CPrimeGenVector::ConstructL(const TTestActionSpec& aTestActionSpec)
62 CTestAction::ConstructL(aTestActionSpec);
64 iBody = HBufC8::NewL(aTestActionSpec.iActionBody.Length());
65 iBody->Des().Copy(aTestActionSpec.iActionBody);
67 iBits = Input::ParseIntElement(*iBody, _L8("<bits>"), _L8("</bits>"));
68 iRandomDes = Input::ParseElementHexL(*iBody, _L8("<random>"));
69 iPrimeDes = Input::ParseElementHexL(*iBody, _L8("<prime>"));
72 void CPrimeGenVector::DoPerformPrerequisite(TRequestStatus& aStatus)
74 iRandom = RInteger::NewL(*iRandomDes);
75 iPrime = RInteger::NewL(*iPrimeDes);
76 TRequestStatus* status = &aStatus;
77 User::RequestComplete(status, KErrNone);
78 iActionState = CTestAction::EAction;
81 void CPrimeGenVector::DoPerformPostrequisite(TRequestStatus& aStatus)
83 TRequestStatus* status = &aStatus;
85 User::RequestComplete(status, KErrNone);
88 void CPrimeGenVector::DoReportAction(void)
92 void CPrimeGenVector::DoCheckResult(TInt)
94 iResult = (iResult && iExpectedResult) || (!iResult && !iExpectedResult);
96 iConsole.Printf(_L("."));
98 iConsole.Printf(_L("X"));
101 void CPrimeGenVector::PerformAction(TRequestStatus& aStatus)
103 TRAPD(res, PerformActionL());
104 __ASSERT_ALWAYS(!res, User::Panic(_L("CPrimeGenVector::PerformAction"), res));
105 TRequestStatus* status = &aStatus;
106 User::RequestComplete(status, KErrNone);
107 iActionState = CTestAction::EPostrequisite;
110 void CPrimeGenVector::PerformActionL()
116 //Returned number should be the next prime after our initial "random" number
118 //This CRandomSetSource stuff is a little dodgy as:
119 // 1) it has no NewL's with is fine as long as it doesn't allocate memory
120 // 2) more importantly, the prime generation routines use random numbers to
121 // determine whether or not the numbers it generates are prime.
122 // Since CRandomSetSource has already exhausted its given list of "random"
123 // numbers it returns 0's for use with anything else that calls it. It
124 // makes the primality testing a little bogus if you were using it for real
125 // things, but the test vectors that are there have already been verified
126 // and are known to be prime.
127 CRandomSetSource* incrementingRandom = new(ELeave)CRandomSetSource(*iRandomDes);
128 SetThreadRandomLC(incrementingRandom);
130 RInteger prime = RInteger::NewPrimeL(iBits);
138 CleanupStack::PopAndDestroy(1); //SetThreadRandomLC