diff -r 000000000000 -r bde4ae8d615e os/kernelhwsrv/kerneltest/f32test/server/t_misc.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/os/kernelhwsrv/kerneltest/f32test/server/t_misc.cpp Fri Jun 15 03:10:57 2012 +0200 @@ -0,0 +1,1398 @@ +// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of the License "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// f32test\server\t_misc.cpp +// +// + +#include +#include +#include "t_server.h" + +#ifdef __VC32__ + // Solve compilation problem caused by non-English locale + #pragma setlocale("english") +#endif + +GLDEF_D RTest test(_L("T_MISC")); + +LOCAL_C void Test1() +// +// Open, write to and read from a file +// + { + + test.Next(_L("Open, write to and read from a file")); + TInt r=TheFs.SetSessionPath(gSessionPath); + test(r==KErrNone); + RFile file; + r=file.Create(TheFs,_L("Hello.Wld"),EFileWrite); + test(r==KErrNone); + r=file.Write(_L8("Hello World"),11); + test(r==KErrNone); + file.Close(); + + r=file.Open(TheFs,_L("Hello.Wld"),EFileRead); + test(r==KErrNone); + TBuf8<256> buf; + r=file.Read(buf); + test(r==KErrNone); + test(buf==_L8("Hello World")); + file.Close(); + } + +LOCAL_C void Test2() +// +// Open and read from a file +// + { + + test.Next(_L("Open and read from a file")); + TInt r=TheFs.SetSessionPath(gSessionPath); + test(r==KErrNone); + RFile file; + r=file.Open(TheFs,_L("Hello.Wld"),EFileRead); + test(r==KErrNone); + TBuf8<256> buf; + r=file.Read(buf); + test(r==KErrNone); + test(buf==_L8("Hello World")); + file.Close(); + r=TheFs.Delete(_L("HELLO.WLD")); + test(r==KErrNone); + } + +LOCAL_C void Test3() +// +// Create nested directories +// + { + + test.Next(_L("Create nested directories")); + TInt r=TheFs.SetSessionPath(gSessionPath); + test(r==KErrNone); + TheFs.ResourceCountMarkStart(); +// + r=TheFs.MkDir(_L("\\F32-TST\\LEFT\\A.B")); + test(r==KErrNone || r==KErrAlreadyExists); + r=TheFs.MkDir(_L("\\F32-TST\\RIGHT\\")); + test(r==KErrNone || r==KErrAlreadyExists); +// + r=TheFs.MkDir(_L("\\F32-TST\\LEFT\\ONE\\")); + test(r==KErrNone || r==KErrAlreadyExists); + r=TheFs.MkDir(_L("\\F32-TST\\LEFT\\TWO\\")); + test(r==KErrNone || r==KErrAlreadyExists); + r=TheFs.MkDir(_L("\\F32-TST\\LEFT\\THREE\\")); + test(r==KErrNone || r==KErrAlreadyExists); + r=TheFs.MkDir(_L("\\F32-TST\\LEFT\\TWO\\BOTTOM\\")); + test(r==KErrNone || r==KErrAlreadyExists); +// + r=TheFs.MkDirAll(_L("\\F32-TST\\RIGHT\\TOP\\MID\\BOT\\")); + test(r==KErrNone || r==KErrAlreadyExists); + } + +LOCAL_C void Test4() +// +// Test returned error values +// + { + + test.Next(_L("Test returned error values")); + TInt r=TheFs.SetSessionPath(gSessionPath); + test(r==KErrNone); + TheFs.ResourceCountMarkStart(); +// + r=TheFs.MkDir(_L("\\")); + test(r==KErrAlreadyExists); + r=TheFs.MkDir(_L("\\LEFT")); + test(r==KErrAlreadyExists); + r=TheFs.MkDir(_L("\\F32-TST\\LEFT\\")); + test(r==KErrAlreadyExists); + r=TheFs.MkDir(_L("\\F32-TST\\LEFT\\..\\NEWDIR\\")); + test(r==KErrBadName); + r=TheFs.MkDir(_L("\\F32-TST\\NEWDIR\\SUBDIR\\")); + test(r==KErrPathNotFound); +// + r=TheFs.RmDir(_L("\\")); + test(r==KErrInUse); + r=TheFs.RmDir(_L("\\PROG")); + test(r==KErrInUse); + r=TheFs.RmDir(_L("\\F32-TST\\")); + test(r==KErrInUse); + + + RDir dir; + r=dir.Open(TheFs,_L("V:\\asdf"),KEntryAttNormal); + test(r==KErrNone || r==KErrNotReady || r==KErrNotFound); + if (r==KErrNone) + dir.Close(); + r=dir.Open(TheFs,_L("L:\\asdf"),KEntryAttNormal); + test(r==KErrNone || r==KErrNotReady || r==KErrNotFound); + dir.Close(); +// + TEntry entry; + r=TheFs.Entry(_L("z:\\NOTEXiSTS\\file.txt"),entry); + test(r==KErrPathNotFound); + r=TheFs.Entry(_L("z:\\NOTEXiSTS\\"),entry); + test(r==KErrNotFound); + r=TheFs.Entry(_L("z:\\SYSTEM\\"),entry); + test(r==KErrNone); + r=TheFs.Entry(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin)?_L("z:\\SYS\\BIN\\ESHELL.EXE"):_L("z:\\SYSTEM\\BIN\\ESHELL.EXE"),entry); + test(r==KErrNone); + + r=dir.Open(TheFs,_L("\\*"),NULL); + test(r==KErrNone); + TEntry dirEntry; + r=dir.Read(dirEntry); + test(r==KErrNone || r==KErrEof); + if (r==KErrNone) + test.Printf(_L("%S\n"),&dirEntry.iName); + dir.Close(); + + r=dir.Open(TheFs,_L("A:\\*"),NULL); + test(r==KErrNotReady || r==KErrNone); + dir.Close(); + } + +LOCAL_C void Test5() +// +// Read files directly from the rom +// + + { + test.Next(_L("Read Files directly from the rom")); + + TInt pos=0; + TInt r; + _LIT(KTFileCpp, "Z:\\test\\T_FILE.CPP"); + _LIT(KTFsrvCpp, "Z:\\test\\T_FSRV.CPP"); + + if ( TheFs.IsFileInRom(KTFileCpp) != NULL && TheFs.IsFileInRom(KTFsrvCpp) != NULL ) + { + RFile f; + r=f.Open(TheFs,KTFileCpp,EFileRead); + test(r==KErrNone); + r=f.Seek(ESeekAddress,pos); + TText8* ptrPos=*(TText8**)&pos; + test(r==KErrNone); + TBuf8<1024> readBuf; + r=f.Read(readBuf); + test(r==KErrNone); + test(readBuf.Length()==readBuf.MaxLength()); + TPtrC8 memBuf(ptrPos,readBuf.Length()); + test(memBuf==readBuf); + + ptrPos+=9913; + pos=9913; + r=f.Seek(ESeekStart,pos); + test(r==KErrNone); + readBuf.SetLength(0); + r=f.Read(readBuf); + test(r==KErrNone); + test(readBuf.Length()==readBuf.MaxLength()); + memBuf.Set(ptrPos,readBuf.Length()); + test(memBuf==readBuf); + + RFile f2; + pos=10; + r=f2.Open(TheFs,KTFsrvCpp,EFileRead); + + test(r==KErrNone); + r=f2.Seek(ESeekAddress,pos); + ptrPos=*(TText8**)&pos; + test(r==KErrNone); + readBuf.SetLength(0); + pos=10; + r=f2.Seek(ESeekStart,pos); + test(r==KErrNone); + r=f2.Read(readBuf); + test(r==KErrNone); + test(readBuf.Length()==readBuf.MaxLength()); + memBuf.Set(ptrPos,readBuf.Length()); + test(memBuf==readBuf); + + ptrPos+=2445; + pos=10+2445; + r=f2.Seek(ESeekStart,pos); + test(r==KErrNone); + readBuf.SetLength(0); + r=f2.Read(readBuf); + test(r==KErrNone); + test(readBuf.Length()==readBuf.MaxLength()); + memBuf.Set(ptrPos,readBuf.Length()); + test(memBuf==readBuf); + + pos=0; + r=f.Seek(ESeekAddress,pos); + ptrPos=*(TText8**)&pos; + test(r==KErrNone); + readBuf.SetLength(0); + pos=0; + r=f.Seek(ESeekStart,pos); + test(r==KErrNone); + r=f.Read(readBuf); + test(r==KErrNone); + test(readBuf.Length()==readBuf.MaxLength()); + memBuf.Set(ptrPos,readBuf.Length()); + test(memBuf==readBuf); + + ptrPos+=5245; + pos=5245; + r=f.Seek(ESeekStart,pos); + test(r==KErrNone); + readBuf.SetLength(0); + r=f.Read(readBuf); + test(r==KErrNone); + test(readBuf.Length()==readBuf.MaxLength()); + memBuf.Set(ptrPos,readBuf.Length()); + test(memBuf==readBuf); + + f.Close(); + f2.Close(); + } + } + +LOCAL_C void Test6() +// +// Test rom return values +// + { + test.Next(_L("Test rom return values")); + + RFile f; + TInt r=f.Replace(TheFs,_L("Z:\\Test\\T_Fsrv.Cpp"),EFileRead); + test(r==KErrAccessDenied); + r=f.Create(TheFs,_L("Z:\\Test\\newT_Fsrv.Cpp"),EFileRead); + test(r==KErrAccessDenied); + r=f.Open(TheFs,_L("Z:\\Test\\T_Fsrv.Cpp"),EFileRead); + test(r==KErrNone); + f.Close(); + r=f.Open(TheFs,_L("Z:\\Test\\T_Fsrv.Cpp"),EFileRead|EFileWrite); + test(r==KErrAccessDenied); + } + +LOCAL_C void Test7() +// +// Test cache +// + { + + test.Next(_L("Test cache updated when writing to a file")); + TUidType uid1(TUid::Uid(1),TUid::Uid(2),TUid::Uid(3)); + TBuf8<32> contents1=_L8("asdf asdf asdf"); + TBuf<32> file1=_L("\\TMISC\\CACHE.FILE"); + MakeFile(file1,uid1,contents1); + + TEntry entry; + TInt r=TheFs.Entry(file1,entry); + test(r==KErrNone); + test(entry.iType==uid1); + + TUidType uid2(TUid::Uid(4),TUid::Uid(5),TUid::Uid(6)); + TCheckedUid checkedUid(uid2); + TPtrC8 uidData((TUint8*)&checkedUid,sizeof(TCheckedUid)); + RFile f; + r=f.Open(TheFs,file1,EFileRead|EFileWrite); + test(r==KErrNone); + r=f.Write(uidData); + test(r==KErrNone); + r = f.Flush(); + test(r==KErrNone); + + r=TheFs.Entry(file1,entry); + test(r==KErrNone); + test(entry.iType==uid2); + + f.Close(); + r=TheFs.Entry(file1,entry); + test(r==KErrNone); + test(entry.iType==uid2); + } + +LOCAL_C void Test8() +// +// Test IsValidName +// + { + test.Next(_L("Test RFs::IsValidName(TDesC)")); + + // tests calling IsValidName() with invalid name as first call to session + // see defect EXT-57KH9K + _LIT(KInvalidName, "test\\i1.jpg"); + RFs fs; + test(KErrNone==fs.Connect()); + test(fs.IsValidName(KInvalidName)==EFalse); + fs.Close(); + + test(TheFs.IsValidName(_L("*"))==EFalse); + test(TheFs.IsValidName(_L("?"))==EFalse); + test(TheFs.IsValidName(_L(">"))==EFalse); + test(TheFs.IsValidName(_L("<"))==EFalse); + test(TheFs.IsValidName(_L(":"))==EFalse); + test(TheFs.IsValidName(_L("\""))==EFalse); + test(TheFs.IsValidName(_L("/"))==EFalse); + test(TheFs.IsValidName(_L("|"))==EFalse); + test(TheFs.IsValidName(_L("\\"))==EFalse); + + test(TheFs.IsValidName(_L("xx*yy"))==EFalse); + test(TheFs.IsValidName(_L("xx?yy"))==EFalse); + test(TheFs.IsValidName(_L("xx>yy"))==EFalse); + test(TheFs.IsValidName(_L("xx\\group\\release.txt"))==EFalse); + test(TheFs.IsValidName(_L("C:\\<\\group\\release.txt"))==EFalse); + test(TheFs.IsValidName(_L("C:\\:\\group\\release.txt"))==EFalse); + test(TheFs.IsValidName(_L("C:\\\"\\group\\release.txt"))==EFalse); + test(TheFs.IsValidName(_L("C:\\/\\group\\release.txt"))==EFalse); + test(TheFs.IsValidName(_L("C:\\|\\group\\release.txt"))==EFalse); + + test(TheFs.IsValidName(_L(""))==EFalse); // must be a name or extension present + test(TheFs.IsValidName(_L(".ext"))); + test(TheFs.IsValidName(_L("C:\\asdf.blarg\\"))==EFalse); + test(TheFs.IsValidName(_L("\\"))==EFalse); + + test(TheFs.IsValidName(_L("as(){}@~#;!\xA3$%^&()df.blarg"))); // Valid names + test(TheFs.IsValidName(_L("C:\\asdf.blarg\\asdf.blarg"))); // Valid names + test(TheFs.IsValidName(_L("\'"))); // Valid names + + test.Next(_L("Test RFs::IsValidName(TDesC, TDes) overload")); + + TText testChar; + test(TheFs.IsValidName(_L("*"),testChar)==EFalse); + test(testChar=='*'); + test(TheFs.IsValidName(_L("?"),testChar)==EFalse); + test(testChar=='?'); + test(TheFs.IsValidName(_L(">"),testChar)==EFalse); + test(testChar=='>'); + test(TheFs.IsValidName(_L("<"),testChar)==EFalse); + test(testChar=='<'); + test(TheFs.IsValidName(_L(":"),testChar)==EFalse); + test(testChar==':'); + test(TheFs.IsValidName(_L("\""),testChar)==EFalse); + test(testChar=='\"'); // Tests that " is illegal + test(TheFs.IsValidName(_L("/"),testChar)==EFalse); + test(testChar=='/'); + test(TheFs.IsValidName(_L("|"),testChar)==EFalse); + test(testChar=='|'); + test(TheFs.IsValidName(_L("\\"),testChar)==EFalse); + test(testChar==' '); + + test(TheFs.IsValidName(_L("xx*yy"),testChar)==EFalse); + test(testChar=='*'); + test(TheFs.IsValidName(_L("xx?yy"),testChar)==EFalse); + test(testChar=='?'); + test(TheFs.IsValidName(_L("xx>yy"),testChar)==EFalse); + test(testChar=='>'); + test(TheFs.IsValidName(_L("xx\\group\\release.txt"),testChar)==EFalse); + test(testChar=='>'); + test(TheFs.IsValidName(_L("C:\\<\\group\\release.txt"),testChar)==EFalse); + test(testChar=='<'); + test(TheFs.IsValidName(_L("C:\\HelloWorld\\:\\group\\release.txt"),testChar)==EFalse); + test(testChar==':'); + + + test(TheFs.IsValidName(_L("C::\\group\\release.txt"),testChar)==EFalse); + test(testChar==':'); + test(TheFs.IsValidName(_L(">\\group\\release.txt"),testChar)==EFalse); + test(testChar=='>'); + test(TheFs.IsValidName(_L("C|group\\release.txt"),testChar)==EFalse); + test(testChar=='|'); + test(TheFs.IsValidName(_L("C\\|\\group\\release.txt"),testChar)==EFalse); + test(testChar=='|'); + + test(TheFs.IsValidName(_L("\\>"),testChar)==EFalse); + test(testChar=='>'); + test(TheFs.IsValidName(_L("C:\\|group\\release.txt"),testChar)==EFalse); + test(testChar=='|'); + + test(TheFs.IsValidName(_L("C:\\\"\\group\\release.txt"),testChar)==EFalse); + test(testChar=='\"'); + test(TheFs.IsValidName(_L("C:\\/\\group\\release.txt"),testChar)==EFalse); + test(testChar=='/'); + test(TheFs.IsValidName(_L("C:\\|\\group\\release.txt"),testChar)==EFalse); + test(testChar=='|'); + test(TheFs.IsValidName(_L("C:\\ \\group\\release.txt"),testChar)==EFalse); // must be a name or extension present + test(testChar==' '); + +// Test that \ is not allowed in filenames + TFileName filename; + filename=_L("C:\\HelloWorld\\\\\\group\\release.txt"); + TPtr pChar(&testChar,sizeof(TText),sizeof(TText)); + test(TheFs.IsValidName(filename,testChar)==EFalse); + test(pChar.Find(_L("\\"))!=KErrNotFound); + filename=_L("C:\\\\\\group\\release.txt"); + test(TheFs.IsValidName(filename,testChar)==EFalse); + test(pChar.Find(_L("\\"))!=KErrNotFound); + filename=_L("C:\\Hello World\\group\\release.txt"); + filename[8]=KPathDelimiter; // Makes C:\\Hello World\\group\\release.txt + test(TheFs.IsValidName(filename,testChar)); + filename=_L("C:\\HelloWorld\\::\\group\\release.txt"); + test(TheFs.IsValidName(filename,testChar)==EFalse); + test(pChar.Find(_L(":"))!=KErrNotFound); + + filename=_L("C:\\>>\\group\\release.txt"); + test(TheFs.IsValidName(filename,testChar)==EFalse); + test(pChar.Find(_L(">"))!=KErrNotFound); + + test(TheFs.IsValidName(_L(""),testChar)==EFalse); // Must be a name + test(testChar==' '); + test(TheFs.IsValidName(_L(".ext"),testChar)); + test(TheFs.IsValidName(_L("C:\\asdf.blarg\\"),testChar)==EFalse); + test(testChar==' '); // Must be a name else testChar is set to blank + test(TheFs.IsValidName(_L("C:\\asdf.blarg"),testChar)); + + test(TheFs.IsValidName(_L("C:\\asdf..blarg\\"),testChar)==EFalse); + test(testChar==' '); // Must be a name else testChar is set to blank + test(TheFs.IsValidName(_L("C:\\asdf..blarg"),testChar)); + + test(TheFs.IsValidName(_L("\\"),testChar)==EFalse); + test(testChar==' '); + +// Test multiple evil characters - parsing occurs from right to left +// except that wildcarded characters take priority and are picked out first + test(TheFs.IsValidName(_L("abc>def|ghi?jkl:mnodef|ghidef|ghidef|ghidef|ghi"),testChar)==EFalse); + test(testChar=='|'); + test(TheFs.IsValidName(_L("abc>def"),testChar)==EFalse); + test(testChar=='>'); + + test(!TheFs.IsValidName(_L("C:\\v123456.."),testChar)); // Valid name + test(TheFs.IsValidName(_L("abc"),testChar)); // Valid name + test(TheFs.IsValidName(_L("as(){}@~#;!\xA3$%^&()df.blarg"),testChar)); // Valid name + test(TheFs.IsValidName(_L("C:\\asdf.blarg\\asdf.blarg"),testChar)); // Valid name + test(TheFs.IsValidName(_L("\'"),testChar)); // Valid name + + //PDEF133084: The wild character in the extension was not being detected. + _LIT( KTestString, "E:\\My Videos\\Downloads\\1\\1\\Name.3gp?" ); + TBuf<50> path; + path = KTestString; + TBool validName( EFalse ); + TText badChar; + TInt badCharLoc( KErrNotFound ); + + while ( ! validName ) + { + validName = TheFs.IsValidName( path, badChar ); + + if ( ! validName ) + { + badCharLoc = path.LocateReverse( badChar ); + + if ( KErrNotFound != badCharLoc ) + { + path[badCharLoc] = '_'; + } + } + } + } + +LOCAL_C void Test9() +// +// Test IsFileInRom +// + { + + test.Next(_L("Test RFs::IsFileInRom")); + + CFileMan* fMan=CFileMan::NewL(TheFs); + TInt r=fMan->Copy(_L("Z:\\TEST\\T_FILE.CPP"),_L("C:\\T_FILE.CPP")); + test(r==KErrNone || r==KErrAccessDenied); + delete fMan; + TUint8* addr=TheFs.IsFileInRom(_L("C:\\ESHELL.EXE")); + test(addr==NULL); + addr=TheFs.IsFileInRom(_L("Z:\\TEST\\T_FILE.CPP")); + if (addr!=NULL) + { + test(addr!=NULL); + TPtrC8 startOfFile(addr,12); + test(startOfFile==_L8("// Copyright")); + } + else + { + test (addr==NULL); + } + } + +LOCAL_C void Test10() +// +// Test drive names +// + { + + test.Next(_L("Test Drive Names")); + TFileName driveName; + TInt i; + for(i=0;i drive0=_L("Dilbert"); + TBuf<64> drive4=_L("Dogbert"); + TBuf<64> drive17=_L("Flibble"); + TBuf<64> drive25=_L("RAMDRIVE"); + TInt r=TheFs.SetDriveName(0,drive0); + test(r==KErrNone); + r=TheFs.SetDriveName(4,drive4); + test(r==KErrNone); + r=TheFs.SetDriveName(17,drive17); + test(r==KErrNone); + r=TheFs.SetDriveName(25,drive25); + test(r==KErrNone); + + r=TheFs.GetDriveName(0,driveName); + test(r==KErrNone); + test(driveName==drive0); + r=TheFs.GetDriveName(4,driveName); + test(r==KErrNone); + test(driveName==drive4); + r=TheFs.GetDriveName(17,driveName); + test(r==KErrNone); + test(driveName==drive17); + r=TheFs.GetDriveName(25,driveName); + test(r==KErrNone); + test(driveName==drive25); + + drive0=_L("askdjflsdfourewoqiuroiuaksjdvx,cvsdhwjhjhalsjhfshfkjhslj"); + r=TheFs.SetDriveName(0,drive0); + test(r==KErrNone); + r=TheFs.GetDriveName(0,driveName); + test(r==KErrNone); + test(driveName==drive0); + +// Test with illegal characters in drive name + drive0=_L("Dil>bert"); + drive4=_L("Dog?bert"); + drive17=_L("Fli*bble"); + drive25=_L("RAMD//RIVE"); + + r=TheFs.SetDriveName(0,drive0); + test(r==KErrBadName); + r=TheFs.SetDriveName(4,drive4); + test(r==KErrBadName); + r=TheFs.SetDriveName(17,drive17); + test(r==KErrBadName); + r=TheFs.SetDriveName(25,drive25); + test(r==KErrBadName); + +// Test that it is OK to set the name to no characters + + drive0=_L(""); + drive4=_L(""); + drive17=_L(""); + drive25=_L(""); + + r=TheFs.SetDriveName(0,drive0); + test(r==KErrNone); + r=TheFs.SetDriveName(4,drive4); + test(r==KErrNone); + r=TheFs.SetDriveName(17,drive17); + test(r==KErrNone); + r=TheFs.SetDriveName(25,drive25); + test(r==KErrNone); + + r=TheFs.GetDriveName(0,driveName); + test(r==KErrNone); + test(driveName==drive0); + r=TheFs.GetDriveName(4,driveName); + test(r==KErrNone); + test(driveName==drive4); + r=TheFs.GetDriveName(17,driveName); + test(r==KErrNone); + test(driveName==drive17); + r=TheFs.GetDriveName(25,driveName); + test(r==KErrNone); + test(driveName==drive25); + + + } + +LOCAL_C void Test11() +// +// Miscellaneous tests +// + { + + test.Next(_L("Miscellaneous tests")); + TVolumeInfo vol; + TInt r=TheFs.Volume(vol); + test.Printf(_L("VolumeName = %S\n"),&vol.iName); + test(r==KErrNone); + r=TheFs.RmDir(_L("\\asdfasdf.\\")); + test(r==KErrBadName); + r=TheFs.MkDir(_L("\\asdfasdf.\\")); + test(r==KErrBadName); + } + +LOCAL_C void Test12() +// +// Test SetNotifyUser and GetNotifyUser +// + { + + test.Next(_L("Test Set and GetNotifyUser")); + TBool notifyState=TheFs.GetNotifyUser(); + test(notifyState); + notifyState=EFalse; + TheFs.SetNotifyUser(notifyState); + notifyState=TheFs.GetNotifyUser(); + test(notifyState==EFalse); + notifyState=ETrue; + TheFs.SetNotifyUser(notifyState); + notifyState=TheFs.GetNotifyUser(); + test(notifyState); + } + +LOCAL_C void Test13() +// +// Test return values from RFs::Volume on cf-cards +// + { + + test.Next(_L("Test RFs::Volume")); + TVolumeInfo vol; + TInt r=TheFs.Volume(vol,EDriveB); + test(r==KErrNotReady || r==KErrNone || KErrPathNotFound); + test.Printf(_L("RFs::Volume EDriveB returned %d\n"),r); + + r=TheFs.Volume(vol,EDriveC); + test(r==KErrNotReady || r==KErrNone || KErrPathNotFound); + test.Printf(_L("RFs::Volume EDriveC returned %d\n"),r); + + r=TheFs.Volume(vol,EDriveD); + test(r==KErrNotReady || r==KErrNone || KErrPathNotFound); + test.Printf(_L("RFs::Volume EDriveD returned %d\n"),r); + + r=TheFs.Volume(vol,EDriveE); + test(r==KErrNotReady || r==KErrNone || KErrPathNotFound); + test.Printf(_L("RFs::Volume EDriveE returned %d\n"),r); + + r=TheFs.Volume(vol,EDriveF); + test(r==KErrNotReady || r==KErrNone || KErrPathNotFound); + test.Printf(_L("RFs::Volume EDriveF returned %d\n"),r); + } + + +void DoTest14(TInt aDrvNum); +TInt CreateStuffedFile(RFs& aFs, const TDesC& aFileName, TUint aFileSize); +TInt CreateEmptyFile(RFs& aFs, const TDesC& aFileName, TUint aFileSize); +TBool CheckFileContents(RFs& aFs, const TDesC& aFileName); +TBool CheckBufferContents(const TDesC8& aBuffer, TUint aPrintBaseAddr=0); + +/** +Testing unallocated data initialization vulnerability in RFile +This test is performed on RAM drives and non-removable media that supports DeleteNotify (KMediaAttDeleteNotify flag) +e.g. XSR NAND +*/ +LOCAL_C void Test14() +{ + TInt nRes; + + test.Next(_L("Testing unallocated data initialization vulnerability in RFile")); + + TDriveList driveList; + TDriveInfo driveInfo; + + //-- 1. get drives list + nRes=TheFs.DriveList(driveList); + test(nRes == KErrNone); + + //-- 2. walk through all drives, performing the test only on suitable ones + for (TInt drvNum=0; drvNum"),param)==EFalse); + test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); + test(param.InvalidCharPos() == 1); + + test(TheFs.IsValidName(_L("<"),param)==EFalse); + test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); + test(param.InvalidCharPos() == 1); + + test(TheFs.IsValidName(_L(":"),param)==EFalse); + test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); + test(param.InvalidCharPos() == 1); + + test(TheFs.IsValidName(_L("\""),param)==EFalse); + test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); + test(param.InvalidCharPos() == 1); + + test(TheFs.IsValidName(_L("/"),param)==EFalse); + test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); + test(param.InvalidCharPos() == 1); + + test(TheFs.IsValidName(_L("|"),param)==EFalse); + test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); + test(param.InvalidCharPos() == 1); + + test(TheFs.IsValidName(_L("xx*yy"),param)==EFalse); + test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); + test(param.InvalidCharPos() == 3); + + test(TheFs.IsValidName(_L("xx?yy"),param)==EFalse); + test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); + test(param.InvalidCharPos() == 3); + + test(TheFs.IsValidName(_L("xx>yy"),param)==EFalse); + test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); + test(param.InvalidCharPos() == 3); + + test(TheFs.IsValidName(_L("xx\\group\\release.txt"),param)==EFalse); + test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); + test(param.InvalidCharPos() == 4); + + test(TheFs.IsValidName(_L("C:\\<\\group\\release.txt"),param)==EFalse); + test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); + test(param.InvalidCharPos() == 4); + + test(TheFs.IsValidName(_L("C:\\HelloWorld\\:\\group\\release.txt"),param)==EFalse); + test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); + test(param.InvalidCharPos() == 15); + + test(TheFs.IsValidName(_L("C::\\group\\release.txt"),param)==EFalse); + test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); + test(param.InvalidCharPos() == 3); + + test(TheFs.IsValidName(_L(">\\group\\release.txt"),param)==EFalse); + test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); + test(param.InvalidCharPos() == 1); + + test(TheFs.IsValidName(_L("C|group\\release.txt"),param)==EFalse); + test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); + test(param.InvalidCharPos() == 2); + + test(TheFs.IsValidName(_L("C\\|\\group\\release.txt"),param)==EFalse); + test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); + test(param.InvalidCharPos() == 3); + + test(TheFs.IsValidName(_L("\\>"),param)==EFalse); + test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); + test(param.InvalidCharPos() == 2); + + test(TheFs.IsValidName(_L("C:\\|group\\release.txt"),param)==EFalse); + test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); + test(param.InvalidCharPos() == 4); + + test(TheFs.IsValidName(_L("C:\\\"\\group\\release.txt"),param)==EFalse); + test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); + test(param.InvalidCharPos() == 4); + + test(TheFs.IsValidName(_L("C:\\/\\group\\release.txt"),param)==EFalse); + test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); + test(param.InvalidCharPos() == 4); + + test(TheFs.IsValidName(_L("C:\\|\\group\\release.txt"),param)==EFalse); + test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); + test(param.InvalidCharPos() == 4); + + test(TheFs.IsValidName(_L("C:\\ \\group\\release.txt"),param)==EFalse);//intermediate directory names cannot be blank + test(param.ErrorCode() == RFs::TNameValidParam::ErrBadName); + + // Test that \ is not allowed in filenames + TFileName filename; + filename=_L("C:\\HelloWorld\\\\\\group\\release.txt"); + + test(TheFs.IsValidName(filename,param)==EFalse); + test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); + test(param.InvalidCharPos() == 22); + + filename=_L("C:\\\\\\group\\release.txt"); + test(TheFs.IsValidName(filename,param)==EFalse); + test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); + test(param.InvalidCharPos() == 11); + + filename=_L("C:\\Hello World\\group\\release.txt"); + filename[8]=KPathDelimiter; + test(TheFs.IsValidName(filename,param)); + test(param.ErrorCode() == RFs::TNameValidParam::ErrNone); + + filename=_L("C:\\HelloWorld\\::\\group\\release.txt"); + test(TheFs.IsValidName(filename,param)==EFalse); + test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); + test(param.InvalidCharPos() == 16); + + filename=_L("C:\\>>\\group\\release.txt"); + test(TheFs.IsValidName(filename,param)==EFalse); + test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); + test(param.InvalidCharPos() == 5); + + test(TheFs.IsValidName(_L(""),param)==EFalse); // Must be a name + test(param.ErrorCode() == RFs::TNameValidParam::ErrBadName); + + test(TheFs.IsValidName(_L(".ext"),param)); + test(param.ErrorCode() == RFs::TNameValidParam::ErrNone); + + test(TheFs.IsValidName(_L("C:\\asdf.blarg"),param)); + test(param.ErrorCode() == RFs::TNameValidParam::ErrNone); + + test(TheFs.IsValidName(_L("C:\\asdf..blarg"),param)); + test(param.ErrorCode() == RFs::TNameValidParam::ErrNone); + + // Test multiple evil characters - parsing occurs from right to left + // except that wildcarded characters take priority and are picked out first + + test(TheFs.IsValidName(_L("abc>def|ghi?jkl:mnodef|ghidef|ghidef|ghidef|ghidef|ghidef|ghi"),param)==EFalse); + test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); + test(param.InvalidCharPos() == 8); + + test(TheFs.IsValidName(_L("abc>def|ghi"),param)==EFalse); + test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); + test(param.InvalidCharPos() == 8); + + test(TheFs.IsValidName(_L("abc>def"),param)==EFalse); + test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); + test(param.InvalidCharPos() == 4); + + test(TheFs.IsValidName(_L("abc>def"),param)==EFalse); + test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); + test(param.InvalidCharPos() == 4); + + test(!TheFs.IsValidName(_L("C:\\v123456.."),param)); + test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); + test(param.InvalidCharPos() == 11); + + test(!TheFs.IsValidName(_L("C:\\v123456.."),param)); + test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); + test(param.InvalidCharPos() == 11); + + test(TheFs.IsValidName(_L("abc"),param)); // Valid name + test(param.ErrorCode() == RFs::TNameValidParam::ErrNone); + + test(TheFs.IsValidName(_L("abc"),param)); // Valid name + test(param.ErrorCode() == RFs::TNameValidParam::ErrNone); + + test(TheFs.IsValidName(_L("as(){}@~#;!\xA3$%^&()df.blarg"),param)); // Valid name + test(param.ErrorCode() == RFs::TNameValidParam::ErrNone); + + test(TheFs.IsValidName(_L("as(){}@~#;!\xA3$%^&()df.blarg"),param)); // Valid name + test(param.ErrorCode() == RFs::TNameValidParam::ErrNone); + + test(TheFs.IsValidName(_L("C:\\asdf.blarg\\asdf.blarg"),param)); // Valid name + test(param.ErrorCode() == RFs::TNameValidParam::ErrNone); + + test(TheFs.IsValidName(_L("C:\\asdf.blarg\\asdf.blarg"),param)); // Valid name + test(param.ErrorCode() == RFs::TNameValidParam::ErrNone); + + test(TheFs.IsValidName(_L("\'"),param)); // Valid name + test(param.ErrorCode() == RFs::TNameValidParam::ErrNone); + + test(TheFs.IsValidName(_L("\'"),param)); // Valid name + test(param.ErrorCode() == RFs::TNameValidParam::ErrNone); + + //testing directory names + test(TheFs.IsValidName(_L("\\"),param)); + test(param.ErrorCode() == RFs::TNameValidParam::ErrNone); // Valid Name + + test(TheFs.IsValidName(_L("C:\\asdf.blarg\\"),param)); + test(param.ErrorCode() == RFs::TNameValidParam::ErrNone); // Valid Name + + + test(TheFs.IsValidName(_L("C:\\asdf..blarg\\"),param)); + test(param.ErrorCode() == RFs::TNameValidParam::ErrNone); // Valid Name + + test(TheFs.IsValidName(_L("file1.txt\\\\"),param) == EFalse); + test(param.ErrorCode() == RFs::TNameValidParam::ErrBadName); + + // test name which exceeds KMaxFileName only on prepending the session path + _LIT(KNameLength250, "AAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAA"); + if(useDefaultSessionPath) + { + test(TheFs.IsValidName(KNameLength250, param)==EFalse); + test(param.ErrorCode() == RFs::TNameValidParam::ErrNameTooLong); + break; + } + else + { + test(TheFs.IsValidName(KNameLength250, param)); + test(param.ErrorCode() == RFs::TNameValidParam::ErrNone); + } + useDefaultSessionPath = ETrue; + } + } + + + +void TestGetMediaSerialNumber() + { + test.Next(_L("Test RFs::GetMediaSerialNumber")); + TInt theDrive; + TInt r = TheFs.CharToDrive(gDriveToTest,theDrive); + test(r == KErrNone); + TMediaSerialNumber serNum; + r = TheFs.GetMediaSerialNumber(serNum, theDrive); + if (r) test.Printf(_L("RFs::GetMediaSerialNumber returned error %d"), r); + test(r == KErrNotSupported || r == KErrNotReady || r == KErrNone); + if (r == KErrNotSupported) + { + test.Printf(_L("MediaSerialNumber: Not Supported\n")); + } + else + { + test.Printf(_L("MediaSerialNumber: length=%d\n"), serNum.Length()); + TBuf<20> str; + _LIT(KNumberString, "%02X"); + _LIT(KNewLine, "\n"); + TInt i; + for (i = 0; i < serNum.Length(); i++) + { + str.AppendFormat(KNumberString, serNum[i]); + if (i%8 == 7) + { + str.Append(KNewLine); + test.Printf(_L("%S"), &str); + str.SetLength(0); + } + } + if (i%8 != 7) + { + test.Printf(KNewLine); + } + } + } + + +//-------------------------------------------------------- + +/** + Create an empty file of specified size. + @param aFs ref. to the FS + @param aFileName name of the file + @param aFileSize size of the file to be created + @return KErrNone on success, system-wide error code otherwise +*/ +TInt CreateEmptyFile(RFs& aFs, const TDesC& aFileName, TUint aFileSize) +{ + RFile file; + TInt nRes; + + nRes = file.Create(aFs, aFileName, EFileRead|EFileWrite); + if(nRes != KErrNone) + return nRes; + + nRes = file.SetSize(aFileSize); + if(nRes != KErrNone) + return nRes; + + file.Close(); + + return KErrNone; +} + +//-------------------------------------------------------- + +/** + Create a file of specified size filled with some data pattern. + @param aFs ref. to the FS + @param aFileName name of the file + @param aFileSize size of the file to be created + @return KErrNone on success, system-wide error code otherwise +*/ +TInt CreateStuffedFile(RFs& aFs, const TDesC& aFileName, TUint aFileSize) +{ + TInt nRes; + RFile file; + + //-- create a buffer with some data + const TUint KBufLength = 0x100; + TBuf8 buffer; + buffer.SetLength(KBufLength); + + TUint i; + + for(i = 0; i < KBufLength; i++) + buffer[i] = static_cast (i) ; + + //-- create a file + nRes = file.Create(aFs, aFileName, EFileRead|EFileWrite); + if(nRes != KErrNone) + return nRes; + + const TUint n1 = aFileSize / KBufLength; + const TUint n2 = aFileSize % KBufLength; + + //-- fill the file with the data from buffer + for(i=0; i buffer; + buffer.SetLength(0); + + //-- open the file + nRes = file.Open(aFs, aFileName, EFileRead); + test(nRes == KErrNone); + + //-- check file contents + TUint nFilePos=0; + for(;;) + { + //-- read data from the file into the buffer + nRes = file.Read(buffer); + test(nRes == KErrNone); + + if(buffer.Length() == 0) + { + nRes = KErrNone; //-- read all the file, no illegitimate information found + break; //EOF + } + + //-- check if the buffer contains only allowed data (RAM page initialisation data, etc. e.g. 0x00, 0xff, 0x03, 0xcc) + if(!CheckBufferContents(buffer, nFilePos)) + { + test.Printf(_L("\nCheckFileContents failed ! The file contains illegitimate information!\n")); + nRes = KErrCorrupt; //-- indicate that the read buffer contains illegitimate information + break; //-- comment this out if you need a full dump of the file + } + + nFilePos+=buffer.Length(); + } + + file.Close(); + return nRes; +} + +//-------------------------------------------------------- + +/** + Check if the buffer contains illegitimate information i.e. something different from 0x00, 0xff, 0x03, 0xcc + + @param aBuffer buffer descriptor to check + @param aPrintBaseAddr dump base address, used for dumping buffer only + @return ETrue on success +*/ +TBool CheckBufferContents(const TDesC8& aBuffer, TUint aPrintBaseAddr/*=0*/) +{ + TBool bRes = ETrue; + + //-- check if the buffer filled with allowable data (RAM page initialisation data or something similar) + //-- but not something meaningful. + //-- allowable bytes: 0x00, 0x03, 0xff, 0xcc + for(TInt i=0; i byteBuffer; + TBuf16<256> lineBuffer; + lineBuffer.Format(_L("%08X: "), aPrintBaseAddr+n); + for (TInt m=0; m<16 && n