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