sl@0: /* sl@0: * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * ASN1TestAction.cpp: implementation of the CASN1NormalTest class. sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: */ sl@0: sl@0: #include "tasn1normaltest.h" sl@0: #include "testnull.h" sl@0: #include "testboolean.h" sl@0: #include "testint.h" sl@0: #include "testbigint.h" sl@0: #include "testoctetstr.h" sl@0: #include "testoid.h" sl@0: #include "testinvalidoid.h" sl@0: #include "testgeneralizedtime.h" sl@0: #include "testsequence.h" sl@0: #include "testexplicittag.h" sl@0: #include "testimplicittag.h" sl@0: #include "testoutput.h" sl@0: #include "testbitstr.h" sl@0: #include "t_input.h" sl@0: sl@0: ////////////////////////////////////////////////////////////////////// sl@0: // Construction/Destruction sl@0: ////////////////////////////////////////////////////////////////////// sl@0: TInt CASN1NormalTest::iReportCount = 1; sl@0: sl@0: _LIT(KASN1TestStart, ""); sl@0: _LIT(KTypeStart, ""); sl@0: _LIT(KIntType, "int"); sl@0: _LIT(KBigIntType, "bigint"); sl@0: _LIT(KBooleanType, "boolean"); sl@0: _LIT(KNullType, "null"); sl@0: _LIT(KExplicitTagType, "explicittag"); sl@0: _LIT(KImplicitTagType, "implicittag"); sl@0: _LIT(KGeneralizedTimeType, "generalizedtime"); sl@0: _LIT(KOctetStringType, "octetstring"); sl@0: _LIT(KObjectIDType, "objectid"); sl@0: _LIT(KInvaidObjectIDType, "invalidobjectid"); sl@0: _LIT(KSequenceType, "sequence"); sl@0: _LIT(KOutputType, "output"); sl@0: _LIT(KBitStrType, "bitstring"); sl@0: sl@0: CASN1NormalTest::~CASN1NormalTest() sl@0: { sl@0: delete iTestType; sl@0: } sl@0: sl@0: CASN1NormalTest::CASN1NormalTest(RFs& /*aFs*/, sl@0: CConsoleBase& aConsole, sl@0: Output& aOut) sl@0: : CTestAction(aConsole, aOut), iTestType(0), iPercentReported(-1), iReportNumber(iReportCount++) sl@0: { sl@0: } sl@0: sl@0: CTestAction* CASN1NormalTest::NewL(RFs& aFs, sl@0: CConsoleBase& aConsole, sl@0: Output& aOut, sl@0: const TTestActionSpec& aTestActionSpec) sl@0: { sl@0: CTestAction* self = CASN1NormalTest::NewLC(aFs, aConsole, sl@0: aOut, aTestActionSpec); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: CTestAction* CASN1NormalTest::NewLC(RFs& aFs, sl@0: CConsoleBase& aConsole, sl@0: Output& aOut, sl@0: const TTestActionSpec& aTestActionSpec) sl@0: { sl@0: CASN1NormalTest* self = new(ELeave) CASN1NormalTest(aFs, aConsole, aOut); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aTestActionSpec); sl@0: return self; sl@0: } sl@0: sl@0: sl@0: void CASN1NormalTest::ConstructL(const TTestActionSpec& aTestActionSpec) sl@0: { sl@0: CTestAction::ConstructL(aTestActionSpec); sl@0: HBufC* body = HBufC::NewLC(aTestActionSpec.iActionBody.Length()); sl@0: sl@0: body->Des().Copy(aTestActionSpec.iActionBody); sl@0: TPtrC rootCert = Input::ParseElement(*body, KASN1TestStart); sl@0: TPtrC iType = Input::ParseElement(rootCert, KTypeStart); sl@0: sl@0: // constucts correct class depending on string sl@0: if(iType.CompareF(KIntType)==0) sl@0: iTestType = CTestInt::NewL(*this); sl@0: else if(iType.CompareF(KBigIntType)==0) sl@0: iTestType = CTestBigInt::NewL(*this); sl@0: else if(iType.CompareF(KBooleanType)==0) sl@0: iTestType = CTestBoolean::NewL(*this); sl@0: else if(iType.CompareF(KNullType)==0) sl@0: iTestType = CTestNull::NewL(*this); sl@0: else if(iType.CompareF(KExplicitTagType)==0) sl@0: iTestType = CTestExplicitTag::NewL(*this); sl@0: else if(iType.CompareF(KImplicitTagType)==0) sl@0: iTestType = CTestImplicitTag::NewL(*this); sl@0: else if(iType.CompareF(KGeneralizedTimeType)==0) sl@0: iTestType = CTestGeneralizedTime::NewL(*this); sl@0: else if(iType.CompareF(KOctetStringType)==0) sl@0: iTestType = CTestOctetString::NewL(*this); sl@0: else if(iType.CompareF(KObjectIDType)==0) sl@0: iTestType = CTestOID::NewL(*this); sl@0: else if(iType.CompareF(KSequenceType)==0) sl@0: iTestType = CTestSequence::NewL(*this); sl@0: else if(iType.CompareF(KOutputType)==0) sl@0: iTestType = CTestOutput::NewL(*this); sl@0: else if(iType.CompareF(KBitStrType)==0) sl@0: iTestType = CTestBitStr::NewL(*this); sl@0: else if(iType.CompareF(KInvaidObjectIDType)==0) sl@0: iTestType = CTestInvalidOID::NewL(*this); sl@0: sl@0: if(iTestType) sl@0: SetScriptError(iTestType->ConstructL(aTestActionSpec), iTestType->iSyntaxErrorDescription); sl@0: sl@0: CleanupStack::PopAndDestroy(); // body sl@0: } sl@0: sl@0: void CASN1NormalTest::PerformAction(TRequestStatus& aStatus) sl@0: { sl@0: TRAPD(err, iResult = iTestType->PerformTestsL(iConsole)); sl@0: if (err==KErrNoMemory) sl@0: User::Leave(err); sl@0: else sl@0: { sl@0: iActionState = EPostrequisite; sl@0: TRequestStatus* status = &aStatus; sl@0: User::RequestComplete(status, err); sl@0: } sl@0: } sl@0: sl@0: sl@0: void CASN1NormalTest::ReportProgressL(const TInt aError, const TInt aCount, const TInt aMax) sl@0: { sl@0: if(aMax == 0) return; sl@0: TInt newPercentage = aCount * 100 / aMax; sl@0: sl@0: if (newPercentage > iPercentReported && iResult == 0) sl@0: { sl@0: iPercentReported = newPercentage; sl@0: sl@0: iConsole.Printf(_L(" %d"), iPercentReported); sl@0: sl@0: if (iPercentReported == 100) sl@0: { sl@0: iConsole.Write(_L("%")); sl@0: iConsole.Write(_L(" Completed:\n")); sl@0: CheckResult(aError); sl@0: iPercentReported = -1; sl@0: } sl@0: } sl@0: if(aError != 0) sl@0: { sl@0: iFinished = ETrue; sl@0: iResult = EFalse; sl@0: } sl@0: } sl@0: sl@0: void CASN1NormalTest::DoCheckResult(TInt aError) sl@0: { sl@0: if(aError == 0 && !iFinished) sl@0: { sl@0: iFinished = ETrue; sl@0: iResult = ETrue; sl@0: } sl@0: } sl@0: sl@0: sl@0: void CASN1NormalTest::DoReportAction() sl@0: { sl@0: HBufC *tmp = HBufC::NewMaxLC(iNameInfo->Length()); sl@0: sl@0: // converts name to unicode (if necessary) and dumps it out to screen sl@0: tmp->Des().Copy(*iNameInfo); sl@0: iConsole.Printf(_L("\n")); sl@0: iConsole.Printf(_L("Report %d - "), iReportNumber); sl@0: iConsole.Write(*tmp); sl@0: iConsole.Printf(_L("\n")); sl@0: sl@0: CleanupStack::PopAndDestroy(); // tmp sl@0: } sl@0: sl@0: TBool CASN1NormalTest::TestResult(TInt /*aError*/) sl@0: { sl@0: return 0; sl@0: } sl@0: sl@0: void CASN1NormalTest::PerformCancel() sl@0: { sl@0: } sl@0: sl@0: void CASN1NormalTest::Reset() sl@0: { sl@0: } sl@0: