55
|
1 |
// Copyright (c) 2010 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 |
//
|
|
15 |
#include <e32test.h>
|
|
16 |
#include "t_dbcmdlineutil.h"
|
|
17 |
|
|
18 |
static void GetCmdLine(RTest& aTest, const TDesC& aTestName, TDes& aCmdLine)
|
|
19 |
{
|
|
20 |
User::CommandLine(aCmdLine);
|
|
21 |
aCmdLine.TrimAll();
|
|
22 |
if(aCmdLine.Length() == 0)
|
|
23 |
{
|
|
24 |
aTest.Printf(_L("Usage: %S [/drv=<drive letter>:] [/logfile=<log file name>]\r\n"), &aTestName);
|
|
25 |
return;
|
|
26 |
}
|
|
27 |
aCmdLine.Append(TChar('/'));
|
|
28 |
}
|
|
29 |
|
|
30 |
static void ExtractCmdLineParams(TDes& aCmdLine, RArray<TPtrC>& aPrmNames, RArray<TPtrC>& aPrmValues)
|
|
31 |
{
|
|
32 |
aPrmNames.Reset();
|
|
33 |
aPrmValues.Reset();
|
|
34 |
|
|
35 |
enum TState{EWaitPrmStart, EReadPrmName, EReadPrmValue};
|
|
36 |
TState state = EWaitPrmStart;
|
|
37 |
TInt startPos = -1;
|
|
38 |
TPtr prmName(0, 0);
|
|
39 |
TPtr prmValue(0, 0);
|
|
40 |
|
|
41 |
aCmdLine.Append(TChar('/'));
|
|
42 |
|
|
43 |
for(TInt i=0;i<aCmdLine.Length();++i)
|
|
44 |
{
|
|
45 |
switch(state)
|
|
46 |
{
|
|
47 |
case EWaitPrmStart:
|
|
48 |
if(aCmdLine[i] == TChar('/'))
|
|
49 |
{
|
|
50 |
startPos = i + 1;
|
|
51 |
prmName.Zero();
|
|
52 |
state = EReadPrmName;
|
|
53 |
}
|
|
54 |
break;
|
|
55 |
case EReadPrmName:
|
|
56 |
if(aCmdLine[i] == TChar('='))
|
|
57 |
{
|
|
58 |
TPtr p = aCmdLine.MidTPtr(startPos, i - startPos);
|
|
59 |
prmName.Set(p);
|
|
60 |
prmName.TrimRight();
|
|
61 |
startPos = i + 1;
|
|
62 |
prmValue.Zero();
|
|
63 |
state = EReadPrmValue;
|
|
64 |
}
|
|
65 |
break;
|
|
66 |
case EReadPrmValue:
|
|
67 |
if(aCmdLine[i] == TChar('/'))
|
|
68 |
{
|
|
69 |
TPtr p = aCmdLine.MidTPtr(startPos, i - startPos);
|
|
70 |
prmValue.Set(p);
|
|
71 |
prmValue.Trim();
|
|
72 |
startPos = i + 1;
|
|
73 |
aPrmNames.Append(prmName);
|
|
74 |
aPrmValues.Append(prmValue);
|
|
75 |
prmName.Zero();
|
|
76 |
prmValue.Zero();
|
|
77 |
state = EReadPrmName;
|
|
78 |
}
|
|
79 |
break;
|
|
80 |
default:
|
|
81 |
break;
|
|
82 |
}
|
|
83 |
}
|
|
84 |
}
|
|
85 |
|
|
86 |
static void ExtractParamNamesAndValues(const RArray<TPtrC>& aPrmNames, const RArray<TPtrC>& aPrmValues, TCmdLineParams& aCmdLineParams)
|
|
87 |
{
|
|
88 |
__ASSERT_ALWAYS(aPrmNames.Count() == aPrmValues.Count(), User::Invariant());
|
|
89 |
|
|
90 |
aCmdLineParams.SetDefaults();
|
|
91 |
|
|
92 |
for(TInt i=0;i<aPrmNames.Count();++i)
|
|
93 |
{
|
|
94 |
if(aPrmNames[i].CompareF(_L("drv")) == 0)
|
|
95 |
{
|
|
96 |
if(aPrmValues[i].Length() == 2 && aPrmValues[i][1] == TChar(':'))
|
|
97 |
{
|
|
98 |
TChar ch(aPrmValues[i][0]);
|
|
99 |
ch.LowerCase();
|
|
100 |
if(ch >= TChar('a') && ch <= TChar('z'))
|
|
101 |
aCmdLineParams.iDriveName.Copy(aPrmValues[i]);
|
|
102 |
}
|
|
103 |
}
|
|
104 |
else if(aPrmNames[i].CompareF(_L("logfile")) == 0)
|
|
105 |
{
|
|
106 |
aCmdLineParams.iLogFileName.Copy(aPrmValues[i]);
|
|
107 |
}
|
|
108 |
}
|
|
109 |
}
|
|
110 |
|
|
111 |
void GetCmdLineParams(RTest& aTest, const TDesC& aTestName, TCmdLineParams& aCmdLineParams)
|
|
112 |
{
|
|
113 |
TBuf<200> cmdLine;
|
|
114 |
GetCmdLine(aTest, aTestName, cmdLine);
|
|
115 |
RArray<TPtrC> prmNames;
|
|
116 |
RArray<TPtrC> prmValues;
|
|
117 |
ExtractCmdLineParams(cmdLine, prmNames, prmValues);
|
|
118 |
ExtractParamNamesAndValues(prmNames, prmValues, aCmdLineParams);
|
|
119 |
prmValues.Close();
|
|
120 |
prmNames.Close();
|
|
121 |
aTest.Printf(_L("--PRM--Database drive: %S\r\n"), &aCmdLineParams.iDriveName);
|
|
122 |
if(aCmdLineParams.iLogFileName.Length() > 0)
|
|
123 |
{
|
|
124 |
aTest.Printf(_L("--PRM--Log file name: %S\r\n"), &aCmdLineParams.iLogFileName);
|
|
125 |
}
|
|
126 |
else
|
|
127 |
{
|
|
128 |
aTest.Printf(_L("--PRM--Test output: to screen only\r\n"));
|
|
129 |
}
|
|
130 |
}
|
|
131 |
|
|
132 |
void PrepareDbName(const TDesC& aDeafultDbName, const TDriveName& aDriveName, TDes& aDbName)
|
|
133 |
{
|
|
134 |
TParse parse;
|
|
135 |
parse.Set(aDriveName, &aDeafultDbName, 0);
|
|
136 |
const TDesC& dbFilePath = parse.FullName();
|
|
137 |
aDbName.Copy(dbFilePath);
|
|
138 |
}
|
|
139 |
|
|
140 |
void LogConfig(RFile& aLogFile, const TCmdLineParams& aCmdLineParams)
|
|
141 |
{
|
|
142 |
TBuf8<100> buf;
|
|
143 |
buf.Format(_L8("Database drive:%S\r\n"), &aCmdLineParams.iDriveName);
|
|
144 |
(void)aLogFile.Write(buf);
|
|
145 |
buf.Format(_L8("\r\n\r\n"));
|
|
146 |
(void)aLogFile.Write(buf);
|
|
147 |
}
|