|
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 // This file contains the test steps for Unit Test Suite 13 : TestUtils.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 // EPOC includes |
|
19 #include <e32base.h> |
|
20 |
|
21 // Test system includes |
|
22 #include <testframework.h> |
|
23 |
|
24 // Specific includes for this test suite |
|
25 #include "TSU_MmTsthStep13.h" |
|
26 #include "TSU_MmTsthSuite13.h" |
|
27 |
|
28 // Specific includes for these test steps |
|
29 #include "TSU_MmTsth13.h" |
|
30 |
|
31 // -------------------------------------------- |
|
32 |
|
33 // Unit Test Suite 13 : TestUtils.cpp |
|
34 // Depends on : none |
|
35 |
|
36 // Tests :- |
|
37 // 1. NewL / Construct - create with a CLog; |
|
38 // RunUtils / RunUtilsL - script-line format testing :- |
|
39 // 2 Copy File |
|
40 // 3 Make Dir. |
|
41 // 4 Change Dir. |
|
42 // 5 Make Read/Write |
|
43 // 6 Delete File |
|
44 // 11 Syntax error (demonstrate no panic) |
|
45 |
|
46 // NB! Test Utils in themselves are not test steps, and do NOT run in their own thread |
|
47 |
|
48 // ------------------------ |
|
49 // RTestMmTsthU1301 |
|
50 |
|
51 RTestMmTsthU1301* RTestMmTsthU1301::NewL() |
|
52 { |
|
53 RTestMmTsthU1301* self = new(ELeave) RTestMmTsthU1301; |
|
54 return self; |
|
55 } |
|
56 |
|
57 // Each test step initialises its own name. |
|
58 RTestMmTsthU1301::RTestMmTsthU1301() |
|
59 { |
|
60 iTestStepName = _L("MM-TSTH-U-1301"); |
|
61 } |
|
62 |
|
63 // preamble |
|
64 TVerdict RTestMmTsthU1301::OpenL() |
|
65 { |
|
66 // stub - purpose is that for this test we do not run the parent preamble |
|
67 // which initialises iTestUtils |
|
68 return iTestStepResult = EPass; |
|
69 } |
|
70 |
|
71 // postamble |
|
72 void RTestMmTsthU1301::Close() |
|
73 { |
|
74 } |
|
75 |
|
76 // do the test step |
|
77 TVerdict RTestMmTsthU1301::DoTestStepL() |
|
78 { |
|
79 // NB CTestUtils does not report errors, but it DOES log them. |
|
80 |
|
81 // NB a single run of TestFrameworkMain can only have ONE log file open at the server. |
|
82 // Hence we must use that one. |
|
83 |
|
84 TVerdict currentVerdict = EPass; |
|
85 |
|
86 INFO_PRINTF1(_L("Unit test for TestUtils : Construct")); |
|
87 |
|
88 CLog* theLog = iSuite->LogSystem(); // use the current log |
|
89 CTestUtils* theTestUtils = NULL; |
|
90 TRAPD(err, theTestUtils = CTestUtils::NewL(theLog)); |
|
91 if(err != KErrNone) |
|
92 { |
|
93 ERR_PRINTF2(_L("CTestUtils::NewL() failed with error code %d"), err); |
|
94 return iTestStepResult = EFail; |
|
95 } |
|
96 |
|
97 delete theTestUtils; |
|
98 |
|
99 return iTestStepResult = currentVerdict; // should be EPass if we've got here |
|
100 } |
|
101 |
|
102 // ------------------------ |
|
103 // RTestMmTsthU1302 |
|
104 |
|
105 RTestMmTsthU1302* RTestMmTsthU1302::NewL() |
|
106 { |
|
107 RTestMmTsthU1302* self = new(ELeave) RTestMmTsthU1302; |
|
108 return self; |
|
109 } |
|
110 |
|
111 // Each test step initialises its own name. |
|
112 RTestMmTsthU1302::RTestMmTsthU1302() |
|
113 { |
|
114 iTestStepName = _L("MM-TSTH-U-1302"); |
|
115 } |
|
116 |
|
117 |
|
118 // preamble |
|
119 TVerdict RTestMmTsthU1302::OpenL() |
|
120 { |
|
121 // do the standard preamble |
|
122 TVerdict currentVerdict = RTSUMmTsthStep13::OpenL(); |
|
123 if(currentVerdict != EPass) |
|
124 return currentVerdict; |
|
125 |
|
126 // do extra, to set up the files/directories we need, which are :- |
|
127 // C:\\TFData1\\testfile1.txt must exist |
|
128 // C:\\TFData2 must exist |
|
129 |
|
130 RFs theFs; |
|
131 theFs.Connect(); |
|
132 RFile theFile; |
|
133 |
|
134 TFileName theDirName = _L("c:\\TFData1\\"); |
|
135 TFileName theFileName = _L("c:\\TFData1\\testfile1.txt"); |
|
136 TInt rc = theFs.MkDir(theDirName); |
|
137 if (rc != KErrNone && rc != KErrAlreadyExists) |
|
138 { |
|
139 ERR_PRINTF2(_L("Preamble failed RFs::MkDir() error code %d"), rc); |
|
140 theFs.Close(); |
|
141 return iTestStepResult = EFail; |
|
142 } |
|
143 rc = theFile.Replace(theFs, theFileName, EFileWrite | EFileStreamText); |
|
144 |
|
145 // check if open fails |
|
146 if (rc == KErrNone) |
|
147 { |
|
148 theFile.Write(_L8("This is a test file for MM_TSTH_U_1302\n")); |
|
149 theFile.Close(); |
|
150 } |
|
151 else |
|
152 { |
|
153 ERR_PRINTF2(_L("Preamble failed RFile::Write() error code %d"), rc); |
|
154 theFs.Close(); |
|
155 return iTestStepResult = EFail; |
|
156 } |
|
157 |
|
158 theDirName = _L("c:\\TFData2\\"); |
|
159 rc = theFs.MkDir(theDirName); |
|
160 if (rc != KErrNone && rc != KErrAlreadyExists) |
|
161 { |
|
162 ERR_PRINTF2(_L("Preamble failed RFs::MkDir() error code %d"), rc); |
|
163 theFs.Close(); |
|
164 return iTestStepResult = EFail; |
|
165 } |
|
166 |
|
167 theFs.Close(); |
|
168 return iTestStepResult = currentVerdict; |
|
169 } |
|
170 |
|
171 // postamble |
|
172 void RTestMmTsthU1302::Close() |
|
173 { |
|
174 // clean up the extra files / directories we created |
|
175 CleanupFileSystem(); |
|
176 |
|
177 // do the standard postamble |
|
178 RTSUMmTsthStep13::Close(); |
|
179 } |
|
180 |
|
181 // do the test step |
|
182 TVerdict RTestMmTsthU1302::DoTestStepL() |
|
183 { |
|
184 INFO_PRINTF1(_L("Unit test for TestUtils : RunUtils - CopyFile")); |
|
185 |
|
186 TVerdict currentVerdict = EPass; |
|
187 |
|
188 iTestUtils->RunUtils(_L("run_utils copyfile c:\\TFData1\\testfile1.txt c:\\TFData2\\testfile2.txt")); |
|
189 |
|
190 // check that testfile2.txt exists |
|
191 TUint dummy; |
|
192 RFs theFs; |
|
193 theFs.Connect(); |
|
194 TInt rc = theFs.Att(_L("c:\\TFData2\\testfile2.txt"), dummy); |
|
195 if(rc != KErrNone) |
|
196 { |
|
197 ERR_PRINTF2(_L("CTestUtils : run_utils copyfile failed, error %d"), rc); |
|
198 theFs.Close(); |
|
199 return iTestStepResult = EFail; |
|
200 } |
|
201 |
|
202 // cleanup |
|
203 theFs.Close(); |
|
204 return iTestStepResult = currentVerdict; // should be EPass if we've got here |
|
205 } |
|
206 |
|
207 // -------------------- |
|
208 // RTestMmTsthU1303 |
|
209 |
|
210 RTestMmTsthU1303* RTestMmTsthU1303::NewL() |
|
211 { |
|
212 RTestMmTsthU1303* self = new(ELeave) RTestMmTsthU1303; |
|
213 return self; |
|
214 } |
|
215 |
|
216 // Each test step initialises its own name. |
|
217 RTestMmTsthU1303::RTestMmTsthU1303() |
|
218 { |
|
219 // store the name of this test case |
|
220 // this is the name that is used by the script file |
|
221 iTestStepName = _L("MM-TSTH-U-1303"); |
|
222 } |
|
223 |
|
224 // preamble |
|
225 TVerdict RTestMmTsthU1303::OpenL() |
|
226 { |
|
227 // do the standard preamble |
|
228 TVerdict currentVerdict = RTSUMmTsthStep13::OpenL(); |
|
229 if(currentVerdict != EPass) |
|
230 return currentVerdict; |
|
231 |
|
232 // do extra, to set up the files/directories we need, which are :- |
|
233 // C:\\TFData2 must not exist |
|
234 |
|
235 RFs theFs; |
|
236 CFileMan* theFm = NULL; |
|
237 theFs.Connect(); |
|
238 TRAPD(err, theFm = CFileMan::NewL(theFs)); |
|
239 if(err != KErrNone) |
|
240 { |
|
241 ERR_PRINTF2(_L("Cannot create CFileMan, error code %d"), err); |
|
242 theFs.Close(); |
|
243 return iTestStepResult = EFail; |
|
244 } |
|
245 |
|
246 TInt rc = theFm->RmDir(_L("c:\\TFData2\\")); |
|
247 if (rc != KErrNone && rc != KErrPathNotFound) |
|
248 { |
|
249 ERR_PRINTF2(_L("Preamble failed CFileMan::RmDir() error code %d"), rc); |
|
250 currentVerdict = EFail; |
|
251 } |
|
252 |
|
253 theFs.Close(); |
|
254 delete theFm; |
|
255 return iTestStepResult = currentVerdict; |
|
256 } |
|
257 |
|
258 // postamble |
|
259 void RTestMmTsthU1303::Close() |
|
260 { |
|
261 // clean up the extra files / directories we created |
|
262 CleanupFileSystem(); |
|
263 |
|
264 // do the standard postamble |
|
265 RTSUMmTsthStep13::Close(); |
|
266 } |
|
267 |
|
268 // do the test step. |
|
269 TVerdict RTestMmTsthU1303::DoTestStepL() |
|
270 { |
|
271 INFO_PRINTF1(_L("Unit test for TestUtils : RunUtils - MkDir")); |
|
272 |
|
273 TVerdict currentVerdict = EPass; |
|
274 |
|
275 iTestUtils->RunUtils(_L("run_utils mkdir c:\\TFData2\\")); |
|
276 |
|
277 // check that TFData2 exists |
|
278 TUint dummy; |
|
279 RFs theFs; |
|
280 theFs.Connect(); |
|
281 TInt rc = theFs.Att(_L("c:\\TFData2\\"), dummy); |
|
282 if(rc != KErrNone) |
|
283 { |
|
284 ERR_PRINTF2(_L("CTestUtils : run_utils mkdir failed, error %d"), rc); |
|
285 theFs.Close(); |
|
286 return iTestStepResult = EFail; |
|
287 } |
|
288 |
|
289 theFs.Close(); |
|
290 return iTestStepResult = currentVerdict; // should be EPass if we've got here |
|
291 } |
|
292 |
|
293 // -------------------- |
|
294 // RTestMmTsthU1304 |
|
295 RTestMmTsthU1304* RTestMmTsthU1304::NewL() |
|
296 { |
|
297 RTestMmTsthU1304* self = new(ELeave) RTestMmTsthU1304; |
|
298 return self; |
|
299 } |
|
300 |
|
301 // Each test step initialises its own name. |
|
302 RTestMmTsthU1304::RTestMmTsthU1304() |
|
303 { |
|
304 iTestStepName = _L("MM-TSTH-U-1304"); |
|
305 } |
|
306 |
|
307 // preamble |
|
308 TVerdict RTestMmTsthU1304::OpenL() |
|
309 { |
|
310 // do the standard preamble |
|
311 TVerdict currentVerdict = RTSUMmTsthStep13::OpenL(); |
|
312 if(currentVerdict != EPass) |
|
313 return currentVerdict; |
|
314 |
|
315 // do extra, to set up the files/directories we need, which are :- |
|
316 // C:\\TFData1\\testfile1.txt must exist and be read-only |
|
317 |
|
318 RFs theFs; |
|
319 theFs.Connect(); |
|
320 RFile theFile; |
|
321 |
|
322 TFileName theDirName = _L("c:\\TFData1\\"); |
|
323 TFileName theFileName = _L("c:\\TFData1\\testfile1.txt"); |
|
324 TInt rc = theFs.MkDir(theDirName); |
|
325 if (rc != KErrNone && rc != KErrAlreadyExists) |
|
326 { |
|
327 ERR_PRINTF2(_L("Preamble failed RFs::MkDir() error code %d"), rc); |
|
328 theFs.Close(); |
|
329 return iTestStepResult = EFail; |
|
330 } |
|
331 rc = theFile.Replace(theFs, theFileName, EFileWrite | EFileStreamText); |
|
332 |
|
333 // check if open fails |
|
334 if (rc == KErrNone) |
|
335 { |
|
336 theFile.Write(_L8("This is a test file for MM_TSTH_U_1304\n")); |
|
337 theFile.Close(); |
|
338 } |
|
339 else |
|
340 { |
|
341 ERR_PRINTF2(_L("Preamble failed RFile::Replace() error code %d"), rc); |
|
342 theFs.Close(); |
|
343 return iTestStepResult = EFail; |
|
344 } |
|
345 |
|
346 // set read-only |
|
347 rc = theFs.SetAtt(theFileName, KEntryAttReadOnly, 0); |
|
348 |
|
349 theFs.Close(); |
|
350 return iTestStepResult = currentVerdict; |
|
351 } |
|
352 |
|
353 // postamble |
|
354 void RTestMmTsthU1304::Close() |
|
355 { |
|
356 // set the file read-write for deletion |
|
357 RFs theFs; |
|
358 theFs.Connect(); |
|
359 TFileName theFileName = _L("c:\\TFData1\\testfile1.txt"); |
|
360 theFs.SetAtt(theFileName, 0, KEntryAttReadOnly); |
|
361 theFs.Close(); |
|
362 |
|
363 // clean up the extra files / directories we created |
|
364 CleanupFileSystem(); |
|
365 |
|
366 // do the standard postamble |
|
367 RTSUMmTsthStep13::Close(); |
|
368 } |
|
369 |
|
370 // do the test step |
|
371 TVerdict RTestMmTsthU1304::DoTestStepL() |
|
372 { |
|
373 INFO_PRINTF1(_L("Unit test for TestUtils : RunUtils - MakeReadWrite")); |
|
374 |
|
375 TVerdict currentVerdict = EPass; |
|
376 |
|
377 iTestUtils->RunUtils(_L("run_utils makereadwrite c:\\TFData1\\testfile1.txt")); |
|
378 |
|
379 // check that file exists and is read-only |
|
380 TUint theAtts; |
|
381 RFs theFs; |
|
382 theFs.Connect(); |
|
383 theFs.Att(_L("c:\\TFData1\\testfile1.txt"), theAtts); |
|
384 if(theAtts & KEntryAttReadOnly) |
|
385 { |
|
386 ERR_PRINTF1(_L("CTestUtils : run_utils makereadwrite failed, file is still read-only")); |
|
387 theFs.Close(); |
|
388 return iTestStepResult = EFail; |
|
389 } |
|
390 |
|
391 theFs.Close(); |
|
392 return iTestStepResult = currentVerdict; // should be EPass if we've got here |
|
393 } |
|
394 |
|
395 // -------------------- |
|
396 // RTestMmTsthU1305 |
|
397 RTestMmTsthU1305* RTestMmTsthU1305::NewL() |
|
398 { |
|
399 RTestMmTsthU1305* self = new(ELeave) RTestMmTsthU1305; |
|
400 return self; |
|
401 } |
|
402 |
|
403 // Each test step initialises its own name. |
|
404 RTestMmTsthU1305::RTestMmTsthU1305() |
|
405 { |
|
406 iTestStepName = _L("MM-TSTH-U-1305"); |
|
407 } |
|
408 |
|
409 // preamble |
|
410 TVerdict RTestMmTsthU1305::OpenL() |
|
411 { |
|
412 // do the standard preamble |
|
413 TVerdict currentVerdict = RTSUMmTsthStep13::OpenL(); |
|
414 if(currentVerdict != EPass) |
|
415 return currentVerdict; |
|
416 |
|
417 // do extra, to set up the files/directories we need, which are :- |
|
418 // C:\\TFData1\\testfile1.txt must exist and be read-write |
|
419 |
|
420 RFs theFs; |
|
421 theFs.Connect(); |
|
422 RFile theFile; |
|
423 |
|
424 TFileName theDirName = _L("c:\\TFData1\\"); |
|
425 TFileName theFileName = _L("c:\\TFData1\\testfile1.txt"); |
|
426 TInt rc = theFs.MkDir(theDirName); |
|
427 if (rc != KErrNone && rc != KErrAlreadyExists) |
|
428 { |
|
429 ERR_PRINTF2(_L("Preamble failed RFs::MkDir() error code %d"), rc); |
|
430 theFs.Close(); |
|
431 return iTestStepResult = EFail; |
|
432 } |
|
433 rc = theFile.Replace(theFs, theFileName, EFileWrite | EFileStreamText); |
|
434 |
|
435 // check if open fails |
|
436 if (rc == KErrNone) |
|
437 { |
|
438 theFile.Write(_L8("This is a test file for MM_TSTH_U_1305\n")); |
|
439 theFile.Close(); |
|
440 } |
|
441 else |
|
442 { |
|
443 ERR_PRINTF2(_L("Preamble failed RFile::Replace() error code %d"), rc); |
|
444 theFs.Close(); |
|
445 return iTestStepResult = EFail; |
|
446 } |
|
447 |
|
448 // set read-write |
|
449 rc = theFs.SetAtt(theFileName, 0, KEntryAttReadOnly); |
|
450 |
|
451 theFs.Close(); |
|
452 return iTestStepResult = currentVerdict; |
|
453 } |
|
454 |
|
455 // postamble |
|
456 void RTestMmTsthU1305::Close() |
|
457 { |
|
458 // clean up the extra files / directories we created |
|
459 CleanupFileSystem(); |
|
460 |
|
461 // do the standard postamble |
|
462 RTSUMmTsthStep13::Close(); |
|
463 } |
|
464 |
|
465 // do the test step |
|
466 TVerdict RTestMmTsthU1305::DoTestStepL() |
|
467 { |
|
468 INFO_PRINTF1(_L("Unit test for TestUtils : RunUtils - Delete")); |
|
469 |
|
470 TVerdict currentVerdict = EPass; |
|
471 |
|
472 iTestUtils->RunUtils(_L("run_utils delete c:\\TFData1\\testfile1.txt")); |
|
473 |
|
474 // check that file does not exist |
|
475 TUint dummy; |
|
476 RFs theFs; |
|
477 theFs.Connect(); |
|
478 TInt rc = theFs.Att(_L("c:\\TFData1\\testfile1.txt"), dummy); |
|
479 if(rc != KErrNotFound) |
|
480 { |
|
481 ERR_PRINTF1(_L("CTestUtils : run_utils delete failed, file still exists")); |
|
482 theFs.Close(); |
|
483 return iTestStepResult = EFail; |
|
484 } |
|
485 |
|
486 theFs.Close(); |
|
487 return iTestStepResult = currentVerdict; // should be EPass if we've got here |
|
488 } |
|
489 |
|
490 // ---------------------- |
|
491 // RTestMmTsthU1306 |
|
492 |
|
493 RTestMmTsthU1306* RTestMmTsthU1306::NewL() |
|
494 { |
|
495 RTestMmTsthU1306* self = new(ELeave) RTestMmTsthU1306; |
|
496 return self; |
|
497 } |
|
498 |
|
499 // Each test step initialises its own name. |
|
500 RTestMmTsthU1306::RTestMmTsthU1306() |
|
501 { |
|
502 iTestStepName = _L("MM-TSTH-U-1306"); |
|
503 } |
|
504 |
|
505 // preamble |
|
506 TVerdict RTestMmTsthU1306::OpenL() |
|
507 { |
|
508 // do the standard preamble |
|
509 TVerdict currentVerdict = RTSUMmTsthStep13::OpenL(); |
|
510 if(currentVerdict != EPass) |
|
511 return currentVerdict; |
|
512 |
|
513 // do extra, to set up the files/directories we need, which are :- |
|
514 // C:\\TFData2 must exist |
|
515 |
|
516 RFs theFs; |
|
517 theFs.Connect(); |
|
518 |
|
519 TFileName theDirName = _L("c:\\TFData2\\"); |
|
520 TInt rc = theFs.MkDir(theDirName); |
|
521 if (rc != KErrNone && rc != KErrAlreadyExists) |
|
522 { |
|
523 ERR_PRINTF2(_L("Preamble failed RFs::MkDir() error code %d"), rc); |
|
524 theFs.Close(); |
|
525 return iTestStepResult = EFail; |
|
526 } |
|
527 |
|
528 theFs.Close(); |
|
529 return iTestStepResult = currentVerdict; |
|
530 } |
|
531 |
|
532 // postamble |
|
533 void RTestMmTsthU1306::Close() |
|
534 { |
|
535 // clean up the extra files / directories we created |
|
536 CleanupFileSystem(); |
|
537 |
|
538 // do the standard postamble |
|
539 RTSUMmTsthStep13::Close(); |
|
540 } |
|
541 |
|
542 // do the test step. |
|
543 TVerdict RTestMmTsthU1306::DoTestStepL() |
|
544 { |
|
545 |
|
546 INFO_PRINTF1(_L("This test step is not available on EKA2 - Passing test!")); |
|
547 return EPass; |
|
548 |
|
549 } |
|
550 |
|
551 // -------------------- |
|
552 // RTestMmTsthU1311 |
|
553 |
|
554 RTestMmTsthU1311* RTestMmTsthU1311::NewL() |
|
555 { |
|
556 RTestMmTsthU1311* self = new(ELeave) RTestMmTsthU1311; |
|
557 return self; |
|
558 } |
|
559 |
|
560 // Each test step initialises its own name. |
|
561 RTestMmTsthU1311::RTestMmTsthU1311() |
|
562 { |
|
563 iTestStepName = _L("MM-TSTH-U-1311"); |
|
564 } |
|
565 |
|
566 // do the test step |
|
567 TVerdict RTestMmTsthU1311::DoTestStepL() |
|
568 { |
|
569 // to demonstrate that bad syntax does not panic |
|
570 INFO_PRINTF1(_L("Unit test for TestUtils : RunUtils - bad syntax")); |
|
571 |
|
572 TVerdict currentVerdict = EPass; |
|
573 |
|
574 iTestUtils->RunUtils(_L("run_utils gobbledygook")); |
|
575 INFO_PRINTF1(_L("RunUtils did not panic")); |
|
576 |
|
577 return iTestStepResult = currentVerdict; // should be EPass if we've got here |
|
578 } |
|
579 |
|
580 // -------------------- |