|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @internalTechnology |
|
19 */ |
|
20 |
|
21 // User Include |
|
22 #include "TestCreateFileStep.h" |
|
23 |
|
24 /** |
|
25 Constructor. Sets the test step name |
|
26 */ |
|
27 CTestCreateFileStep::CTestCreateFileStep() |
|
28 { |
|
29 //Call base class method to set human readable name for test step |
|
30 SetTestStepName(KTestCreateFileStep); |
|
31 } |
|
32 |
|
33 /** |
|
34 Tries to create a file mentioned in the ini file. |
|
35 @internalTechnology |
|
36 @param None |
|
37 @return EPass or EFail indicating the success or failure of file creation. |
|
38 */ |
|
39 TVerdict CTestCreateFileStep::doTestStepL() |
|
40 { |
|
41 // Get file path and name from ini file |
|
42 TPtrC fileName; |
|
43 TPtrC fileType; |
|
44 TPtrC drive; |
|
45 TInt err = KErrNone; |
|
46 RFs fs; |
|
47 RFile file; |
|
48 |
|
49 if (!GetStringFromConfig(ConfigSection(), KIniFileName, fileName)) |
|
50 { |
|
51 ERR_PRINTF1(_L("Unable to read filename from ini file")); |
|
52 SetTestStepResult(EFail); |
|
53 } |
|
54 else |
|
55 { |
|
56 INFO_PRINTF2(_L("File name = %S"), &fileName); |
|
57 |
|
58 // check whether the filetype field exists in INI |
|
59 if(GetStringFromConfig(ConfigSection(), KIniFileType, fileType)) |
|
60 { |
|
61 INFO_PRINTF2(_L("File type = %S"), &fileType); |
|
62 } |
|
63 |
|
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)) |
|
67 { |
|
68 ERR_PRINTF1(_L("If file type is private, drive should be provided. Unable to read drive")); |
|
69 SetTestStepResult(EFail); |
|
70 return TestStepResult(); |
|
71 } |
|
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 |
|
76 // expected file-name |
|
77 if((err = CTestFileUriServer::CreateFullyQualifiedName(fileName, drive, fullyQualifiedName)) != KErrNone) |
|
78 { |
|
79 ERR_PRINTF2(_L("Error returned by CTestFileUriServer::CreateFullyQualifiedName: %D"), err); |
|
80 SetTestStepResult(EFail); |
|
81 return TestStepResult(); |
|
82 } |
|
83 fileName.Set(fullyQualifiedName); |
|
84 INFO_PRINTF2(_L("Fully qualified name = %S"), &fileName); |
|
85 } |
|
86 |
|
87 // Connect to file server |
|
88 err = fs.Connect(); |
|
89 if(err != KErrNone) |
|
90 { |
|
91 ERR_PRINTF2(_L("Error occured while connecting to file server: %D"), err); |
|
92 SetTestStepResult(EFail); |
|
93 } |
|
94 |
|
95 if(TestStepResult() == EPass) |
|
96 { |
|
97 // Try opening first to see whether file already exists. |
|
98 err = file.Open(fs, fileName, EFileRead); |
|
99 switch(err) |
|
100 { |
|
101 case KErrNone: |
|
102 // File already exists, this is NOT considered as fail |
|
103 INFO_PRINTF1(_L("File already exists")); |
|
104 break; |
|
105 case KErrNotReady: |
|
106 // Drive is not ready, this is NOT considered as fail |
|
107 INFO_PRINTF1(_L("Drive not ready")); |
|
108 break; |
|
109 case KErrPathNotFound: |
|
110 // Create directories |
|
111 err = fs.MkDirAll(fileName); |
|
112 if (err != KErrNone) |
|
113 { |
|
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 |
|
118 break; |
|
119 } |
|
120 // No break |
|
121 case KErrNotFound: |
|
122 // Create the file |
|
123 err = file.Create(fs, fileName, EFileWrite); |
|
124 if(err != KErrNone) |
|
125 { |
|
126 ERR_PRINTF2(_L("Error occured while creating file: %D"), err); |
|
127 SetTestStepResult(EFail); |
|
128 } |
|
129 else |
|
130 { |
|
131 INFO_PRINTF1(_L("Successfully created file")); |
|
132 } |
|
133 break; |
|
134 default: |
|
135 ERR_PRINTF2(_L("Error occured: %D"), err); |
|
136 SetTestStepResult(EFail); |
|
137 } |
|
138 file.Close(); |
|
139 fs.Close(); |
|
140 } |
|
141 } |
|
142 return TestStepResult(); |
|
143 } // doTestStepL |