|
1 // Copyright (c) 2007-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 the License "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 // Base class for FileOperations and ReadFiles |
|
15 // |
|
16 // |
|
17 |
|
18 #include "sdfileoperationsbase.h" |
|
19 |
|
20 /* |
|
21 Test Step Preamble |
|
22 - Initialise attribute iDrive |
|
23 - Connect to the File Server |
|
24 - Instatiate a CFileMan object |
|
25 - Read test step configuration from INI file |
|
26 |
|
27 @param None |
|
28 @return EPass if successful or EFail if not |
|
29 @see TVerdict |
|
30 */ |
|
31 TVerdict CBaseTestSDFileOperationsBase::doTestStepPreambleL() |
|
32 { |
|
33 SetTestStepResult(EFail); |
|
34 |
|
35 if (!InitDriveLetter()) |
|
36 return TestStepResult(); |
|
37 if (!InitFileServer()) |
|
38 return TestStepResult(); |
|
39 if (!InitFileMan()) |
|
40 return TestStepResult(); |
|
41 |
|
42 _LIT(KRootEntries, "FileOperationsRootEntries"); |
|
43 _LIT(KExpandRootFilesNumber, "FileOperationsExpandRootFilesNumber"); |
|
44 _LIT(KExpandRootFilesSize, "FileOperationsExpandRootFilesSize"); |
|
45 _LIT(KDeleteRootDirs, "FileOperationsDeleteRootDirs"); |
|
46 _LIT(KSubDirEntries, "FileOperationsSubDirEntries"); |
|
47 _LIT(KLargeFileSize, "FileOperationsLargeFileSize"); |
|
48 _LIT(KVolumeName, "FileOperationsVolumeName"); |
|
49 _LIT(KExpectedErrorCode, "FileOperationsExpectedErrorCode"); |
|
50 |
|
51 if (!GetIntFromConfig(ConfigSection(), KRootEntries, iRootEntries)) |
|
52 { |
|
53 ERR_PRINTF1(_L("INI File Read Error")); |
|
54 return TestStepResult(); |
|
55 } |
|
56 if (!GetIntFromConfig(ConfigSection(), KExpandRootFilesNumber, iExpandRootFilesNumber)) |
|
57 { |
|
58 ERR_PRINTF1(_L("INI File Read Error")); |
|
59 return TestStepResult(); |
|
60 } |
|
61 if (!GetIntFromConfig(ConfigSection(), KExpandRootFilesSize, iExpandRootFilesSize)) |
|
62 { |
|
63 ERR_PRINTF1(_L("INI File Read Error")); |
|
64 return TestStepResult(); |
|
65 } |
|
66 if (!GetIntFromConfig(ConfigSection(), KDeleteRootDirs, iDeleteRootDirs)) |
|
67 { |
|
68 ERR_PRINTF1(_L("INI File Read Error")); |
|
69 return TestStepResult(); |
|
70 } |
|
71 if (!GetIntFromConfig(ConfigSection(), KSubDirEntries, iSubDirEntries)) |
|
72 { |
|
73 ERR_PRINTF1(_L("INI File Read Error")); |
|
74 return TestStepResult(); |
|
75 } |
|
76 if (!GetIntFromConfig(ConfigSection(), KLargeFileSize, iLargeFileSize)) |
|
77 { |
|
78 ERR_PRINTF1(_L("INI File Read Error")); |
|
79 return TestStepResult(); |
|
80 } |
|
81 if (!GetStringFromConfig(ConfigSection(), KVolumeName, iVolumeName)) |
|
82 { |
|
83 ERR_PRINTF1(_L("INI File Read Error")); |
|
84 return TestStepResult(); |
|
85 } |
|
86 if (!GetIntFromConfig(ConfigSection(), KExpectedErrorCode, iExpectedErrorCode)) |
|
87 { |
|
88 INFO_PRINTF1(_L("No expected error code found in INI File - KErrNone is expected")); |
|
89 iExpectedErrorCode = KErrNone; |
|
90 } |
|
91 SetTestStepResult(EPass); |
|
92 return TestStepResult(); |
|
93 } |
|
94 |
|
95 /* |
|
96 Change the volume name of the disk under test |
|
97 |
|
98 @param None |
|
99 @return KErrNone if successful, otherwise any other system-wide error code |
|
100 */ |
|
101 TInt CBaseTestSDFileOperationsBase::SetVolumeName() |
|
102 { |
|
103 TInt r; |
|
104 INFO_PRINTF2(_L("Set volume label to: %S"), &iVolumeName); |
|
105 r = iFs.SetVolumeLabel(iVolumeName); |
|
106 return r; |
|
107 } |
|
108 |
|
109 /* |
|
110 Create files and directories under the toot of the drive under test |
|
111 |
|
112 @param None |
|
113 @return KErrNone if successful, otherwise any other system-wide error code |
|
114 */ |
|
115 TInt CBaseTestSDFileOperationsBase::CreateRootEntries() |
|
116 { |
|
117 TInt r = iExpectedErrorCode; |
|
118 INFO_PRINTF4(_L("Create %d root directory entries (%d directories and %d files)"), iRootEntries, iRootEntries / 2, iRootEntries - (TInt) (iRootEntries / 2)); |
|
119 for (TInt i = 0; i < iRootEntries / 2; i++) |
|
120 { |
|
121 TFileName dirname; |
|
122 dirname.Format(_L("\\dir%03d\\"), i); |
|
123 r = iFs.MkDir(dirname); |
|
124 if (r != iExpectedErrorCode) |
|
125 { |
|
126 ERR_PRINTF3(_L("Error %d when making %S"), r, &dirname); |
|
127 return r; |
|
128 } |
|
129 } |
|
130 for (TInt i = iRootEntries / 2; i < iRootEntries; i++) |
|
131 { |
|
132 RFile file; |
|
133 TFileName filename; |
|
134 filename.Format(_L("\\file%03d"), i - iRootEntries / 2); |
|
135 r = file.Create(iFs, filename, EFileWrite); |
|
136 if (r != iExpectedErrorCode) |
|
137 { |
|
138 ERR_PRINTF3(_L("Error %d RFile::Create %S"), r, &filename); |
|
139 return r; |
|
140 } |
|
141 if (r != KErrNone) |
|
142 continue; |
|
143 file.Write(_L8("SD")); |
|
144 if (r != KErrNone) |
|
145 { |
|
146 ERR_PRINTF3(_L("Error %d RFile::Write %S"), r, &filename); |
|
147 return r; |
|
148 } |
|
149 file.Close(); |
|
150 } |
|
151 return r; |
|
152 } |
|
153 |
|
154 /* |
|
155 Increase the size of some files on the root directory |
|
156 |
|
157 @param None |
|
158 @return KErrNone if successful, otherwise any other system-wide error code |
|
159 */ |
|
160 TInt CBaseTestSDFileOperationsBase::ExpandRootFiles() |
|
161 { |
|
162 TInt r = iExpectedErrorCode; |
|
163 for (TInt i = 2; i < iExpandRootFilesNumber + 2; i++) |
|
164 { |
|
165 TFileName filename; |
|
166 filename.Format(_L("\\file%03d"), i); |
|
167 r = ExpandFile(filename, iExpandRootFilesSize); |
|
168 if (r != iExpectedErrorCode) |
|
169 break; |
|
170 } |
|
171 return r; |
|
172 } |
|
173 |
|
174 /* |
|
175 Delete some directories on the root directory |
|
176 |
|
177 @param None |
|
178 @return KErrNone if successful, otherwise any other system-wide error code |
|
179 */ |
|
180 TInt CBaseTestSDFileOperationsBase::DeleteRootDirs() |
|
181 { |
|
182 TInt r = iExpectedErrorCode; |
|
183 INFO_PRINTF2(_L("Delete first %d directories"), iDeleteRootDirs); |
|
184 for (TInt i = iDeleteRootDirs - 1; i >= 0; i--) |
|
185 { |
|
186 TFileName dirname; |
|
187 dirname.Format(_L("\\dir%03d\\"), i); |
|
188 r = iFs.RmDir(dirname); |
|
189 if (r != iExpectedErrorCode) |
|
190 { |
|
191 ERR_PRINTF3(_L("Error %d when deleting %S"), r, &dirname); |
|
192 return r; |
|
193 } |
|
194 } |
|
195 return r; |
|
196 } |
|
197 |
|
198 /* |
|
199 Rename a file |
|
200 |
|
201 @param aOldFile File to be renamed |
|
202 @param aNewFile New name |
|
203 @return KErrNone if successful, otherwise any other system-wide error code |
|
204 */ |
|
205 TInt CBaseTestSDFileOperationsBase::RenameFile(const TDesC& aOldFile, const TDesC& aNewFile) |
|
206 { |
|
207 TInt r; |
|
208 INFO_PRINTF3(_L("Rename %S to %S"), &aOldFile, &aNewFile); |
|
209 r = iFileMan->Rename(aOldFile, aNewFile, CFileMan::EOverWrite); |
|
210 if (r != iExpectedErrorCode) |
|
211 { |
|
212 ERR_PRINTF2(_L("Error %d"), r); |
|
213 } |
|
214 return r; |
|
215 } |
|
216 |
|
217 /* |
|
218 Create files under a directory |
|
219 |
|
220 @param aDir Path to the directory where the files will be created |
|
221 @return KErrNone if successful, otherwise any other system-wide error code |
|
222 */ |
|
223 TInt CBaseTestSDFileOperationsBase::CreateSubDirEntries(const TDesC& aDir) |
|
224 { |
|
225 TInt r = iExpectedErrorCode; |
|
226 INFO_PRINTF3(_L("Create %d subdir entries in %S"), iSubDirEntries, &aDir); |
|
227 for (TInt i = 0; i < iSubDirEntries; i++) |
|
228 { |
|
229 RFile file; |
|
230 TFileName filename; |
|
231 filename.Format(_L("%Sfile%04d"), &aDir, i); |
|
232 r = file.Create(iFs, filename, EFileWrite); |
|
233 if (r != iExpectedErrorCode) |
|
234 { |
|
235 ERR_PRINTF3(_L("Error %d RFile::Create %S\n"), r, &filename); |
|
236 return r; |
|
237 } |
|
238 if (r != KErrNone) |
|
239 break; |
|
240 file.Write(_L8("SD")); |
|
241 if (r != KErrNone) |
|
242 { |
|
243 ERR_PRINTF3(_L("Error %d RFile::Write %S\n"), r, &filename); |
|
244 return r; |
|
245 } |
|
246 file.Close(); |
|
247 } |
|
248 return r; |
|
249 } |
|
250 |
|
251 /* |
|
252 Change the volume name of the disk under test |
|
253 |
|
254 @param None |
|
255 @return KErrNone if successful, otherwise any other system-wide error code |
|
256 */ |
|
257 TInt CBaseTestSDFileOperationsBase::DeleteSubDirEntries(const TDesC& aDir) |
|
258 { |
|
259 TInt r = iExpectedErrorCode; |
|
260 INFO_PRINTF3(_L("Delete %d subdir entries in %S"), iSubDirEntries, &aDir); |
|
261 for (TInt i = 0; i < iSubDirEntries; i++) |
|
262 { |
|
263 TFileName filename; |
|
264 filename.Format(_L("%Sfile%04d"), &aDir, i); |
|
265 r = iFs.Delete(filename); |
|
266 if (r != iExpectedErrorCode) |
|
267 { |
|
268 ERR_PRINTF3(_L("Error %d RFs::Delete %S\n"), r, &filename); |
|
269 return r; |
|
270 } |
|
271 } |
|
272 return r; |
|
273 } |
|
274 |
|
275 /* |
|
276 Change the size of a file |
|
277 |
|
278 @param aFile File who's size is to be changed |
|
279 @param aSize New file size in megabytes |
|
280 @return KErrNone if successful, otherwise any other system-wide error code |
|
281 */ |
|
282 TInt CBaseTestSDFileOperationsBase::ExpandFile(const TDesC& aFile, TInt aSize) |
|
283 { |
|
284 TInt r; |
|
285 INFO_PRINTF3(_L("Expand size of %S to %dMB"), &aFile, aSize); |
|
286 RFile file; |
|
287 r = file.Open(iFs, aFile, EFileWrite); |
|
288 if (r != iExpectedErrorCode) |
|
289 { |
|
290 ERR_PRINTF2(_L("Error %d RFile::Open\n"), r); |
|
291 return r; |
|
292 } |
|
293 if (r != KErrNone) |
|
294 return r; |
|
295 r = file.SetSize(1024*1024*aSize); |
|
296 if (r != KErrNone) |
|
297 { |
|
298 ERR_PRINTF2(_L("Error %d RFile::SetSize\n"), r); |
|
299 file.Close(); |
|
300 return r; |
|
301 } |
|
302 file.Close(); |
|
303 return r; |
|
304 } |
|
305 |
|
306 /* |
|
307 Copy file |
|
308 |
|
309 @param aOrig File to be copied |
|
310 @param aDest Destination path |
|
311 @return KErrNone if successful, otherwise any other system-wide error code |
|
312 */ |
|
313 TInt CBaseTestSDFileOperationsBase::CopyFile(const TDesC& aOrig, const TDesC& aDest) |
|
314 { |
|
315 TInt r; |
|
316 INFO_PRINTF3(_L("Copy %S to %S"), &aOrig, &aDest); |
|
317 r = iFileMan->Copy(aOrig, aDest, CFileMan::EOverWrite); |
|
318 INFO_PRINTF2(_L("Returned value: %d"), r); |
|
319 return r; |
|
320 } |
|
321 |
|
322 /* |
|
323 Move file |
|
324 |
|
325 @param aOrig File to be moved |
|
326 @param aDest Destination path |
|
327 @return KErrNone if successful, otherwise any other system-wide error code |
|
328 */ |
|
329 TInt CBaseTestSDFileOperationsBase::MoveFile(const TDesC& aOrig, const TDesC& aDest) |
|
330 { |
|
331 TInt r; |
|
332 INFO_PRINTF3(_L("Move %S to %S"), &aOrig, &aDest); |
|
333 r = iFileMan->Move(aOrig, aDest, CFileMan::EOverWrite); |
|
334 INFO_PRINTF2(_L("Returned value: %d"), r); |
|
335 return r; |
|
336 } |