sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
|
sl@0
|
19 |
#include "tbasicmathsvector.h"
|
sl@0
|
20 |
#include "t_input.h"
|
sl@0
|
21 |
#include <bigint.h>
|
sl@0
|
22 |
|
sl@0
|
23 |
CTestAction* CBasicMathsVector::NewL(RFs& aFs, CConsoleBase& aConsole,
|
sl@0
|
24 |
Output& aOut, const TTestActionSpec& aTestActionSpec)
|
sl@0
|
25 |
{
|
sl@0
|
26 |
CTestAction* self = CBasicMathsVector::NewLC(aFs, aConsole,
|
sl@0
|
27 |
aOut, aTestActionSpec);
|
sl@0
|
28 |
CleanupStack::Pop();
|
sl@0
|
29 |
return self;
|
sl@0
|
30 |
}
|
sl@0
|
31 |
|
sl@0
|
32 |
CTestAction* CBasicMathsVector::NewLC(RFs& aFs, CConsoleBase& aConsole,
|
sl@0
|
33 |
Output& aOut, const TTestActionSpec& aTestActionSpec)
|
sl@0
|
34 |
{
|
sl@0
|
35 |
CBasicMathsVector* self = new(ELeave) CBasicMathsVector(aFs, aConsole, aOut);
|
sl@0
|
36 |
CleanupStack::PushL(self);
|
sl@0
|
37 |
self->ConstructL(aTestActionSpec);
|
sl@0
|
38 |
return self;
|
sl@0
|
39 |
}
|
sl@0
|
40 |
|
sl@0
|
41 |
CBasicMathsVector::~CBasicMathsVector()
|
sl@0
|
42 |
{
|
sl@0
|
43 |
delete iBody;
|
sl@0
|
44 |
delete iA;
|
sl@0
|
45 |
delete iB;
|
sl@0
|
46 |
delete iAns;
|
sl@0
|
47 |
}
|
sl@0
|
48 |
|
sl@0
|
49 |
CBasicMathsVector::CBasicMathsVector(RFs& aFs, CConsoleBase& aConsole,
|
sl@0
|
50 |
Output& aOut) : CTestAction(aConsole, aOut), iFs(aFs)
|
sl@0
|
51 |
{
|
sl@0
|
52 |
}
|
sl@0
|
53 |
|
sl@0
|
54 |
void CBasicMathsVector::ConstructL(const TTestActionSpec& aTestActionSpec)
|
sl@0
|
55 |
{
|
sl@0
|
56 |
CTestAction::ConstructL(aTestActionSpec);
|
sl@0
|
57 |
iBody = HBufC8::NewL(aTestActionSpec.iActionBody.Length());
|
sl@0
|
58 |
iBody->Des().Copy(aTestActionSpec.iActionBody);
|
sl@0
|
59 |
|
sl@0
|
60 |
iA = Input::ParseElementHexL(*iBody, _L8("<a>"));
|
sl@0
|
61 |
iB = Input::ParseElementHexL(*iBody, _L8("<b>"));
|
sl@0
|
62 |
iAns = Input::ParseElementHexL(*iBody, _L8("<ans>"));
|
sl@0
|
63 |
TPtrC8 op = Input::ParseElement(*iBody, _L8("<op>"));
|
sl@0
|
64 |
if( op == _L8("add") )
|
sl@0
|
65 |
{
|
sl@0
|
66 |
iOp = EAdd;
|
sl@0
|
67 |
}
|
sl@0
|
68 |
else if( op == _L8("subtract") )
|
sl@0
|
69 |
{
|
sl@0
|
70 |
iOp = ESubtract;
|
sl@0
|
71 |
}
|
sl@0
|
72 |
else if( op == _L8("multiply") )
|
sl@0
|
73 |
{
|
sl@0
|
74 |
iOp = EMultiply;
|
sl@0
|
75 |
}
|
sl@0
|
76 |
else if( op == _L8("divide") )
|
sl@0
|
77 |
{
|
sl@0
|
78 |
iOp = EDivide;
|
sl@0
|
79 |
}
|
sl@0
|
80 |
else if( op == _L8("modulus") )
|
sl@0
|
81 |
{
|
sl@0
|
82 |
iOp = EModulus;
|
sl@0
|
83 |
}
|
sl@0
|
84 |
else if( op == _L8("gcd") )
|
sl@0
|
85 |
{
|
sl@0
|
86 |
iOp = EGCD;
|
sl@0
|
87 |
}
|
sl@0
|
88 |
else if( op == _L8("inversemod") )
|
sl@0
|
89 |
{
|
sl@0
|
90 |
iOp = EInverseMod;
|
sl@0
|
91 |
}
|
sl@0
|
92 |
else
|
sl@0
|
93 |
{
|
sl@0
|
94 |
User::Panic(_L("tbasicmathsvector"), 1);
|
sl@0
|
95 |
}
|
sl@0
|
96 |
}
|
sl@0
|
97 |
|
sl@0
|
98 |
void CBasicMathsVector::DoPerformPrerequisite(TRequestStatus& aStatus)
|
sl@0
|
99 |
{
|
sl@0
|
100 |
TRequestStatus* status = &aStatus;
|
sl@0
|
101 |
User::RequestComplete(status, KErrNone);
|
sl@0
|
102 |
iActionState = CTestAction::EAction;
|
sl@0
|
103 |
}
|
sl@0
|
104 |
|
sl@0
|
105 |
void CBasicMathsVector::DoPerformPostrequisite(TRequestStatus& aStatus)
|
sl@0
|
106 |
{
|
sl@0
|
107 |
TRequestStatus* status = &aStatus;
|
sl@0
|
108 |
iFinished = ETrue;
|
sl@0
|
109 |
User::RequestComplete(status, KErrNone);
|
sl@0
|
110 |
}
|
sl@0
|
111 |
|
sl@0
|
112 |
void CBasicMathsVector::DoReportAction(void)
|
sl@0
|
113 |
{
|
sl@0
|
114 |
}
|
sl@0
|
115 |
|
sl@0
|
116 |
void CBasicMathsVector::DoCheckResult(TInt)
|
sl@0
|
117 |
{
|
sl@0
|
118 |
}
|
sl@0
|
119 |
|
sl@0
|
120 |
void CBasicMathsVector::PerformAction(TRequestStatus& aStatus)
|
sl@0
|
121 |
{
|
sl@0
|
122 |
__UHEAP_MARK;
|
sl@0
|
123 |
TRequestStatus* status = &aStatus;
|
sl@0
|
124 |
iResult = ETrue;
|
sl@0
|
125 |
|
sl@0
|
126 |
RInteger a = RInteger::NewL(*iA);
|
sl@0
|
127 |
CleanupStack::PushL(a);
|
sl@0
|
128 |
RInteger b = RInteger::NewL(*iB);
|
sl@0
|
129 |
CleanupStack::PushL(b);
|
sl@0
|
130 |
RInteger ans = RInteger::NewL(*iAns);
|
sl@0
|
131 |
CleanupStack::PushL(ans);
|
sl@0
|
132 |
RInteger result;
|
sl@0
|
133 |
switch(iOp)
|
sl@0
|
134 |
{
|
sl@0
|
135 |
case EAdd:
|
sl@0
|
136 |
a += b;
|
sl@0
|
137 |
break;
|
sl@0
|
138 |
case ESubtract:
|
sl@0
|
139 |
a -= b;
|
sl@0
|
140 |
break;
|
sl@0
|
141 |
case EMultiply:
|
sl@0
|
142 |
a *= b;
|
sl@0
|
143 |
break;
|
sl@0
|
144 |
case EDivide:
|
sl@0
|
145 |
a /= b;
|
sl@0
|
146 |
break;
|
sl@0
|
147 |
case EModulus:
|
sl@0
|
148 |
a %= b;
|
sl@0
|
149 |
break;
|
sl@0
|
150 |
case EGCD:
|
sl@0
|
151 |
result = a.GCDL(b);
|
sl@0
|
152 |
a.Set(result);
|
sl@0
|
153 |
break;
|
sl@0
|
154 |
case EInverseMod:
|
sl@0
|
155 |
result = a.InverseModL(b);
|
sl@0
|
156 |
a.Set(result);
|
sl@0
|
157 |
break;
|
sl@0
|
158 |
default:
|
sl@0
|
159 |
User::Panic(_L("tbasicmathsvector"), 2);
|
sl@0
|
160 |
break;
|
sl@0
|
161 |
}
|
sl@0
|
162 |
|
sl@0
|
163 |
if( a != ans )
|
sl@0
|
164 |
{
|
sl@0
|
165 |
iResult = EFalse;
|
sl@0
|
166 |
}
|
sl@0
|
167 |
CleanupStack::PopAndDestroy(&ans);
|
sl@0
|
168 |
CleanupStack::PopAndDestroy(&b);
|
sl@0
|
169 |
CleanupStack::PopAndDestroy(&a);
|
sl@0
|
170 |
|
sl@0
|
171 |
User::RequestComplete(status, KErrNone);
|
sl@0
|
172 |
iActionState = CTestAction::EPostrequisite;
|
sl@0
|
173 |
__UHEAP_MARKEND;
|
sl@0
|
174 |
}
|
sl@0
|
175 |
|