os/ossrv/genericservices/httputils/Test/Integration/TestFileUriSuite/TestCreateFileStep.cpp
Update contrib.
1 // Copyright (c) 2004-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.
22 #include "TestCreateFileStep.h"
25 Constructor. Sets the test step name
27 CTestCreateFileStep::CTestCreateFileStep()
29 //Call base class method to set human readable name for test step
30 SetTestStepName(KTestCreateFileStep);
34 Tries to create a file mentioned in the ini file.
37 @return EPass or EFail indicating the success or failure of file creation.
39 TVerdict CTestCreateFileStep::doTestStepL()
41 // Get file path and name from ini file
49 if (!GetStringFromConfig(ConfigSection(), KIniFileName, fileName))
51 ERR_PRINTF1(_L("Unable to read filename from ini file"));
52 SetTestStepResult(EFail);
56 INFO_PRINTF2(_L("File name = %S"), &fileName);
58 // check whether the filetype field exists in INI
59 if(GetStringFromConfig(ConfigSection(), KIniFileType, fileType))
61 INFO_PRINTF2(_L("File type = %S"), &fileType);
64 if(fileType == KFileTypePrivate)
65 {// The file is a private file. We require the drive too, as the path is relative
66 if (!GetStringFromConfig(ConfigSection(), KIniDrive, drive))
68 ERR_PRINTF1(_L("If file type is private, drive should be provided. Unable to read drive"));
69 SetTestStepResult(EFail);
70 return TestStepResult();
72 TFileName fullyQualifiedName(fileName);
73 // In the case of a secure vesrion of the OS
74 // As the INI file contains relative file-name for private files
75 // under the ExpectedFileName field, construct the fully-qualified
77 if((err = CTestFileUriServer::CreateFullyQualifiedName(fileName, drive, fullyQualifiedName)) != KErrNone)
79 ERR_PRINTF2(_L("Error returned by CTestFileUriServer::CreateFullyQualifiedName: %D"), err);
80 SetTestStepResult(EFail);
81 return TestStepResult();
83 fileName.Set(fullyQualifiedName);
84 INFO_PRINTF2(_L("Fully qualified name = %S"), &fileName);
87 // Connect to file server
91 ERR_PRINTF2(_L("Error occured while connecting to file server: %D"), err);
92 SetTestStepResult(EFail);
95 if(TestStepResult() == EPass)
97 // Try opening first to see whether file already exists.
98 err = file.Open(fs, fileName, EFileRead);
102 // File already exists, this is NOT considered as fail
103 INFO_PRINTF1(_L("File already exists"));
106 // Drive is not ready, this is NOT considered as fail
107 INFO_PRINTF1(_L("Drive not ready"));
109 case KErrPathNotFound:
110 // Create directories
111 err = fs.MkDirAll(fileName);
114 ERR_PRINTF2(_L("Could not create directories. Error returned: %D"), err);
115 SetTestStepResult(EFail);
116 // Only if unable to create directories we break
117 // else, next case should also be executed which creates the file
123 err = file.Create(fs, fileName, EFileWrite);
126 ERR_PRINTF2(_L("Error occured while creating file: %D"), err);
127 SetTestStepResult(EFail);
131 INFO_PRINTF1(_L("Successfully created file"));
135 ERR_PRINTF2(_L("Error occured: %D"), err);
136 SetTestStepResult(EFail);
142 return TestStepResult();