sl@0: // Copyright (c) 2004-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: // sl@0: sl@0: /** sl@0: @file sl@0: @internalTechnology sl@0: */ sl@0: sl@0: // User Include sl@0: #include "TestCreateFileStep.h" sl@0: sl@0: /** sl@0: Constructor. Sets the test step name sl@0: */ sl@0: CTestCreateFileStep::CTestCreateFileStep() sl@0: { sl@0: //Call base class method to set human readable name for test step sl@0: SetTestStepName(KTestCreateFileStep); sl@0: } sl@0: sl@0: /** sl@0: Tries to create a file mentioned in the ini file. sl@0: @internalTechnology sl@0: @param None sl@0: @return EPass or EFail indicating the success or failure of file creation. sl@0: */ sl@0: TVerdict CTestCreateFileStep::doTestStepL() sl@0: { sl@0: // Get file path and name from ini file sl@0: TPtrC fileName; sl@0: TPtrC fileType; sl@0: TPtrC drive; sl@0: TInt err = KErrNone; sl@0: RFs fs; sl@0: RFile file; sl@0: sl@0: if (!GetStringFromConfig(ConfigSection(), KIniFileName, fileName)) sl@0: { sl@0: ERR_PRINTF1(_L("Unable to read filename from ini file")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF2(_L("File name = %S"), &fileName); sl@0: sl@0: // check whether the filetype field exists in INI sl@0: if(GetStringFromConfig(ConfigSection(), KIniFileType, fileType)) sl@0: { sl@0: INFO_PRINTF2(_L("File type = %S"), &fileType); sl@0: } sl@0: sl@0: if(fileType == KFileTypePrivate) sl@0: {// The file is a private file. We require the drive too, as the path is relative sl@0: if (!GetStringFromConfig(ConfigSection(), KIniDrive, drive)) sl@0: { sl@0: ERR_PRINTF1(_L("If file type is private, drive should be provided. Unable to read drive")); sl@0: SetTestStepResult(EFail); sl@0: return TestStepResult(); sl@0: } sl@0: TFileName fullyQualifiedName(fileName); sl@0: // In the case of a secure vesrion of the OS sl@0: // As the INI file contains relative file-name for private files sl@0: // under the ExpectedFileName field, construct the fully-qualified sl@0: // expected file-name sl@0: if((err = CTestFileUriServer::CreateFullyQualifiedName(fileName, drive, fullyQualifiedName)) != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Error returned by CTestFileUriServer::CreateFullyQualifiedName: %D"), err); sl@0: SetTestStepResult(EFail); sl@0: return TestStepResult(); sl@0: } sl@0: fileName.Set(fullyQualifiedName); sl@0: INFO_PRINTF2(_L("Fully qualified name = %S"), &fileName); sl@0: } sl@0: sl@0: // Connect to file server sl@0: err = fs.Connect(); sl@0: if(err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Error occured while connecting to file server: %D"), err); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: if(TestStepResult() == EPass) sl@0: { sl@0: // Try opening first to see whether file already exists. sl@0: err = file.Open(fs, fileName, EFileRead); sl@0: switch(err) sl@0: { sl@0: case KErrNone: sl@0: // File already exists, this is NOT considered as fail sl@0: INFO_PRINTF1(_L("File already exists")); sl@0: break; sl@0: case KErrNotReady: sl@0: // Drive is not ready, this is NOT considered as fail sl@0: INFO_PRINTF1(_L("Drive not ready")); sl@0: break; sl@0: case KErrPathNotFound: sl@0: // Create directories sl@0: err = fs.MkDirAll(fileName); sl@0: if (err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Could not create directories. Error returned: %D"), err); sl@0: SetTestStepResult(EFail); sl@0: // Only if unable to create directories we break sl@0: // else, next case should also be executed which creates the file sl@0: break; sl@0: } sl@0: // No break sl@0: case KErrNotFound: sl@0: // Create the file sl@0: err = file.Create(fs, fileName, EFileWrite); sl@0: if(err != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Error occured while creating file: %D"), err); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Successfully created file")); sl@0: } sl@0: break; sl@0: default: sl@0: ERR_PRINTF2(_L("Error occured: %D"), err); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: file.Close(); sl@0: fs.Close(); sl@0: } sl@0: } sl@0: return TestStepResult(); sl@0: } // doTestStepL