1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/cryptoservices/certificateandkeymgmt/tasn1/tasn1normaltest.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,215 @@
1.4 +/*
1.5 +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +* ASN1TestAction.cpp: implementation of the CASN1NormalTest class.
1.19 +*
1.20 +*/
1.21 +
1.22 +
1.23 +/**
1.24 + @file
1.25 +*/
1.26 +
1.27 +#include "tasn1normaltest.h"
1.28 +#include "testnull.h"
1.29 +#include "testboolean.h"
1.30 +#include "testint.h"
1.31 +#include "testbigint.h"
1.32 +#include "testoctetstr.h"
1.33 +#include "testoid.h"
1.34 +#include "testinvalidoid.h"
1.35 +#include "testgeneralizedtime.h"
1.36 +#include "testsequence.h"
1.37 +#include "testexplicittag.h"
1.38 +#include "testimplicittag.h"
1.39 +#include "testoutput.h"
1.40 +#include "testbitstr.h"
1.41 +#include "t_input.h"
1.42 +
1.43 +//////////////////////////////////////////////////////////////////////
1.44 +// Construction/Destruction
1.45 +//////////////////////////////////////////////////////////////////////
1.46 +TInt CASN1NormalTest::iReportCount = 1;
1.47 +
1.48 +_LIT(KASN1TestStart, "<asn1test>");
1.49 +_LIT(KTypeStart, "<type>");
1.50 +_LIT(KIntType, "int");
1.51 +_LIT(KBigIntType, "bigint");
1.52 +_LIT(KBooleanType, "boolean");
1.53 +_LIT(KNullType, "null");
1.54 +_LIT(KExplicitTagType, "explicittag");
1.55 +_LIT(KImplicitTagType, "implicittag");
1.56 +_LIT(KGeneralizedTimeType, "generalizedtime");
1.57 +_LIT(KOctetStringType, "octetstring");
1.58 +_LIT(KObjectIDType, "objectid");
1.59 +_LIT(KInvaidObjectIDType, "invalidobjectid");
1.60 +_LIT(KSequenceType, "sequence");
1.61 +_LIT(KOutputType, "output");
1.62 +_LIT(KBitStrType, "bitstring");
1.63 +
1.64 +CASN1NormalTest::~CASN1NormalTest()
1.65 + {
1.66 + delete iTestType;
1.67 + }
1.68 +
1.69 +CASN1NormalTest::CASN1NormalTest(RFs& /*aFs*/,
1.70 + CConsoleBase& aConsole,
1.71 + Output& aOut)
1.72 +: CTestAction(aConsole, aOut), iTestType(0), iPercentReported(-1), iReportNumber(iReportCount++)
1.73 + {
1.74 + }
1.75 +
1.76 +CTestAction* CASN1NormalTest::NewL(RFs& aFs,
1.77 + CConsoleBase& aConsole,
1.78 + Output& aOut,
1.79 + const TTestActionSpec& aTestActionSpec)
1.80 + {
1.81 + CTestAction* self = CASN1NormalTest::NewLC(aFs, aConsole,
1.82 + aOut, aTestActionSpec);
1.83 + CleanupStack::Pop(self);
1.84 + return self;
1.85 + }
1.86 +
1.87 +CTestAction* CASN1NormalTest::NewLC(RFs& aFs,
1.88 + CConsoleBase& aConsole,
1.89 + Output& aOut,
1.90 + const TTestActionSpec& aTestActionSpec)
1.91 + {
1.92 + CASN1NormalTest* self = new(ELeave) CASN1NormalTest(aFs, aConsole, aOut);
1.93 + CleanupStack::PushL(self);
1.94 + self->ConstructL(aTestActionSpec);
1.95 + return self;
1.96 + }
1.97 +
1.98 +
1.99 +void CASN1NormalTest::ConstructL(const TTestActionSpec& aTestActionSpec)
1.100 + {
1.101 + CTestAction::ConstructL(aTestActionSpec);
1.102 + HBufC* body = HBufC::NewLC(aTestActionSpec.iActionBody.Length());
1.103 +
1.104 + body->Des().Copy(aTestActionSpec.iActionBody);
1.105 + TPtrC rootCert = Input::ParseElement(*body, KASN1TestStart);
1.106 + TPtrC iType = Input::ParseElement(rootCert, KTypeStart);
1.107 +
1.108 + // constucts correct class depending on string
1.109 + if(iType.CompareF(KIntType)==0)
1.110 + iTestType = CTestInt::NewL(*this);
1.111 + else if(iType.CompareF(KBigIntType)==0)
1.112 + iTestType = CTestBigInt::NewL(*this);
1.113 + else if(iType.CompareF(KBooleanType)==0)
1.114 + iTestType = CTestBoolean::NewL(*this);
1.115 + else if(iType.CompareF(KNullType)==0)
1.116 + iTestType = CTestNull::NewL(*this);
1.117 + else if(iType.CompareF(KExplicitTagType)==0)
1.118 + iTestType = CTestExplicitTag::NewL(*this);
1.119 + else if(iType.CompareF(KImplicitTagType)==0)
1.120 + iTestType = CTestImplicitTag::NewL(*this);
1.121 + else if(iType.CompareF(KGeneralizedTimeType)==0)
1.122 + iTestType = CTestGeneralizedTime::NewL(*this);
1.123 + else if(iType.CompareF(KOctetStringType)==0)
1.124 + iTestType = CTestOctetString::NewL(*this);
1.125 + else if(iType.CompareF(KObjectIDType)==0)
1.126 + iTestType = CTestOID::NewL(*this);
1.127 + else if(iType.CompareF(KSequenceType)==0)
1.128 + iTestType = CTestSequence::NewL(*this);
1.129 + else if(iType.CompareF(KOutputType)==0)
1.130 + iTestType = CTestOutput::NewL(*this);
1.131 + else if(iType.CompareF(KBitStrType)==0)
1.132 + iTestType = CTestBitStr::NewL(*this);
1.133 + else if(iType.CompareF(KInvaidObjectIDType)==0)
1.134 + iTestType = CTestInvalidOID::NewL(*this);
1.135 +
1.136 + if(iTestType)
1.137 + SetScriptError(iTestType->ConstructL(aTestActionSpec), iTestType->iSyntaxErrorDescription);
1.138 +
1.139 + CleanupStack::PopAndDestroy(); // body
1.140 + }
1.141 +
1.142 +void CASN1NormalTest::PerformAction(TRequestStatus& aStatus)
1.143 + {
1.144 + TRAPD(err, iResult = iTestType->PerformTestsL(iConsole));
1.145 + if (err==KErrNoMemory)
1.146 + User::Leave(err);
1.147 + else
1.148 + {
1.149 + iActionState = EPostrequisite;
1.150 + TRequestStatus* status = &aStatus;
1.151 + User::RequestComplete(status, err);
1.152 + }
1.153 + }
1.154 +
1.155 +
1.156 +void CASN1NormalTest::ReportProgressL(const TInt aError, const TInt aCount, const TInt aMax)
1.157 + {
1.158 + if(aMax == 0) return;
1.159 + TInt newPercentage = aCount * 100 / aMax;
1.160 +
1.161 + if (newPercentage > iPercentReported && iResult == 0)
1.162 + {
1.163 + iPercentReported = newPercentage;
1.164 +
1.165 + iConsole.Printf(_L(" %d"), iPercentReported);
1.166 +
1.167 + if (iPercentReported == 100)
1.168 + {
1.169 + iConsole.Write(_L("%"));
1.170 + iConsole.Write(_L(" Completed:\n"));
1.171 + CheckResult(aError);
1.172 + iPercentReported = -1;
1.173 + }
1.174 + }
1.175 + if(aError != 0)
1.176 + {
1.177 + iFinished = ETrue;
1.178 + iResult = EFalse;
1.179 + }
1.180 + }
1.181 +
1.182 +void CASN1NormalTest::DoCheckResult(TInt aError)
1.183 + {
1.184 + if(aError == 0 && !iFinished)
1.185 + {
1.186 + iFinished = ETrue;
1.187 + iResult = ETrue;
1.188 + }
1.189 + }
1.190 +
1.191 +
1.192 +void CASN1NormalTest::DoReportAction()
1.193 + {
1.194 + HBufC *tmp = HBufC::NewMaxLC(iNameInfo->Length());
1.195 +
1.196 + // converts name to unicode (if necessary) and dumps it out to screen
1.197 + tmp->Des().Copy(*iNameInfo);
1.198 + iConsole.Printf(_L("\n"));
1.199 + iConsole.Printf(_L("Report %d - "), iReportNumber);
1.200 + iConsole.Write(*tmp);
1.201 + iConsole.Printf(_L("\n"));
1.202 +
1.203 + CleanupStack::PopAndDestroy(); // tmp
1.204 + }
1.205 +
1.206 +TBool CASN1NormalTest::TestResult(TInt /*aError*/)
1.207 + {
1.208 + return 0;
1.209 + }
1.210 +
1.211 +void CASN1NormalTest::PerformCancel()
1.212 + {
1.213 + }
1.214 +
1.215 +void CASN1NormalTest::Reset()
1.216 + {
1.217 + }
1.218 +