os/security/cryptoservices/certificateandkeymgmt/tasn1/testparameter.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/cryptoservices/certificateandkeymgmt/tasn1/testparameter.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,167 @@
     1.4 +/*
     1.5 +* Copyright (c) 2006-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 +* TestParameter.cpp: implementation of the CTestParameter class.
    1.19 +*
    1.20 +*/
    1.21 +
    1.22 +
    1.23 +/**
    1.24 + @file
    1.25 +*/
    1.26 +
    1.27 +#include "testparameter.h"
    1.28 +
    1.29 +
    1.30 +CTestParameter::CTestParameter() : iValid(EFalse) 
    1.31 +{
    1.32 +};
    1.33 +
    1.34 +
    1.35 +CIntTestParameter* CIntTestParameter::NewL(TDes& aValue)
    1.36 +	{
    1.37 +	CIntTestParameter* self = CIntTestParameter::NewLC(aValue);
    1.38 +	CleanupStack::Pop(self);
    1.39 +	return self;
    1.40 +	}
    1.41 +
    1.42 +CIntTestParameter* CIntTestParameter::NewLC(TDes& aValue)
    1.43 +	{
    1.44 +	CIntTestParameter* self = new(ELeave) CIntTestParameter();
    1.45 +	CleanupStack::PushL(self);
    1.46 +	self->Construct(aValue);
    1.47 +	return self;
    1.48 +	}
    1.49 +
    1.50 +void CIntTestParameter::Construct(TDes& aValue)
    1.51 +	{
    1.52 +	TLex lexValue(aValue);
    1.53 +
    1.54 +	if(aValue.Left(2) == _L("0x"))
    1.55 +		{
    1.56 +		// its a hex number 
    1.57 +		TUint hexValue;
    1.58 +		TLex hexLex(aValue.Mid(2));
    1.59 +
    1.60 +		if(hexLex.Val(hexValue, EHex)!=KErrNone)
    1.61 +			return;
    1.62 +		// checks if hexLex is at end of string, if not there was garbage in the string
    1.63 +		// so throw it out
    1.64 +		else if(!hexLex.Eos())
    1.65 +			return;
    1.66 +
    1.67 +		iValue = STATIC_CAST(TInt,hexValue);
    1.68 +		}
    1.69 +	else if(lexValue.Val(iValue)!=KErrNone)
    1.70 +		return;
    1.71 +		// checks if lexValue is at end of string, if not there was garbage in the string
    1.72 +		// so throw it out
    1.73 +	else if(!lexValue.Eos())
    1.74 +		return;
    1.75 +
    1.76 +	iValid = ETrue;
    1.77 +	}
    1.78 +
    1.79 +CIntRangeTestParameter* CIntRangeTestParameter::NewL(TDes& aValue)
    1.80 +	{
    1.81 +	CIntRangeTestParameter* self = CIntRangeTestParameter::NewLC(aValue);
    1.82 +	CleanupStack::Pop(self);
    1.83 +	return self;
    1.84 +	}
    1.85 +
    1.86 +CIntRangeTestParameter* CIntRangeTestParameter::NewLC(TDes& aValue)
    1.87 +	{
    1.88 +	CIntRangeTestParameter* self = new(ELeave) CIntRangeTestParameter();
    1.89 +	CleanupStack::PushL(self);
    1.90 +	self->Construct(aValue);
    1.91 +	return self;
    1.92 +	}
    1.93 +
    1.94 +void CIntRangeTestParameter::Construct(TDes& aValue)
    1.95 +	{
    1.96 +	if(aValue.Find(_L("..")) != KErrNotFound)
    1.97 +		{
    1.98 +		TInt pos = aValue.Find(_L(".."));
    1.99 +		TLex startLex(aValue.Left(pos));
   1.100 +		TLex endLex(aValue.Mid(pos+2));
   1.101 +
   1.102 +		if(startLex.Val(iStart)!=KErrNone)
   1.103 +			return;
   1.104 +			// checks if startLex is at end of string, if not there was garbage in the string so throw it out
   1.105 +		else if(!startLex.Eos())
   1.106 +			return;
   1.107 +
   1.108 +		if(endLex.Val(iFinish)!=KErrNone)
   1.109 +			return;
   1.110 +			// checks if startLex is at end of string, if not there was garbage in the string so throw it out
   1.111 +		else if(!endLex.Eos())
   1.112 +			return;
   1.113 +		// checks if range is doable
   1.114 +		if(iStart > iFinish)
   1.115 +			return;
   1.116 +		}
   1.117 +	else
   1.118 +		return;
   1.119 +	iValid = ETrue;
   1.120 +	}
   1.121 +
   1.122 +CRandomTestParameter* CRandomTestParameter::NewL(TDes& aValue)
   1.123 +	{
   1.124 +	CRandomTestParameter* self = CRandomTestParameter::NewLC(aValue);
   1.125 +	CleanupStack::Pop(self);
   1.126 +	return self;
   1.127 +	}
   1.128 +
   1.129 +CRandomTestParameter* CRandomTestParameter::NewLC(TDes& aValue)
   1.130 +	{
   1.131 +	CRandomTestParameter* self = new(ELeave) CRandomTestParameter();
   1.132 +	CleanupStack::PushL(self);
   1.133 +	self->Construct(aValue);
   1.134 +	return self;
   1.135 +	}
   1.136 +
   1.137 +
   1.138 +void CRandomTestParameter::Construct(TDes& aValue)
   1.139 +	{
   1.140 +	TLex lexValue(aValue);
   1.141 +
   1.142 +	if(lexValue.Val(iInterations)!=KErrNone)
   1.143 +		return;
   1.144 +	else if(!lexValue.Eos())
   1.145 +		// checks if startLex is at end of string, if not there was garbage in the string so throw it out
   1.146 +		return;
   1.147 +
   1.148 +	iValid = ETrue;
   1.149 +	}
   1.150 +
   1.151 +CStringTestParameter* CStringTestParameter::NewL(TDes& aValue)
   1.152 +	{
   1.153 +	CStringTestParameter* self = CStringTestParameter::NewLC(aValue);
   1.154 +	CleanupStack::Pop(self);
   1.155 +	return self;
   1.156 +	}
   1.157 +
   1.158 +CStringTestParameter* CStringTestParameter::NewLC(TDes& aValue)
   1.159 +	{
   1.160 +	CStringTestParameter* self = new(ELeave) CStringTestParameter();
   1.161 +	CleanupStack::PushL(self);
   1.162 +	self->Construct(aValue);
   1.163 +	return self;
   1.164 +	}
   1.165 +
   1.166 +void CStringTestParameter::Construct(TDes& aValue)
   1.167 +	{
   1.168 +	iValue.Copy(aValue);
   1.169 +	iValid = ETrue;
   1.170 +	}