Update contrib.
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
19 #include "TestStepV2.h"
22 /// Constant Literals used.
23 _LIT(KIncludeSection, "include");
24 _LIT(KFile, "file%d");
25 _LIT(KMatch, "*{*,*}*");
27 _LIT(KSeparator, ",");
29 _LIT(KDataRead, "INI READ : %S %S %S");
32 CTestStepV2::CTestStepV2()
37 CTestStepV2::~CTestStepV2()
39 iInclude.ResetAndDestroy();
40 iBuffer.ResetAndDestroy();
43 enum TVerdict CTestStepV2::doTestStepPreambleL()
45 TBuf<KMaxTestExecuteCommandLength> tempStore;
47 TVerdict ret=CTestStep::doTestStepPreambleL();
53 tempStore.Format(KFile(), ++index);
54 moreData=GetStringFromConfig(KIncludeSection, tempStore, fileName);
57 CIniData* iniData=CIniData::NewL(fileName);
58 CleanupStack::PushL(iniData);
59 iInclude.Append(iniData);
60 CleanupStack::Pop(iniData);
67 TBool CTestStepV2::GetBoolFromConfig(const TDesC& aSectName,const TDesC& aKeyName,TBool& aResult)
71 TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, result));
72 if ( err != KErrNone )
79 aResult=(result.FindF(KTrue) != KErrNotFound);
84 TBool CTestStepV2::GetIntFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TInt& aResult)
88 TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, result));
89 if ( err != KErrNone )
96 ret=(lex.Val(aResult)==KErrNone);
102 TBool CTestStepV2::GetStringFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TPtrC& aResult)
105 TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, aResult));
106 if ( err != KErrNone )
113 TBool CTestStepV2::GetHexFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TInt& aResult)
117 TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, result));
118 if ( err != KErrNone )
125 ret=(lex.Val((TUint &)aResult, EHex)==KErrNone);
131 TBool CTestStepV2::GetCommandStringParameterL(const TDesC& aSectName, const TDesC& aKeyName, TPtrC& aResult)
133 TBool ret=CTestStep::GetStringFromConfig(aSectName, aKeyName, aResult);
135 for ( TInt index=iInclude.Count(); (index>0) && (!ret); )
137 ret=iInclude[--index]->FindVar(aSectName, aKeyName, aResult);
142 if ( aResult.Match(KMatch)!=KErrNotFound )
144 // We have an entry of the format
145 // entry =*{section,entry}*
146 // where * is one or more characters
147 // We need to construct this from other data in the ini file replacing {*,*}
148 // with the data from
151 HBufC* buffer=HBufC::NewLC(aResult.Length());
152 buffer->Des().Copy(aResult);
154 TInt startLength=KStart().Length();
155 TInt sparatorLength=KSeparator().Length();
156 TInt endLength=KEnd().Length();
165 bufferLength=buffer->Length();
166 start=buffer->Find(KStart);
168 remaining.Set(buffer->Des().Right(bufferLength-start-startLength));
169 sparator=remaining.Find(KSeparator);
170 remaining.Set(remaining.Right(remaining.Length()-sparator-sparatorLength));
171 sparator += (start + startLength);
173 end=remaining.Find(KEnd) + sparator + sparatorLength;
175 TPtrC sectionName(buffer->Ptr()+start+startLength, sparator-start-startLength);
176 TPtrC keyName(buffer->Ptr()+sparator+sparatorLength, end-sparator-sparatorLength);
177 sectionName.Set(TLex(sectionName).NextToken());
178 keyName.Set(TLex(keyName).NextToken());
182 TBool found=CTestStep::GetStringFromConfig(sectionName, keyName, entryData);
183 for ( TInt index=iInclude.Count(); (index>0) && (!found); )
185 found=iInclude[--index]->FindVar(sectionName, keyName, entryData);
189 entrySize=entryData.Length();
192 TInt newLength=start + bufferLength - end - endLength + entrySize;
193 HBufC* bufferNew=HBufC::NewLC(newLength);
194 bufferNew->Des().Copy(buffer->Ptr(), start);
197 bufferNew->Des().Append(entryData);
199 bufferNew->Des().Append(buffer->Ptr() + end + endLength, bufferLength - end - endLength);
200 CleanupStack::Pop(bufferNew);
201 CleanupStack::PopAndDestroy(buffer);
203 CleanupStack::PushL(buffer);
205 while ( buffer->Match(KMatch)!=KErrNotFound );
206 iBuffer.Append(buffer);
207 CleanupStack::Pop(buffer);
208 aResult.Set(*buffer);
209 INFO_PRINTF4(KDataRead, &aSectName, &aKeyName , &aResult);