Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // This file contains the test steps for Unit Test Suite 13 : TestUtils.cpp
21 // Test system includes
22 #include <testframework.h>
24 // Specific includes for this test suite
25 #include "TSU_MmTsthStep13.h"
26 #include "TSU_MmTsthSuite13.h"
28 // Specific includes for these test steps
29 #include "TSU_MmTsth13.h"
31 // --------------------------------------------
33 // Unit Test Suite 13 : TestUtils.cpp
37 // 1. NewL / Construct - create with a CLog;
38 // RunUtils / RunUtilsL - script-line format testing :-
44 // 11 Syntax error (demonstrate no panic)
46 // NB! Test Utils in themselves are not test steps, and do NOT run in their own thread
48 // ------------------------
51 RTestMmTsthU1301* RTestMmTsthU1301::NewL()
53 RTestMmTsthU1301* self = new(ELeave) RTestMmTsthU1301;
57 // Each test step initialises its own name.
58 RTestMmTsthU1301::RTestMmTsthU1301()
60 iTestStepName = _L("MM-TSTH-U-1301");
64 TVerdict RTestMmTsthU1301::OpenL()
66 // stub - purpose is that for this test we do not run the parent preamble
67 // which initialises iTestUtils
68 return iTestStepResult = EPass;
72 void RTestMmTsthU1301::Close()
77 TVerdict RTestMmTsthU1301::DoTestStepL()
79 // NB CTestUtils does not report errors, but it DOES log them.
81 // NB a single run of TestFrameworkMain can only have ONE log file open at the server.
82 // Hence we must use that one.
84 TVerdict currentVerdict = EPass;
86 INFO_PRINTF1(_L("Unit test for TestUtils : Construct"));
88 CLog* theLog = iSuite->LogSystem(); // use the current log
89 CTestUtils* theTestUtils = NULL;
90 TRAPD(err, theTestUtils = CTestUtils::NewL(theLog));
93 ERR_PRINTF2(_L("CTestUtils::NewL() failed with error code %d"), err);
94 return iTestStepResult = EFail;
99 return iTestStepResult = currentVerdict; // should be EPass if we've got here
102 // ------------------------
105 RTestMmTsthU1302* RTestMmTsthU1302::NewL()
107 RTestMmTsthU1302* self = new(ELeave) RTestMmTsthU1302;
111 // Each test step initialises its own name.
112 RTestMmTsthU1302::RTestMmTsthU1302()
114 iTestStepName = _L("MM-TSTH-U-1302");
119 TVerdict RTestMmTsthU1302::OpenL()
121 // do the standard preamble
122 TVerdict currentVerdict = RTSUMmTsthStep13::OpenL();
123 if(currentVerdict != EPass)
124 return currentVerdict;
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
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)
139 ERR_PRINTF2(_L("Preamble failed RFs::MkDir() error code %d"), rc);
141 return iTestStepResult = EFail;
143 rc = theFile.Replace(theFs, theFileName, EFileWrite | EFileStreamText);
145 // check if open fails
148 theFile.Write(_L8("This is a test file for MM_TSTH_U_1302\n"));
153 ERR_PRINTF2(_L("Preamble failed RFile::Write() error code %d"), rc);
155 return iTestStepResult = EFail;
158 theDirName = _L("c:\\TFData2\\");
159 rc = theFs.MkDir(theDirName);
160 if (rc != KErrNone && rc != KErrAlreadyExists)
162 ERR_PRINTF2(_L("Preamble failed RFs::MkDir() error code %d"), rc);
164 return iTestStepResult = EFail;
168 return iTestStepResult = currentVerdict;
172 void RTestMmTsthU1302::Close()
174 // clean up the extra files / directories we created
177 // do the standard postamble
178 RTSUMmTsthStep13::Close();
182 TVerdict RTestMmTsthU1302::DoTestStepL()
184 INFO_PRINTF1(_L("Unit test for TestUtils : RunUtils - CopyFile"));
186 TVerdict currentVerdict = EPass;
188 iTestUtils->RunUtils(_L("run_utils copyfile c:\\TFData1\\testfile1.txt c:\\TFData2\\testfile2.txt"));
190 // check that testfile2.txt exists
194 TInt rc = theFs.Att(_L("c:\\TFData2\\testfile2.txt"), dummy);
197 ERR_PRINTF2(_L("CTestUtils : run_utils copyfile failed, error %d"), rc);
199 return iTestStepResult = EFail;
204 return iTestStepResult = currentVerdict; // should be EPass if we've got here
207 // --------------------
210 RTestMmTsthU1303* RTestMmTsthU1303::NewL()
212 RTestMmTsthU1303* self = new(ELeave) RTestMmTsthU1303;
216 // Each test step initialises its own name.
217 RTestMmTsthU1303::RTestMmTsthU1303()
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");
225 TVerdict RTestMmTsthU1303::OpenL()
227 // do the standard preamble
228 TVerdict currentVerdict = RTSUMmTsthStep13::OpenL();
229 if(currentVerdict != EPass)
230 return currentVerdict;
232 // do extra, to set up the files/directories we need, which are :-
233 // C:\\TFData2 must not exist
236 CFileMan* theFm = NULL;
238 TRAPD(err, theFm = CFileMan::NewL(theFs));
241 ERR_PRINTF2(_L("Cannot create CFileMan, error code %d"), err);
243 return iTestStepResult = EFail;
246 TInt rc = theFm->RmDir(_L("c:\\TFData2\\"));
247 if (rc != KErrNone && rc != KErrPathNotFound)
249 ERR_PRINTF2(_L("Preamble failed CFileMan::RmDir() error code %d"), rc);
250 currentVerdict = EFail;
255 return iTestStepResult = currentVerdict;
259 void RTestMmTsthU1303::Close()
261 // clean up the extra files / directories we created
264 // do the standard postamble
265 RTSUMmTsthStep13::Close();
269 TVerdict RTestMmTsthU1303::DoTestStepL()
271 INFO_PRINTF1(_L("Unit test for TestUtils : RunUtils - MkDir"));
273 TVerdict currentVerdict = EPass;
275 iTestUtils->RunUtils(_L("run_utils mkdir c:\\TFData2\\"));
277 // check that TFData2 exists
281 TInt rc = theFs.Att(_L("c:\\TFData2\\"), dummy);
284 ERR_PRINTF2(_L("CTestUtils : run_utils mkdir failed, error %d"), rc);
286 return iTestStepResult = EFail;
290 return iTestStepResult = currentVerdict; // should be EPass if we've got here
293 // --------------------
295 RTestMmTsthU1304* RTestMmTsthU1304::NewL()
297 RTestMmTsthU1304* self = new(ELeave) RTestMmTsthU1304;
301 // Each test step initialises its own name.
302 RTestMmTsthU1304::RTestMmTsthU1304()
304 iTestStepName = _L("MM-TSTH-U-1304");
308 TVerdict RTestMmTsthU1304::OpenL()
310 // do the standard preamble
311 TVerdict currentVerdict = RTSUMmTsthStep13::OpenL();
312 if(currentVerdict != EPass)
313 return currentVerdict;
315 // do extra, to set up the files/directories we need, which are :-
316 // C:\\TFData1\\testfile1.txt must exist and be read-only
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)
327 ERR_PRINTF2(_L("Preamble failed RFs::MkDir() error code %d"), rc);
329 return iTestStepResult = EFail;
331 rc = theFile.Replace(theFs, theFileName, EFileWrite | EFileStreamText);
333 // check if open fails
336 theFile.Write(_L8("This is a test file for MM_TSTH_U_1304\n"));
341 ERR_PRINTF2(_L("Preamble failed RFile::Replace() error code %d"), rc);
343 return iTestStepResult = EFail;
347 rc = theFs.SetAtt(theFileName, KEntryAttReadOnly, 0);
350 return iTestStepResult = currentVerdict;
354 void RTestMmTsthU1304::Close()
356 // set the file read-write for deletion
359 TFileName theFileName = _L("c:\\TFData1\\testfile1.txt");
360 theFs.SetAtt(theFileName, 0, KEntryAttReadOnly);
363 // clean up the extra files / directories we created
366 // do the standard postamble
367 RTSUMmTsthStep13::Close();
371 TVerdict RTestMmTsthU1304::DoTestStepL()
373 INFO_PRINTF1(_L("Unit test for TestUtils : RunUtils - MakeReadWrite"));
375 TVerdict currentVerdict = EPass;
377 iTestUtils->RunUtils(_L("run_utils makereadwrite c:\\TFData1\\testfile1.txt"));
379 // check that file exists and is read-only
383 theFs.Att(_L("c:\\TFData1\\testfile1.txt"), theAtts);
384 if(theAtts & KEntryAttReadOnly)
386 ERR_PRINTF1(_L("CTestUtils : run_utils makereadwrite failed, file is still read-only"));
388 return iTestStepResult = EFail;
392 return iTestStepResult = currentVerdict; // should be EPass if we've got here
395 // --------------------
397 RTestMmTsthU1305* RTestMmTsthU1305::NewL()
399 RTestMmTsthU1305* self = new(ELeave) RTestMmTsthU1305;
403 // Each test step initialises its own name.
404 RTestMmTsthU1305::RTestMmTsthU1305()
406 iTestStepName = _L("MM-TSTH-U-1305");
410 TVerdict RTestMmTsthU1305::OpenL()
412 // do the standard preamble
413 TVerdict currentVerdict = RTSUMmTsthStep13::OpenL();
414 if(currentVerdict != EPass)
415 return currentVerdict;
417 // do extra, to set up the files/directories we need, which are :-
418 // C:\\TFData1\\testfile1.txt must exist and be read-write
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)
429 ERR_PRINTF2(_L("Preamble failed RFs::MkDir() error code %d"), rc);
431 return iTestStepResult = EFail;
433 rc = theFile.Replace(theFs, theFileName, EFileWrite | EFileStreamText);
435 // check if open fails
438 theFile.Write(_L8("This is a test file for MM_TSTH_U_1305\n"));
443 ERR_PRINTF2(_L("Preamble failed RFile::Replace() error code %d"), rc);
445 return iTestStepResult = EFail;
449 rc = theFs.SetAtt(theFileName, 0, KEntryAttReadOnly);
452 return iTestStepResult = currentVerdict;
456 void RTestMmTsthU1305::Close()
458 // clean up the extra files / directories we created
461 // do the standard postamble
462 RTSUMmTsthStep13::Close();
466 TVerdict RTestMmTsthU1305::DoTestStepL()
468 INFO_PRINTF1(_L("Unit test for TestUtils : RunUtils - Delete"));
470 TVerdict currentVerdict = EPass;
472 iTestUtils->RunUtils(_L("run_utils delete c:\\TFData1\\testfile1.txt"));
474 // check that file does not exist
478 TInt rc = theFs.Att(_L("c:\\TFData1\\testfile1.txt"), dummy);
479 if(rc != KErrNotFound)
481 ERR_PRINTF1(_L("CTestUtils : run_utils delete failed, file still exists"));
483 return iTestStepResult = EFail;
487 return iTestStepResult = currentVerdict; // should be EPass if we've got here
490 // ----------------------
493 RTestMmTsthU1306* RTestMmTsthU1306::NewL()
495 RTestMmTsthU1306* self = new(ELeave) RTestMmTsthU1306;
499 // Each test step initialises its own name.
500 RTestMmTsthU1306::RTestMmTsthU1306()
502 iTestStepName = _L("MM-TSTH-U-1306");
506 TVerdict RTestMmTsthU1306::OpenL()
508 // do the standard preamble
509 TVerdict currentVerdict = RTSUMmTsthStep13::OpenL();
510 if(currentVerdict != EPass)
511 return currentVerdict;
513 // do extra, to set up the files/directories we need, which are :-
514 // C:\\TFData2 must exist
519 TFileName theDirName = _L("c:\\TFData2\\");
520 TInt rc = theFs.MkDir(theDirName);
521 if (rc != KErrNone && rc != KErrAlreadyExists)
523 ERR_PRINTF2(_L("Preamble failed RFs::MkDir() error code %d"), rc);
525 return iTestStepResult = EFail;
529 return iTestStepResult = currentVerdict;
533 void RTestMmTsthU1306::Close()
535 // clean up the extra files / directories we created
538 // do the standard postamble
539 RTSUMmTsthStep13::Close();
543 TVerdict RTestMmTsthU1306::DoTestStepL()
546 INFO_PRINTF1(_L("This test step is not available on EKA2 - Passing test!"));
551 // --------------------
554 RTestMmTsthU1311* RTestMmTsthU1311::NewL()
556 RTestMmTsthU1311* self = new(ELeave) RTestMmTsthU1311;
560 // Each test step initialises its own name.
561 RTestMmTsthU1311::RTestMmTsthU1311()
563 iTestStepName = _L("MM-TSTH-U-1311");
567 TVerdict RTestMmTsthU1311::DoTestStepL()
569 // to demonstrate that bad syntax does not panic
570 INFO_PRINTF1(_L("Unit test for TestUtils : RunUtils - bad syntax"));
572 TVerdict currentVerdict = EPass;
574 iTestUtils->RunUtils(_L("run_utils gobbledygook"));
575 INFO_PRINTF1(_L("RunUtils did not panic"));
577 return iTestStepResult = currentVerdict; // should be EPass if we've got here
580 // --------------------