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