|
1 /* |
|
2 * Copyright (c) 2003-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 "tprimegen.h" |
|
20 #include "t_input.h" |
|
21 #include <bigint.h> |
|
22 #include "tutils.h" |
|
23 #include <random.h> |
|
24 |
|
25 CTestAction* CPrimeGen::NewL(RFs& aFs, CConsoleBase& aConsole, |
|
26 Output& aOut, const TTestActionSpec& aTestActionSpec) |
|
27 { |
|
28 CTestAction* self = CPrimeGen::NewLC(aFs, aConsole, |
|
29 aOut, aTestActionSpec); |
|
30 CleanupStack::Pop(); |
|
31 return self; |
|
32 } |
|
33 |
|
34 CTestAction* CPrimeGen::NewLC(RFs& aFs, CConsoleBase& aConsole, |
|
35 Output& aOut, const TTestActionSpec& aTestActionSpec) |
|
36 { |
|
37 CPrimeGen* self = new(ELeave) CPrimeGen(aFs, aConsole, aOut); |
|
38 CleanupStack::PushL(self); |
|
39 self->ConstructL(aTestActionSpec); |
|
40 return self; |
|
41 } |
|
42 |
|
43 CPrimeGen::~CPrimeGen() |
|
44 { |
|
45 delete iBody; |
|
46 } |
|
47 |
|
48 CPrimeGen::CPrimeGen(RFs& aFs, CConsoleBase& aConsole, |
|
49 Output& aOut) : CTestAction(aConsole, aOut), iFs(aFs) |
|
50 { |
|
51 } |
|
52 |
|
53 void CPrimeGen::ConstructL(const TTestActionSpec& aTestActionSpec) |
|
54 { |
|
55 CTestAction::ConstructL(aTestActionSpec); |
|
56 iBody = HBufC8::NewL(aTestActionSpec.iActionBody.Length()); |
|
57 iBody->Des().Copy(aTestActionSpec.iActionBody); |
|
58 |
|
59 iBits = Input::ParseIntElement(*iBody, _L8("<bits>"), _L8("</bits>")); |
|
60 } |
|
61 |
|
62 void CPrimeGen::DoPerformPrerequisite(TRequestStatus& aStatus) |
|
63 { |
|
64 TRequestStatus* status = &aStatus; |
|
65 User::RequestComplete(status, KErrNone); |
|
66 iActionState = CTestAction::EAction; |
|
67 } |
|
68 |
|
69 void CPrimeGen::DoPerformPostrequisite(TRequestStatus& aStatus) |
|
70 { |
|
71 TRequestStatus* status = &aStatus; |
|
72 iFinished = ETrue; |
|
73 User::RequestComplete(status, KErrNone); |
|
74 } |
|
75 |
|
76 void CPrimeGen::DoReportAction(void) |
|
77 { |
|
78 } |
|
79 |
|
80 void CPrimeGen::DoCheckResult(TInt) |
|
81 { |
|
82 } |
|
83 |
|
84 void CPrimeGen::PerformAction(TRequestStatus& aStatus) |
|
85 { |
|
86 __UHEAP_MARK; |
|
87 TRequestStatus* status = &aStatus; |
|
88 iResult = EFalse; |
|
89 |
|
90 RInteger prime = RInteger::NewPrimeL(iBits, TInteger::ETopBitSet); |
|
91 CleanupStack::PushL(prime); |
|
92 if(prime.BitCount() == iBits && prime.IsPrimeL()) |
|
93 { |
|
94 iResult = ETrue; |
|
95 } |
|
96 |
|
97 CleanupStack::PopAndDestroy(&prime); |
|
98 |
|
99 User::RequestComplete(status, KErrNone); |
|
100 iActionState = CTestAction::EPostrequisite; |
|
101 __UHEAP_MARKEND; |
|
102 } |
|
103 |