sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
|
sl@0
|
19 |
#include "t_testsetup.h"
|
sl@0
|
20 |
#include "t_testactionspec.h"
|
sl@0
|
21 |
#include "t_input.h"
|
sl@0
|
22 |
#include "t_certstoreactionmemfail.h"
|
sl@0
|
23 |
#include "tcancel.h"
|
sl@0
|
24 |
#include "t_message.h"
|
sl@0
|
25 |
#include "tScriptSetup.h"
|
sl@0
|
26 |
#include "Thardcodedsetup.h"
|
sl@0
|
27 |
#include "t_testhandler.h"
|
sl@0
|
28 |
#include "t_output.h"
|
sl@0
|
29 |
#include "tTestSpec.h"
|
sl@0
|
30 |
#include "ttesthandlersettings.h"
|
sl@0
|
31 |
#include "testexecuteinterface.h"
|
sl@0
|
32 |
#include "t_logger.h"
|
sl@0
|
33 |
#include "t_testrunner.h"
|
sl@0
|
34 |
#include "t_dummyconsole.h"
|
sl@0
|
35 |
|
sl@0
|
36 |
EXPORT_C HBufC* CTestSetup::GetArgument(TInt nPos)
|
sl@0
|
37 |
{
|
sl@0
|
38 |
// Get command line
|
sl@0
|
39 |
HBufC *argv = HBufC::NewLC(User::CommandLineLength());
|
sl@0
|
40 |
TPtr cmd(argv->Des());
|
sl@0
|
41 |
User::CommandLine(cmd);
|
sl@0
|
42 |
|
sl@0
|
43 |
TLex arguments(cmd);
|
sl@0
|
44 |
TPtrC token;
|
sl@0
|
45 |
token.Set(KNullDesC);
|
sl@0
|
46 |
|
sl@0
|
47 |
// finds nth parameter that doesnt have a -
|
sl@0
|
48 |
while(nPos >= 0 && !arguments.Eos())
|
sl@0
|
49 |
{
|
sl@0
|
50 |
token.Set(arguments.NextToken());
|
sl@0
|
51 |
if(token.Length() > 0 && token[0] != '-')
|
sl@0
|
52 |
nPos--;
|
sl@0
|
53 |
}
|
sl@0
|
54 |
|
sl@0
|
55 |
HBufC* result = token.AllocL();
|
sl@0
|
56 |
|
sl@0
|
57 |
CleanupStack::PopAndDestroy(argv);
|
sl@0
|
58 |
|
sl@0
|
59 |
return result;
|
sl@0
|
60 |
}
|
sl@0
|
61 |
|
sl@0
|
62 |
void CTestSetup::InitFileserverSessionLC(RFs& aFs)
|
sl@0
|
63 |
{
|
sl@0
|
64 |
User::LeaveIfError(aFs.Connect());
|
sl@0
|
65 |
CleanupClosePushL(aFs);
|
sl@0
|
66 |
|
sl@0
|
67 |
// enable tests to pass file handles between processes
|
sl@0
|
68 |
aFs.ShareProtected();
|
sl@0
|
69 |
|
sl@0
|
70 |
// Create the private directory, to fix failures in tests that write to
|
sl@0
|
71 |
// relative paths that were broken when the default path was changed to the
|
sl@0
|
72 |
// private path in build 03429
|
sl@0
|
73 |
TFileName privatePath;
|
sl@0
|
74 |
User::LeaveIfError(aFs.PrivatePath(privatePath));
|
sl@0
|
75 |
TInt err = aFs.MkDir(privatePath);
|
sl@0
|
76 |
if (err != KErrNone && err != KErrAlreadyExists)
|
sl@0
|
77 |
{
|
sl@0
|
78 |
User::Leave(err);
|
sl@0
|
79 |
}
|
sl@0
|
80 |
}
|
sl@0
|
81 |
|
sl@0
|
82 |
EXPORT_C void CTestSetup::CreateAndRunTestsL(TScriptTests theTestTypes[],
|
sl@0
|
83 |
const TDesC& aScript, const TDesC& aLogFile, TBool aUseCommandLine,
|
sl@0
|
84 |
CConsoleBase* aConsole, TBool* aResult)
|
sl@0
|
85 |
{
|
sl@0
|
86 |
LOG(_L("-- Test handler starting"));
|
sl@0
|
87 |
|
sl@0
|
88 |
RFs fs;
|
sl@0
|
89 |
|
sl@0
|
90 |
InitFileserverSessionLC(fs);
|
sl@0
|
91 |
|
sl@0
|
92 |
CScriptSetup* testSetup = CScriptSetup::NewLC(aConsole);
|
sl@0
|
93 |
CTestHandlerSettings* commandLineArgs = CTestHandlerSettings::NewLC();
|
sl@0
|
94 |
CTestSpec* testSpec = CTestSpec::NewL();
|
sl@0
|
95 |
CleanupStack::PushL(testSpec);
|
sl@0
|
96 |
|
sl@0
|
97 |
TTestSummary summary;
|
sl@0
|
98 |
if(testSetup->InitialiseL(fs, aScript, aLogFile, aUseCommandLine))
|
sl@0
|
99 |
{
|
sl@0
|
100 |
|
sl@0
|
101 |
// Store the state of the heap and RFs resource count before the tests
|
sl@0
|
102 |
|
sl@0
|
103 |
TInt initAllocCount = User::CountAllocCells();
|
sl@0
|
104 |
TInt initRFsCount = fs.ResourceCount();
|
sl@0
|
105 |
|
sl@0
|
106 |
// Store the initial count of process and thread handles
|
sl@0
|
107 |
TInt initThreadHandleCount;
|
sl@0
|
108 |
TInt initProcessHandleCount;
|
sl@0
|
109 |
RThread().HandleCount(initProcessHandleCount, initThreadHandleCount);
|
sl@0
|
110 |
|
sl@0
|
111 |
testSetup->LogFile().write(_L("<html><body><pre>\r\n"));
|
sl@0
|
112 |
testSetup->LogFile().write(_L("State of the system before the tests:\n"));
|
sl@0
|
113 |
testSetup->LogFile().write(_L("\tRFs resource count: %d\n"), initRFsCount);
|
sl@0
|
114 |
testSetup->LogFile().write(_L("\tProcess handle count: %d\n"), initProcessHandleCount);
|
sl@0
|
115 |
testSetup->LogFile().write(_L("\tThread handle count: %d\n"), initThreadHandleCount);
|
sl@0
|
116 |
|
sl@0
|
117 |
TRAPD(error, testSetup->SetupTestsL(fs, *testSpec, theTestTypes, *commandLineArgs))
|
sl@0
|
118 |
|
sl@0
|
119 |
if(error==KErrNone)
|
sl@0
|
120 |
{
|
sl@0
|
121 |
CTestHandler* handler = CTestHandler::NewLC(fs, *testSpec, *commandLineArgs,
|
sl@0
|
122 |
&testSetup->Console(),
|
sl@0
|
123 |
&testSetup->LogFile());
|
sl@0
|
124 |
handler->RunTestsL();
|
sl@0
|
125 |
summary = handler->Summary();
|
sl@0
|
126 |
testSpec->FreeAllTests();
|
sl@0
|
127 |
CleanupStack::PopAndDestroy(handler);
|
sl@0
|
128 |
|
sl@0
|
129 |
// Do heap, RFs resource, process and thread handle balance checks
|
sl@0
|
130 |
|
sl@0
|
131 |
TInt finalRFsCount = fs.ResourceCount();
|
sl@0
|
132 |
|
sl@0
|
133 |
testSetup->LogFile().write(_L("State of the system after the tests:\n"));
|
sl@0
|
134 |
testSetup->LogFile().write(_L("\tRFs resource count: %d\n"), finalRFsCount);
|
sl@0
|
135 |
|
sl@0
|
136 |
if (initRFsCount == finalRFsCount)
|
sl@0
|
137 |
{
|
sl@0
|
138 |
testSetup->LogFile().write(_L("\nRFs resource count ok: %d final\n\n"),
|
sl@0
|
139 |
finalRFsCount);
|
sl@0
|
140 |
}
|
sl@0
|
141 |
else
|
sl@0
|
142 |
{
|
sl@0
|
143 |
testSetup->LogFile().write(_L("\nRFs resource count inbalance: %d final\n\n"),
|
sl@0
|
144 |
finalRFsCount);
|
sl@0
|
145 |
++summary.iTestsFailed;
|
sl@0
|
146 |
}
|
sl@0
|
147 |
|
sl@0
|
148 |
|
sl@0
|
149 |
TInt finalAllocCount = User::CountAllocCells();
|
sl@0
|
150 |
if (initAllocCount == finalAllocCount)
|
sl@0
|
151 |
{
|
sl@0
|
152 |
testSetup->LogFile().write(_L("\nHeap alloc count ok: %d final vs %d initial\n\n"),
|
sl@0
|
153 |
finalAllocCount, initAllocCount);
|
sl@0
|
154 |
}
|
sl@0
|
155 |
else
|
sl@0
|
156 |
{
|
sl@0
|
157 |
testSetup->LogFile().write(_L("\nHeap alloc count inbalance: %d final vs %d initial\n\n"),
|
sl@0
|
158 |
finalAllocCount, initAllocCount);
|
sl@0
|
159 |
++summary.iTestsFailed;
|
sl@0
|
160 |
}
|
sl@0
|
161 |
|
sl@0
|
162 |
TInt finalThreadHandleCount;
|
sl@0
|
163 |
TInt finalProcessHandleCount;
|
sl@0
|
164 |
RThread().HandleCount(finalProcessHandleCount, finalThreadHandleCount);
|
sl@0
|
165 |
|
sl@0
|
166 |
if (initProcessHandleCount == finalProcessHandleCount)
|
sl@0
|
167 |
{
|
sl@0
|
168 |
testSetup->LogFile().write(_L("\nProcess handle count ok: %d final vs %d initial\n\n"),
|
sl@0
|
169 |
finalProcessHandleCount, initProcessHandleCount);
|
sl@0
|
170 |
}
|
sl@0
|
171 |
else
|
sl@0
|
172 |
{
|
sl@0
|
173 |
testSetup->LogFile().write(_L("\nProcess handle count imbalance: %d final vs %d initial\n\n"),
|
sl@0
|
174 |
finalProcessHandleCount, initProcessHandleCount);
|
sl@0
|
175 |
++summary.iTestsFailed;
|
sl@0
|
176 |
}
|
sl@0
|
177 |
|
sl@0
|
178 |
if (initThreadHandleCount == finalThreadHandleCount)
|
sl@0
|
179 |
{
|
sl@0
|
180 |
testSetup->LogFile().write(_L("\nThread handle count ok: %d final vs %d initial\n\n"),
|
sl@0
|
181 |
finalThreadHandleCount, initThreadHandleCount);
|
sl@0
|
182 |
}
|
sl@0
|
183 |
else
|
sl@0
|
184 |
{
|
sl@0
|
185 |
testSetup->LogFile().write(_L("\nThread handle count imbalance: %d final vs %d initial\n\n"),
|
sl@0
|
186 |
finalThreadHandleCount, initThreadHandleCount);
|
sl@0
|
187 |
++summary.iTestsFailed;
|
sl@0
|
188 |
}
|
sl@0
|
189 |
++summary.iTestsRun;
|
sl@0
|
190 |
}
|
sl@0
|
191 |
|
sl@0
|
192 |
// Set the result if required by caller
|
sl@0
|
193 |
if (aResult)
|
sl@0
|
194 |
{
|
sl@0
|
195 |
*aResult = summary.AllTestsPassed();
|
sl@0
|
196 |
}
|
sl@0
|
197 |
|
sl@0
|
198 |
summary.PrintL(testSetup->LogFile());
|
sl@0
|
199 |
|
sl@0
|
200 |
// pauses runtime if command line requests it i.e. -w
|
sl@0
|
201 |
if(commandLineArgs->iWaitForKeyPressAtEnd)
|
sl@0
|
202 |
{
|
sl@0
|
203 |
testSetup->Console().Printf(_L("\nPress a key to quit"));
|
sl@0
|
204 |
testSetup->Console().Getch();
|
sl@0
|
205 |
}
|
sl@0
|
206 |
|
sl@0
|
207 |
}
|
sl@0
|
208 |
|
sl@0
|
209 |
CleanupStack::PopAndDestroy(4, &fs); // fs, testsetup, commandLineArgs and testspec
|
sl@0
|
210 |
// this MUST be the last thing to do incase objects being destructed on cleanup
|
sl@0
|
211 |
// have debug info
|
sl@0
|
212 |
//if (bTestSuccess)
|
sl@0
|
213 |
// RDebug::RawPrint(_L("RTEST: SUCCESS : testhandler\n"));
|
sl@0
|
214 |
}
|
sl@0
|
215 |
|
sl@0
|
216 |
EXPORT_C void CTestSetup::CreateAndRunTestsL(THardcodedTests theTestTypes[], const TDesC& aDefaultLog)
|
sl@0
|
217 |
{
|
sl@0
|
218 |
LOG(_L("-- Test handler starting"));
|
sl@0
|
219 |
|
sl@0
|
220 |
RFs fs;
|
sl@0
|
221 |
|
sl@0
|
222 |
InitFileserverSessionLC(fs);
|
sl@0
|
223 |
|
sl@0
|
224 |
InitFileserverSessionLC(fs);
|
sl@0
|
225 |
|
sl@0
|
226 |
CHardcodedSetup* testSetup = CHardcodedSetup::NewLC();
|
sl@0
|
227 |
CTestHandlerSettings* commandLineArgs = CTestHandlerSettings::NewLC();
|
sl@0
|
228 |
CTestSpec* testSpec = CTestSpec::NewL();
|
sl@0
|
229 |
CleanupStack::PushL(testSpec);
|
sl@0
|
230 |
|
sl@0
|
231 |
TTestSummary summary;
|
sl@0
|
232 |
if(testSetup->InitialiseL(fs, aDefaultLog))
|
sl@0
|
233 |
{
|
sl@0
|
234 |
|
sl@0
|
235 |
// Store the state of the heap and RFs resource count before the tests
|
sl@0
|
236 |
|
sl@0
|
237 |
TInt initAllocCount = User::CountAllocCells();
|
sl@0
|
238 |
TInt initRFsCount = fs.ResourceCount();
|
sl@0
|
239 |
|
sl@0
|
240 |
TRAPD(error, testSetup->SetupTestsL(fs, *testSpec, theTestTypes, *commandLineArgs));
|
sl@0
|
241 |
|
sl@0
|
242 |
if(error==KErrNone)
|
sl@0
|
243 |
{
|
sl@0
|
244 |
CTestHandler* handler = CTestHandler::NewLC(fs, *testSpec, *commandLineArgs,
|
sl@0
|
245 |
&testSetup->Console(),
|
sl@0
|
246 |
&testSetup->LogFile());
|
sl@0
|
247 |
handler->RunTestsL();
|
sl@0
|
248 |
summary = handler->Summary();
|
sl@0
|
249 |
testSpec->FreeAllTests();
|
sl@0
|
250 |
CleanupStack::PopAndDestroy(handler);
|
sl@0
|
251 |
|
sl@0
|
252 |
// Do heap and RFs resource balance checks
|
sl@0
|
253 |
|
sl@0
|
254 |
TInt finalRFsCount = fs.ResourceCount();
|
sl@0
|
255 |
|
sl@0
|
256 |
testSetup->LogFile().write(_L("State of the system after the tests:\n"));
|
sl@0
|
257 |
testSetup->LogFile().write(_L("\tRFs resource count: %d\n"), finalRFsCount);
|
sl@0
|
258 |
|
sl@0
|
259 |
if (initRFsCount == finalRFsCount)
|
sl@0
|
260 |
{
|
sl@0
|
261 |
testSetup->LogFile().write(_L("\nRFs resource count ok: %d final\n\n"),
|
sl@0
|
262 |
finalRFsCount);
|
sl@0
|
263 |
}
|
sl@0
|
264 |
else
|
sl@0
|
265 |
{
|
sl@0
|
266 |
testSetup->LogFile().write(_L("\nRFs resource count inbalance: %d final\n\n"),
|
sl@0
|
267 |
finalRFsCount);
|
sl@0
|
268 |
++summary.iTestsFailed;
|
sl@0
|
269 |
}
|
sl@0
|
270 |
|
sl@0
|
271 |
TInt finalAllocCount = User::CountAllocCells();
|
sl@0
|
272 |
if (initAllocCount == finalAllocCount)
|
sl@0
|
273 |
{
|
sl@0
|
274 |
testSetup->LogFile().write(_L("\nHeap alloc count ok: %d final vs %d initial\n\n"),
|
sl@0
|
275 |
finalAllocCount, initAllocCount);
|
sl@0
|
276 |
}
|
sl@0
|
277 |
else
|
sl@0
|
278 |
{
|
sl@0
|
279 |
testSetup->LogFile().write(_L("\nHeap alloc count inbalance: %d final vs %d initial\n\n"),
|
sl@0
|
280 |
finalAllocCount, initAllocCount);
|
sl@0
|
281 |
++summary.iTestsFailed;
|
sl@0
|
282 |
}
|
sl@0
|
283 |
++summary.iTestsRun;
|
sl@0
|
284 |
}
|
sl@0
|
285 |
|
sl@0
|
286 |
summary.PrintL(testSetup->LogFile());
|
sl@0
|
287 |
|
sl@0
|
288 |
// pauses runtime if command line requests it i.e. -w
|
sl@0
|
289 |
if(commandLineArgs->iWaitForKeyPressAtEnd)
|
sl@0
|
290 |
{
|
sl@0
|
291 |
testSetup->Console().Printf(_L("\nPress a key to quit"));
|
sl@0
|
292 |
testSetup->Console().Getch();
|
sl@0
|
293 |
}
|
sl@0
|
294 |
}
|
sl@0
|
295 |
|
sl@0
|
296 |
CleanupStack::PopAndDestroy(4, &fs); // fs, testsetup, commandLineArgs and testspec
|
sl@0
|
297 |
|
sl@0
|
298 |
//if (bTestSuccess)
|
sl@0
|
299 |
// RDebug::RawPrint(_L("RTEST: SUCCESS : testhandler\n"));
|
sl@0
|
300 |
}
|
sl@0
|
301 |
|
sl@0
|
302 |
//Check all flags is provided for understanability - Each grouping function called calls the next function
|
sl@0
|
303 |
// if it has succeeded
|
sl@0
|
304 |
TBool CTestSetup::CheckAllFlags(const CTestHandlerSettings& aCommandLineSettings, TInt& aScriptGroupings)
|
sl@0
|
305 |
{
|
sl@0
|
306 |
return CheckExhaustiveandSmoke(aCommandLineSettings,aScriptGroupings);
|
sl@0
|
307 |
}
|
sl@0
|
308 |
|
sl@0
|
309 |
TBool CTestSetup::CheckExhaustiveandSmoke(const CTestHandlerSettings& aCommandLineSettings, TInt& aScriptGroupings)
|
sl@0
|
310 |
{
|
sl@0
|
311 |
|
sl@0
|
312 |
if (aCommandLineSettings.iExhaust || (aScriptGroupings & SMOKE))
|
sl@0
|
313 |
{
|
sl@0
|
314 |
//Do other flags
|
sl@0
|
315 |
return CheckSkipped(aCommandLineSettings, aScriptGroupings);
|
sl@0
|
316 |
}
|
sl@0
|
317 |
else
|
sl@0
|
318 |
|
sl@0
|
319 |
return EFalse;
|
sl@0
|
320 |
}
|
sl@0
|
321 |
|
sl@0
|
322 |
|
sl@0
|
323 |
TBool CTestSetup::CheckSkipped(const CTestHandlerSettings& aCommandLineSettings,
|
sl@0
|
324 |
TInt& aScriptGroupings)
|
sl@0
|
325 |
{
|
sl@0
|
326 |
if (aCommandLineSettings.iSkip || !(aScriptGroupings & SKIP))
|
sl@0
|
327 |
{
|
sl@0
|
328 |
//Do other flags
|
sl@0
|
329 |
return CheckInteractive(aCommandLineSettings, aScriptGroupings);
|
sl@0
|
330 |
}
|
sl@0
|
331 |
else
|
sl@0
|
332 |
return EFalse;
|
sl@0
|
333 |
}
|
sl@0
|
334 |
|
sl@0
|
335 |
TBool CTestSetup::CheckInteractive(const CTestHandlerSettings& aCommandLineSettings,
|
sl@0
|
336 |
TInt& aScriptGroupings)
|
sl@0
|
337 |
{
|
sl@0
|
338 |
if (aCommandLineSettings.iInt || !(aScriptGroupings & INTER))
|
sl@0
|
339 |
{
|
sl@0
|
340 |
//Do other flags
|
sl@0
|
341 |
return CheckOOMandCancel(aCommandLineSettings, aScriptGroupings);
|
sl@0
|
342 |
}
|
sl@0
|
343 |
else
|
sl@0
|
344 |
return EFalse;
|
sl@0
|
345 |
}
|
sl@0
|
346 |
|
sl@0
|
347 |
TBool CTestSetup::CheckOOMandCancel(const CTestHandlerSettings& aCommandLineSettings,
|
sl@0
|
348 |
TInt& aScriptGroupings)
|
sl@0
|
349 |
{
|
sl@0
|
350 |
|
sl@0
|
351 |
if ((aScriptGroupings & (EXOOM | INOOM)) == (EXOOM | INOOM))
|
sl@0
|
352 |
User::Panic(_L("Test is both Included and Excluded from OOM"), 1);
|
sl@0
|
353 |
|
sl@0
|
354 |
if ((aScriptGroupings & (EXCANCEL | INCANCEL)) == (EXCANCEL | INCANCEL))
|
sl@0
|
355 |
User::Panic(_L("Test is both Included and Excluded from Cancel"), 1);
|
sl@0
|
356 |
|
sl@0
|
357 |
if ((aScriptGroupings & (INOOM | INCANCEL)) == (INOOM | INCANCEL))
|
sl@0
|
358 |
User::Panic(_L("Test is in both OOM and Cancel groups"), 1);
|
sl@0
|
359 |
|
sl@0
|
360 |
// Check to see whether -o set
|
sl@0
|
361 |
if (aCommandLineSettings.iOOM)
|
sl@0
|
362 |
{
|
sl@0
|
363 |
//Is the test in OOM group?
|
sl@0
|
364 |
if (aScriptGroupings & INOOM)
|
sl@0
|
365 |
return ETrue;
|
sl@0
|
366 |
else
|
sl@0
|
367 |
//Is the test excluded from OOM?
|
sl@0
|
368 |
if (aScriptGroupings & EXOOM)
|
sl@0
|
369 |
return EFalse;
|
sl@0
|
370 |
}
|
sl@0
|
371 |
else
|
sl@0
|
372 |
if (aScriptGroupings & INOOM)
|
sl@0
|
373 |
return EFalse;
|
sl@0
|
374 |
|
sl@0
|
375 |
// Check to see whether -c set
|
sl@0
|
376 |
if (aCommandLineSettings.iCancel)
|
sl@0
|
377 |
{
|
sl@0
|
378 |
//Is the test in CANCEL group?
|
sl@0
|
379 |
if (aScriptGroupings & INCANCEL)
|
sl@0
|
380 |
return ETrue;
|
sl@0
|
381 |
else
|
sl@0
|
382 |
//Is the test excluded from CANCEL?
|
sl@0
|
383 |
if (aScriptGroupings & EXCANCEL)
|
sl@0
|
384 |
return EFalse;
|
sl@0
|
385 |
}
|
sl@0
|
386 |
else
|
sl@0
|
387 |
if (aScriptGroupings & INCANCEL)
|
sl@0
|
388 |
return EFalse;
|
sl@0
|
389 |
|
sl@0
|
390 |
|
sl@0
|
391 |
return ETrue;
|
sl@0
|
392 |
}
|
sl@0
|
393 |
|
sl@0
|
394 |
|
sl@0
|
395 |
EXPORT_C CTestSetup::~CTestSetup()
|
sl@0
|
396 |
{
|
sl@0
|
397 |
delete iLogFile;
|
sl@0
|
398 |
delete iTestConsole;
|
sl@0
|
399 |
if (iConsoleOwned)
|
sl@0
|
400 |
{
|
sl@0
|
401 |
// Note that the heap count when this is deleted must be the same as
|
sl@0
|
402 |
// when the console was allocated, otherwise a panic will occur. This
|
sl@0
|
403 |
// is due to the techview implementation of the console doing a heap
|
sl@0
|
404 |
// mark in its destructor.
|
sl@0
|
405 |
delete iConsole;
|
sl@0
|
406 |
}
|
sl@0
|
407 |
}
|
sl@0
|
408 |
|
sl@0
|
409 |
CTestSetup::CTestSetup(CConsoleBase* aConsole)
|
sl@0
|
410 |
: iConsole(aConsole), iConsoleOwned(aConsole == NULL)
|
sl@0
|
411 |
{
|
sl@0
|
412 |
}
|
sl@0
|
413 |
|
sl@0
|
414 |
void CTestSetup::ConstructL()
|
sl@0
|
415 |
{
|
sl@0
|
416 |
if (iConsoleOwned)
|
sl@0
|
417 |
{
|
sl@0
|
418 |
iConsole = Console::NewL(_L("Test code"), TSize(KDefaultConsWidth, KDefaultConsHeight));
|
sl@0
|
419 |
}
|
sl@0
|
420 |
|
sl@0
|
421 |
// Currently the console passed to the test actions discards all output -
|
sl@0
|
422 |
// this is an attempt to make hardware tests run faster. All information
|
sl@0
|
423 |
// should be written to the log file anyway, and I'd like to remove use of a
|
sl@0
|
424 |
// console as well as the log file. -- jc
|
sl@0
|
425 |
iTestConsole = new (ELeave) CDummyConsole();
|
sl@0
|
426 |
}
|
sl@0
|
427 |
|
sl@0
|
428 |
void CTestSetup::OpenLogFileL(RFs &aFs, TInt nPos, const TDesC &aLogFile, TBool aUseCommandline)
|
sl@0
|
429 |
{
|
sl@0
|
430 |
HBufC* logFileName = NULL;
|
sl@0
|
431 |
|
sl@0
|
432 |
if (aUseCommandline)
|
sl@0
|
433 |
{
|
sl@0
|
434 |
logFileName = GetArgument(nPos);
|
sl@0
|
435 |
CleanupStack::PushL(logFileName);
|
sl@0
|
436 |
|
sl@0
|
437 |
// check if logfile was specified on command line
|
sl@0
|
438 |
if(logFileName->Length()==0)
|
sl@0
|
439 |
{
|
sl@0
|
440 |
// empty so remove it
|
sl@0
|
441 |
CleanupStack::PopAndDestroy(logFileName);
|
sl@0
|
442 |
logFileName = NULL;
|
sl@0
|
443 |
}
|
sl@0
|
444 |
}
|
sl@0
|
445 |
|
sl@0
|
446 |
if(logFileName == NULL)
|
sl@0
|
447 |
{
|
sl@0
|
448 |
if(aLogFile.Length()==0)
|
sl@0
|
449 |
{
|
sl@0
|
450 |
PRINTANDLOG(_L("No log file specified on command line and no default given"));
|
sl@0
|
451 |
User::Leave(KErrArgument);
|
sl@0
|
452 |
}
|
sl@0
|
453 |
else
|
sl@0
|
454 |
{
|
sl@0
|
455 |
// there is a default copy that
|
sl@0
|
456 |
logFileName = aLogFile.AllocL();
|
sl@0
|
457 |
CleanupStack::PushL(logFileName);
|
sl@0
|
458 |
}
|
sl@0
|
459 |
}
|
sl@0
|
460 |
|
sl@0
|
461 |
PRINTANDLOG1(_L("Log file: %S"), logFileName);
|
sl@0
|
462 |
|
sl@0
|
463 |
RFile logFile;
|
sl@0
|
464 |
|
sl@0
|
465 |
// attempts to create directories incase they dont exist
|
sl@0
|
466 |
aFs.MkDirAll(*logFileName); // ignore errors
|
sl@0
|
467 |
|
sl@0
|
468 |
// write over any existing log
|
sl@0
|
469 |
User::LeaveIfError(logFile.Replace(aFs, *logFileName, EFileWrite));
|
sl@0
|
470 |
|
sl@0
|
471 |
// output goes only to the log file
|
sl@0
|
472 |
iLogFile = new(ELeave) FileOutput(logFile);
|
sl@0
|
473 |
CleanupStack::PopAndDestroy(logFileName);
|
sl@0
|
474 |
};
|