1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/mmtestenv/mmtestfwunittest/src/tsu_mmtsth13/TSU_MmTsth13.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,580 @@
1.4 +// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// This file contains the test steps for Unit Test Suite 13 : TestUtils.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +// EPOC includes
1.22 +#include <e32base.h>
1.23 +
1.24 +// Test system includes
1.25 +#include <testframework.h>
1.26 +
1.27 +// Specific includes for this test suite
1.28 +#include "TSU_MmTsthStep13.h"
1.29 +#include "TSU_MmTsthSuite13.h"
1.30 +
1.31 +// Specific includes for these test steps
1.32 +#include "TSU_MmTsth13.h"
1.33 +
1.34 +// --------------------------------------------
1.35 +
1.36 +// Unit Test Suite 13 : TestUtils.cpp
1.37 +// Depends on : none
1.38 +
1.39 +// Tests :-
1.40 +// 1. NewL / Construct - create with a CLog;
1.41 +// RunUtils / RunUtilsL - script-line format testing :-
1.42 +// 2 Copy File
1.43 +// 3 Make Dir.
1.44 +// 4 Change Dir.
1.45 +// 5 Make Read/Write
1.46 +// 6 Delete File
1.47 +// 11 Syntax error (demonstrate no panic)
1.48 +
1.49 +// NB! Test Utils in themselves are not test steps, and do NOT run in their own thread
1.50 +
1.51 +// ------------------------
1.52 +// RTestMmTsthU1301
1.53 +
1.54 +RTestMmTsthU1301* RTestMmTsthU1301::NewL()
1.55 + {
1.56 + RTestMmTsthU1301* self = new(ELeave) RTestMmTsthU1301;
1.57 + return self;
1.58 + }
1.59 +
1.60 +// Each test step initialises its own name.
1.61 +RTestMmTsthU1301::RTestMmTsthU1301()
1.62 + {
1.63 + iTestStepName = _L("MM-TSTH-U-1301");
1.64 + }
1.65 +
1.66 +// preamble
1.67 +TVerdict RTestMmTsthU1301::OpenL()
1.68 + {
1.69 + // stub - purpose is that for this test we do not run the parent preamble
1.70 + // which initialises iTestUtils
1.71 + return iTestStepResult = EPass;
1.72 + }
1.73 +
1.74 +// postamble
1.75 +void RTestMmTsthU1301::Close()
1.76 + {
1.77 + }
1.78 +
1.79 +// do the test step
1.80 +TVerdict RTestMmTsthU1301::DoTestStepL()
1.81 + {
1.82 + // NB CTestUtils does not report errors, but it DOES log them.
1.83 +
1.84 + // NB a single run of TestFrameworkMain can only have ONE log file open at the server.
1.85 + // Hence we must use that one.
1.86 +
1.87 + TVerdict currentVerdict = EPass;
1.88 +
1.89 + INFO_PRINTF1(_L("Unit test for TestUtils : Construct"));
1.90 +
1.91 + CLog* theLog = iSuite->LogSystem(); // use the current log
1.92 + CTestUtils* theTestUtils = NULL;
1.93 + TRAPD(err, theTestUtils = CTestUtils::NewL(theLog));
1.94 + if(err != KErrNone)
1.95 + {
1.96 + ERR_PRINTF2(_L("CTestUtils::NewL() failed with error code %d"), err);
1.97 + return iTestStepResult = EFail;
1.98 + }
1.99 +
1.100 + delete theTestUtils;
1.101 +
1.102 + return iTestStepResult = currentVerdict; // should be EPass if we've got here
1.103 + }
1.104 +
1.105 +// ------------------------
1.106 +// RTestMmTsthU1302
1.107 +
1.108 +RTestMmTsthU1302* RTestMmTsthU1302::NewL()
1.109 + {
1.110 + RTestMmTsthU1302* self = new(ELeave) RTestMmTsthU1302;
1.111 + return self;
1.112 + }
1.113 +
1.114 +// Each test step initialises its own name.
1.115 +RTestMmTsthU1302::RTestMmTsthU1302()
1.116 + {
1.117 + iTestStepName = _L("MM-TSTH-U-1302");
1.118 + }
1.119 +
1.120 +
1.121 +// preamble
1.122 +TVerdict RTestMmTsthU1302::OpenL()
1.123 + {
1.124 + // do the standard preamble
1.125 + TVerdict currentVerdict = RTSUMmTsthStep13::OpenL();
1.126 + if(currentVerdict != EPass)
1.127 + return currentVerdict;
1.128 +
1.129 + // do extra, to set up the files/directories we need, which are :-
1.130 + // C:\\TFData1\\testfile1.txt must exist
1.131 + // C:\\TFData2 must exist
1.132 +
1.133 + RFs theFs;
1.134 + theFs.Connect();
1.135 + RFile theFile;
1.136 +
1.137 + TFileName theDirName = _L("c:\\TFData1\\");
1.138 + TFileName theFileName = _L("c:\\TFData1\\testfile1.txt");
1.139 + TInt rc = theFs.MkDir(theDirName);
1.140 + if (rc != KErrNone && rc != KErrAlreadyExists)
1.141 + {
1.142 + ERR_PRINTF2(_L("Preamble failed RFs::MkDir() error code %d"), rc);
1.143 + theFs.Close();
1.144 + return iTestStepResult = EFail;
1.145 + }
1.146 + rc = theFile.Replace(theFs, theFileName, EFileWrite | EFileStreamText);
1.147 +
1.148 + // check if open fails
1.149 + if (rc == KErrNone)
1.150 + {
1.151 + theFile.Write(_L8("This is a test file for MM_TSTH_U_1302\n"));
1.152 + theFile.Close();
1.153 + }
1.154 + else
1.155 + {
1.156 + ERR_PRINTF2(_L("Preamble failed RFile::Write() error code %d"), rc);
1.157 + theFs.Close();
1.158 + return iTestStepResult = EFail;
1.159 + }
1.160 +
1.161 + theDirName = _L("c:\\TFData2\\");
1.162 + rc = theFs.MkDir(theDirName);
1.163 + if (rc != KErrNone && rc != KErrAlreadyExists)
1.164 + {
1.165 + ERR_PRINTF2(_L("Preamble failed RFs::MkDir() error code %d"), rc);
1.166 + theFs.Close();
1.167 + return iTestStepResult = EFail;
1.168 + }
1.169 +
1.170 + theFs.Close();
1.171 + return iTestStepResult = currentVerdict;
1.172 + }
1.173 +
1.174 +// postamble
1.175 +void RTestMmTsthU1302::Close()
1.176 + {
1.177 + // clean up the extra files / directories we created
1.178 + CleanupFileSystem();
1.179 +
1.180 + // do the standard postamble
1.181 + RTSUMmTsthStep13::Close();
1.182 + }
1.183 +
1.184 +// do the test step
1.185 +TVerdict RTestMmTsthU1302::DoTestStepL()
1.186 + {
1.187 + INFO_PRINTF1(_L("Unit test for TestUtils : RunUtils - CopyFile"));
1.188 +
1.189 + TVerdict currentVerdict = EPass;
1.190 +
1.191 + iTestUtils->RunUtils(_L("run_utils copyfile c:\\TFData1\\testfile1.txt c:\\TFData2\\testfile2.txt"));
1.192 +
1.193 + // check that testfile2.txt exists
1.194 + TUint dummy;
1.195 + RFs theFs;
1.196 + theFs.Connect();
1.197 + TInt rc = theFs.Att(_L("c:\\TFData2\\testfile2.txt"), dummy);
1.198 + if(rc != KErrNone)
1.199 + {
1.200 + ERR_PRINTF2(_L("CTestUtils : run_utils copyfile failed, error %d"), rc);
1.201 + theFs.Close();
1.202 + return iTestStepResult = EFail;
1.203 + }
1.204 +
1.205 + // cleanup
1.206 + theFs.Close();
1.207 + return iTestStepResult = currentVerdict; // should be EPass if we've got here
1.208 + }
1.209 +
1.210 +// --------------------
1.211 +// RTestMmTsthU1303
1.212 +
1.213 +RTestMmTsthU1303* RTestMmTsthU1303::NewL()
1.214 + {
1.215 + RTestMmTsthU1303* self = new(ELeave) RTestMmTsthU1303;
1.216 + return self;
1.217 + }
1.218 +
1.219 +// Each test step initialises its own name.
1.220 +RTestMmTsthU1303::RTestMmTsthU1303()
1.221 + {
1.222 + // store the name of this test case
1.223 + // this is the name that is used by the script file
1.224 + iTestStepName = _L("MM-TSTH-U-1303");
1.225 + }
1.226 +
1.227 +// preamble
1.228 +TVerdict RTestMmTsthU1303::OpenL()
1.229 + {
1.230 + // do the standard preamble
1.231 + TVerdict currentVerdict = RTSUMmTsthStep13::OpenL();
1.232 + if(currentVerdict != EPass)
1.233 + return currentVerdict;
1.234 +
1.235 + // do extra, to set up the files/directories we need, which are :-
1.236 + // C:\\TFData2 must not exist
1.237 +
1.238 + RFs theFs;
1.239 + CFileMan* theFm = NULL;
1.240 + theFs.Connect();
1.241 + TRAPD(err, theFm = CFileMan::NewL(theFs));
1.242 + if(err != KErrNone)
1.243 + {
1.244 + ERR_PRINTF2(_L("Cannot create CFileMan, error code %d"), err);
1.245 + theFs.Close();
1.246 + return iTestStepResult = EFail;
1.247 + }
1.248 +
1.249 + TInt rc = theFm->RmDir(_L("c:\\TFData2\\"));
1.250 + if (rc != KErrNone && rc != KErrPathNotFound)
1.251 + {
1.252 + ERR_PRINTF2(_L("Preamble failed CFileMan::RmDir() error code %d"), rc);
1.253 + currentVerdict = EFail;
1.254 + }
1.255 +
1.256 + theFs.Close();
1.257 + delete theFm;
1.258 + return iTestStepResult = currentVerdict;
1.259 + }
1.260 +
1.261 +// postamble
1.262 +void RTestMmTsthU1303::Close()
1.263 + {
1.264 + // clean up the extra files / directories we created
1.265 + CleanupFileSystem();
1.266 +
1.267 + // do the standard postamble
1.268 + RTSUMmTsthStep13::Close();
1.269 + }
1.270 +
1.271 +// do the test step.
1.272 +TVerdict RTestMmTsthU1303::DoTestStepL()
1.273 + {
1.274 + INFO_PRINTF1(_L("Unit test for TestUtils : RunUtils - MkDir"));
1.275 +
1.276 + TVerdict currentVerdict = EPass;
1.277 +
1.278 + iTestUtils->RunUtils(_L("run_utils mkdir c:\\TFData2\\"));
1.279 +
1.280 + // check that TFData2 exists
1.281 + TUint dummy;
1.282 + RFs theFs;
1.283 + theFs.Connect();
1.284 + TInt rc = theFs.Att(_L("c:\\TFData2\\"), dummy);
1.285 + if(rc != KErrNone)
1.286 + {
1.287 + ERR_PRINTF2(_L("CTestUtils : run_utils mkdir failed, error %d"), rc);
1.288 + theFs.Close();
1.289 + return iTestStepResult = EFail;
1.290 + }
1.291 +
1.292 + theFs.Close();
1.293 + return iTestStepResult = currentVerdict; // should be EPass if we've got here
1.294 + }
1.295 +
1.296 +// --------------------
1.297 +// RTestMmTsthU1304
1.298 +RTestMmTsthU1304* RTestMmTsthU1304::NewL()
1.299 + {
1.300 + RTestMmTsthU1304* self = new(ELeave) RTestMmTsthU1304;
1.301 + return self;
1.302 + }
1.303 +
1.304 +// Each test step initialises its own name.
1.305 +RTestMmTsthU1304::RTestMmTsthU1304()
1.306 + {
1.307 + iTestStepName = _L("MM-TSTH-U-1304");
1.308 + }
1.309 +
1.310 +// preamble
1.311 +TVerdict RTestMmTsthU1304::OpenL()
1.312 + {
1.313 + // do the standard preamble
1.314 + TVerdict currentVerdict = RTSUMmTsthStep13::OpenL();
1.315 + if(currentVerdict != EPass)
1.316 + return currentVerdict;
1.317 +
1.318 + // do extra, to set up the files/directories we need, which are :-
1.319 + // C:\\TFData1\\testfile1.txt must exist and be read-only
1.320 +
1.321 + RFs theFs;
1.322 + theFs.Connect();
1.323 + RFile theFile;
1.324 +
1.325 + TFileName theDirName = _L("c:\\TFData1\\");
1.326 + TFileName theFileName = _L("c:\\TFData1\\testfile1.txt");
1.327 + TInt rc = theFs.MkDir(theDirName);
1.328 + if (rc != KErrNone && rc != KErrAlreadyExists)
1.329 + {
1.330 + ERR_PRINTF2(_L("Preamble failed RFs::MkDir() error code %d"), rc);
1.331 + theFs.Close();
1.332 + return iTestStepResult = EFail;
1.333 + }
1.334 + rc = theFile.Replace(theFs, theFileName, EFileWrite | EFileStreamText);
1.335 +
1.336 + // check if open fails
1.337 + if (rc == KErrNone)
1.338 + {
1.339 + theFile.Write(_L8("This is a test file for MM_TSTH_U_1304\n"));
1.340 + theFile.Close();
1.341 + }
1.342 + else
1.343 + {
1.344 + ERR_PRINTF2(_L("Preamble failed RFile::Replace() error code %d"), rc);
1.345 + theFs.Close();
1.346 + return iTestStepResult = EFail;
1.347 + }
1.348 +
1.349 + // set read-only
1.350 + rc = theFs.SetAtt(theFileName, KEntryAttReadOnly, 0);
1.351 +
1.352 + theFs.Close();
1.353 + return iTestStepResult = currentVerdict;
1.354 + }
1.355 +
1.356 +// postamble
1.357 +void RTestMmTsthU1304::Close()
1.358 + {
1.359 + // set the file read-write for deletion
1.360 + RFs theFs;
1.361 + theFs.Connect();
1.362 + TFileName theFileName = _L("c:\\TFData1\\testfile1.txt");
1.363 + theFs.SetAtt(theFileName, 0, KEntryAttReadOnly);
1.364 + theFs.Close();
1.365 +
1.366 + // clean up the extra files / directories we created
1.367 + CleanupFileSystem();
1.368 +
1.369 + // do the standard postamble
1.370 + RTSUMmTsthStep13::Close();
1.371 + }
1.372 +
1.373 +// do the test step
1.374 +TVerdict RTestMmTsthU1304::DoTestStepL()
1.375 + {
1.376 + INFO_PRINTF1(_L("Unit test for TestUtils : RunUtils - MakeReadWrite"));
1.377 +
1.378 + TVerdict currentVerdict = EPass;
1.379 +
1.380 + iTestUtils->RunUtils(_L("run_utils makereadwrite c:\\TFData1\\testfile1.txt"));
1.381 +
1.382 + // check that file exists and is read-only
1.383 + TUint theAtts;
1.384 + RFs theFs;
1.385 + theFs.Connect();
1.386 + theFs.Att(_L("c:\\TFData1\\testfile1.txt"), theAtts);
1.387 + if(theAtts & KEntryAttReadOnly)
1.388 + {
1.389 + ERR_PRINTF1(_L("CTestUtils : run_utils makereadwrite failed, file is still read-only"));
1.390 + theFs.Close();
1.391 + return iTestStepResult = EFail;
1.392 + }
1.393 +
1.394 + theFs.Close();
1.395 + return iTestStepResult = currentVerdict; // should be EPass if we've got here
1.396 + }
1.397 +
1.398 +// --------------------
1.399 +// RTestMmTsthU1305
1.400 +RTestMmTsthU1305* RTestMmTsthU1305::NewL()
1.401 + {
1.402 + RTestMmTsthU1305* self = new(ELeave) RTestMmTsthU1305;
1.403 + return self;
1.404 + }
1.405 +
1.406 +// Each test step initialises its own name.
1.407 +RTestMmTsthU1305::RTestMmTsthU1305()
1.408 + {
1.409 + iTestStepName = _L("MM-TSTH-U-1305");
1.410 + }
1.411 +
1.412 +// preamble
1.413 +TVerdict RTestMmTsthU1305::OpenL()
1.414 + {
1.415 + // do the standard preamble
1.416 + TVerdict currentVerdict = RTSUMmTsthStep13::OpenL();
1.417 + if(currentVerdict != EPass)
1.418 + return currentVerdict;
1.419 +
1.420 + // do extra, to set up the files/directories we need, which are :-
1.421 + // C:\\TFData1\\testfile1.txt must exist and be read-write
1.422 +
1.423 + RFs theFs;
1.424 + theFs.Connect();
1.425 + RFile theFile;
1.426 +
1.427 + TFileName theDirName = _L("c:\\TFData1\\");
1.428 + TFileName theFileName = _L("c:\\TFData1\\testfile1.txt");
1.429 + TInt rc = theFs.MkDir(theDirName);
1.430 + if (rc != KErrNone && rc != KErrAlreadyExists)
1.431 + {
1.432 + ERR_PRINTF2(_L("Preamble failed RFs::MkDir() error code %d"), rc);
1.433 + theFs.Close();
1.434 + return iTestStepResult = EFail;
1.435 + }
1.436 + rc = theFile.Replace(theFs, theFileName, EFileWrite | EFileStreamText);
1.437 +
1.438 + // check if open fails
1.439 + if (rc == KErrNone)
1.440 + {
1.441 + theFile.Write(_L8("This is a test file for MM_TSTH_U_1305\n"));
1.442 + theFile.Close();
1.443 + }
1.444 + else
1.445 + {
1.446 + ERR_PRINTF2(_L("Preamble failed RFile::Replace() error code %d"), rc);
1.447 + theFs.Close();
1.448 + return iTestStepResult = EFail;
1.449 + }
1.450 +
1.451 + // set read-write
1.452 + rc = theFs.SetAtt(theFileName, 0, KEntryAttReadOnly);
1.453 +
1.454 + theFs.Close();
1.455 + return iTestStepResult = currentVerdict;
1.456 + }
1.457 +
1.458 +// postamble
1.459 +void RTestMmTsthU1305::Close()
1.460 + {
1.461 + // clean up the extra files / directories we created
1.462 + CleanupFileSystem();
1.463 +
1.464 + // do the standard postamble
1.465 + RTSUMmTsthStep13::Close();
1.466 + }
1.467 +
1.468 +// do the test step
1.469 +TVerdict RTestMmTsthU1305::DoTestStepL()
1.470 + {
1.471 + INFO_PRINTF1(_L("Unit test for TestUtils : RunUtils - Delete"));
1.472 +
1.473 + TVerdict currentVerdict = EPass;
1.474 +
1.475 + iTestUtils->RunUtils(_L("run_utils delete c:\\TFData1\\testfile1.txt"));
1.476 +
1.477 + // check that file does not exist
1.478 + TUint dummy;
1.479 + RFs theFs;
1.480 + theFs.Connect();
1.481 + TInt rc = theFs.Att(_L("c:\\TFData1\\testfile1.txt"), dummy);
1.482 + if(rc != KErrNotFound)
1.483 + {
1.484 + ERR_PRINTF1(_L("CTestUtils : run_utils delete failed, file still exists"));
1.485 + theFs.Close();
1.486 + return iTestStepResult = EFail;
1.487 + }
1.488 +
1.489 + theFs.Close();
1.490 + return iTestStepResult = currentVerdict; // should be EPass if we've got here
1.491 + }
1.492 +
1.493 +// ----------------------
1.494 +// RTestMmTsthU1306
1.495 +
1.496 +RTestMmTsthU1306* RTestMmTsthU1306::NewL()
1.497 + {
1.498 + RTestMmTsthU1306* self = new(ELeave) RTestMmTsthU1306;
1.499 + return self;
1.500 + }
1.501 +
1.502 +// Each test step initialises its own name.
1.503 +RTestMmTsthU1306::RTestMmTsthU1306()
1.504 + {
1.505 + iTestStepName = _L("MM-TSTH-U-1306");
1.506 + }
1.507 +
1.508 +// preamble
1.509 +TVerdict RTestMmTsthU1306::OpenL()
1.510 + {
1.511 + // do the standard preamble
1.512 + TVerdict currentVerdict = RTSUMmTsthStep13::OpenL();
1.513 + if(currentVerdict != EPass)
1.514 + return currentVerdict;
1.515 +
1.516 + // do extra, to set up the files/directories we need, which are :-
1.517 + // C:\\TFData2 must exist
1.518 +
1.519 + RFs theFs;
1.520 + theFs.Connect();
1.521 +
1.522 + TFileName theDirName = _L("c:\\TFData2\\");
1.523 + TInt rc = theFs.MkDir(theDirName);
1.524 + if (rc != KErrNone && rc != KErrAlreadyExists)
1.525 + {
1.526 + ERR_PRINTF2(_L("Preamble failed RFs::MkDir() error code %d"), rc);
1.527 + theFs.Close();
1.528 + return iTestStepResult = EFail;
1.529 + }
1.530 +
1.531 + theFs.Close();
1.532 + return iTestStepResult = currentVerdict;
1.533 + }
1.534 +
1.535 +// postamble
1.536 +void RTestMmTsthU1306::Close()
1.537 + {
1.538 + // clean up the extra files / directories we created
1.539 + CleanupFileSystem();
1.540 +
1.541 + // do the standard postamble
1.542 + RTSUMmTsthStep13::Close();
1.543 + }
1.544 +
1.545 +// do the test step.
1.546 +TVerdict RTestMmTsthU1306::DoTestStepL()
1.547 + {
1.548 +
1.549 + INFO_PRINTF1(_L("This test step is not available on EKA2 - Passing test!"));
1.550 + return EPass;
1.551 +
1.552 + }
1.553 +
1.554 +// --------------------
1.555 +// RTestMmTsthU1311
1.556 +
1.557 +RTestMmTsthU1311* RTestMmTsthU1311::NewL()
1.558 + {
1.559 + RTestMmTsthU1311* self = new(ELeave) RTestMmTsthU1311;
1.560 + return self;
1.561 + }
1.562 +
1.563 +// Each test step initialises its own name.
1.564 +RTestMmTsthU1311::RTestMmTsthU1311()
1.565 + {
1.566 + iTestStepName = _L("MM-TSTH-U-1311");
1.567 + }
1.568 +
1.569 +// do the test step
1.570 +TVerdict RTestMmTsthU1311::DoTestStepL()
1.571 + {
1.572 + // to demonstrate that bad syntax does not panic
1.573 + INFO_PRINTF1(_L("Unit test for TestUtils : RunUtils - bad syntax"));
1.574 +
1.575 + TVerdict currentVerdict = EPass;
1.576 +
1.577 + iTestUtils->RunUtils(_L("run_utils gobbledygook"));
1.578 + INFO_PRINTF1(_L("RunUtils did not panic"));
1.579 +
1.580 + return iTestStepResult = currentVerdict; // should be EPass if we've got here
1.581 + }
1.582 +
1.583 +// --------------------