sl@0: // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "t_server.h" sl@0: sl@0: GLDEF_D RTest test(_L("t_dctcballfiles")); sl@0: GLDEF_D TTime gTimeNow; sl@0: LOCAL_D TInt gTheDriveNum; sl@0: sl@0: const TInt KPathPosition = 2; sl@0: _LIT(KExpectedPrivatePath, "\\Private\\00000001\\"); sl@0: sl@0: _LIT(KResourcePath, "?:\\Resource\\"); sl@0: _LIT(KSystemPath, "?:\\Sys\\"); sl@0: _LIT(KPrivatePath, "?:\\Private\\"); sl@0: _LIT(KPrivateFalseID, "?:\\Private\\FFFFFFFF\\"); sl@0: _LIT(KDriveName, "Billy"); sl@0: _LIT(KVolLable, "Benny"); sl@0: _LIT(KFileSys, "systemfile.txt"); sl@0: _LIT(KFileSys3, "sysfile.rna"); sl@0: _LIT(KFilePri, "privatefile.txt"); sl@0: _LIT(KFilePri2, "privatefile.tmp"); sl@0: _LIT(KFilePri3, "prifile.rna"); sl@0: _LIT(KFileRes, "resourcefile.txt"); sl@0: _LIT(KFileRes3, "resfile.rna"); sl@0: _LIT(KMkDirSub,"Subdir\\"); sl@0: _LIT(KOldFile,"?:\\Anyold.txt"); sl@0: _LIT(KWildPath, "Z:\\SYS\\"); sl@0: _LIT(KWildFile, "*"); sl@0: sl@0: TCapability TheCaps; sl@0: TBuf<4> driveBuf=_L("?:\\"); sl@0: RFormat format; sl@0: TInt count; sl@0: RRawDisk rawdisk; sl@0: RFile file1; sl@0: RFile file2; sl@0: RDir dir; sl@0: sl@0: TInt r; sl@0: TBuf<40> fsname; sl@0: TBuf<40> systestname; sl@0: TBuf<40> pritestname; sl@0: TBuf<40> restestname; sl@0: TBuf<40> theprivatepath; sl@0: TBuf<40> pritestfalseidname; sl@0: TBuf<40> mkdirname; sl@0: TFileName fromTemp; sl@0: sl@0: TBuf<25> sysfilename; sl@0: TBuf<30> realName; sl@0: TBuf<40> shortfilename; sl@0: TBuf<40> longfilename; sl@0: sl@0: TRequestStatus aStat1; sl@0: TRequestStatus aStat2; sl@0: TRequestStatus aStat3; sl@0: TRequestStatus aStat4; sl@0: sl@0: TVolumeInfo aVolInfo; sl@0: // TDriveInfo adriveInfo; sl@0: sl@0: TBuf<40> systestfile; sl@0: TBuf<40> pritestfile; sl@0: TBuf<40> restestfile; sl@0: TBuf<40> systestfile1; sl@0: TBuf<40> pritestfile1; sl@0: TBuf<40> restestfile1; sl@0: sl@0: TTime testtime; sl@0: TBuf<20> oldName; sl@0: sl@0: TBuf<25> temp; sl@0: sl@0: TEntry entry; sl@0: sl@0: sl@0: LOCAL_C void systemRFsTest() sl@0: // sl@0: // RFs test on system Directory sl@0: // sl@0: { sl@0: systestname=KSystemPath; sl@0: systestname[0]=(TText)('A' + gTheDriveNum); sl@0: sl@0: mkdirname.Zero(); sl@0: mkdirname.Append(systestname); sl@0: mkdirname.Append(KMkDirSub); sl@0: r=TheFs.MkDirAll(mkdirname); sl@0: test(r==KErrNone); sl@0: sl@0: TheFs.RmDir(mkdirname); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.SetSubst(systestname,EDriveO); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=TheFs.RealName(_L("O:\\File.XXX"),realName); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.SetSessionPath(systestname); sl@0: test(r==KErrNone); sl@0: sl@0: TheFs.NotifyChange(ENotifyAll,aStat1,systestname); sl@0: test(aStat1==KRequestPending); sl@0: sl@0: systestfile=KSystemPath; sl@0: systestfile[0]=(TText)('A' + gTheDriveNum); sl@0: systestfile1=systestfile; sl@0: systestfile.Append(KFileSys); sl@0: systestfile1.Append(KFileSys3); sl@0: sl@0: oldName=KOldFile; sl@0: oldName[0]=(TText)gDriveToTest; sl@0: sl@0: r=TheFs.GetShortName(systestfile, shortfilename); sl@0: test(r==KErrNotFound || r==KErrNotSupported); sl@0: sl@0: r=TheFs.GetLongName(systestfile1, longfilename); sl@0: test(r==KErrNotFound || r==KErrNotSupported); sl@0: sl@0: r=file1.Create(TheFs,oldName,EFileWrite); sl@0: test(r==KErrNone || r==KErrAlreadyExists); sl@0: file1.Close(); sl@0: sl@0: r=TheFs.Replace(oldName,systestfile); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.Rename(systestfile,systestfile1); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.Entry(systestfile1,entry); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.SetEntry(systestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.Delete(systestfile1); sl@0: test(r==KErrNone); sl@0: } sl@0: sl@0: LOCAL_C void ResourceRFsTest() sl@0: // sl@0: // sl@0: // sl@0: { sl@0: restestname=KResourcePath; sl@0: restestname[0]=(TText)('A' + gTheDriveNum); sl@0: sl@0: mkdirname.Zero(); sl@0: mkdirname.Append(restestname); sl@0: mkdirname.Append(KMkDirSub); sl@0: r=TheFs.MkDirAll(mkdirname); sl@0: test(r==KErrNone); sl@0: sl@0: TheFs.RmDir(mkdirname); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.SetSubst(restestname,EDriveO); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=TheFs.RealName(_L("O:\\File.XXX"),realName); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.SetSessionPath(restestname); sl@0: test(r==KErrNone); sl@0: sl@0: TheFs.NotifyChange(ENotifyAll,aStat4,restestname); sl@0: test(aStat4==KRequestPending); sl@0: sl@0: restestfile=KResourcePath; sl@0: restestfile[0]=(TText)('A' + gTheDriveNum); sl@0: restestfile1=restestfile; sl@0: restestfile.Append(KFileRes); sl@0: restestfile1.Append(KFileRes3); sl@0: sl@0: oldName=KOldFile; sl@0: oldName[0]=(TText)gDriveToTest; sl@0: sl@0: r=TheFs.GetShortName(restestfile, shortfilename); sl@0: test(r==KErrNone || KErrNotFound || r==KErrNotSupported); sl@0: sl@0: r=TheFs.GetLongName(restestfile1, longfilename); sl@0: test(r==KErrNone || KErrNotFound || r==KErrNotSupported); sl@0: sl@0: r=file1.Create(TheFs,oldName,EFileWrite); sl@0: test(r==KErrNone || r==KErrAlreadyExists); sl@0: file1.Close(); sl@0: sl@0: r=TheFs.Replace(oldName,restestfile); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.Rename(restestfile,restestfile1); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.Entry(restestfile1,entry); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.SetEntry(restestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.Delete(restestfile1); sl@0: test(r==KErrNone); sl@0: sl@0: } sl@0: sl@0: sl@0: LOCAL_C void privatefalseIDRFsTest() sl@0: // sl@0: // sl@0: // sl@0: { sl@0: pritestfalseidname=KPrivateFalseID; sl@0: pritestfalseidname[0]=(TText)('A' + gTheDriveNum); sl@0: sl@0: mkdirname.Zero(); sl@0: mkdirname.Append(pritestfalseidname); sl@0: mkdirname.Append(KMkDirSub); sl@0: sl@0: r=TheFs.MkDirAll(mkdirname); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.RmDir(mkdirname); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.SetSubst(pritestfalseidname,EDriveO); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=TheFs.RealName(_L("O:\\File.XXX"),realName); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.SetSessionPath(pritestfalseidname); sl@0: test(r==KErrNone); sl@0: sl@0: TheFs.NotifyChange(ENotifyAll,aStat2,pritestfalseidname); sl@0: test(aStat2==KRequestPending); sl@0: sl@0: sl@0: pritestfile=KPrivateFalseID; sl@0: pritestfile[0]=(TText)('A' + gTheDriveNum); sl@0: pritestfile1=pritestfile; sl@0: pritestfile.Append(KFilePri2); sl@0: pritestfile1.Append(KFilePri3); sl@0: sl@0: oldName=KOldFile; sl@0: oldName[0]=(TText)gDriveToTest; sl@0: sl@0: r=TheFs.GetShortName(pritestfile, shortfilename); sl@0: test(r==KErrNone || r==KErrNotFound || r==KErrNotSupported); sl@0: sl@0: r=TheFs.GetLongName(pritestfile1, longfilename); sl@0: test(r==KErrNone || r==KErrNotFound || r==KErrNotSupported); sl@0: sl@0: r=file1.Create(TheFs,oldName,EFileWrite); sl@0: test(r==KErrNone || r==KErrAlreadyExists); sl@0: file1.Close(); sl@0: sl@0: r=TheFs.Replace(oldName,pritestfile); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.Rename(pritestfile,pritestfile1); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.Entry(pritestfile1,entry); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.SetEntry(pritestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.Delete(pritestfile1); sl@0: test(r==KErrNone); sl@0: sl@0: } sl@0: sl@0: sl@0: LOCAL_C void privateRFsTest() sl@0: // sl@0: // sl@0: // sl@0: { sl@0: //private sl@0: pritestname=KPrivatePath; sl@0: pritestname[0]=(TText)('A' + gTheDriveNum); sl@0: sl@0: mkdirname.Zero(); sl@0: mkdirname.Append(pritestname); sl@0: mkdirname.Append(KMkDirSub); sl@0: sl@0: r=TheFs.MkDirAll(mkdirname); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.RmDir(mkdirname); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.SetSubst(pritestname,EDriveO); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=TheFs.RealName(_L("O:\\File.XXX"),realName); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.SetSessionPath(pritestname); sl@0: test(r==KErrNone); sl@0: sl@0: TheFs.NotifyChange(ENotifyAll,aStat2,pritestname); sl@0: test(aStat2==KRequestPending); sl@0: sl@0: sl@0: pritestfile=KPrivatePath; sl@0: pritestfile[0]=(TText)('A' + gTheDriveNum); sl@0: pritestfile1=pritestfile; sl@0: pritestfile.Append(KFilePri2); sl@0: pritestfile1.Append(KFilePri3); sl@0: sl@0: oldName=KOldFile; sl@0: oldName[0]=(TText)gDriveToTest; sl@0: sl@0: r=TheFs.GetShortName(pritestfile, shortfilename); sl@0: test(r==KErrNone || r==KErrNotFound || r==KErrNotSupported); sl@0: sl@0: r=TheFs.GetLongName(pritestfile1, longfilename); sl@0: test(r==KErrNone || r==KErrNotFound || r==KErrNotSupported); sl@0: sl@0: r=file1.Create(TheFs,oldName,EFileWrite); sl@0: test(r==KErrNone || r==KErrAlreadyExists); sl@0: file1.Close(); sl@0: sl@0: r=TheFs.Replace(oldName,pritestfile); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.Rename(pritestfile,pritestfile1); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.Entry(pritestfile1,entry); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.SetEntry(pritestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.Delete(pritestfile1); sl@0: test(r==KErrNone); sl@0: sl@0: } sl@0: sl@0: sl@0: LOCAL_C void privateSIDRFstest() sl@0: { sl@0: theprivatepath[0]=(TText)gDriveToTest; sl@0: test.Printf(_L("the Private Path = %S"),&theprivatepath); sl@0: sl@0: mkdirname.Zero(); sl@0: mkdirname.Append(theprivatepath); sl@0: mkdirname.Append(KMkDirSub); sl@0: r=TheFs.MkDirAll(mkdirname); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.RmDir(mkdirname); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.SetSubst(theprivatepath,EDriveO); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=TheFs.RealName(_L("O:\\File.XXX"),realName); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.SetSessionPath(theprivatepath); sl@0: test(r==KErrNone); sl@0: sl@0: TheFs.NotifyChange(ENotifyAll,aStat3,theprivatepath); sl@0: test(aStat3==KRequestPending); sl@0: sl@0: pritestfile=theprivatepath; sl@0: pritestfile[0]=(TText)('A' + gTheDriveNum); sl@0: pritestfile1=pritestfile; sl@0: pritestfile.Append(KFilePri2); sl@0: pritestfile1.Append(KFilePri3); sl@0: sl@0: oldName=KOldFile; sl@0: oldName[0]=(TText)gDriveToTest; sl@0: sl@0: r=TheFs.GetShortName(pritestfile, shortfilename); sl@0: test(r==KErrNone || r==KErrNotFound || r==KErrNotSupported); sl@0: sl@0: r=TheFs.GetLongName(pritestfile1, longfilename); sl@0: test(r==KErrNone || r==KErrNotFound || r==KErrNotSupported); sl@0: sl@0: r=file1.Create(TheFs,oldName,EFileWrite); sl@0: test(r==KErrNone || r==KErrAlreadyExists); sl@0: file1.Close(); sl@0: sl@0: r=TheFs.Replace(oldName,pritestfile); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.Rename(pritestfile,pritestfile1); sl@0: test(r==KErrNone || r==KErrAlreadyExists); sl@0: sl@0: r=TheFs.Entry(pritestfile1,entry); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.SetEntry(pritestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.Delete(pritestfile1); sl@0: test(r==KErrNone); sl@0: } sl@0: sl@0: sl@0: LOCAL_C void systemRFiletest() sl@0: // sl@0: //RFile testing with session path set to //system// sl@0: // sl@0: { sl@0: sl@0: r=TheFs.SetSessionPath(systestname); sl@0: test(r==KErrNone); sl@0: sl@0: r=file1.Temp(TheFs,systestname,fromTemp,EFileWrite); sl@0: test(r==KErrNone); sl@0: file1.Close(); sl@0: sl@0: r=file1.Create(TheFs,KFileSys,EFileWrite); sl@0: test(r==KErrNone); sl@0: file1.Close(); sl@0: sl@0: r=file1.Open(TheFs,KFileSys,EFileWrite); sl@0: test(r==KErrNone); sl@0: file1.Close(); sl@0: sl@0: r=file1.Open(TheFs,KFileSys,EFileRead); sl@0: test(r==KErrNone); sl@0: file1.Close(); sl@0: sl@0: r=file1.Replace(TheFs,KFileSys,EFileWrite); sl@0: test(r==KErrNone); sl@0: sl@0: r=file1.Rename(KFileSys3); sl@0: test(r==KErrNone); sl@0: file1.Close(); sl@0: sl@0: TFindFile finder(TheFs); sl@0: CDir* dir = NULL; sl@0: r=finder.FindWildByDir(KWildFile, KWildPath, dir); sl@0: if (!(r==KErrNone)) sl@0: test.Printf(_L("T_DCTCBALLFILES: test find wildcards r = %d (expected KErrNone)\n"), r); sl@0: test(r==KErrNone); sl@0: delete dir; sl@0: } sl@0: sl@0: LOCAL_C void resourceRFiletest() sl@0: // sl@0: //RFile testing with session path set to //resource// sl@0: // sl@0: { sl@0: r=TheFs.SetSessionPath(restestname); sl@0: test(r==KErrNone); sl@0: sl@0: r=file1.Temp(TheFs,restestname,fromTemp,EFileWrite); sl@0: test(r==KErrNone); sl@0: file1.Close(); sl@0: sl@0: r=file1.Create(TheFs,KFileRes,EFileWrite); sl@0: test(r==KErrNone); sl@0: file1.Close(); sl@0: sl@0: r=file1.Open(TheFs,KFileRes,EFileWrite|EFileShareExclusive ); sl@0: test(r==KErrNone); sl@0: sl@0: r=file1.Rename(KFileRes3); sl@0: test(r==KErrNone); sl@0: file1.Close(); sl@0: sl@0: r=file1.Open(TheFs,KFileRes3,EFileShareReadersOrWriters|EFileRead); sl@0: test(r==KErrNone); sl@0: file1.Close(); sl@0: sl@0: r=file1.Open(TheFs,KFileRes3,EFileShareReadersOrWriters|EFileWrite); sl@0: test(r==KErrNone); sl@0: file1.Close(); sl@0: sl@0: r=file1.Open(TheFs,KFileRes3,EFileShareReadersOnly); sl@0: test(r==KErrNone); sl@0: sl@0: r=file1.ChangeMode(EFileShareExclusive); sl@0: test(r==KErrNone); sl@0: file1.Close(); sl@0: sl@0: r=file1.Replace(TheFs,KFileRes,EFileWrite); sl@0: test(r==KErrNone); sl@0: file1.Close(); sl@0: } sl@0: sl@0: sl@0: LOCAL_C void privateRFiletest() sl@0: // sl@0: //RFile testing with session path set to //Private// sl@0: // sl@0: { sl@0: r=TheFs.SetSessionPath(pritestfalseidname); sl@0: test(r==KErrNone); sl@0: sl@0: r=file1.Temp(TheFs,pritestfalseidname,fromTemp,EFileWrite); sl@0: test(r==KErrNone); sl@0: file1.Close(); sl@0: sl@0: r=file1.Create(TheFs,KFilePri,EFileWrite); sl@0: test(r==KErrNone); sl@0: file1.Close(); sl@0: sl@0: r=file1.Open(TheFs,KFilePri,EFileWrite); sl@0: test(r==KErrNone); sl@0: file1.Close(); sl@0: sl@0: r=file1.Open(TheFs,KFilePri,EFileRead); sl@0: test(r==KErrNone); sl@0: file1.Close(); sl@0: sl@0: r=file1.Replace(TheFs,KFilePri,EFileWrite); sl@0: test(r==KErrNone); sl@0: sl@0: r=file1.Rename(KFilePri3); sl@0: test(r==KErrNone); sl@0: file1.Close(); sl@0: } sl@0: sl@0: sl@0: LOCAL_C void privatefalseIDRFiletest() sl@0: // sl@0: //RFile testing with session path set to //Private// sl@0: // sl@0: { sl@0: r=TheFs.SetSessionPath(pritestname); sl@0: test(r==KErrNone); sl@0: sl@0: r=file1.Temp(TheFs,pritestname,fromTemp,EFileWrite); sl@0: test(r==KErrNone); sl@0: file1.Close(); sl@0: sl@0: r=file1.Create(TheFs,KFilePri,EFileWrite); sl@0: test(r==KErrNone); sl@0: file1.Close(); sl@0: sl@0: r=file1.Open(TheFs,KFilePri,EFileWrite); sl@0: test(r==KErrNone); sl@0: file1.Close(); sl@0: sl@0: r=file1.Open(TheFs,KFilePri,EFileRead); sl@0: test(r==KErrNone); sl@0: file1.Close(); sl@0: sl@0: r=file1.Replace(TheFs,KFilePri,EFileWrite); sl@0: test(r==KErrNone); sl@0: sl@0: r=file1.Rename(KFilePri3); sl@0: test(r==KErrNone); sl@0: file1.Close(); sl@0: } sl@0: sl@0: sl@0: LOCAL_C void privateSIDRFiletest() sl@0: // sl@0: //Rfile Testing with session path set to //Private//UID// sl@0: // sl@0: { sl@0: r=TheFs.SetSessionToPrivate(gTheDriveNum); sl@0: test(r==KErrNone); sl@0: sl@0: r=file1.Temp(TheFs,theprivatepath,fromTemp,EFileWrite); sl@0: test(r==KErrNone); sl@0: file1.Close(); sl@0: sl@0: r=file1.Create(TheFs,KFilePri,EFileWrite); sl@0: test(r==KErrNone); sl@0: file1.Close(); sl@0: sl@0: r=file1.Open(TheFs,KFilePri,EFileWrite); sl@0: test(r==KErrNone); sl@0: file1.Close(); sl@0: sl@0: r=file1.Open(TheFs,KFilePri,EFileRead); sl@0: test(r==KErrNone); sl@0: file1.Close(); sl@0: sl@0: r=file1.Replace(TheFs,KFilePri,EFileWrite); sl@0: test(r==KErrNone); sl@0: sl@0: r=file1.Rename(KFilePri3); sl@0: test(r==KErrNone); sl@0: file1.Close(); sl@0: } sl@0: sl@0: LOCAL_C void RDirtest() sl@0: // sl@0: // sl@0: // sl@0: { sl@0: sl@0: //system sl@0: CDir* dirEntries; sl@0: TBuf<30> dirNameBuf(KSystemPath); sl@0: dirNameBuf[0]=(TText)gDriveToTest; sl@0: r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal); sl@0: test(r==KErrNone); sl@0: dir.Close(); sl@0: r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries); sl@0: test(r==KErrNone); sl@0: dirNameBuf.Zero(); sl@0: delete dirEntries; sl@0: sl@0: //Private sl@0: dirNameBuf=KPrivatePath; sl@0: dirNameBuf[0]=(TText)gDriveToTest; sl@0: r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal); sl@0: test(r==KErrNone); sl@0: dir.Close(); sl@0: r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries); sl@0: test(r==KErrNone); sl@0: dirNameBuf.Zero(); sl@0: delete dirEntries; sl@0: sl@0: //Private//false ID sl@0: dirNameBuf=KPrivateFalseID; sl@0: dirNameBuf[0]=(TText)gDriveToTest; sl@0: r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal); sl@0: test(r==KErrNone); sl@0: dir.Close(); sl@0: r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries); sl@0: test(r==KErrNone); sl@0: dirNameBuf.Zero(); sl@0: delete dirEntries; sl@0: sl@0: //Private/uid sl@0: TheFs.PrivatePath(dirNameBuf); sl@0: dirNameBuf.Insert(0,_L("?:")); sl@0: dirNameBuf[0]=(TText)gDriveToTest; sl@0: r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal); sl@0: test(r==KErrNone); sl@0: dir.Close(); sl@0: r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries); sl@0: test(r==KErrNone); sl@0: dirNameBuf.Zero(); sl@0: delete dirEntries; sl@0: //Resource sl@0: dirNameBuf=KResourcePath; sl@0: dirNameBuf[0]=(TText)gDriveToTest; sl@0: r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal); sl@0: test(r==KErrNone); sl@0: r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries); sl@0: test(r==KErrNone); sl@0: dir.Close(); sl@0: delete dirEntries; sl@0: } sl@0: sl@0: sl@0: LOCAL_C void TestTcbAllfiles() sl@0: // sl@0: // Test with tcb capabilities sl@0: // sl@0: { sl@0: r=TheFs.FileSystemName(fsname,gTheDriveNum); sl@0: test(r==KErrNone); sl@0: r = DismountFileSystem(TheFs, fsname, gTheDriveNum); sl@0: test(r==KErrPermissionDenied); sl@0: // r=TheFs.RemoveFileSystem(fsname); //can not test due to bug else where fix exists sl@0: // test(r==KErrNone); sl@0: // r=TheFs.AddFileSystem(fsname); sl@0: // test(r==KErrNone); sl@0: r = MountFileSystem(TheFs, fsname, gTheDriveNum); sl@0: test(r==KErrPermissionDenied); sl@0: test.Printf(_L("r=%d"),r); sl@0: r=TheFs.SetDriveName(gTheDriveNum,KDriveName); sl@0: test(r==KErrPermissionDenied); sl@0: #ifndef __WINS__ sl@0: r=TheFs.SetVolumeLabel(KVolLable, gTheDriveNum); sl@0: test(r==KErrPermissionDenied); sl@0: #endif sl@0: sl@0: systemRFsTest(); sl@0: ResourceRFsTest(); sl@0: privateRFsTest(); sl@0: privateSIDRFstest(); sl@0: privatefalseIDRFsTest(); sl@0: sl@0: systemRFiletest(); sl@0: resourceRFiletest(); sl@0: privateRFiletest(); sl@0: privateSIDRFiletest(); sl@0: privatefalseIDRFiletest(); sl@0: sl@0: //check notifier return values set in rfs testing sl@0: User::WaitForRequest(aStat1); sl@0: User::WaitForRequest(aStat2); sl@0: User::WaitForRequest(aStat3); sl@0: User::WaitForRequest(aStat4); sl@0: test(aStat1==KErrNone); sl@0: test(aStat2==KErrNone); sl@0: test(aStat3==KErrNone); sl@0: test(aStat4==KErrNone); sl@0: sl@0: r=TheFs.SetSessionPath(systestname); sl@0: test(r==KErrNone); sl@0: sl@0: //Test RRawDisk class sl@0: r=rawdisk.Open(TheFs,gTheDriveNum); sl@0: test(r==KErrNone); sl@0: rawdisk.Close(); sl@0: sl@0: RDirtest(); sl@0: sl@0: #ifdef __WINS__ sl@0: if (User::UpperCase(driveBuf[0]) != 'C') sl@0: #endif sl@0: { sl@0: //Test RFormat class sl@0: r=format.Open(TheFs,driveBuf,EHighDensity,count); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: while(count) sl@0: { sl@0: TInt r=format.Next(count); sl@0: test(r==KErrNone); sl@0: } sl@0: format.Close(); sl@0: } sl@0: sl@0: driveBuf[0]=(TText)gDriveToTest; sl@0: r=TheFs.ScanDrive(driveBuf); sl@0: RDebug::Print(_L("r=%d"),r); sl@0: test(r==KErrPermissionDenied); sl@0: r=TheFs.CheckDisk(driveBuf); sl@0: test(r==KErrPermissionDenied); sl@0: } sl@0: sl@0: LOCAL_C void TestCaps() sl@0: // sl@0: // test format etc that require certain capabilities sl@0: // sl@0: { sl@0: #ifndef __REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__ sl@0: const char myDiagMsg[] = "Capability Check Failure"; sl@0: #endif //!__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__ sl@0: r=RProcess().HasCapability(ECapabilityTCB, __PLATSEC_DIAGNOSTIC_STRING(myDiagMsg)); sl@0: test(r); sl@0: r=RProcess().HasCapability(ECapabilityAllFiles, __PLATSEC_DIAGNOSTIC_STRING(myDiagMsg)); sl@0: test(r); sl@0: sl@0: driveBuf[0]=(TText)gDriveToTest; sl@0: r=TheFs.SessionPath(temp); sl@0: test(r==KErrNone); sl@0: sl@0: test.Printf(_L("Session path: %S"),&temp); sl@0: sl@0: r=TheFs.CreatePrivatePath(gTheDriveNum); sl@0: test(r==KErrNone || r== KErrAlreadyExists); sl@0: sl@0: TBuf<18> tempPri; sl@0: r=TheFs.PrivatePath(tempPri); sl@0: test(r==KErrNone); sl@0: theprivatepath = _L("?:"); sl@0: theprivatepath.Append(tempPri); sl@0: sl@0: TestTcbAllfiles(); sl@0: sl@0: TFileName thesessionpath; sl@0: r=TheFs.SetSessionToPrivate(gTheDriveNum); sl@0: test(r==KErrNone); sl@0: r=TheFs.SessionPath(thesessionpath); sl@0: test(r==KErrNone); sl@0: sl@0: test(thesessionpath == theprivatepath); sl@0: } sl@0: sl@0: sl@0: TFileName dirName; sl@0: sl@0: LOCAL_C void ScanDir(const TDesC& aName, CDirScan::TScanDirection aDirection, TInt aError) sl@0: { sl@0: CDirScan* scanner = NULL; sl@0: TRAP(r, scanner = CDirScan::NewL(TheFs)); sl@0: test(r == KErrNone && scanner); sl@0: sl@0: TRAP(r, scanner->SetScanDataL(aName,KEntryAttDir,ESortByName|EAscending,aDirection)); sl@0: test(r == KErrNone); sl@0: sl@0: CDir *entryList=NULL; sl@0: for (;;) sl@0: { sl@0: TRAP(r, scanner->NextL(entryList)); sl@0: test(r == aError); sl@0: if (entryList==NULL) sl@0: break; sl@0: sl@0: TInt count=entryList->Count(); sl@0: sl@0: while (count--) sl@0: { sl@0: TEntry data=(*entryList)[count]; sl@0: TBuf path=scanner->AbbreviatedPath(); sl@0: sl@0: dirName = path; sl@0: dirName.Append(data.iName); sl@0: test.Printf(_L(" %S\n"),&dirName); sl@0: sl@0: } sl@0: delete entryList; sl@0: entryList=NULL; sl@0: } sl@0: delete scanner; sl@0: sl@0: } sl@0: sl@0: /** sl@0: The following test, tests CFileMan and CDirScan API on folders private and sys sl@0: to confirm that any operation on these folders for any app with incorrect capability sl@0: returns KErrPermissionDenied. This test step was added as a result of DEF051428 sl@0: ("PlatSec: Incorrect errors returned by f32") sl@0: */ sl@0: LOCAL_C void TestCaging() sl@0: { sl@0: CFileMan* fMan=CFileMan::NewL(TheFs); sl@0: TInt r; sl@0: if(fMan!=NULL) sl@0: { sl@0: sl@0: // Checking the private path sl@0: TBuf<30> privatepath; sl@0: r=TheFs.PrivatePath(privatepath); sl@0: test.Printf(_L("Private Path is=%S"),&privatepath); sl@0: sl@0: r = TheFs.MkDir(_L("\\Caged\\")); sl@0: test(r==KErrNone || r==KErrAlreadyExists); sl@0: sl@0: CDir* entryCount=NULL; sl@0: r=TheFs.GetDir(_L("\\*.*"),KEntryAttNormal|KEntryAttDir,ESortNone,entryCount); sl@0: test(r==KErrNone); sl@0: sl@0: delete entryCount; sl@0: entryCount=NULL; sl@0: sl@0: sl@0: //Testing Copy sl@0: CDir* entryCount2=NULL; sl@0: r=fMan->Copy(_L("\\sys\\"),_L("\\Caged\\")); sl@0: test(r == KErrNone); sl@0: r=fMan->Copy(_L("\\*"),_L("\\Caged\\")); sl@0: test(r == KErrNone); sl@0: sl@0: r=TheFs.GetDir(_L("\\Caged\\*.*"),KEntryAttNormal|KEntryAttDir,ESortNone,entryCount2); sl@0: test(r==KErrNone); sl@0: sl@0: delete entryCount2; sl@0: entryCount2=NULL; sl@0: sl@0: r=fMan->Copy(_L("\\private\\two\\moo"),_L("\\private\\two\\mew")); sl@0: test(r == KErrPathNotFound); sl@0: sl@0: // Create a test file sl@0: RFile testFile; sl@0: r = testFile.Replace(TheFs, _L("\\capTest"),EFileWrite); sl@0: test(r==KErrNone || r==KErrAlreadyExists); sl@0: testFile.Close(); sl@0: sl@0: TFileName name; sl@0: name = privatepath; sl@0: name.Append(_L("privateFile.tst")); sl@0: RFile privateFile; sl@0: r = privateFile.Replace(TheFs, name,EFileWrite); sl@0: test(r==KErrNone || r==KErrAlreadyExists); sl@0: privateFile.Close(); sl@0: sl@0: sl@0: r=fMan->Copy(_L("\\capTest"),_L("\\private\\two\\moo")); sl@0: test(r == KErrPathNotFound); sl@0: r=fMan->Copy(_L("\\capTest"),_L("\\sys\\bin\\moo")); sl@0: test(r == KErrPathNotFound); sl@0: r=fMan->Copy(_L("\\sys\\bin\\capTest"),_L("\\sys\\bin\\moo")); sl@0: test(r == KErrPathNotFound); sl@0: r=fMan->Copy(_L("\\capTest"),_L("\\sys\\capTest")); sl@0: test(r == KErrNone || r==KErrAlreadyExists); sl@0: r=fMan->Copy(_L("\\sys\\*"),_L("\\")); sl@0: test (r==KErrNone); sl@0: r=fMan->Copy(name,_L("\\sys\\")); sl@0: test(r==KErrNone); sl@0: sl@0: // Testing Attribs sl@0: r=fMan->Attribs(_L("\\private\\two\\moo"),KEntryAttReadOnly,0,TTime(0)); sl@0: test(r == KErrPathNotFound); sl@0: r=fMan->Attribs(_L("\\private\\moo"),KEntryAttReadOnly,0,TTime(0)); sl@0: test(r == KErrNotFound); sl@0: r=fMan->Attribs(name,KEntryAttReadOnly,0,TTime(0)); sl@0: test(r == KErrNone); sl@0: r=fMan->Attribs(name,0,KEntryAttReadOnly,TTime(0)); sl@0: test(r == KErrNone); sl@0: sl@0: // Testing Move sl@0: r=fMan->Move(_L("\\private\\two\\moo"),_L("\\private\\one\\moo")); sl@0: test(r == KErrPathNotFound); sl@0: r=fMan->Move(_L("\\private\\two\\moo.."),_L("\\private\\one\\moo")); sl@0: test(r == KErrPathNotFound); sl@0: r=fMan->Move(_L("\\private\\two\\moo"),_L("\\private\\one\\moo..")); sl@0: test(r == KErrPathNotFound); sl@0: r=fMan->Move(name,_L("\\privateFile.tst")); sl@0: test(r == KErrNone); sl@0: r=fMan->Move(_L("\\privateFile.tst"),name); sl@0: test(r == KErrNone); sl@0: sl@0: sl@0: // Testing RmDir sl@0: r=fMan->RmDir(_L("\\private\\")); sl@0: test(r == KErrNone); sl@0: // put it back where it was sl@0: r = TheFs.MkDirAll(_L("\\private\\00000001\\")); sl@0: test(r == KErrNone); sl@0: r=fMan->RmDir(_L("\\private\\two\\")); sl@0: test(r == KErrPathNotFound); sl@0: r=fMan->RmDir(_L("\\private\\tw?\\")); sl@0: test(r == KErrBadName); sl@0: sl@0: r=fMan->RmDir(_L("\\private\\two\\")); sl@0: test(r == KErrPathNotFound); sl@0: r=fMan->RmDir(_L("\\private\\tw?\\")); sl@0: test(r == KErrBadName); sl@0: sl@0: sl@0: // Testing Rename sl@0: r=fMan->Rename(_L("\\private\\two\\moo"),_L("\\private\\two\\mew")); sl@0: test(r == KErrPathNotFound); sl@0: sl@0: // Testing Delete sl@0: r=fMan->Delete(_L("\\private\\two\\test")); sl@0: test(r == KErrPathNotFound); sl@0: r=fMan->Delete(_L("\\private\\moo")); sl@0: test(r == KErrNotFound); sl@0: sl@0: //Something that actually exists in Private sl@0: r=fMan->Rename(name,_L("\\private\\00000001\\moo")); sl@0: test(r == KErrNotFound); sl@0: r=fMan->Rename(_L("\\private\\00000001\\moo"),name); sl@0: test(r == KErrNotFound); sl@0: r=fMan->Copy(name,_L("\\private\\00000001\\moo")); sl@0: test(r == KErrNotFound); sl@0: r=fMan->Delete(_L("\\private\\00000001\\moo")); sl@0: test(r == KErrNotFound); sl@0: sl@0: // Clean up the test data sl@0: r=fMan->RmDir(_L("\\Caged\\")); sl@0: test(r == KErrNone); sl@0: r=fMan->Delete(_L("\\capTest")); sl@0: test(r == KErrNone); sl@0: delete(fMan); sl@0: } sl@0: sl@0: // CDirScan tests sl@0: ScanDir(_L("\\"), CDirScan::EScanUpTree, KErrNone); sl@0: ScanDir(_L("\\"), CDirScan::EScanDownTree, KErrNone); sl@0: ScanDir(_L("\\private\\"), CDirScan::EScanDownTree, KErrNone); sl@0: ScanDir(_L("\\private\\"), CDirScan::EScanUpTree, KErrNone); sl@0: ScanDir(_L("\\sys\\"), CDirScan::EScanDownTree, KErrNone); sl@0: ScanDir(_L("\\sys\\"), CDirScan::EScanUpTree, KErrNone); sl@0: } sl@0: sl@0: LOCAL_C void CleanupL() sl@0: // sl@0: // Clean up tests sl@0: // sl@0: { sl@0: test.Next(_L("Delete test directory")); sl@0: CFileMan* fMan=CFileMan::NewL(TheFs); sl@0: TInt r=fMan->RmDir(gSessionPath); sl@0: test(r==KErrNone || KErrPathNotFound); sl@0: delete fMan; sl@0: } sl@0: sl@0: GLDEF_C void CallTestsL(/*TChar aDriveLetter*/) sl@0: // sl@0: // Do all tests sl@0: // sl@0: { sl@0: if( !PlatSec::IsCapabilityEnforced(ECapabilityTCB) || sl@0: !PlatSec::IsCapabilityEnforced(ECapabilityAllFiles)) sl@0: { sl@0: test.Printf(_L("Insufficient capabilities enabled - leaving t_dctcballfiles")); sl@0: test.Printf(_L("\n")); // Prevent overwrite by next print sl@0: return; sl@0: } sl@0: TurnAllocFailureOff(); sl@0: TheFs.CharToDrive(gDriveToTest,gTheDriveNum); sl@0: sl@0: TBuf<30> sesspath; sl@0: sesspath=_L("?:\\"); sl@0: sesspath[0] = (TText)gDriveToTest; sl@0: sl@0: TInt r= TheFs.SetSessionPath(sesspath); sl@0: test(r==KErrNone); sl@0: sl@0: //cleanup from previous run of this test sl@0: TBuf<20> delDir; sl@0: CFileMan* fMan=CFileMan::NewL(TheFs); sl@0: delDir=KResourcePath; sl@0: delDir[0]=(TText)gDriveToTest; sl@0: r=fMan->RmDir(delDir); sl@0: test(r==KErrNone || KErrNotFound); sl@0: delDir=KSystemPath; sl@0: delDir[0]=(TText)gDriveToTest; sl@0: r=fMan->RmDir(delDir); sl@0: test(r==KErrNone || KErrNotFound); sl@0: delDir=KPrivatePath; sl@0: delDir[0]=(TText)gDriveToTest; sl@0: r=fMan->RmDir(delDir); sl@0: test(r==KErrNone || KErrNotFound); sl@0: delete fMan; sl@0: sl@0: //check double mode ie that Defpath still works sl@0: RFs fs1; sl@0: RFs fs2; sl@0: sl@0: r=fs1.Connect(); sl@0: test(r==KErrNone); sl@0: r=fs1.SessionPath(sesspath); sl@0: test(r==KErrNone); sl@0: test.Printf(_L("session1 Path=%S"),&sesspath); sl@0: sl@0: TBuf<30> privatepath; sl@0: r=fs1.SetSessionToPrivate(gTheDriveNum); sl@0: test(r==KErrNone); sl@0: r=fs1.PrivatePath(privatepath); sl@0: test(r==KErrNone); sl@0: r=privatepath.Compare(KExpectedPrivatePath()); sl@0: test(r==0); sl@0: r=fs1.SessionPath(sesspath); sl@0: test(r==KErrNone); sl@0: r=privatepath.Compare(sesspath.Mid(KPathPosition)); sl@0: test(r==0); sl@0: r=fs1.CreatePrivatePath(gTheDriveNum); sl@0: test(r==KErrNone); sl@0: fs1.Close(); sl@0: sl@0: r=fs2.Connect(); sl@0: test(r==KErrNone); sl@0: r=fs2.SessionPath(sesspath); sl@0: test(r==KErrNone); sl@0: test.Printf(_L("session2 Path=%S"),&sesspath); sl@0: fs2.Close(); sl@0: sl@0: TestCaps(); sl@0: TestCaging(); sl@0: sl@0: test.Printf(_L("No of files open=%d"), TheFs.ResourceCount()); sl@0: sl@0: CleanupL(); sl@0: }