|
1 // Copyright (c) 1998-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 // f32test\fsstress\t_sesfs.cpp |
|
15 // |
|
16 // |
|
17 #define __E32TEST_EXTENSION__ |
|
18 #include "t_sess.h" |
|
19 |
|
20 GLDEF_D TFileName tPath; |
|
21 GLREF_D TFileName gExeFileName; |
|
22 |
|
23 LOCAL_C void printDriveAtt(TInt aDrive,TUint anAtt); |
|
24 LOCAL_C void printDriveInfo(TInt aDrive,TDriveInfo& anInfo); |
|
25 LOCAL_C void DriveInfo(TInt aDrive,TDriveInfo& anInfo); |
|
26 |
|
27 |
|
28 void TSessionTest::Initialise(RFs& aFs) |
|
29 // |
|
30 // Initialise iFs |
|
31 // |
|
32 { |
|
33 iFs=aFs; |
|
34 } |
|
35 |
|
36 |
|
37 void TSessionTest::RunTests() |
|
38 // |
|
39 // Run tests on iFs file server session |
|
40 // |
|
41 |
|
42 { |
|
43 |
|
44 testDriveList(); |
|
45 testDriveInfo(); |
|
46 testVolumeInfo(); |
|
47 testSetVolume(); |
|
48 testPath(); |
|
49 CreateTestDirectory(_L("\\SESSION_TEST\\TFSRV\\")); |
|
50 testInitialisation(); |
|
51 testSubst(); |
|
52 CopyFileToTestDirectory(); |
|
53 MakeAndDeleteFiles(); |
|
54 } |
|
55 |
|
56 |
|
57 |
|
58 void TSessionTest::testDriveList() |
|
59 // |
|
60 // Test the drive list. |
|
61 // |
|
62 { |
|
63 |
|
64 test.Start(_L("The drive list")); |
|
65 TDriveList list; |
|
66 TDriveInfo info; |
|
67 TInt r=iFs.DriveList(list); |
|
68 test_KErrNone(r); |
|
69 for (TInt i=0;i<KMaxDrives;i++) |
|
70 { |
|
71 if (list[i]) |
|
72 { |
|
73 r = iFs.Drive(info, i); |
|
74 test_KErrNone(r); |
|
75 printDriveAtt(i,info.iDriveAtt); |
|
76 } |
|
77 } |
|
78 |
|
79 test.End(); |
|
80 } |
|
81 |
|
82 void TSessionTest::testDriveInfo() |
|
83 // |
|
84 // Test the drive info. |
|
85 // |
|
86 { |
|
87 |
|
88 test.Start(_L("The drive info")); |
|
89 TDriveList list; |
|
90 TInt r=iFs.DriveList(list); |
|
91 test_KErrNone(r); |
|
92 for (TInt i=0;i<KMaxDrives;i++) |
|
93 { |
|
94 TInt att=list[i]; |
|
95 if (att) |
|
96 { |
|
97 TDriveInfo d; |
|
98 r=iFs.Drive(d,i); |
|
99 test_KErrNone(r); |
|
100 printDriveInfo(i,d); |
|
101 test.Printf(_L("\n")); |
|
102 DriveInfo(i,d); |
|
103 } |
|
104 } |
|
105 |
|
106 test.End(); |
|
107 } |
|
108 |
|
109 void TSessionTest::testVolumeInfo() |
|
110 // |
|
111 // Test volume info. |
|
112 // |
|
113 { |
|
114 |
|
115 test.Start(_L("The volume info")); |
|
116 TDriveList list; |
|
117 TInt r=iFs.DriveList(list); |
|
118 test_KErrNone(r); |
|
119 for (TInt i=0;i<KMaxDrives;i++) |
|
120 { |
|
121 TVolumeInfo v; |
|
122 TDriveInfo d; |
|
123 switch (r=iFs.Volume(v,i)) |
|
124 { |
|
125 case KErrNone: |
|
126 printDriveInfo(i,v.iDrive); |
|
127 test.Printf(_L(" VOL=\"%S\" ID=%08x\n"),&v.iName,v.iUniqueID); |
|
128 test.Printf(_L(" SIZE=%ldK FREE=%ldK\n"),v.iSize/1024,v.iFree/1024); |
|
129 break; |
|
130 case KErrNotReady: |
|
131 r=iFs.Drive(d, i); |
|
132 test_KErrNone(r); |
|
133 if (d.iType == EMediaNotPresent) |
|
134 test.Printf(_L("%c: Medium not present - cannot perform test.\n"), i + 'A'); |
|
135 else |
|
136 test.Printf(_L("medium found (type %d) but drive %c: not ready\nPrevious test may have hung; else, check hardware.\n"), (TInt)d.iType, i + 'A'); |
|
137 break; |
|
138 case KErrPathNotFound: |
|
139 test.Printf(_L("%c: Not Found\n"), i + 'A'); |
|
140 break; |
|
141 case KErrCorrupt: |
|
142 test.Printf(_L("%c: Media corruption; previous test may have aborted; else, check hardware\n"), i + 'A'); |
|
143 default: |
|
144 test.Printf(_L("%c: Error %d - aborting test.\n"),i + 'A', r); |
|
145 test(0); |
|
146 } |
|
147 test.Printf(_L("\n")); |
|
148 } |
|
149 |
|
150 test.End(); |
|
151 } |
|
152 |
|
153 |
|
154 void TSessionTest::testPath() |
|
155 // |
|
156 // Test the path handling. |
|
157 // |
|
158 { |
|
159 |
|
160 test.Start(_L("Test path handling")); |
|
161 |
|
162 TInt r; |
|
163 |
|
164 TFileName p; |
|
165 r=iFs.SessionPath(p); |
|
166 test_KErrNone(r); |
|
167 test.Printf(_L("SESSION=\"%S\"\n"),&p); |
|
168 r=iFs.SetSessionPath(_L("A:\\TEST\\")); |
|
169 test_KErrNone(r); |
|
170 r=iFs.SessionPath(p); |
|
171 test_KErrNone(r); |
|
172 test(p==_L("A:\\TEST\\")); |
|
173 r=iFs.SetSessionPath(gTestSessionPath); |
|
174 test_KErrNone(r); |
|
175 |
|
176 test.End(); |
|
177 } |
|
178 |
|
179 |
|
180 void TSessionTest::testInitialisation() |
|
181 // |
|
182 // Tests that calls to CheckedClose() are OK, ie, tests bug fix |
|
183 // |
|
184 { |
|
185 test.Next(_L("Test calls to CheckedClose are OK")); |
|
186 |
|
187 RFile file; |
|
188 RDir dir; |
|
189 |
|
190 TInt count; |
|
191 RFormat format; |
|
192 TInt r=format.Open(iFs,_L("Z:\\"),EFullFormat,count); |
|
193 |
|
194 test_Value(r, r==KErrAccessDenied || r==KErrInUse); |
|
195 |
|
196 r=dir.Open(iFs,_L("\\SESSION_TEST\\ERRORTEST\\"),KEntryAttMatchMask); |
|
197 test_Value(r, r==KErrPathNotFound); |
|
198 |
|
199 r=file.Open(iFs,_L("\\SESSION_TEST\\SessionTest1.txt"),EFileRead); |
|
200 test_Value(r, r==KErrNotFound); |
|
201 |
|
202 r=dir.Open(iFs,_L("\\SESSION_TEST\\ERRORTEST2\\"),KEntryAttMatchMask); |
|
203 test_Value(r, r==KErrPathNotFound); |
|
204 |
|
205 r=file.Open(iFs,_L("\\SESSION_TEST\\SessionTest2.txt"),EFileRead); |
|
206 test_Value(r, r==KErrNotFound); |
|
207 |
|
208 r=dir.Open(iFs,_L("\\SESSION_TEST\\ERRORTEST3\\"),KEntryAttMatchMask); |
|
209 test_Value(r, r==KErrPathNotFound); |
|
210 |
|
211 r=file.Open(iFs,_L("\\SESSION_TEST\\SessionTest3.txt"),EFileRead); |
|
212 test_Value(r, r==KErrNotFound); |
|
213 |
|
214 r=file.Open(iFs,_L("\\SESSION_TEST\\SessionTest4.txt"),EFileRead); |
|
215 test_Value(r, r==KErrNotFound); |
|
216 |
|
217 format.Close(); |
|
218 dir.Close(); |
|
219 file.Close(); |
|
220 } |
|
221 |
|
222 |
|
223 void TSessionTest::testSubst() |
|
224 // |
|
225 // Test the substitute functions. |
|
226 // |
|
227 { |
|
228 |
|
229 test.Printf(_L("Test subst")); |
|
230 TVolumeInfo v; |
|
231 TInt r=iFs.Volume(v); |
|
232 test_KErrNone(r); |
|
233 TDriveInfo origDI; |
|
234 r=iFs.Drive(origDI); |
|
235 test_KErrNone(r); |
|
236 |
|
237 TDriveInfo driveInfo; |
|
238 r=iFs.Drive(driveInfo,EDriveO); |
|
239 test_KErrNone(r); |
|
240 |
|
241 testSetVolume(); |
|
242 |
|
243 if (driveInfo.iDriveAtt==KDriveAttLocal) |
|
244 { |
|
245 return; // Subst local drives fails |
|
246 } |
|
247 |
|
248 TFileName n; |
|
249 r=iFs.Subst(n,EDriveO); |
|
250 test_KErrNone(r); |
|
251 test(n.Length()==0); |
|
252 r=iFs.SetSubst(gTestSessionPath,EDriveO); |
|
253 test_KErrNone(r); |
|
254 r=iFs.Subst(n,EDriveO); |
|
255 test_KErrNone(r); |
|
256 test(n==gTestSessionPath); |
|
257 TVolumeInfo w; |
|
258 r=iFs.Volume(w,EDriveO); |
|
259 test_KErrNone(r); |
|
260 test(w.iDrive.iType==v.iDrive.iType); |
|
261 test(w.iDrive.iBattery==v.iDrive.iBattery); |
|
262 test(w.iDrive.iDriveAtt==KDriveAttSubsted); |
|
263 test(w.iDrive.iMediaAtt==v.iDrive.iMediaAtt); |
|
264 test(w.iUniqueID==v.iUniqueID); |
|
265 test(w.iSize==v.iSize); |
|
266 |
|
267 // If this test is being run under windows using drive C then skip free space comparison |
|
268 // as it is likely to fail as the windows file system is unlike to have static freespace |
|
269 #ifdef __WINS__ |
|
270 if(User::UpperCase(gTestSessionPath[0]) != 'C') |
|
271 { |
|
272 #endif |
|
273 test(w.iFree==v.iFree); |
|
274 |
|
275 #ifdef __WINS__ |
|
276 } |
|
277 #endif |
|
278 |
|
279 test(w.iName==v.iName); |
|
280 TDriveList driveList; |
|
281 r=iFs.DriveList(driveList); |
|
282 test_KErrNone(r); |
|
283 test(driveList[EDriveO]==KDriveAttSubsted); |
|
284 TDriveInfo d; |
|
285 r=iFs.Drive(d,EDriveO); |
|
286 test_KErrNone(r); |
|
287 test(d.iDriveAtt==KDriveAttSubsted); |
|
288 test(d.iMediaAtt==origDI.iMediaAtt); |
|
289 test(d.iType==origDI.iType); |
|
290 test(d.iBattery==origDI.iBattery); |
|
291 |
|
292 |
|
293 test.Next(_L("Test real name")); |
|
294 r=iFs.RealName(_L("O:\\FILE.XXX"),n); |
|
295 test_KErrNone(r); |
|
296 TFileName substedPath=gTestSessionPath; |
|
297 substedPath.Append(_L("FILE.XXX")); |
|
298 test(n.CompareF(substedPath)==KErrNone); |
|
299 // |
|
300 test.Next(_L("Test MkDir, Rename and RmDir on Substed drive")); |
|
301 _LIT(KTurgid,"turgid\\"); |
|
302 TFileName dir=gTestSessionPath; |
|
303 dir+=KTurgid; |
|
304 r=iFs.MkDirAll(dir); |
|
305 test_KErrNone(r); |
|
306 dir+=_L("subdir\\"); |
|
307 r=iFs.MkDir(dir); |
|
308 test_KErrNone(r); |
|
309 r=iFs.RmDir(_L("O:\\turgid\\subdir\\")); |
|
310 test_KErrNone(r); |
|
311 r=iFs.Rename(_L("O:\\turgid"), _L("O:\\facile")); |
|
312 test_KErrNone(r); |
|
313 r=iFs.MkDir(_L("O:\\insipid\\")); |
|
314 test_KErrNone(r); |
|
315 r=iFs.Rename(_L("O:\\insipid"), _L("O:\\glib")); |
|
316 test_KErrNone(r); |
|
317 r=iFs.RmDir(_L("O:\\facile\\")); |
|
318 test_KErrNone(r); |
|
319 _LIT(KGlib,"glib\\"); |
|
320 dir=gTestSessionPath; |
|
321 dir+=KGlib; |
|
322 r=iFs.RmDir(dir); |
|
323 test_KErrNone(r); |
|
324 test.Next(_L("Test file operations on Substed drive")); |
|
325 _LIT(File1,"File1.txt"); |
|
326 _LIT(File2,"File2.txt"); |
|
327 _LIT(SubstRoot,"O:\\"); |
|
328 _LIT(Subdir,"subdir\\"); |
|
329 TFileName name1,name2; |
|
330 name1=gTestSessionPath; |
|
331 name1+=File1; |
|
332 RFile f1; |
|
333 r=f1.Create(iFs,name1,EFileShareExclusive|EFileWrite); |
|
334 test_KErrNone(r); |
|
335 name2=SubstRoot; |
|
336 name2+=File2; |
|
337 TBool isValid=iFs.IsValidName(name2); |
|
338 test(isValid); |
|
339 r=f1.Rename(name2); |
|
340 test_KErrNone(r); |
|
341 f1.Close(); |
|
342 r=f1.Create(iFs,name1,EFileShareExclusive|EFileWrite); |
|
343 test_KErrNone(r); |
|
344 f1.Close(); |
|
345 r=iFs.Replace(name2,name1); |
|
346 test_KErrNone(r); |
|
347 r=iFs.Delete(name1); |
|
348 test_KErrNone(r); |
|
349 test.Next(_L("Test notifications on Substed drive")); |
|
350 name1=gTestSessionPath; |
|
351 name1+=Subdir; |
|
352 name2=SubstRoot; |
|
353 name2+=Subdir; |
|
354 // set up some extended notifications |
|
355 TRequestStatus status1; |
|
356 TRequestStatus status2; |
|
357 TRequestStatus status3; |
|
358 iFs.NotifyChange(ENotifyDir,status1,name1); |
|
359 test(status1==KRequestPending); |
|
360 iFs.NotifyChange(ENotifyDir,status2,name2); |
|
361 test(status2==KRequestPending); |
|
362 r=iFs.MkDirAll(name1); |
|
363 test_KErrNone(r); |
|
364 User::WaitForRequest(status1); |
|
365 User::WaitForRequest(status2); |
|
366 test(status1==KErrNone && status2==KErrNone); |
|
367 iFs.NotifyChange(ENotifyDir,status1,name1); |
|
368 test(status1==KRequestPending); |
|
369 iFs.NotifyChange(ENotifyDir,status2,name2); |
|
370 test(status2==KRequestPending); |
|
371 iFs.NotifyChange(ENotifyAll,status3,name2); |
|
372 test(status3==KRequestPending); |
|
373 r=f1.Temp(iFs,name2,n,EFileShareAny|EFileWrite); |
|
374 test_KErrNone(r); |
|
375 User::WaitForRequest(status3); |
|
376 test(status3==KErrNone && status1==KRequestPending && status2==KRequestPending); |
|
377 f1.Close(); |
|
378 iFs.NotifyChangeCancel(); |
|
379 test(status1==KErrCancel && status2==KErrCancel); |
|
380 User::WaitForRequest(status1); |
|
381 User::WaitForRequest(status2); |
|
382 r=iFs.Delete(n); |
|
383 test_KErrNone(r); |
|
384 r=iFs.RmDir(name1); |
|
385 test_KErrNone(r); |
|
386 // |
|
387 test.Next(_L("Test file systems on Substed drive")); |
|
388 // test cannot mount file system on substituted drive |
|
389 TInt sessionDrv; |
|
390 r=iFs.CharToDrive(gTestSessionPath[0],sessionDrv); |
|
391 test_KErrNone(r); |
|
392 r=iFs.FileSystemName(n,sessionDrv); |
|
393 test_Value(r, r==KErrNone || r==KErrNotFound); |
|
394 r=iFs.MountFileSystem(n,EDriveO); |
|
395 test_Value(r, r==KErrAccessDenied); |
|
396 // test file system name on substitued drive is null |
|
397 r=iFs.FileSystemName(n,EDriveO); |
|
398 test_Value(r, r==KErrNotFound && n==KNullDesC); |
|
399 // test cannot format a substitued drive |
|
400 RFormat format; |
|
401 TInt count; |
|
402 r=format.Open(iFs,SubstRoot,EHighDensity,count); |
|
403 test_Value(r, r==KErrAccessDenied); |
|
404 |
|
405 r=iFs.SetSubst(_L(""),EDriveO); |
|
406 test_KErrNone(r); |
|
407 r=iFs.Subst(n,EDriveO); |
|
408 test_KErrNone(r); |
|
409 test(n==_L("")); |
|
410 r=iFs.Drive(d,EDriveO); |
|
411 test_KErrNone(r); |
|
412 test(d.iDriveAtt==0); |
|
413 } |
|
414 |
|
415 |
|
416 LOCAL_C TInt CreateFileX(const TDesC& aBaseName,TInt aX, RFs iFs) |
|
417 // |
|
418 // Create a large file. Return KErrEof or KErrNone |
|
419 // |
|
420 { |
|
421 |
|
422 TBuf<128> fileName=aBaseName; |
|
423 fileName.AppendNum(aX); |
|
424 RFile file; |
|
425 TInt r=file.Replace(iFs,fileName,EFileWrite); |
|
426 if (r==KErrDiskFull) |
|
427 return(r); |
|
428 if (r!=KErrNone) |
|
429 { |
|
430 test.Printf(_L("ERROR:: Replace returned %d\n"),r); |
|
431 return(KErrDiskFull); |
|
432 } |
|
433 r=file.SetSize(65536); |
|
434 if (r==KErrDiskFull) |
|
435 { |
|
436 file.Close(); |
|
437 return(r); |
|
438 } |
|
439 if (r!=KErrNone) |
|
440 { |
|
441 test.Printf(_L("ERROR:: SetSize returned %d\n"),r); |
|
442 file.Close(); |
|
443 return(KErrDiskFull); |
|
444 } |
|
445 file.Close(); |
|
446 // r=iFs.CheckDisk(fileName); |
|
447 // if (r!=KErrNone && r!=KErrNotSupported) |
|
448 // { |
|
449 // test.Printf(_L("ERROR:: CheckDisk returned %d\n"),r); |
|
450 // test.Getch(); |
|
451 // return(KErrDiskFull); |
|
452 // } |
|
453 test.Printf(_L("Created file %d size 64k\n"),aX); |
|
454 return(KErrNone); |
|
455 } |
|
456 |
|
457 LOCAL_C TInt DeleteFileX(TBuf<128>& aBaseName,TInt aX, RFs iFs) |
|
458 // |
|
459 // Delete a file. |
|
460 // |
|
461 { |
|
462 |
|
463 TBuf<128> fileName=aBaseName; |
|
464 fileName.AppendNum(aX); |
|
465 TInt r=iFs.Delete(fileName); |
|
466 test_KErrNone(r); |
|
467 // r=iFs.CheckDisk(fileName); |
|
468 // if (r!=KErrNone && r!=KErrNotSupported) |
|
469 // { |
|
470 // test.Printf(_L("ERROR:: CheckDisk returned %d\n"),r); |
|
471 // test_KErrNone(r); |
|
472 // } |
|
473 test.Printf(_L("Deleted File %d\n"),aX); |
|
474 return(KErrNone); |
|
475 } |
|
476 |
|
477 void TSessionTest::MakeAndDeleteFiles() |
|
478 // |
|
479 // Create and delete large files in a randomish order |
|
480 // |
|
481 { |
|
482 |
|
483 test.Start(_L("Create and delete large files")); |
|
484 TInt r=iFs.MkDirAll(_L("\\SESSION_TEST\\SMALLDIRECTORY\\")); |
|
485 test_Value(r, r==KErrNone || r==KErrAlreadyExists); |
|
486 TBuf<128> fileName=_L("\\SESSION_TEST\\SMALLDIRECTORY\\FILE"); |
|
487 r=CreateFileX(fileName,0,iFs); |
|
488 test_KErrNone(r); |
|
489 r=CreateFileX(fileName,1,iFs); |
|
490 test_KErrNone(r); |
|
491 r=DeleteFileX(fileName,0,iFs); |
|
492 test_KErrNone(r); |
|
493 r=CreateFileX(fileName,2,iFs); |
|
494 test_KErrNone(r); |
|
495 r=CreateFileX(fileName,1,iFs); |
|
496 test_KErrNone(r); |
|
497 r=CreateFileX(fileName,3,iFs); |
|
498 test_KErrNone(r); |
|
499 r=DeleteFileX(fileName,1,iFs); |
|
500 test_KErrNone(r); |
|
501 r=CreateFileX(fileName,4,iFs); |
|
502 test_KErrNone(r); |
|
503 r=DeleteFileX(fileName,2,iFs); |
|
504 test_KErrNone(r); |
|
505 r=DeleteFileX(fileName,3,iFs); |
|
506 test_KErrNone(r); |
|
507 r=DeleteFileX(fileName,4,iFs); |
|
508 test_KErrNone(r); |
|
509 r=CreateFileX(fileName,1,iFs); |
|
510 test_KErrNone(r); |
|
511 r=DeleteFileX(fileName,1,iFs); |
|
512 test_KErrNone(r); |
|
513 |
|
514 r=iFs.CheckDisk(fileName); |
|
515 test_Value(r, r==KErrNone || r==KErrNotSupported); |
|
516 test.End(); |
|
517 } |
|
518 |
|
519 void TSessionTest::FillUpDisk() |
|
520 // |
|
521 // Test that a full disk is ok |
|
522 // |
|
523 { |
|
524 |
|
525 test.Start(_L("Fill disk to capacity")); |
|
526 TInt r=iFs.MkDirAll(_L("\\SESSION_TEST\\BIGDIRECTORY\\")); |
|
527 test_Value(r, r==KErrNone || r==KErrAlreadyExists); |
|
528 TInt count=0; |
|
529 TFileName sessionPath; |
|
530 r=iFs.SessionPath(sessionPath); |
|
531 test_KErrNone(r); |
|
532 TBuf<128> fileName=_L("\\SESSION_TEST\\BIGDIRECTORY\\FILE"); |
|
533 FOREVER |
|
534 { |
|
535 TInt r=CreateFileX(fileName,count,iFs); |
|
536 if (r==KErrDiskFull) |
|
537 break; |
|
538 test_KErrNone(r); |
|
539 count++; |
|
540 #if defined(__WINS__) |
|
541 if (count==32 && sessionPath[0]=='C') // Don't fill up disk on NT |
|
542 break; |
|
543 #endif |
|
544 } |
|
545 |
|
546 r=iFs.CheckDisk(fileName); |
|
547 test_Value(r, r==KErrNone || r==KErrNotSupported); |
|
548 |
|
549 while(count--) |
|
550 DeleteFileX(fileName,count,iFs); |
|
551 |
|
552 r=iFs.CheckDisk(fileName); |
|
553 test_Value(r, r==KErrNone || r==KErrNotSupported); |
|
554 |
|
555 test.End(); |
|
556 } |
|
557 |
|
558 void TSessionTest::CopyFileToTestDirectory() |
|
559 // |
|
560 // Make a copy of the file in ram |
|
561 // |
|
562 { |
|
563 |
|
564 TFileName fn = _L("Z:\\TEST\\T_FSRV.CPP"); |
|
565 fn[0] = gExeFileName[0]; |
|
566 TParse f; |
|
567 TInt r=iFs.Parse(fn,f); |
|
568 test_KErrNone(r); |
|
569 test.Next(_L("Copying file to test directory")); |
|
570 TParse fCopy; |
|
571 r=iFs.Parse(f.NameAndExt(),fCopy); |
|
572 test_KErrNone(r); |
|
573 |
|
574 RFile f1; |
|
575 r=f1.Open(iFs,f.FullName(),EFileStreamText|EFileShareReadersOnly); |
|
576 test.Printf(_L("r=%d\n"),r); |
|
577 test_KErrNone(r); |
|
578 RFile f2; |
|
579 r=f2.Replace(iFs,fCopy.FullName(),EFileWrite); |
|
580 test_KErrNone(r); |
|
581 TBuf8<512> copyBuf; |
|
582 TInt rem; |
|
583 r=f1.Size(rem); |
|
584 test_KErrNone(r); |
|
585 TInt pos=0; |
|
586 while (rem) |
|
587 { |
|
588 TInt s=Min(rem,copyBuf.MaxSize()); |
|
589 r=f1.Read(pos,copyBuf,s); |
|
590 test_KErrNone(r); |
|
591 test(copyBuf.Length()==s); |
|
592 r=f2.Write(pos,copyBuf,s); |
|
593 test_KErrNone(r); |
|
594 pos+=s; |
|
595 rem-=s; |
|
596 } |
|
597 f1.Close(); |
|
598 f2.Close(); |
|
599 } |
|
600 |
|
601 |
|
602 void TSessionTest::testSetVolume() |
|
603 // |
|
604 // Test setting the volume info. |
|
605 // |
|
606 { |
|
607 |
|
608 test.Start(_L("Test setting the volume label")); |
|
609 |
|
610 #if defined(_UNICODE) |
|
611 test.Printf(_L("Unicode volume label set not implemented ****\n")); |
|
612 test.End(); |
|
613 return; |
|
614 #else |
|
615 TInt driveNum=CurrentDrive(); |
|
616 TVolumeInfo v; |
|
617 TInt r=iFs.Volume(v,driveNum); |
|
618 test_KErrNone(r); |
|
619 TFileName n=v.iName; |
|
620 test.Printf(_L("VOL=\"%S\"\n"),&n); |
|
621 |
|
622 test.Next(_L("Set volume label to nothing")); |
|
623 r=iFs.SetVolumeLabel(_L(""),driveNum); |
|
624 #if defined(__WINS__) |
|
625 if (r==KErrGeneral || r==KErrAccessDenied || r==KErrNotSupported) |
|
626 { |
|
627 test.Printf(_L("Error %d: Set volume label not testing on WINS\n"),r); |
|
628 test.End(); |
|
629 return; |
|
630 } |
|
631 #endif |
|
632 test_KErrNone(r); |
|
633 r=iFs.Volume(v,driveNum); |
|
634 test_KErrNone(r); |
|
635 test(v.iName==_L("")); |
|
636 test.Printf(_L("VOL=\"%S\"\n"),&v.iName); |
|
637 |
|
638 test.Next(_L("Set volume label to ABCDEFGHIJK")); |
|
639 r=iFs.SetVolumeLabel(_L("ABCDEFGHIJK"),driveNum); |
|
640 test_KErrNone(r); |
|
641 r=iFs.Volume(v,driveNum); |
|
642 test_KErrNone(r); |
|
643 test(v.iName==_L("ABCDEFGHIJK")); |
|
644 test.Printf(_L("VOL=\"%S\"\n"),&v.iName); |
|
645 |
|
646 test.Next(_L("Set volume label back to nothing")); |
|
647 r=iFs.SetVolumeLabel(_L(""),driveNum); |
|
648 test_KErrNone(r); |
|
649 r=iFs.Volume(v,driveNum); |
|
650 test_KErrNone(r); |
|
651 test(v.iName==_L("")); |
|
652 test.Printf(_L("VOL=\"%S\"\n"),&v.iName); |
|
653 |
|
654 test.Next(_L("Set volume label to original")); |
|
655 r=iFs.SetVolumeLabel(n,driveNum); |
|
656 test_KErrNone(r); |
|
657 r=iFs.Volume(v,driveNum); |
|
658 test_KErrNone(r); |
|
659 test(v.iName==n); |
|
660 test.Printf(_L("VOL=\"%S\"\n"),&v.iName); |
|
661 |
|
662 test.End(); |
|
663 #endif |
|
664 } |
|
665 |
|
666 LOCAL_C void printDriveAtt(TInt aDrive,TUint anAtt) |
|
667 // |
|
668 // Print a drive attribute. |
|
669 // |
|
670 { |
|
671 |
|
672 test.Printf(_L("%c: "),aDrive+'A'); |
|
673 if (anAtt&KDriveAttLocal) |
|
674 test.Printf(_L("LOCAL ")); |
|
675 if (anAtt&KDriveAttRom) |
|
676 test.Printf(_L("ROM ")); |
|
677 if (anAtt&KDriveAttRedirected) |
|
678 test.Printf(_L("REDIR ")); |
|
679 if (anAtt&KDriveAttSubsted) |
|
680 test.Printf(_L("SUBST ")); |
|
681 if (anAtt&KDriveAttInternal) |
|
682 test.Printf(_L("INTERNAL ")); |
|
683 if ((anAtt&KDriveAttRemovable) && !(anAtt&KDriveAttLogicallyRemovable)) |
|
684 test.Printf(_L("PHYSICALLY-REMOVABLE ")); |
|
685 if (anAtt&KDriveAttLogicallyRemovable) |
|
686 test.Printf(_L("LOGICALLY-REMOVABLE ")); |
|
687 if (anAtt&KDriveAttHidden) |
|
688 test.Printf(_L("HIDDEN ")); |
|
689 test.Printf(_L("\n")); |
|
690 } |
|
691 |
|
692 LOCAL_C void printDriveInfo(TInt aDrive,TDriveInfo& anInfo) |
|
693 // |
|
694 // Print a drive info. |
|
695 // |
|
696 { |
|
697 |
|
698 printDriveAtt(aDrive,anInfo.iDriveAtt); |
|
699 test.Printf(_L(" MEDIA-ATT=")); |
|
700 if (anInfo.iMediaAtt==0) |
|
701 test.Printf(_L("<none>")); |
|
702 if (anInfo.iMediaAtt&KMediaAttVariableSize) |
|
703 test.Printf(_L("VariableSize ")); |
|
704 if (anInfo.iMediaAtt&KMediaAttDualDensity) |
|
705 test.Printf(_L("DualDensity ")); |
|
706 if (anInfo.iMediaAtt&KMediaAttFormattable) |
|
707 test.Printf(_L("Formattable ")); |
|
708 if (anInfo.iMediaAtt&KMediaAttWriteProtected) |
|
709 test.Printf(_L("WProtected ")); |
|
710 test.Printf(_L("\n BATTERY=")); |
|
711 switch(anInfo.iBattery) |
|
712 { |
|
713 case EBatNotSupported: test.Printf(_L("Not supported\n")); break; |
|
714 case EBatGood: test.Printf(_L("Good\n")); break; |
|
715 case EBatLow: test.Printf(_L("Low\n")); break; |
|
716 default: |
|
717 test.Printf(_L("Unknown value\n")); |
|
718 } |
|
719 test.Printf(_L(" MEDIA=")); |
|
720 switch(anInfo.iType) |
|
721 { |
|
722 case EMediaNotPresent: test.Printf(_L("Not present\n")); break; |
|
723 case EMediaUnknown: test.Printf(_L("Unknown\n")); break; |
|
724 case EMediaFloppy: test.Printf(_L("Floppy\n")); break; |
|
725 case EMediaHardDisk: test.Printf(_L("Hard disk\n")); break; |
|
726 case EMediaCdRom: test.Printf(_L("CD Rom\n")); break; |
|
727 case EMediaRam: test.Printf(_L("Ram\n")); break; |
|
728 case EMediaFlash: test.Printf(_L("Flash\n")); break; |
|
729 case EMediaRom: test.Printf(_L("Rom\n")); break; |
|
730 case EMediaRemote: test.Printf(_L("Remote\n")); break; |
|
731 default: |
|
732 test.Printf(_L("Unknown value\n")); |
|
733 } |
|
734 } |
|
735 |
|
736 LOCAL_C void DriveInfo(TInt aDrive,TDriveInfo& anInfo) |
|
737 // |
|
738 // Test the drive info is reasonable |
|
739 // |
|
740 { |
|
741 |
|
742 test(anInfo.iBattery==EBatLow || anInfo.iBattery==EBatGood || anInfo.iBattery==EBatNotSupported); |
|
743 |
|
744 if (aDrive==EDriveZ) |
|
745 { |
|
746 if (anInfo.iType==EMediaNotPresent) |
|
747 return; |
|
748 |
|
749 test(anInfo.iMediaAtt==KMediaAttWriteProtected); |
|
750 test(anInfo.iDriveAtt==(KDriveAttRom|KDriveAttInternal)); |
|
751 test(anInfo.iType==EMediaRom); |
|
752 } |
|
753 |
|
754 /* |
|
755 Why assume certain drive letters can only refer to certain drive types? |
|
756 else if (aDrive==EDriveC || aDrive==EDriveY) |
|
757 { |
|
758 if (anInfo.iType==EMediaNotPresent) |
|
759 return; |
|
760 |
|
761 // test(anInfo.iDriveAtt==(KDriveAttLocal|KDriveAttInternal)); |
|
762 |
|
763 test(anInfo.iDriveAtt&(KDriveAttLocal|KDriveAttInternal)==KDriveAttLocal|KDriveAttInternal); // LFFS sets KDriveAttTransaction as well |
|
764 test(anInfo.iType==EMediaRam || anInfo.iType==EMediaFlash); |
|
765 if(anInfo.iType==EMediaRam) test(anInfo.iMediaAtt==(KMediaAttVariableSize|KMediaAttFormattable)); |
|
766 else if(anInfo.iType==EMediaFlash) test(anInfo.iMediaAtt==KMediaAttFormattable); |
|
767 } |
|
768 |
|
769 else if (aDrive==EDriveD || aDrive==EDriveX) |
|
770 { |
|
771 if (anInfo.iType==EMediaNotPresent) |
|
772 return; |
|
773 |
|
774 test(anInfo.iDriveAtt==(KDriveAttLocal|KDriveAttRemovable)); |
|
775 test(anInfo.iType==EMediaHardDisk); |
|
776 test(anInfo.iMediaAtt&KMediaAttFormattable); |
|
777 } |
|
778 */ |
|
779 } |
|
780 |
|
781 void TSessionTest::CreateTestDirectory(const TDesC& aSessionPath) |
|
782 // |
|
783 // Create directory for test |
|
784 // |
|
785 { |
|
786 TParsePtrC path(aSessionPath); |
|
787 test(path.DrivePresent()==EFalse); |
|
788 |
|
789 TInt r=iFs.SetSessionPath(aSessionPath); |
|
790 test_KErrNone(r); |
|
791 r=iFs.SessionPath(gTestSessionPath); |
|
792 test_KErrNone(r); |
|
793 r=iFs.MkDirAll(gTestSessionPath); |
|
794 test_Value(r, r==KErrNone || r==KErrAlreadyExists); |
|
795 } |
|
796 |
|
797 TInt TSessionTest::CurrentDrive() |
|
798 // |
|
799 // Return the current drive number |
|
800 // |
|
801 { |
|
802 |
|
803 TInt driveNum; |
|
804 TInt r=iFs.CharToDrive(gTestSessionPath[0],driveNum); |
|
805 test_KErrNone(r); |
|
806 return(driveNum); |
|
807 } |
|
808 |