Update contrib.
1 // Copyright (c) 1995-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.
19 #include <e32std_private.h>
21 #include <e32def_private.h>
25 GLDEF_D RTest test(_L("t_dcallcaps"));
26 GLDEF_D TTime gTimeNow;
27 LOCAL_D TInt gTheDriveNum;
30 const TInt KPathPosition = 2;
31 _LIT(KExpectedPrivatePath, "\\Private\\00000001\\");
32 _LIT(KResourcePath, "?:\\Resource\\");
33 _LIT(KSystemPath, "?:\\Sys\\");
34 _LIT(KPrivatePath, "?:\\Private\\");
35 _LIT(KPrivateFalseID, "?:\\Private\\FFFFFFFF\\");
36 _LIT(KDriveName, "Billy");
37 _LIT(KVolLable, "Benny");
38 _LIT(KFileSys, "systemfile.txt");
39 _LIT(KFileSys3, "sysfile.rna");
40 _LIT(KFilePri, "privatefile.txt");
41 _LIT(KFilePri2, "privatefile.tmp");
42 _LIT(KFilePri3, "prifile.rna");
43 _LIT(KFileRes, "resourcefile.txt");
44 _LIT(KFileRes3, "resfile.rna");
45 _LIT(KMkDirSub,"Subdir\\");
46 _LIT(KOldFile,"?:\\Anyold.txt");
47 _LIT(KWildPath, "Z:\\SYS\\");
51 TBuf<4> driveBuf=_L("?:\\");
64 TBuf<40> theprivatepath;
65 TBuf<40> pritestfalseidname;
71 TBuf<40> shortfilename;
72 TBuf<40> longfilename;
74 TRequestStatus aStat1;
75 TRequestStatus aStat2;
76 TRequestStatus aStat3;
77 TRequestStatus aStat4;
80 // TDriveInfo adriveInfo;
85 TBuf<40> systestfile1;
86 TBuf<40> pritestfile1;
87 TBuf<40> restestfile1;
96 LOCAL_C void systemRFsTest()
98 // RFs test on system Directory
101 systestname=KSystemPath;
102 systestname[0]=(TText)('A' + gTheDriveNum);
105 mkdirname.Append(systestname);
106 mkdirname.Append(KMkDirSub);
107 r=TheFs.MkDirAll(mkdirname);
110 TheFs.RmDir(mkdirname);
113 r=TheFs.SetSubst(systestname,EDriveO);
116 r=TheFs.RealName(_L("O:\\File.XXX"),realName);
119 r=TheFs.SetSubst(_L(""),EDriveO); //to unsubst
122 r=TheFs.SetSessionPath(systestname);
125 TheFs.NotifyChange(ENotifyAll,aStat1,systestname);
126 test(aStat1==KRequestPending);
128 systestfile=KSystemPath;
129 systestfile[0]=(TText)('A' + gTheDriveNum);
130 systestfile1=systestfile;
131 systestfile.Append(KFileSys);
132 systestfile1.Append(KFileSys3);
135 oldName[0]=(TText)gDriveToTest;
137 r=TheFs.GetShortName(systestfile, shortfilename);
138 test(r==KErrNotFound || r==KErrNotSupported);
140 r=TheFs.GetLongName(systestfile1, longfilename);
141 test(r==KErrNotFound || r==KErrNotSupported);
143 r=file1.Create(TheFs,oldName,EFileWrite);
144 test(r==KErrNone || r==KErrAlreadyExists);
147 r=TheFs.Replace(oldName,systestfile);
150 r=TheFs.Rename(systestfile,systestfile1);
153 r=TheFs.Entry(systestfile1,entry);
156 r=TheFs.SetEntry(systestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
159 r=TheFs.Delete(systestfile1);
163 LOCAL_C void ResourceRFsTest()
168 restestname=KResourcePath;
169 restestname[0]=(TText)('A' + gTheDriveNum);
172 mkdirname.Append(restestname);
173 mkdirname.Append(KMkDirSub);
174 r=TheFs.MkDirAll(mkdirname);
177 TheFs.RmDir(mkdirname);
180 r=TheFs.SetSubst(restestname,EDriveO);
183 r=TheFs.RealName(_L("O:\\File.XXX"),realName);
186 r=TheFs.SetSubst(_L(""),EDriveO);
189 r=TheFs.SetSessionPath(restestname);
192 TheFs.NotifyChange(ENotifyAll,aStat4,restestname);
193 test(aStat4==KRequestPending);
195 restestfile=KResourcePath;
196 restestfile[0]=(TText)('A' + gTheDriveNum);
197 restestfile1=restestfile;
198 restestfile.Append(KFileRes);
199 restestfile1.Append(KFileRes3);
202 oldName[0]=(TText)gDriveToTest;
204 r=TheFs.GetShortName(restestfile, shortfilename);
205 test(r==KErrNone || r==KErrNotFound || r==KErrNotSupported);
207 r=TheFs.GetLongName(restestfile1, longfilename);
208 test(r==KErrNone || r==KErrNotFound || r==KErrNotSupported);
210 r=file1.Create(TheFs,oldName,EFileWrite);
211 test(r==KErrNone || r==KErrAlreadyExists);
214 r=TheFs.Replace(oldName,restestfile);
217 r=TheFs.Rename(restestfile,restestfile1);
220 r=TheFs.Entry(restestfile1,entry);
223 r=TheFs.SetEntry(restestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
226 r=TheFs.Delete(restestfile1);
232 LOCAL_C void privatefalseIDRFsTest()
238 pritestfalseidname=KPrivateFalseID;
239 pritestfalseidname[0]=(TText)('A' + gTheDriveNum);
242 mkdirname.Append(pritestfalseidname);
243 mkdirname.Append(KMkDirSub);
245 r=TheFs.MkDirAll(mkdirname);
248 r=TheFs.RmDir(mkdirname);
251 r=TheFs.SetSubst(pritestfalseidname,EDriveO);
254 r=TheFs.RealName(_L("O:\\File.XXX"),realName);
257 r=TheFs.SetSubst(_L(""),EDriveO);
260 r=TheFs.SetSessionPath(pritestfalseidname);
263 TheFs.NotifyChange(ENotifyAll,aStat2,pritestfalseidname);
264 test(aStat2==KRequestPending);
267 pritestfile=KPrivateFalseID;
268 pritestfile[0]=(TText)('A' + gTheDriveNum);
269 pritestfile1=pritestfile;
270 pritestfile.Append(KFilePri2);
271 pritestfile1.Append(KFilePri3);
274 oldName[0]=(TText)gDriveToTest;
276 r=TheFs.GetShortName(pritestfile, shortfilename);
277 test(r==KErrNone || r==KErrNotFound || r==KErrNotSupported);
279 r=TheFs.GetLongName(pritestfile1, longfilename);
280 test(r==KErrNone || r==KErrNotFound || r==KErrNotSupported);
282 r=file1.Create(TheFs,oldName,EFileWrite);
283 test(r==KErrNone || r==KErrAlreadyExists);
286 r=TheFs.Replace(oldName,pritestfile);
289 r=TheFs.Rename(pritestfile,pritestfile1);
292 r=TheFs.Entry(pritestfile1,entry);
295 r=TheFs.SetEntry(pritestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
298 r=TheFs.Delete(pritestfile1);
305 LOCAL_C void privateRFsTest()
311 pritestname=KPrivatePath;
312 pritestname[0]=(TText)('A' + gTheDriveNum);
315 mkdirname.Append(pritestname);
316 mkdirname.Append(KMkDirSub);
318 r=TheFs.MkDirAll(mkdirname);
321 r=TheFs.RmDir(mkdirname);
324 r=TheFs.SetSubst(pritestname,EDriveO);
327 r=TheFs.RealName(_L("O:\\File.XXX"),realName);
330 r=TheFs.SetSubst(_L(""),EDriveO);
333 r=TheFs.SetSessionPath(pritestname);
336 TheFs.NotifyChange(ENotifyAll,aStat2,pritestname);
337 test(aStat2==KRequestPending);
340 pritestfile=KPrivatePath;
341 pritestfile[0]=(TText)('A' + gTheDriveNum);
342 pritestfile1=pritestfile;
343 pritestfile.Append(KFilePri2);
344 pritestfile1.Append(KFilePri3);
347 oldName[0]=(TText)gDriveToTest;
349 r=TheFs.GetShortName(pritestfile, shortfilename);
350 test(r==KErrNone || r==KErrNotFound || r==KErrNotSupported);
352 r=TheFs.GetLongName(pritestfile1, longfilename);
353 test(r==KErrNone || r==KErrNotFound || r==KErrNotSupported);
355 r=file1.Create(TheFs,oldName,EFileWrite);
356 test(r==KErrNone || r==KErrAlreadyExists);
359 r=TheFs.Replace(oldName,pritestfile);
362 r=TheFs.Rename(pritestfile,pritestfile1);
365 r=TheFs.Entry(pritestfile1,entry);
368 r=TheFs.SetEntry(pritestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
371 r=TheFs.Delete(pritestfile1);
377 LOCAL_C void privateSIDRFstest()
379 theprivatepath[0]=(TText)gDriveToTest;
380 test.Printf(_L("the Private Path = %S"),&theprivatepath);
383 mkdirname.Append(theprivatepath);
384 mkdirname.Append(KMkDirSub);
385 r=TheFs.MkDirAll(mkdirname);
388 r=TheFs.RmDir(mkdirname);
391 r=TheFs.SetSubst(theprivatepath,EDriveO);
394 r=TheFs.RealName(_L("O:\\File.XXX"),realName);
397 r=TheFs.SetSubst(_L(""),EDriveO);
400 r=TheFs.SetSessionPath(theprivatepath);
403 TheFs.NotifyChange(ENotifyAll,aStat3,theprivatepath);
404 test(aStat3==KRequestPending);
406 pritestfile=theprivatepath;
407 pritestfile[0]=(TText)('A' + gTheDriveNum);
408 pritestfile1=pritestfile;
409 pritestfile.Append(KFilePri2);
410 pritestfile1.Append(KFilePri3);
413 oldName[0]=(TText)gDriveToTest;
415 r=TheFs.GetShortName(pritestfile, shortfilename);
416 test(r==KErrNone || r==KErrNotFound || r==KErrNotSupported);
418 r=TheFs.GetLongName(pritestfile1, longfilename);
419 test(r==KErrNone || r==KErrNotFound || r==KErrNotSupported);
421 r=file1.Create(TheFs,oldName,EFileWrite);
422 test(r==KErrNone || r==KErrAlreadyExists);
425 r=TheFs.Replace(oldName,pritestfile);
428 r=TheFs.Rename(pritestfile,pritestfile1);
429 test(r==KErrNone || r==KErrAlreadyExists);
431 r=TheFs.Entry(pritestfile1,entry);
434 r=TheFs.SetEntry(pritestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
437 r=TheFs.Delete(pritestfile1);
442 LOCAL_C void systemRFiletest()
444 //RFile testing with session path set to //system//
448 r=TheFs.SetSessionPath(systestname);
451 r=file1.Temp(TheFs,systestname,fromTemp,EFileWrite);
455 r=file1.Create(TheFs,KFileSys,EFileWrite);
459 r=file1.Open(TheFs,KFileSys,EFileWrite);
463 r=file1.Open(TheFs,KFileSys,EFileRead);
467 r=file1.Replace(TheFs,KFileSys,EFileWrite);
470 r=file1.Rename(KFileSys3);
474 TFindFile finder(TheFs);
476 r=finder.FindWildByDir(KWildFile, KWildPath, dir);
478 test.Printf(_L("T_DCALLCAPS: test find wildcards r = %d (expected KErrNone)\n"), r);
483 LOCAL_C void resourceRFiletest()
485 //RFile testing with session path set to //resource//
488 r=TheFs.SetSessionPath(restestname);
491 r=file1.Temp(TheFs,restestname,fromTemp,EFileWrite);
495 r=file1.Create(TheFs,KFileRes,EFileWrite);
499 r=file1.Open(TheFs,KFileRes,EFileWrite|EFileShareExclusive );
502 r=file1.Rename(KFileRes3);
506 r=file1.Open(TheFs,KFileRes3,EFileShareReadersOrWriters|EFileRead);
510 r=file1.Open(TheFs,KFileRes3,EFileShareReadersOrWriters|EFileWrite);
514 r=file1.Open(TheFs,KFileRes3,EFileShareReadersOnly);
517 r=file1.ChangeMode(EFileShareExclusive);
521 r=file1.Replace(TheFs,KFileRes,EFileWrite);
527 LOCAL_C void privatefalseIDRFiletest()
529 //RFile testing with session path set to //Private//falseID
532 r=TheFs.SetSessionPath(pritestfalseidname);
535 r=file1.Temp(TheFs,pritestfalseidname,fromTemp,EFileWrite);
539 r=file1.Create(TheFs,KFilePri,EFileWrite);
543 r=file1.Open(TheFs,KFilePri,EFileWrite);
547 r=file1.Open(TheFs,KFilePri,EFileRead);
551 r=file1.Replace(TheFs,KFilePri,EFileWrite);
554 r=file1.Rename(KFilePri3);
559 LOCAL_C void privateRFiletest()
561 //RFile testing with session path set to //Private//falseID
564 r=TheFs.SetSessionPath(pritestname);
567 r=file1.Temp(TheFs,pritestname,fromTemp,EFileWrite);
571 r=file1.Create(TheFs,KFilePri,EFileWrite);
575 r=file1.Open(TheFs,KFilePri,EFileWrite);
579 r=file1.Open(TheFs,KFilePri,EFileRead);
583 r=file1.Replace(TheFs,KFilePri,EFileWrite);
586 r=file1.Rename(KFilePri3);
593 LOCAL_C void privateSIDRFiletest()
595 //Rfile Testing with session path set to //Private//UID//
598 r=TheFs.SetSessionToPrivate(gTheDriveNum);
601 r=file1.Temp(TheFs,theprivatepath,fromTemp,EFileWrite);
605 r=file1.Create(TheFs,KFilePri,EFileWrite);
609 r=file1.Open(TheFs,KFilePri,EFileWrite);
613 r=file1.Open(TheFs,KFilePri,EFileRead);
617 r=file1.Replace(TheFs,KFilePri,EFileWrite);
620 r=file1.Rename(KFilePri3);
625 LOCAL_C void RDirtest()
633 TBuf<30> dirNameBuf(KSystemPath);
634 dirNameBuf[0]=(TText)gDriveToTest;
635 r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
638 r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
643 dirNameBuf=KPrivateFalseID;
644 dirNameBuf[0]=(TText)gDriveToTest;
645 r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
648 r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
653 dirNameBuf=KPrivatePath;
654 dirNameBuf[0]=(TText)gDriveToTest;
655 r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
658 r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
663 TheFs.PrivatePath(dirNameBuf);
664 dirNameBuf.Insert(0,_L("?:"));
665 dirNameBuf[0]=(TText)gDriveToTest;
666 r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
669 r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
674 dirNameBuf=KResourcePath;
675 dirNameBuf[0]=(TText)gDriveToTest;
676 r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
678 r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
685 LOCAL_C void TestAllCaps()
687 // Test with root capabilities
690 r=TheFs.FileSystemName(fsname,gTheDriveNum);
691 test(r==KErrNone || r==KErrNotFound);
692 r=DismountFileSystem(TheFs, fsname,gTheDriveNum);
693 test(r==KErrNone || r==KErrNotFound);
694 // r=TheFs.RemoveFileSystem(fsname); //can not test due to bug else where fix exists
695 // test(r==KErrNone);
696 // r=TheFs.AddFileSystem(fsname);
697 // test(r==KErrNone);
698 r=MountFileSystem(TheFs,fsname,gTheDriveNum);
700 r=TheFs.SetDriveName(gTheDriveNum,KDriveName);
703 r=TheFs.SetVolumeLabel(KVolLable, gTheDriveNum);
711 privatefalseIDRFsTest();
716 privateSIDRFiletest();
717 privatefalseIDRFiletest();
719 //check notifier return values set in rfs testing
720 User::WaitForRequest(aStat1);
721 User::WaitForRequest(aStat2);
722 User::WaitForRequest(aStat3);
723 User::WaitForRequest(aStat4);
724 test(aStat1==KErrNone);
725 test(aStat2==KErrNone);
726 test(aStat3==KErrNone);
727 test(aStat4==KErrNone);
729 r=TheFs.SetSessionPath(systestname);
732 //Test RRawDisk class
733 r=rawdisk.Open(TheFs,gTheDriveNum);
740 if (User::UpperCase(driveBuf[0]) != 'C')
744 r=format.Open(TheFs,driveBuf,EHighDensity,count);
749 TInt r=format.Next(count);
755 driveBuf[0]=(TText)gDriveToTest;
756 r=TheFs.ScanDrive(driveBuf);
757 test(r==KErrNone || r==KErrNotSupported);
758 r=TheFs.CheckDisk(driveBuf);
759 test(r==KErrNone || r==KErrNotSupported);
762 LOCAL_C void TestCaps()
764 // test format etc that require certain capabilities
767 #ifndef __REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
768 const char myDiagMsg[] = __PLATSEC_DIAGNOSTIC_STRING("Capability Check Failure");
769 #endif //!__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
771 r=RProcess().HasCapability(ECapabilityAllFiles, __PLATSEC_DIAGNOSTIC_STRING(myDiagMsg));
773 r=RProcess().HasCapability(ECapabilityTCB, __PLATSEC_DIAGNOSTIC_STRING(myDiagMsg));
775 r=RProcess().HasCapability(ECapabilityDiskAdmin, __PLATSEC_DIAGNOSTIC_STRING(myDiagMsg));
778 driveBuf[0]=(TText)gDriveToTest;
779 r=TheFs.SessionPath(temp);
782 test.Printf(_L("Session path: %S"),&temp);
784 r=TheFs.CreatePrivatePath(gTheDriveNum);
785 test(r==KErrNone || r== KErrAlreadyExists);
788 r=TheFs.PrivatePath(tempPri);
790 theprivatepath = _L("?:");
791 theprivatepath.Append(tempPri);
795 TFileName thesessionpath;
797 r=TheFs.SetSessionToPrivate(gTheDriveNum);
799 r=TheFs.SessionPath(thesessionpath);
802 test(thesessionpath == theprivatepath);
805 LOCAL_C void CleanupL()
810 test.Next(_L("Delete test directory"));
811 CFileMan* fMan=CFileMan::NewL(TheFs);
812 TInt r=fMan->RmDir(gSessionPath);
813 test(r==KErrNone || KErrPathNotFound);
817 GLDEF_C void CallTestsL(/*TChar aDriveLetter*/)
822 TurnAllocFailureOff();
823 TheFs.CharToDrive(gDriveToTest,gTheDriveNum);
827 sesspath[0] = (TText)gDriveToTest;
829 TInt r= TheFs.SetSessionPath(sesspath);
832 //cleanup from previous run of this test
834 CFileMan* fMan=CFileMan::NewL(TheFs);
835 delDir=KResourcePath;
836 delDir[0]=(TText)gDriveToTest;
837 r=fMan->RmDir(delDir);
838 test(r==KErrNone || KErrNotFound);
840 delDir[0]=(TText)gDriveToTest;
841 r=fMan->RmDir(delDir);
842 test(r==KErrNone || KErrNotFound);
844 delDir[0]=(TText)gDriveToTest;
845 r=fMan->RmDir(delDir);
846 test(r==KErrNone || KErrNotFound);
849 //check double mode ie that Defpath still works
855 r=fs1.SessionPath(sesspath);
857 test.Printf(_L("session1 Path=%S"),&sesspath);
859 TBuf<30> privatepath;
860 r=fs1.SetSessionToPrivate(gTheDriveNum);
862 r=fs1.PrivatePath(privatepath);
864 r=privatepath.Compare(KExpectedPrivatePath());
866 r=fs1.SessionPath(sesspath);
868 r=privatepath.Compare(sesspath.Mid(KPathPosition));
870 r=fs1.CreatePrivatePath(gTheDriveNum);
876 r=fs2.SessionPath(sesspath);
878 test.Printf(_L("session2 Path=%S"),&sesspath);
883 test.Printf(_L("No of files open=%d"), TheFs.ResourceCount());