sl@0: /* sl@0: * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * TestParameter.cpp: implementation of the CTestParameter class. sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: */ sl@0: sl@0: #include "testparameter.h" sl@0: sl@0: sl@0: CTestParameter::CTestParameter() : iValid(EFalse) sl@0: { sl@0: }; sl@0: sl@0: sl@0: CIntTestParameter* CIntTestParameter::NewL(TDes& aValue) sl@0: { sl@0: CIntTestParameter* self = CIntTestParameter::NewLC(aValue); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: CIntTestParameter* CIntTestParameter::NewLC(TDes& aValue) sl@0: { sl@0: CIntTestParameter* self = new(ELeave) CIntTestParameter(); sl@0: CleanupStack::PushL(self); sl@0: self->Construct(aValue); sl@0: return self; sl@0: } sl@0: sl@0: void CIntTestParameter::Construct(TDes& aValue) sl@0: { sl@0: TLex lexValue(aValue); sl@0: sl@0: if(aValue.Left(2) == _L("0x")) sl@0: { sl@0: // its a hex number sl@0: TUint hexValue; sl@0: TLex hexLex(aValue.Mid(2)); sl@0: sl@0: if(hexLex.Val(hexValue, EHex)!=KErrNone) sl@0: return; sl@0: // checks if hexLex is at end of string, if not there was garbage in the string sl@0: // so throw it out sl@0: else if(!hexLex.Eos()) sl@0: return; sl@0: sl@0: iValue = STATIC_CAST(TInt,hexValue); sl@0: } sl@0: else if(lexValue.Val(iValue)!=KErrNone) sl@0: return; sl@0: // checks if lexValue is at end of string, if not there was garbage in the string sl@0: // so throw it out sl@0: else if(!lexValue.Eos()) sl@0: return; sl@0: sl@0: iValid = ETrue; sl@0: } sl@0: sl@0: CIntRangeTestParameter* CIntRangeTestParameter::NewL(TDes& aValue) sl@0: { sl@0: CIntRangeTestParameter* self = CIntRangeTestParameter::NewLC(aValue); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: CIntRangeTestParameter* CIntRangeTestParameter::NewLC(TDes& aValue) sl@0: { sl@0: CIntRangeTestParameter* self = new(ELeave) CIntRangeTestParameter(); sl@0: CleanupStack::PushL(self); sl@0: self->Construct(aValue); sl@0: return self; sl@0: } sl@0: sl@0: void CIntRangeTestParameter::Construct(TDes& aValue) sl@0: { sl@0: if(aValue.Find(_L("..")) != KErrNotFound) sl@0: { sl@0: TInt pos = aValue.Find(_L("..")); sl@0: TLex startLex(aValue.Left(pos)); sl@0: TLex endLex(aValue.Mid(pos+2)); sl@0: sl@0: if(startLex.Val(iStart)!=KErrNone) sl@0: return; sl@0: // checks if startLex is at end of string, if not there was garbage in the string so throw it out sl@0: else if(!startLex.Eos()) sl@0: return; sl@0: sl@0: if(endLex.Val(iFinish)!=KErrNone) sl@0: return; sl@0: // checks if startLex is at end of string, if not there was garbage in the string so throw it out sl@0: else if(!endLex.Eos()) sl@0: return; sl@0: // checks if range is doable sl@0: if(iStart > iFinish) sl@0: return; sl@0: } sl@0: else sl@0: return; sl@0: iValid = ETrue; sl@0: } sl@0: sl@0: CRandomTestParameter* CRandomTestParameter::NewL(TDes& aValue) sl@0: { sl@0: CRandomTestParameter* self = CRandomTestParameter::NewLC(aValue); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: CRandomTestParameter* CRandomTestParameter::NewLC(TDes& aValue) sl@0: { sl@0: CRandomTestParameter* self = new(ELeave) CRandomTestParameter(); sl@0: CleanupStack::PushL(self); sl@0: self->Construct(aValue); sl@0: return self; sl@0: } sl@0: sl@0: sl@0: void CRandomTestParameter::Construct(TDes& aValue) sl@0: { sl@0: TLex lexValue(aValue); sl@0: sl@0: if(lexValue.Val(iInterations)!=KErrNone) sl@0: return; sl@0: else if(!lexValue.Eos()) sl@0: // checks if startLex is at end of string, if not there was garbage in the string so throw it out sl@0: return; sl@0: sl@0: iValid = ETrue; sl@0: } sl@0: sl@0: CStringTestParameter* CStringTestParameter::NewL(TDes& aValue) sl@0: { sl@0: CStringTestParameter* self = CStringTestParameter::NewLC(aValue); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: CStringTestParameter* CStringTestParameter::NewLC(TDes& aValue) sl@0: { sl@0: CStringTestParameter* self = new(ELeave) CStringTestParameter(); sl@0: CleanupStack::PushL(self); sl@0: self->Construct(aValue); sl@0: return self; sl@0: } sl@0: sl@0: void CStringTestParameter::Construct(TDes& aValue) sl@0: { sl@0: iValue.Copy(aValue); sl@0: iValid = ETrue; sl@0: }