Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // f32test\fsstress\t_sesfs.cpp
17 #define __E32TEST_EXTENSION__
20 GLDEF_D TFileName tPath;
21 GLREF_D TFileName gExeFileName;
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);
28 void TSessionTest::Initialise(RFs& aFs)
37 void TSessionTest::RunTests()
39 // Run tests on iFs file server session
49 CreateTestDirectory(_L("\\SESSION_TEST\\TFSRV\\"));
52 CopyFileToTestDirectory();
58 void TSessionTest::testDriveList()
60 // Test the drive list.
64 test.Start(_L("The drive list"));
67 TInt r=iFs.DriveList(list);
69 for (TInt i=0;i<KMaxDrives;i++)
73 r = iFs.Drive(info, i);
75 printDriveAtt(i,info.iDriveAtt);
82 void TSessionTest::testDriveInfo()
84 // Test the drive info.
88 test.Start(_L("The drive info"));
90 TInt r=iFs.DriveList(list);
92 for (TInt i=0;i<KMaxDrives;i++)
101 test.Printf(_L("\n"));
109 void TSessionTest::testVolumeInfo()
115 test.Start(_L("The volume info"));
117 TInt r=iFs.DriveList(list);
119 for (TInt i=0;i<KMaxDrives;i++)
123 switch (r=iFs.Volume(v,i))
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);
133 if (d.iType == EMediaNotPresent)
134 test.Printf(_L("%c: Medium not present - cannot perform test.\n"), i + 'A');
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');
138 case KErrPathNotFound:
139 test.Printf(_L("%c: Not Found\n"), i + 'A');
142 test.Printf(_L("%c: Media corruption; previous test may have aborted; else, check hardware\n"), i + 'A');
144 test.Printf(_L("%c: Error %d - aborting test.\n"),i + 'A', r);
147 test.Printf(_L("\n"));
154 void TSessionTest::testPath()
156 // Test the path handling.
160 test.Start(_L("Test path handling"));
165 r=iFs.SessionPath(p);
167 test.Printf(_L("SESSION=\"%S\"\n"),&p);
168 r=iFs.SetSessionPath(_L("A:\\TEST\\"));
170 r=iFs.SessionPath(p);
172 test(p==_L("A:\\TEST\\"));
173 r=iFs.SetSessionPath(gTestSessionPath);
180 void TSessionTest::testInitialisation()
182 // Tests that calls to CheckedClose() are OK, ie, tests bug fix
185 test.Next(_L("Test calls to CheckedClose are OK"));
192 TInt r=format.Open(iFs,_L("Z:\\"),EFullFormat,count);
194 test_Value(r, r==KErrAccessDenied || r==KErrInUse);
196 r=dir.Open(iFs,_L("\\SESSION_TEST\\ERRORTEST\\"),KEntryAttMatchMask);
197 test_Value(r, r==KErrPathNotFound);
199 r=file.Open(iFs,_L("\\SESSION_TEST\\SessionTest1.txt"),EFileRead);
200 test_Value(r, r==KErrNotFound);
202 r=dir.Open(iFs,_L("\\SESSION_TEST\\ERRORTEST2\\"),KEntryAttMatchMask);
203 test_Value(r, r==KErrPathNotFound);
205 r=file.Open(iFs,_L("\\SESSION_TEST\\SessionTest2.txt"),EFileRead);
206 test_Value(r, r==KErrNotFound);
208 r=dir.Open(iFs,_L("\\SESSION_TEST\\ERRORTEST3\\"),KEntryAttMatchMask);
209 test_Value(r, r==KErrPathNotFound);
211 r=file.Open(iFs,_L("\\SESSION_TEST\\SessionTest3.txt"),EFileRead);
212 test_Value(r, r==KErrNotFound);
214 r=file.Open(iFs,_L("\\SESSION_TEST\\SessionTest4.txt"),EFileRead);
215 test_Value(r, r==KErrNotFound);
223 void TSessionTest::testSubst()
225 // Test the substitute functions.
229 test.Printf(_L("Test subst"));
231 TInt r=iFs.Volume(v);
237 TDriveInfo driveInfo;
238 r=iFs.Drive(driveInfo,EDriveO);
243 if (driveInfo.iDriveAtt==KDriveAttLocal)
245 return; // Subst local drives fails
249 r=iFs.Subst(n,EDriveO);
252 r=iFs.SetSubst(gTestSessionPath,EDriveO);
254 r=iFs.Subst(n,EDriveO);
256 test(n==gTestSessionPath);
258 r=iFs.Volume(w,EDriveO);
260 test(w.iDrive.iType==v.iDrive.iType);
261 test(w.iDrive.iConnectionBusType==v.iDrive.iConnectionBusType);
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);
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
270 if(User::UpperCase(gTestSessionPath[0]) != 'C')
273 test(w.iFree==v.iFree);
279 test(w.iName==v.iName);
280 TDriveList driveList;
281 r=iFs.DriveList(driveList);
283 test(driveList[EDriveO]==KDriveAttSubsted);
285 r=iFs.Drive(d,EDriveO);
287 test(d.iDriveAtt==KDriveAttSubsted);
288 test(d.iMediaAtt==origDI.iMediaAtt);
289 test(d.iType==origDI.iType);
290 test(d.iConnectionBusType==origDI.iConnectionBusType);
293 test.Next(_L("Test real name"));
294 r=iFs.RealName(_L("O:\\FILE.XXX"),n);
296 TFileName substedPath=gTestSessionPath;
297 substedPath.Append(_L("FILE.XXX"));
298 test(n.CompareF(substedPath)==KErrNone);
300 test.Next(_L("Test MkDir, Rename and RmDir on Substed drive"));
301 _LIT(KTurgid,"turgid\\");
302 TFileName dir=gTestSessionPath;
309 r=iFs.RmDir(_L("O:\\turgid\\subdir\\"));
311 r=iFs.Rename(_L("O:\\turgid"), _L("O:\\facile"));
313 r=iFs.MkDir(_L("O:\\insipid\\"));
315 r=iFs.Rename(_L("O:\\insipid"), _L("O:\\glib"));
317 r=iFs.RmDir(_L("O:\\facile\\"));
319 _LIT(KGlib,"glib\\");
320 dir=gTestSessionPath;
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;
333 r=f1.Create(iFs,name1,EFileShareExclusive|EFileWrite);
337 TBool isValid=iFs.IsValidName(name2);
342 r=f1.Create(iFs,name1,EFileShareExclusive|EFileWrite);
345 r=iFs.Replace(name2,name1);
349 test.Next(_L("Test notifications on Substed drive"));
350 name1=gTestSessionPath;
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);
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);
375 User::WaitForRequest(status3);
376 test(status3==KErrNone && status1==KRequestPending && status2==KRequestPending);
378 iFs.NotifyChangeCancel();
379 test(status1==KErrCancel && status2==KErrCancel);
380 User::WaitForRequest(status1);
381 User::WaitForRequest(status2);
387 test.Next(_L("Test file systems on Substed drive"));
388 // test cannot mount file system on substituted drive
390 r=iFs.CharToDrive(gTestSessionPath[0],sessionDrv);
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
402 r=format.Open(iFs,SubstRoot,EHighDensity,count);
403 test_Value(r, r==KErrAccessDenied);
405 r=iFs.SetSubst(_L(""),EDriveO);
407 r=iFs.Subst(n,EDriveO);
410 r=iFs.Drive(d,EDriveO);
412 test(d.iDriveAtt==0);
416 LOCAL_C TInt CreateFileX(const TDesC& aBaseName,TInt aX, RFs iFs)
418 // Create a large file. Return KErrEof or KErrNone
422 TBuf<128> fileName=aBaseName;
423 fileName.AppendNum(aX);
425 TInt r=file.Replace(iFs,fileName,EFileWrite);
430 test.Printf(_L("ERROR:: Replace returned %d\n"),r);
431 return(KErrDiskFull);
433 r=file.SetSize(65536);
441 test.Printf(_L("ERROR:: SetSize returned %d\n"),r);
443 return(KErrDiskFull);
446 // r=iFs.CheckDisk(fileName);
447 // if (r!=KErrNone && r!=KErrNotSupported)
449 // test.Printf(_L("ERROR:: CheckDisk returned %d\n"),r);
451 // return(KErrDiskFull);
453 test.Printf(_L("Created file %d size 64k\n"),aX);
457 LOCAL_C TInt DeleteFileX(TBuf<128>& aBaseName,TInt aX, RFs iFs)
463 TBuf<128> fileName=aBaseName;
464 fileName.AppendNum(aX);
465 TInt r=iFs.Delete(fileName);
467 // r=iFs.CheckDisk(fileName);
468 // if (r!=KErrNone && r!=KErrNotSupported)
470 // test.Printf(_L("ERROR:: CheckDisk returned %d\n"),r);
473 test.Printf(_L("Deleted File %d\n"),aX);
477 void TSessionTest::MakeAndDeleteFiles()
479 // Create and delete large files in a randomish order
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);
489 r=CreateFileX(fileName,1,iFs);
491 r=DeleteFileX(fileName,0,iFs);
493 r=CreateFileX(fileName,2,iFs);
495 r=CreateFileX(fileName,1,iFs);
497 r=CreateFileX(fileName,3,iFs);
499 r=DeleteFileX(fileName,1,iFs);
501 r=CreateFileX(fileName,4,iFs);
503 r=DeleteFileX(fileName,2,iFs);
505 r=DeleteFileX(fileName,3,iFs);
507 r=DeleteFileX(fileName,4,iFs);
509 r=CreateFileX(fileName,1,iFs);
511 r=DeleteFileX(fileName,1,iFs);
514 r=iFs.CheckDisk(fileName);
515 test_Value(r, r==KErrNone || r==KErrNotSupported);
519 void TSessionTest::FillUpDisk()
521 // Test that a full disk is ok
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);
529 TFileName sessionPath;
530 r=iFs.SessionPath(sessionPath);
532 TBuf<128> fileName=_L("\\SESSION_TEST\\BIGDIRECTORY\\FILE");
535 TInt r=CreateFileX(fileName,count,iFs);
540 #if defined(__WINS__)
541 if (count==32 && sessionPath[0]=='C') // Don't fill up disk on NT
546 r=iFs.CheckDisk(fileName);
547 test_Value(r, r==KErrNone || r==KErrNotSupported);
550 DeleteFileX(fileName,count,iFs);
552 r=iFs.CheckDisk(fileName);
553 test_Value(r, r==KErrNone || r==KErrNotSupported);
558 void TSessionTest::CopyFileToTestDirectory()
560 // Make a copy of the file in ram
564 TFileName fn = _L("Z:\\TEST\\T_FSRV.CPP");
565 fn[0] = gExeFileName[0];
567 TInt r=iFs.Parse(fn,f);
569 test.Next(_L("Copying file to test directory"));
571 r=iFs.Parse(f.NameAndExt(),fCopy);
575 r=f1.Open(iFs,f.FullName(),EFileStreamText|EFileShareReadersOnly);
576 test.Printf(_L("r=%d\n"),r);
579 r=f2.Replace(iFs,fCopy.FullName(),EFileWrite);
588 TInt s=Min(rem,copyBuf.MaxSize());
589 r=f1.Read(pos,copyBuf,s);
591 test(copyBuf.Length()==s);
592 r=f2.Write(pos,copyBuf,s);
602 void TSessionTest::testSetVolume()
604 // Test setting the volume info.
608 test.Start(_L("Test setting the volume label"));
610 #if defined(_UNICODE)
611 test.Printf(_L("Unicode volume label set not implemented ****\n"));
615 TInt driveNum=CurrentDrive();
617 TInt r=iFs.Volume(v,driveNum);
620 test.Printf(_L("VOL=\"%S\"\n"),&n);
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)
627 test.Printf(_L("Error %d: Set volume label not testing on WINS\n"),r);
633 r=iFs.Volume(v,driveNum);
635 test(v.iName==_L(""));
636 test.Printf(_L("VOL=\"%S\"\n"),&v.iName);
638 test.Next(_L("Set volume label to ABCDEFGHIJK"));
639 r=iFs.SetVolumeLabel(_L("ABCDEFGHIJK"),driveNum);
641 r=iFs.Volume(v,driveNum);
643 test(v.iName==_L("ABCDEFGHIJK"));
644 test.Printf(_L("VOL=\"%S\"\n"),&v.iName);
646 test.Next(_L("Set volume label back to nothing"));
647 r=iFs.SetVolumeLabel(_L(""),driveNum);
649 r=iFs.Volume(v,driveNum);
651 test(v.iName==_L(""));
652 test.Printf(_L("VOL=\"%S\"\n"),&v.iName);
654 test.Next(_L("Set volume label to original"));
655 r=iFs.SetVolumeLabel(n,driveNum);
657 r=iFs.Volume(v,driveNum);
660 test.Printf(_L("VOL=\"%S\"\n"),&v.iName);
666 LOCAL_C void printDriveAtt(TInt aDrive,TUint anAtt)
668 // Print a drive attribute.
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"));
692 LOCAL_C void printDriveInfo(TInt aDrive,TDriveInfo& anInfo)
694 // Print a drive info.
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 CONNECTION BUS="));
711 switch(anInfo.iConnectionBusType)
713 case EConnectionBusInternal: test.Printf(_L("Internal\n")); break;
714 case EConnectionBusUsb: test.Printf(_L("USB\n")); break;
716 test.Printf(_L("Unknown value\n"));
718 test.Printf(_L(" MEDIA="));
721 case EMediaNotPresent: test.Printf(_L("Not present\n")); break;
722 case EMediaUnknown: test.Printf(_L("Unknown\n")); break;
723 case EMediaFloppy: test.Printf(_L("Floppy\n")); break;
724 case EMediaHardDisk: test.Printf(_L("Hard disk\n")); break;
725 case EMediaCdRom: test.Printf(_L("CD Rom\n")); break;
726 case EMediaRam: test.Printf(_L("Ram\n")); break;
727 case EMediaFlash: test.Printf(_L("Flash\n")); break;
728 case EMediaRom: test.Printf(_L("Rom\n")); break;
729 case EMediaRemote: test.Printf(_L("Remote\n")); break;
731 test.Printf(_L("Unknown value\n"));
735 LOCAL_C void DriveInfo(TInt aDrive,TDriveInfo& anInfo)
737 // Test the drive info is reasonable
741 test(anInfo.iConnectionBusType==EConnectionBusInternal || anInfo.iConnectionBusType==EConnectionBusUsb);
745 if (anInfo.iType==EMediaNotPresent)
748 test(anInfo.iMediaAtt==KMediaAttWriteProtected);
749 test(anInfo.iDriveAtt==(KDriveAttRom|KDriveAttInternal));
750 test(anInfo.iType==EMediaRom);
754 Why assume certain drive letters can only refer to certain drive types?
755 else if (aDrive==EDriveC || aDrive==EDriveY)
757 if (anInfo.iType==EMediaNotPresent)
760 // test(anInfo.iDriveAtt==(KDriveAttLocal|KDriveAttInternal));
762 test(anInfo.iDriveAtt&(KDriveAttLocal|KDriveAttInternal)==KDriveAttLocal|KDriveAttInternal); // LFFS sets KDriveAttTransaction as well
763 test(anInfo.iType==EMediaRam || anInfo.iType==EMediaFlash);
764 if(anInfo.iType==EMediaRam) test(anInfo.iMediaAtt==(KMediaAttVariableSize|KMediaAttFormattable));
765 else if(anInfo.iType==EMediaFlash) test(anInfo.iMediaAtt==KMediaAttFormattable);
768 else if (aDrive==EDriveD || aDrive==EDriveX)
770 if (anInfo.iType==EMediaNotPresent)
773 test(anInfo.iDriveAtt==(KDriveAttLocal|KDriveAttRemovable));
774 test(anInfo.iType==EMediaHardDisk);
775 test(anInfo.iMediaAtt&KMediaAttFormattable);
780 void TSessionTest::CreateTestDirectory(const TDesC& aSessionPath)
782 // Create directory for test
785 TParsePtrC path(aSessionPath);
786 test(path.DrivePresent()==EFalse);
788 TInt r=iFs.SetSessionPath(aSessionPath);
790 r=iFs.SessionPath(gTestSessionPath);
792 r=iFs.MkDirAll(gTestSessionPath);
793 test_Value(r, r==KErrNone || r==KErrAlreadyExists);
796 TInt TSessionTest::CurrentDrive()
798 // Return the current drive number
803 TInt r=iFs.CharToDrive(gTestSessionPath[0],driveNum);