|
1 // Copyright (c) 2003-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 // |
|
15 |
|
16 /** |
|
17 * @file |
|
18 * Copyright (c) 2003 Symbian Ltd. All rights reserved. |
|
19 * |
|
20 * Name of test harness: T_BIO_S |
|
21 * |
|
22 * Owner: GKL |
|
23 * |
|
24 */ |
|
25 |
|
26 #include <e32base.h> |
|
27 #include <e32test.h> |
|
28 #include <f32file.h> |
|
29 #include <bacline.h> |
|
30 |
|
31 #include "biotestutils.h" |
|
32 #include "testframeutils.h" |
|
33 #include "harness.h" |
|
34 #include "parsers.h" |
|
35 #include "msvtestutilsbase.h" |
|
36 |
|
37 #ifdef SYMBIAN_BOOKMARK_DATABASE |
|
38 #include <bookmarkdatabase.h> |
|
39 #include <bookmark.h> |
|
40 #endif // SYMBIAN_BOOKMARK_DATABASE |
|
41 |
|
42 // Name of test harness. |
|
43 _LIT(KBioTestName, "BIO Msg Tests"); |
|
44 _LIT(KBioTestExeName, "T_BIOMSG"); |
|
45 |
|
46 // Name of the main script file. |
|
47 _LIT(KScriptFileName, "c:\\msgtest\\biomsg\\scripts\\script.txt"); |
|
48 |
|
49 // Where the test harness places the log file. |
|
50 _LIT(KMsvMsgLogsSrcPath, "c:\\MsgLogs\\"); |
|
51 |
|
52 |
|
53 RFs g_rfs; |
|
54 |
|
55 void MoveLogsL(const TDesC& aTestScript) |
|
56 { |
|
57 // Move the test log directory and file. |
|
58 // |
|
59 // For example: test script "c:\msgtest\biomsg\Wapp\wapp0001.txt", |
|
60 // under a WINS UDEB build, test harness name T_BIOMSG. |
|
61 // |
|
62 // dir src = c:\MsgLogs\T_BIOMSG |
|
63 // dir dst = c:\MsgLogs\T_BIOMSG_wapp001 |
|
64 // |
|
65 // file src = c:\MsgLogs\T_BIOMSG.WINS.DEB.LOG |
|
66 // file dst = c:\MsgLogs\T_BIOMSG_wapp001.WINS.DEB.LOG |
|
67 |
|
68 CFileMan* fileMan = CFileMan::NewL(g_rfs); |
|
69 CleanupStack::PushL(fileMan); |
|
70 |
|
71 // |
|
72 // Determine dir name for src. |
|
73 TFileName msgLogsSrc; |
|
74 |
|
75 msgLogsSrc.Append(KMsvMsgLogsSrcPath); // Add "c:\MsgLogs\". |
|
76 msgLogsSrc.Append(KBioTestExeName); // Add "T_BIOMSG". |
|
77 |
|
78 // |
|
79 // Determine dir name for dst. |
|
80 TFileName msgLogsDst; |
|
81 TInt fileErr; |
|
82 TInt loc; |
|
83 TInt len; |
|
84 |
|
85 msgLogsDst = msgLogsSrc; // Add "c:\MsgLogs\T_BIOMSG". |
|
86 msgLogsDst.Append('_'); // Add "_". |
|
87 |
|
88 // Add test name. |
|
89 len = aTestScript.Length(); |
|
90 loc = aTestScript.LocateReverse('\\'); |
|
91 msgLogsDst.Append(aTestScript.Right(len - loc - 1)); |
|
92 |
|
93 // Remove the ".ext". |
|
94 msgLogsDst = msgLogsDst.Left(msgLogsDst.Locate('.')); |
|
95 |
|
96 // |
|
97 // Move the dir. |
|
98 fileErr = fileMan->Move(msgLogsSrc, msgLogsDst); |
|
99 |
|
100 // Move will not delete existing directories, so we have to do it ourself. |
|
101 // The documentation says it will delete directories !!!! |
|
102 if (fileErr == KErrAlreadyExists) |
|
103 { |
|
104 msgLogsDst.Append('\\'); // To ensure we delete the correct directory. |
|
105 fileErr = fileMan->RmDir(msgLogsDst); |
|
106 msgLogsDst = msgLogsDst.Left(msgLogsDst.Length() - 1); // Remove '\' again. |
|
107 if (fileErr == KErrNone) |
|
108 fileErr = fileMan->Move(msgLogsSrc, msgLogsDst); |
|
109 } |
|
110 |
|
111 // |
|
112 // Now move the file. Append ".WINS.DEB.LOG" to src and dst. |
|
113 CBioTestUtils::DoAppendVariantName(msgLogsSrc); |
|
114 CBioTestUtils::DoAppendVariantName(msgLogsDst); |
|
115 |
|
116 fileErr = fileMan->Move(msgLogsSrc, msgLogsDst); |
|
117 |
|
118 CleanupStack::PopAndDestroy(fileMan); |
|
119 } |
|
120 |
|
121 |
|
122 TInt RunTestL(RTest& aTest, const TDesC& aTestScript) |
|
123 { |
|
124 TInt err = KErrNone; |
|
125 |
|
126 #ifdef SYMBIAN_BOOKMARK_DATABASE |
|
127 // Reset the bookmark database by deleting all bookmarks in root... |
|
128 RBkDatabase bookmarkDb; |
|
129 bookmarkDb.OpenL(); |
|
130 CleanupClosePushL(bookmarkDb); |
|
131 RBkFolder rootFolder = bookmarkDb.OpenRootL(); |
|
132 CleanupClosePushL(rootFolder); |
|
133 RBkNode bookmark; |
|
134 const TInt bookmarkCount = rootFolder.Count(); |
|
135 for( TInt ii=0; ii<bookmarkCount; ++ii ) |
|
136 { |
|
137 bookmark = rootFolder.OpenItemL(0); |
|
138 CleanupClosePushL(bookmark); |
|
139 if( bookmark.Type() == Bookmark::ETypeBookmark ) |
|
140 { |
|
141 Bookmark::TItemId bookmarkId = bookmark.Id(); |
|
142 CleanupStack::PopAndDestroy(&bookmark); |
|
143 TRAP_IGNORE(bookmarkDb.DeleteItemL(bookmarkId)); // ignore errors |
|
144 } |
|
145 else |
|
146 { |
|
147 CleanupStack::PopAndDestroy(&bookmark); |
|
148 } |
|
149 } |
|
150 bookmarkDb.CommitL(); |
|
151 CleanupStack::PopAndDestroy(2, &bookmarkDb); // rootFolder, bookmarkDb |
|
152 #endif // SYMBIAN_BOOKMARK_DATABASE |
|
153 |
|
154 // Create the test script object, which will use the test script |
|
155 CTestScript* script = CTestScript::NewL(g_rfs); |
|
156 CleanupStack::PushL(script); |
|
157 |
|
158 script->LoadFileL(aTestScript); |
|
159 |
|
160 // Create the main test harness, to which all test states will |
|
161 // be appended. |
|
162 CMainTestHarness* mainTest = CMainTestHarness::NewL(aTest); |
|
163 CleanupStack::PushL(mainTest); |
|
164 |
|
165 TTestDebugInfo debugInfo(*script, 0, 0); |
|
166 |
|
167 mainTest->SetDebugInfo(debugInfo); |
|
168 |
|
169 // Create a new section parser. |
|
170 CBioMainSectionParser* mainSectionParser = CBioMainSectionParser::NewL(*mainTest, *script); |
|
171 CleanupStack::PushL(mainSectionParser); |
|
172 |
|
173 // Attempt to parse the script |
|
174 TRAP(err, mainSectionParser->ParseL()); |
|
175 if (err == KErrNone) |
|
176 { |
|
177 // If we've parsed the script OK, attempt to run the test. |
|
178 // The "waiter" object is provided just in case we don't |
|
179 // want to start and stop the active scheduler. |
|
180 CTestActive* waiter = new (ELeave) CTestActive; |
|
181 CleanupStack::PushL(waiter); |
|
182 |
|
183 waiter->StartL(); |
|
184 mainTest->StartL(waiter->iStatus); |
|
185 CActiveScheduler::Start(); |
|
186 err = waiter->iStatus.Int(); |
|
187 |
|
188 CleanupStack::PopAndDestroy(waiter); |
|
189 } |
|
190 |
|
191 CleanupStack::PopAndDestroy(mainSectionParser); |
|
192 CleanupStack::PopAndDestroy(mainTest); |
|
193 CleanupStack::PopAndDestroy(script); |
|
194 |
|
195 return err; |
|
196 } |
|
197 |
|
198 |
|
199 #ifndef CENREP_SOLID_AS_A_ROCK |
|
200 void doCleanEnvironmentL(RTest& aTest) |
|
201 { |
|
202 |
|
203 // central repository cleanup |
|
204 CFileMan* fman = CFileMan::NewL(g_rfs); |
|
205 CleanupStack::PushL(fman); |
|
206 fman->Delete(_L("c:\\private\\10202be9\\*.*")); |
|
207 CleanupStack::PopAndDestroy(fman); |
|
208 |
|
209 // clean message store |
|
210 CBioTestUtils* utils = CBioTestUtils::NewL(aTest); |
|
211 CleanupStack::PushL(utils); |
|
212 TRAPD(ignor, utils->CleanMessageFolderL()); |
|
213 CleanupStack::PopAndDestroy(utils); |
|
214 } |
|
215 #endif |
|
216 |
|
217 |
|
218 TInt doMainL() |
|
219 { |
|
220 TInt err = KErrNone; |
|
221 |
|
222 // Create the test object which we'll use for output etc. |
|
223 RTest test(KBioTestName); |
|
224 |
|
225 g_rfs.Connect(); |
|
226 |
|
227 // Start a new active scheduler. |
|
228 CActiveScheduler* scheduler = new (ELeave) CActiveScheduler; |
|
229 CActiveScheduler::Install(scheduler); |
|
230 CleanupStack::PushL(scheduler); |
|
231 |
|
232 // Name of the actual script being executed. |
|
233 HBufC* scriptFileName = HBufC::NewLC(KMaxFileName); |
|
234 TPtr strPtr = scriptFileName->Des(); |
|
235 |
|
236 _LIT(KInputScriptParameterId, "-i"); |
|
237 _LIT(KScriptNotFoundErr, "%S not found!\n\n"); |
|
238 |
|
239 // Handle command line arguments |
|
240 CCommandLineArguments* args = CCommandLineArguments::NewLC(); |
|
241 TInt argCount = args->Count(); |
|
242 TInt currArg = 0; |
|
243 |
|
244 // Search for "-i" parameter. |
|
245 while ((currArg < argCount) && args->Arg(currArg).Compare(KInputScriptParameterId)) |
|
246 { |
|
247 currArg++; |
|
248 } |
|
249 |
|
250 // Input script filename argument NOT present |
|
251 // |
|
252 // Run multiple test scripts, held in KScriptFileName. |
|
253 if ((currArg == argCount) || (currArg == (argCount - 1))) |
|
254 { |
|
255 CleanupStack::PopAndDestroy(args); // Done with arguments. |
|
256 |
|
257 // Load the main script file, used to determine which actual test scripts are run. |
|
258 CTestScript* mainScript = CTestScript::NewL(g_rfs); |
|
259 CleanupStack::PushL(mainScript); |
|
260 |
|
261 if (mainScript->LoadFileL(KScriptFileName)) |
|
262 { |
|
263 CTestScript::TTestScriptString line; |
|
264 TBool lineGot = false; |
|
265 TInt linePos = 0; |
|
266 |
|
267 |
|
268 // For each valid line in the main script file, run the test. |
|
269 lineGot = mainScript->GetLineL(line, linePos); |
|
270 while (lineGot) |
|
271 { |
|
272 #ifndef CENREP_SOLID_AS_A_ROCK |
|
273 // MLM added to handle KErrCorrupts from CenRep !!! |
|
274 doCleanEnvironmentL(test); |
|
275 #endif |
|
276 |
|
277 if (line.Length() > 0) |
|
278 { |
|
279 TInt fileErr; |
|
280 TBool dummy = TRUE; |
|
281 |
|
282 |
|
283 // Determine the test script file name and path. |
|
284 strPtr.Copy(line); |
|
285 strPtr.Insert(0, KScriptFileName().Left(KScriptFileName().LocateReverse('\\') + 1)); // inserts path |
|
286 |
|
287 // Ensure file exsits. |
|
288 fileErr = g_rfs.IsFileOpen(scriptFileName->Des(), dummy); |
|
289 if (fileErr == KErrNone) |
|
290 { |
|
291 // Start the test. |
|
292 err = RunTestL(test, scriptFileName->Des()); |
|
293 |
|
294 // Move the output log. |
|
295 MoveLogsL(scriptFileName->Des()); |
|
296 } |
|
297 } |
|
298 |
|
299 else |
|
300 { |
|
301 test.Printf(KScriptNotFoundErr, scriptFileName); |
|
302 } |
|
303 |
|
304 linePos += line.Length() + 2; // 2 for cr/lf pair. |
|
305 lineGot = mainScript->GetLineL(line, linePos); |
|
306 } |
|
307 } |
|
308 |
|
309 else |
|
310 { |
|
311 test.Printf(KScriptNotFoundErr, &KScriptFileName); |
|
312 User::After(5000000); |
|
313 } |
|
314 |
|
315 CleanupStack::PopAndDestroy(mainScript); |
|
316 } |
|
317 |
|
318 // Run single test script. |
|
319 else |
|
320 { |
|
321 #ifndef CENREP_SOLID_AS_A_ROCK |
|
322 // MLM added to handle KErrCorrupts from CenRep !!! |
|
323 doCleanEnvironmentL(test); |
|
324 #endif |
|
325 |
|
326 TInt fileErr; |
|
327 TBool dummy = TRUE; |
|
328 |
|
329 // Determine the test script file name and path. |
|
330 strPtr.Copy(args->Arg(currArg + 1)); |
|
331 strPtr.Insert(0, KScriptFileName().Left(KScriptFileName().LocateReverse('\\') + 1)); // inserts path |
|
332 |
|
333 CleanupStack::PopAndDestroy(args); // Done with arguments. |
|
334 |
|
335 // Ensure file exsits. |
|
336 fileErr = g_rfs.IsFileOpen(scriptFileName->Des(), dummy); |
|
337 if (fileErr == KErrNone) |
|
338 { |
|
339 // Start the test. |
|
340 err = RunTestL(test, scriptFileName->Des()); |
|
341 |
|
342 // Move the output log. |
|
343 MoveLogsL(scriptFileName->Des()); |
|
344 } |
|
345 else |
|
346 { |
|
347 test.Printf(KScriptNotFoundErr, scriptFileName); |
|
348 User::After(5000000); |
|
349 } |
|
350 } |
|
351 CleanupStack::PopAndDestroy(scriptFileName); |
|
352 CleanupStack::PopAndDestroy(scheduler); |
|
353 |
|
354 g_rfs.Close(); |
|
355 test.Close(); |
|
356 |
|
357 return err; |
|
358 } |
|
359 |
|
360 |
|
361 LOCAL_D CTrapCleanup* theCleanup; |
|
362 |
|
363 GLDEF_C TInt E32Main() |
|
364 { |
|
365 __UHEAP_MARK; |
|
366 theCleanup=CTrapCleanup::New(); |
|
367 |
|
368 TInt status = KErrNone; |
|
369 |
|
370 TRAPD(ret, status = doMainL()); |
|
371 |
|
372 delete theCleanup; |
|
373 __UHEAP_MARKEND; |
|
374 User::Heap().Check(); |
|
375 return status; |
|
376 } |