|
1 // Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // TESTUTL.CPP |
|
15 // |
|
16 // |
|
17 |
|
18 #include "tcfgfile.h" |
|
19 #include <f32file.h> |
|
20 |
|
21 //PhilippeG 15/05/2000 |
|
22 //New object to load and parse the test parameters file |
|
23 CConfigParams* CConfigParams::NewL(const TDesC &aCfgFileName) |
|
24 { |
|
25 CConfigParams *f; |
|
26 f=new (ELeave) CConfigParams(); |
|
27 CleanupStack::PushL(f); |
|
28 //A leave during the ConstrucL is not fatal, just means there's no param file |
|
29 TRAPD(err,f->ConstructL(aCfgFileName)); |
|
30 CleanupStack::Pop(); |
|
31 return f; |
|
32 } |
|
33 void CConfigParams::ConstructL(const TDesC &aCfgFileName) |
|
34 { |
|
35 //Find the config file |
|
36 TAutoClose<RFs> fs; |
|
37 User::LeaveIfError(fs.iObj.Connect()); |
|
38 fs.PushL(); |
|
39 //Location for the test parameter config file |
|
40 _LIT(KTinetConfigFilePaths,"\\testdata\\configs\\ppp\\;\\;\\system\\data\\"); |
|
41 TFindFile filePath(fs.iObj); |
|
42 User::LeaveIfError(filePath.FindByPath(aCfgFileName,&KTinetConfigFilePaths)); |
|
43 //read the content of the file |
|
44 TAutoClose<RFile> fl; |
|
45 fl.PushL(); |
|
46 User::LeaveIfError(fl.iObj.Open(fs.iObj,filePath.File(),EFileShareExclusive)); |
|
47 User::LeaveIfError(fl.iObj.Read(iConfigParamBuf8)); |
|
48 iConfigParamBuf.Copy(iConfigParamBuf8); |
|
49 CleanupStack::Pop(2); |
|
50 iFileExist = ETrue; |
|
51 } |
|
52 |
|
53 const TPtrC CConfigParams::FindAlphaVar(const TDesC &aVarName, const TDesC &aDefault) |
|
54 { |
|
55 if(!iFileExist) |
|
56 return TPtrC(aDefault); |
|
57 TInt pos=iConfigParamBuf.Find(aVarName); |
|
58 if (pos==KErrNotFound) |
|
59 return TPtrC(aDefault); |
|
60 TLex lex(iConfigParamBuf.Mid(pos)); |
|
61 lex.SkipCharacters(); |
|
62 lex.SkipSpaceAndMark(); // Should be at the start of the data |
|
63 lex.SkipCharacters(); |
|
64 return TPtrC(lex.MarkedToken().Ptr(),lex.MarkedToken().Length()); |
|
65 } |
|
66 const TInt CConfigParams::FindNumVar(const TDesC &aVarName, const TInt aDefault) |
|
67 { |
|
68 TInt result; |
|
69 TPtrC ptr = FindAlphaVar(aVarName,KNullDesC); |
|
70 if(ptr.Length()) |
|
71 { |
|
72 TLex lex(ptr); |
|
73 if (lex.Val(result)==KErrNone) |
|
74 return result; |
|
75 } |
|
76 return aDefault; |
|
77 } |