os/security/cryptoservices/certificateandkeymgmt/tasn1/testparameter.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.
     1 /*
     2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     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".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 * TestParameter.cpp: implementation of the CTestParameter class.
    16 *
    17 */
    18 
    19 
    20 /**
    21  @file
    22 */
    23 
    24 #include "testparameter.h"
    25 
    26 
    27 CTestParameter::CTestParameter() : iValid(EFalse) 
    28 {
    29 };
    30 
    31 
    32 CIntTestParameter* CIntTestParameter::NewL(TDes& aValue)
    33 	{
    34 	CIntTestParameter* self = CIntTestParameter::NewLC(aValue);
    35 	CleanupStack::Pop(self);
    36 	return self;
    37 	}
    38 
    39 CIntTestParameter* CIntTestParameter::NewLC(TDes& aValue)
    40 	{
    41 	CIntTestParameter* self = new(ELeave) CIntTestParameter();
    42 	CleanupStack::PushL(self);
    43 	self->Construct(aValue);
    44 	return self;
    45 	}
    46 
    47 void CIntTestParameter::Construct(TDes& aValue)
    48 	{
    49 	TLex lexValue(aValue);
    50 
    51 	if(aValue.Left(2) == _L("0x"))
    52 		{
    53 		// its a hex number 
    54 		TUint hexValue;
    55 		TLex hexLex(aValue.Mid(2));
    56 
    57 		if(hexLex.Val(hexValue, EHex)!=KErrNone)
    58 			return;
    59 		// checks if hexLex is at end of string, if not there was garbage in the string
    60 		// so throw it out
    61 		else if(!hexLex.Eos())
    62 			return;
    63 
    64 		iValue = STATIC_CAST(TInt,hexValue);
    65 		}
    66 	else if(lexValue.Val(iValue)!=KErrNone)
    67 		return;
    68 		// checks if lexValue is at end of string, if not there was garbage in the string
    69 		// so throw it out
    70 	else if(!lexValue.Eos())
    71 		return;
    72 
    73 	iValid = ETrue;
    74 	}
    75 
    76 CIntRangeTestParameter* CIntRangeTestParameter::NewL(TDes& aValue)
    77 	{
    78 	CIntRangeTestParameter* self = CIntRangeTestParameter::NewLC(aValue);
    79 	CleanupStack::Pop(self);
    80 	return self;
    81 	}
    82 
    83 CIntRangeTestParameter* CIntRangeTestParameter::NewLC(TDes& aValue)
    84 	{
    85 	CIntRangeTestParameter* self = new(ELeave) CIntRangeTestParameter();
    86 	CleanupStack::PushL(self);
    87 	self->Construct(aValue);
    88 	return self;
    89 	}
    90 
    91 void CIntRangeTestParameter::Construct(TDes& aValue)
    92 	{
    93 	if(aValue.Find(_L("..")) != KErrNotFound)
    94 		{
    95 		TInt pos = aValue.Find(_L(".."));
    96 		TLex startLex(aValue.Left(pos));
    97 		TLex endLex(aValue.Mid(pos+2));
    98 
    99 		if(startLex.Val(iStart)!=KErrNone)
   100 			return;
   101 			// checks if startLex is at end of string, if not there was garbage in the string so throw it out
   102 		else if(!startLex.Eos())
   103 			return;
   104 
   105 		if(endLex.Val(iFinish)!=KErrNone)
   106 			return;
   107 			// checks if startLex is at end of string, if not there was garbage in the string so throw it out
   108 		else if(!endLex.Eos())
   109 			return;
   110 		// checks if range is doable
   111 		if(iStart > iFinish)
   112 			return;
   113 		}
   114 	else
   115 		return;
   116 	iValid = ETrue;
   117 	}
   118 
   119 CRandomTestParameter* CRandomTestParameter::NewL(TDes& aValue)
   120 	{
   121 	CRandomTestParameter* self = CRandomTestParameter::NewLC(aValue);
   122 	CleanupStack::Pop(self);
   123 	return self;
   124 	}
   125 
   126 CRandomTestParameter* CRandomTestParameter::NewLC(TDes& aValue)
   127 	{
   128 	CRandomTestParameter* self = new(ELeave) CRandomTestParameter();
   129 	CleanupStack::PushL(self);
   130 	self->Construct(aValue);
   131 	return self;
   132 	}
   133 
   134 
   135 void CRandomTestParameter::Construct(TDes& aValue)
   136 	{
   137 	TLex lexValue(aValue);
   138 
   139 	if(lexValue.Val(iInterations)!=KErrNone)
   140 		return;
   141 	else if(!lexValue.Eos())
   142 		// checks if startLex is at end of string, if not there was garbage in the string so throw it out
   143 		return;
   144 
   145 	iValid = ETrue;
   146 	}
   147 
   148 CStringTestParameter* CStringTestParameter::NewL(TDes& aValue)
   149 	{
   150 	CStringTestParameter* self = CStringTestParameter::NewLC(aValue);
   151 	CleanupStack::Pop(self);
   152 	return self;
   153 	}
   154 
   155 CStringTestParameter* CStringTestParameter::NewLC(TDes& aValue)
   156 	{
   157 	CStringTestParameter* self = new(ELeave) CStringTestParameter();
   158 	CleanupStack::PushL(self);
   159 	self->Construct(aValue);
   160 	return self;
   161 	}
   162 
   163 void CStringTestParameter::Construct(TDes& aValue)
   164 	{
   165 	iValue.Copy(aValue);
   166 	iValid = ETrue;
   167 	}