|
1 // Copyright (c) 2002-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 // $Workfile: t_main.cpp $ |
|
15 // $Author: Stevep $ |
|
16 // $Revision: 6 $ |
|
17 // $Date: 27/03/02 11:13 $ |
|
18 // |
|
19 // |
|
20 |
|
21 |
|
22 #include <e32std.h> |
|
23 #include <c32comm.h> |
|
24 #include <bacline.h> |
|
25 |
|
26 #include "obextestutils.h" |
|
27 #include "harness.h" |
|
28 #include "parsers.h" |
|
29 #include "obexparsers.h" |
|
30 |
|
31 |
|
32 // Name of test harness. |
|
33 _LIT(KObexTestName, "OBEX Mtm Tests"); |
|
34 _LIT(KObexTestExeName, "T_OBEXMTM"); |
|
35 |
|
36 //Name of the main script file. |
|
37 _LIT(KScriptFileName, "c:\\msgtest\\obexsmoke\\scripts\\script.txt"); |
|
38 |
|
39 // Where the test harness places the log file. |
|
40 _LIT(KMsvMsgLogsSrcPath, "c:\\MsgLogs\\"); |
|
41 |
|
42 // Device drivers. |
|
43 #if defined (__WINS__) |
|
44 #define PDD_NAME _L("ECDRV") |
|
45 #define LDD_NAME _L("ECOMM") |
|
46 #else // __GCC32__ |
|
47 #define PDD_NAME _L("EUART2") |
|
48 #define LDD_NAME _L("ECOMM") |
|
49 #define FIR_PDD_NAME _L("DIFIR") // Brutus FIR PDD |
|
50 #define FIR_LDD_NAME _L("EFIR") // Brutus FIR LDD |
|
51 #endif |
|
52 |
|
53 |
|
54 void AppendVariantName(TDes& aFileName) |
|
55 { |
|
56 #if defined(__WINS__) && defined(__WINSCW__) |
|
57 aFileName.Append(_L(".WINSCW.")); |
|
58 #elif(__WINS__) |
|
59 aFileName.Append(_L(".WINS.")); |
|
60 #endif |
|
61 #if (defined(__THUMB__) || defined(__MARM_THUMB__)) |
|
62 aFileName.Append(_L(".THUMB.")); |
|
63 #endif |
|
64 #if (defined(__ARMI__) || defined(__MARM_ARMI__)) |
|
65 aFileName.Append(_L(".ARMI.")); |
|
66 #endif |
|
67 #if (defined(__ARM4__) || defined(__MISA__) || defined(__MARM_ARM4__)) |
|
68 aFileName.Append(_L(".ARM4.")); |
|
69 #endif |
|
70 |
|
71 #if defined(_DEBUG) |
|
72 aFileName.Append(_L("DEB.")); |
|
73 #else |
|
74 aFileName.Append(_L("REL.")); |
|
75 #endif |
|
76 |
|
77 aFileName.Append(_L("LOG")); |
|
78 } |
|
79 |
|
80 |
|
81 void MoveLogsL(RFs& aRfs, const TDesC& aTestScript) |
|
82 { |
|
83 // Move the test log directory and file. |
|
84 // |
|
85 // For example: test script "c:\msgtest\mmssmoke\scripts\MTM_Registering_Script.txt", |
|
86 // under a WINS UDEB build, test harness name T_OBEXMTM. |
|
87 // |
|
88 // dir src = c:\MsgLogs\T_OBEXMTM |
|
89 // dir dst = c:\MsgLogs\T_OBEXMTM_MTM_Registering_Script |
|
90 // |
|
91 // file src = c:\MsgLogs\T_OBEXMTM.WINS.DEB.LOG |
|
92 // file dst = c:\MsgLogs\T_OBEXMTM_MTM_Registering_Script.WINS.DEB.LOG |
|
93 |
|
94 CFileMan* fileMan = CFileMan::NewL(aRfs); |
|
95 CleanupStack::PushL(fileMan); |
|
96 |
|
97 // |
|
98 // Determine dir name for src. |
|
99 TFileName msgLogsSrc; |
|
100 |
|
101 msgLogsSrc.Append(KMsvMsgLogsSrcPath); // Add "c:\MsgLogs\". |
|
102 msgLogsSrc.Append(KObexTestExeName); // Add "T_OBEXMTM". |
|
103 |
|
104 // |
|
105 // Determine dir name for dst. |
|
106 TFileName msgLogsDst; |
|
107 TInt fileErr; |
|
108 TInt loc; |
|
109 TInt len; |
|
110 |
|
111 msgLogsDst = msgLogsSrc; // Add "c:\MsgLogs\T_OBEXMTM". |
|
112 msgLogsDst.Append('_'); // Add "_". |
|
113 |
|
114 // Add test name. |
|
115 len = aTestScript.Length(); |
|
116 loc = aTestScript.LocateReverse('\\'); |
|
117 msgLogsDst.Append(aTestScript.Right(len - loc - 1)); |
|
118 |
|
119 // Remove the ".ext". |
|
120 msgLogsDst = msgLogsDst.Left(msgLogsDst.Locate('.')); |
|
121 |
|
122 // |
|
123 // Move the dir. |
|
124 fileErr = fileMan->Move(msgLogsSrc, msgLogsDst); |
|
125 |
|
126 // Move will not delete existing directories, so we have to do it ourself. |
|
127 // The documentation says it will delete directories !!!! |
|
128 if (fileErr == KErrAlreadyExists) |
|
129 { |
|
130 msgLogsDst.Append('\\'); // To ensure we delete the correct directory. |
|
131 fileErr = fileMan->RmDir(msgLogsDst); |
|
132 msgLogsDst = msgLogsDst.Left(msgLogsDst.Length() - 1); // Remove '\' again. |
|
133 if (fileErr == KErrNone) |
|
134 fileErr = fileMan->Move(msgLogsSrc, msgLogsDst); |
|
135 } |
|
136 |
|
137 // |
|
138 // Now move the file. Append ".WINS.DEB.LOG" to src and dst. |
|
139 AppendVariantName(msgLogsSrc); |
|
140 AppendVariantName(msgLogsDst); |
|
141 |
|
142 fileErr = fileMan->Move(msgLogsSrc, msgLogsDst); |
|
143 |
|
144 CleanupStack::PopAndDestroy(fileMan); |
|
145 } |
|
146 |
|
147 |
|
148 TInt RunTestL(RFs& aRfs, RTest& aTest, const TDesC& aTestScript) |
|
149 { |
|
150 TInt err = KErrNone; |
|
151 |
|
152 // Create the test script object, which will use the test script |
|
153 CTestScript* script = CTestScript::NewL(aRfs); |
|
154 CleanupStack::PushL(script); |
|
155 |
|
156 script->LoadFileL(aTestScript); |
|
157 |
|
158 // Create the main test harness, to which all test states will |
|
159 // be appended. |
|
160 CMainTestHarness* mainTest = CMainTestHarness::NewL(aTest); |
|
161 CleanupStack::PushL(mainTest); |
|
162 |
|
163 TTestDebugInfo debugInfo(*script, 0, 0); |
|
164 |
|
165 mainTest->SetDebugInfo(debugInfo); |
|
166 |
|
167 // Create a new section parser. |
|
168 CObexMainSectionParser* mainSectionParser = CObexMainSectionParser::NewL(*mainTest, *script); |
|
169 CleanupStack::PushL(mainSectionParser); |
|
170 |
|
171 // Attempt to parse the script |
|
172 TRAP(err, mainSectionParser->ParseL()); |
|
173 if (err == KErrNone) |
|
174 { |
|
175 // If we've parsed the script OK, attempt to run the test. |
|
176 // The "waiter" object is provided just in case we don't |
|
177 // want to start and stop the active scheduler. |
|
178 CTestActive* waiter = new (ELeave) CTestActive; |
|
179 CleanupStack::PushL(waiter); |
|
180 |
|
181 waiter->StartL(); |
|
182 mainTest->StartL(waiter->iStatus); |
|
183 CActiveScheduler::Start(); |
|
184 err = waiter->iStatus.Int(); |
|
185 |
|
186 CleanupStack::PopAndDestroy(waiter); |
|
187 } |
|
188 |
|
189 CleanupStack::PopAndDestroy(mainSectionParser); |
|
190 CleanupStack::PopAndDestroy(mainTest); |
|
191 CleanupStack::PopAndDestroy(script); |
|
192 |
|
193 return err; |
|
194 } |
|
195 |
|
196 |
|
197 TInt doMainL() |
|
198 { |
|
199 TInt err = KErrNone; |
|
200 |
|
201 // Create the test object which we'll use for output etc. |
|
202 RTest test(KObexTestName); |
|
203 CleanupClosePushL(test); |
|
204 |
|
205 // Load Device drivers ... may have to move this... |
|
206 |
|
207 #ifdef __EPOC32__ |
|
208 StartC32(); |
|
209 #endif |
|
210 User::LoadPhysicalDevice(PDD_NAME); |
|
211 User::LoadLogicalDevice(LDD_NAME); |
|
212 #ifdef __EPOC32__ |
|
213 User::LoadPhysicalDevice(FIR_PDD_NAME); |
|
214 User::LoadLogicalDevice(FIR_LDD_NAME); |
|
215 #endif |
|
216 |
|
217 // Start the file system. |
|
218 RFs rfs; |
|
219 User::LeaveIfError(rfs.Connect()); |
|
220 CleanupClosePushL(rfs); |
|
221 |
|
222 // Start a new active scheduler. |
|
223 CActiveScheduler* scheduler = new (ELeave) CActiveScheduler; |
|
224 CActiveScheduler::Install(scheduler); |
|
225 CleanupStack::PushL(scheduler); |
|
226 |
|
227 // Name of the actual script being executed. |
|
228 HBufC* scriptFileName = HBufC::NewLC(KMaxFileName); |
|
229 TPtr strPtr = scriptFileName->Des(); |
|
230 |
|
231 _LIT(KInputScriptParameterId, "-i"); |
|
232 _LIT(KScriptNotFoundErr, "%S not found!\n\n"); |
|
233 |
|
234 // Handle command line arguments |
|
235 CCommandLineArguments* args = CCommandLineArguments::NewLC(); |
|
236 TInt argCount = args->Count(); |
|
237 TInt currArg = 0; |
|
238 |
|
239 // Search for "-i" parameter. |
|
240 while ((currArg < argCount) && args->Arg(currArg).Compare(KInputScriptParameterId)) |
|
241 { |
|
242 currArg++; |
|
243 } |
|
244 |
|
245 // Input script filename argument NOT present |
|
246 // |
|
247 // Run multiple test scripts, held in KScriptFileName. |
|
248 if ((currArg == argCount) || (currArg == (argCount - 1))) |
|
249 { |
|
250 CleanupStack::PopAndDestroy(args); // Done with arguments. |
|
251 |
|
252 // Load the main script file, used to determine which actual test scripts are run. |
|
253 CTestScript* mainScript = CTestScript::NewL(rfs); |
|
254 CleanupStack::PushL(mainScript); |
|
255 |
|
256 if (mainScript->LoadFileL(KScriptFileName)) |
|
257 { |
|
258 CTestScript::TTestScriptString line; |
|
259 TBool lineGot = false; |
|
260 TInt linePos = 0; |
|
261 |
|
262 |
|
263 // For each valid line in the main script file, run the test. |
|
264 lineGot = mainScript->GetLineL(line, linePos); |
|
265 while (lineGot) |
|
266 { |
|
267 if (line.Length() > 0) |
|
268 { |
|
269 TInt fileErr; |
|
270 TBool dummy = TRUE; |
|
271 |
|
272 |
|
273 // Determine the test script file name and path. |
|
274 strPtr.Copy(line); |
|
275 strPtr.Insert(0, KScriptFileName().Left(KScriptFileName().LocateReverse('\\') + 1)); // inserts path |
|
276 |
|
277 // Ensure file exsits. |
|
278 fileErr = rfs.IsFileOpen(scriptFileName->Des(), dummy); |
|
279 if (fileErr == KErrNone) |
|
280 { |
|
281 // Start the test. |
|
282 err = RunTestL(rfs, test, scriptFileName->Des()); |
|
283 |
|
284 // Move the output log. |
|
285 MoveLogsL(rfs, scriptFileName->Des()); |
|
286 } |
|
287 } |
|
288 |
|
289 else |
|
290 { |
|
291 test.Printf(KScriptNotFoundErr, scriptFileName); |
|
292 } |
|
293 |
|
294 linePos += line.Length() + 2; // 2 for cr/lf pair. |
|
295 lineGot = mainScript->GetLineL(line, linePos); |
|
296 } |
|
297 } |
|
298 |
|
299 else |
|
300 { |
|
301 test.Printf(KScriptNotFoundErr, &KScriptFileName); |
|
302 User::After(5000000); |
|
303 } |
|
304 |
|
305 CleanupStack::PopAndDestroy(mainScript); |
|
306 } |
|
307 |
|
308 // Run single test script. |
|
309 else |
|
310 { |
|
311 TInt fileErr; |
|
312 TBool dummy = TRUE; |
|
313 |
|
314 // Determine the test script file name and path. |
|
315 strPtr.Copy(args->Arg(currArg + 1)); |
|
316 strPtr.Insert(0, KScriptFileName().Left(KScriptFileName().LocateReverse('\\') + 1)); // inserts path |
|
317 |
|
318 CleanupStack::PopAndDestroy(args); // Done with arguments. |
|
319 |
|
320 // Ensure file exsits. |
|
321 fileErr = rfs.IsFileOpen(scriptFileName->Des(), dummy); |
|
322 if (fileErr == KErrNone) |
|
323 { |
|
324 // Start the test. |
|
325 err = RunTestL(rfs, test, scriptFileName->Des()); |
|
326 |
|
327 // Move the output log. |
|
328 MoveLogsL(rfs, scriptFileName->Des()); |
|
329 } |
|
330 else |
|
331 { |
|
332 test.Printf(KScriptNotFoundErr, scriptFileName); |
|
333 User::After(5000000); |
|
334 } |
|
335 } |
|
336 |
|
337 CleanupStack::PopAndDestroy(scriptFileName); |
|
338 CleanupStack::PopAndDestroy(scheduler); |
|
339 CleanupStack::PopAndDestroy(); // rfs |
|
340 CleanupStack::PopAndDestroy(); // test |
|
341 |
|
342 return err; |
|
343 } |
|
344 |
|
345 |
|
346 LOCAL_D CTrapCleanup* theCleanup; |
|
347 |
|
348 GLDEF_C TInt E32Main() |
|
349 { |
|
350 __UHEAP_MARK; |
|
351 theCleanup=CTrapCleanup::New(); |
|
352 |
|
353 TInt status = KErrNone; |
|
354 |
|
355 TRAPD(ret, status = doMainL()); |
|
356 |
|
357 delete theCleanup; |
|
358 __UHEAP_MARKEND; |
|
359 User::Heap().Check(); |
|
360 return status; |
|
361 } |