sl@0: // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // This file contains the test steps for Unit Test Suite 13 : TestUtils.cpp sl@0: // sl@0: // sl@0: sl@0: // EPOC includes sl@0: #include sl@0: sl@0: // Test system includes sl@0: #include sl@0: sl@0: // Specific includes for this test suite sl@0: #include "TSU_MmTsthStep13.h" sl@0: #include "TSU_MmTsthSuite13.h" sl@0: sl@0: // Specific includes for these test steps sl@0: #include "TSU_MmTsth13.h" sl@0: sl@0: // -------------------------------------------- sl@0: sl@0: // Unit Test Suite 13 : TestUtils.cpp sl@0: // Depends on : none sl@0: sl@0: // Tests :- sl@0: // 1. NewL / Construct - create with a CLog; sl@0: // RunUtils / RunUtilsL - script-line format testing :- sl@0: // 2 Copy File sl@0: // 3 Make Dir. sl@0: // 4 Change Dir. sl@0: // 5 Make Read/Write sl@0: // 6 Delete File sl@0: // 11 Syntax error (demonstrate no panic) sl@0: sl@0: // NB! Test Utils in themselves are not test steps, and do NOT run in their own thread sl@0: sl@0: // ------------------------ sl@0: // RTestMmTsthU1301 sl@0: sl@0: RTestMmTsthU1301* RTestMmTsthU1301::NewL() sl@0: { sl@0: RTestMmTsthU1301* self = new(ELeave) RTestMmTsthU1301; sl@0: return self; sl@0: } sl@0: sl@0: // Each test step initialises its own name. sl@0: RTestMmTsthU1301::RTestMmTsthU1301() sl@0: { sl@0: iTestStepName = _L("MM-TSTH-U-1301"); sl@0: } sl@0: sl@0: // preamble sl@0: TVerdict RTestMmTsthU1301::OpenL() sl@0: { sl@0: // stub - purpose is that for this test we do not run the parent preamble sl@0: // which initialises iTestUtils sl@0: return iTestStepResult = EPass; sl@0: } sl@0: sl@0: // postamble sl@0: void RTestMmTsthU1301::Close() sl@0: { sl@0: } sl@0: sl@0: // do the test step sl@0: TVerdict RTestMmTsthU1301::DoTestStepL() sl@0: { sl@0: // NB CTestUtils does not report errors, but it DOES log them. sl@0: sl@0: // NB a single run of TestFrameworkMain can only have ONE log file open at the server. sl@0: // Hence we must use that one. sl@0: sl@0: TVerdict currentVerdict = EPass; sl@0: sl@0: INFO_PRINTF1(_L("Unit test for TestUtils : Construct")); sl@0: sl@0: CLog* theLog = iSuite->LogSystem(); // use the current log sl@0: CTestUtils* theTestUtils = NULL; sl@0: TRAPD(err, theTestUtils = CTestUtils::NewL(theLog)); sl@0: if(err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("CTestUtils::NewL() failed with error code %d"), err); sl@0: return iTestStepResult = EFail; sl@0: } sl@0: sl@0: delete theTestUtils; sl@0: sl@0: return iTestStepResult = currentVerdict; // should be EPass if we've got here sl@0: } sl@0: sl@0: // ------------------------ sl@0: // RTestMmTsthU1302 sl@0: sl@0: RTestMmTsthU1302* RTestMmTsthU1302::NewL() sl@0: { sl@0: RTestMmTsthU1302* self = new(ELeave) RTestMmTsthU1302; sl@0: return self; sl@0: } sl@0: sl@0: // Each test step initialises its own name. sl@0: RTestMmTsthU1302::RTestMmTsthU1302() sl@0: { sl@0: iTestStepName = _L("MM-TSTH-U-1302"); sl@0: } sl@0: sl@0: sl@0: // preamble sl@0: TVerdict RTestMmTsthU1302::OpenL() sl@0: { sl@0: // do the standard preamble sl@0: TVerdict currentVerdict = RTSUMmTsthStep13::OpenL(); sl@0: if(currentVerdict != EPass) sl@0: return currentVerdict; sl@0: sl@0: // do extra, to set up the files/directories we need, which are :- sl@0: // C:\\TFData1\\testfile1.txt must exist sl@0: // C:\\TFData2 must exist sl@0: sl@0: RFs theFs; sl@0: theFs.Connect(); sl@0: RFile theFile; sl@0: sl@0: TFileName theDirName = _L("c:\\TFData1\\"); sl@0: TFileName theFileName = _L("c:\\TFData1\\testfile1.txt"); sl@0: TInt rc = theFs.MkDir(theDirName); sl@0: if (rc != KErrNone && rc != KErrAlreadyExists) sl@0: { sl@0: ERR_PRINTF2(_L("Preamble failed RFs::MkDir() error code %d"), rc); sl@0: theFs.Close(); sl@0: return iTestStepResult = EFail; sl@0: } sl@0: rc = theFile.Replace(theFs, theFileName, EFileWrite | EFileStreamText); sl@0: sl@0: // check if open fails sl@0: if (rc == KErrNone) sl@0: { sl@0: theFile.Write(_L8("This is a test file for MM_TSTH_U_1302\n")); sl@0: theFile.Close(); sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF2(_L("Preamble failed RFile::Write() error code %d"), rc); sl@0: theFs.Close(); sl@0: return iTestStepResult = EFail; sl@0: } sl@0: sl@0: theDirName = _L("c:\\TFData2\\"); sl@0: rc = theFs.MkDir(theDirName); sl@0: if (rc != KErrNone && rc != KErrAlreadyExists) sl@0: { sl@0: ERR_PRINTF2(_L("Preamble failed RFs::MkDir() error code %d"), rc); sl@0: theFs.Close(); sl@0: return iTestStepResult = EFail; sl@0: } sl@0: sl@0: theFs.Close(); sl@0: return iTestStepResult = currentVerdict; sl@0: } sl@0: sl@0: // postamble sl@0: void RTestMmTsthU1302::Close() sl@0: { sl@0: // clean up the extra files / directories we created sl@0: CleanupFileSystem(); sl@0: sl@0: // do the standard postamble sl@0: RTSUMmTsthStep13::Close(); sl@0: } sl@0: sl@0: // do the test step sl@0: TVerdict RTestMmTsthU1302::DoTestStepL() sl@0: { sl@0: INFO_PRINTF1(_L("Unit test for TestUtils : RunUtils - CopyFile")); sl@0: sl@0: TVerdict currentVerdict = EPass; sl@0: sl@0: iTestUtils->RunUtils(_L("run_utils copyfile c:\\TFData1\\testfile1.txt c:\\TFData2\\testfile2.txt")); sl@0: sl@0: // check that testfile2.txt exists sl@0: TUint dummy; sl@0: RFs theFs; sl@0: theFs.Connect(); sl@0: TInt rc = theFs.Att(_L("c:\\TFData2\\testfile2.txt"), dummy); sl@0: if(rc != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("CTestUtils : run_utils copyfile failed, error %d"), rc); sl@0: theFs.Close(); sl@0: return iTestStepResult = EFail; sl@0: } sl@0: sl@0: // cleanup sl@0: theFs.Close(); sl@0: return iTestStepResult = currentVerdict; // should be EPass if we've got here sl@0: } sl@0: sl@0: // -------------------- sl@0: // RTestMmTsthU1303 sl@0: sl@0: RTestMmTsthU1303* RTestMmTsthU1303::NewL() sl@0: { sl@0: RTestMmTsthU1303* self = new(ELeave) RTestMmTsthU1303; sl@0: return self; sl@0: } sl@0: sl@0: // Each test step initialises its own name. sl@0: RTestMmTsthU1303::RTestMmTsthU1303() sl@0: { sl@0: // store the name of this test case sl@0: // this is the name that is used by the script file sl@0: iTestStepName = _L("MM-TSTH-U-1303"); sl@0: } sl@0: sl@0: // preamble sl@0: TVerdict RTestMmTsthU1303::OpenL() sl@0: { sl@0: // do the standard preamble sl@0: TVerdict currentVerdict = RTSUMmTsthStep13::OpenL(); sl@0: if(currentVerdict != EPass) sl@0: return currentVerdict; sl@0: sl@0: // do extra, to set up the files/directories we need, which are :- sl@0: // C:\\TFData2 must not exist sl@0: sl@0: RFs theFs; sl@0: CFileMan* theFm = NULL; sl@0: theFs.Connect(); sl@0: TRAPD(err, theFm = CFileMan::NewL(theFs)); sl@0: if(err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Cannot create CFileMan, error code %d"), err); sl@0: theFs.Close(); sl@0: return iTestStepResult = EFail; sl@0: } sl@0: sl@0: TInt rc = theFm->RmDir(_L("c:\\TFData2\\")); sl@0: if (rc != KErrNone && rc != KErrPathNotFound) sl@0: { sl@0: ERR_PRINTF2(_L("Preamble failed CFileMan::RmDir() error code %d"), rc); sl@0: currentVerdict = EFail; sl@0: } sl@0: sl@0: theFs.Close(); sl@0: delete theFm; sl@0: return iTestStepResult = currentVerdict; sl@0: } sl@0: sl@0: // postamble sl@0: void RTestMmTsthU1303::Close() sl@0: { sl@0: // clean up the extra files / directories we created sl@0: CleanupFileSystem(); sl@0: sl@0: // do the standard postamble sl@0: RTSUMmTsthStep13::Close(); sl@0: } sl@0: sl@0: // do the test step. sl@0: TVerdict RTestMmTsthU1303::DoTestStepL() sl@0: { sl@0: INFO_PRINTF1(_L("Unit test for TestUtils : RunUtils - MkDir")); sl@0: sl@0: TVerdict currentVerdict = EPass; sl@0: sl@0: iTestUtils->RunUtils(_L("run_utils mkdir c:\\TFData2\\")); sl@0: sl@0: // check that TFData2 exists sl@0: TUint dummy; sl@0: RFs theFs; sl@0: theFs.Connect(); sl@0: TInt rc = theFs.Att(_L("c:\\TFData2\\"), dummy); sl@0: if(rc != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("CTestUtils : run_utils mkdir failed, error %d"), rc); sl@0: theFs.Close(); sl@0: return iTestStepResult = EFail; sl@0: } sl@0: sl@0: theFs.Close(); sl@0: return iTestStepResult = currentVerdict; // should be EPass if we've got here sl@0: } sl@0: sl@0: // -------------------- sl@0: // RTestMmTsthU1304 sl@0: RTestMmTsthU1304* RTestMmTsthU1304::NewL() sl@0: { sl@0: RTestMmTsthU1304* self = new(ELeave) RTestMmTsthU1304; sl@0: return self; sl@0: } sl@0: sl@0: // Each test step initialises its own name. sl@0: RTestMmTsthU1304::RTestMmTsthU1304() sl@0: { sl@0: iTestStepName = _L("MM-TSTH-U-1304"); sl@0: } sl@0: sl@0: // preamble sl@0: TVerdict RTestMmTsthU1304::OpenL() sl@0: { sl@0: // do the standard preamble sl@0: TVerdict currentVerdict = RTSUMmTsthStep13::OpenL(); sl@0: if(currentVerdict != EPass) sl@0: return currentVerdict; sl@0: sl@0: // do extra, to set up the files/directories we need, which are :- sl@0: // C:\\TFData1\\testfile1.txt must exist and be read-only sl@0: sl@0: RFs theFs; sl@0: theFs.Connect(); sl@0: RFile theFile; sl@0: sl@0: TFileName theDirName = _L("c:\\TFData1\\"); sl@0: TFileName theFileName = _L("c:\\TFData1\\testfile1.txt"); sl@0: TInt rc = theFs.MkDir(theDirName); sl@0: if (rc != KErrNone && rc != KErrAlreadyExists) sl@0: { sl@0: ERR_PRINTF2(_L("Preamble failed RFs::MkDir() error code %d"), rc); sl@0: theFs.Close(); sl@0: return iTestStepResult = EFail; sl@0: } sl@0: rc = theFile.Replace(theFs, theFileName, EFileWrite | EFileStreamText); sl@0: sl@0: // check if open fails sl@0: if (rc == KErrNone) sl@0: { sl@0: theFile.Write(_L8("This is a test file for MM_TSTH_U_1304\n")); sl@0: theFile.Close(); sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF2(_L("Preamble failed RFile::Replace() error code %d"), rc); sl@0: theFs.Close(); sl@0: return iTestStepResult = EFail; sl@0: } sl@0: sl@0: // set read-only sl@0: rc = theFs.SetAtt(theFileName, KEntryAttReadOnly, 0); sl@0: sl@0: theFs.Close(); sl@0: return iTestStepResult = currentVerdict; sl@0: } sl@0: sl@0: // postamble sl@0: void RTestMmTsthU1304::Close() sl@0: { sl@0: // set the file read-write for deletion sl@0: RFs theFs; sl@0: theFs.Connect(); sl@0: TFileName theFileName = _L("c:\\TFData1\\testfile1.txt"); sl@0: theFs.SetAtt(theFileName, 0, KEntryAttReadOnly); sl@0: theFs.Close(); sl@0: sl@0: // clean up the extra files / directories we created sl@0: CleanupFileSystem(); sl@0: sl@0: // do the standard postamble sl@0: RTSUMmTsthStep13::Close(); sl@0: } sl@0: sl@0: // do the test step sl@0: TVerdict RTestMmTsthU1304::DoTestStepL() sl@0: { sl@0: INFO_PRINTF1(_L("Unit test for TestUtils : RunUtils - MakeReadWrite")); sl@0: sl@0: TVerdict currentVerdict = EPass; sl@0: sl@0: iTestUtils->RunUtils(_L("run_utils makereadwrite c:\\TFData1\\testfile1.txt")); sl@0: sl@0: // check that file exists and is read-only sl@0: TUint theAtts; sl@0: RFs theFs; sl@0: theFs.Connect(); sl@0: theFs.Att(_L("c:\\TFData1\\testfile1.txt"), theAtts); sl@0: if(theAtts & KEntryAttReadOnly) sl@0: { sl@0: ERR_PRINTF1(_L("CTestUtils : run_utils makereadwrite failed, file is still read-only")); sl@0: theFs.Close(); sl@0: return iTestStepResult = EFail; sl@0: } sl@0: sl@0: theFs.Close(); sl@0: return iTestStepResult = currentVerdict; // should be EPass if we've got here sl@0: } sl@0: sl@0: // -------------------- sl@0: // RTestMmTsthU1305 sl@0: RTestMmTsthU1305* RTestMmTsthU1305::NewL() sl@0: { sl@0: RTestMmTsthU1305* self = new(ELeave) RTestMmTsthU1305; sl@0: return self; sl@0: } sl@0: sl@0: // Each test step initialises its own name. sl@0: RTestMmTsthU1305::RTestMmTsthU1305() sl@0: { sl@0: iTestStepName = _L("MM-TSTH-U-1305"); sl@0: } sl@0: sl@0: // preamble sl@0: TVerdict RTestMmTsthU1305::OpenL() sl@0: { sl@0: // do the standard preamble sl@0: TVerdict currentVerdict = RTSUMmTsthStep13::OpenL(); sl@0: if(currentVerdict != EPass) sl@0: return currentVerdict; sl@0: sl@0: // do extra, to set up the files/directories we need, which are :- sl@0: // C:\\TFData1\\testfile1.txt must exist and be read-write sl@0: sl@0: RFs theFs; sl@0: theFs.Connect(); sl@0: RFile theFile; sl@0: sl@0: TFileName theDirName = _L("c:\\TFData1\\"); sl@0: TFileName theFileName = _L("c:\\TFData1\\testfile1.txt"); sl@0: TInt rc = theFs.MkDir(theDirName); sl@0: if (rc != KErrNone && rc != KErrAlreadyExists) sl@0: { sl@0: ERR_PRINTF2(_L("Preamble failed RFs::MkDir() error code %d"), rc); sl@0: theFs.Close(); sl@0: return iTestStepResult = EFail; sl@0: } sl@0: rc = theFile.Replace(theFs, theFileName, EFileWrite | EFileStreamText); sl@0: sl@0: // check if open fails sl@0: if (rc == KErrNone) sl@0: { sl@0: theFile.Write(_L8("This is a test file for MM_TSTH_U_1305\n")); sl@0: theFile.Close(); sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF2(_L("Preamble failed RFile::Replace() error code %d"), rc); sl@0: theFs.Close(); sl@0: return iTestStepResult = EFail; sl@0: } sl@0: sl@0: // set read-write sl@0: rc = theFs.SetAtt(theFileName, 0, KEntryAttReadOnly); sl@0: sl@0: theFs.Close(); sl@0: return iTestStepResult = currentVerdict; sl@0: } sl@0: sl@0: // postamble sl@0: void RTestMmTsthU1305::Close() sl@0: { sl@0: // clean up the extra files / directories we created sl@0: CleanupFileSystem(); sl@0: sl@0: // do the standard postamble sl@0: RTSUMmTsthStep13::Close(); sl@0: } sl@0: sl@0: // do the test step sl@0: TVerdict RTestMmTsthU1305::DoTestStepL() sl@0: { sl@0: INFO_PRINTF1(_L("Unit test for TestUtils : RunUtils - Delete")); sl@0: sl@0: TVerdict currentVerdict = EPass; sl@0: sl@0: iTestUtils->RunUtils(_L("run_utils delete c:\\TFData1\\testfile1.txt")); sl@0: sl@0: // check that file does not exist sl@0: TUint dummy; sl@0: RFs theFs; sl@0: theFs.Connect(); sl@0: TInt rc = theFs.Att(_L("c:\\TFData1\\testfile1.txt"), dummy); sl@0: if(rc != KErrNotFound) sl@0: { sl@0: ERR_PRINTF1(_L("CTestUtils : run_utils delete failed, file still exists")); sl@0: theFs.Close(); sl@0: return iTestStepResult = EFail; sl@0: } sl@0: sl@0: theFs.Close(); sl@0: return iTestStepResult = currentVerdict; // should be EPass if we've got here sl@0: } sl@0: sl@0: // ---------------------- sl@0: // RTestMmTsthU1306 sl@0: sl@0: RTestMmTsthU1306* RTestMmTsthU1306::NewL() sl@0: { sl@0: RTestMmTsthU1306* self = new(ELeave) RTestMmTsthU1306; sl@0: return self; sl@0: } sl@0: sl@0: // Each test step initialises its own name. sl@0: RTestMmTsthU1306::RTestMmTsthU1306() sl@0: { sl@0: iTestStepName = _L("MM-TSTH-U-1306"); sl@0: } sl@0: sl@0: // preamble sl@0: TVerdict RTestMmTsthU1306::OpenL() sl@0: { sl@0: // do the standard preamble sl@0: TVerdict currentVerdict = RTSUMmTsthStep13::OpenL(); sl@0: if(currentVerdict != EPass) sl@0: return currentVerdict; sl@0: sl@0: // do extra, to set up the files/directories we need, which are :- sl@0: // C:\\TFData2 must exist sl@0: sl@0: RFs theFs; sl@0: theFs.Connect(); sl@0: sl@0: TFileName theDirName = _L("c:\\TFData2\\"); sl@0: TInt rc = theFs.MkDir(theDirName); sl@0: if (rc != KErrNone && rc != KErrAlreadyExists) sl@0: { sl@0: ERR_PRINTF2(_L("Preamble failed RFs::MkDir() error code %d"), rc); sl@0: theFs.Close(); sl@0: return iTestStepResult = EFail; sl@0: } sl@0: sl@0: theFs.Close(); sl@0: return iTestStepResult = currentVerdict; sl@0: } sl@0: sl@0: // postamble sl@0: void RTestMmTsthU1306::Close() sl@0: { sl@0: // clean up the extra files / directories we created sl@0: CleanupFileSystem(); sl@0: sl@0: // do the standard postamble sl@0: RTSUMmTsthStep13::Close(); sl@0: } sl@0: sl@0: // do the test step. sl@0: TVerdict RTestMmTsthU1306::DoTestStepL() sl@0: { sl@0: sl@0: INFO_PRINTF1(_L("This test step is not available on EKA2 - Passing test!")); sl@0: return EPass; sl@0: sl@0: } sl@0: sl@0: // -------------------- sl@0: // RTestMmTsthU1311 sl@0: sl@0: RTestMmTsthU1311* RTestMmTsthU1311::NewL() sl@0: { sl@0: RTestMmTsthU1311* self = new(ELeave) RTestMmTsthU1311; sl@0: return self; sl@0: } sl@0: sl@0: // Each test step initialises its own name. sl@0: RTestMmTsthU1311::RTestMmTsthU1311() sl@0: { sl@0: iTestStepName = _L("MM-TSTH-U-1311"); sl@0: } sl@0: sl@0: // do the test step sl@0: TVerdict RTestMmTsthU1311::DoTestStepL() sl@0: { sl@0: // to demonstrate that bad syntax does not panic sl@0: INFO_PRINTF1(_L("Unit test for TestUtils : RunUtils - bad syntax")); sl@0: sl@0: TVerdict currentVerdict = EPass; sl@0: sl@0: iTestUtils->RunUtils(_L("run_utils gobbledygook")); sl@0: INFO_PRINTF1(_L("RunUtils did not panic")); sl@0: sl@0: return iTestStepResult = currentVerdict; // should be EPass if we've got here sl@0: } sl@0: sl@0: // --------------------