|
1 /* |
|
2 * Copyright (c) 2005-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 * ASN1TestAction.cpp: implementation of the CASN1NormalTest class. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 /** |
|
23 @file |
|
24 */ |
|
25 |
|
26 #include "tasn1normaltest.h" |
|
27 #include "testnull.h" |
|
28 #include "testboolean.h" |
|
29 #include "testint.h" |
|
30 #include "testbigint.h" |
|
31 #include "testoctetstr.h" |
|
32 #include "testoid.h" |
|
33 #include "testinvalidoid.h" |
|
34 #include "testgeneralizedtime.h" |
|
35 #include "testsequence.h" |
|
36 #include "testexplicittag.h" |
|
37 #include "testimplicittag.h" |
|
38 #include "testoutput.h" |
|
39 #include "testbitstr.h" |
|
40 #include "t_input.h" |
|
41 |
|
42 ////////////////////////////////////////////////////////////////////// |
|
43 // Construction/Destruction |
|
44 ////////////////////////////////////////////////////////////////////// |
|
45 TInt CASN1NormalTest::iReportCount = 1; |
|
46 |
|
47 _LIT(KASN1TestStart, "<asn1test>"); |
|
48 _LIT(KTypeStart, "<type>"); |
|
49 _LIT(KIntType, "int"); |
|
50 _LIT(KBigIntType, "bigint"); |
|
51 _LIT(KBooleanType, "boolean"); |
|
52 _LIT(KNullType, "null"); |
|
53 _LIT(KExplicitTagType, "explicittag"); |
|
54 _LIT(KImplicitTagType, "implicittag"); |
|
55 _LIT(KGeneralizedTimeType, "generalizedtime"); |
|
56 _LIT(KOctetStringType, "octetstring"); |
|
57 _LIT(KObjectIDType, "objectid"); |
|
58 _LIT(KInvaidObjectIDType, "invalidobjectid"); |
|
59 _LIT(KSequenceType, "sequence"); |
|
60 _LIT(KOutputType, "output"); |
|
61 _LIT(KBitStrType, "bitstring"); |
|
62 |
|
63 CASN1NormalTest::~CASN1NormalTest() |
|
64 { |
|
65 delete iTestType; |
|
66 } |
|
67 |
|
68 CASN1NormalTest::CASN1NormalTest(RFs& /*aFs*/, |
|
69 CConsoleBase& aConsole, |
|
70 Output& aOut) |
|
71 : CTestAction(aConsole, aOut), iTestType(0), iPercentReported(-1), iReportNumber(iReportCount++) |
|
72 { |
|
73 } |
|
74 |
|
75 CTestAction* CASN1NormalTest::NewL(RFs& aFs, |
|
76 CConsoleBase& aConsole, |
|
77 Output& aOut, |
|
78 const TTestActionSpec& aTestActionSpec) |
|
79 { |
|
80 CTestAction* self = CASN1NormalTest::NewLC(aFs, aConsole, |
|
81 aOut, aTestActionSpec); |
|
82 CleanupStack::Pop(self); |
|
83 return self; |
|
84 } |
|
85 |
|
86 CTestAction* CASN1NormalTest::NewLC(RFs& aFs, |
|
87 CConsoleBase& aConsole, |
|
88 Output& aOut, |
|
89 const TTestActionSpec& aTestActionSpec) |
|
90 { |
|
91 CASN1NormalTest* self = new(ELeave) CASN1NormalTest(aFs, aConsole, aOut); |
|
92 CleanupStack::PushL(self); |
|
93 self->ConstructL(aTestActionSpec); |
|
94 return self; |
|
95 } |
|
96 |
|
97 |
|
98 void CASN1NormalTest::ConstructL(const TTestActionSpec& aTestActionSpec) |
|
99 { |
|
100 CTestAction::ConstructL(aTestActionSpec); |
|
101 HBufC* body = HBufC::NewLC(aTestActionSpec.iActionBody.Length()); |
|
102 |
|
103 body->Des().Copy(aTestActionSpec.iActionBody); |
|
104 TPtrC rootCert = Input::ParseElement(*body, KASN1TestStart); |
|
105 TPtrC iType = Input::ParseElement(rootCert, KTypeStart); |
|
106 |
|
107 // constucts correct class depending on string |
|
108 if(iType.CompareF(KIntType)==0) |
|
109 iTestType = CTestInt::NewL(*this); |
|
110 else if(iType.CompareF(KBigIntType)==0) |
|
111 iTestType = CTestBigInt::NewL(*this); |
|
112 else if(iType.CompareF(KBooleanType)==0) |
|
113 iTestType = CTestBoolean::NewL(*this); |
|
114 else if(iType.CompareF(KNullType)==0) |
|
115 iTestType = CTestNull::NewL(*this); |
|
116 else if(iType.CompareF(KExplicitTagType)==0) |
|
117 iTestType = CTestExplicitTag::NewL(*this); |
|
118 else if(iType.CompareF(KImplicitTagType)==0) |
|
119 iTestType = CTestImplicitTag::NewL(*this); |
|
120 else if(iType.CompareF(KGeneralizedTimeType)==0) |
|
121 iTestType = CTestGeneralizedTime::NewL(*this); |
|
122 else if(iType.CompareF(KOctetStringType)==0) |
|
123 iTestType = CTestOctetString::NewL(*this); |
|
124 else if(iType.CompareF(KObjectIDType)==0) |
|
125 iTestType = CTestOID::NewL(*this); |
|
126 else if(iType.CompareF(KSequenceType)==0) |
|
127 iTestType = CTestSequence::NewL(*this); |
|
128 else if(iType.CompareF(KOutputType)==0) |
|
129 iTestType = CTestOutput::NewL(*this); |
|
130 else if(iType.CompareF(KBitStrType)==0) |
|
131 iTestType = CTestBitStr::NewL(*this); |
|
132 else if(iType.CompareF(KInvaidObjectIDType)==0) |
|
133 iTestType = CTestInvalidOID::NewL(*this); |
|
134 |
|
135 if(iTestType) |
|
136 SetScriptError(iTestType->ConstructL(aTestActionSpec), iTestType->iSyntaxErrorDescription); |
|
137 |
|
138 CleanupStack::PopAndDestroy(); // body |
|
139 } |
|
140 |
|
141 void CASN1NormalTest::PerformAction(TRequestStatus& aStatus) |
|
142 { |
|
143 TRAPD(err, iResult = iTestType->PerformTestsL(iConsole)); |
|
144 if (err==KErrNoMemory) |
|
145 User::Leave(err); |
|
146 else |
|
147 { |
|
148 iActionState = EPostrequisite; |
|
149 TRequestStatus* status = &aStatus; |
|
150 User::RequestComplete(status, err); |
|
151 } |
|
152 } |
|
153 |
|
154 |
|
155 void CASN1NormalTest::ReportProgressL(const TInt aError, const TInt aCount, const TInt aMax) |
|
156 { |
|
157 if(aMax == 0) return; |
|
158 TInt newPercentage = aCount * 100 / aMax; |
|
159 |
|
160 if (newPercentage > iPercentReported && iResult == 0) |
|
161 { |
|
162 iPercentReported = newPercentage; |
|
163 |
|
164 iConsole.Printf(_L(" %d"), iPercentReported); |
|
165 |
|
166 if (iPercentReported == 100) |
|
167 { |
|
168 iConsole.Write(_L("%")); |
|
169 iConsole.Write(_L(" Completed:\n")); |
|
170 CheckResult(aError); |
|
171 iPercentReported = -1; |
|
172 } |
|
173 } |
|
174 if(aError != 0) |
|
175 { |
|
176 iFinished = ETrue; |
|
177 iResult = EFalse; |
|
178 } |
|
179 } |
|
180 |
|
181 void CASN1NormalTest::DoCheckResult(TInt aError) |
|
182 { |
|
183 if(aError == 0 && !iFinished) |
|
184 { |
|
185 iFinished = ETrue; |
|
186 iResult = ETrue; |
|
187 } |
|
188 } |
|
189 |
|
190 |
|
191 void CASN1NormalTest::DoReportAction() |
|
192 { |
|
193 HBufC *tmp = HBufC::NewMaxLC(iNameInfo->Length()); |
|
194 |
|
195 // converts name to unicode (if necessary) and dumps it out to screen |
|
196 tmp->Des().Copy(*iNameInfo); |
|
197 iConsole.Printf(_L("\n")); |
|
198 iConsole.Printf(_L("Report %d - "), iReportNumber); |
|
199 iConsole.Write(*tmp); |
|
200 iConsole.Printf(_L("\n")); |
|
201 |
|
202 CleanupStack::PopAndDestroy(); // tmp |
|
203 } |
|
204 |
|
205 TBool CASN1NormalTest::TestResult(TInt /*aError*/) |
|
206 { |
|
207 return 0; |
|
208 } |
|
209 |
|
210 void CASN1NormalTest::PerformCancel() |
|
211 { |
|
212 } |
|
213 |
|
214 void CASN1NormalTest::Reset() |
|
215 { |
|
216 } |