sl@0
|
1 |
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// @file testengine.cpp
|
sl@0
|
15 |
// @internalComponent
|
sl@0
|
16 |
//
|
sl@0
|
17 |
//
|
sl@0
|
18 |
|
sl@0
|
19 |
#include "TestEngine.h"
|
sl@0
|
20 |
#include "testdebug.h"
|
sl@0
|
21 |
#include "TestCaseController.h"
|
sl@0
|
22 |
#include "TestCaseFactory.h"
|
sl@0
|
23 |
|
sl@0
|
24 |
// Console application options
|
sl@0
|
25 |
|
sl@0
|
26 |
_LIT(KArgRole,"-role=");
|
sl@0
|
27 |
_LIT(KArgTestCases,"-cases=");
|
sl@0
|
28 |
_LIT(KArgTestRepeats,"-repeats=");
|
sl@0
|
29 |
|
sl@0
|
30 |
// Role values
|
sl@0
|
31 |
|
sl@0
|
32 |
_LIT(KArgRoleHost,"host");
|
sl@0
|
33 |
_LIT(KArgRoleClient,"client");
|
sl@0
|
34 |
|
sl@0
|
35 |
|
sl@0
|
36 |
extern RTest gtest;
|
sl@0
|
37 |
|
sl@0
|
38 |
namespace NUnitTesting_USBDI
|
sl@0
|
39 |
{
|
sl@0
|
40 |
const TUint KDefaultNumRepeats = 1;
|
sl@0
|
41 |
const TUint KTestIdSize = 4;
|
sl@0
|
42 |
_LIT(KTestStringPreamble,"PBASE-T_USBDI-");
|
sl@0
|
43 |
|
sl@0
|
44 |
CTestEngine* CTestEngine::NewL()
|
sl@0
|
45 |
{
|
sl@0
|
46 |
CTestEngine* self = new (ELeave) CTestEngine;
|
sl@0
|
47 |
CleanupStack::PushL(self);
|
sl@0
|
48 |
self->ConstructL();
|
sl@0
|
49 |
CleanupStack::Pop(self);
|
sl@0
|
50 |
return self;
|
sl@0
|
51 |
}
|
sl@0
|
52 |
|
sl@0
|
53 |
|
sl@0
|
54 |
|
sl@0
|
55 |
CTestEngine::CTestEngine()
|
sl@0
|
56 |
: CActive(EPriorityUserInput),
|
sl@0
|
57 |
iTestCaseIndex(0), iRepeat(0), iNumRepeats(KDefaultNumRepeats)
|
sl@0
|
58 |
{
|
sl@0
|
59 |
}
|
sl@0
|
60 |
|
sl@0
|
61 |
|
sl@0
|
62 |
|
sl@0
|
63 |
CTestEngine::~CTestEngine()
|
sl@0
|
64 |
{
|
sl@0
|
65 |
// Cancel reading user console input
|
sl@0
|
66 |
Cancel();
|
sl@0
|
67 |
|
sl@0
|
68 |
// Destroy the test case controller
|
sl@0
|
69 |
delete iTestCaseController;
|
sl@0
|
70 |
|
sl@0
|
71 |
// Destroy the identity array and its contents
|
sl@0
|
72 |
iTestCasesIdentities.ResetAndDestroy();
|
sl@0
|
73 |
|
sl@0
|
74 |
// Finish test and release resources
|
sl@0
|
75 |
gtest.End();
|
sl@0
|
76 |
gtest.Close();
|
sl@0
|
77 |
}
|
sl@0
|
78 |
|
sl@0
|
79 |
|
sl@0
|
80 |
|
sl@0
|
81 |
void CTestEngine::ConstructL()
|
sl@0
|
82 |
{
|
sl@0
|
83 |
LOG_FUNC
|
sl@0
|
84 |
CActiveScheduler::Add(this);
|
sl@0
|
85 |
|
sl@0
|
86 |
// Display information (construction text and OS build version number
|
sl@0
|
87 |
gtest.Title();
|
sl@0
|
88 |
gtest.Start(_L("Test Engine Initiation"));
|
sl@0
|
89 |
gtest.Printf(_L(">>\n"));
|
sl@0
|
90 |
gtest.Printf(_L(">> T E S T R U N \n"));
|
sl@0
|
91 |
gtest.Printf(_L(">>\n"));
|
sl@0
|
92 |
|
sl@0
|
93 |
// Process the command line option for role
|
sl@0
|
94 |
TInt cmdLineLength(User::CommandLineLength());
|
sl@0
|
95 |
HBufC* cmdLine = HBufC::NewMax(cmdLineLength);
|
sl@0
|
96 |
CleanupStack::PushL(cmdLine);
|
sl@0
|
97 |
TPtr cmdLinePtr = cmdLine->Des();
|
sl@0
|
98 |
User::CommandLine(cmdLinePtr);
|
sl@0
|
99 |
|
sl@0
|
100 |
// be careful, command line length is limited(248 characters)
|
sl@0
|
101 |
gtest.Printf(_L("***cmdLine = %lS\n"), cmdLine);
|
sl@0
|
102 |
|
sl@0
|
103 |
TLex args(*cmdLine);
|
sl@0
|
104 |
args.SkipSpace();
|
sl@0
|
105 |
|
sl@0
|
106 |
// Obtain the role of this test module
|
sl@0
|
107 |
TPtrC roleToken = args.NextToken(); // e.g. -role=host
|
sl@0
|
108 |
TBool hostFlag(ETrue);
|
sl@0
|
109 |
|
sl@0
|
110 |
TInt pos(roleToken.FindF(KArgRole));
|
sl@0
|
111 |
if(pos != KErrNotFound)
|
sl@0
|
112 |
{
|
sl@0
|
113 |
pos = roleToken.FindF(_L("="));
|
sl@0
|
114 |
TPtrC role = roleToken.Right(roleToken.Length()-pos-1);
|
sl@0
|
115 |
if(role.Compare(KArgRoleHost) == 0)
|
sl@0
|
116 |
{
|
sl@0
|
117 |
hostFlag = ETrue;
|
sl@0
|
118 |
}
|
sl@0
|
119 |
else if(role.Compare(KArgRoleClient) == 0)
|
sl@0
|
120 |
{
|
sl@0
|
121 |
hostFlag = EFalse;
|
sl@0
|
122 |
}
|
sl@0
|
123 |
else
|
sl@0
|
124 |
{
|
sl@0
|
125 |
gtest.Printf(_L("Test configuration: could not find option -role\n"));
|
sl@0
|
126 |
gtest(EFalse);
|
sl@0
|
127 |
}
|
sl@0
|
128 |
}
|
sl@0
|
129 |
else
|
sl@0
|
130 |
{
|
sl@0
|
131 |
gtest.Printf(_L("Test configuration option not found: %S\n"),&KArgRole);
|
sl@0
|
132 |
gtest(EFalse);
|
sl@0
|
133 |
}
|
sl@0
|
134 |
|
sl@0
|
135 |
// Obtain the test cases to be run
|
sl@0
|
136 |
TPtrC casesToken = args.NextToken();
|
sl@0
|
137 |
|
sl@0
|
138 |
pos = casesToken.FindF(KArgTestCases);
|
sl@0
|
139 |
if(pos != KErrNotFound)
|
sl@0
|
140 |
{
|
sl@0
|
141 |
pos = casesToken.FindF(_L("="));
|
sl@0
|
142 |
TPtrC testCases = casesToken.Right(casesToken.Length()-pos-1);
|
sl@0
|
143 |
|
sl@0
|
144 |
// Remaining test cases
|
sl@0
|
145 |
TPtrC remCases(testCases);
|
sl@0
|
146 |
while(pos != KErrNotFound)
|
sl@0
|
147 |
{
|
sl@0
|
148 |
pos = remCases.FindF(_L(","));
|
sl@0
|
149 |
HBufC* tc = HBufC::NewLC(KTestCaseIdLength);
|
sl@0
|
150 |
TPtr tcPtr = tc->Des();
|
sl@0
|
151 |
tcPtr.Append(KTestStringPreamble);
|
sl@0
|
152 |
|
sl@0
|
153 |
if(pos == KErrNotFound)
|
sl@0
|
154 |
{
|
sl@0
|
155 |
// This is the last test case identity
|
sl@0
|
156 |
tcPtr.Append(remCases);
|
sl@0
|
157 |
}
|
sl@0
|
158 |
else
|
sl@0
|
159 |
{
|
sl@0
|
160 |
tcPtr.Append(remCases.Left(KTestIdSize));
|
sl@0
|
161 |
}
|
sl@0
|
162 |
|
sl@0
|
163 |
gtest.Printf(_L("Test case specified: %S\n"),tc);
|
sl@0
|
164 |
|
sl@0
|
165 |
|
sl@0
|
166 |
iTestCasesIdentities.Append(tc);
|
sl@0
|
167 |
CleanupStack::Pop(tc);
|
sl@0
|
168 |
remCases.Set(testCases.Right(remCases.Length()-pos-1));
|
sl@0
|
169 |
}
|
sl@0
|
170 |
}
|
sl@0
|
171 |
else
|
sl@0
|
172 |
{
|
sl@0
|
173 |
gtest.Printf(_L("Test configuration option not found: %S\n"),&KArgTestCases);
|
sl@0
|
174 |
gtest(EFalse);
|
sl@0
|
175 |
}
|
sl@0
|
176 |
|
sl@0
|
177 |
// Obtain the role of this test module
|
sl@0
|
178 |
TPtrC repeatsToken = args.NextToken(); // e.g. -repeats=4
|
sl@0
|
179 |
|
sl@0
|
180 |
pos = repeatsToken.FindF(KArgTestRepeats);
|
sl@0
|
181 |
if(pos != KErrNotFound)
|
sl@0
|
182 |
{
|
sl@0
|
183 |
pos = repeatsToken.FindF(_L("="));
|
sl@0
|
184 |
TPtrC repeats = repeatsToken.Right(repeatsToken.Length()-pos-1);
|
sl@0
|
185 |
TLex lex(repeats);
|
sl@0
|
186 |
TInt ret = lex.Val(iNumRepeats, EDecimal);
|
sl@0
|
187 |
if(ret)
|
sl@0
|
188 |
{
|
sl@0
|
189 |
gtest.Printf(_L("Test configuration option not found: %S\n"),&KArgTestRepeats);
|
sl@0
|
190 |
gtest.Printf(_L("DEFAULT to number of repeats = %d\n"),KDefaultNumRepeats);
|
sl@0
|
191 |
iNumRepeats = KDefaultNumRepeats;
|
sl@0
|
192 |
}
|
sl@0
|
193 |
gtest.Printf(_L("Test repeats specified: %d cycles\n"),iNumRepeats);
|
sl@0
|
194 |
}
|
sl@0
|
195 |
else
|
sl@0
|
196 |
{
|
sl@0
|
197 |
gtest.Printf(_L("Test configuration option not found: %S\n"),&KArgTestRepeats);
|
sl@0
|
198 |
gtest.Printf(_L("DEFAULT to number of repeats = %d\n"),KDefaultNumRepeats);
|
sl@0
|
199 |
iNumRepeats = KDefaultNumRepeats;
|
sl@0
|
200 |
}
|
sl@0
|
201 |
|
sl@0
|
202 |
// Create the test case controller
|
sl@0
|
203 |
gtest.Printf(_L("Creating the test controller\n"));
|
sl@0
|
204 |
iTestCaseController = CTestCaseController::NewL(*this,hostFlag);
|
sl@0
|
205 |
|
sl@0
|
206 |
CleanupStack::PopAndDestroy(cmdLine);
|
sl@0
|
207 |
|
sl@0
|
208 |
gtest.Console()->Read(iStatus);
|
sl@0
|
209 |
SetActive();
|
sl@0
|
210 |
}
|
sl@0
|
211 |
|
sl@0
|
212 |
|
sl@0
|
213 |
TInt CTestEngine::NextTestCaseId(TDes& aTestCaseId)
|
sl@0
|
214 |
{
|
sl@0
|
215 |
LOG_FUNC
|
sl@0
|
216 |
if(iTestCaseIndex < iTestCasesIdentities.Count())
|
sl@0
|
217 |
{
|
sl@0
|
218 |
aTestCaseId = *iTestCasesIdentities[iTestCaseIndex++];
|
sl@0
|
219 |
if(iTestCaseIndex==iTestCasesIdentities.Count())
|
sl@0
|
220 |
{
|
sl@0
|
221 |
iRepeat++;
|
sl@0
|
222 |
if(iRepeat < iNumRepeats)
|
sl@0
|
223 |
{
|
sl@0
|
224 |
iTestCaseIndex = 0; //prepare to start again
|
sl@0
|
225 |
}
|
sl@0
|
226 |
}
|
sl@0
|
227 |
return KErrNone;
|
sl@0
|
228 |
}
|
sl@0
|
229 |
else
|
sl@0
|
230 |
{
|
sl@0
|
231 |
return KErrNotFound;
|
sl@0
|
232 |
}
|
sl@0
|
233 |
}
|
sl@0
|
234 |
|
sl@0
|
235 |
RPointerArray<HBufC>& CTestEngine::TestCasesIdentities()
|
sl@0
|
236 |
{
|
sl@0
|
237 |
return iTestCasesIdentities;
|
sl@0
|
238 |
}
|
sl@0
|
239 |
|
sl@0
|
240 |
TUint CTestEngine::NumRepeats()
|
sl@0
|
241 |
{
|
sl@0
|
242 |
return iNumRepeats;
|
sl@0
|
243 |
}
|
sl@0
|
244 |
|
sl@0
|
245 |
void CTestEngine::DoCancel()
|
sl@0
|
246 |
{
|
sl@0
|
247 |
LOG_FUNC
|
sl@0
|
248 |
gtest.Console()->ReadCancel();
|
sl@0
|
249 |
}
|
sl@0
|
250 |
|
sl@0
|
251 |
|
sl@0
|
252 |
void CTestEngine::RunL()
|
sl@0
|
253 |
{
|
sl@0
|
254 |
LOG_FUNC
|
sl@0
|
255 |
TInt completionCode(iStatus.Int());
|
sl@0
|
256 |
|
sl@0
|
257 |
if(completionCode == KErrNone)
|
sl@0
|
258 |
{
|
sl@0
|
259 |
// Possibility of displaying a range of key commands
|
sl@0
|
260 |
// then gtest.Console()->Getch()
|
sl@0
|
261 |
|
sl@0
|
262 |
TKeyCode keyCode(gtest.Console()->KeyCode());
|
sl@0
|
263 |
if(keyCode == EKeySpace)
|
sl@0
|
264 |
{
|
sl@0
|
265 |
iTestCaseController->Cancel();
|
sl@0
|
266 |
gtest.Printf(_L("Test module terminating\n"));
|
sl@0
|
267 |
RDebug::Printf("CActiveScheduler::Stop CTestEngine::RunL");
|
sl@0
|
268 |
CActiveScheduler::Stop();
|
sl@0
|
269 |
}
|
sl@0
|
270 |
else
|
sl@0
|
271 |
{
|
sl@0
|
272 |
gtest.Printf(_L("%d key pressed"),keyCode);
|
sl@0
|
273 |
}
|
sl@0
|
274 |
}
|
sl@0
|
275 |
else
|
sl@0
|
276 |
{
|
sl@0
|
277 |
gtest.Printf(_L("Manual key error %d\n"),completionCode);
|
sl@0
|
278 |
SetActive();
|
sl@0
|
279 |
}
|
sl@0
|
280 |
}
|
sl@0
|
281 |
|
sl@0
|
282 |
|
sl@0
|
283 |
TInt CTestEngine::RunError(TInt aError)
|
sl@0
|
284 |
{
|
sl@0
|
285 |
return KErrNone;
|
sl@0
|
286 |
}
|
sl@0
|
287 |
|
sl@0
|
288 |
}
|