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