Update contrib.
2 * Copyright (c) 2005-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.
15 * ASN1TestAction.cpp: implementation of the CASN1NormalTest class.
24 #include "tasn1normaltest.h"
26 #include "testboolean.h"
28 #include "testbigint.h"
29 #include "testoctetstr.h"
31 #include "testinvalidoid.h"
32 #include "testgeneralizedtime.h"
33 #include "testsequence.h"
34 #include "testexplicittag.h"
35 #include "testimplicittag.h"
36 #include "testoutput.h"
37 #include "testbitstr.h"
40 //////////////////////////////////////////////////////////////////////
41 // Construction/Destruction
42 //////////////////////////////////////////////////////////////////////
43 TInt CASN1NormalTest::iReportCount = 1;
45 _LIT(KASN1TestStart, "<asn1test>");
46 _LIT(KTypeStart, "<type>");
47 _LIT(KIntType, "int");
48 _LIT(KBigIntType, "bigint");
49 _LIT(KBooleanType, "boolean");
50 _LIT(KNullType, "null");
51 _LIT(KExplicitTagType, "explicittag");
52 _LIT(KImplicitTagType, "implicittag");
53 _LIT(KGeneralizedTimeType, "generalizedtime");
54 _LIT(KOctetStringType, "octetstring");
55 _LIT(KObjectIDType, "objectid");
56 _LIT(KInvaidObjectIDType, "invalidobjectid");
57 _LIT(KSequenceType, "sequence");
58 _LIT(KOutputType, "output");
59 _LIT(KBitStrType, "bitstring");
61 CASN1NormalTest::~CASN1NormalTest()
66 CASN1NormalTest::CASN1NormalTest(RFs& /*aFs*/,
67 CConsoleBase& aConsole,
69 : CTestAction(aConsole, aOut), iTestType(0), iPercentReported(-1), iReportNumber(iReportCount++)
73 CTestAction* CASN1NormalTest::NewL(RFs& aFs,
74 CConsoleBase& aConsole,
76 const TTestActionSpec& aTestActionSpec)
78 CTestAction* self = CASN1NormalTest::NewLC(aFs, aConsole,
79 aOut, aTestActionSpec);
80 CleanupStack::Pop(self);
84 CTestAction* CASN1NormalTest::NewLC(RFs& aFs,
85 CConsoleBase& aConsole,
87 const TTestActionSpec& aTestActionSpec)
89 CASN1NormalTest* self = new(ELeave) CASN1NormalTest(aFs, aConsole, aOut);
90 CleanupStack::PushL(self);
91 self->ConstructL(aTestActionSpec);
96 void CASN1NormalTest::ConstructL(const TTestActionSpec& aTestActionSpec)
98 CTestAction::ConstructL(aTestActionSpec);
99 HBufC* body = HBufC::NewLC(aTestActionSpec.iActionBody.Length());
101 body->Des().Copy(aTestActionSpec.iActionBody);
102 TPtrC rootCert = Input::ParseElement(*body, KASN1TestStart);
103 TPtrC iType = Input::ParseElement(rootCert, KTypeStart);
105 // constucts correct class depending on string
106 if(iType.CompareF(KIntType)==0)
107 iTestType = CTestInt::NewL(*this);
108 else if(iType.CompareF(KBigIntType)==0)
109 iTestType = CTestBigInt::NewL(*this);
110 else if(iType.CompareF(KBooleanType)==0)
111 iTestType = CTestBoolean::NewL(*this);
112 else if(iType.CompareF(KNullType)==0)
113 iTestType = CTestNull::NewL(*this);
114 else if(iType.CompareF(KExplicitTagType)==0)
115 iTestType = CTestExplicitTag::NewL(*this);
116 else if(iType.CompareF(KImplicitTagType)==0)
117 iTestType = CTestImplicitTag::NewL(*this);
118 else if(iType.CompareF(KGeneralizedTimeType)==0)
119 iTestType = CTestGeneralizedTime::NewL(*this);
120 else if(iType.CompareF(KOctetStringType)==0)
121 iTestType = CTestOctetString::NewL(*this);
122 else if(iType.CompareF(KObjectIDType)==0)
123 iTestType = CTestOID::NewL(*this);
124 else if(iType.CompareF(KSequenceType)==0)
125 iTestType = CTestSequence::NewL(*this);
126 else if(iType.CompareF(KOutputType)==0)
127 iTestType = CTestOutput::NewL(*this);
128 else if(iType.CompareF(KBitStrType)==0)
129 iTestType = CTestBitStr::NewL(*this);
130 else if(iType.CompareF(KInvaidObjectIDType)==0)
131 iTestType = CTestInvalidOID::NewL(*this);
134 SetScriptError(iTestType->ConstructL(aTestActionSpec), iTestType->iSyntaxErrorDescription);
136 CleanupStack::PopAndDestroy(); // body
139 void CASN1NormalTest::PerformAction(TRequestStatus& aStatus)
141 TRAPD(err, iResult = iTestType->PerformTestsL(iConsole));
142 if (err==KErrNoMemory)
146 iActionState = EPostrequisite;
147 TRequestStatus* status = &aStatus;
148 User::RequestComplete(status, err);
153 void CASN1NormalTest::ReportProgressL(const TInt aError, const TInt aCount, const TInt aMax)
155 if(aMax == 0) return;
156 TInt newPercentage = aCount * 100 / aMax;
158 if (newPercentage > iPercentReported && iResult == 0)
160 iPercentReported = newPercentage;
162 iConsole.Printf(_L(" %d"), iPercentReported);
164 if (iPercentReported == 100)
166 iConsole.Write(_L("%"));
167 iConsole.Write(_L(" Completed:\n"));
169 iPercentReported = -1;
179 void CASN1NormalTest::DoCheckResult(TInt aError)
181 if(aError == 0 && !iFinished)
189 void CASN1NormalTest::DoReportAction()
191 HBufC *tmp = HBufC::NewMaxLC(iNameInfo->Length());
193 // converts name to unicode (if necessary) and dumps it out to screen
194 tmp->Des().Copy(*iNameInfo);
195 iConsole.Printf(_L("\n"));
196 iConsole.Printf(_L("Report %d - "), iReportNumber);
197 iConsole.Write(*tmp);
198 iConsole.Printf(_L("\n"));
200 CleanupStack::PopAndDestroy(); // tmp
203 TBool CASN1NormalTest::TestResult(TInt /*aError*/)
208 void CASN1NormalTest::PerformCancel()
212 void CASN1NormalTest::Reset()