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: #define __E32TEST_EXTENSION__ sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include "t_server.h" sl@0: #include "t_chlffs.h" sl@0: #include "fs_utils.h" sl@0: sl@0: #include "f32_test_utils.h" sl@0: sl@0: using namespace F32_Test_Utils; sl@0: sl@0: RTest test(_L("T_FILE")); sl@0: sl@0: TBool gShortFileNamesSupported = EFalse; sl@0: sl@0: static TBuf8<1500> gBuf; sl@0: sl@0: TInt gDriveNum = -1; sl@0: sl@0: static void testShare() sl@0: // sl@0: // Test file sharing. sl@0: // sl@0: { sl@0: sl@0: test.Start(_L("Test exclusive sharing")); sl@0: MakeFile(_L("TESTER")); sl@0: sl@0: /* sl@0: Extra code to answer a question about a potential WINS bug. WINS Elocal returns sl@0: KErrAccessDenied to the write operation but EFat returns sl@0: KErrNone... sl@0: sl@0: RFile f1; sl@0: TInt r=f1.Open(TheFs,_L("TESTER"),EFileRead|EFileShareAny); sl@0: test(r==KErrNone); sl@0: RFile f2; sl@0: r=f2.Open(TheFs,_L("TESTER"),EFileWrite|EFileShareAny); sl@0: test(r==KErrNone); sl@0: sl@0: r=f2.Write(_L("0")); sl@0: test.Printf(_L("returned %d"),r); sl@0: sl@0: f1.Close(); sl@0: f2.Close(); sl@0: sl@0: r=TheFs.Delete(_L("TESTER")); sl@0: test(r==KErrNone); sl@0: */ sl@0: sl@0: RFile f1; sl@0: TInt r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareExclusive); sl@0: test(r==KErrNone); sl@0: RFile f2; sl@0: r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareExclusive); sl@0: test(r==KErrInUse); sl@0: r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly); sl@0: test(r==KErrInUse); sl@0: r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareAny); sl@0: test(r==KErrInUse); sl@0: f1.Close(); sl@0: r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileWrite|EFileShareExclusive); sl@0: test(r==KErrNone); sl@0: f1.Close(); sl@0: sl@0: test.Next(_L("Test readers only sharing")); sl@0: r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileWrite|EFileShareReadersOnly); sl@0: test(r==KErrArgument); sl@0: r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly); sl@0: test(r==KErrNone); sl@0: r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareExclusive); sl@0: test(r==KErrInUse); sl@0: r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareAny); sl@0: test(r==KErrInUse); sl@0: r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileWrite|EFileShareReadersOnly); sl@0: test(r==KErrArgument); sl@0: r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly); sl@0: test(r==KErrNone); sl@0: f1.Close(); sl@0: f2.Close(); sl@0: sl@0: test.Next(_L("Test any sharing")); sl@0: r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileWrite|EFileShareAny); sl@0: test(r==KErrNone); sl@0: r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareExclusive); sl@0: test(r==KErrInUse); sl@0: r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly); sl@0: test(r==KErrInUse); sl@0: r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareAny); sl@0: test(r==KErrNone); sl@0: f1.Close(); sl@0: f2.Close(); sl@0: sl@0: test.End(); sl@0: } sl@0: sl@0: static void testChangeMode() sl@0: // sl@0: // Test changing the share mode of a file between EFileShareReadersOnly <-> EFileShareExclusive sl@0: // sl@0: { sl@0: sl@0: test.Start(_L("Test change mode")); sl@0: RFile f1; sl@0: RFile f2; sl@0: TInt r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareExclusive); sl@0: test(r==KErrNone); // Opened exclusive sl@0: r=f1.ChangeMode(EFileShareReadersOnly); sl@0: test(r==KErrNone); // Change to readers only sl@0: r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly); sl@0: test(r==KErrNone); // Open as reader sl@0: r=f1.ChangeMode(EFileShareExclusive); sl@0: test(r==KErrAccessDenied); // Change back to exclusive fails sl@0: r=f2.ChangeMode(EFileShareExclusive); sl@0: test(r==KErrAccessDenied); // Change to exclusive fails sl@0: f1.Close(); // Close other reader sl@0: r=f2.ChangeMode(EFileShareExclusive); sl@0: test(r==KErrNone); // Change to exclusive succeeds. sl@0: f2.Close(); sl@0: sl@0: r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly); sl@0: test(r==KErrNone); // Opened readers only sl@0: r=f1.ChangeMode(EFileShareExclusive); sl@0: test(r==KErrNone); // Change to exclusive sl@0: r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly); sl@0: test(r==KErrInUse); // Open as reader fails sl@0: r=f1.ChangeMode(EFileShareReadersOnly); sl@0: test(r==KErrNone); // Change to readers only sl@0: r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly); sl@0: test(r==KErrNone); // Open as reader sl@0: r=f1.ChangeMode(EFileShareExclusive); sl@0: test(r==KErrAccessDenied); // Change back to exclusive fails sl@0: r=f2.ChangeMode(EFileShareExclusive); sl@0: test(r==KErrAccessDenied); // Change to exclusive fails sl@0: f1.Close(); // Close other reader sl@0: r=f2.ChangeMode(EFileShareExclusive); sl@0: test(r==KErrNone); // Change to exclusive succeeds. sl@0: f2.Close(); sl@0: sl@0: r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileWrite|EFileShareExclusive); sl@0: test(r==KErrNone); // Opened exclusive for writing sl@0: r=f1.ChangeMode(EFileShareReadersOnly); sl@0: test(r==KErrAccessDenied); // Change to readers fails sl@0: r=f1.ChangeMode(EFileShareExclusive); sl@0: test(r==KErrNone); // No change ok sl@0: r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly); sl@0: test(r==KErrInUse); // Open as reader fails sl@0: f1.Close(); sl@0: sl@0: r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareAny); sl@0: test(r==KErrNone); // Opened share any sl@0: r=f1.ChangeMode(EFileShareExclusive); sl@0: test(r==KErrAccessDenied); // Change to exclusive fails sl@0: r=f1.ChangeMode(EFileShareReadersOnly); sl@0: test(r==KErrAccessDenied); // Change to readers only fails sl@0: f1.Close(); sl@0: sl@0: r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareExclusive); sl@0: test(r==KErrNone); // Opened exclusive sl@0: r=f1.ChangeMode(EFileShareAny); sl@0: test(r==KErrArgument); // Change to share any fails KErrArgument sl@0: r=f1.ChangeMode((TFileMode)42); sl@0: test(r==KErrArgument); // Change to random value fails sl@0: f1.Close(); sl@0: test.End(); sl@0: } sl@0: sl@0: static void testReadFile() sl@0: // sl@0: // Test read file handling. sl@0: // sl@0: { sl@0: sl@0: test.Start(_L("Test read file")); sl@0: RFile f,ZFile; sl@0: TInt r=f.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText); sl@0: test(r==KErrNone); sl@0: TFileName fn = _L("Z:\\TEST\\T_FILE.CPP"); sl@0: fn[0] = gExeFileName[0]; sl@0: r=ZFile.Open(TheFs,fn,EFileStreamText); sl@0: test(r==KErrNone); sl@0: sl@0: test.Next(_L("Read file")); sl@0: TBuf8<0x100> a,b; sl@0: FOREVER sl@0: { sl@0: r=f.Read(b); sl@0: test(r==KErrNone); sl@0: r=ZFile.Read(a); sl@0: test(r==KErrNone); sl@0: test(a==b); sl@0: if (b.Length() b1; sl@0: r=f1.Read(b1); sl@0: test(r==KErrNone); sl@0: TBuf8<0x100> b2; sl@0: r=f2.Read(b2); sl@0: test(r==KErrNone); sl@0: test(b1==b2); sl@0: if (b1.Length() testData=_L8("testData"); sl@0: sl@0: // write test 1 sl@0: TInt r=file.Replace(TheFs,fn,EFileStreamText); sl@0: test(r==KErrNone); sl@0: sl@0: test.Next(_L("Write file")); sl@0: sl@0: r=file.Write(testData); sl@0: test(r==KErrNone); sl@0: sl@0: file.Close(); sl@0: sl@0: // test write modes sl@0: // test writing with EFileRead sl@0: r=file.Open(TheFs,fn,EFileStreamText|EFileRead); sl@0: test(r==KErrNone); sl@0: sl@0: test.Next(_L("Write file")); sl@0: r=file.Write(testData); sl@0: test(r==KErrAccessDenied); sl@0: file.Close(); sl@0: sl@0: // test writing with EFileWrite sl@0: r=file.Open(TheFs,fn,EFileStreamText|EFileWrite); sl@0: test(r==KErrNone); sl@0: sl@0: test.Next(_L("Write file")); sl@0: r=file.Write(testData); sl@0: test(r==KErrNone); sl@0: file.Close(); sl@0: sl@0: // test writing with share mode EFileShareExclusive sl@0: r=file.Open(TheFs,fn,EFileStreamText|EFileWrite|EFileShareExclusive); sl@0: test(r==KErrNone); sl@0: sl@0: test.Next(_L("Write file")); sl@0: r=file.Write(testData); sl@0: test(r==KErrNone); sl@0: file.Close(); sl@0: sl@0: // test writing with share mode EFileShareReadersOnly (fails with KErrArgument) sl@0: r=file.Open(TheFs,fn,EFileStreamText|EFileWrite|EFileShareReadersOnly); sl@0: test(r==KErrArgument); sl@0: sl@0: // test writing with share mode EFileShareReadersOrWriters sl@0: r=file.Open(TheFs,fn,EFileStreamText|EFileWrite|EFileShareReadersOrWriters); sl@0: test(r==KErrNone); sl@0: sl@0: test.Next(_L("Write file")); sl@0: r=file.Write(testData); sl@0: test(r==KErrNone); sl@0: file.Close(); sl@0: sl@0: // test writing with share mode EFileShareAny sl@0: r=file.Open(TheFs,fn,EFileStreamText|EFileWrite|EFileShareAny); sl@0: test(r==KErrNone); sl@0: sl@0: test.Next(_L("Write file")); sl@0: r=file.Write(testData); sl@0: test(r==KErrNone); sl@0: file.Close(); sl@0: sl@0: // tidy up sl@0: r=TheFs.Delete(fn); sl@0: test(r==KErrNone); sl@0: sl@0: test.End(); sl@0: } sl@0: sl@0: static void CopyFileToTestDirectory() sl@0: // sl@0: // Make a copy of the file in ram sl@0: // sl@0: { sl@0: sl@0: TFileName fn = _L("Z:\\TEST\\T_FILE.CPP"); sl@0: fn[0] = gExeFileName[0]; sl@0: TParse f; sl@0: TInt r; sl@0: r=TheFs.Parse(fn,f); sl@0: test(r==KErrNone); sl@0: TParse fCopy; sl@0: r=TheFs.Parse(f.NameAndExt(),fCopy); sl@0: test(r==KErrNone); sl@0: sl@0: RFile f1; sl@0: r=f1.Open(TheFs,f.FullName(),EFileStreamText|EFileShareReadersOnly); sl@0: test(r==KErrNone); sl@0: RFile f2; sl@0: r=f2.Replace(TheFs,fCopy.FullName(),EFileWrite); sl@0: test(r==KErrNone); sl@0: TBuf8<512> copyBuf; sl@0: TInt rem; sl@0: r=f1.Size(rem); sl@0: test(r==KErrNone); sl@0: TInt pos=0; sl@0: while (rem) sl@0: { sl@0: TInt s=Min(rem,copyBuf.MaxSize()); sl@0: r=f1.Read(pos,copyBuf,s); sl@0: test(r==KErrNone); sl@0: test(copyBuf.Length()==s); sl@0: r=f2.Write(pos,copyBuf,s); sl@0: test(r==KErrNone); sl@0: pos+=s; sl@0: rem-=s; sl@0: } sl@0: f1.Close(); sl@0: f2.Close(); sl@0: } sl@0: sl@0: static void testFileText() sl@0: // sl@0: // Test TFileText class methods sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Test file text")); sl@0: TPtrC record[5]; sl@0: record[0].Set(_L("First record")); sl@0: record[1].Set(_L("Second record")); sl@0: record[2].Set(_L("Third record")); sl@0: record[3].Set(_L("Fourth record")); sl@0: record[4].Set(_L("Fifth record")); sl@0: sl@0: RFile f; sl@0: TInt r=f.Replace(TheFs,_L("TEXTFILE.TXT"),0); sl@0: test(r==KErrNone); sl@0: TFileText textFile; sl@0: textFile.Set(f); sl@0: TInt i=0; sl@0: for (i=0;i<5;i++) sl@0: { sl@0: r=textFile.Write(record[i]); sl@0: test(r==KErrNone); sl@0: } sl@0: r=textFile.Seek(ESeekStart); sl@0: test(r==KErrNone); sl@0: TBuf<16> recBuf; sl@0: for(i=0;i<5;i++) sl@0: { sl@0: r=textFile.Read(recBuf); sl@0: test(r==KErrNone); sl@0: test(recBuf==record[i]); sl@0: } sl@0: r=textFile.Read(recBuf); sl@0: test(r==KErrEof); sl@0: test(recBuf.Length()==0); sl@0: f.Close(); sl@0: sl@0: test.Next(_L("Test dosfile terminator")); sl@0: TPtrC8 trecord[7]; sl@0: TPtrC tTextrecord[7]; sl@0: tTextrecord[0].Set(_L("First record\r\n")); sl@0: tTextrecord[1].Set(_L("Second record\r\n")); sl@0: tTextrecord[2].Set(_L("Third record\r\n")); sl@0: tTextrecord[3].Set(_L("Fourth record\r\n")); sl@0: tTextrecord[4].Set(_L("Fifth record\r\n")); sl@0: tTextrecord[5].Set(_L("Sixth record\n\r")); sl@0: tTextrecord[6].Set(_L("Seventh record\n")); sl@0: trecord[0].Set((TUint8*)tTextrecord[0].Ptr(),tTextrecord[0].Length()*sizeof(TText)); sl@0: trecord[1].Set((TUint8*)tTextrecord[1].Ptr(),tTextrecord[1].Length()*sizeof(TText)); sl@0: trecord[2].Set((TUint8*)tTextrecord[2].Ptr(),tTextrecord[2].Length()*sizeof(TText)); sl@0: trecord[3].Set((TUint8*)tTextrecord[3].Ptr(),tTextrecord[3].Length()*sizeof(TText)); sl@0: trecord[4].Set((TUint8*)tTextrecord[4].Ptr(),tTextrecord[4].Length()*sizeof(TText)); sl@0: trecord[5].Set((TUint8*)tTextrecord[5].Ptr(),tTextrecord[5].Length()*sizeof(TText)); sl@0: trecord[6].Set((TUint8*)tTextrecord[6].Ptr(),tTextrecord[6].Length()*sizeof(TText)); sl@0: r=f.Replace(TheFs,_L("TEXTFILE.TXT"),0); sl@0: test(r==KErrNone); sl@0: for(i=0;i<7;i++) sl@0: { sl@0: TBuf8<256> buf; sl@0: buf.Copy(trecord[i]); sl@0: r=f.Write(buf); sl@0: test(r==KErrNone); sl@0: } sl@0: textFile.Set(f); sl@0: textFile.Seek(ESeekStart); sl@0: for(i=0;i<5;i++) sl@0: { sl@0: r=textFile.Read(recBuf); sl@0: test(r==KErrNone); sl@0: test(recBuf==record[i]); sl@0: } sl@0: r=textFile.Read(recBuf); sl@0: test(r==KErrNone); sl@0: test(recBuf==_L("Sixth record")); sl@0: r=textFile.Read(recBuf); sl@0: test(r==KErrNone); sl@0: test(recBuf==_L("\rSeventh record")); sl@0: r=textFile.Read(recBuf); sl@0: test(r==KErrEof); sl@0: test(recBuf.Length()==0); sl@0: f.Close(); sl@0: sl@0: test.Next(_L("Test read with bufferSize == dataSize")); sl@0: r=f.Replace(TheFs,_L("TEXTFILE.TXT"),0); sl@0: test(r==KErrNone); sl@0: record[0].Set(_L("1234567890123456")); sl@0: // trecord[0].Set(_L8("1234567890123456\r\n")); sl@0: // trecord[1].Set(_L8("1234567890123456\n")); sl@0: sl@0: TPtrC tmpTextrecord; sl@0: tmpTextrecord.Set(_L("1234567890123456\r\n")); sl@0: trecord[0].Set((TUint8*)tmpTextrecord.Ptr(),tmpTextrecord.Length()*sizeof(TText)); sl@0: sl@0: tmpTextrecord.Set(_L("1234567890123456\n")); sl@0: trecord[1].Set((TUint8*)tmpTextrecord.Ptr(),tmpTextrecord.Length()*sizeof(TText)); sl@0: sl@0: for (i=0;i<2;i++) sl@0: { sl@0: r=f.Write(trecord[i]); sl@0: test(r==KErrNone); sl@0: } sl@0: textFile.Set(f); sl@0: textFile.Seek(ESeekStart); sl@0: for(i=0;i<2;i++) sl@0: { sl@0: r=textFile.Read(recBuf); sl@0: test(r==KErrNone); sl@0: test(recBuf==record[0]); sl@0: } sl@0: r=textFile.Read(recBuf); sl@0: test(r==KErrEof); sl@0: test(recBuf.Length()==0); sl@0: f.Close(); sl@0: sl@0: test.Next(_L("Read into a buffer < recordSize")); sl@0: TBuf<8> smallBuf; sl@0: r=f.Open(TheFs,_L("TEXTFILE.txt"),0); sl@0: test(r==KErrNone); sl@0: textFile.Set(f); sl@0: for(i=0;i<2;i++) sl@0: { sl@0: r=textFile.Read(smallBuf); sl@0: test(r==KErrTooBig); sl@0: test(smallBuf==_L("12345678")); sl@0: } sl@0: f.Close(); sl@0: sl@0: test.Next(_L("Nasty cases: 1) \\r \\n split over buffer boundary")); sl@0: r=f.Replace(TheFs,_L("TEXTFILE.txt"),0); sl@0: test(r==KErrNone); sl@0: HBufC* largeRecord=HBufC::NewL(600); sl@0: largeRecord->Des().SetLength(250); sl@0: largeRecord->Des().Fill('A'); sl@0: largeRecord->Des()[249]='\n'; sl@0: TPtrC8 bufPtr; sl@0: bufPtr.Set((TUint8*)largeRecord->Ptr(),largeRecord->Size()); // Size() returns length in bytes sl@0: r=f.Write(bufPtr); sl@0: test(r==KErrNone); sl@0: TBuf<16> boundaryBuf=_L("12345\r\n"); sl@0: bufPtr.Set((TUint8*)boundaryBuf.Ptr(),boundaryBuf.Size()); sl@0: r=f.Write(bufPtr); sl@0: test(r==KErrNone); sl@0: r=f.Write(trecord[0]); sl@0: test(r==KErrNone); sl@0: sl@0: textFile.Set(f); sl@0: textFile.Seek(ESeekStart); sl@0: r=textFile.Read(recBuf); sl@0: test(r==KErrTooBig); sl@0: test(recBuf==_L("AAAAAAAAAAAAAAAA")); sl@0: r=textFile.Read(recBuf); sl@0: test(r==KErrNone); sl@0: test(recBuf==_L("12345")); sl@0: r=textFile.Read(recBuf); sl@0: test(r==KErrNone); sl@0: test(recBuf==record[0]); sl@0: f.Close(); sl@0: sl@0: test.Next(_L("Nasty cases: 2) \\r on buffer boundary")); sl@0: r=f.Replace(TheFs,_L("TEXTFILE.txt"),0); sl@0: test(r==KErrNone); sl@0: largeRecord->Des().SetLength(250); sl@0: largeRecord->Des().Fill('A'); sl@0: largeRecord->Des()[249]='\n'; sl@0: bufPtr.Set((TUint8*)largeRecord->Ptr(),largeRecord->Size()); sl@0: r=f.Write(bufPtr); sl@0: test(r==KErrNone); sl@0: boundaryBuf=_L("12345\rxyz\n"); sl@0: bufPtr.Set((TUint8*)boundaryBuf.Ptr(),boundaryBuf.Size()); sl@0: r=f.Write(bufPtr); sl@0: test(r==KErrNone); sl@0: r=f.Write(trecord[0]); sl@0: test(r==KErrNone); sl@0: sl@0: textFile.Set(f); sl@0: textFile.Seek(ESeekStart); sl@0: r=textFile.Read(recBuf); sl@0: test(r==KErrTooBig); sl@0: test(recBuf==_L("AAAAAAAAAAAAAAAA")); sl@0: r=textFile.Read(recBuf); sl@0: test(r==KErrNone); sl@0: test(recBuf==_L("12345\rxyz")); sl@0: r=textFile.Read(recBuf); sl@0: test(r==KErrNone); sl@0: test(recBuf==record[0]); sl@0: f.Close(); sl@0: sl@0: test.Next(_L("Nasty cases: 3) record size > buffer size")); sl@0: r=f.Replace(TheFs,_L("TEXTFILE.txt"),0); sl@0: test(r==KErrNone); sl@0: largeRecord->Des().SetLength(600); sl@0: largeRecord->Des().Fill('Z'); sl@0: largeRecord->Des()[511]='\r'; sl@0: largeRecord->Des()[599]='\n'; sl@0: bufPtr.Set((TUint8*)largeRecord->Ptr(),largeRecord->Size()); sl@0: r=f.Write(bufPtr); sl@0: test(r==KErrNone); sl@0: boundaryBuf=_L("12345\rxyz\n"); sl@0: bufPtr.Set((TUint8*)boundaryBuf.Ptr(),boundaryBuf.Size()); sl@0: r=f.Write(bufPtr); sl@0: test(r==KErrNone); sl@0: r=f.Write(trecord[0]); sl@0: test(r==KErrNone); sl@0: sl@0: textFile.Set(f); sl@0: textFile.Seek(ESeekStart); sl@0: r=textFile.Read(recBuf); sl@0: test(r==KErrTooBig); sl@0: test(recBuf==_L("ZZZZZZZZZZZZZZZZ")); sl@0: r=textFile.Read(recBuf); sl@0: test(r==KErrNone); sl@0: test(recBuf==_L("12345\rxyz")); sl@0: r=textFile.Read(recBuf); sl@0: test(r==KErrNone); sl@0: test(recBuf==record[0]); sl@0: sl@0: TBuf<601> bigBuf; sl@0: TPtrC largePtr((TText*)largeRecord->Ptr(),(largeRecord->Length()-1)); sl@0: textFile.Seek(ESeekStart); sl@0: r=textFile.Read(bigBuf); sl@0: test(r==KErrNone); sl@0: test(bigBuf==largePtr); sl@0: r=textFile.Read(recBuf); sl@0: test(r==KErrNone); sl@0: test(recBuf==_L("12345\rxyz")); sl@0: r=textFile.Read(recBuf); sl@0: test(r==KErrNone); sl@0: test(recBuf==record[0]); sl@0: f.Close(); sl@0: sl@0: User::Free(largeRecord); sl@0: } sl@0: sl@0: static void testFileTextEndRecord() sl@0: // sl@0: // Test terminating record sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Test FileText last record has no terminator")); sl@0: RFile f; sl@0: TInt r=f.Replace(TheFs,_L("TextFile"),0); sl@0: test(r==KErrNone); sl@0: TPtrC8 bufPtr; sl@0: TBuf<16>boundaryBuf=_L("Record1\n"); sl@0: bufPtr.Set((TUint8*)boundaryBuf.Ptr(),boundaryBuf.Size()); sl@0: r=f.Write(bufPtr); sl@0: test(r==KErrNone); sl@0: boundaryBuf=_L("Record2\n"); sl@0: bufPtr.Set((TUint8*)boundaryBuf.Ptr(),boundaryBuf.Size()); sl@0: r=f.Write(bufPtr); sl@0: test(r==KErrNone); sl@0: boundaryBuf=_L("Record3\n"); sl@0: bufPtr.Set((TUint8*)boundaryBuf.Ptr(),boundaryBuf.Size()); sl@0: r=f.Write(bufPtr); sl@0: test(r==KErrNone); sl@0: sl@0: TFileText fText; sl@0: fText.Set(f); sl@0: r=fText.Seek(ESeekStart); sl@0: test(r==KErrNone); sl@0: TBuf<32> recBuf; sl@0: r=fText.Read(recBuf); sl@0: test(r==KErrNone); sl@0: test(recBuf.MatchF(_L("record1"))!=KErrNotFound); sl@0: r=fText.Read(recBuf); sl@0: test(r==KErrNone); sl@0: test(recBuf.MatchF(_L("record2"))!=KErrNotFound); sl@0: r=fText.Read(recBuf); sl@0: test(r==KErrNone); sl@0: test(recBuf.MatchF(_L("record3"))!=KErrNotFound); sl@0: r=fText.Read(recBuf); sl@0: test(r==KErrEof); sl@0: test(recBuf.Length()==0); sl@0: f.Close(); sl@0: sl@0: TBuf<0x100> bigBuf(0x100); sl@0: bigBuf.Fill('A'); sl@0: r=f.Replace(TheFs,_L("TextFile"),0); sl@0: test(r==KErrNone); sl@0: sl@0: bufPtr.Set((TUint8*)bigBuf.Ptr(),bigBuf.Size()); sl@0: r=f.Write(bufPtr); sl@0: test(r==KErrNone); sl@0: sl@0: fText.Set(f); sl@0: r=fText.Seek(ESeekStart); sl@0: test(r==KErrNone); sl@0: bigBuf.SetLength(0); sl@0: r=fText.Read(bigBuf); sl@0: test.Printf(_L("fText.Read returns %d\n"),r); sl@0: test(r==KErrNone); sl@0: test.Printf(_L("BigBuf.Length()==%d\n"),bigBuf.Length()); sl@0: test(bigBuf.Length()==0x100); sl@0: r=fText.Read(bigBuf); sl@0: test(r==KErrEof); sl@0: test(bigBuf.Length()==0); sl@0: f.Close(); sl@0: } sl@0: sl@0: static void testFileNames() sl@0: // sl@0: // Test file names sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Test temp filenames specify drive")); sl@0: TFileName tempFileName; sl@0: RFile f; sl@0: TInt r=f.Temp(TheFs,_L(""),tempFileName,EFileRead); sl@0: test(r==KErrNone); sl@0: TParse p; sl@0: p.Set(tempFileName,NULL,NULL); sl@0: test(p.DrivePresent()); sl@0: test(p.PathPresent()); sl@0: test(p.NamePresent()); sl@0: test(p.ExtPresent()); sl@0: f.Close(); sl@0: sl@0: r=f.Replace(TheFs,_L("WELCOMETO"),EFileWrite); sl@0: test(r==KErrNone); sl@0: f.Close(); sl@0: r=f.Replace(TheFs,_L("WELCOMETO.WRD"),EFileWrite); sl@0: test(r==KErrNone); sl@0: f.Close(); sl@0: } sl@0: sl@0: // Nasty hack - mask attributes returned by RFile::Att() with this. sl@0: // File server used to do this but that stopped the XIP attribute on the ROM file system sl@0: // from being returned. It should really be up to the file system to return only sl@0: // the attributes which it supports rather than having the file server unilaterally sl@0: // mask off any attributes which don't exist on FAT. sl@0: #define ATT_MASK 0x3f sl@0: static void testFileAttributes() sl@0: // sl@0: // Test the archive attribute gets set sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Archive att is set after creation")); sl@0: RFile f; sl@0: TInt r=TheFs.Delete(_L("FILEATT.ARC")); sl@0: test(r==KErrNone || r==KErrNotFound); sl@0: r=f.Create(TheFs,_L("FILEATT.ARC"),EFileRead); sl@0: test(r==KErrNone); sl@0: TUint atts; sl@0: r=f.Att(atts); sl@0: test(r==KErrNone); sl@0: test((atts&ATT_MASK)==KEntryAttArchive); sl@0: TEntry fileAtt; sl@0: r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); sl@0: test(r==KErrNone); sl@0: test(fileAtt.iAtt==KEntryAttArchive); sl@0: f.Close(); sl@0: r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); sl@0: test(r==KErrNone); sl@0: test(fileAtt.iAtt==KEntryAttArchive); sl@0: sl@0: test.Next(_L("Archive att is set after a write")); sl@0: TheFs.SetAtt(_L("FILEATT.ARC"),0,KEntryAttArchive); sl@0: r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); sl@0: test(r==KErrNone); sl@0: test(fileAtt.iAtt==0); sl@0: r=f.Open(TheFs,_L("FILEATT.ARC"),EFileWrite); sl@0: test(r==KErrNone); sl@0: r=f.Write(_L8("Hello World")); sl@0: test(r==KErrNone); sl@0: r=f.Att(atts); sl@0: test(r==KErrNone); sl@0: test((atts&ATT_MASK)==KEntryAttArchive); sl@0: r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); sl@0: test(r==KErrNone); sl@0: test(fileAtt.iAtt==KEntryAttArchive); sl@0: f.Close(); sl@0: r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); sl@0: test(r==KErrNone); sl@0: test(fileAtt.iAtt==KEntryAttArchive); sl@0: sl@0: test.Next(_L("Archive att is set after setsize")); sl@0: TheFs.SetAtt(_L("FILEATT.ARC"),0,KEntryAttArchive); sl@0: r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); sl@0: test(r==KErrNone); sl@0: test(fileAtt.iAtt==0); sl@0: r=f.Open(TheFs,_L("FILEATT.ARC"),EFileWrite); sl@0: test(r==KErrNone); sl@0: r=f.SetSize(447); sl@0: test(r==KErrNone); sl@0: TInt size; sl@0: r=f.Size(size); sl@0: test(r==KErrNone); sl@0: test(size==447); sl@0: r=f.Att(atts); sl@0: test(r==KErrNone); sl@0: test((atts&ATT_MASK)==KEntryAttArchive); sl@0: r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); sl@0: test(r==KErrNone); sl@0: test(fileAtt.iAtt==KEntryAttArchive); sl@0: f.Close(); sl@0: r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); sl@0: test(r==KErrNone); sl@0: test(fileAtt.iAtt==KEntryAttArchive); sl@0: sl@0: test.Next(_L("Archive att is not set after open")); sl@0: r=TheFs.SetAtt(_L("FILEATT.ARC"),0,KEntryAttArchive); sl@0: test(r==KErrNone); sl@0: r=f.Open(TheFs,_L("FILEATT.ARC"),EFileWrite); sl@0: test(r==KErrNone); sl@0: r=f.Att(atts); sl@0: test(r==KErrNone); sl@0: test((atts&ATT_MASK)==0); sl@0: r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); sl@0: test(r==KErrNone); sl@0: test(fileAtt.iAtt==0); sl@0: f.Close(); sl@0: r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); sl@0: test(r==KErrNone); sl@0: test(fileAtt.iAtt==0); sl@0: sl@0: test.Next(_L("Archive att is not set after a read")); sl@0: TheFs.SetAtt(_L("FILEATT.ARC"),0,KEntryAttArchive); sl@0: r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); sl@0: test(r==KErrNone); sl@0: test(fileAtt.iAtt==0); sl@0: r=f.Open(TheFs,_L("FILEATT.ARC"),EFileWrite); sl@0: test(r==KErrNone); sl@0: TBuf8<16> readBuf; sl@0: r=f.Read(readBuf); sl@0: test(r==KErrNone); sl@0: r=f.Att(atts); sl@0: test(r==KErrNone); sl@0: test((atts&ATT_MASK)==0); sl@0: r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); sl@0: test(r==KErrNone); sl@0: test(fileAtt.iAtt==0); sl@0: f.Close(); sl@0: r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); sl@0: test(r==KErrNone); sl@0: test(fileAtt.iAtt==0); sl@0: sl@0: test.Next(_L("Archive att is set after replace")); sl@0: r=f.Replace(TheFs,_L("FILEATT.ARC"),EFileWrite); sl@0: test(r==KErrNone); sl@0: r=f.Att(atts); sl@0: test(r==KErrNone); sl@0: test((atts&ATT_MASK)==KEntryAttArchive); sl@0: r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); sl@0: test(r==KErrNone); sl@0: test(fileAtt.iAtt==KEntryAttArchive); sl@0: f.Close(); sl@0: r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); sl@0: test(r==KErrNone); sl@0: test(fileAtt.iAtt==KEntryAttArchive); sl@0: sl@0: test.Next(_L("Read only bit can be unset")); sl@0: r=TheFs.SetAtt(_L("FILEATT.ARC"),KEntryAttReadOnly|KEntryAttHidden,0); sl@0: test(r==KErrNone); sl@0: r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); sl@0: test(r==KErrNone); sl@0: test(fileAtt.iAtt==(KEntryAttReadOnly|KEntryAttHidden|KEntryAttArchive)); sl@0: sl@0: r=TheFs.SetAtt(_L("FILEATT.ARC"),0,KEntryAttHidden); sl@0: test(r==KErrNone); sl@0: r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); sl@0: test(r==KErrNone); sl@0: test(fileAtt.iAtt==(KEntryAttReadOnly|KEntryAttArchive)); sl@0: sl@0: r=TheFs.SetAtt(_L("FILEATT.ARC"),0,KEntryAttReadOnly); sl@0: test(r==KErrNone); sl@0: r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); sl@0: test(r==KErrNone); sl@0: test(fileAtt.iAtt==(KEntryAttArchive)); sl@0: sl@0: r=TheFs.SetAtt(_L("FILEATT.ARC"),KEntryAttReadOnly|KEntryAttHidden,0); sl@0: test(r==KErrNone); sl@0: r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); sl@0: test(r==KErrNone); sl@0: test(fileAtt.iAtt==(KEntryAttReadOnly|KEntryAttHidden|KEntryAttArchive)); sl@0: sl@0: r=TheFs.SetAtt(_L("FILEATT.ARC"),0,KEntryAttReadOnly); sl@0: test(r==KErrNone); sl@0: r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); sl@0: test(r==KErrNone); sl@0: test(fileAtt.iAtt==(KEntryAttHidden|KEntryAttArchive)); sl@0: sl@0: r=TheFs.SetAtt(_L("FILEATT.ARC"),0,KEntryAttHidden); sl@0: test(r==KErrNone); sl@0: r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); sl@0: test(r==KErrNone); sl@0: test(fileAtt.iAtt==(KEntryAttArchive)); sl@0: sl@0: TTime time(0); sl@0: r=TheFs.SetEntry(_L("FILEATT.ARC"),time,KEntryAttReadOnly|KEntryAttHidden,0); sl@0: test(r==KErrNone); sl@0: r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); sl@0: test(r==KErrNone); sl@0: test(fileAtt.iAtt==(KEntryAttReadOnly|KEntryAttHidden|KEntryAttArchive)); sl@0: sl@0: r=TheFs.SetEntry(_L("FILEATT.ARC"),time,0,KEntryAttHidden); sl@0: test(r==KErrNone); sl@0: r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); sl@0: test(r==KErrNone); sl@0: test(fileAtt.iAtt==(KEntryAttReadOnly|KEntryAttArchive)); sl@0: sl@0: r=TheFs.SetEntry(_L("FILEATT.ARC"),time,0,KEntryAttReadOnly); sl@0: test(r==KErrNone); sl@0: r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); sl@0: test(r==KErrNone); sl@0: test(fileAtt.iAtt==(KEntryAttArchive)); sl@0: sl@0: r=TheFs.SetEntry(_L("FILEATT.ARC"),time,KEntryAttReadOnly|KEntryAttHidden,0); sl@0: test(r==KErrNone); sl@0: r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); sl@0: test(r==KErrNone); sl@0: test(fileAtt.iAtt==(KEntryAttReadOnly|KEntryAttHidden|KEntryAttArchive)); sl@0: sl@0: r=TheFs.SetEntry(_L("FILEATT.ARC"),time,0,KEntryAttReadOnly); sl@0: test(r==KErrNone); sl@0: r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); sl@0: test(r==KErrNone); sl@0: test(fileAtt.iAtt==(KEntryAttHidden|KEntryAttArchive)); sl@0: sl@0: r=TheFs.SetEntry(_L("FILEATT.ARC"),time,0,KEntryAttHidden); sl@0: test(r==KErrNone); sl@0: r=TheFs.Entry(_L("FILEATT.ARC"),fileAtt); sl@0: test(r==KErrNone); sl@0: test(fileAtt.iAtt==(KEntryAttArchive)); sl@0: sl@0: test.Next(_L("Cashing the 'read-only' attribute")); sl@0: const TDesC& fname = _L("TEST.RO"); sl@0: sl@0: // Test RO attribute after creating a file sl@0: r=f.Create(TheFs,fname,EFileWrite); sl@0: test(r==KErrNone); sl@0: r=f.SetAtt(KEntryAttReadOnly,0); sl@0: test(r==KErrNone); sl@0: r=f.Write(_L8("Hello World")); sl@0: test(r==KErrNone); // <-- here! sl@0: f.Close(); sl@0: sl@0: // Test we can't open for write or delete a RO file sl@0: r=f.Open(TheFs,fname,EFileWrite); sl@0: test(r==KErrAccessDenied); sl@0: r=TheFs.Delete(fname); sl@0: test(r==KErrAccessDenied); sl@0: sl@0: // Tidy up and re-create test file sl@0: r=TheFs.SetAtt(fname,0,KEntryAttReadOnly); sl@0: test(r==KErrNone); sl@0: r=TheFs.Delete(fname); sl@0: test(r==KErrNone); sl@0: r=f.Create(TheFs,fname,EFileWrite); sl@0: test(r==KErrNone); sl@0: f.Close(); sl@0: sl@0: // Test RO attribute after opening a file sl@0: r=f.Open(TheFs,fname,EFileWrite); sl@0: test(r==KErrNone); sl@0: r=f.SetAtt(KEntryAttReadOnly,0); sl@0: test(r==KErrNone); sl@0: r=f.Write(_L8("Hello World")); sl@0: test(r==KErrNone); sl@0: f.Close(); sl@0: sl@0: // Tidy up sl@0: r=TheFs.SetAtt(fname,0,KEntryAttReadOnly); sl@0: test(r==KErrNone); sl@0: r=TheFs.Delete(fname); sl@0: test(r==KErrNone); sl@0: } sl@0: sl@0: static void testShortNameAccessorFunctions() sl@0: // sl@0: // Test RFs::GetShortName(...) sl@0: // sl@0: { sl@0: test.Next(_L("Test short name accessor functions")); sl@0: sl@0: if(!gShortFileNamesSupported) sl@0: { sl@0: test.Printf(_L("Short Names are not supported!. Skipping...")); sl@0: return; sl@0: } sl@0: sl@0: sl@0: TBuf<64> sessionPath; sl@0: TInt r=TheFs.SessionPath(sessionPath); sl@0: test(r==KErrNone); sl@0: RFile f; sl@0: r=TheFs.MkDirAll(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\RANDOM.ENDBIT")); sl@0: test(r==KErrNone || r==KErrAlreadyExists); sl@0: r=f.Replace(TheFs,_L("LONGFILENAME.LONGEXT"),EFileWrite); sl@0: test(r==KErrNone); sl@0: f.Close(); sl@0: r=f.Replace(TheFs,_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\LONGFILENAME.LONGEXT"),EFileWrite); sl@0: test(r==KErrNone); sl@0: f.Close(); sl@0: r=f.Replace(TheFs,_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\BAD CHAR"),EFileWrite); sl@0: test(r==KErrNone); sl@0: f.Close(); sl@0: r=f.Replace(TheFs,_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\GoodCHAR.TXT"),EFileWrite); sl@0: test(r==KErrNone); sl@0: f.Close(); sl@0: TBuf<12> shortName1; sl@0: TBuf<12> shortName2; sl@0: TBuf<12> shortName3; sl@0: TBuf<12> shortName4; sl@0: TBuf<12> shortName5; sl@0: r=TheFs.GetShortName(_L("LONGFILENAME.LONGEXT"),shortName1); sl@0: test(r==KErrNone); sl@0: r=TheFs.GetShortName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\LONGFILENAME.LONGEXT"),shortName2); sl@0: test(r==KErrNone); sl@0: r=TheFs.GetShortName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\BAD CHAR"),shortName3); sl@0: test(r==KErrNone); sl@0: r=TheFs.GetShortName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\GOODCHAR.TXT"),shortName4); sl@0: test(r==KErrNone); sl@0: r=TheFs.GetShortName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY"),shortName5); sl@0: test(r==KErrNone); sl@0: sl@0: if(Is_Win32(TheFs, gDriveNum)) sl@0: { sl@0: test(shortName1==_L("LONGFI~1.LON")); sl@0: test(shortName2==_L("LONGFI~1.LON")); sl@0: test(shortName3==_L("BADCHA~1")); sl@0: test(shortName4.FindF(_L("GOODCHAR.TXT"))>=0); sl@0: test(shortName5==_L("MIDDLE~1")); sl@0: } sl@0: else if(!IsTestingLFFS()) sl@0: { sl@0: // LFFS short names not the same as VFAT ones sl@0: test(shortName1==_L("LONGFI~1.LON")); sl@0: test(shortName2==_L("LONGFI~1.LON")); sl@0: test(shortName3==_L("BAD_CHAR")); sl@0: test(shortName4.FindF(_L("GOODCHAR.TXT"))>=0); sl@0: test(shortName5==_L("MIDDLE~1")); sl@0: } sl@0: sl@0: TFileName longName1; sl@0: TFileName longName2; sl@0: TFileName longName3; sl@0: TFileName longName4; sl@0: TFileName longName5; sl@0: sl@0: if (Is_Win32(TheFs, gDriveNum)) sl@0: { sl@0: r=TheFs.GetLongName(_L("LONGFI~1.LON"),longName1); sl@0: test(r==KErrNone); sl@0: r=TheFs.GetLongName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\LONGFI~1.LON"),longName2); sl@0: test(r==KErrNone); sl@0: r=TheFs.GetLongName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\BADCHA~1"),longName3); sl@0: test(r==KErrNone); sl@0: r=TheFs.GetLongName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\GOODCHAR.TXT"),longName4); sl@0: test(r==KErrNone); sl@0: r=TheFs.GetLongName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE~1"),longName5); sl@0: test(r==KErrNone); sl@0: } sl@0: else if (!IsTestingLFFS()) sl@0: { sl@0: r=TheFs.GetLongName(_L("LONGFI~1.LON"),longName1); sl@0: test(r==KErrNone); sl@0: r=TheFs.GetLongName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\LONGFI~1.LON"),longName2); sl@0: test(r==KErrNone); sl@0: r=TheFs.GetLongName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\BAD_CHAR"),longName3); sl@0: test(r==KErrNone); sl@0: r=TheFs.GetLongName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\GOODCHAR.TXT"),longName4); sl@0: test(r==KErrNone); sl@0: r=TheFs.GetLongName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE~1"),longName5); sl@0: test(r==KErrNone); sl@0: } sl@0: else sl@0: { sl@0: // LFFS longname tests sl@0: r=TheFs.GetLongName(shortName1,longName1); sl@0: test(r==KErrNone); sl@0: r=TheFs.SetSessionPath(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-DIRECTORY\\LASTDIR\\")); sl@0: test(r==KErrNone); sl@0: r=TheFs.GetLongName(shortName2,longName2); sl@0: test(r==KErrNone); sl@0: r=TheFs.GetLongName(shortName3,longName3); sl@0: test(r==KErrNone); sl@0: r=TheFs.GetLongName(shortName4,longName4); sl@0: test(r==KErrNone); sl@0: r=TheFs.SetSessionPath(_L("\\F32-TST\\TFILE\\TOPLEVEL\\")); sl@0: test(r==KErrNone); sl@0: r=TheFs.GetLongName(shortName5,longName5); sl@0: test(r==KErrNone); sl@0: r=TheFs.SetSessionPath(sessionPath); sl@0: test(r==KErrNone); sl@0: } sl@0: sl@0: test(longName1==_L("LONGFILENAME.LONGEXT")); sl@0: test(longName2==_L("LONGFILENAME.LONGEXT")); sl@0: test(longName3==_L("BAD CHAR")); sl@0: test(longName4.FindF(_L("GOODCHAR.TXT"))>=0); sl@0: test(longName5==_L("MIDDLE-DIRECTORY")); sl@0: sl@0: r=TheFs.GetShortName(_L("XXX.YYY"),shortName1); sl@0: test(r==KErrNotFound); sl@0: r=TheFs.GetShortName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-YROTCERID\\LASTDIR\\BAD-CHAR"),shortName1); sl@0: test(r==KErrPathNotFound); sl@0: r=TheFs.GetLongName(_L("XXX.YYY"),longName1); sl@0: test(r==KErrNotFound); sl@0: r=TheFs.GetLongName(_L("\\F32-TST\\TFILE\\TOPLEVEL\\MIDDLE-YROTCERID\\LASTDIR\\BAD-CHAR"),longName1); sl@0: test(r==KErrPathNotFound); sl@0: sl@0: r=TheFs.Delete(_L("LONGFILENAME.LONGEXT")); sl@0: test(r==KErrNone); sl@0: sl@0: TEntry romEntry; sl@0: r=TheFs.Entry(_L("Z:\\System"),romEntry); sl@0: if (r==KErrNotReady) sl@0: { sl@0: test.Printf(_L("ERROR: No rom filesystem present")); sl@0: //test.Getch(); sl@0: //return; sl@0: } sl@0: test(r==KErrNone); sl@0: TBuf<64> romFileName=_L("Z:\\"); sl@0: romFileName.Append(romEntry.iName); sl@0: r=TheFs.GetShortName(romFileName,shortName1); sl@0: test(r==KErrNotSupported); sl@0: r=TheFs.GetLongName(_L("Z:\\system"),longName1); sl@0: test(r==KErrNotSupported); sl@0: } sl@0: sl@0: static void RmDir(const TDesC& aDirName) sl@0: // sl@0: // Remove a directory sl@0: // sl@0: { sl@0: CFileMan* fMan=CFileMan::NewL(TheFs); sl@0: test(fMan!=NULL); sl@0: TInt r=TheFs.SessionPath(gSessionPath); sl@0: test(r==KErrNone); sl@0: r=TheFs.CheckDisk(gSessionPath); sl@0: if (r!=KErrNone && r!=KErrNotSupported) sl@0: ReportCheckDiskFailure(r); sl@0: sl@0: TFileName removeDirName = gSessionPath; sl@0: removeDirName.Append(aDirName); sl@0: sl@0: fMan->Attribs(removeDirName, 0, KEntryAttReadOnly, 0, CFileMan::ERecurse); sl@0: r=fMan->RmDir(removeDirName); sl@0: test(r==KErrNone || r==KErrNotFound || r==KErrPathNotFound); sl@0: sl@0: delete fMan; sl@0: } sl@0: //--------------------------------------------- sl@0: //! @SYMTestCaseID PBASE-T_TFILE-0659 sl@0: //! @SYMTestType CT sl@0: //! @SYMREQ INC112803 sl@0: //! @SYMTestCaseDesc Tests that RFs::GetShortName() considers the file extension while generating sl@0: //! shortname from longname and applies ~num if applicable. sl@0: //! @SYMTestActions 1. Generates the shortname for the given filename. sl@0: //! 2. Validates the generated shortname against the original filename. sl@0: //! @SYMTestExpectedResults The operation completes with no error. Valid shortname is generated. sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestStatus Implemented sl@0: //--------------------------------------------- sl@0: static void TestINC112803() sl@0: { sl@0: sl@0: if(!gShortFileNamesSupported) sl@0: { sl@0: test.Printf(_L("TestINC112803 : Short names are not supported!\n")); sl@0: return; sl@0: } sl@0: sl@0: sl@0: TInt err =0; sl@0: _LIT(KOrigFileName,"\\F32-TST\\TFILE\\INC112803\\Private2\\101f875a\\2222.JARX"); sl@0: _LIT(KOrigFileShortName,"\\F32-TST\\TFILE\\INC112803\\Private2\\101f875a\\2222~1.JAR"); sl@0: _LIT(KDestinationFileName,"\\F32-TST\\TFILE\\INC112803\\Private2\\101f875a\\2222.JAR"); sl@0: sl@0: // Make sure the file does not already exist sl@0: RmDir(_L("INC112803\\")); sl@0: sl@0: // Create directories and the file sl@0: MakeDir(_L("\\F32-TST\\TFILE\\INC112803\\Private2\\101f875a\\")); sl@0: MakeFile(KOrigFileName,_L8("FILE PATH : \\F32-TST\\TFILE\\INC112803\\Private2\\101f875a\\")); sl@0: sl@0: // Check the generated shortname of the original file sl@0: TBuf<12> shortName; sl@0: err = TheFs.GetShortName(KOrigFileName, shortName); sl@0: test(err==KErrNone); sl@0: sl@0: // Validate the generated shorname against the original filename. sl@0: if (Is_Win32(TheFs, gDriveNum)) sl@0: { sl@0: test(shortName==_L("2222~1.JAR")); sl@0: } sl@0: else if(!IsTestingLFFS()) sl@0: { sl@0: // LFFS short names not the same as VFAT ones sl@0: test(shortName==_L("2222~1.JAR")); sl@0: } sl@0: sl@0: // Validate that the file "2222~1.JAR" can not be created as this is the shortname for "2222.JARX". sl@0: MakeFile(KOrigFileShortName,_L8("FILE PATH : \\F32-TST\\TFILE\\INC112803\\Private2\\101f875a\\")); sl@0: CheckFileExists(KOrigFileShortName, KErrNone, EFalse); sl@0: sl@0: err = TheFs.Rename(KOrigFileName,KDestinationFileName); sl@0: test(err==KErrNone); sl@0: sl@0: // Clean up before leaving sl@0: RmDir(_L("INC112803\\")); sl@0: } sl@0: sl@0: static void testIsFileOpen() sl@0: // sl@0: // Test the IsFileOpen method sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Test IsFileOpen")); sl@0: TBool answer; sl@0: TInt r=TheFs.IsFileOpen(_L("OPEN.FILE"),answer); sl@0: test(r==KErrNotFound || (r==KErrNone && answer==EFalse)); sl@0: RFile f; sl@0: r=f.Replace(TheFs,_L("OPEN.FILE"),EFileWrite); sl@0: test(r==KErrNone); sl@0: r=TheFs.IsFileOpen(_L("OPEN.FILE"),answer); sl@0: test(r==KErrNone); sl@0: test(answer!=EFalse); sl@0: f.Close(); sl@0: r=TheFs.IsFileOpen(_L("OPEN.FILE"),answer); sl@0: test(r==KErrNone); sl@0: test(answer==EFalse); sl@0: r=TheFs.Delete(_L("OPEN.FILE")); sl@0: test(r==KErrNone); sl@0: sl@0: RFile f2; sl@0: r=f2.Replace(TheFs,_L("AnotherOpen.File"),EFileWrite); sl@0: test(r==KErrNone); sl@0: r=TheFs.IsFileOpen(_L("AnotherOpen.File"),answer); sl@0: test(r==KErrNone); sl@0: test(answer!=EFalse); sl@0: r=f.Replace(TheFs,_L("OPEN.FILE"),EFileWrite); sl@0: test(r==KErrNone); sl@0: r=TheFs.IsFileOpen(_L("OPEN.FILE"),answer); sl@0: test(r==KErrNone); sl@0: test(answer!=EFalse); sl@0: f2.Close(); sl@0: r=TheFs.IsFileOpen(_L("OPEN.FILE"),answer); sl@0: test(r==KErrNone); sl@0: test(answer!=EFalse); sl@0: f.Close(); sl@0: r=TheFs.IsFileOpen(_L("OPEN.FILE"),answer); sl@0: test(r==KErrNone); sl@0: test(answer==EFalse); sl@0: r=TheFs.Delete(_L("AnotherOpen.File")); sl@0: test(r==KErrNone); sl@0: r=TheFs.Delete(_L("OPEN.FILE")); sl@0: test(r==KErrNone); sl@0: } sl@0: sl@0: static void testDeleteOpenFiles() sl@0: // sl@0: // Test opened files cannot be deleted sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Test opened files cannot be deleted")); sl@0: RFile f; sl@0: f.Close(); sl@0: TInt r=f.Replace(TheFs,_L("Open.File"),EFileWrite); sl@0: test(r==KErrNone); sl@0: r=TheFs.Delete(_L("OPEN.FILE")); sl@0: test(r==KErrInUse); sl@0: f.Close(); sl@0: f.Close(); sl@0: f.Close(); sl@0: r=TheFs.Delete(_L("Open.FILe")); sl@0: test(r==KErrNone); sl@0: sl@0: TFileName fileName; sl@0: r=f.Temp(TheFs,_L(""),fileName,EFileWrite); sl@0: test(r==KErrNone); sl@0: r=TheFs.Delete(fileName); sl@0: test(r==KErrInUse); sl@0: f.Close(); sl@0: r=TheFs.Delete(fileName); sl@0: test(r==KErrNone); sl@0: sl@0: MakeFile(_L("\\Documents\\TEstfile.txt")); sl@0: r=f.Open(TheFs,_L("\\Documents\\TEstfile.txt"),EFileWrite); sl@0: test(r==KErrNone); sl@0: r=TheFs.Delete(_L("\\Documents\\TEstfile.txt")); sl@0: test(r==KErrInUse); sl@0: r=TheFs.Delete(_L("\\documents\\TEstfile.txt")); sl@0: test(r==KErrInUse); sl@0: r=TheFs.Delete(_L("\\Documents.\\TEstfile.txt")); sl@0: test(r==KErrBadName); sl@0: r=TheFs.Delete(_L("\\documents.\\TEstfile.txt")); sl@0: test(r==KErrBadName); sl@0: r=TheFs.Delete(_L("\\Documents\\Testfile.txt")); sl@0: test(r==KErrInUse); sl@0: r=TheFs.Delete(_L("\\documents\\testfile.txt")); sl@0: test(r==KErrInUse); sl@0: r=TheFs.Delete(_L("\\Documents.\\TEstfile.TXT")); sl@0: test(r==KErrBadName); sl@0: r=TheFs.Delete(_L("\\docUMENTS.\\TESTFILE.TXT")); sl@0: test(r==KErrBadName); sl@0: f.Close(); sl@0: r=TheFs.Delete(_L("\\Documents\\TEstfile.TXT")); sl@0: test(r==KErrNone); sl@0: sl@0: MakeFile(_L("\\Documents\\Documents\\TEstfile.txt")); sl@0: r=f.Open(TheFs,_L("\\Documents\\Documents\\TEstfile.txt"),EFileWrite); sl@0: test(r==KErrNone); sl@0: r=TheFs.Delete(_L("\\Documents\\documents.\\TEstfile.txt")); sl@0: test(r==KErrBadName); sl@0: r=TheFs.Delete(_L("\\documents\\Documents.\\TEstfile.txt")); sl@0: test(r==KErrBadName); sl@0: r=TheFs.Delete(_L("\\Documents.\\documents\\TEstfile.txt")); sl@0: test(r==KErrBadName); sl@0: r=TheFs.Delete(_L("\\documents.\\Documents\\TEstfile.txt")); sl@0: test(r==KErrBadName); sl@0: r=TheFs.Delete(_L("\\Documents\\Documents\\Testfile.txt")); sl@0: test(r==KErrInUse); sl@0: r=TheFs.Delete(_L("\\documents\\documents\\testfile.txt")); sl@0: test(r==KErrInUse); sl@0: r=TheFs.Delete(_L("\\Documents.\\Documents.\\TEstfile.TXT")); sl@0: test(r==KErrBadName); sl@0: r=TheFs.Delete(_L("\\docUMENTS.\\docUMENTS.\\TESTFILE.TXT")); sl@0: test(r==KErrBadName); sl@0: sl@0: sl@0: r=TheFs.RmDir(_L("\\Documents\\")); sl@0: test(r==KErrInUse); sl@0: r=TheFs.RmDir(_L("\\documents\\")); sl@0: test(r==KErrInUse); sl@0: r=TheFs.RmDir(_L("\\Documents.\\")); sl@0: test(r==KErrBadName); sl@0: r=TheFs.RmDir(_L("\\documents.\\")); sl@0: test(r==KErrBadName); sl@0: r=TheFs.RmDir(_L("\\Documents\\documents\\")); sl@0: test(r==KErrInUse); sl@0: r=TheFs.RmDir(_L("\\documents\\documents.\\")); sl@0: test(r==KErrBadName); sl@0: r=TheFs.RmDir(_L("\\Documents.\\Documents\\")); sl@0: test(r==KErrBadName); sl@0: r=TheFs.RmDir(_L("\\documents.\\Documents.\\")); sl@0: test(r==KErrBadName); sl@0: r=TheFs.RmDir(_L("\\Documents\\TestFile.TXT")); sl@0: test(r==KErrInUse); sl@0: r=TheFs.RmDir(_L("\\documents\\TestFile")); sl@0: test(r==KErrInUse); sl@0: r=TheFs.RmDir(_L("\\Documents.\\Testfile.")); sl@0: test(r==KErrBadName); sl@0: r=TheFs.RmDir(_L("\\documents.\\t")); sl@0: test(r==KErrBadName); sl@0: f.Close(); sl@0: r=TheFs.Delete(_L("\\Documents\\documents\\TEstfile.TXT")); sl@0: test(r==KErrNone); sl@0: r=TheFs.RmDir(_L("\\Documents\\documents.\\")); sl@0: test(r==KErrBadName); sl@0: r=TheFs.RmDir(_L("\\Documents.\\")); sl@0: test(r==KErrBadName); sl@0: } sl@0: sl@0: static void testFileSeek() sl@0: // sl@0: // Test seeking sl@0: // sl@0: { sl@0: test.Next(_L("Test file seek")); sl@0: RFile f; sl@0: TInt r=f.Open(TheFs,_L("T_File.cpp"),EFileWrite); sl@0: test(r==KErrNone); sl@0: sl@0: TBuf8<20> text1;TInt pos1=0; sl@0: TBuf8<20> text2;TInt pos2=510; sl@0: TBuf8<20> text3;TInt pos3=900; sl@0: TBuf8<20> text4;TInt pos4=2010; sl@0: TBuf8<20> text5;TInt pos5=4999; sl@0: sl@0: r=f.Read(pos1,text1); sl@0: test(r==KErrNone); sl@0: r=f.Read(pos2,text2); sl@0: test(r==KErrNone); sl@0: r=f.Read(pos3,text3); sl@0: test(r==KErrNone); sl@0: r=f.Read(pos4,text4); sl@0: test(r==KErrNone); sl@0: r=f.Read(pos5,text5); sl@0: test(r==KErrNone); sl@0: sl@0: TBuf8<20> testBuf; sl@0: sl@0: r=f.Read(pos3,testBuf); sl@0: test(r==KErrNone); sl@0: test(testBuf==text3); sl@0: sl@0: r=f.Read(pos1,testBuf); sl@0: test(r==KErrNone); sl@0: test(testBuf==text1); sl@0: sl@0: r=f.Read(pos4,testBuf); sl@0: test(r==KErrNone); sl@0: test(testBuf==text4); sl@0: sl@0: r=f.Read(pos2,testBuf); sl@0: test(r==KErrNone); sl@0: test(testBuf==text2); sl@0: sl@0: r=f.Read(pos5,testBuf); sl@0: test(r==KErrNone); sl@0: test(testBuf==text5); sl@0: sl@0: r=f.Read(pos2,testBuf); sl@0: test(r==KErrNone); sl@0: test(testBuf==text2); sl@0: r=f.SetSize(1023); sl@0: test(r==KErrNone); sl@0: r=f.Read(pos2,testBuf); sl@0: test(r==KErrNone); sl@0: test(testBuf==text2); sl@0: r=f.SetSize(1024); sl@0: test(r==KErrNone); sl@0: r=f.Read(pos1,testBuf); sl@0: test(r==KErrNone); sl@0: test(testBuf==text1); sl@0: r=f.Read(pos2,testBuf); sl@0: test(r==KErrNone); sl@0: test(testBuf==text2); sl@0: sl@0: r=f.Read(pos1,testBuf); sl@0: test(r==KErrNone); sl@0: test(testBuf==text1); sl@0: r=f.SetSize(511); sl@0: test(r==KErrNone); sl@0: r=f.Read(pos1,testBuf); sl@0: test(r==KErrNone); sl@0: test(testBuf==text1); sl@0: r=f.SetSize(512); sl@0: test(r==KErrNone); sl@0: r=f.Read(pos1,testBuf); sl@0: test(r==KErrNone); sl@0: test(testBuf==text1); sl@0: f.Close(); sl@0: } sl@0: sl@0: static void testMoreFileSeek() sl@0: // sl@0: // Further test of RFile::Seek() sl@0: // sl@0: { sl@0: // Create a zero length file sl@0: RFile file; sl@0: TInt r=file.Replace(TheFs,_L("\\F32-TST\\TFILE\\seektest"),EFileRead|EFileWrite); sl@0: test(r==KErrNone); sl@0: r=file.SetSize(20); sl@0: test(r==KErrNone); sl@0: // Seek beyond the length of the file sl@0: TInt seekPos; sl@0: seekPos = 80; // Pick a likely offset sl@0: TInt err = file.Seek(ESeekEnd, seekPos); // and go there sl@0: test(err==KErrNone); sl@0: test(seekPos==20); // Somewhat non-intuitive? sl@0: sl@0: r=file.Write(_L8("A Devil's Haircut")); sl@0: test(r==KErrNone); sl@0: TInt newFileSize; sl@0: r=file.Size(newFileSize); sl@0: test(r==KErrNone); sl@0: sl@0: seekPos = 0; sl@0: err = file.Seek(ESeekCurrent, seekPos); // Find out where we ended up? sl@0: test(err==KErrNone); sl@0: test(seekPos==37); sl@0: sl@0: file.SetSize(512); sl@0: seekPos=513; sl@0: err=file.Seek(ESeekStart, seekPos); sl@0: test(err==KErrNone); sl@0: test(seekPos==513); sl@0: sl@0: err=file.Seek(ESeekEnd, seekPos); sl@0: test(err==KErrNone); sl@0: test(seekPos==512); sl@0: sl@0: seekPos=-530; sl@0: err=file.Seek(ESeekEnd, seekPos); sl@0: test(err==KErrNone); sl@0: test(seekPos==0); sl@0: sl@0: seekPos=-10; sl@0: err=file.Seek(ESeekEnd, seekPos); sl@0: test(err==KErrNone); sl@0: test(seekPos==502); sl@0: sl@0: seekPos=-10; sl@0: err=file.Seek(ESeekStart,seekPos); sl@0: test(err==KErrArgument); sl@0: test(seekPos==-10); sl@0: sl@0: seekPos=0; sl@0: err=file.Seek(ESeekEnd,seekPos); sl@0: test(err==KErrNone); sl@0: test(seekPos==512); sl@0: sl@0: file.Close(); sl@0: r=TheFs.Delete(_L("\\F32-TST\\TFILE\\seektest")); sl@0: test(r==KErrNone); sl@0: } sl@0: sl@0: static void testSetSize() sl@0: // sl@0: // Test setsize sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Test SetSize")); sl@0: RFile f1; sl@0: TInt i=0; sl@0: TInt r=f1.Replace(TheFs,_L("File.File"),EFileWrite); sl@0: test(r==KErrNone); sl@0: gBuf.SetLength(32); sl@0: for(i=0;i<32;i++) sl@0: gBuf[i]=(TUint8)i; sl@0: r=f1.Write(gBuf); sl@0: test(r==KErrNone); sl@0: gBuf.SetLength(1334); sl@0: for(i=64;i<1334+64;i++) sl@0: gBuf[i-64]=(TUint8)i; sl@0: r=f1.Write(30,gBuf); sl@0: r=f1.Read(30,gBuf,1000); sl@0: test(r==KErrNone); sl@0: test(gBuf[0]==64); sl@0: test(gBuf[1]==65); sl@0: test(gBuf[2]==66); sl@0: f1.Close(); sl@0: sl@0: test.Next(_L("Open a large file")); sl@0: r=f1.Replace(TheFs,_L("File.File"),EFileWrite); sl@0: test(r==KErrNone); sl@0: CheckDisk(); sl@0: r=f1.SetSize(131072); // 128K sl@0: test(r==KErrNone); sl@0: TBuf8<16> testData=_L8("testData"); sl@0: r=f1.Write(131060,testData); sl@0: test(r==KErrNone); sl@0: f1.Close(); sl@0: r=f1.Open(TheFs,_L("File.File"),EFileRead); sl@0: test(r==KErrNone); sl@0: TInt size; sl@0: r=f1.Size(size); sl@0: test(r==KErrNone); sl@0: test(size==131072); sl@0: TBuf8<16> testData2; sl@0: r=f1.Read(131060,testData2,8); sl@0: test(r==KErrNone); sl@0: test(testData==testData2); sl@0: f1.Close(); sl@0: TheFs.Delete(_L("File.file")); sl@0: CheckDisk(); sl@0: } sl@0: sl@0: static void testIsRomAddress() sl@0: { sl@0: RFile f; sl@0: TInt r=f.Open(TheFs, PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin)?_L("Z:\\Sys\\Bin\\eshell.exe"):_L("Z:\\System\\Bin\\eshell.exe"), EFileRead); sl@0: test(r==KErrNone); sl@0: TInt anAddress=0; sl@0: r=f.Seek(ESeekAddress, anAddress); sl@0: test(r==KErrNone); sl@0: #if !defined(__WINS__) sl@0: test(RFs::IsRomAddress((TAny *)anAddress)); // Always returns EFalse if WINS sl@0: #endif sl@0: test(RFs::IsRomAddress(NULL)==FALSE); sl@0: f.Close(); sl@0: } sl@0: sl@0: #include "../../../userlibandfileserver/fileserver/inc/message.h" sl@0: #include sl@0: sl@0: static void testMiscellaneousReportedBugs() sl@0: // sl@0: // Test bug reports, real or imaginary sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Miscellaneous tests")); sl@0: RFile f1; sl@0: TInt temp; sl@0: TInt r=f1.Replace(TheFs,_L("File.File"),EFileWrite); sl@0: test(r==KErrNone); sl@0: r=f1.Size(temp); sl@0: test(r==KErrNone); sl@0: test(temp==0); sl@0: TUint data=0; sl@0: TPtrC8 buf((TText8*)&data,1); sl@0: r=f1.Write(buf); sl@0: // r=f1.Write(_L("\0")); sl@0: test(r==KErrNone); sl@0: r=f1.Size(temp); sl@0: test(r==KErrNone); sl@0: test(temp==1); sl@0: temp=0; sl@0: r=f1.Seek(ESeekStart,temp); sl@0: test(r==KErrNone); sl@0: test(temp==0); sl@0: TBuf8<32> testBuf; sl@0: r=f1.Read(testBuf); sl@0: test(r==KErrNone); sl@0: test(testBuf==buf); sl@0: f1.Close(); sl@0: sl@0: class RHackFile : public RFile sl@0: { sl@0: public: sl@0: inline TInt SendReceive(TInt aFunction, const TIpcArgs& aArgs) const sl@0: { return RSubSessionBase::SendReceive(aFunction, aArgs); } sl@0: }; sl@0: sl@0: RHackFile f2; sl@0: f2.Open(TheFs, _L("File.File"), EFileRead); sl@0: test(r == KErrNone); sl@0: r = f2.SendReceive(/*47*/ EFsFileChangeMode, TIpcArgs(EFileRead | EFileWrite)); // <- must fail! sl@0: test(r == KErrArgument); sl@0: r = f2.Write(_L8("Hacked!")); // <- must fail! sl@0: test(r == KErrAccessDenied); sl@0: f2.Close(); sl@0: sl@0: r=TheFs.Delete(_L("File.FIle")); sl@0: test(r==KErrNone); sl@0: } sl@0: sl@0: static void testFileRename() sl@0: // sl@0: // Test rename sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Test rename")); sl@0: TBuf<64> name1=_L("asdfasdfasdfasfd.qwer"); sl@0: TBuf<64> name2=_L("File.xyz"); sl@0: TBuf<64> name3=_L("ASdfasdFasdfasfd.qwer"); sl@0: TBuf8<64> contents; sl@0: sl@0: TInt r; sl@0: RFile f1; sl@0: sl@0: //-- test renaming a file to a non-existing directory sl@0: r = TheFs.MkDir(_L("\\temp\\")); sl@0: test(r==KErrNone || r==KErrAlreadyExists); sl@0: sl@0: r = f1.Replace(TheFs, _L("\\temp\\file1"), 0); sl@0: test(r==KErrNone); sl@0: sl@0: r = f1.Rename(_L("\\temp\\temp\\file1")); sl@0: test(r == KErrPathNotFound); sl@0: sl@0: f1.Close(); sl@0: sl@0: sl@0: r=f1.Replace(TheFs,name2,EFileWrite); sl@0: test(r==KErrNone); sl@0: r=f1.Write(_L8("1234")); sl@0: test(r==KErrNone); sl@0: TInt len=CheckFileExists(name2,KErrNone); sl@0: test(len==4); sl@0: r=f1.Rename(name1); sl@0: test(r==KErrNone); sl@0: sl@0: r=f1.Read(0,contents); sl@0: test(r==KErrNone); sl@0: test(contents==_L8("1234")); sl@0: r=f1.Write(4,_L8("5678")); sl@0: test(r==KErrNone); sl@0: sl@0: len=CheckFileExists(name1,KErrNone); sl@0: test(len==8); sl@0: CheckFileExists(name2,KErrNotFound); sl@0: r=f1.Write(8,_L8("90")); sl@0: test(r==KErrNone); sl@0: f1.Close(); sl@0: len=CheckFileExists(name1,KErrNone); sl@0: test(len==10); sl@0: sl@0: test.Next(_L("Test can change case using rename")); sl@0: r=f1.Open(TheFs,name1,EFileRead|EFileWrite); sl@0: test(r==KErrNone); sl@0: r=f1.Rename(name3); sl@0: test(r==KErrNone); sl@0: CheckFileExists(name1,KErrNone,EFalse); sl@0: len=CheckFileExists(name3,KErrNone); sl@0: test(len==10); sl@0: f1.Close(); sl@0: CheckFileExists(name1,KErrNone,EFalse); sl@0: len=CheckFileExists(name3,KErrNone); sl@0: test(len==10); sl@0: sl@0: test.Next(_L("Test can rename to an identical filename")); sl@0: r=f1.Open(TheFs,name3,EFileRead|EFileWrite); sl@0: test(r==KErrNone); sl@0: r=f1.Rename(name3); sl@0: test(r==KErrNone); sl@0: len=CheckFileExists(name3,KErrNone); sl@0: test(len==10); sl@0: f1.Close(); sl@0: len=CheckFileExists(name3,KErrNone); sl@0: test(len==10); sl@0: sl@0: test.Next(_L("Test rename to a name containing a wildcard is rejected")); sl@0: r=f1.Open(TheFs,name3,EFileRead|EFileWrite); sl@0: test(r==KErrNone); sl@0: r=f1.Rename(_L("asdf*ASDF")); sl@0: test(r==KErrBadName); sl@0: r=f1.Rename(_L("asdf?AF")); sl@0: test(r==KErrBadName); sl@0: f1.Close(); sl@0: sl@0: r=f1.Open(TheFs,name3,EFileRead); sl@0: test(r==KErrNone); sl@0: r=f1.Read(contents); sl@0: test(r==KErrNone); sl@0: test(contents==_L8("1234567890")); sl@0: r=f1.Read(contents); sl@0: test(r==KErrNone); sl@0: test(contents.Length()==0); sl@0: f1.Close(); sl@0: sl@0: test.Next(_L("Check file date is retained")); sl@0: TDateTime dateTime(1995,(TMonth)10,19,23,0,0,0); sl@0: TTime oldTime(dateTime); sl@0: r=TheFs.SetEntry(name3,oldTime,0,0); sl@0: test(r==KErrNone); sl@0: r=f1.Open(TheFs,name3,EFileRead|EFileWrite); sl@0: test(r==KErrNone); sl@0: TTime check; sl@0: r=f1.Modified(check); sl@0: test(r==KErrNone); sl@0: test(check==oldTime); sl@0: sl@0: r=f1.Rename(_L("OldFile.Old")); sl@0: test(r==KErrNone); sl@0: sl@0: r=f1.Modified(check); sl@0: test(r==KErrNone); sl@0: test(check==oldTime); sl@0: r=TheFs.Modified(_L("oldfile.old"),check); sl@0: test(r==KErrNone); sl@0: test(check==oldTime); sl@0: f1.Close(); sl@0: r=TheFs.Modified(_L("oldfile.old"),check); sl@0: test(r==KErrNone); sl@0: test(check==oldTime); sl@0: } sl@0: sl@0: static void TestFileUids() sl@0: // sl@0: // Test uids in files sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Uids in files")); sl@0: TUidType uidData(TUid::Uid(1),TUid::Uid(1),TUid::Uid(1)); sl@0: MakeFile(_L("Tmp04005.$$$"),uidData,_L8("Some other data")); sl@0: TUidType uidData1(TUid::Uid(2),TUid::Uid(2),TUid::Uid(2)); sl@0: MakeFile(_L("Sketch(01)"),uidData1,_L8("A different sketch")); sl@0: sl@0: TEntry e; sl@0: TInt r=TheFs.Entry(_L("Tmp04005.$$$"),e); sl@0: test(r==KErrNone); sl@0: test(uidData==e.iType); sl@0: r=TheFs.Entry(_L("Sketch(01)"),e); sl@0: test(r==KErrNone); sl@0: test(uidData1==e.iType); sl@0: sl@0: test.Next(_L("Test replace preserves UIDs")); sl@0: r=TheFs.Replace(_L("Tmp04005.$$$"),_L("Sketch(01)")); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.Entry(_L("Tmp04005.$$$"),e); sl@0: test(r==KErrNotFound); sl@0: r=TheFs.Entry(_L("Sketch(01)"),e); sl@0: test(r==KErrNone); sl@0: test(uidData==e.iType); sl@0: } sl@0: sl@0: sl@0: static void TestMaxLengthFilenames() sl@0: // sl@0: // Test max length filenames can be created/deleted sl@0: // sl@0: { sl@0: sl@0: #if defined(__WINS__) sl@0: if (gSessionPath[0]=='C') sl@0: return; sl@0: #endif sl@0: sl@0: test.Next(_L("Test max length filenames")); sl@0: TFileName bigName; sl@0: CreateLongName(bigName,gSeed,255); sl@0: bigName[0]='\\'; sl@0: RFile f; sl@0: TInt r=f.Create(TheFs,bigName,EFileRead); sl@0: test(r==KErrBadName); sl@0: bigName.SetLength(254); sl@0: r=f.Create(TheFs,bigName,EFileRead); sl@0: test(r==KErrNone); sl@0: f.Close(); sl@0: sl@0: TInt count; sl@0: TFileName countedBigName=bigName; sl@0: // This loop may not reach the '\' character, or we will get a bad path. sl@0: for (count=0;count<('Z'-'A');count++) sl@0: { sl@0: countedBigName[2]=(TText)('A'+count); sl@0: r=f.Create(TheFs,countedBigName,EFileRead); sl@0: if (r==KErrDirFull) sl@0: { sl@0: r=TheFs.Delete(countedBigName); sl@0: test(r==KErrNotFound); sl@0: break; sl@0: } sl@0: if (r!=KErrNone) sl@0: test.Printf(_L("File create failed:%d"),r); sl@0: test(r==KErrNone); sl@0: f.Close(); sl@0: } sl@0: while(count--) sl@0: { sl@0: countedBigName[2]=(TText)('A'+count); sl@0: r=TheFs.Delete(countedBigName); sl@0: test(r==KErrNone); sl@0: } sl@0: sl@0: r=TheFs.Delete(bigName); sl@0: test(r==KErrNone); sl@0: sl@0: TFileName subDirFileName=_L("\\F32-TST\\TFILE"); sl@0: bigName.SetLength(241); sl@0: subDirFileName.Append(bigName); sl@0: r=f.Create(TheFs,subDirFileName,EFileRead); sl@0: test(r==KErrBadName); sl@0: subDirFileName.SetLength(254); sl@0: r=f.Create(TheFs,subDirFileName,EFileRead); sl@0: test(r==KErrNone); sl@0: f.Close(); sl@0: r=TheFs.Delete(subDirFileName); sl@0: test(r==KErrNone); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: static void testReadersWriters() sl@0: // sl@0: // Test EFileShareReadersOrWriters file sharing. sl@0: // sl@0: { sl@0: sl@0: test.Start(_L("Test EFileShareReadersOrWriters sharing")); sl@0: MakeFile(_L("TESTER")); sl@0: sl@0: // Open a file in EFileShareReadersOnly mode sl@0: RFile f1; sl@0: TInt r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly); sl@0: test(r==KErrNone); sl@0: sl@0: // Opening a share in EFileShareReadersOnly mode should succeed sl@0: RFile f2; sl@0: r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly); sl@0: test(r==KErrNone); sl@0: f2.Close(); sl@0: sl@0: // Opening a share in EFileShareReadersOrWriters mode with EFileRead access should succeed sl@0: r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead); sl@0: test(r==KErrNone); sl@0: f2.Close(); sl@0: sl@0: // Opening a share in EFileShareReadersOrWriters mode with EFileWrite access should succeed sl@0: r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileWrite); sl@0: test(r==KErrInUse); sl@0: sl@0: // Opening a share in EFileShareReadersOrWriters mode with EFileRead|EFileWrite access should succeed sl@0: r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead|EFileWrite); sl@0: test(r==KErrInUse); sl@0: sl@0: // Opening a share in EShareAny mode should fail sl@0: r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareAny); sl@0: test(r==KErrInUse); sl@0: sl@0: f1.Close(); sl@0: sl@0: ////////////////////// sl@0: sl@0: // Open a file in EFileShareReadersOrWriters mode for reading sl@0: r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead); sl@0: test(r==KErrNone); sl@0: sl@0: // Opening a share in EFileShareExclusive mode should fail sl@0: r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareExclusive); sl@0: test(r==KErrInUse); sl@0: sl@0: // Opening a share in EFileShareReadersOnly mode should succeed sl@0: // (the share doesn't care if the file is opened for reading or writing) sl@0: r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly); sl@0: test(r==KErrNone); sl@0: f2.Close(); sl@0: sl@0: // Opening a share in EFileShareReadersOnly mode with EFileRead accesss should succeed sl@0: r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead); sl@0: test(r==KErrNone); sl@0: f2.Close(); sl@0: sl@0: // Opening a share in EFileShareReadersOnly mode with EFileWrite accesss should succeed sl@0: r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileWrite); sl@0: test(r==KErrNone); sl@0: f2.Close(); sl@0: sl@0: // Opening a share in EFileShareReadersOnly mode with EFileRead|EFileWrite accesss should succeed sl@0: r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead|EFileWrite); sl@0: test(r==KErrNone); sl@0: f2.Close(); sl@0: sl@0: // Opening a share in EFileShareAny mode should succeed sl@0: r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareAny); sl@0: test(r==KErrNone); sl@0: f2.Close(); sl@0: sl@0: f1.Close(); sl@0: sl@0: ////////////////////// sl@0: sl@0: // Open a file in EFileShareReadersOrWriters mode for writing sl@0: r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileWrite); sl@0: test(r==KErrNone); sl@0: sl@0: // Opening a share in EFileShareExclusive mode should fail sl@0: r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareExclusive); sl@0: test(r==KErrInUse); sl@0: sl@0: // Opening a share in EFileShareReadersOnly mode should fail sl@0: r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly); sl@0: test(r==KErrInUse); sl@0: sl@0: // Opening a share in EFileShareReadersOrWriters mode with EFileRead access should succeed sl@0: r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead); sl@0: test(r==KErrNone); sl@0: f2.Close(); sl@0: sl@0: // Opening a share in EFileShareReadersOrWriters mode with EFileWrite access should succeed sl@0: r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileWrite); sl@0: test(r==KErrNone); sl@0: f2.Close(); sl@0: sl@0: // Opening a share in EFileShareReadersOrWriters mode with EFileRead|EFileWrite access should succeed sl@0: r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead|EFileWrite); sl@0: test(r==KErrNone); sl@0: f2.Close(); sl@0: sl@0: // Opening a share in EFileShareAny mode should succeed sl@0: r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareAny); sl@0: test(r==KErrNone); sl@0: f2.Close(); sl@0: sl@0: f1.Close(); sl@0: sl@0: ////////////////////////// sl@0: sl@0: // Open a file in EFileShareAny mode sl@0: r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareAny); sl@0: test(r==KErrNone); sl@0: sl@0: // Opening a share in EFileShareExclusive mode should fail sl@0: r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareExclusive); sl@0: test(r==KErrInUse); sl@0: sl@0: // Opening a share in EFileShareReadersOnly mode should fail sl@0: r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly); sl@0: test(r==KErrInUse); sl@0: sl@0: // Opening a share in EFileShareReadersOrWriters mode with EFileRead access should succeed sl@0: r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead); sl@0: test(r==KErrNone); sl@0: f2.Close(); sl@0: sl@0: // Opening a share in EFileShareReadersOrWriters mode with EFileWrite access should succeed sl@0: r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileWrite); sl@0: test(r==KErrNone); sl@0: f2.Close(); sl@0: sl@0: // Opening a share in EFileShareReadersOrWriters mode with EFileRead|EFileWrite access should succeed sl@0: r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead|EFileWrite); sl@0: test(r==KErrNone); sl@0: f2.Close(); sl@0: sl@0: // Opening a share in EFileShareAny mode with should succeed sl@0: r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareAny); sl@0: test(r==KErrNone); sl@0: f2.Close(); sl@0: sl@0: f1.Close(); sl@0: sl@0: ////////////////////// sl@0: sl@0: // Open a file in EFileShareReadersOrWriters mode for reading sl@0: r=f1.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead); sl@0: test(r==KErrNone); sl@0: sl@0: // Opening a share in EFileShareReadersOnly mode should succeed sl@0: // - The share should now be promoted to EFileShareReadersOnly mode sl@0: r=f2.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOnly); sl@0: test(r==KErrNone); sl@0: sl@0: TInt pass = 2; sl@0: while(pass--) sl@0: { sl@0: RFile f3; sl@0: // Opening a share in EFileShareReadersOnly mode with EFileRead accesss should succeed sl@0: r=f3.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead); sl@0: test(r==KErrNone); sl@0: f3.Close(); sl@0: sl@0: // Opening a share in EFileShareReadersOnly mode with EFileWrite accesss should fail sl@0: r=f3.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileWrite); sl@0: if(pass == 1) sl@0: { sl@0: // The share is promoted - should obey EFileShareReadersOnly rules sl@0: test(r==KErrInUse); sl@0: } sl@0: else sl@0: { sl@0: // The share is demoted - should obey EFileShareReadersOrWriters rules sl@0: test(r==KErrNone); sl@0: f3.Close(); sl@0: } sl@0: sl@0: // Opening a share in EFileShareReadersOnly mode with EFileRead|EFileWrite accesss should fail sl@0: r=f3.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareReadersOrWriters|EFileRead|EFileWrite); sl@0: if(pass == 1) sl@0: { sl@0: // The share is promoted - should obey EFileShareReadersOnly rules sl@0: test(r==KErrInUse); sl@0: } sl@0: else sl@0: { sl@0: // The share is demoted - should obey EFileShareReadersOrWriters rules sl@0: test(r==KErrNone); sl@0: f3.Close(); sl@0: } sl@0: sl@0: // Opening a share in EFileShareAny mode should fails sl@0: r=f3.Open(TheFs,_L("T_FILE.CPP"),EFileStreamText|EFileShareAny); sl@0: if(pass == 1) sl@0: { sl@0: // The share is promoted - should obey EFileShareReadersOnly rules sl@0: test(r==KErrInUse); sl@0: f2.Close(); sl@0: } sl@0: else sl@0: { sl@0: // The share is demoted - should obey EFileShareReadersOrWriters rules sl@0: test(r==KErrNone); sl@0: f3.Close(); sl@0: } sl@0: } sl@0: sl@0: f1.Close(); sl@0: sl@0: test.End(); sl@0: } sl@0: sl@0: sl@0: static void testINC070455() sl@0: // sl@0: // INC070455 - RFile.ChangeMode() panics sl@0: // sl@0: { sl@0: _LIT(KTestName, "Test INC070455 - RFile.ChangeMode() panics"); sl@0: test.Start(KTestName); sl@0: sl@0: sl@0: // To reproduce this defect, we need a filename of less than 10 characters. sl@0: // We cannot use the directories used by the rest of this test harness. sl@0: _LIT(KShortName, "C:\\file.txt"); sl@0: sl@0: sl@0: test.Next(_L("Create file...")); sl@0: RFile TheFile; sl@0: TInt r = TheFile.Create(TheFs, KShortName, EFileWrite); sl@0: test((KErrNone == r) || (KErrAlreadyExists == r)); sl@0: TheFile.Close(); sl@0: sl@0: sl@0: test.Next(_L("Re-open the file...")); sl@0: r = TheFile.Open(TheFs, KShortName, EFileRead | EFileShareExclusive); sl@0: test (KErrNone == r); sl@0: sl@0: sl@0: test.Next(_L("Change the file\'s mode...")); sl@0: r = TheFile.ChangeMode(EFileShareReadersOnly); sl@0: test (KErrNone == r); sl@0: TheFile.Close(); sl@0: sl@0: sl@0: test.Next(_L("Tidy up")); sl@0: r = TheFs.Delete(KShortName); sl@0: test (KErrNone == r); sl@0: sl@0: test.End(); sl@0: } sl@0: sl@0: sl@0: LOCAL_D TBuf8<0x80000> gLongBuf; sl@0: _LIT(KFileName, "\\zerolengthsourcedescriptortest.txt"); sl@0: sl@0: static void zeroSrcDesc() sl@0: { sl@0: gLongBuf.Zero(); sl@0: } sl@0: sl@0: static void setSrcDescLen() sl@0: { sl@0: gLongBuf.SetLength(0x80000); sl@0: } sl@0: sl@0: static void createTestFile(RFile& aFile) sl@0: { sl@0: TInt r = aFile.Create(TheFs, KFileName, EFileWrite); sl@0: test((KErrNone == r) || (KErrAlreadyExists == r)); sl@0: } sl@0: sl@0: static void removeTestFile(RFile& aFile) sl@0: { sl@0: aFile.Close(); sl@0: TInt r = TheFs.Delete(KFileName); sl@0: test (KErrNone == r); sl@0: } sl@0: sl@0: #ifdef _DEBUG sl@0: static TInt testWritePanic(TAny* aPtr) sl@0: { sl@0: RFile * ptr = (RFile *)aPtr; sl@0: TInt r=ptr->Write(gLongBuf,0x80000); sl@0: test (KErrNone == r); sl@0: return KErrNone; sl@0: } sl@0: #endif sl@0: static void testNegativeLengthToWrite() sl@0: // sl@0: // DEF091545 - Tests added to check the write function behaviour with Negative length sl@0: { sl@0: sl@0: test.Start(_L("Test RFile::Write variants with Negative Length parameter")); sl@0: sl@0: LOCAL_D TBuf8<0x100> gBuf; sl@0: RFile TheFile; sl@0: TInt r; sl@0: TRequestStatus status1(KRequestPending); sl@0: TRequestStatus status2(KRequestPending); sl@0: sl@0: // EXPORT_C TInt RFile::Write(const TDesC8& aDes,TInt aLength) sl@0: createTestFile(TheFile); sl@0: sl@0: r=TheFile.Write(gBuf, -1); sl@0: test(r==KErrArgument); sl@0: sl@0: removeTestFile(TheFile); sl@0: sl@0: // EXPORT_C void RFile::Write(const TDesC8& aDes,TInt aLength, TRequestStatus& aStatus) sl@0: createTestFile(TheFile); sl@0: TheFile.Write(gBuf,-1, status1); sl@0: User::WaitForRequest(status1); sl@0: test ( status1.Int() == KErrArgument); sl@0: sl@0: removeTestFile(TheFile); sl@0: sl@0: sl@0: sl@0: // EXPORT_C TInt RFile::Write(TInt aPos,const TDesC8& aDes,TInt aLength) sl@0: createTestFile(TheFile); sl@0: r = TheFile.Write(0,gBuf,-1); sl@0: test(r==KErrArgument); sl@0: removeTestFile(TheFile); sl@0: sl@0: sl@0: // EXPORT_C void RFile::Write(TInt aPos,const TDesC8& aDes, TInt aLength, TRequestStatus& aStatus) sl@0: createTestFile(TheFile); sl@0: TheFile.Write(0, gBuf,-1, status2); sl@0: User::WaitForRequest(status2); sl@0: test ( status2.Int() == KErrArgument); sl@0: removeTestFile(TheFile); sl@0: sl@0: test.End(); sl@0: sl@0: sl@0: sl@0: } sl@0: sl@0: static TInt testLockPanic(TAny* aPtr) sl@0: { sl@0: TInt aPos=128; sl@0: TInt aLen=-1; sl@0: RFile * ptr = (RFile *)aPtr; sl@0: TInt r=ptr->Lock(aPos, aLen); sl@0: test (KErrNone == r); sl@0: return KErrNone; sl@0: } sl@0: sl@0: static TInt testUnLockPanic(TAny* aPtr) sl@0: { sl@0: TInt aPos=128; sl@0: TInt aLen=-1; sl@0: RFile * ptr = (RFile *)aPtr; sl@0: TInt r=ptr->UnLock(aPos, aLen); sl@0: test (KErrNone == r); sl@0: return KErrNone; sl@0: } sl@0: sl@0: static TInt testSetSizePanic(TAny* aPtr) sl@0: { sl@0: TInt aSize=-1; sl@0: RFile * ptr = (RFile *)aPtr; sl@0: TInt r=ptr->SetSize(aSize); sl@0: test (KErrNone == r); sl@0: return KErrNone; sl@0: } sl@0: sl@0: static void testNegativeLength() sl@0: { sl@0: test.Start(_L("Test RFile::Lock, RFile::Unlock and RFile::SetSize with Negative Length parameter")); sl@0: sl@0: test(TheFs.ShareProtected() == KErrNone); sl@0: sl@0: RFile TheFile; sl@0: createTestFile(TheFile); sl@0: TRequestStatus status = KRequestPending; sl@0: sl@0: // launch call on separate thread as expected to panic sl@0: // Test Lock with a negative length sl@0: User::SetJustInTime(EFalse); sl@0: RThread t; sl@0: test(t.Create(_L("testLockPanic"), testLockPanic, KDefaultStackSize, 0x2000, 0x2000, &TheFile) == KErrNone); sl@0: t.Logon(status); sl@0: t.Resume(); sl@0: User::WaitForRequest(status); sl@0: User::SetJustInTime(ETrue); sl@0: test(t.ExitType() == EExitPanic); sl@0: test(t.ExitReason() == 17); sl@0: t.Close(); sl@0: sl@0: sl@0: // Test Unlock with a negative length sl@0: User::SetJustInTime(EFalse); sl@0: status = KRequestPending; sl@0: test(t.Create(_L("testUnLockPanic"), testUnLockPanic, KDefaultStackSize, 0x2000, 0x2000, &TheFile) == KErrNone); sl@0: t.Logon(status); sl@0: t.Resume(); sl@0: User::WaitForRequest(status); sl@0: test(t.ExitType() == EExitPanic); sl@0: test(t.ExitReason() == 18); sl@0: t.Close(); sl@0: User::SetJustInTime(ETrue); sl@0: sl@0: // Test SetSize with a negative length sl@0: User::SetJustInTime(EFalse); sl@0: status = KRequestPending; sl@0: test(t.Create(_L("testSetSizePanic"), testSetSizePanic, KDefaultStackSize, 0x2000, 0x2000, &TheFile) == KErrNone); sl@0: t.Logon(status); sl@0: t.Resume(); sl@0: User::WaitForRequest(status); sl@0: test(t.ExitType() == EExitPanic); sl@0: test(t.ExitReason() == 20); sl@0: t.Close(); sl@0: User::SetJustInTime(ETrue); sl@0: sl@0: removeTestFile(TheFile); sl@0: test.End(); sl@0: } sl@0: sl@0: static void testZeroLengthDescriptors() sl@0: // sl@0: // INC088416 - NAND thread crash when doing async writes to internal memory sl@0: // sl@0: // Test each variant of RFile::Write against zero length source descriptor arguements sl@0: { sl@0: test.Start(_L("Test RFile::Write variants with Zero Length Source Descriptor")); sl@0: sl@0: RFile TheFile; sl@0: TRequestStatus status(KRequestPending); sl@0: sl@0: sl@0: // EXPORT_C TInt RFile::Write(const TDesC8& aDes) PASS ZERO length descriptor sl@0: sl@0: createTestFile(TheFile); sl@0: sl@0: zeroSrcDesc(); sl@0: sl@0: test.Next(_L("Execute sync call RFile::Write(const TDesC8& aDes) with zero length aDes")); sl@0: TInt r=TheFile.Write(gLongBuf); sl@0: test(r==KErrNone); sl@0: sl@0: test.Printf(_L("Test case passed\n")); sl@0: sl@0: removeTestFile(TheFile); sl@0: sl@0: sl@0: // EXPORT_C void RFile::Write(const TDesC8& aDes,TRequestStatus& aStatus) PASS ZERO length descriptor sl@0: sl@0: createTestFile(TheFile); sl@0: sl@0: status = KRequestPending; sl@0: zeroSrcDesc(); sl@0: sl@0: test.Next(_L("Start async call RFile::Write(const TDesC8& aDes,TRequestStatus& aStatus) with zero length sDes")); sl@0: TheFile.Write(gLongBuf,status); sl@0: User::WaitForRequest(status); sl@0: test(status.Int()==KErrNone); sl@0: sl@0: test.Printf(_L("Test case passed\n")); sl@0: sl@0: removeTestFile(TheFile); sl@0: sl@0: sl@0: // EXPORT_C void RFile::Write(const TDesC8& aDes,TRequestStatus& aStatus) SCROBBLE descriptor to ZERO length during async write sl@0: sl@0: createTestFile(TheFile); sl@0: sl@0: status = KRequestPending; sl@0: setSrcDescLen(); sl@0: sl@0: test.Next(_L("Start async call RFile::Write(const TDesC8& aDes,TRequestStatus& aStatus)")); sl@0: TheFile.Write(gLongBuf,status); sl@0: test.Printf(_L("Zero source descriptor during async write\n")); sl@0: zeroSrcDesc(); sl@0: User::WaitForRequest(status); sl@0: test(status.Int()==KErrNone); sl@0: sl@0: test.Printf(_L("Test case passed\n")); sl@0: sl@0: removeTestFile(TheFile); sl@0: sl@0: sl@0: // EXPORT_C TInt RFile::Write(const TDesC8& aDes,TInt aLength) PASS ZERO length descriptor sl@0: sl@0: createTestFile(TheFile); sl@0: sl@0: status = KRequestPending; sl@0: zeroSrcDesc(); sl@0: sl@0: test.Next(_L("Execute sync call RFile::Write(const TDesC8& aDes,TInt aLength) with zero length aDes")); sl@0: #ifdef _DEBUG sl@0: // launch call on separate thread as expected to panic sl@0: User::SetJustInTime(EFalse); sl@0: status = KRequestPending; sl@0: RThread t; sl@0: test(t.Create(_L("testWritePanic"), testWritePanic, KDefaultStackSize, 0x2000, 0x2000, &TheFile) == KErrNone); sl@0: t.Logon(status); sl@0: t.Resume(); sl@0: User::WaitForRequest(status); sl@0: test(t.ExitType() == EExitPanic); sl@0: test(t.ExitReason() == 27); sl@0: t.Close(); sl@0: User::SetJustInTime(ETrue); sl@0: #else sl@0: sl@0: r=TheFile.Write(gLongBuf, 0x80000); sl@0: test(r==KErrNone); sl@0: #endif sl@0: sl@0: test.Printf(_L("Test case passed\n")); sl@0: sl@0: removeTestFile(TheFile); sl@0: sl@0: sl@0: // EXPORT_C void RFile::Write(const TDesC8& aDes,TInt aLength, TRequestStatus& aStatus) PASS ZERO length descriptor sl@0: sl@0: createTestFile(TheFile); sl@0: sl@0: status = KRequestPending; sl@0: zeroSrcDesc(); sl@0: sl@0: test.Next(_L("Start async call RFile::Write(const TDesC8& aDes, TInt aLength,TRequestStatus& aStatus) with zero length sDes")); sl@0: TheFile.Write(gLongBuf, 0x80000, status); ; sl@0: User::WaitForRequest(status); sl@0: test(status.Int()==KErrNone); sl@0: sl@0: test.Printf(_L("Test case passed\n")); sl@0: sl@0: removeTestFile(TheFile); sl@0: sl@0: sl@0: // EXPORT_C void RFile::Write(const TDesC8& aDes,TInt aLength, TRequestStatus& aStatus) SCROBBLE descriptor to ZERO length during async write sl@0: sl@0: createTestFile(TheFile); sl@0: sl@0: status = KRequestPending; sl@0: setSrcDescLen(); sl@0: sl@0: test.Next(_L("Start async call RFile::Write(const TDesC8& aDes, Int aLength,TRequestStatus& aStatus)")); sl@0: TheFile.Write(gLongBuf,0x80000, status); sl@0: test.Printf(_L("Zero source descriptor during async write\n")); sl@0: zeroSrcDesc(); sl@0: User::WaitForRequest(status); sl@0: test(status.Int()==KErrNone); sl@0: sl@0: test.Printf(_L("Test case passed\n")); sl@0: sl@0: removeTestFile(TheFile); sl@0: sl@0: sl@0: // EXPORT_C TInt RFile::Write(TInt aPos,const TDesC8& aDes) PASS ZERO length descriptor sl@0: sl@0: createTestFile(TheFile); sl@0: sl@0: zeroSrcDesc(); sl@0: sl@0: test.Next(_L("Execute sync call RFile::Write(TInt aPos, const TDesC8& aDes) with zero length aDes")); sl@0: r=TheFile.Write(0, gLongBuf); sl@0: test(r==KErrNone); sl@0: sl@0: test.Printf(_L("Test case passed\n")); sl@0: sl@0: removeTestFile(TheFile); sl@0: sl@0: sl@0: // EXPORT_C void RFile::Write(TInt aPos,const TDesC8& aDes,TRequestStatus& aStatus) PASS ZERO length descriptor sl@0: sl@0: createTestFile(TheFile); sl@0: sl@0: status = KRequestPending; sl@0: zeroSrcDesc(); sl@0: sl@0: test.Next(_L("Start async call RFile::Write(TInt aPos, const TDesC8& aDes, TRequestStatus& aStatus) with zero length sDes")); sl@0: TheFile.Write(0, gLongBuf, status); sl@0: User::WaitForRequest(status); sl@0: test(status.Int()==KErrNone); sl@0: sl@0: test.Printf(_L("Test case passed\n")); sl@0: sl@0: removeTestFile(TheFile); sl@0: sl@0: sl@0: // EXPORT_C void RFile::Write(TInt aPos,const TDesC8& aDes,TRequestStatus& aStatus) SCROBBLE descriptor to ZERO length during async write sl@0: sl@0: createTestFile(TheFile); sl@0: sl@0: status = KRequestPending; sl@0: setSrcDescLen(); sl@0: sl@0: test.Next(_L("Start async call RFile::Write(TInt aPos, const TDesC8& aDes, TRequestStatus& aStatus)")); sl@0: TheFile.Write(0, gLongBuf, status); sl@0: test.Printf(_L("Zero source descriptor during async write\n")); sl@0: zeroSrcDesc(); sl@0: User::WaitForRequest(status); sl@0: test(status.Int()==KErrNone); sl@0: sl@0: test.Printf(_L("Test case passed\n")); sl@0: sl@0: removeTestFile(TheFile); sl@0: sl@0: sl@0: // EXPORT_C TInt RFile::Write(TInt aPos,const TDesC8& aDes,TInt aLength) PASS ZERO length descriptor sl@0: sl@0: createTestFile(TheFile); sl@0: sl@0: zeroSrcDesc(); sl@0: sl@0: test.Next(_L("Execute sync call RFile::Write(TInt aPos, const TDesC8& aDes, TInt aLength) with zero length aDes")); sl@0: r=TheFile.Write(0, gLongBuf, 0x80000); sl@0: test(r==KErrNone); sl@0: sl@0: test.Printf(_L("Test case passed\n")); sl@0: sl@0: removeTestFile(TheFile); sl@0: sl@0: sl@0: // EXPORT_C void RFile::Write(TInt aPos,const TDesC8& aDes, TInt aLength, TRequestStatus& aStatus) PASS ZERO length descriptor sl@0: sl@0: createTestFile(TheFile); sl@0: sl@0: status = KRequestPending; sl@0: zeroSrcDesc(); sl@0: sl@0: test.Next(_L("Start async call RFile::Write(TInt aPos, const TDesC8& aDes, TInt aLength, TRequestStatus& aStatus) with zero length sDes")); sl@0: TheFile.Write(0, gLongBuf, 0x80000, status); sl@0: User::WaitForRequest(status); sl@0: test(status.Int()==KErrNone); sl@0: sl@0: test.Printf(_L("Test case passed\n")); sl@0: sl@0: removeTestFile(TheFile); sl@0: sl@0: sl@0: // EXPORT_C void RFile::Write(TInt aPos,const TDesC8& aDes, TInt aLength, TRequestStatus& aStatus) SCROBBLE descriptor to ZERO length during async write sl@0: sl@0: createTestFile(TheFile); sl@0: sl@0: status = KRequestPending; sl@0: setSrcDescLen(); sl@0: sl@0: test.Next(_L("Start async call RFile::Write(TInt aPos, const TDesC8& aDes, TInt aLength, TRequestStatus& aStatus")); sl@0: TheFile.Write(0, gLongBuf, 0x80000, status); sl@0: test.Printf(_L("Zero source descriptor during async write\n")); sl@0: zeroSrcDesc(); sl@0: User::WaitForRequest(status); sl@0: test(status.Int()==KErrNone); sl@0: sl@0: test.Printf(_L("Test case passed\n")); sl@0: sl@0: removeTestFile(TheFile); sl@0: sl@0: sl@0: test.End(); sl@0: } sl@0: sl@0: static void testReadBufferOverflow() sl@0: // sl@0: // Test each variant of RFile::Read when the specified extent to read is sl@0: // greater than the available buffer space sl@0: // sl@0: { sl@0: test.Start(_L("Test RFile::Read for oversized requests")); sl@0: sl@0: RFile file; sl@0: TInt r = file.Create(TheFs, KFileName, EFileRead); sl@0: test((KErrNone == r) || (KErrAlreadyExists == r)); sl@0: sl@0: TInt err = KErrNone; sl@0: TRequestStatus status(KRequestPending); sl@0: TBuf8<2> buf8; sl@0: sl@0: // EXPORT_C TInt RFile::Read(TDes8& aDes,TInt aLength) const sl@0: err = file.Read(buf8,5); sl@0: test(err==KErrOverflow); sl@0: err = KErrNone; sl@0: sl@0: // EXPORT_C void RFile::Read(TDes8& aDes,TInt aLength,TRequestStatus& aStatus) const sl@0: file.Read(buf8,5,status); sl@0: test(status.Int()==KErrOverflow); sl@0: status = KRequestPending; sl@0: sl@0: // EXPORT_C TInt RFile::Read(TInt aPos,TDes8& aDes,TInt aLength) const sl@0: err = file.Read(0,buf8,5); sl@0: test(err==KErrOverflow); sl@0: sl@0: // EXPORT_C void RFile::Read(TInt aPos,TDes8& aDes,TInt aLength,TRequestStatus& aStatus) const sl@0: file.Read(0,buf8,5,status); sl@0: test(status.Int()==KErrOverflow); sl@0: sl@0: removeTestFile(file); sl@0: test.End(); sl@0: } sl@0: sl@0: RSemaphore gSleepThread; sl@0: TFileName gLastTempFileName; sl@0: enum TTestDoCMode sl@0: { sl@0: EDoCPanic=1, sl@0: EDoCDeleteOnClose=2 sl@0: }; sl@0: sl@0: static TInt DeleteOnCloseClientThread(TAny* aMode) sl@0: { sl@0: TTestDoCMode testMode = *(TTestDoCMode*)&aMode; sl@0: TUint fileMode=EFileRead; sl@0: RFs fs; sl@0: RFile file; sl@0: sl@0: TInt r=fs.Connect(); sl@0: test(r==KErrNone); sl@0: r=fs.SetSessionPath(gSessionPath); sl@0: test(r==KErrNone); sl@0: if (testMode & EDoCDeleteOnClose) sl@0: fileMode|=EDeleteOnClose; sl@0: r=file.Temp(fs,_L(""),gLastTempFileName,fileMode); sl@0: test(r==KErrNone); sl@0: // Signal controlling thread and pause for panic where requested sl@0: // by caller. sl@0: if (testMode & EDoCPanic) sl@0: { sl@0: gSleepThread.Signal(); sl@0: User::After(10000000); sl@0: } sl@0: file.Close(); sl@0: if (!(testMode & EDoCPanic)) sl@0: gSleepThread.Signal(); sl@0: fs.Close(); sl@0: return KErrNone; sl@0: } sl@0: sl@0: static void TestDeleteOnClose() sl@0: // sl@0: // Test RFile::Temp delete on close behaviour sl@0: // sl@0: { sl@0: test.Start(_L("RFile::Temp default file close behaviour")); sl@0: sl@0: gSleepThread.CreateLocal(0); sl@0: RThread clientThread; sl@0: RFile file; sl@0: RFile file2; sl@0: TFileName filename =_L("DoCFile.tst"); sl@0: TInt r; sl@0: sl@0: // sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID PBASE-t_file-0804 sl@0: //! @SYMTestType UT sl@0: //! @SYMTestCaseDesc Verifying the original behaviour of RFile::Temp() sl@0: //! @SYMPREQ CR1266 sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestActions sl@0: //! 1. Test thread creates a file with DeleteOnClose flag unset and sl@0: //! exits normally. sl@0: //! The main test body attempts to delete the resulting temporary sl@0: //! file. sl@0: //! sl@0: //! @SYMTestExpectedResults sl@0: //! 1. The temporary file is successfully created and deleted. sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: r=clientThread.Create(_L("DeleteOnCloseClientThread 1"),DeleteOnCloseClientThread,KDefaultStackSize,0x2000,0x2000,(TAny*)0); sl@0: test(r==KErrNone); sl@0: clientThread.Resume(); sl@0: gSleepThread.Wait(); sl@0: r=TheFs.Delete(gLastTempFileName); sl@0: test(r==KErrNone); sl@0: clientThread.Close(); sl@0: sl@0: // sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID PBASE-t_file-0805 sl@0: //! @SYMTestType UT sl@0: //! @SYMTestCaseDesc Verifying the Delete on Close behaviour of RFile::Temp() sl@0: //! @SYMPREQ CR1266 sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestActions sl@0: //! 1. Test thread creates a file with DeleteOnClose flag set and sl@0: //! exits normally. sl@0: //! The main test body attempts to delete the resulting temporary sl@0: //! file. sl@0: //! sl@0: //! @SYMTestExpectedResults sl@0: //! 1. The temporary file is successfully created and automatically sl@0: //! deleted upon close. The subsequent attempted file deletion sl@0: //! by the main test body should fail with KErrNotFound. sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: test.Next(_L("RFile::Temp EDeleteOnClose behaviour")); sl@0: r=clientThread.Create(_L("DeleteOnCloseClientThread 2"),DeleteOnCloseClientThread,KDefaultStackSize,0x2000,0x2000,(TAny*)EDoCDeleteOnClose); sl@0: test(r==KErrNone); sl@0: clientThread.Resume(); sl@0: gSleepThread.Wait(); sl@0: r=TheFs.Delete(gLastTempFileName); sl@0: test(r==KErrNotFound); sl@0: clientThread.Close(); sl@0: sl@0: // sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID PBASE-t_file-0806 sl@0: //! @SYMTestType UT sl@0: //! @SYMTestCaseDesc Verifying the original, panic behaviour of RFile::Temp() sl@0: //! @SYMPREQ CR1266 sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestActions sl@0: //! 1. Test thread creates a file with DeleteOnClose flag unset and sl@0: //! is paniced by the main test body. sl@0: //! The main test body attempts to delete the resulting temporary sl@0: //! file. sl@0: //! sl@0: //! @SYMTestExpectedResults sl@0: //! 1. The temporary file is successfully created and deleted. sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: test.Next(_L("RFile::Temp default panic behaviour")); sl@0: r=clientThread.Create(_L("DeleteOnCloseClientThread 3"),DeleteOnCloseClientThread,KDefaultStackSize,0x2000,0x2000,(TAny*)EDoCPanic); sl@0: test(r==KErrNone); sl@0: clientThread.Resume(); sl@0: gSleepThread.Wait(); sl@0: User::SetJustInTime(EFalse); sl@0: clientThread.Panic(_L("Panic temp file thread #3"),KErrGeneral); sl@0: User::SetJustInTime(ETrue); sl@0: CLOSE_AND_WAIT(clientThread); sl@0: FsBarrier(); sl@0: r=TheFs.Delete(gLastTempFileName); sl@0: test(r==KErrNone); sl@0: sl@0: // sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID PBASE-t_file-0807 sl@0: //! @SYMTestType UT sl@0: //! @SYMTestCaseDesc Verifying the Delete on Close, panic behaviour of RFile::Temp() sl@0: //! @SYMPREQ CR1266 sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestActions sl@0: //! 1. Test thread creates a file with DeleteOnClose flag set and sl@0: //! is paniced by the main test body. sl@0: //! The main test body attempts to delete the resulting temporary sl@0: //! file. sl@0: //! sl@0: //! @SYMTestExpectedResults sl@0: //! 1. The temporary file is successfully created and automatically sl@0: //! deleted upon close. The subsequent attempted file deletion sl@0: //! by the main test body should fail with KErrNotFound. sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: test.Next(_L("RFile::Temp EDeleteOnClose panic behaviour")); sl@0: r=clientThread.Create(_L("DeleteOnCloseClientThread 4"),DeleteOnCloseClientThread,KDefaultStackSize,0x2000,0x2000,(TAny*)(EDoCPanic|EDoCDeleteOnClose)); sl@0: test(r==KErrNone); sl@0: clientThread.Resume(); sl@0: gSleepThread.Wait(); sl@0: User::SetJustInTime(EFalse); sl@0: clientThread.Panic(_L("Panic temp file thread #4"),KErrGeneral); sl@0: User::SetJustInTime(ETrue); sl@0: CLOSE_AND_WAIT(clientThread); sl@0: FsBarrier(); sl@0: r=TheFs.Delete(gLastTempFileName); sl@0: test(r==KErrNotFound); sl@0: sl@0: // sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID PBASE-t_file-0808 sl@0: //! @SYMTestType UT sl@0: //! @SYMTestCaseDesc Verifying RFile::Create() supports Delete On Close. sl@0: //! @SYMPREQ CR1266 sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestActions sl@0: //! 1. Test creates a file with DeleteOnClose flag set and sl@0: //! then closes the file. sl@0: //! 2. Test attempts to delete the file. sl@0: //! sl@0: //! @SYMTestExpectedResults sl@0: //! 1. The file creation should succeed. sl@0: //! 2. The file deletion should fail with KErrNotFound. sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: test.Next(_L("RFile::Create EDeleteOnClose behaviour")); sl@0: r=file.Create(TheFs,_L("DoC5"),EFileRead|EFileWrite|EDeleteOnClose); sl@0: test(r==KErrNone); sl@0: file.Close(); sl@0: r=TheFs.Delete(filename); sl@0: test(r==KErrNotFound); sl@0: sl@0: // sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID PBASE-t_file-0809 sl@0: //! @SYMTestType UT sl@0: //! @SYMTestCaseDesc Verifying Delete On Close with multiple subsessions. sl@0: //! @SYMPREQ CR1266 sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestActions sl@0: //! 1. Test creates a file with DeleteOnClose and FileShareAny flags sl@0: //! set, opens the file a second time with the FileShareAny flag set sl@0: //! and then closes the first file handle. sl@0: //! 2. Test attempts to delete the file. sl@0: //! 3. The second file handle is closed and the test attempts to delete sl@0: //! the file. sl@0: //! sl@0: //! @SYMTestExpectedResults sl@0: //! 1. The file create and file open should succeed. sl@0: //! 2. The file deletion should fail with KErrInUse. sl@0: //! 3. The file deletion should fail with KErrNotFound. sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: test.Next(_L("DoC 6 - Multiple subsessions")); sl@0: r=file.Create(TheFs,filename,EFileShareAny|EFileRead|EFileWrite|EDeleteOnClose); sl@0: test(r==KErrNone); sl@0: r=file2.Open(TheFs,filename,EFileShareAny|EFileRead|EFileWrite); sl@0: test(r==KErrNone); sl@0: file.Close(); sl@0: test(r==KErrNone); sl@0: r=TheFs.Delete(filename); sl@0: test(r==KErrInUse); sl@0: file2.Close(); sl@0: r=TheFs.Delete(filename); sl@0: test(r==KErrNotFound); sl@0: sl@0: // sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID PBASE-t_file-0810 sl@0: //! @SYMTestType UT sl@0: //! @SYMTestCaseDesc Verifying Delete On Close with preexisting file. sl@0: //! @SYMPREQ CR1266 sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestActions sl@0: //! 1. Test creates and closes a file, then attempts to create the same sl@0: //! file with Delete on Close set. sl@0: //! sl@0: //! @SYMTestExpectedResults sl@0: //! 1. The second create should fail with KErrAlreadyExists. sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: test.Next(_L("RFile::Create existing file behaviour")); sl@0: r=file.Create(TheFs,filename,EFileRead|EFileWrite); sl@0: test(r==KErrNone); sl@0: file.Close(); sl@0: r=file.Create(TheFs,filename,EFileRead|EFileWrite|EDeleteOnClose); sl@0: test(r==KErrAlreadyExists); sl@0: sl@0: // sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID PBASE-t_file-0811 sl@0: //! @SYMTestType UT sl@0: //! @SYMTestCaseDesc Verifying existing file cannot be opened with delete on close set. sl@0: //! @SYMPREQ CR1266 sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestActions sl@0: //! 1. Test attempts to open an existing file with delete on close set. sl@0: //! sl@0: //! @SYMTestExpectedResults sl@0: //! 1. The open should fail with KErrArgument. sl@0: //--------------------------------------------------------------------------------------------------------------------- sl@0: test.Next(_L("RFile::Open EDeleteOnClose flag validation")); sl@0: r=file.Open(TheFs,filename,EFileRead|EFileWrite|EDeleteOnClose); sl@0: test(r==KErrArgument); sl@0: r=TheFs.Delete(filename); sl@0: test(r==KErrNone); sl@0: sl@0: gSleepThread.Close(); sl@0: test.End(); sl@0: } sl@0: sl@0: //-------------------------------------------------------------- sl@0: /** sl@0: Test that flushing dirty file cache does not affect file attributes and time. sl@0: This test shall pass disregarding if there is file cache or not. sl@0: sl@0: */ sl@0: void TestFileAttributesAndCacheFlushing() sl@0: { sl@0: test.Next(_L("Test that file cache flushing does not affect the file attributes.")); sl@0: if(Is_Win32(TheFs, gDriveNum)) sl@0: { sl@0: test.Printf(_L("This test doesn't work on Win32 FS, skipping!\n")); sl@0: return; sl@0: } sl@0: sl@0: _LIT(KFile, "\\file1"); sl@0: sl@0: TInt nRes; sl@0: TEntry entry; sl@0: TheFs.Delete(KFile); sl@0: sl@0: //-- 1. create test file sl@0: nRes = CreateEmptyFile(TheFs, KFile, 33); sl@0: test(nRes == KErrNone); sl@0: sl@0: //-- 2. open it for write sl@0: RFile file; sl@0: nRes = file.Open(TheFs, KFile, EFileWrite); sl@0: test(nRes == KErrNone); sl@0: sl@0: //-- 3. write a couple of bytes there. This must cause 'Archive' attribute set sl@0: nRes = file.Write(0, _L8("a")); sl@0: test(nRes == KErrNone); sl@0: nRes = file.Write(10, _L8("b")); sl@0: test(nRes == KErrNone); sl@0: sl@0: nRes = TheFs.Entry(KFile, entry); sl@0: test(nRes == KErrNone); sl@0: sl@0: test(entry.IsArchive()); //-- 'A' attribute must be set. sl@0: sl@0: //-- the file cache (if present) is dirty now. Dirty data timer starts to tick. sl@0: //-- 4. set new file attributes (w/o 'A') and creation time sl@0: const TUint newAtt = KEntryAttSystem ; sl@0: nRes = file.SetAtt(newAtt, ~newAtt & KEntryAttMaskSupported); sl@0: test(nRes == KErrNone); sl@0: sl@0: TTime newTime; sl@0: nRes = newTime.Set(_L("19970310:101809.000000")); sl@0: test(nRes == KErrNone); sl@0: nRes = file.SetModified(newTime); sl@0: test(nRes == KErrNone); sl@0: sl@0: //-- 5. wait 5 seconds. file server shall flush dirty data during this period. sl@0: User::After(5*K1Sec); sl@0: sl@0: //-- 6. check that attributes haven't chanded because of flush sl@0: nRes = file.Flush(); //-- this will flush attributes to the media sl@0: test(nRes == KErrNone); sl@0: sl@0: nRes = TheFs.Entry(KFile, entry); sl@0: test(nRes == KErrNone); sl@0: sl@0: test(entry.iAtt == newAtt); sl@0: test(entry.iModified.DateTime().Year() == 1997); sl@0: test(entry.iModified.DateTime().Month() == 3); sl@0: test(entry.iModified.DateTime().Day() == 10); sl@0: sl@0: //-- 7. write some data and ensure that 'A' attribute is set now and 'modified' time updated sl@0: nRes = file.Write(12, _L8("c")); sl@0: test(nRes == KErrNone); sl@0: sl@0: file.Close(); //-- this will flush attributes to the media sl@0: sl@0: nRes = TheFs.Entry(KFile, entry); sl@0: test(nRes == KErrNone); sl@0: test(entry.iAtt == (newAtt | KEntryAttArchive)); sl@0: test(entry.iModified.DateTime().Year() != 1997); sl@0: sl@0: sl@0: sl@0: } sl@0: sl@0: /** sl@0: Testing access to the very last bytes in the maximal (for FAT32) file size. sl@0: This test must pass regardless of write caching configuration. sl@0: */ sl@0: void TestMaxFileSize() sl@0: { sl@0: test.Next(_L("test maximal file size on FAT32\n")); sl@0: sl@0: #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API sl@0: sl@0: if(!Is_Fat32(TheFs, gDriveNum)) sl@0: { sl@0: test.Printf(_L("This test requires FAT32! skipping.\n")); sl@0: return; sl@0: } sl@0: sl@0: TInt nRes; sl@0: sl@0: //-- check disk space, it shall be > 4G sl@0: TVolumeInfo volInfo; sl@0: nRes = TheFs.Volume(volInfo, gDriveNum); sl@0: test(nRes == KErrNone); sl@0: sl@0: const TUint32 KMaxFAT32FileSize = 0xFFFFFFFF; // 4GB-1 sl@0: sl@0: if(volInfo.iFree <= KMaxFAT32FileSize) sl@0: { sl@0: test.Printf(_L("Not enough space for 4GB file! skipping.\n")); sl@0: return; sl@0: } sl@0: sl@0: _LIT(KFileName, "\\huge_file"); sl@0: TBuf8<10> buf(10); sl@0: RFile64 file64; sl@0: sl@0: //-- 1. create 4GB-1 file sl@0: //-- this file has enabled write caching by default sl@0: test.Printf(_L("creating maximal length file, size = 0x%x\n"),KMaxFAT32FileSize); sl@0: nRes = file64.Replace(TheFs, KFileName, EFileWrite); sl@0: test(nRes == KErrNone); sl@0: sl@0: const TInt64 fileSize = KMaxFAT32FileSize; sl@0: sl@0: nRes = file64.SetSize(fileSize); sl@0: test(nRes == KErrNone); sl@0: sl@0: test.Printf(_L("seeking to the file end...\n")); sl@0: TInt64 filePos = 0; sl@0: nRes = file64.Seek(ESeekEnd, filePos); sl@0: test(nRes == KErrNone); sl@0: sl@0: sl@0: test.Printf(_L("test writing to the last bytes of the file (rel pos addressing) \n")); sl@0: sl@0: //-- 1. writing using relative position sl@0: filePos = -1; sl@0: nRes = file64.Seek(ESeekEnd, filePos); sl@0: test(nRes == KErrNone); sl@0: test(filePos == fileSize-1); sl@0: sl@0: nRes = file64.Write(_L8("z")); //-- write 1 byte a pos 0xFFFFFFFE, this is the last allowed position of the FAT32 file sl@0: test(nRes == KErrNone); sl@0: sl@0: nRes = file64.Write(_L8("x")); //-- write 1 byte a pos 0xFFFFFFFF, beyond the max. allowed file size, this shall fail sl@0: test(nRes == KErrNotSupported); sl@0: sl@0: nRes = file64.Flush(); sl@0: test(nRes == KErrNone); sl@0: sl@0: //-- 1.1 check the result by reading data using rel. pos sl@0: filePos = -1; sl@0: nRes = file64.Seek(ESeekEnd, filePos); sl@0: test(nRes == KErrNone); sl@0: test(filePos == fileSize-1); sl@0: sl@0: test.Printf(_L("reading 1 byte at pos: 0x%x\n"), filePos); sl@0: nRes = file64.Read(buf, 1); //-- read 1 byte a pos 0xFFFFFFFE, this is the last allowed position of the FAT32 file sl@0: test(nRes == KErrNone); sl@0: test(buf.Length() == 1 && buf[0]=='z'); sl@0: sl@0: nRes = file64.Read(buf, 1); //-- read 1 byte a pos 0xFFFFFFFF, beyond the max. allowed file size, this shall fail sl@0: test(nRes == KErrNone); sl@0: test(buf.Length() == 0); sl@0: sl@0: file64.Close(); sl@0: sl@0: test.Printf(_L("test writing to the last bytes of the file (absolute pos addressing) \n")); sl@0: //-- 2. writing using absolute position sl@0: nRes = file64.Open(TheFs, KFileName, EFileWrite); sl@0: test(nRes == KErrNone); sl@0: sl@0: filePos = fileSize-1; sl@0: sl@0: nRes = file64.Write(filePos-2, _L8("0"), 1); //-- write 1 byte a pos 0xFFFFFFFC sl@0: test(nRes == KErrNone); sl@0: sl@0: nRes = file64.Write(filePos, _L8("a"), 1); //-- write 1 byte a pos 0xFFFFFFFE, this is the last allowed position of the FAT32 file sl@0: test(nRes == KErrNone); sl@0: sl@0: nRes = file64.Write(filePos+1, _L8("b"), 1); //-- write 1 byte a pos 0xFFFFFFFF, beyond the max. allowed file size, this shall fail sl@0: test(nRes == KErrNotSupported); sl@0: sl@0: nRes = file64.Flush(); sl@0: test(nRes == KErrNone); sl@0: sl@0: //-- 1.1 check the result by reading data absolute rel. position sl@0: sl@0: nRes = file64.Read(filePos-2, buf, 1); //-- read 1 byte a pos 0xFFFFFFFD sl@0: test(nRes == KErrNone); sl@0: test(buf.Length() == 1 && buf[0]=='0'); sl@0: sl@0: nRes = file64.Read(filePos, buf, 1); //-- read 1 byte a pos 0xFFFFFFFE, this is the last allowed position of the FAT32 file sl@0: test(nRes == KErrNone); sl@0: test(buf.Length() == 1 && buf[0]=='a'); sl@0: sl@0: nRes = file64.Read(filePos+1, buf, 1); //-- read 1 byte a pos 0xFFFFFFFF, beyond the max. allowed file size sl@0: test(nRes == KErrNone); sl@0: test(buf.Length() == 0); sl@0: sl@0: nRes = file64.Read(filePos+2, buf, 1); //buf.Len must be 0 sl@0: test(nRes == KErrNone); sl@0: test(buf.Length() == 0); sl@0: sl@0: file64.Close(); sl@0: sl@0: test.Printf(_L("deleting the huge file.\n")); sl@0: nRes = TheFs.Delete(KFileName); sl@0: test(nRes == KErrNone); sl@0: sl@0: #else sl@0: sl@0: test.Printf(_L("RFile64 is not supported! Skipping.\n")); sl@0: sl@0: #endif //SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API sl@0: sl@0: } sl@0: sl@0: sl@0: //-------------------------------------------------------------- sl@0: sl@0: void CallTestsL() sl@0: { sl@0: sl@0: //-- set up console output sl@0: F32_Test_Utils::SetConsole(test.Console()); sl@0: sl@0: TInt nRes=TheFs.CharToDrive(gDriveToTest, gDriveNum); sl@0: test(nRes==KErrNone); sl@0: sl@0: PrintDrvInfo(TheFs, gDriveNum); sl@0: sl@0: //-- FAT Supports short file names sl@0: if(Is_Fat(TheFs, gDriveNum)) sl@0: gShortFileNamesSupported = ETrue; sl@0: sl@0: if(Is_Win32(TheFs, gDriveNum)) sl@0: {//-- find out if this is NTFS and if it supports short names (this feature can be switched OFF) sl@0: sl@0: _LIT(KLongFN, "\\this is a long file name"); sl@0: nRes = CreateEmptyFile(TheFs, KLongFN, 10); sl@0: test(nRes==KErrNone); sl@0: sl@0: TBuf<12> shortName; sl@0: nRes = TheFs.GetShortName(KLongFN, shortName); sl@0: gShortFileNamesSupported = (nRes == KErrNone); sl@0: sl@0: nRes = TheFs.Delete(KLongFN); sl@0: test(nRes==KErrNone); sl@0: sl@0: DeleteTestDirectory(); sl@0: } sl@0: else sl@0: { sl@0: nRes = FormatDrive(TheFs, gDriveNum, ETrue); sl@0: test(nRes==KErrNone); sl@0: } sl@0: sl@0: CreateTestDirectory(_L("\\F32-TST\\TFILE\\")); sl@0: sl@0: testFileRename(); sl@0: testSetSize(); sl@0: CopyFileToTestDirectory(); sl@0: testFileSeek(); sl@0: testMoreFileSeek(); sl@0: CopyFileToTestDirectory(); sl@0: testFileText(); sl@0: testFileTextEndRecord(); sl@0: testDeleteOpenFiles(); sl@0: testFileAttributes(); sl@0: testFileNames(); sl@0: testShare(); sl@0: testReadersWriters(); sl@0: testReadFile(); sl@0: testMultipleReadFile(); sl@0: testWriteFile(); sl@0: testChangeMode(); sl@0: testShortNameAccessorFunctions(); sl@0: testIsFileOpen(); sl@0: testMiscellaneousReportedBugs(); sl@0: testIsRomAddress(); sl@0: TestFileUids(); sl@0: TestMaxLengthFilenames(); sl@0: testINC070455(); sl@0: TestINC112803(); sl@0: testZeroLengthDescriptors(); sl@0: testNegativeLengthToWrite(); sl@0: testNegativeLength(); sl@0: testReadBufferOverflow(); sl@0: TestDeleteOnClose(); sl@0: TestFileAttributesAndCacheFlushing(); sl@0: TestMaxFileSize(); sl@0: sl@0: DeleteTestDirectory(); sl@0: } sl@0: