|
1 // Copyright (c) 1997-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 "Symbian Foundation License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #ifdef __TOOLS2__ |
|
17 #include <sys/stat.h> |
|
18 #include <stdlib.h> |
|
19 #ifdef linux |
|
20 #include <string.h> |
|
21 #endif |
|
22 #endif |
|
23 |
|
24 #include <e32test.h> |
|
25 #include <f32file.h> |
|
26 |
|
27 RTest test(_L("SymFile RFs Tests")); |
|
28 |
|
29 void testAtt() |
|
30 { |
|
31 // Connect to the file system |
|
32 RFs fs; |
|
33 test(fs.Connect() == KErrNone); |
|
34 |
|
35 _LIT(KTestDir1, "c:\\symport_test_rfs1\\"); |
|
36 _LIT(KTestFile, "c:\\symport_test_rfs1\\test.txt"); |
|
37 |
|
38 // Test with root |
|
39 TUint att; |
|
40 test(fs.Att(_L("C:\\"), att) == KErrBadName); |
|
41 test(fs.Att(_L("\\"), att) == KErrBadName); |
|
42 |
|
43 // Make sure the directory doesn't exist |
|
44 TInt err = fs.Delete(KTestFile); |
|
45 test(err == KErrNone || err == KErrNotFound || err == KErrPathNotFound); |
|
46 err = fs.RmDir(KTestDir1); |
|
47 test(err == KErrNone || err == KErrNotFound); |
|
48 |
|
49 // Check it fails |
|
50 test(fs.Att(KTestDir1, att) == KErrNotFound); |
|
51 |
|
52 // See if it works for directories |
|
53 test(fs.MkDir(KTestDir1) == KErrNone); |
|
54 test(fs.Att(KTestDir1, att) == KErrNone && att&KEntryAttDir); |
|
55 |
|
56 // See if it works for normal files |
|
57 test(fs.Att(KTestFile, att) == KErrNotFound); |
|
58 RFile file; |
|
59 test(file.Create(fs, KTestFile, EFileShareAny|EFileWrite) == KErrNone); |
|
60 test(file.Write(_L8("test")) == KErrNone); |
|
61 file.Close(); |
|
62 test(fs.Att(KTestFile, att) == KErrNone); |
|
63 test(!(att&KEntryAttDir)); |
|
64 |
|
65 // Check readonly flag |
|
66 test(!(att&KEntryAttReadOnly)); |
|
67 test(fs.SetAtt(KTestFile, KEntryAttReadOnly, 0) == KErrNone); |
|
68 test(fs.Att(KTestFile, att) == KErrNone && att&KEntryAttReadOnly); |
|
69 |
|
70 // Clear the flag |
|
71 test(fs.SetAtt(KTestFile, 0, KEntryAttReadOnly) == KErrNone); |
|
72 test(fs.Att(KTestFile, att) == KErrNone); |
|
73 test(!(att&KEntryAttReadOnly)); |
|
74 |
|
75 // Delete the file and make sure it goes away |
|
76 test(fs.RmDir(KTestDir1) == KErrInUse); |
|
77 test(fs.Delete(KTestFile) == KErrNone); |
|
78 test(fs.Att(KTestFile, att) == KErrNotFound); |
|
79 |
|
80 // Delete directory and make sure it really went away |
|
81 test(fs.RmDir(KTestDir1) == KErrNone); |
|
82 test(fs.Att(KTestDir1, att) == KErrNotFound); |
|
83 |
|
84 fs.Close(); |
|
85 } |
|
86 |
|
87 void testSetAtt() |
|
88 { |
|
89 // Connect to the file system |
|
90 RFs fs; |
|
91 test(fs.Connect() == KErrNone); |
|
92 |
|
93 // Make sure the file doesn't exist |
|
94 _LIT(KTestFile, "c:\\symport_test_rfs2_test.txt"); |
|
95 fs.SetAtt(KTestFile, 0, KEntryAttReadOnly); |
|
96 fs.Delete(KTestFile); |
|
97 |
|
98 // File doesn't exist |
|
99 test(fs.SetAtt(KTestFile, KEntryAttReadOnly, 0) == KErrNotFound); |
|
100 |
|
101 // Create a file |
|
102 RFile file; |
|
103 test(file.Create(fs, KTestFile, EFileShareAny|EFileWrite) == KErrNone); |
|
104 test(file.Write(_L8("test")) == KErrNone); |
|
105 file.Close(); |
|
106 |
|
107 // Set readonly flag |
|
108 TUint att; |
|
109 test(fs.Att(KTestFile, att) == KErrNone); |
|
110 test(!(att&KEntryAttReadOnly)); |
|
111 test(fs.SetAtt(KTestFile, KEntryAttReadOnly, 0) == KErrNone); |
|
112 test(fs.Att(KTestFile, att) == KErrNone && att&KEntryAttReadOnly); |
|
113 |
|
114 // Clear readonly flag |
|
115 test(fs.SetAtt(KTestFile, 0, KEntryAttReadOnly) == KErrNone); |
|
116 test(fs.Att(KTestFile, att) == KErrNone); |
|
117 test(!(att&KEntryAttReadOnly)); |
|
118 |
|
119 test(fs.Delete(KTestFile) == KErrNone); |
|
120 fs.Close(); |
|
121 } |
|
122 |
|
123 void testModified() |
|
124 { |
|
125 // Connect to the file system |
|
126 RFs fs; |
|
127 test(fs.Connect() == KErrNone); |
|
128 |
|
129 // Make sure the file doesn't exist |
|
130 _LIT(KTestFile, "c:\\symport_test_rfs2a_test.txt"); |
|
131 fs.Delete(KTestFile); |
|
132 |
|
133 // Get time now |
|
134 TTime start; |
|
135 start.UniversalTime(); |
|
136 |
|
137 // File doesn't exist |
|
138 TTime time1; |
|
139 test(fs.Modified(KTestFile, time1) == KErrNotFound); |
|
140 User::After(1000000); |
|
141 |
|
142 // Create a file |
|
143 RFile file; |
|
144 test(file.Create(fs, KTestFile, EFileShareAny|EFileWrite) == KErrNone); |
|
145 test(file.Write(_L8("test")) == KErrNone); |
|
146 file.Close(); |
|
147 |
|
148 // Get modified time |
|
149 test(fs.Modified(KTestFile, time1) == KErrNone && time1 > start); |
|
150 User::After(1000000); |
|
151 |
|
152 // Edit the file |
|
153 test(file.Open(fs, KTestFile, EFileShareAny|EFileWrite) == KErrNone); |
|
154 test(file.Write(_L8("test")) == KErrNone); |
|
155 file.Close(); |
|
156 |
|
157 // Get modified time |
|
158 TTime time2; |
|
159 test(fs.Modified(KTestFile, time2) == KErrNone && time2 > time1); |
|
160 |
|
161 test(fs.Delete(KTestFile) == KErrNone); |
|
162 fs.Close(); |
|
163 } |
|
164 |
|
165 void testMkDirAll() |
|
166 { |
|
167 RFs fs; |
|
168 test(fs.Connect() == KErrNone); |
|
169 |
|
170 _LIT(KTestFile, "c:\\symport_test_rfs3_parent\\symport_test_rfs3_child"); |
|
171 fs.Delete(KTestFile); |
|
172 |
|
173 // Make sure the directories don't exist already |
|
174 _LIT(KTestDirParent1, "c:\\symport_test_rfs3_parent\\"); |
|
175 _LIT(KTestDir1, "c:\\symport_test_rfs3_parent\\symport_test_rfs3_child\\"); |
|
176 fs.RmDir(KTestDir1); |
|
177 fs.RmDir(KTestDirParent1); |
|
178 |
|
179 // Check it can handle drive letter |
|
180 test(fs.MkDirAll(KTestDir1) == KErrNone); |
|
181 test(fs.MkDirAll(KTestDir1) == KErrAlreadyExists); |
|
182 TUint att; |
|
183 test(fs.Att(KTestDir1, att) == KErrNone && att&KEntryAttDir); |
|
184 |
|
185 // Delete the folder for the next test |
|
186 test(fs.RmDir(KTestDir1) == KErrNone && fs.RmDir(KTestDirParent1) == KErrNone); |
|
187 TInt err = fs.Att(KTestDir1, att); |
|
188 test(err == KErrNotFound || err == KErrPathNotFound); |
|
189 |
|
190 // Check it fails if file is encountered |
|
191 test(fs.MkDir(KTestDirParent1) == KErrNone); |
|
192 RFile file; |
|
193 test(file.Create(fs, KTestFile, EFileShareAny|EFileWrite) == KErrNone); |
|
194 test(file.Write(_L8("test")) == KErrNone); |
|
195 file.Close(); |
|
196 test(fs.MkDirAll(KTestDir1) == KErrAccessDenied); |
|
197 |
|
198 // Check for failure on itermediate file |
|
199 _LIT(KTestDir3, "c:\\symport_test_rfs3_parent\\symport_test_rfs3_child\\wibble\\"); |
|
200 test(fs.MkDirAll(KTestDir3) == KErrAccessDenied); |
|
201 |
|
202 test(fs.Delete(KTestFile) == KErrNone); |
|
203 test(fs.RmDir(KTestDirParent1) == KErrNone); |
|
204 |
|
205 fs.Close(); |
|
206 } |
|
207 |
|
208 void testMkDir() |
|
209 { |
|
210 RFs fs; |
|
211 test(fs.Connect() == KErrNone); |
|
212 |
|
213 _LIT(KTestDir1, "c:\\symport_test_rfs5\\"); |
|
214 _LIT(KTestFile, "c:\\symport_test_rfs5"); |
|
215 _LIT(KTestDir1Sub, "c:\\symport_test_rfs5\\sub\\"); |
|
216 |
|
217 // Make sure the test stuff doesn't exist already |
|
218 fs.RmDir(KTestDir1Sub); |
|
219 fs.Delete(KTestFile); |
|
220 fs.RmDir(KTestDir1); |
|
221 |
|
222 // Check the directory can be created |
|
223 TUint att; |
|
224 test(fs.MkDir(KTestDir1) == KErrNone); |
|
225 test(fs.MkDir(KTestDir1) == KErrAlreadyExists); |
|
226 test(fs.Att(KTestDir1, att) == KErrNone); |
|
227 test(fs.MkDir(KTestDir1Sub) == KErrNone); |
|
228 test(fs.MkDir(KTestDir1Sub) == KErrAlreadyExists); |
|
229 test(fs.RmDir(KTestDir1Sub) == KErrNone); |
|
230 test(fs.RmDir(KTestDir1) == KErrNone); |
|
231 test(fs.Att(KTestDir1, att) == KErrNotFound); |
|
232 |
|
233 // Check file error |
|
234 RFile file; |
|
235 test(file.Create(fs, KTestFile, EFileShareAny|EFileWrite) == KErrNone); |
|
236 test(file.Write(_L8("test")) == KErrNone); |
|
237 file.Close(); |
|
238 |
|
239 test(fs.MkDir(KTestDir1) == KErrAccessDenied); |
|
240 test(fs.Delete(KTestFile) == KErrNone); |
|
241 |
|
242 fs.Close(); |
|
243 } |
|
244 |
|
245 void testRmDir() |
|
246 { |
|
247 RFs fs; |
|
248 test(fs.Connect() == KErrNone); |
|
249 |
|
250 // Make sure the test stuff isn't there |
|
251 _LIT(KTestDir1, "c:\\symport_test_rfs6\\"); |
|
252 _LIT(KTestFile, "c:\\symport_test_rfs6\\testfile"); |
|
253 _LIT(KTestDir3, "c:\\symport_test_rfs6\\testfile\\"); |
|
254 fs.Delete(KTestFile); |
|
255 fs.RmDir(KTestDir1); |
|
256 |
|
257 // Create the directory and make sure you can delete it |
|
258 TUint att; |
|
259 test(fs.MkDir(KTestDir1) == KErrNone); |
|
260 test(fs.Att(KTestDir1, att) == KErrNone && att|KEntryAttDir); |
|
261 test(fs.RmDir(KTestDir1) == KErrNone); |
|
262 test(fs.RmDir(KTestDir1) == KErrNotFound); |
|
263 test(fs.Att(KTestDir1, att) == KErrNotFound); |
|
264 |
|
265 test(fs.MkDir(KTestDir1) == KErrNone); |
|
266 test(fs.Att(KTestDir1, att) == KErrNone && att|KEntryAttDir); |
|
267 |
|
268 RFile file; |
|
269 test(file.Create(fs, KTestFile, EFileShareAny|EFileWrite) == KErrNone); |
|
270 test(file.Write(_L8("test")) == KErrNone); |
|
271 file.Close(); |
|
272 |
|
273 // Check you can't delete a file or a none empty directory |
|
274 TInt err = fs.RmDir(KTestDir3); |
|
275 test(err == KErrNotFound || err == KErrPathNotFound); |
|
276 test(fs.RmDir(KTestDir1) == KErrInUse); |
|
277 test(fs.Delete(KTestFile) == KErrNone); |
|
278 test(fs.RmDir(KTestDir1) == KErrNone); |
|
279 |
|
280 // KErrInUse when removing a root directory |
|
281 test(fs.RmDir(_L("c:\\")) == KErrInUse); |
|
282 |
|
283 fs.Close(); |
|
284 } |
|
285 |
|
286 void testParse() |
|
287 { |
|
288 RFs fs; |
|
289 test(fs.Connect() == KErrNone); |
|
290 |
|
291 _LIT(KTestFile, "c:\\symport_test_rfs7.txt"); |
|
292 fs.Delete(KTestFile); |
|
293 |
|
294 // Parse file spec |
|
295 TParse parse; |
|
296 test(fs.Parse(KTestFile, parse) == KErrNone); |
|
297 |
|
298 // See if we can create the file |
|
299 RFile file; |
|
300 test(file.Create(fs, parse.FullName(), EFileShareAny|EFileWrite) == KErrNone); |
|
301 test(file.Write(_L8("test")) == KErrNone); |
|
302 file.Close(); |
|
303 test(fs.Delete(parse.FullName()) == KErrNone); |
|
304 |
|
305 fs.Close(); |
|
306 } |
|
307 |
|
308 void testSessionPath() |
|
309 { |
|
310 RFs fs; |
|
311 test(fs.Connect() == KErrNone); |
|
312 |
|
313 // Check we get a session path |
|
314 TFileName name; |
|
315 test(fs.SessionPath(name) == KErrNone); |
|
316 test(name.Length() > 0); |
|
317 |
|
318 // Check there's a backslash on the end and no forward slashes |
|
319 test(name[name.Length() - 1] == TChar('\\')); |
|
320 test(name.Locate(TChar('/')) == KErrNotFound); |
|
321 |
|
322 fs.Close(); |
|
323 } |
|
324 |
|
325 void testSetSessionPath() |
|
326 { |
|
327 RFs fs; |
|
328 test(fs.Connect() == KErrNone); |
|
329 |
|
330 _LIT(KTestDir1, "c:\\symport_test_rfs8\\"); |
|
331 _LIT(KTestFile1, "c:\\symport_test_rfs8\\test"); |
|
332 _LIT(KTestFilename1, "test"); |
|
333 fs.Delete(KTestFile1); |
|
334 fs.RmDir(KTestDir1); |
|
335 |
|
336 // Check we get a session path |
|
337 TFileName name; |
|
338 test(fs.SessionPath(name) == KErrNone); |
|
339 test(name.Length() > 0); |
|
340 |
|
341 // Check we can set it |
|
342 fs.SetSessionPath(KTestDir1); |
|
343 test(fs.MkDir(KTestDir1) == KErrNone); |
|
344 test(fs.SetSessionPath(KTestDir1) == KErrNone); |
|
345 |
|
346 // See if we can create a file in the session path |
|
347 RFile file; |
|
348 test(file.Create(fs, KTestFilename1, EFileShareAny|EFileWrite) == KErrNone); |
|
349 test(file.Write(_L8("test")) == KErrNone); |
|
350 file.Close(); |
|
351 |
|
352 // Check the file is there |
|
353 TUint att; |
|
354 test(fs.Att(KTestFile1, att) == KErrNone); |
|
355 test(fs.Delete(KTestFilename1) == KErrNone); |
|
356 |
|
357 // Reset session path! |
|
358 test(fs.SetSessionPath(name) == KErrNone); |
|
359 test(fs.RmDir(KTestDir1) == KErrNone); |
|
360 |
|
361 fs.Close(); |
|
362 } |
|
363 |
|
364 void testDelete() |
|
365 { |
|
366 RFs fs; |
|
367 test(fs.Connect() == KErrNone); |
|
368 |
|
369 _LIT(KTestDir, "c:\\symport_test_rfs9\\"); |
|
370 _LIT(KTestFile, "c:\\symport_test_rfs9"); |
|
371 fs.Delete(KTestFile); |
|
372 fs.RmDir(KTestDir); |
|
373 |
|
374 // Error if the file doesn't exist |
|
375 test(fs.Delete(KTestFile) == KErrNotFound); |
|
376 |
|
377 // Create the file |
|
378 RFile file; |
|
379 test(file.Create(fs, KTestFile, EFileShareAny|EFileWrite) == KErrNone); |
|
380 test(file.Write(_L8("test")) == KErrNone); |
|
381 |
|
382 |
|
383 |
|
384 // On Linux it seems it's perfectly correct to "delete" an open file |
|
385 |
|
386 // Removing an open file is sometimes recommended to hide the names of temporary files that may be prone to attack! |
|
387 |
|
388 TInt err = 0; |
|
389 #ifndef linux |
|
390 |
|
391 // Should be locked |
|
392 |
|
393 err = fs.Delete(KTestFile); |
|
394 test(err == KErrInUse || err == KErrAccessDenied); |
|
395 #endif |
|
396 |
|
397 file.Close(); |
|
398 |
|
399 // Check success |
|
400 test(fs.Delete(KTestFile) == KErrNone); |
|
401 test(fs.Delete(KTestFile) == KErrNotFound); |
|
402 |
|
403 // Check you can't delete a directory |
|
404 test(fs.MkDir(KTestDir) == KErrNone); |
|
405 test(fs.Delete(KTestFile) == KErrAccessDenied); |
|
406 |
|
407 err = fs.Delete(KTestDir); |
|
408 test(err == KErrBadName || err == KErrAccessDenied); |
|
409 test(fs.RmDir(KTestDir) == KErrNone); |
|
410 |
|
411 fs.Close(); |
|
412 } |
|
413 |
|
414 // This is only valid for TOOLS2 |
|
415 #ifdef __TOOLS2__ |
|
416 extern TInt gBlockSize; |
|
417 extern TInt gClusterSize; |
|
418 void testVolumeIOParam() |
|
419 { |
|
420 RFs fs; |
|
421 test(fs.Connect() == KErrNone); |
|
422 |
|
423 // We rely on this error code being returned - preventing STORE cleverness? |
|
424 TVolumeIOParamInfo param; |
|
425 param.iBlockSize = 0; |
|
426 param.iClusterSize = 0; |
|
427 param.iRecReadBufSize = 0; |
|
428 param.iRecWriteBufSize = 0; |
|
429 |
|
430 test(fs.VolumeIOParam(EDriveC, param) == KErrNone); |
|
431 |
|
432 test(param.iBlockSize == 4096); |
|
433 test(param.iClusterSize == 4096); |
|
434 test(param.iRecReadBufSize == 4096); |
|
435 test(param.iRecWriteBufSize == 4096); |
|
436 |
|
437 gBlockSize = 8096; |
|
438 gClusterSize = 8096; |
|
439 |
|
440 test(fs.VolumeIOParam(EDriveC, param) == KErrNone); |
|
441 |
|
442 test(param.iBlockSize == 8096); |
|
443 test(param.iClusterSize == 8096); |
|
444 test(param.iRecReadBufSize == 4096); |
|
445 test(param.iRecWriteBufSize == 4096); |
|
446 |
|
447 fs.Close(); |
|
448 } |
|
449 #endif |
|
450 |
|
451 void testEntry() |
|
452 { |
|
453 RFs fs; |
|
454 test(fs.Connect() == KErrNone); |
|
455 |
|
456 _LIT(KTestFile, "c:\\symport_test_rfs10"); |
|
457 _LIT(KTestDir, "c:\\symport_test_rfs10_dir\\"); |
|
458 fs.Delete(KTestFile); |
|
459 fs.RmDir(KTestDir); |
|
460 |
|
461 // Check error when file doesn't exist |
|
462 TEntry entry; |
|
463 test(fs.Entry(KTestFile, entry) == KErrNotFound); |
|
464 |
|
465 // Create test data |
|
466 TUidType testUid(TUid::Uid(0x1), TUid::Uid(0x2), TUid::Uid(0x3)); |
|
467 TCheckedUid checkedUid(testUid); |
|
468 TPckg<TCheckedUid> checkedUidBuf(checkedUid); |
|
469 |
|
470 // Create the file |
|
471 RFile file; |
|
472 test(file.Create(fs, KTestFile, EFileShareAny|EFileWrite) == KErrNone); |
|
473 test(file.Write(checkedUidBuf) == KErrNone); |
|
474 file.Close(); |
|
475 |
|
476 // Get file details |
|
477 User::After(1000000); |
|
478 test(fs.Entry(KTestFile, entry) == KErrNone); |
|
479 |
|
480 // Check the data looks right |
|
481 test(entry.iSize == checkedUidBuf.Length()); |
|
482 test(entry.iType == testUid); |
|
483 test(entry.iName == KTestFile().Mid(3)); // No path |
|
484 test(!(entry.iAtt&KEntryAttDir)); |
|
485 |
|
486 TTimeIntervalSeconds sec; |
|
487 TTime now; now.UniversalTime(); |
|
488 test(now.SecondsFrom(entry.iModified, sec) == KErrNone); |
|
489 test(sec.Int() >= 1); |
|
490 |
|
491 _LIT8(KTestText, "Some junk that is not a uid"); |
|
492 User::After(2000000); |
|
493 |
|
494 test(file.Replace(fs, KTestFile, EFileShareAny|EFileWrite) == KErrNone); |
|
495 test(file.Write(KTestText) == KErrNone); |
|
496 file.Close(); |
|
497 |
|
498 // Get file details |
|
499 test(fs.Entry(KTestFile, entry) == KErrNone); |
|
500 |
|
501 // Check the data looks right |
|
502 test(entry.iSize == KTestText().Length()); |
|
503 test(entry.iType == TUidType(TUid::Uid(0), TUid::Uid(0), TUid::Uid(0))); |
|
504 test(entry.iName == KTestFile().Mid(3)); // No path |
|
505 |
|
506 test(now.SecondsFrom(entry.iModified, sec) == KErrNone); |
|
507 test(sec.Int() <= -1); |
|
508 |
|
509 // Test it works for directories |
|
510 test(fs.Entry(KTestDir, entry) == KErrNotFound); |
|
511 test(fs.MkDir(KTestDir) == KErrNone); |
|
512 test(fs.Entry(KTestDir, entry) == KErrNone); |
|
513 test(entry.iSize == 0); |
|
514 test(entry.iType == TUidType(TUid::Null(), TUid::Null(), TUid::Null())); |
|
515 test(entry.iName == KTestDir().Mid(3, KTestDir().Length() - 4)); // Lose path and end slash |
|
516 test(entry.iAtt&KEntryAttDir); |
|
517 |
|
518 test(fs.Delete(KTestFile) == KErrNone); |
|
519 test(fs.RmDir(KTestDir) == KErrNone); |
|
520 fs.Close(); |
|
521 } |
|
522 |
|
523 void testSetEntry() |
|
524 { |
|
525 // Connect to the file system |
|
526 RFs fs; |
|
527 test(fs.Connect() == KErrNone); |
|
528 |
|
529 TTime start; |
|
530 start.UniversalTime(); |
|
531 |
|
532 // Make sure the file doesn't exist |
|
533 _LIT(KTestFile, "c:\\symport_test_rfs2b_test.txt"); |
|
534 fs.SetEntry(KTestFile, start, 0, KEntryAttReadOnly); |
|
535 fs.Delete(KTestFile); |
|
536 |
|
537 // File doesn't exist |
|
538 test(fs.SetEntry(KTestFile, start, KEntryAttReadOnly, 0) == KErrNotFound); |
|
539 |
|
540 // Create a file |
|
541 RFile file; |
|
542 test(file.Create(fs, KTestFile, EFileShareAny|EFileWrite) == KErrNone); |
|
543 test(file.Write(_L8("test")) == KErrNone); |
|
544 file.Close(); |
|
545 |
|
546 // Set readonly flag |
|
547 TUint att; |
|
548 test(fs.Att(KTestFile, att) == KErrNone && !(att&KEntryAttReadOnly)); |
|
549 test(fs.SetEntry(KTestFile, start, KEntryAttReadOnly, 0) == KErrNone); |
|
550 test(fs.Att(KTestFile, att) == KErrNone && att&KEntryAttReadOnly); |
|
551 |
|
552 // Clear readonly flag |
|
553 test(fs.SetEntry(KTestFile, start, 0, KEntryAttReadOnly) == KErrNone); |
|
554 test(fs.Att(KTestFile, att) == KErrNone && !(att&KEntryAttReadOnly)); |
|
555 |
|
556 test(fs.Delete(KTestFile) == KErrNone); |
|
557 fs.Close(); |
|
558 } |
|
559 |
|
560 // Only relevant to TOOLS2 |
|
561 #ifdef __TOOLS2__ |
|
562 void testSetErrorCondition() |
|
563 { |
|
564 RFs fs; |
|
565 test(fs.Connect() == KErrNone); |
|
566 test(fs.SetErrorCondition(KErrGeneral, 1) == KErrNotSupported); |
|
567 fs.Close(); |
|
568 } |
|
569 #endif |
|
570 |
|
571 void testCharToDrive() |
|
572 { |
|
573 RFs fs; |
|
574 test(fs.Connect() == KErrNone); |
|
575 |
|
576 TInt drive; |
|
577 |
|
578 // Test invalid |
|
579 test(fs.CharToDrive(TChar('$'), drive) == KErrArgument); |
|
580 |
|
581 // Test valid - upper and lower case |
|
582 test(fs.CharToDrive(TChar('a'), drive) == KErrNone && drive == EDriveA); |
|
583 test(fs.CharToDrive(TChar('A'), drive) == KErrNone && drive == EDriveA); |
|
584 test(fs.CharToDrive(TChar('z'), drive) == KErrNone && drive == EDriveZ); |
|
585 test(fs.CharToDrive(TChar('Z'), drive) == KErrNone && drive == EDriveZ); |
|
586 |
|
587 fs.Close(); |
|
588 } |
|
589 |
|
590 void testDriveToChar() |
|
591 { |
|
592 RFs fs; |
|
593 test(fs.Connect() == KErrNone); |
|
594 |
|
595 TChar dChar; |
|
596 |
|
597 // Test invalid |
|
598 test(fs.DriveToChar(99, dChar) == KErrArgument); |
|
599 |
|
600 // Ask for default drive |
|
601 test(fs.DriveToChar(KDefaultDrive, dChar) == KErrNone); |
|
602 |
|
603 test(TUint(dChar) >= TUint(TChar('A'))); |
|
604 |
|
605 test(TUint(dChar) <= TUint(TChar('Z'))); |
|
606 |
|
607 // Check valid |
|
608 test(fs.DriveToChar(EDriveA, dChar) == KErrNone && dChar == TChar('A')); |
|
609 test(fs.DriveToChar(EDriveZ, dChar) == KErrNone && dChar == TChar('Z')); |
|
610 |
|
611 fs.Close(); |
|
612 } |
|
613 |
|
614 void testIsValidDrive() |
|
615 { |
|
616 RFs fs; |
|
617 test(fs.Connect() == KErrNone); |
|
618 |
|
619 // Invalid |
|
620 test(!fs.IsValidDrive(99)); |
|
621 test(!fs.IsValidDrive(-99)); |
|
622 |
|
623 // Valid |
|
624 test(fs.IsValidDrive(KDefaultDrive)); |
|
625 test(fs.IsValidDrive(EDriveA)); |
|
626 test(fs.IsValidDrive(EDriveZ)); |
|
627 |
|
628 fs.Close(); |
|
629 } |
|
630 |
|
631 void testDrive() |
|
632 { |
|
633 RFs fs; |
|
634 test(fs.Connect() == KErrNone); |
|
635 |
|
636 // Test invalid drive |
|
637 TDriveInfo drive; |
|
638 test(fs.Drive(drive, 99) == KErrBadName); |
|
639 |
|
640 #ifdef __TOOLS2__ |
|
641 // Test valid drives |
|
642 test(fs.Drive(drive, EDriveC) == KErrNone); |
|
643 test(drive.iType == EMediaHardDisk && drive.iBattery == EBatNotSupported && drive.iDriveAtt&KDriveAttLocal|KDriveAttInternal && drive.iMediaAtt == 0); |
|
644 test(fs.Drive(drive, KDefaultDrive) == KErrNone); |
|
645 test(drive.iType == EMediaHardDisk && drive.iBattery == EBatNotSupported && drive.iDriveAtt&KDriveAttLocal|KDriveAttInternal && drive.iMediaAtt == 0); |
|
646 #endif |
|
647 |
|
648 fs.Close(); |
|
649 } |
|
650 |
|
651 void testGetSystemDrive() |
|
652 { |
|
653 RFs fs; |
|
654 test(fs.Connect() == KErrNone); |
|
655 test(fs.GetSystemDrive() == EDriveC); |
|
656 test(fs.GetSystemDriveChar() == TChar('C')); |
|
657 fs.Close(); |
|
658 } |
|
659 |
|
660 void testReplace() |
|
661 { |
|
662 RFs fs; |
|
663 test(fs.Connect() == KErrNone); |
|
664 |
|
665 _LIT(KTestFile1, "c:\\symport_test_rfs11a"); |
|
666 _LIT(KTestFile2, "c:\\symport_test_rfs11b"); |
|
667 |
|
668 fs.Delete(KTestFile1); |
|
669 fs.Delete(KTestFile2); |
|
670 |
|
671 // Error when file doesn't exist |
|
672 test(fs.Replace(KTestFile1, KTestFile2) == KErrNotFound); |
|
673 |
|
674 RFile file; |
|
675 test(file.Create(fs, KTestFile1, EFileShareAny|EFileWrite) == KErrNone); |
|
676 test(file.Write(_L8("test")) == KErrNone); |
|
677 file.Close(); |
|
678 |
|
679 // Test success |
|
680 test(fs.Replace(KTestFile1, KTestFile2) == KErrNone); |
|
681 |
|
682 TUint att; |
|
683 test(fs.Att(KTestFile1, att) == KErrNotFound); |
|
684 test(fs.Att(KTestFile2, att) == KErrNone); |
|
685 test(fs.Replace(KTestFile2, KTestFile1) == KErrNone); |
|
686 test(fs.Att(KTestFile1, att) == KErrNone); |
|
687 test(fs.Att(KTestFile2, att) == KErrNotFound); |
|
688 |
|
689 // Test when both files exist |
|
690 test(file.Create(fs, KTestFile2, EFileShareAny|EFileWrite) == KErrNone); |
|
691 test(file.Write(_L8("test")) == KErrNone); |
|
692 file.Close(); |
|
693 |
|
694 test(fs.Att(KTestFile1, att) == KErrNone); |
|
695 test(fs.Att(KTestFile2, att) == KErrNone); |
|
696 test(fs.Replace(KTestFile1, KTestFile2) == KErrNone); |
|
697 test(fs.Att(KTestFile1, att) == KErrNotFound); |
|
698 test(fs.Att(KTestFile2, att) == KErrNone); |
|
699 |
|
700 test(fs.Replace(KTestFile2, KTestFile1) == KErrNone); |
|
701 test(fs.Att(KTestFile1, att) == KErrNone); |
|
702 test(fs.Att(KTestFile2, att) == KErrNotFound); |
|
703 |
|
704 test(fs.Delete(KTestFile1) == KErrNone); |
|
705 fs.Close(); |
|
706 } |
|
707 |
|
708 void testRename() |
|
709 { |
|
710 RFs fs; |
|
711 test(fs.Connect() == KErrNone); |
|
712 |
|
713 _LIT(KTestFile1, "c:\\symport_test_rfs12a"); |
|
714 _LIT(KTestFile2, "c:\\symport_test_rfs12b"); |
|
715 |
|
716 _LIT(KTestDir1, "c:\\symport_test_rfs12a\\"); |
|
717 _LIT(KTestDir2, "c:\\symport_test_rfs12b\\"); |
|
718 |
|
719 fs.Delete(KTestFile1); |
|
720 fs.Delete(KTestFile2); |
|
721 fs.RmDir(KTestDir1); |
|
722 fs.RmDir(KTestDir2); |
|
723 |
|
724 // Error when source doesn't exist |
|
725 test(fs.Rename(KTestFile1, KTestFile2) == KErrNotFound); |
|
726 |
|
727 // Error when destination does exist |
|
728 RFile file; |
|
729 test(file.Create(fs, KTestFile1, EFileShareAny|EFileWrite) == KErrNone); |
|
730 test(file.Write(_L8("test")) == KErrNone); |
|
731 file.Close(); |
|
732 |
|
733 test(file.Create(fs, KTestFile2, EFileShareAny|EFileWrite) == KErrNone); |
|
734 test(file.Write(_L8("test")) == KErrNone); |
|
735 file.Close(); |
|
736 |
|
737 test(fs.Rename(KTestFile1, KTestFile2) == KErrAlreadyExists); |
|
738 test(fs.Delete(KTestFile2) == KErrNone); |
|
739 |
|
740 // Test Success |
|
741 test(fs.SetAtt(KTestFile1, 0, KEntryAttReadOnly) == KErrNone); |
|
742 test(fs.Rename(KTestFile1, KTestFile2) == KErrNone); |
|
743 |
|
744 TUint att; |
|
745 test(fs.Att(KTestFile1, att) == KErrNotFound); |
|
746 test(fs.Att(KTestFile2, att) == KErrNone); |
|
747 test(fs.Rename(KTestFile2, KTestFile1) == KErrNone); |
|
748 test(fs.Att(KTestFile1, att) == KErrNone); |
|
749 test(fs.Att(KTestFile2, att) == KErrNotFound); |
|
750 |
|
751 test(fs.Delete(KTestFile1) == KErrNone); |
|
752 |
|
753 fs.Close(); |
|
754 } |
|
755 |
|
756 TPtrC test_string=_L("Y:\\"); |
|
757 LOCAL_C void TestTParse1() |
|
758 // |
|
759 // Test all TParse methods |
|
760 // |
|
761 { |
|
762 TBuf<16> relatedFiles(_L(".CCC")); |
|
763 TBuf<16> defaultPath(_L("C:\\")); |
|
764 TParse parser; |
|
765 TInt r=parser.Set(_L("\\WWW\\XXX\\YYY\\ZZZ\\AAA"),&relatedFiles,&defaultPath); |
|
766 test(r==KErrNone); |
|
767 test(parser.FullName()==_L("C:\\WWW\\XXX\\YYY\\ZZZ\\AAA.CCC")); |
|
768 test(parser.Drive()==_L("C:")); |
|
769 test(parser.Path()==_L("\\WWW\\XXX\\YYY\\ZZZ\\")); |
|
770 test(parser.DriveAndPath()==_L("C:\\WWW\\XXX\\YYY\\ZZZ\\")); |
|
771 test(parser.Name()==_L("AAA")); |
|
772 test(parser.Ext()==_L(".CCC")); |
|
773 test(parser.NameAndExt()==_L("AAA.CCC")); |
|
774 test(parser.DrivePresent()==EFalse); |
|
775 test(parser.PathPresent()); |
|
776 test(parser.NamePresent()); |
|
777 test(parser.ExtPresent()==EFalse); |
|
778 test(parser.NameOrExtPresent()); |
|
779 test(parser.IsRoot()==EFalse); |
|
780 test(parser.IsWild()==EFalse); |
|
781 test(parser.IsNameWild()==EFalse); |
|
782 test(parser.IsExtWild()==EFalse); |
|
783 r=parser.SetNoWild(_L("\\WWW\\XXX\\YYY\\ZZZ\\AAA.EXT"),&relatedFiles,&defaultPath); |
|
784 test(r==KErrNone); |
|
785 test(parser.PopDir()==KErrNone); |
|
786 test(parser.AddDir(_L("BBB"))==KErrNone); |
|
787 } |
|
788 |
|
789 LOCAL_C void TestTParse2() |
|
790 // |
|
791 // Test multiple PopDirs |
|
792 // |
|
793 { |
|
794 |
|
795 TParse parser; |
|
796 TInt r=parser.Set(_L("\\WWW\\XXX\\YYY\\ZZZ\\"),NULL,NULL); |
|
797 // TParsePtrC parser(_L("\\WWW\\XXX\\YYY\\ZZZ\\")); |
|
798 test(r==KErrNone); |
|
799 r=parser.PopDir(); |
|
800 test(r==KErrNone); |
|
801 test(parser.Path()==_L("\\WWW\\XXX\\YYY\\")); |
|
802 r=parser.PopDir(); |
|
803 test(r==KErrNone); |
|
804 test(parser.Path()==_L("\\WWW\\XXX\\")); |
|
805 r=parser.PopDir(); |
|
806 test(r==KErrNone); |
|
807 test(parser.Path()==_L("\\WWW\\")); |
|
808 r=parser.PopDir(); |
|
809 test(r==KErrNone); |
|
810 test(parser.Path()==_L("\\")); |
|
811 r=parser.PopDir(); |
|
812 test(r==KErrGeneral); |
|
813 // |
|
814 test(parser.Set(_L("C:\\Documents\\.TXT"),NULL,NULL)==KErrNone); |
|
815 test(parser.PopDir()==KErrNone); |
|
816 test(parser.FullName()==_L("C:\\.TXT")); |
|
817 } |
|
818 |
|
819 LOCAL_C void TestTParse3() |
|
820 // |
|
821 // Test conflicting drive letters |
|
822 // |
|
823 { |
|
824 |
|
825 TParse parser; |
|
826 TPtrC one=_L("\\ONE\\"); |
|
827 TPtrC null=_L("\\"); |
|
828 TPtrC x=_L("X:"); |
|
829 TPtrC x2=_L("X:\\"); |
|
830 TPtrC z=_L("Z:"); |
|
831 TInt r=parser.Set(_L("Z:\\Hello"),&one,&null); |
|
832 test(r==KErrNone); |
|
833 test(parser.FullName()==_L("Z:\\Hello")); |
|
834 TPtrC sht=_L("*.SHT"); |
|
835 r=parser.Set(_L("Z:"),&sht,&x); |
|
836 test(r==KErrNone); |
|
837 test(parser.FullName()==_L("Z:*.SHT")); |
|
838 r=parser.Set(_L("Hello"),&z,&x2); |
|
839 test(r==KErrNone); |
|
840 test(parser.FullName()==_L("Z:\\Hello")); |
|
841 r=parser.Set(_L("W:\\Hello"),&z,&x2); |
|
842 test(r==KErrNone); |
|
843 test(parser.FullName()==_L("W:\\Hello")); |
|
844 TPtrC abcdefg=_L("abcdefg"); |
|
845 TPtrC onetwo=_L("X:\\ONE\\TWO\\.CCC"); |
|
846 r=parser.Set(_L("W:"),&abcdefg,&onetwo); |
|
847 test(r==KErrNone); |
|
848 test(parser.FullName()==_L("W:\\ONE\\TWO\\abcdefg.CCC")); |
|
849 TPtrC y=_L("Y:"); |
|
850 TPtrC xhello=_L("X:\\HELLO\\"); |
|
851 r=parser.Set(_L("World"),&y,&xhello); |
|
852 test(r==KErrNone); |
|
853 test(parser.FullName()==_L("Y:\\HELLO\\World")); |
|
854 TPtrC xhelloext=_L("X:\\HELLO\\.EXT"); |
|
855 r=parser.Set(_L("World"),&y,&xhelloext); |
|
856 test(r==KErrNone); |
|
857 test(parser.FullName()==_L("Y:\\HELLO\\World.EXT")); |
|
858 } |
|
859 |
|
860 LOCAL_C void TestTParse4() |
|
861 // |
|
862 // Conflicting relative path drives and names |
|
863 // |
|
864 { |
|
865 |
|
866 TParse parser; |
|
867 TPtrC xone=_L("X:\\ONE\\"); |
|
868 TPtrC y=_L("Y:\\"); |
|
869 TInt r=parser.Set(_L("Z:\\Hello"),&xone,&y); |
|
870 test(r==KErrNone); |
|
871 test(parser.FullName()==_L("Z:\\Hello")); |
|
872 TPtrC zone=_L("Z:\\ONE\\"); |
|
873 TPtrC xnew=_L("X:\\NEW\\"); |
|
874 r=parser.Set(_L("\\Hello"),&zone,&xnew); |
|
875 test(r==KErrNone); |
|
876 test(parser.FullName()==_L("Z:\\Hello")); |
|
877 TPtrC aone=_L("A:\\ONE\\"); |
|
878 TPtrC anew=_L("A:\\NEW\\"); |
|
879 r=parser.Set(_L("A:Hello"),&aone,&anew); |
|
880 test(r==KErrNone); |
|
881 test(parser.FullName()==_L("A:\\ONE\\Hello")); |
|
882 TPtrC a=_L("A:\\"); |
|
883 r=parser.Set(_L("Hello"),&a,&xnew); |
|
884 test(r==KErrNone); |
|
885 test(parser.FullName()==_L("A:\\Hello")); |
|
886 r=parser.Set(_L("Hello"),&aone,&xnew); |
|
887 test(r==KErrNone); |
|
888 test(parser.FullName()==_L("A:\\ONE\\Hello")); |
|
889 } |
|
890 |
|
891 |
|
892 LOCAL_C void TestTParse5() |
|
893 // |
|
894 // Test illegal paths |
|
895 // |
|
896 { |
|
897 |
|
898 TParse parser; |
|
899 TInt r=parser.Set(_L("FOO\\"),NULL,NULL); |
|
900 test(r==KErrBadName); |
|
901 r=parser.Set(_L("C:\\FOO\\\\"),NULL,NULL); |
|
902 test(r==KErrNone); |
|
903 } |
|
904 |
|
905 LOCAL_C void TestTParse6() |
|
906 // |
|
907 // Test AddDir |
|
908 // |
|
909 { |
|
910 |
|
911 TParse parser; |
|
912 test(parser.Set(_L("C:\\"),NULL,NULL)==KErrNone); |
|
913 test(parser.IsRoot()); |
|
914 test(parser.FullName()==_L("C:\\")); |
|
915 test(parser.AddDir(_L("HELLO"))==KErrNone); |
|
916 test(parser.IsRoot()==EFalse); |
|
917 test(parser.FullName()==_L("C:\\HELLO\\")); |
|
918 test(parser.AddDir(_L("BYEBYE"))==KErrNone); |
|
919 test(parser.IsRoot()==EFalse); |
|
920 test(parser.FullName()==_L("C:\\HELLO\\BYEBYE\\")); |
|
921 test(parser.PopDir()==KErrNone); |
|
922 test(parser.IsRoot()==EFalse); |
|
923 test(parser.FullName()==_L("C:\\HELLO\\")); |
|
924 test(parser.PopDir()==KErrNone); |
|
925 test(parser.IsRoot()); |
|
926 test(parser.FullName()==_L("C:\\")); |
|
927 // |
|
928 test(parser.AddDir(_L(""))==KErrNone); |
|
929 test(parser.IsRoot()); |
|
930 test(parser.FullName()==_L("C:\\")); |
|
931 test(parser.AddDir(_L("HELLO"))==KErrNone); |
|
932 test(parser.IsRoot()==EFalse); |
|
933 test(parser.FullName()==_L("C:\\HELLO\\")); |
|
934 test(parser.AddDir(_L(""))==KErrNone); |
|
935 test(parser.IsRoot()==EFalse); |
|
936 test(parser.FullName()==_L("C:\\HELLO\\")); |
|
937 // |
|
938 test(parser.Set(_L("C:\\Documents\\.TXT"),NULL,NULL)==KErrNone); |
|
939 test(parser.AddDir(_L("Documents"))==KErrNone); |
|
940 test(parser.FullName()==_L("C:\\Documents\\Documents\\.TXT")); |
|
941 } |
|
942 |
|
943 LOCAL_C void TestTParse7() |
|
944 // |
|
945 // Test TParsePtr |
|
946 // |
|
947 { |
|
948 |
|
949 TBuf<128> nameBuf=_L("C:\\WWW\\XXX\\YYY\\ZZZ\\AAA.CCC"); |
|
950 TParsePtr parser(nameBuf); |
|
951 |
|
952 test(parser.FullName()==_L("C:\\WWW\\XXX\\YYY\\ZZZ\\AAA.CCC")); |
|
953 test(parser.Drive()==_L("C:")); |
|
954 test(parser.Path()==_L("\\WWW\\XXX\\YYY\\ZZZ\\")); |
|
955 test(parser.DriveAndPath()==_L("C:\\WWW\\XXX\\YYY\\ZZZ\\")); |
|
956 test(parser.Name()==_L("AAA")); |
|
957 test(parser.Ext()==_L(".CCC")); |
|
958 test(parser.NameAndExt()==_L("AAA.CCC")); |
|
959 test(parser.DrivePresent()); |
|
960 test(parser.PathPresent()); |
|
961 test(parser.NamePresent()); |
|
962 test(parser.ExtPresent()); |
|
963 test(parser.NameOrExtPresent()); |
|
964 test(parser.IsRoot()==EFalse); |
|
965 test(parser.IsWild()==EFalse); |
|
966 test(parser.IsNameWild()==EFalse); |
|
967 test(parser.IsExtWild()==EFalse); |
|
968 |
|
969 test(parser.AddDir(_L("HELLO"))==KErrNone); |
|
970 test(parser.Path()==_L("\\WWW\\XXX\\YYY\\ZZZ\\HELLO\\")); |
|
971 |
|
972 TBuf<16> shortName=_L("1234567812345678"); |
|
973 TParsePtr parser2(shortName); |
|
974 test(parser2.FullName()==_L("1234567812345678")); |
|
975 test(parser2.Path()==_L("")); |
|
976 test(parser2.DriveAndPath()==_L("")); |
|
977 test(parser2.Ext()==_L("")); |
|
978 test(parser2.Name()==_L("1234567812345678")); |
|
979 test(parser2.AddDir(_L("TOOBIG"))==KErrGeneral); |
|
980 } |
|
981 |
|
982 LOCAL_C void TestTParse8() |
|
983 // |
|
984 // Test TParsePtrC |
|
985 // |
|
986 { |
|
987 |
|
988 TBuf<128> nameBuf=_L("C:\\WWW\\XXX\\YYY\\ZZZ\\AAA.CCC"); |
|
989 TParsePtrC parser(nameBuf); |
|
990 |
|
991 test(parser.FullName()==_L("C:\\WWW\\XXX\\YYY\\ZZZ\\AAA.CCC")); |
|
992 test(parser.Drive()==_L("C:")); |
|
993 test(parser.Path()==_L("\\WWW\\XXX\\YYY\\ZZZ\\")); |
|
994 test(parser.DriveAndPath()==_L("C:\\WWW\\XXX\\YYY\\ZZZ\\")); |
|
995 test(parser.Name()==_L("AAA")); |
|
996 test(parser.Ext()==_L(".CCC")); |
|
997 test(parser.NameAndExt()==_L("AAA.CCC")); |
|
998 test(parser.DrivePresent()); |
|
999 test(parser.PathPresent()); |
|
1000 test(parser.NamePresent()); |
|
1001 test(parser.ExtPresent()); |
|
1002 test(parser.NameOrExtPresent()); |
|
1003 test(parser.IsRoot()==EFalse); |
|
1004 test(parser.IsWild()==EFalse); |
|
1005 test(parser.IsNameWild()==EFalse); |
|
1006 test(parser.IsExtWild()==EFalse); |
|
1007 } |
|
1008 |
|
1009 LOCAL_C void TestTParse9() |
|
1010 // |
|
1011 // Test names with leading spaces |
|
1012 // |
|
1013 { |
|
1014 |
|
1015 TParse parser; |
|
1016 TBuf<16> nameBuf=_L(" name.txt"); |
|
1017 TBuf<16> pathBuf=_L("\\PATH\\"); |
|
1018 |
|
1019 TInt r=parser.Set(pathBuf,NULL,&nameBuf); |
|
1020 test(r==KErrNone); |
|
1021 test(parser.FullName()==_L("\\PATH\\ name.txt")); |
|
1022 r=parser.Set(_L(""),&nameBuf,&pathBuf); |
|
1023 test(r==KErrNone); |
|
1024 test(parser.FullName()==_L("\\PATH\\ name.txt")); |
|
1025 r=parser.Set(_L(" name.txt"),NULL,&pathBuf); |
|
1026 test(r==KErrNone); |
|
1027 test(parser.FullName()==_L("\\PATH\\ name.txt")); |
|
1028 r=parser.Set(nameBuf,&pathBuf,NULL); |
|
1029 test(r==KErrNone); |
|
1030 test(parser.FullName()==_L("\\PATH\\ name.txt")); |
|
1031 |
|
1032 TBuf<16> badPath=_L(" \\PATH\\"); |
|
1033 r=parser.Set(_L("C:\\"),NULL,&badPath); |
|
1034 test(r==KErrBadName); |
|
1035 r=parser.Set(_L("C:\\"),&badPath,NULL); |
|
1036 test(r==KErrBadName); |
|
1037 |
|
1038 TBuf<16> spacePath=_L("\\ PATH\\"); |
|
1039 r=parser.Set(_L("C:"),&nameBuf,&spacePath); |
|
1040 test(r==KErrNone); |
|
1041 test(parser.FullName()==_L("C:\\ PATH\\ name.txt")); |
|
1042 |
|
1043 TBuf<32> spacename=_L("\\ name . txt "); |
|
1044 r=parser.Set(_L("C:"),&spacename,NULL); |
|
1045 test(r==KErrNone); |
|
1046 test(parser.FullName()==_L("C:\\ name . txt")); |
|
1047 |
|
1048 // Illegal (?) values |
|
1049 |
|
1050 TBuf<16> pureSpace=_L(" "); |
|
1051 r=parser.Set(_L("C:\\NAME\\"),NULL,&pureSpace); |
|
1052 test(r==KErrNone); |
|
1053 test(parser.FullName()==_L("C:\\NAME\\")); // Trims right off name |
|
1054 r=parser.Set(_L("C:\\NAME\\ "),NULL,NULL); |
|
1055 test(r==KErrNone); |
|
1056 test(parser.FullName()==_L("C:\\NAME\\")); |
|
1057 |
|
1058 TBuf<16> spacePlusExt=_L(" . ext "); |
|
1059 r=parser.Set(_L("C:\\NAME\\"),NULL,&spacePlusExt); |
|
1060 test(r==KErrNone); |
|
1061 test(parser.FullName()==_L("C:\\NAME\\ . ext")); // Trims right off ext |
|
1062 r=parser.Set(_L("C:\\NAME\\ . ext "),NULL,NULL); |
|
1063 test(r==KErrNone); |
|
1064 test(parser.FullName()==_L("C:\\NAME\\ . ext")); |
|
1065 |
|
1066 TBuf<32> pathSpace=_L("\\asdf\\zxcv\\ \\asdf\\"); |
|
1067 r=parser.Set(_L("C:"),NULL,&pathSpace); |
|
1068 test(r==KErrNone); |
|
1069 test(parser.FullName()==_L("C:\\asdf\\zxcv\\ \\asdf\\")); // Leaves spaces in path |
|
1070 r=parser.Set(_L("C:\\NAME\\ \\alt.sdf"),NULL,NULL); |
|
1071 test(r==KErrNone); |
|
1072 test(parser.FullName()==_L("C:\\NAME\\ \\alt.sdf")); |
|
1073 |
|
1074 |
|
1075 TBuf<32> zeroPath=_L("\\asdf\\wqer\\\\asdf\\"); |
|
1076 r=parser.Set(_L("NAME.TXT"),NULL,&zeroPath); |
|
1077 test(r==KErrNone); |
|
1078 test(parser.FullName()==_L("\\asdf\\wqer\\\\asdf\\NAME.TXT")); // Leaves zerolength path |
|
1079 r=parser.Set(_L("C:\\NAME\\\\alt.sdf"),NULL,NULL); |
|
1080 test(r==KErrNone); |
|
1081 test(parser.FullName()==_L("C:\\NAME\\\\alt.sdf")); |
|
1082 } |
|
1083 |
|
1084 LOCAL_C void TestTParse10() |
|
1085 // |
|
1086 // Test a very long path |
|
1087 // |
|
1088 { |
|
1089 |
|
1090 TBuf<16> pathPart=_L("\\2345678"); |
|
1091 TBuf<512> testPath; |
|
1092 |
|
1093 for(TInt i=0;i<63;i++) |
|
1094 testPath+=pathPart; |
|
1095 |
|
1096 RFs fs; |
|
1097 TInt r=fs.Connect(); |
|
1098 test(r==KErrNone); |
|
1099 TParse parse; |
|
1100 r=fs.Parse(testPath,parse); |
|
1101 test(r==KErrBadName); |
|
1102 fs.Close(); |
|
1103 |
|
1104 TFileName longFileName; |
|
1105 longFileName.SetLength(254); |
|
1106 // Mem::Fill((TUint8*)longFileName.Ptr(),254,'A'); |
|
1107 Mem::Fill((TUint8*)longFileName.Ptr(),254*sizeof(TText),'A'); |
|
1108 longFileName[0]='\\'; |
|
1109 longFileName[253]='\\'; |
|
1110 r=parse.Set(longFileName,&test_string,NULL); |
|
1111 test(r==KErrNone); |
|
1112 r=parse.PopDir(); |
|
1113 test(r==KErrNone); |
|
1114 |
|
1115 longFileName[123]='\\'; |
|
1116 r=parse.Set(longFileName,&test_string,NULL); |
|
1117 test(r==KErrNone); |
|
1118 r=parse.PopDir(); |
|
1119 test(r==KErrNone); |
|
1120 TPtrC startPath((TText*)longFileName.Ptr(),124); |
|
1121 test(parse.Path()==startPath); |
|
1122 |
|
1123 TPtrC endPath((TText*)longFileName.Ptr()+124,252-124+1); |
|
1124 r=parse.AddDir(endPath); |
|
1125 test(r==KErrNone); |
|
1126 test(parse.Path()==longFileName); |
|
1127 } |
|
1128 |
|
1129 LOCAL_C void testTFileTextApi() |
|
1130 // |
|
1131 // Test TFileText class methods |
|
1132 // |
|
1133 { |
|
1134 |
|
1135 TPtrC record[5]; |
|
1136 record[0].Set(_L("First record")); |
|
1137 record[1].Set(_L("Second record")); |
|
1138 record[2].Set(_L("Third record")); |
|
1139 record[3].Set(_L("Fourth record")); |
|
1140 record[4].Set(_L("Fifth record")); |
|
1141 |
|
1142 RFs fs; |
|
1143 test(fs.Connect() == KErrNone); |
|
1144 |
|
1145 RFile f; |
|
1146 TInt r=f.Replace(fs,_L("TEXTFILE.TXT"),0); |
|
1147 test(r==KErrNone); |
|
1148 TFileText textFile; |
|
1149 textFile.Set(f); |
|
1150 TInt i=0; |
|
1151 for (i=0;i<5;i++) |
|
1152 { |
|
1153 r=textFile.Write(record[i]); |
|
1154 test(r==KErrNone); |
|
1155 } |
|
1156 r=textFile.Seek(ESeekStart); |
|
1157 test(r==KErrNone); |
|
1158 TBuf<16> recBuf; |
|
1159 for(i=0;i<5;i++) |
|
1160 { |
|
1161 r=textFile.Read(recBuf); |
|
1162 test(r==KErrNone); |
|
1163 test(recBuf==record[i]); |
|
1164 } |
|
1165 r=textFile.Read(recBuf); |
|
1166 test(r==KErrEof); |
|
1167 test(recBuf.Length()==0); |
|
1168 f.Close(); |
|
1169 |
|
1170 test.Next(_L("Test dosfile terminator")); |
|
1171 TPtrC8 trecord[7]; |
|
1172 TPtrC tTextrecord[7]; |
|
1173 tTextrecord[0].Set(_L("First record\r\n")); |
|
1174 tTextrecord[1].Set(_L("Second record\r\n")); |
|
1175 tTextrecord[2].Set(_L("Third record\r\n")); |
|
1176 tTextrecord[3].Set(_L("Fourth record\r\n")); |
|
1177 tTextrecord[4].Set(_L("Fifth record\r\n")); |
|
1178 tTextrecord[5].Set(_L("Sixth record\n\r")); |
|
1179 tTextrecord[6].Set(_L("Seventh record\n")); |
|
1180 trecord[0].Set((TUint8*)tTextrecord[0].Ptr(),tTextrecord[0].Length()*sizeof(TText)); |
|
1181 trecord[1].Set((TUint8*)tTextrecord[1].Ptr(),tTextrecord[1].Length()*sizeof(TText)); |
|
1182 trecord[2].Set((TUint8*)tTextrecord[2].Ptr(),tTextrecord[2].Length()*sizeof(TText)); |
|
1183 trecord[3].Set((TUint8*)tTextrecord[3].Ptr(),tTextrecord[3].Length()*sizeof(TText)); |
|
1184 trecord[4].Set((TUint8*)tTextrecord[4].Ptr(),tTextrecord[4].Length()*sizeof(TText)); |
|
1185 trecord[5].Set((TUint8*)tTextrecord[5].Ptr(),tTextrecord[5].Length()*sizeof(TText)); |
|
1186 trecord[6].Set((TUint8*)tTextrecord[6].Ptr(),tTextrecord[6].Length()*sizeof(TText)); |
|
1187 r=f.Replace(fs,_L("TEXTFILE.TXT"),0); |
|
1188 test(r==KErrNone); |
|
1189 for(i=0;i<7;i++) |
|
1190 { |
|
1191 TBuf8<256> buf; |
|
1192 buf.Copy(trecord[i]); |
|
1193 r=f.Write(buf); |
|
1194 test(r==KErrNone); |
|
1195 } |
|
1196 textFile.Set(f); |
|
1197 textFile.Seek(ESeekStart); |
|
1198 for(i=0;i<5;i++) |
|
1199 { |
|
1200 r=textFile.Read(recBuf); |
|
1201 test(r==KErrNone); |
|
1202 test(recBuf==record[i]); |
|
1203 } |
|
1204 r=textFile.Read(recBuf); |
|
1205 test(r==KErrNone); |
|
1206 test(recBuf==_L("Sixth record")); |
|
1207 r=textFile.Read(recBuf); |
|
1208 test(r==KErrNone); |
|
1209 test(recBuf==_L("\rSeventh record")); |
|
1210 r=textFile.Read(recBuf); |
|
1211 test(r==KErrEof); |
|
1212 test(recBuf.Length()==0); |
|
1213 f.Close(); |
|
1214 |
|
1215 test.Next(_L("Test read with bufferSize == dataSize")); |
|
1216 r=f.Replace(fs,_L("TEXTFILE.TXT"),0); |
|
1217 test(r==KErrNone); |
|
1218 record[0].Set(_L("1234567890123456")); |
|
1219 // trecord[0].Set(_L8("1234567890123456\r\n")); |
|
1220 // trecord[1].Set(_L8("1234567890123456\n")); |
|
1221 |
|
1222 TPtrC tmpTextrecord; |
|
1223 tmpTextrecord.Set(_L("1234567890123456\r\n")); |
|
1224 trecord[0].Set((TUint8*)tmpTextrecord.Ptr(),tmpTextrecord.Length()*sizeof(TText)); |
|
1225 |
|
1226 tmpTextrecord.Set(_L("1234567890123456\n")); |
|
1227 trecord[1].Set((TUint8*)tmpTextrecord.Ptr(),tmpTextrecord.Length()*sizeof(TText)); |
|
1228 |
|
1229 for (i=0;i<2;i++) |
|
1230 { |
|
1231 r=f.Write(trecord[i]); |
|
1232 test(r==KErrNone); |
|
1233 } |
|
1234 textFile.Set(f); |
|
1235 textFile.Seek(ESeekStart); |
|
1236 for(i=0;i<2;i++) |
|
1237 { |
|
1238 r=textFile.Read(recBuf); |
|
1239 test(r==KErrNone); |
|
1240 test(recBuf==record[0]); |
|
1241 } |
|
1242 r=textFile.Read(recBuf); |
|
1243 test(r==KErrEof); |
|
1244 test(recBuf.Length()==0); |
|
1245 f.Close(); |
|
1246 |
|
1247 test.Next(_L("Read into a buffer < recordSize")); |
|
1248 TBuf<8> smallBuf; |
|
1249 r=f.Open(fs,_L("TEXTFILE.txt"),0); |
|
1250 test(r==KErrNone); |
|
1251 textFile.Set(f); |
|
1252 for(i=0;i<2;i++) |
|
1253 { |
|
1254 r=textFile.Read(smallBuf); |
|
1255 test(r==KErrTooBig); |
|
1256 test(smallBuf==_L("12345678")); |
|
1257 } |
|
1258 f.Close(); |
|
1259 |
|
1260 test.Next(_L("Nasty cases: 1) split over buffer boundary")); |
|
1261 r=f.Replace(fs,_L("TEXTFILE.txt"),0); |
|
1262 test(r==KErrNone); |
|
1263 HBufC* largeRecord=HBufC::NewL(600); |
|
1264 largeRecord->Des().SetLength(250); |
|
1265 largeRecord->Des().Fill('A'); |
|
1266 largeRecord->Des()[249]='\n'; |
|
1267 TPtrC8 bufPtr; |
|
1268 bufPtr.Set((TUint8*)largeRecord->Ptr(),largeRecord->Size()); // Size() returns length in bytes |
|
1269 r=f.Write(bufPtr); |
|
1270 test(r==KErrNone); |
|
1271 TBuf<16> boundaryBuf=_L("12345\r\n"); |
|
1272 bufPtr.Set((TUint8*)boundaryBuf.Ptr(),boundaryBuf.Size()); |
|
1273 r=f.Write(bufPtr); |
|
1274 test(r==KErrNone); |
|
1275 r=f.Write(trecord[0]); |
|
1276 test(r==KErrNone); |
|
1277 |
|
1278 textFile.Set(f); |
|
1279 textFile.Seek(ESeekStart); |
|
1280 r=textFile.Read(recBuf); |
|
1281 test(r==KErrTooBig); |
|
1282 test(recBuf==_L("AAAAAAAAAAAAAAAA")); |
|
1283 r=textFile.Read(recBuf); |
|
1284 test(r==KErrNone); |
|
1285 test(recBuf==_L("12345")); |
|
1286 r=textFile.Read(recBuf); |
|
1287 test(r==KErrNone); |
|
1288 test(recBuf==record[0]); |
|
1289 f.Close(); |
|
1290 |
|
1291 test.Next(_L("Nasty cases: 2) on buffer boundary")); |
|
1292 r=f.Replace(fs,_L("TEXTFILE.txt"),0); |
|
1293 test(r==KErrNone); |
|
1294 largeRecord->Des().SetLength(250); |
|
1295 largeRecord->Des().Fill('A'); |
|
1296 largeRecord->Des()[249]='\n'; |
|
1297 bufPtr.Set((TUint8*)largeRecord->Ptr(),largeRecord->Size()); |
|
1298 r=f.Write(bufPtr); |
|
1299 test(r==KErrNone); |
|
1300 boundaryBuf=_L("12345\rxyz\n"); |
|
1301 bufPtr.Set((TUint8*)boundaryBuf.Ptr(),boundaryBuf.Size()); |
|
1302 r=f.Write(bufPtr); |
|
1303 test(r==KErrNone); |
|
1304 r=f.Write(trecord[0]); |
|
1305 test(r==KErrNone); |
|
1306 |
|
1307 textFile.Set(f); |
|
1308 textFile.Seek(ESeekStart); |
|
1309 r=textFile.Read(recBuf); |
|
1310 test(r==KErrTooBig); |
|
1311 test(recBuf==_L("AAAAAAAAAAAAAAAA")); |
|
1312 r=textFile.Read(recBuf); |
|
1313 test(r==KErrNone); |
|
1314 test(recBuf==_L("12345\rxyz")); |
|
1315 r=textFile.Read(recBuf); |
|
1316 test(r==KErrNone); |
|
1317 test(recBuf==record[0]); |
|
1318 f.Close(); |
|
1319 |
|
1320 test.Next(_L("Nasty cases: 3) record size > buffer size")); |
|
1321 r=f.Replace(fs,_L("TEXTFILE.txt"),0); |
|
1322 test(r==KErrNone); |
|
1323 largeRecord->Des().SetLength(600); |
|
1324 largeRecord->Des().Fill('Z'); |
|
1325 largeRecord->Des()[511]='\r'; |
|
1326 largeRecord->Des()[599]='\n'; |
|
1327 bufPtr.Set((TUint8*)largeRecord->Ptr(),largeRecord->Size()); |
|
1328 r=f.Write(bufPtr); |
|
1329 test(r==KErrNone); |
|
1330 boundaryBuf=_L("12345\rxyz\n"); |
|
1331 bufPtr.Set((TUint8*)boundaryBuf.Ptr(),boundaryBuf.Size()); |
|
1332 r=f.Write(bufPtr); |
|
1333 test(r==KErrNone); |
|
1334 r=f.Write(trecord[0]); |
|
1335 test(r==KErrNone); |
|
1336 |
|
1337 textFile.Set(f); |
|
1338 textFile.Seek(ESeekStart); |
|
1339 r=textFile.Read(recBuf); |
|
1340 test(r==KErrTooBig); |
|
1341 test(recBuf==_L("ZZZZZZZZZZZZZZZZ")); |
|
1342 r=textFile.Read(recBuf); |
|
1343 test(r==KErrNone); |
|
1344 test(recBuf==_L("12345\rxyz")); |
|
1345 r=textFile.Read(recBuf); |
|
1346 test(r==KErrNone); |
|
1347 test(recBuf==record[0]); |
|
1348 |
|
1349 TBuf<601> bigBuf; |
|
1350 TPtrC largePtr((TText*)largeRecord->Ptr(),(largeRecord->Length()-1)); |
|
1351 textFile.Seek(ESeekStart); |
|
1352 r=textFile.Read(bigBuf); |
|
1353 test(r==KErrNone); |
|
1354 test(bigBuf==largePtr); |
|
1355 r=textFile.Read(recBuf); |
|
1356 test(r==KErrNone); |
|
1357 test(recBuf==_L("12345\rxyz")); |
|
1358 r=textFile.Read(recBuf); |
|
1359 test(r==KErrNone); |
|
1360 test(recBuf==record[0]); |
|
1361 f.Close(); |
|
1362 |
|
1363 User::Free(largeRecord); |
|
1364 test(fs.Delete(_L("TEXTFILE.txt")) == KErrNone); |
|
1365 fs.Close(); |
|
1366 } |
|
1367 |
|
1368 LOCAL_C void testTFileTextEndRecord() |
|
1369 // |
|
1370 // Test terminating record |
|
1371 // |
|
1372 { |
|
1373 RFs fs; |
|
1374 test(fs.Connect() == KErrNone); |
|
1375 |
|
1376 RFile f; |
|
1377 TInt r=f.Replace(fs,_L("TextFile"),0); |
|
1378 test(r==KErrNone); |
|
1379 TPtrC8 bufPtr; |
|
1380 TBuf<16>boundaryBuf=_L("Record1\n"); |
|
1381 bufPtr.Set((TUint8*)boundaryBuf.Ptr(),boundaryBuf.Size()); |
|
1382 r=f.Write(bufPtr); |
|
1383 test(r==KErrNone); |
|
1384 boundaryBuf=_L("Record2\n"); |
|
1385 bufPtr.Set((TUint8*)boundaryBuf.Ptr(),boundaryBuf.Size()); |
|
1386 r=f.Write(bufPtr); |
|
1387 test(r==KErrNone); |
|
1388 boundaryBuf=_L("Record3\n"); |
|
1389 bufPtr.Set((TUint8*)boundaryBuf.Ptr(),boundaryBuf.Size()); |
|
1390 r=f.Write(bufPtr); |
|
1391 test(r==KErrNone); |
|
1392 |
|
1393 TFileText fText; |
|
1394 fText.Set(f); |
|
1395 r=fText.Seek(ESeekStart); |
|
1396 test(r==KErrNone); |
|
1397 TBuf<32> recBuf; |
|
1398 r=fText.Read(recBuf); |
|
1399 test(r==KErrNone); |
|
1400 test(recBuf.MatchF(_L("record1"))!=KErrNotFound); |
|
1401 r=fText.Read(recBuf); |
|
1402 test(r==KErrNone); |
|
1403 test(recBuf.MatchF(_L("record2"))!=KErrNotFound); |
|
1404 r=fText.Read(recBuf); |
|
1405 test(r==KErrNone); |
|
1406 test(recBuf.MatchF(_L("record3"))!=KErrNotFound); |
|
1407 r=fText.Read(recBuf); |
|
1408 test(r==KErrEof); |
|
1409 test(recBuf.Length()==0); |
|
1410 f.Close(); |
|
1411 |
|
1412 TBuf<0x100> bigBuf(0x100); |
|
1413 bigBuf.Fill('A'); |
|
1414 r=f.Replace(fs,_L("TextFile"),0); |
|
1415 test(r==KErrNone); |
|
1416 |
|
1417 bufPtr.Set((TUint8*)bigBuf.Ptr(),bigBuf.Size()); |
|
1418 r=f.Write(bufPtr); |
|
1419 test(r==KErrNone); |
|
1420 |
|
1421 fText.Set(f); |
|
1422 r=fText.Seek(ESeekStart); |
|
1423 test(r==KErrNone); |
|
1424 bigBuf.SetLength(0); |
|
1425 r=fText.Read(bigBuf); |
|
1426 // test.Printf(_L("fText.Read returns %d\n"),r); |
|
1427 test(r==KErrNone); |
|
1428 // test.Printf(_L("BigBuf.Length()==%d\n"),bigBuf.Length()); |
|
1429 test(bigBuf.Length()==0x100); |
|
1430 r=fText.Read(bigBuf); |
|
1431 test(r==KErrEof); |
|
1432 test(bigBuf.Length()==0); |
|
1433 f.Close(); |
|
1434 |
|
1435 test(fs.Delete(_L("TextFile")) == KErrNone); |
|
1436 fs.Close(); |
|
1437 } |
|
1438 |
|
1439 void testRFileOpen() |
|
1440 { |
|
1441 _LIT(KTestFile, "c:\\symport_test_rfile_open"); |
|
1442 _LIT8(KTestText, "abcdefghijklmnopqrstuvwxyz"); |
|
1443 |
|
1444 RFs fs; |
|
1445 test(fs.Connect() == KErrNone); |
|
1446 |
|
1447 fs.SetAtt(KTestFile, 0, KEntryAttReadOnly); |
|
1448 fs.Delete(KTestFile); |
|
1449 |
|
1450 // File doesn't exist |
|
1451 RFile file; |
|
1452 test(file.Open(fs, KTestFile, 0) == KErrNotFound); |
|
1453 |
|
1454 // Create the file |
|
1455 test(file.Create(fs, KTestFile, 0) == KErrNone); |
|
1456 test(file.Write(KTestText) == KErrNone); |
|
1457 |
|
1458 // Should be okay to close a file twice |
|
1459 file.Close(); |
|
1460 file.Close(); |
|
1461 |
|
1462 // Open the file for reading |
|
1463 TBuf8<26> buf; |
|
1464 test(file.Open(fs, KTestFile, EFileShareAny) == KErrNone); |
|
1465 test(file.Read(buf) == KErrNone && buf == KTestText); |
|
1466 |
|
1467 // Check you can't write to it |
|
1468 test(file.Write(KTestText) == KErrAccessDenied); |
|
1469 |
|
1470 // Check another file can be opened at the same time |
|
1471 RFile file2; |
|
1472 test(file2.Open(fs, KTestFile, EFileShareAny) == KErrNone); |
|
1473 test(file2.Read(buf) == KErrNone && buf == KTestText); |
|
1474 file2.Close(); |
|
1475 test(file2.Open(fs, KTestFile, EFileShareAny|EFileWrite) == KErrNone); |
|
1476 file2.Close(); |
|
1477 file.Close(); |
|
1478 |
|
1479 // Open the file for writing |
|
1480 test(file.Open(fs, KTestFile, EFileShareAny|EFileWrite) == KErrNone); |
|
1481 test(file.Read(buf) == KErrNone && buf == KTestText); |
|
1482 |
|
1483 // Check you can write to it |
|
1484 test(file.Write(KTestText) == KErrNone); |
|
1485 |
|
1486 // Check another file can be opened at the same time |
|
1487 test(file2.Open(fs, KTestFile, EFileShareAny|EFileRead) == KErrNone); |
|
1488 file2.Close(); |
|
1489 test(file2.Open(fs, KTestFile, EFileShareAny|EFileWrite) == KErrNone); |
|
1490 file2.Close(); |
|
1491 |
|
1492 // Read back what we just wrote |
|
1493 file.Close(); |
|
1494 test(file.Open(fs, KTestFile, 0) == KErrNone); |
|
1495 test(file.Read(buf) == KErrNone && buf == KTestText); |
|
1496 test(file.Read(buf) == KErrNone && buf == KTestText); |
|
1497 file.Close(); |
|
1498 |
|
1499 // Check error on read only file |
|
1500 test(fs.SetAtt(KTestFile, KEntryAttReadOnly, 0) == KErrNone); |
|
1501 test(file.Open(fs, KTestFile, EFileWrite) == KErrAccessDenied); |
|
1502 test(fs.SetAtt(KTestFile, 0, KEntryAttReadOnly) == KErrNone); |
|
1503 test(file.Open(fs, KTestFile, EFileWrite) == KErrNone); |
|
1504 file.Close(); |
|
1505 |
|
1506 test(fs.Delete(KTestFile) == KErrNone); |
|
1507 fs.Close(); |
|
1508 } |
|
1509 |
|
1510 void testRFileCreate() |
|
1511 { |
|
1512 _LIT(KTestFile, "c:\\symport_test_rfile_create"); |
|
1513 _LIT8(KTestText, "abcdefghijklmnopqrstuvwxyz"); |
|
1514 |
|
1515 RFs fs; |
|
1516 test(fs.Connect() == KErrNone); |
|
1517 fs.Delete(KTestFile); |
|
1518 |
|
1519 // Create should work when file doesn't exist |
|
1520 RFile file; |
|
1521 test(file.Create(fs, KTestFile, 0) == KErrNone); |
|
1522 test(file.Write(KTestText) == KErrNone); |
|
1523 file.Close(); |
|
1524 |
|
1525 // Create should fail when file does exist |
|
1526 test(file.Create(fs, KTestFile, 0) == KErrAlreadyExists); |
|
1527 test(fs.Delete(KTestFile) == KErrNone); |
|
1528 |
|
1529 // Check you can read from the file |
|
1530 test(file.Create(fs, KTestFile, 0) == KErrNone); |
|
1531 test(file.Write(KTestText) == KErrNone); |
|
1532 TInt pos = 0; |
|
1533 test(file.Seek(ESeekStart, pos) == KErrNone); |
|
1534 TBuf8<26> buf; |
|
1535 test(file.Read(buf) == KErrNone && buf == KTestText); |
|
1536 test(file.Write(KTestText) == KErrNone); |
|
1537 pos = 26; |
|
1538 test(file.Seek(ESeekStart, pos) == KErrNone); |
|
1539 test(file.Read(buf) == KErrNone && buf == KTestText); |
|
1540 file.Close(); |
|
1541 |
|
1542 // Check error on read only file |
|
1543 test(fs.SetAtt(KTestFile, KEntryAttReadOnly, 0) == KErrNone); |
|
1544 test(file.Replace(fs, KTestFile, EFileWrite) == KErrAccessDenied); |
|
1545 test(fs.SetAtt(KTestFile, 0, KEntryAttReadOnly) == KErrNone); |
|
1546 test(file.Replace(fs, KTestFile, EFileWrite) == KErrNone); |
|
1547 file.Close(); |
|
1548 |
|
1549 fs.Delete(KTestFile); |
|
1550 fs.Close(); |
|
1551 } |
|
1552 |
|
1553 void testRFileReplace() |
|
1554 { |
|
1555 _LIT(KTestFile, "c:\\symport_test_rfile_replace"); |
|
1556 _LIT8(KTestText, "abcdefghijklmnopqrstuvwxyz"); |
|
1557 |
|
1558 RFs fs; |
|
1559 test(fs.Connect() == KErrNone); |
|
1560 fs.Delete(KTestFile); |
|
1561 |
|
1562 // Reaplce should work when file doesn't exist |
|
1563 RFile file; |
|
1564 test(file.Replace(fs, KTestFile, 0) == KErrNone); |
|
1565 test(file.Write(KTestText) == KErrNone); |
|
1566 file.Close(); |
|
1567 |
|
1568 // Replace should also work when file does exist |
|
1569 test(file.Replace(fs, KTestFile, 0) == KErrNone); |
|
1570 test(file.Write(KTestText) == KErrNone); |
|
1571 |
|
1572 // Check you can read from the file |
|
1573 TInt pos = 0; |
|
1574 test(file.Seek(ESeekStart, pos) == KErrNone); |
|
1575 TBuf8<26> buf; |
|
1576 test(file.Read(buf) == KErrNone && buf == KTestText); |
|
1577 test(file.Write(KTestText) == KErrNone); |
|
1578 pos = 26; |
|
1579 test(file.Seek(ESeekStart, pos) == KErrNone); |
|
1580 test(file.Read(buf) == KErrNone && buf == KTestText); |
|
1581 file.Close(); |
|
1582 |
|
1583 fs.Delete(KTestFile); |
|
1584 fs.Close(); |
|
1585 } |
|
1586 |
|
1587 void testRFileTemp() |
|
1588 { |
|
1589 _LIT(KTestDir, "c:\\symport_test_rfile_temp\\"); |
|
1590 _LIT8(KTestText, "abcdefghijklmnopqrstuvwxyz"); |
|
1591 |
|
1592 RFs fs; |
|
1593 test(fs.Connect() == KErrNone); |
|
1594 fs.MkDir(KTestDir); |
|
1595 |
|
1596 TFileName f1; |
|
1597 RFile file; |
|
1598 |
|
1599 // Use invalid path |
|
1600 test(file.Temp(fs, _L("invalid"), f1, 0) == KErrBadName); |
|
1601 test(file.Temp(fs, _L("invalid\\"), f1, 0) == KErrBadName); |
|
1602 |
|
1603 // Try to use a file for the path |
|
1604 test(file.Replace(fs, _L("invalid"), 0) == KErrNone); |
|
1605 file.Close(); |
|
1606 test(file.Temp(fs, _L("invalid"), f1, 0) == KErrBadName); |
|
1607 test(fs.Delete(_L("invalid")) == KErrNone); |
|
1608 |
|
1609 test(file.Temp(fs, KTestDir, f1, 0) == KErrNone); |
|
1610 test(file.Write(KTestText) == KErrNone); |
|
1611 file.Close(); |
|
1612 |
|
1613 // Check it works a second time |
|
1614 TFileName f2; |
|
1615 test(file.Temp(fs, KTestDir, f2, 0) == KErrNone); |
|
1616 |
|
1617 // Check you can read from the file |
|
1618 test(file.Write(KTestText) == KErrNone); |
|
1619 TInt pos = 0; |
|
1620 test(file.Seek(ESeekStart, pos) == KErrNone); |
|
1621 TBuf8<26> buf; |
|
1622 test(file.Read(buf) == KErrNone && buf == KTestText); |
|
1623 test(file.Write(KTestText) == KErrNone); |
|
1624 pos = 26; |
|
1625 test(file.Seek(ESeekStart, pos) == KErrNone); |
|
1626 test(file.Read(buf) == KErrNone && buf == KTestText); |
|
1627 file.Close(); |
|
1628 |
|
1629 test(fs.Delete(f1) == KErrNone); |
|
1630 test(fs.Delete(f2) == KErrNone); |
|
1631 |
|
1632 // See if you can create a temp on root |
|
1633 test(file.Temp(fs, _L("C:\\"), f1, 0) == KErrNone); |
|
1634 file.Close(); |
|
1635 test(fs.Delete(f1) == KErrNone); |
|
1636 |
|
1637 // See if empty path is okay |
|
1638 test(file.Temp(fs, KNullDesC, f1, 0) == KErrNone); |
|
1639 file.Close(); |
|
1640 test(fs.Delete(f1) == KErrNone); |
|
1641 |
|
1642 fs.RmDir(KTestDir); |
|
1643 fs.Close(); |
|
1644 } |
|
1645 |
|
1646 void testRFileRead() |
|
1647 { |
|
1648 _LIT(KTestFile, "c:\\symport_test_rfile_read"); |
|
1649 _LIT8(KTestText, "abcdefghijklmnopqrstuvwxyz"); |
|
1650 |
|
1651 RFs fs; |
|
1652 test(fs.Connect() == KErrNone); |
|
1653 |
|
1654 // Create a test file |
|
1655 RFile file; |
|
1656 test(file.Replace(fs, KTestFile, EFileWrite) == KErrNone); |
|
1657 test(file.Write(KTestText) == KErrNone); |
|
1658 file.Close(); |
|
1659 |
|
1660 TBuf8<13> buf; |
|
1661 test(file.Open(fs, KTestFile, 0) == KErrNone); |
|
1662 |
|
1663 // File position at the start |
|
1664 TInt pos = 0; |
|
1665 test(file.Seek(ESeekCurrent, pos) == KErrNone); |
|
1666 test(pos == 0); |
|
1667 |
|
1668 test(file.Read(buf) == KErrNone); |
|
1669 test(buf.Length() == 13 && buf == KTestText().Left(13)); |
|
1670 |
|
1671 // Check file position is updated |
|
1672 pos = 0; |
|
1673 test(file.Seek(ESeekCurrent, pos) == KErrNone); |
|
1674 test(pos == 13); |
|
1675 |
|
1676 test(file.Read(buf) == KErrNone); |
|
1677 test(buf.Length() == 13 && buf == KTestText().Right(13)); |
|
1678 test(file.Read(buf) == KErrNone); |
|
1679 test(buf.Length() == 0); |
|
1680 |
|
1681 pos = 13; |
|
1682 test(file.Seek(ESeekStart, pos) == KErrNone); |
|
1683 test(file.Read(buf) == KErrNone); |
|
1684 test(buf.Length() == 13 && buf == KTestText().Right(13)); |
|
1685 test(file.Read(buf) == KErrNone); |
|
1686 test(buf.Length() == 0); |
|
1687 |
|
1688 // Move back to the start |
|
1689 pos = 0; |
|
1690 test(file.Seek(ESeekStart, pos) == KErrNone); |
|
1691 |
|
1692 test(file.Read(buf, 6) == KErrNone); |
|
1693 test(buf.Length() == 6 && buf == KTestText().Left(6)); |
|
1694 pos = 20; |
|
1695 test(file.Seek(ESeekStart, pos) == KErrNone); |
|
1696 test(file.Read(buf, 6) == KErrNone); |
|
1697 test(buf.Length() == 6 && buf == KTestText().Right(6)); |
|
1698 test(file.Read(buf, 1) == KErrNone); |
|
1699 test(buf.Length() == 0); |
|
1700 |
|
1701 test(file.Read(0, buf) == KErrNone); |
|
1702 test(buf.Length() == 13 && buf == KTestText().Left(13)); |
|
1703 test(file.Read(13, buf) == KErrNone); |
|
1704 test(buf.Length() == 13 && buf == KTestText().Right(13)); |
|
1705 test(file.Read(23, buf) == KErrNone); |
|
1706 test(buf.Length() == 3 && buf == KTestText().Right(3)); |
|
1707 test(file.Read(27, buf) == KErrNone); |
|
1708 test(buf.Length() == 0); |
|
1709 |
|
1710 test(file.Read(0, buf, 6) == KErrNone); |
|
1711 test(buf.Length() == 6 && buf == KTestText().Left(6)); |
|
1712 test(file.Read(20, buf, 6) == KErrNone); |
|
1713 test(buf.Length() == 6 && buf == KTestText().Right(6)); |
|
1714 test(file.Read(23, buf, 6) == KErrNone); |
|
1715 test(buf.Length() == 3 && buf == KTestText().Right(3)); |
|
1716 test(file.Read(27, buf, 6) == KErrNone); |
|
1717 test(buf.Length() == 0); |
|
1718 |
|
1719 file.Close(); |
|
1720 |
|
1721 test(fs.Delete(KTestFile) == KErrNone); |
|
1722 fs.Close(); |
|
1723 } |
|
1724 |
|
1725 void testRFileWrite() |
|
1726 { |
|
1727 _LIT(KTestFile, "c:\\symport_test_rfile_write"); |
|
1728 _LIT8(KTestText, "abcdefghijklm"); |
|
1729 |
|
1730 RFs fs; |
|
1731 test(fs.Connect() == KErrNone); |
|
1732 |
|
1733 TBuf8<26> buf; |
|
1734 RFile file; |
|
1735 test(file.Replace(fs, KTestFile, 0) == KErrNone); |
|
1736 test(file.Read(buf) == KErrNone && buf.Length() == 0); |
|
1737 |
|
1738 // File position at the start |
|
1739 TInt pos = 0; |
|
1740 test(file.Seek(ESeekCurrent, pos) == KErrNone); |
|
1741 test(pos == 0); |
|
1742 |
|
1743 test(file.Write(KTestText) == KErrNone); //13 |
|
1744 |
|
1745 // Check position updated |
|
1746 pos = 0; |
|
1747 test(file.Seek(ESeekCurrent, pos) == KErrNone); |
|
1748 test(pos == 13); |
|
1749 |
|
1750 test(file.Read(0, buf) == KErrNone && buf == KTestText); |
|
1751 test(file.Write(KTestText) == KErrNone); //26 |
|
1752 test(file.Read(0, buf) == KErrNone && buf.Length() == 26 && buf.Left(13) == KTestText && buf.Right(13) == KTestText); |
|
1753 file.Close(); |
|
1754 |
|
1755 // Test read after write |
|
1756 test(file.Open(fs, KTestFile, EFileWrite) == KErrNone); |
|
1757 test(file.Write(KTestText) == KErrNone); |
|
1758 test(file.Read(buf) == KErrNone); |
|
1759 test(buf.Length() == 13); |
|
1760 file.Close(); |
|
1761 |
|
1762 // Test write after read |
|
1763 test(file.Open(fs, KTestFile, EFileWrite) == KErrNone); |
|
1764 test(file.Read(buf) == KErrNone && buf.Length() == 26); |
|
1765 test(file.Write(KTestText) == KErrNone); |
|
1766 test(file.Read(26, buf) == KErrNone && buf.Length() == 13); |
|
1767 file.Close(); |
|
1768 |
|
1769 test(file.Replace(fs, KTestFile, 0) == KErrNone); |
|
1770 test(file.Read(buf) == KErrNone && buf.Length() == 0); |
|
1771 test(file.Write(KTestText, 6) == KErrNone); //6 |
|
1772 test(file.Read(0, buf) == KErrNone && buf == KTestText().Left(6)); |
|
1773 test(file.Write(KTestText, 6) == KErrNone); //12 |
|
1774 test(file.Read(0, buf) == KErrNone && buf.Length() == 12 && buf.Left(6) == KTestText().Left(6) && buf.Right(6) == KTestText().Left(6)); |
|
1775 file.Close(); |
|
1776 |
|
1777 // Test read after write |
|
1778 test(file.Open(fs, KTestFile, EFileWrite) == KErrNone); |
|
1779 test(file.Write(KTestText, 6) == KErrNone); //6 |
|
1780 test(file.Read(buf) == KErrNone && buf.Length() == 6); |
|
1781 file.Close(); |
|
1782 |
|
1783 // Test write after read |
|
1784 test(file.Open(fs, KTestFile, EFileWrite) == KErrNone); |
|
1785 test(file.Read(buf) == KErrNone && buf.Length() == 12); |
|
1786 test(file.Write(KTestText, 6) == KErrNone); |
|
1787 test(file.Read(12, buf) == KErrNone && buf.Length() == 6); |
|
1788 file.Close(); |
|
1789 |
|
1790 test(file.Replace(fs, KTestFile, 0) == KErrNone); |
|
1791 test(file.Read(buf) == KErrNone && buf.Length() == 0); |
|
1792 test(file.Write(3, KTestText) == KErrNone); //0+13=13 |
|
1793 test(file.Read(0, buf) == KErrNone); |
|
1794 test(buf.Length() == 13); |
|
1795 test(buf == KTestText); |
|
1796 test(file.Write(7, KTestText) == KErrNone); //7+13=20 |
|
1797 test(file.Read(0, buf) == KErrNone && buf.Length() == 20 && buf.Mid(7,13) == KTestText()); |
|
1798 file.Close(); |
|
1799 |
|
1800 // Test read after write |
|
1801 test(file.Open(fs, KTestFile, EFileWrite) == KErrNone); |
|
1802 test(file.Write(0, KTestText) == KErrNone); //13 |
|
1803 test(file.Read(buf) == KErrNone && buf.Length() == 7); |
|
1804 file.Close(); |
|
1805 |
|
1806 // Test write after read |
|
1807 test(file.Open(fs, KTestFile, EFileWrite) == KErrNone); |
|
1808 test(file.Read(buf) == KErrNone && buf.Length() == 20); |
|
1809 test(file.Write(10, KTestText) == KErrNone); //10+13=23 |
|
1810 test(file.Read(0, buf) == KErrNone && buf.Length() == 23); |
|
1811 file.Close(); |
|
1812 |
|
1813 test(file.Replace(fs, KTestFile, 0) == KErrNone); |
|
1814 test(file.Read(buf) == KErrNone && buf.Length() == 0); |
|
1815 test(file.Write(3, KTestText, 10) == KErrNone); //0+10=10 |
|
1816 test(file.Read(0, buf) == KErrNone); |
|
1817 test(buf.Length() == 10 && buf == KTestText().Left(10)); |
|
1818 test(file.Write(0, KTestText, 3) == KErrNone); //10 |
|
1819 test(file.Read(0, buf) == KErrNone ); |
|
1820 test(buf.Length() == 10); |
|
1821 test(buf.Left(3) == KTestText().Left(3)); |
|
1822 file.Close(); |
|
1823 |
|
1824 // Test read after write |
|
1825 test(file.Open(fs, KTestFile, EFileWrite) == KErrNone); |
|
1826 test(file.Write(0, KTestText, 3) == KErrNone); //3 |
|
1827 test(file.Read(buf) == KErrNone); |
|
1828 test(buf.Length() == 7); |
|
1829 file.Close(); |
|
1830 |
|
1831 // Test write after read |
|
1832 test(file.Open(fs, KTestFile, EFileWrite) == KErrNone); |
|
1833 test(file.Read(buf) == KErrNone && buf.Length() == 10); |
|
1834 test(file.Write(13, KTestText, 6) == KErrNone); //10+6=16 |
|
1835 test(file.Read(0, buf) == KErrNone && buf.Length() == 16); |
|
1836 file.Close(); |
|
1837 |
|
1838 test(fs.Delete(KTestFile) == KErrNone); |
|
1839 fs.Close(); |
|
1840 } |
|
1841 |
|
1842 void testRFileSeek() |
|
1843 { |
|
1844 _LIT(KTestFile, "c:\\symport_test_rfile_seek"); |
|
1845 _LIT8(KTestText, "abcdefghijklmnopqrstuvwxyz"); |
|
1846 |
|
1847 RFs fs; |
|
1848 test(fs.Connect() == KErrNone); |
|
1849 |
|
1850 // Create the file |
|
1851 RFile file; |
|
1852 test(file.Replace(fs, KTestFile, EFileWrite) == KErrNone); |
|
1853 test(file.Write(KTestText) == KErrNone); |
|
1854 |
|
1855 // ESeekAddress is invalid |
|
1856 TInt pos = 0; |
|
1857 test(file.Seek(ESeekAddress, pos) == KErrNotSupported); |
|
1858 |
|
1859 // Error on negative offset |
|
1860 pos = -999; |
|
1861 test(file.Seek(ESeekStart, pos) == KErrArgument); |
|
1862 |
|
1863 // Test you can get the file position |
|
1864 pos = 12; |
|
1865 test(file.Seek(ESeekStart, pos) == KErrNone); |
|
1866 test(pos == 12); |
|
1867 TBuf8<26> buf; |
|
1868 test(file.Read(buf, 1) == KErrNone); |
|
1869 test(buf == _L8("m")); //13 |
|
1870 |
|
1871 pos = 0; |
|
1872 test(file.Seek(ESeekCurrent, pos) == KErrNone); |
|
1873 test(pos == 13); |
|
1874 |
|
1875 // Move to the end of the file |
|
1876 pos = 30; |
|
1877 test(file.Seek(ESeekStart, pos) == KErrNone); |
|
1878 test(pos == 30); |
|
1879 test(file.Size(pos) == KErrNone); |
|
1880 test(pos == 26); |
|
1881 |
|
1882 // Move back from the end |
|
1883 pos = -1; |
|
1884 test(file.Seek(ESeekEnd, pos) == KErrNone); |
|
1885 test(pos == 25); |
|
1886 test(file.Read(buf) == KErrNone); |
|
1887 test(buf == _L8("z")); |
|
1888 |
|
1889 // Move past the end |
|
1890 pos = 10; |
|
1891 test(file.Seek(ESeekEnd, pos) == KErrNone); |
|
1892 test(pos == 26); |
|
1893 test(file.Read(buf) == KErrNone); |
|
1894 test(buf.Length() == 0); |
|
1895 |
|
1896 // Move before the start |
|
1897 pos = -30; |
|
1898 test(file.Seek(ESeekEnd, pos) == KErrNone); |
|
1899 test(pos == 0); |
|
1900 test(file.Read(buf) == KErrNone); |
|
1901 test(buf.Length() == 26); |
|
1902 |
|
1903 // Check seek to current |
|
1904 pos = 13; |
|
1905 test(file.Seek(ESeekStart, pos) == KErrNone); |
|
1906 test(file.Read(buf, 1) == KErrNone); //14 |
|
1907 test(buf == _L8("n")); |
|
1908 pos = -13; |
|
1909 test(file.Seek(ESeekCurrent, pos) == KErrNone); |
|
1910 test(pos == 1); |
|
1911 test(file.Read(buf, 1) == KErrNone); //2 |
|
1912 test(buf == _L8("b")); |
|
1913 |
|
1914 // Before the start |
|
1915 pos = -10; |
|
1916 test(file.Seek(ESeekCurrent, pos) == KErrNone); |
|
1917 test(pos == 0); |
|
1918 test(file.Read(buf, 1) == KErrNone); //1 |
|
1919 test(buf == _L8("a")); |
|
1920 |
|
1921 // After the end |
|
1922 pos = 26; |
|
1923 test(file.Seek(ESeekCurrent, pos) == KErrNone); |
|
1924 test(pos == 26); |
|
1925 test(file.Read(buf, 1) == KErrNone); |
|
1926 test(buf.Length() == 0); |
|
1927 |
|
1928 // Check current pos |
|
1929 pos = 0; |
|
1930 test(file.Seek(ESeekCurrent, pos) == KErrNone); |
|
1931 test(pos == 26); |
|
1932 |
|
1933 // And check you can go back |
|
1934 pos = -1; |
|
1935 test(file.Seek(ESeekCurrent, pos) == KErrNone); |
|
1936 test(file.Read(buf, 1) == KErrNone); |
|
1937 test(buf == _L8("z")); |
|
1938 |
|
1939 file.Close(); |
|
1940 test(fs.Delete(KTestFile) == KErrNone); |
|
1941 fs.Close(); |
|
1942 } |
|
1943 |
|
1944 void testRFileFlush() |
|
1945 { |
|
1946 _LIT(KTestFile, "c:\\symport_test_rfile_flush"); |
|
1947 _LIT8(KTestText, "abcdefghijklmnopqrstuvwxyz"); |
|
1948 |
|
1949 RFs fs; |
|
1950 test(fs.Connect() == KErrNone); |
|
1951 fs.Delete(KTestFile); |
|
1952 |
|
1953 // Create the file |
|
1954 RFile file; |
|
1955 test(file.Replace(fs, KTestFile, EFileWrite) == KErrNone); |
|
1956 |
|
1957 // Check file pos |
|
1958 TInt pos = 0; |
|
1959 test(file.Seek(ESeekCurrent, pos) == KErrNone); |
|
1960 test(pos == 0); |
|
1961 |
|
1962 test(file.Write(KTestText) == KErrNone); |
|
1963 |
|
1964 // Check file pos |
|
1965 pos = 0; |
|
1966 test(file.Seek(ESeekCurrent, pos) == KErrNone); |
|
1967 test(pos == 26); |
|
1968 |
|
1969 test(file.Flush() == KErrNone); |
|
1970 |
|
1971 // Check file pos hasn't changed |
|
1972 pos = 0; |
|
1973 test(file.Seek(ESeekCurrent, pos) == KErrNone); |
|
1974 test(pos == 26); |
|
1975 |
|
1976 file.Close(); |
|
1977 |
|
1978 test(fs.Delete(KTestFile) == KErrNone); |
|
1979 fs.Close(); |
|
1980 } |
|
1981 |
|
1982 void testRFileSize() |
|
1983 { |
|
1984 _LIT(KTestFile, "c:\\symport_test_rfile_flush"); |
|
1985 _LIT8(KTestText, "abcdefghijklmnopqrstuvwxyz"); |
|
1986 |
|
1987 RFs fs; |
|
1988 test(fs.Connect() == KErrNone); |
|
1989 fs.Delete(KTestFile); |
|
1990 |
|
1991 // Create the file |
|
1992 RFile file; |
|
1993 test(file.Replace(fs, KTestFile, EFileWrite) == KErrNone); |
|
1994 |
|
1995 TInt size = 0; |
|
1996 test(file.Size(size) == KErrNone); |
|
1997 test(size == 0); |
|
1998 |
|
1999 // Check file pos |
|
2000 TInt pos = 0; |
|
2001 test(file.Seek(ESeekCurrent, pos) == KErrNone); |
|
2002 test(pos == 0); |
|
2003 |
|
2004 test(file.Write(KTestText) == KErrNone); |
|
2005 |
|
2006 size = 0; |
|
2007 test(file.Size(size) == KErrNone); |
|
2008 test(size == 26); |
|
2009 |
|
2010 // Check file pos |
|
2011 pos = 0; |
|
2012 test(file.Seek(ESeekCurrent, pos) == KErrNone); |
|
2013 test(pos == 26); |
|
2014 |
|
2015 file.Close(); |
|
2016 |
|
2017 test(fs.Delete(KTestFile) == KErrNone); |
|
2018 fs.Close(); |
|
2019 } |
|
2020 |
|
2021 void testRFileSetSize() |
|
2022 { |
|
2023 _LIT(KTestFile, "c:\\symport_test_rfile_flush"); |
|
2024 _LIT8(KTestText, "abcdefghijklmnopqrstuvwxyz"); |
|
2025 |
|
2026 RFs fs; |
|
2027 test(fs.Connect() == KErrNone); |
|
2028 fs.Delete(KTestFile); |
|
2029 |
|
2030 // Create the file |
|
2031 RFile file; |
|
2032 test(file.Replace(fs, KTestFile, EFileWrite) == KErrNone); |
|
2033 |
|
2034 // Check file pos |
|
2035 TInt pos = 0; |
|
2036 test(file.Seek(ESeekCurrent, pos) == KErrNone); |
|
2037 test(pos == 0); |
|
2038 |
|
2039 test(file.Write(KTestText) == KErrNone); //26 |
|
2040 |
|
2041 // Set the size to bigger |
|
2042 test(file.SetSize(30) == KErrNone); |
|
2043 |
|
2044 // Check file pos is unchanged |
|
2045 pos = 0; |
|
2046 test(file.Seek(ESeekCurrent, pos) == KErrNone); |
|
2047 test(pos == 26); |
|
2048 |
|
2049 // Set the size to smaller |
|
2050 test(file.SetSize(20) == KErrNone); |
|
2051 |
|
2052 // Check file pos is at the end |
|
2053 pos = 0; |
|
2054 test(file.Seek(ESeekCurrent, pos) == KErrNone); |
|
2055 test(pos == 20); |
|
2056 |
|
2057 file.Close(); |
|
2058 |
|
2059 // Open for reading |
|
2060 test(file.Open(fs, KTestFile, 0) == KErrNone); |
|
2061 |
|
2062 // Shouldn't be allowed to set the size |
|
2063 test(file.SetSize(10) == KErrAccessDenied); |
|
2064 |
|
2065 file.Close(); |
|
2066 |
|
2067 test(fs.Delete(KTestFile) == KErrNone); |
|
2068 fs.Close(); |
|
2069 } |
|
2070 |
|
2071 void testRFileAtt() |
|
2072 { |
|
2073 // Connect to the file system |
|
2074 RFs fs; |
|
2075 test(fs.Connect() == KErrNone); |
|
2076 |
|
2077 _LIT(KTestFile, "c:\\symport_test_rile_att.txt"); |
|
2078 |
|
2079 // See if it works for normal files |
|
2080 TUint att; |
|
2081 RFile file; |
|
2082 test(file.Replace(fs, KTestFile, EFileShareAny|EFileWrite) == KErrNone); |
|
2083 |
|
2084 // Check file pos is at the start |
|
2085 TInt pos = 0; |
|
2086 test(file.Seek(ESeekCurrent, pos) == KErrNone); |
|
2087 test(pos == 0); |
|
2088 |
|
2089 test(file.Write(_L8("test")) == KErrNone); |
|
2090 test(file.Att(att) == KErrNone); |
|
2091 test(!(att&KEntryAttDir)); |
|
2092 |
|
2093 // Check file pos is correct |
|
2094 pos = 0; |
|
2095 test(file.Seek(ESeekCurrent, pos) == KErrNone); |
|
2096 test(pos == 4); |
|
2097 |
|
2098 // Check readonly flag |
|
2099 test(!(att&KEntryAttReadOnly)); |
|
2100 test(file.SetAtt(KEntryAttReadOnly, 0) == KErrNone); |
|
2101 test(file.Att(att) == KErrNone && att&KEntryAttReadOnly); |
|
2102 |
|
2103 // Clear the flag |
|
2104 test(file.SetAtt(0, KEntryAttReadOnly) == KErrNone); |
|
2105 test(file.Att(att) == KErrNone); |
|
2106 test(!(att&KEntryAttReadOnly)); |
|
2107 file.Close(); |
|
2108 |
|
2109 // Delete the file |
|
2110 test(fs.Delete(KTestFile) == KErrNone); |
|
2111 fs.Close(); |
|
2112 } |
|
2113 |
|
2114 void testRFileModified() |
|
2115 { |
|
2116 // Connect to the file system |
|
2117 RFs fs; |
|
2118 test(fs.Connect() == KErrNone); |
|
2119 |
|
2120 _LIT(KTestFile, "c:\\symport_test_rile_modified.txt"); |
|
2121 |
|
2122 // See if it works for normal files |
|
2123 RFile file; |
|
2124 test(file.Replace(fs, KTestFile, EFileShareAny|EFileWrite) == KErrNone); |
|
2125 |
|
2126 // Check file pos is at the start |
|
2127 TInt pos = 0; |
|
2128 test(file.Seek(ESeekCurrent, pos) == KErrNone); |
|
2129 test(pos == 0); |
|
2130 |
|
2131 test(file.Write(_L8("test")) == KErrNone); |
|
2132 test(file.Flush() == KErrNone); |
|
2133 |
|
2134 TTime then; |
|
2135 test(file.Modified(then) == KErrNone); |
|
2136 User::After(2000000); |
|
2137 |
|
2138 // Check file pos is correct |
|
2139 pos = 0; |
|
2140 test(file.Seek(ESeekCurrent, pos) == KErrNone); |
|
2141 test(pos == 4); |
|
2142 |
|
2143 file.Close(); |
|
2144 |
|
2145 test(file.Open(fs, KTestFile, EFileWrite) == KErrNone); |
|
2146 test(file.Write(_L8("test")) == KErrNone); |
|
2147 test(file.Flush() == KErrNone); |
|
2148 |
|
2149 TTime now; |
|
2150 test(file.Modified(now) == KErrNone); |
|
2151 |
|
2152 TTimeIntervalSeconds sec; |
|
2153 test(now.SecondsFrom(then, sec) == KErrNone); |
|
2154 test(sec.Int() >= 1); |
|
2155 |
|
2156 file.Close(); |
|
2157 |
|
2158 // Delete the file |
|
2159 test(fs.Delete(KTestFile) == KErrNone); |
|
2160 fs.Close(); |
|
2161 } |
|
2162 |
|
2163 void testRFileDrive() |
|
2164 { |
|
2165 // Connect to the file system |
|
2166 RFs fs; |
|
2167 test(fs.Connect() == KErrNone); |
|
2168 |
|
2169 _LIT(KTestFile, "c:\\symport_test_rile_drive.txt"); |
|
2170 |
|
2171 // See if it works for normal files |
|
2172 RFile file; |
|
2173 test(file.Replace(fs, KTestFile, EFileShareAny|EFileWrite) == KErrNone); |
|
2174 |
|
2175 TInt drive; |
|
2176 TDriveInfo info; |
|
2177 |
|
2178 test(file.Drive(drive, info) == KErrNone); |
|
2179 test(drive == EDriveC); |
|
2180 |
|
2181 #ifdef __TOOLS2__ |
|
2182 test(info.iType == EMediaHardDisk); |
|
2183 test(info.iBattery == EBatNotSupported); |
|
2184 test(info.iDriveAtt&(KDriveAttLocal|KDriveAttInternal)); |
|
2185 test(info.iMediaAtt == 0); |
|
2186 #endif |
|
2187 |
|
2188 file.Close(); |
|
2189 |
|
2190 // Delete the file |
|
2191 test(fs.Delete(KTestFile) == KErrNone); |
|
2192 file.Close(); |
|
2193 fs.Close(); |
|
2194 } |
|
2195 |
|
2196 void testRFileRename() |
|
2197 { |
|
2198 // Connect to the file system |
|
2199 RFs fs; |
|
2200 test(fs.Connect() == KErrNone); |
|
2201 |
|
2202 _LIT(KTestFile1, "c:\\symport_test_rile_rename_a.txt"); |
|
2203 _LIT(KTestFile2, "c:\\symport_test_rile_rename_b.txt"); |
|
2204 fs.Delete(KTestFile1); |
|
2205 fs.Delete(KTestFile2); |
|
2206 |
|
2207 // See if it works for normal files |
|
2208 RFile file; |
|
2209 test(file.Replace(fs, KTestFile1, EFileShareExclusive|EFileWrite) == KErrNone); |
|
2210 |
|
2211 // Check file pos is correct |
|
2212 TInt pos = 0; |
|
2213 test(file.Seek(ESeekCurrent, pos) == KErrNone); |
|
2214 test(pos == 0); |
|
2215 test(file.Write(_L8("test")) == KErrNone); |
|
2216 pos = 0; |
|
2217 test(file.Seek(ESeekCurrent, pos) == KErrNone); |
|
2218 test(pos == 4); |
|
2219 |
|
2220 test(file.Rename(KTestFile2) == KErrNone); |
|
2221 |
|
2222 // Check file pos is correct |
|
2223 pos = 0; |
|
2224 test(file.Seek(ESeekCurrent, pos) == KErrNone); |
|
2225 test(pos == 4); |
|
2226 test(file.Write(_L8("test")) == KErrNone); |
|
2227 file.Close(); |
|
2228 |
|
2229 test(file.Open(fs, KTestFile2, EFileShareExclusive) == KErrNone); |
|
2230 |
|
2231 // Check file pos is correct |
|
2232 pos = 0; |
|
2233 test(file.Seek(ESeekCurrent, pos) == KErrNone); |
|
2234 test(pos == 0); |
|
2235 TBuf8<16> buf; |
|
2236 test(file.Read(buf) == KErrNone); |
|
2237 test(buf.Length() == 8); |
|
2238 pos = 0; |
|
2239 test(file.Seek(ESeekCurrent, pos) == KErrNone); |
|
2240 test(pos == 8); |
|
2241 |
|
2242 // Should fail because not opened for write |
|
2243 test(file.Rename(KTestFile1) == KErrAccessDenied); |
|
2244 |
|
2245 // Check file pos is correct |
|
2246 pos = 0; |
|
2247 test(file.Seek(ESeekCurrent, pos) == KErrNone); |
|
2248 test(pos == 8); |
|
2249 |
|
2250 // Check you can't write to the file |
|
2251 test(file.Write(_L8("test")) == KErrAccessDenied); |
|
2252 file.Close(); |
|
2253 |
|
2254 // Recreate the first file |
|
2255 test(file.Replace(fs, KTestFile1, EFileShareExclusive|EFileWrite) == KErrNone); |
|
2256 file.Close(); |
|
2257 |
|
2258 // Check error if renaming to existing file |
|
2259 test(file.Open(fs, KTestFile2, EFileShareExclusive) == KErrNone); |
|
2260 test(file.Rename(KTestFile1) == KErrAccessDenied); |
|
2261 file.Close(); |
|
2262 |
|
2263 // Cleanup |
|
2264 test(fs.Delete(KTestFile1) == KErrNone); |
|
2265 test(fs.Delete(KTestFile2) == KErrNone); |
|
2266 fs.Close(); |
|
2267 } |
|
2268 |
|
2269 void testRFileDuplicate() |
|
2270 { |
|
2271 // Connect to the file system |
|
2272 RFs fs; |
|
2273 test(fs.Connect() == KErrNone); |
|
2274 |
|
2275 _LIT(KTestFile1, "c:\\symport_test_rile_duplicate.txt"); |
|
2276 |
|
2277 RFile file1; |
|
2278 test(file1.Replace(fs, KTestFile1, EFileWrite) == KErrNone); |
|
2279 test(file1.Write(_L8("Test")) == KErrNone); |
|
2280 test(file1.Flush() == KErrNone); |
|
2281 |
|
2282 // Test you can duplicate the handle and read from it |
|
2283 RFile file2; |
|
2284 test(file2.Duplicate(file1) == KErrNone); |
|
2285 |
|
2286 // File position should match |
|
2287 TInt pos = 0; |
|
2288 test(file2.Seek(ESeekCurrent, pos) == KErrNone); |
|
2289 test(pos == 4); |
|
2290 |
|
2291 // Move back to the start |
|
2292 pos = 0; |
|
2293 test(file2.Seek(ESeekStart, pos) == KErrNone); |
|
2294 test(pos == 0); |
|
2295 |
|
2296 // Check you can read from the file |
|
2297 TBuf8<8> buf; |
|
2298 test(file2.Read(buf) == KErrNone); |
|
2299 test(buf.Length() == 4); |
|
2300 |
|
2301 // Check you can write to the file |
|
2302 test(file2.Write(_L8("Test")) == KErrNone); |
|
2303 |
|
2304 file1.Close(); |
|
2305 file2.Close(); |
|
2306 |
|
2307 // Now open readonly |
|
2308 test(file1.Open(fs, KTestFile1, 0) == KErrNone); |
|
2309 pos = 4; |
|
2310 test(file1.Seek(ESeekStart, pos) == KErrNone); |
|
2311 test(pos == 4); |
|
2312 |
|
2313 // Test you can duplicate the handle and read from it |
|
2314 test(file2.Duplicate(file1) == KErrNone); |
|
2315 |
|
2316 // File position should match |
|
2317 pos = 0; |
|
2318 test(file2.Seek(ESeekCurrent, pos) == KErrNone); |
|
2319 test(pos == 4); |
|
2320 |
|
2321 // Move back to the start |
|
2322 pos = 0; |
|
2323 test(file2.Seek(ESeekStart, pos) == KErrNone); |
|
2324 test(pos == 0); |
|
2325 |
|
2326 // Check you can read from the file |
|
2327 test(file2.Read(buf) == KErrNone); |
|
2328 test(buf.Length() == 8); |
|
2329 |
|
2330 // Check you can't write to the file |
|
2331 test(file2.Write(_L8("Test")) == KErrAccessDenied); |
|
2332 |
|
2333 file1.Close(); |
|
2334 file2.Close(); |
|
2335 |
|
2336 test(fs.Delete(KTestFile1) == KErrNone); |
|
2337 fs.Close(); |
|
2338 } |
|
2339 |
|
2340 void testRFileName() |
|
2341 { |
|
2342 // Connect to the file system |
|
2343 RFs fs; |
|
2344 test(fs.Connect() == KErrNone); |
|
2345 |
|
2346 _LIT(KTestFile1, "C:\\symport_test_rile_filename.txt"); |
|
2347 |
|
2348 RFile file1; |
|
2349 test(file1.Replace(fs, KTestFile1, 0) == KErrNone); |
|
2350 |
|
2351 TFileName name; |
|
2352 test(file1.Name(name) == KErrNone); |
|
2353 test(name == KTestFile1().Mid(3)); |
|
2354 test(file1.FullName(name) == KErrNone); |
|
2355 test(name == KTestFile1); |
|
2356 file1.Close(); |
|
2357 |
|
2358 test(fs.Delete(KTestFile1) == KErrNone); |
|
2359 fs.Close(); |
|
2360 } |
|
2361 |
|
2362 void testRFs() |
|
2363 { |
|
2364 test.Start(_L("Att")); |
|
2365 testAtt(); |
|
2366 |
|
2367 test.Next(_L("SetAtt")); |
|
2368 testSetAtt(); |
|
2369 |
|
2370 test.Next(_L("Modified")); |
|
2371 testModified(); |
|
2372 |
|
2373 test.Next(_L("MkDir")); |
|
2374 testMkDir(); |
|
2375 |
|
2376 test.Next(_L("MkDirAll")); |
|
2377 testMkDirAll(); |
|
2378 |
|
2379 test.Next(_L("RmDir")); |
|
2380 testRmDir(); |
|
2381 |
|
2382 test.Next(_L("Parse")); |
|
2383 testParse(); |
|
2384 |
|
2385 test.Next(_L("SessionPath")); |
|
2386 testSessionPath(); |
|
2387 |
|
2388 test.Next(_L("SetSessionPath")); |
|
2389 testSetSessionPath(); |
|
2390 |
|
2391 test.Next(_L("Delete")); |
|
2392 testDelete(); |
|
2393 |
|
2394 test.Next(_L("VolumeIOParam")); |
|
2395 #ifdef __TOOLS2__ |
|
2396 testVolumeIOParam(); |
|
2397 #endif |
|
2398 |
|
2399 test.Next(_L("Entry")); |
|
2400 testEntry(); |
|
2401 |
|
2402 test.Next(_L("SetEntry")); |
|
2403 testSetEntry(); |
|
2404 |
|
2405 test.Next(_L("SetErrorCondition")); |
|
2406 #ifdef __TOOLS2__ |
|
2407 testSetErrorCondition(); |
|
2408 #endif |
|
2409 |
|
2410 test.Next(_L("CharToDrive")); |
|
2411 testCharToDrive(); |
|
2412 |
|
2413 test.Next(_L("DriveToChar")); |
|
2414 testDriveToChar(); |
|
2415 |
|
2416 test.Next(_L("IsValidDrive")); |
|
2417 testIsValidDrive(); |
|
2418 |
|
2419 test.Next(_L("Drive")); |
|
2420 testDrive(); |
|
2421 |
|
2422 test.Next(_L("GetSystemDrive")); |
|
2423 testGetSystemDrive(); |
|
2424 |
|
2425 test.Next(_L("Replace")); |
|
2426 testReplace(); |
|
2427 |
|
2428 test.Next(_L("Rename")); |
|
2429 testRename(); |
|
2430 |
|
2431 test.End(); |
|
2432 } |
|
2433 |
|
2434 void testTParse() |
|
2435 { |
|
2436 test.Start(_L("Test all TParse methods")); |
|
2437 TestTParse1(); |
|
2438 |
|
2439 test.Next(_L("Test multiple PopDirs")); |
|
2440 TestTParse2(); |
|
2441 |
|
2442 test.Next(_L("Test conflicting default drive letters")); |
|
2443 TestTParse3(); |
|
2444 |
|
2445 test.Next(_L("Test conflicting relative drive letters")); |
|
2446 TestTParse4(); |
|
2447 |
|
2448 test.Next(_L("Test errors returned by illegal paths")); |
|
2449 TestTParse5(); |
|
2450 |
|
2451 test.Next(_L("Test AddDir")); |
|
2452 TestTParse6(); |
|
2453 |
|
2454 test.Next(_L("Test TParsePtr")); |
|
2455 TestTParse7(); |
|
2456 |
|
2457 test.Next(_L("Test TParsePtrC")); |
|
2458 TestTParse8(); |
|
2459 |
|
2460 test.Next(_L("Test names with leading spaces")); |
|
2461 TestTParse9(); |
|
2462 |
|
2463 test.Next(_L("Test a Path > 256 chars")); |
|
2464 TestTParse10(); |
|
2465 |
|
2466 test.End(); |
|
2467 } |
|
2468 |
|
2469 void testTFileText() |
|
2470 { |
|
2471 test.Start(_L("Test file text")); |
|
2472 testTFileTextApi(); |
|
2473 |
|
2474 test.Next(_L("Test FileText last record has no terminator")); |
|
2475 testTFileTextEndRecord(); |
|
2476 |
|
2477 test.End(); |
|
2478 } |
|
2479 |
|
2480 void testRFile() |
|
2481 { |
|
2482 test.Start(_L("Open")); |
|
2483 testRFileOpen(); |
|
2484 |
|
2485 test.Next(_L("Create")); |
|
2486 testRFileCreate(); |
|
2487 |
|
2488 test.Next(_L("Replace")); |
|
2489 testRFileReplace(); |
|
2490 |
|
2491 test.Next(_L("Temp")); |
|
2492 testRFileTemp(); |
|
2493 |
|
2494 test.Next(_L("Read")); |
|
2495 testRFileRead(); |
|
2496 |
|
2497 test.Next(_L("Write")); |
|
2498 testRFileWrite(); |
|
2499 |
|
2500 test.Next(_L("Seek")); |
|
2501 testRFileSeek(); |
|
2502 |
|
2503 test.Next(_L("Flush")); |
|
2504 testRFileFlush(); |
|
2505 |
|
2506 test.Next(_L("Size")); |
|
2507 testRFileSize(); |
|
2508 |
|
2509 test.Next(_L("SetSize")); |
|
2510 testRFileSetSize(); |
|
2511 |
|
2512 test.Next(_L("Att")); |
|
2513 testRFileAtt(); |
|
2514 |
|
2515 test.Next(_L("Modified")); |
|
2516 testRFileModified(); |
|
2517 |
|
2518 test.Next(_L("Drive")); |
|
2519 testRFileDrive(); |
|
2520 |
|
2521 test.Next(_L("Rename")); |
|
2522 testRFileRename(); |
|
2523 |
|
2524 test.Next(_L("Duplicate")); |
|
2525 testRFileDuplicate(); |
|
2526 |
|
2527 test.Next(_L("Name")); |
|
2528 testRFileName(); |
|
2529 |
|
2530 test.End(); |
|
2531 } |
|
2532 |
|
2533 // This following isn't relevant to WINSCW |
|
2534 #ifdef __TOOLS2__ |
|
2535 void testSpecialFilenameProcessing() |
|
2536 { |
|
2537 // Connect to the file system |
|
2538 RFs fs; |
|
2539 test(fs.Connect() == KErrNone); |
|
2540 |
|
2541 fs.RmDir(_L("c:\\testMisc\\epoc32\\test1\\")); |
|
2542 fs.RmDir(_L("c:\\testMisc\\epoc32\\test2\\")); |
|
2543 fs.RmDir(_L("c:\\testMisc\\epoc32\\")); |
|
2544 fs.RmDir(_L("c:\\testMisc\\")); |
|
2545 |
|
2546 TUint att; |
|
2547 _LIT(KCDriveTest1, "c:\\testMisc\\epoc32\\test1\\"); |
|
2548 test(fs.MkDirAll(KCDriveTest1) == KErrNone); |
|
2549 test(fs.Att(KCDriveTest1, att) == KErrNone); |
|
2550 |
|
2551 struct stat sb; |
|
2552 #ifdef _WIN32 |
|
2553 test(stat("c:\\testMisc\\epoc32\\test1", &sb) == 0); |
|
2554 #else |
|
2555 // Get home |
|
2556 char* env = getenv("HOME"); |
|
2557 test(env != NULL); |
|
2558 char home[0x100]; |
|
2559 strcpy(home, env); |
|
2560 |
|
2561 // Check it's replaced c: with HOME |
|
2562 char testpath[0x100]; |
|
2563 strcpy(testpath, home); |
|
2564 strcat(testpath, "/testmisc/epoc32/test1"); |
|
2565 test(stat(testpath, &sb) == 0); |
|
2566 #endif |
|
2567 |
|
2568 #ifdef _WIN32 |
|
2569 static char *env = "EPOCROOT=\\"; |
|
2570 test(putenv(env) == 0); |
|
2571 #else |
|
2572 test(setenv("EPOCROOT", home, 1) == 0); |
|
2573 #endif |
|
2574 |
|
2575 _LIT(KEpocRootTest, "\\epoc32\\winscw\\c\\testMisc\\test1\\"); |
|
2576 test(fs.MkDirAll(KEpocRootTest) == KErrNone); |
|
2577 test(fs.Att(KEpocRootTest, att) == KErrNone); |
|
2578 |
|
2579 #ifdef _WIN32 |
|
2580 test(stat("\\epoc32\\winscw\\c\\testMisc\\test1", &sb) == 0); |
|
2581 #else |
|
2582 // Check it's replaced \epoc32 with $(EPOCROOT)epoc32 |
|
2583 strcpy(testpath, home); |
|
2584 strcat(testpath, "/epoc32/winscw/c/testmisc/test1"); |
|
2585 test(stat(testpath, &sb) == 0); |
|
2586 #endif |
|
2587 |
|
2588 test(fs.RmDir(KEpocRootTest) == KErrNone); |
|
2589 test(fs.RmDir(_L("\\epoc32\\winscw\\c\\testMisc\\")) == KErrNone); |
|
2590 |
|
2591 // Now set EPOCROOT to something a bit more complicated |
|
2592 #ifdef _WIN32 |
|
2593 env = "EPOCROOT=c:\\testMisc"; |
|
2594 test(putenv(env) == 0); |
|
2595 #else |
|
2596 strcpy(testpath, home); |
|
2597 strcat(testpath, "/testmisc/"); |
|
2598 test(setenv("EPOCROOT", testpath, 1) == 0); |
|
2599 #endif |
|
2600 |
|
2601 _LIT(KCDriveTest2, "\\epoc32\\test2\\"); |
|
2602 test(fs.MkDirAll(KCDriveTest2) == KErrNone); |
|
2603 test(fs.Att(_L("\\epoc32\\test1\\"),att) == KErrNone); |
|
2604 test(fs.Att(_L("\\epoc32\\test2\\"),att) == KErrNone); |
|
2605 |
|
2606 #ifdef _WIN32 |
|
2607 test(stat("c:\\testMisc\\epoc32\\test2", &sb) == 0); |
|
2608 #else |
|
2609 strcpy(testpath, home); |
|
2610 strcat(testpath, "/testmisc/epoc32/test2"); |
|
2611 test(stat(testpath, &sb) == 0); |
|
2612 #endif |
|
2613 |
|
2614 #ifdef _WIN32 |
|
2615 env = "EPOCROOT=\\"; |
|
2616 test(putenv(env) == 0); |
|
2617 #else |
|
2618 test(setenv("EPOCROOT", home, 1) == 0); |
|
2619 #endif |
|
2620 |
|
2621 test(fs.RmDir(_L("c:\\testMisc\\epoc32\\test1\\")) == KErrNone); |
|
2622 test(fs.RmDir(_L("c:\\testMisc\\epoc32\\test2\\")) == KErrNone); |
|
2623 test(fs.RmDir(_L("c:\\testMisc\\epoc32\\")) == KErrNone); |
|
2624 test(fs.RmDir(_L("c:\\testMisc\\")) == KErrNone); |
|
2625 |
|
2626 fs.Close(); |
|
2627 } |
|
2628 |
|
2629 #ifdef USING_SYMPORT_DLL |
|
2630 IMPORT_C TVersion SymPortVersion(); |
|
2631 void testVersion() |
|
2632 { |
|
2633 TVersion ver(SymPortVersion()); |
|
2634 test(ver.iMajor >= 1); |
|
2635 |
|
2636 TPtrC name(ver.Name()); |
|
2637 test.Printf(_L("Symport Version: %S\n"), &name); |
|
2638 } |
|
2639 #endif |
|
2640 #endif |
|
2641 |
|
2642 void doMainL() |
|
2643 { |
|
2644 test.Start(_L("RFs")); |
|
2645 testRFs(); |
|
2646 |
|
2647 test.Next(_L("TParse")); |
|
2648 testTParse(); |
|
2649 |
|
2650 test.Next(_L("TFileText")); |
|
2651 testTFileText(); |
|
2652 |
|
2653 test.Next(_L("RFile")); |
|
2654 testRFile(); |
|
2655 |
|
2656 test.Next(_L("Misc")); |
|
2657 #ifdef __TOOLS2__ |
|
2658 testSpecialFilenameProcessing(); |
|
2659 #ifdef USING_SYMPORT_DLL |
|
2660 testVersion(); |
|
2661 #endif |
|
2662 #endif |
|
2663 |
|
2664 test.End(); |
|
2665 } |
|
2666 int E32Main() |
|
2667 { |
|
2668 __UHEAP_MARK; |
|
2669 CTrapCleanup* theCleanup = CTrapCleanup::New(); |
|
2670 TRAPD(ret, doMainL()); |
|
2671 test(ret == KErrNone); |
|
2672 test.Close(); |
|
2673 delete theCleanup; |
|
2674 __UHEAP_MARKEND; |
|
2675 return ret; |
|
2676 } |