sl@0: // Copyright (c) 1998-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 "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: sl@0: const TInt KTestCleanupStack=0x20; sl@0: sl@0: // This is a path specification and should not be used as is sl@0: _LIT(KFileLocationSpec, "Z:\\STOR-TST\\T_FBUF.DAT"); sl@0: const TUint8* KTestData=_S8("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"); sl@0: const TUint8* KTestDataLong=_S8("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0"); sl@0: const TUint8* KTestData10Chars = _S8("0123456789"); sl@0: sl@0: const TInt KTestLength=36; sl@0: const TInt KTestTotal=KTestLength*(KTestLength+1); sl@0: const TPtrC8 KTestDes(KTestData,KTestLength); sl@0: const TPtrC8 KTestDesLong(KTestDataLong,KTestLength+1); sl@0: const TInt KTestFileBufSize=7; sl@0: const TInt KTestWriteBufSize=5; sl@0: const TInt KTestReadBufSize=3; sl@0: const TInt KTestSkipBufSize=2; sl@0: const TInt KTestCopyBufSize=1; sl@0: sl@0: LOCAL_D CTrapCleanup* TheTrapCleanup; sl@0: LOCAL_D RTest test(_L("t_storfbuf")); sl@0: LOCAL_D RFs TheFs; sl@0: LOCAL_D TFileName TheTempFile; sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-STORE-CT-1136 sl@0: @SYMTestCaseDesc Writing to a stream buffer test sl@0: @SYMTestPriority High sl@0: @SYMTestActions Tests for RWriteStream::WriteL() function sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: LOCAL_C void testWriteL(RWriteStream& aStream) sl@0: { sl@0: test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1136 Writing... ")); sl@0: for (TInt i=0;i<=KTestLength;++i) sl@0: { sl@0: aStream.WriteL(KTestDes,i); sl@0: aStream.WriteL(&KTestData[i],KTestLength-i); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-STORE-CT-1137 sl@0: @SYMTestCaseDesc Reading from a stream buffer test sl@0: @SYMTestPriority High sl@0: @SYMTestActions Tests for RReadStream::ReadL() function sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: LOCAL_C void testReadL(RReadStream& aStream) sl@0: { sl@0: test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1137 Reading... ")); sl@0: for (TInt i=KTestLength;i>=0;--i) sl@0: { sl@0: TBuf8 buf; sl@0: aStream.ReadL(buf,i); sl@0: test(buf.Length()==i); sl@0: buf.SetMax(); sl@0: aStream.ReadL(&buf[i],KTestLength-i); sl@0: buf.SetLength(KTestLength); sl@0: test(buf==KTestDes); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-STORE-CT-1138 sl@0: @SYMTestCaseDesc Skipping data on a stream buffer test. sl@0: @SYMTestPriority High sl@0: @SYMTestActions Tests skipping data while reading from a stream sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: LOCAL_C void testSkipL(RReadStream& aStream) sl@0: { sl@0: test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1138 Skipping... ")); sl@0: for (TInt i=0;i<=KTestLength;++i) sl@0: { sl@0: aStream.ReadL(i); sl@0: aStream.ReadL(KTestLength-i); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-STORE-CT-1139 sl@0: @SYMTestCaseDesc Tests a stream buffer is at end-of-file. sl@0: @SYMTestPriority High sl@0: @SYMTestActions Tests for end of file while reading from a stream buffer sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: LOCAL_C void testEofL(RReadStream& aStream) sl@0: { sl@0: test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1139 At end ")); sl@0: TUint8 b; sl@0: test(aStream.Source()->ReadL(&b,1)==0); sl@0: } sl@0: sl@0: // sl@0: // Test copying from one stream to another. sl@0: // sl@0: LOCAL_C void testCopyL(RWriteStream& aWriteStream,RReadStream& aReadStream) sl@0: { sl@0: test.Next(_L("Copying")); sl@0: for (TInt i=KTestLength;i>=0;--i) sl@0: { sl@0: aWriteStream.WriteL(aReadStream,i); sl@0: aReadStream.ReadL(aWriteStream,KTestLength-i); sl@0: } sl@0: } sl@0: sl@0: // sl@0: // Test writing to a stream buffer. sl@0: // sl@0: LOCAL_C void testWriteL(MStreamBuf& aBuf) sl@0: { sl@0: RWriteStream stream(&aBuf); sl@0: testWriteL(stream); sl@0: } sl@0: sl@0: // sl@0: // Test reading from a stream buffer. sl@0: // sl@0: LOCAL_C void testReadL(MStreamBuf& aBuf) sl@0: { sl@0: RReadStream stream(&aBuf); sl@0: testReadL(stream); sl@0: } sl@0: sl@0: // sl@0: // Test skipping data on a stream buffer. sl@0: // sl@0: LOCAL_C void testSkipL(MStreamBuf& aBuf) sl@0: { sl@0: RReadStream stream(&aBuf); sl@0: testSkipL(stream); sl@0: } sl@0: sl@0: // sl@0: // Test a stream buffer is at end-of-file. sl@0: // sl@0: LOCAL_C void testEofL(MStreamBuf& aBuf) sl@0: { sl@0: RReadStream stream(&aBuf); sl@0: testEofL(stream); sl@0: } sl@0: sl@0: // sl@0: // Test copying from one stream buffer to another. sl@0: // sl@0: LOCAL_C void testCopyL(MStreamBuf& aSink,MStreamBuf& aSource) sl@0: { sl@0: RWriteStream out(&aSink); sl@0: RReadStream in(&aSource); sl@0: testCopyL(out,in); sl@0: } sl@0: /** sl@0: @SYMTestCaseID PDS-STORE-CT-4027 sl@0: @SYMTestCaseDesc Writing to a stream buffer test sl@0: @SYMTestPriority High sl@0: @SYMTestActions Validate the MStreamBuf Write API sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMDEF DEF135804 sl@0: */ sl@0: LOCAL_C void testStreamBufWriteL(MStreamBuf& aBuf) sl@0: { sl@0: test.Next(_L(" @SYMTestCaseID:PDS-STORE-CT-4027 Writing... ")); sl@0: TRequestStatus status; sl@0: aBuf.Write(KTestDes,status); sl@0: User::WaitForRequest(status); sl@0: sl@0: aBuf.SeekL(aBuf.EWrite,EStreamBeginning,0); sl@0: aBuf.WriteL(KTestDes,status); sl@0: User::WaitForRequest(status); sl@0: sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID PDS-STORE-CT-4026 sl@0: @SYMTestCaseDesc Reading from a stream buffer test sl@0: @SYMTestPriority High sl@0: @SYMTestActions Validate the MStreamBuf Read API sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMDEF DEF135804 sl@0: */ sl@0: LOCAL_C void testStreamBufReadL(MStreamBuf& aBuf) sl@0: { sl@0: test.Next(_L(" @SYMTestCaseID:PDS-STORE-CT-4026 Reading... ")); sl@0: TRequestStatus status; sl@0: sl@0: TBuf8 buf; sl@0: aBuf.Read(buf, KTestLength, status); sl@0: User::WaitForRequest(status); sl@0: test(buf.Length()==KTestLength); sl@0: test(buf==KTestDes); sl@0: sl@0: aBuf.SeekL(aBuf.ERead,EStreamBeginning,0); sl@0: aBuf.ReadL(buf, status); sl@0: User::WaitForRequest(status); sl@0: test(buf.Length()== KTestLength+1); sl@0: test(buf==KTestDesLong); sl@0: sl@0: aBuf.SeekL(aBuf.ERead,EStreamBeginning,0); sl@0: aBuf.Read(buf, status); sl@0: User::WaitForRequest(status); sl@0: test(buf.Length()== KTestLength+1); sl@0: test(buf==KTestDesLong); sl@0: sl@0: } sl@0: /** sl@0: @SYMTestCaseID SYSLIB-STORE-CT-1140 sl@0: @SYMTestCaseDesc Write to a file buffer test. sl@0: @SYMTestPriority High sl@0: @SYMTestActions Tests for writing to an attached file,a replaced file,a temporary file,an opened file sl@0: Tests for replacing an existing file,test for deleting a file. sl@0: Tests for writing to a new file buffer after the deletion of old file. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: LOCAL_C void testWriteL() sl@0: { sl@0: test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1140 Writing to attached file ")); sl@0: sl@0: sl@0: TDriveUnit drive(static_cast(RFs::GetSystemDrive())); sl@0: TParse parse; sl@0: parse.Set(drive.Name(), &KFileLocationSpec, NULL); sl@0: sl@0: sl@0: sl@0: RFile file; sl@0: if (file.Replace(TheFs,parse.NameAndExt(),EFileWrite)!=KErrNone) sl@0: test.Panic(_L("Replacing file")); sl@0: RFileBuf rbuf(KTestWriteBufSize); sl@0: RFile file2 = file;//Keep a copy in file2, because Attach() will clear the passed RFile parameter sl@0: rbuf.Attach(file); sl@0: rbuf.Detach(); sl@0: rbuf.Reattach(file2); sl@0: testStreamBufWriteL(rbuf); sl@0: rbuf.SynchL(); sl@0: rbuf.Close(); sl@0: if (TheFs.Delete(parse.NameAndExt())!=KErrNone) sl@0: test.Panic(_L("Deleting file")); sl@0: sl@0: if (file.Replace(TheFs,parse.NameAndExt(),EFileWrite)!=KErrNone) sl@0: test.Panic(_L("Replacing file")); sl@0: RFileBuf buf(KTestWriteBufSize); sl@0: buf.Attach(file); sl@0: testWriteL(buf); sl@0: buf.SynchL(); sl@0: buf.Reset(KTestFileBufSize); sl@0: test(buf.SizeL()==KTestTotal); sl@0: test(buf.SeekL(buf.EWrite,EStreamBeginning,KTestTotal/2)==KStreamBeginning+KTestTotal/2); sl@0: testWriteL(buf); sl@0: buf.Close(); sl@0: // sl@0: test.Next(_L("Writing to replaced file")); sl@0: test(buf.Replace(TheFs,parse.NameAndExt(),EFileWrite)==KErrNone); sl@0: testWriteL(buf); sl@0: buf.SynchL(); sl@0: buf.File().Close(); sl@0: buf.Detach(); sl@0: // sl@0: test.Next(_L("Writing to temp file")); sl@0: test(buf.Temp(TheFs,parse.DriveAndPath(),TheTempFile,EFileWrite)==KErrNone); sl@0: testWriteL(buf); sl@0: buf.SynchL(); sl@0: buf.File().Close(); sl@0: buf.Close(); sl@0: // sl@0: test.Next(_L("Writing to opened file")); sl@0: test(buf.Open(TheFs,parse.NameAndExt(),EFileRead|EFileWrite)==KErrNone); sl@0: testWriteL(buf); sl@0: // sl@0: test.Next(_L("Failing to create existing file")); sl@0: test(buf.Create(TheFs,TheTempFile,EFileWrite)==KErrAlreadyExists); sl@0: // sl@0: test.Next(_L("Write overtaking read mark")); sl@0: test(buf.SeekL(buf.ERead,KTestLength)==KStreamBeginning+KTestLength); sl@0: RReadStream in(&buf); sl@0: in.ReadL(1); sl@0: test(buf.TellL(buf.ERead)==KStreamBeginning+KTestLength+1); sl@0: test(buf.SeekL(buf.EWrite,EStreamBeginning)==KStreamBeginning); sl@0: testWriteL(buf); sl@0: buf.Close(); sl@0: if (TheFs.Delete(parse.NameAndExt())!=KErrNone) sl@0: test.Panic(_L("Deleting file")); sl@0: // sl@0: test.Next(_L("Writing to created file")); sl@0: test(buf.Create(TheFs,parse.NameAndExt(),EFileWrite)==KErrNone); sl@0: testWriteL(buf); sl@0: buf.SynchL(); sl@0: buf.Close(); sl@0: sl@0: sl@0: } sl@0: /** sl@0: @SYMTestCaseID SYSLIB-STORE-CT-1141 sl@0: @SYMTestCaseDesc Reading from a file buffer test. sl@0: @SYMTestPriority High sl@0: @SYMTestActions Tests for reading from a file buffer.Tests for panic while opening a file. sl@0: Tests for reading from opened file,and a temporary file. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: LOCAL_C void testReadL() sl@0: { sl@0: test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1141 Reading from attached file ")); sl@0: sl@0: TParsePtrC parse(KFileLocationSpec); sl@0: sl@0: RFile file; sl@0: if (file.Open(TheFs,parse.NameAndExt(),EFileRead)!=KErrNone) sl@0: test.Panic(_L("Opening file")); sl@0: RFileBuf buf(KTestReadBufSize); sl@0: buf.Attach(file); sl@0: test(buf.SeekL(buf.ERead,EStreamBeginning,KTestTotal)==KStreamBeginning+KTestTotal); sl@0: testEofL(buf); sl@0: test(buf.SeekL(buf.ERead,EStreamBeginning)==KStreamBeginning); sl@0: testReadL(buf); sl@0: testEofL(buf); sl@0: buf.SynchL(); sl@0: buf.Reset(KTestFileBufSize); sl@0: buf.SeekL(buf.ERead|buf.EWrite,KStreamBeginning); sl@0: testReadL(buf); sl@0: testEofL(buf); sl@0: buf.SynchL(); sl@0: buf.Reset(KTestFileBufSize); sl@0: buf.SeekL(buf.ERead|buf.EWrite,KStreamBeginning); sl@0: testStreamBufReadL(buf); sl@0: buf.Close(); sl@0: buf.Close(); sl@0: // sl@0: test.Next(_L("Reading from opened file")); sl@0: test(buf.Open(TheFs,parse.NameAndExt(),EFileRead|EFileWrite)==KErrNone); sl@0: test(buf.SeekL(buf.ERead,EStreamEnd)==KStreamBeginning+KTestTotal); sl@0: testEofL(buf); sl@0: test(buf.SeekL(buf.ERead,EStreamEnd,-KTestTotal)==KStreamBeginning); sl@0: testReadL(buf); sl@0: testEofL(buf); sl@0: // sl@0: test.Next(_L("Read overtaking write mark")); sl@0: test(buf.SeekL(buf.EWrite,KTestLength)==KStreamBeginning+KTestLength); sl@0: RWriteStream out(&buf); sl@0: out.WriteL(KTestData,1); sl@0: test(buf.TellL(buf.EWrite)==KStreamBeginning+KTestLength+1); sl@0: test(buf.SeekL(buf.ERead,EStreamBeginning)==KStreamBeginning); sl@0: testReadL(buf); sl@0: testEofL(buf); sl@0: buf.Close(); sl@0: // sl@0: test.Next(_L("Reading from temp file")); sl@0: test(buf.Open(TheFs,TheTempFile,EFileRead)==KErrNone); sl@0: test(buf.SeekL(buf.ERead,EStreamMark,KTestTotal)==KStreamBeginning+KTestTotal); sl@0: testEofL(buf); sl@0: test(buf.SeekL(buf.ERead,-KTestTotal)==KStreamBeginning); sl@0: testReadL(buf); sl@0: testEofL(buf); sl@0: buf.Close(); sl@0: } sl@0: /** sl@0: @SYMTestCaseID SYSLIB-STORE-CT-1142 sl@0: @SYMTestCaseDesc Tests for skipping on a file buffer. sl@0: @SYMTestPriority High sl@0: @SYMTestActions Tests for skipping data while reading.Test for end of file error sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: LOCAL_C void testSkipL() sl@0: { sl@0: test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1142 Skipping using small transfers ")); sl@0: sl@0: TParsePtrC parse(KFileLocationSpec); sl@0: sl@0: RFileBuf buf(KTestSkipBufSize); sl@0: test(buf.Open(TheFs,parse.NameAndExt(),EFileRead)==KErrNone); sl@0: testSkipL(buf); sl@0: testEofL(buf); sl@0: buf.SynchL(); sl@0: buf.Reset(KTestFileBufSize); sl@0: buf.SeekL(buf.ERead|buf.EWrite,KStreamBeginning); sl@0: testSkipL(buf); sl@0: testEofL(buf); sl@0: buf.Close(); sl@0: // sl@0: test.Next(_L("Skipping using a single big transfer")); sl@0: test(buf.Open(TheFs,parse.NameAndExt(),EFileRead)==KErrNone); sl@0: RReadStream in(&buf); sl@0: in.ReadL(KTestTotal); sl@0: testEofL(buf); sl@0: buf.Close(); sl@0: } sl@0: /** sl@0: @SYMTestCaseID SYSLIB-STORE-CT-1143 sl@0: @SYMTestCaseDesc Tests for copying within a single file buffer sl@0: @SYMTestPriority High sl@0: @SYMTestActions Tests for copying using a different buffer sizes. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: LOCAL_C void testCopyL() sl@0: { sl@0: test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1143 Copying using small transfers ")); sl@0: sl@0: TParsePtrC parse(KFileLocationSpec); sl@0: sl@0: RFileBuf buf(KTestCopyBufSize); sl@0: test(buf.Open(TheFs,TheTempFile,EFileRead|EFileWrite)==KErrNone); sl@0: testCopyL(buf,buf); sl@0: testEofL(buf); sl@0: buf.SynchL(); sl@0: buf.Reset(KTestFileBufSize); sl@0: buf.SeekL(buf.ERead,KStreamBeginning); sl@0: testCopyL(buf,buf); sl@0: buf.SeekL(buf.ERead,KStreamBeginning); sl@0: testReadL(buf); sl@0: testReadL(buf); sl@0: testEofL(buf); sl@0: buf.Close(); sl@0: // sl@0: test.Next(_L("Copying using a single big transfer")); sl@0: test(buf.Open(TheFs,parse.NameAndExt(),EFileRead|EFileWrite)==KErrNone); sl@0: RWriteStream out(&buf); sl@0: RReadStream in(&buf); sl@0: in.ReadL(out,KTestTotal); sl@0: testEofL(buf); sl@0: buf.SeekL(buf.ERead|buf.EWrite,KStreamBeginning); sl@0: out.WriteL(in,KTestTotal); sl@0: testEofL(buf); sl@0: buf.SeekL(buf.ERead|buf.EWrite,KStreamBeginning); sl@0: testReadL(buf); sl@0: testEofL(buf); sl@0: buf.Close(); sl@0: // sl@0: test.Next(_L("Copying until end of file")); sl@0: test(buf.Open(TheFs,parse.NameAndExt(),EFileRead|EFileWrite)==KErrNone); sl@0: in.ReadL(out); sl@0: testEofL(buf); sl@0: buf.SeekL(buf.ERead|buf.EWrite,KStreamBeginning); sl@0: out.WriteL(in); sl@0: testEofL(buf); sl@0: buf.SeekL(buf.ERead|buf.EWrite,KStreamBeginning); sl@0: testReadL(buf); sl@0: testEofL(buf); sl@0: buf.Close(); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-STORE-UT-4005 sl@0: @SYMTestCaseDesc DEF118202 - STORE component, RFileBuf, truncate, file position set incorrectly. sl@0: The test creates an RFileBuf object and writes 30 bytes to the underlying file then sl@0: commits. The file size is checked and should be 30 bytes. sl@0: Then the test writes to the file another 20 bytes, commits and sets the file size to sl@0: be 30 bytes. Then the test checks that the file size is really 30 bytes using sl@0: the RFielBuf::SizeL() function. sl@0: @SYMTestPriority High sl@0: @SYMTestActions DEF118202 - STORE component, RFileBuf, truncate, file position set incorrectly. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMDEF DEF118202 sl@0: */ sl@0: LOCAL_C void DEF118202L() sl@0: { sl@0: test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-UT-4005 DEF118202 - STORE component, RFileBuf, truncate, file position set incorrectly ")); sl@0: sl@0: TParsePtrC parse(KFileLocationSpec); sl@0: sl@0: RFileBuf buf; sl@0: CleanupClosePushL(buf); sl@0: if(buf.Replace(TheFs, parse.NameAndExt(), EFileWrite) != KErrNone) sl@0: test.Panic(_L("Replacing file")); sl@0: TInt size0 = buf.SizeL(); sl@0: test(size0 == 0); sl@0: sl@0: buf.WriteL(KTestData10Chars, 10); sl@0: buf.WriteL(KTestData10Chars, 10); sl@0: buf.WriteL(KTestData10Chars, 10); sl@0: buf.SynchL(); sl@0: TInt size1 = buf.SizeL(); sl@0: sl@0: buf.WriteL(KTestData10Chars, 10); sl@0: buf.WriteL(KTestData10Chars, 10); sl@0: buf.SynchL(); sl@0: sl@0: buf.SetSizeL(30); sl@0: buf.SynchL(); sl@0: TInt size2 = buf.SizeL(); sl@0: sl@0: CleanupStack::PopAndDestroy(&buf); sl@0: if (TheFs.Delete(parse.NameAndExt()) != KErrNone) sl@0: test.Panic(_L("Deleting file")); sl@0: sl@0: test(size1 == size2); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID PDS-STORE-CT-4017 sl@0: @SYMTestCaseDesc Operation read / write sl@0: @SYMTestPriority High sl@0: @SYMTestActions Reading and writing RFileBuf using protected API. sl@0: @SYMTestExpectedResults Data written must equal data read. sl@0: @SYMDEF DEF135804 sl@0: */ sl@0: sl@0: class RFileBufNext: public RFileBuf sl@0: { sl@0: public: sl@0: TInt DoReadL(TDes8& aDes,TInt aMaxLength,TRequestStatus& aStatus) sl@0: { sl@0: return RFileBuf::DoReadL(aDes,aMaxLength,aStatus); sl@0: } sl@0: TInt DoWriteL(const TDesC8& aDes,TInt aMaxLength,TRequestStatus& aStatus) sl@0: { sl@0: return RFileBuf::DoWriteL(aDes,aMaxLength,aStatus); sl@0: } sl@0: TInt Avail(TArea anArea) const sl@0: { sl@0: return TStreamBuf::Avail(anArea); sl@0: } sl@0: TUint8* End(TArea anArea) const sl@0: { sl@0: return TStreamBuf::End(anArea); sl@0: } sl@0: void SetEnd(TArea anArea,TUint8* anEnd) sl@0: { sl@0: TStreamBuf::SetEnd(anArea, anEnd); sl@0: } sl@0: }; sl@0: sl@0: LOCAL_C void testReadWriteL() sl@0: { sl@0: test.Next(_L("@SYMTestCaseID PDS-STORE-CT-4017")); sl@0: _LIT(KFileStore2, "c:\\STOR-TST\\T_FILESTORE.DAT"); sl@0: _LIT8(KTestTextBuf, "Ala ma kota, Ola ma psa a osa lata."); sl@0: RFileBufNext fbuf; sl@0: RFs fs; sl@0: test( fs.Connect() == KErrNone ); sl@0: fs.Delete(KFileStore2); sl@0: test( fbuf.Create(fs, KFileStore2, EFileWrite ) == KErrNone ); sl@0: TRequestStatus status; sl@0: TRAPD(err, fbuf.DoWriteL(KTestTextBuf(),KTestTextBuf().Length(),status) ); sl@0: test(err == KErrNone); sl@0: User::WaitForRequest(status); sl@0: TRAP(err, fbuf.SeekL(MStreamBuf::ERead|MStreamBuf::EWrite, 0) ); sl@0: test(err == KErrNone); sl@0: TBuf8<250> temp; sl@0: fbuf.DoReadL(temp,temp.MaxLength(),status); sl@0: User::WaitForRequest(status); sl@0: test(temp.Compare(KTestTextBuf)==0); sl@0: sl@0: TInt av = fbuf.Avail(MStreamBuf::ERead); sl@0: av = fbuf.Avail(MStreamBuf::EWrite); sl@0: TUint8* end = fbuf.End(MStreamBuf::ERead); sl@0: fbuf.SetEnd(MStreamBuf::ERead, end-1); sl@0: end = fbuf.End(MStreamBuf::EWrite); sl@0: fbuf.SetEnd(MStreamBuf::EWrite, end-1); sl@0: sl@0: fbuf.Close(); sl@0: fs.Delete(KFileStore2); sl@0: fs.Close(); sl@0: } sl@0: sl@0: // sl@0: // Prepare the test directory. sl@0: // sl@0: LOCAL_C void setupTestDirectory() sl@0: { sl@0: TInt r=TheFs.Connect(); sl@0: test(r==KErrNone); sl@0: // sl@0: TDriveUnit drive(static_cast(RFs::GetSystemDrive())); sl@0: TParse parse; sl@0: parse.Set(drive.Name(), &KFileLocationSpec, NULL); sl@0: sl@0: r=TheFs.MkDir(parse.DriveAndPath()); sl@0: test(r==KErrNone||r==KErrAlreadyExists); sl@0: r=TheFs.SetSessionPath(parse.DriveAndPath()); sl@0: test(r==KErrNone); sl@0: } sl@0: sl@0: // sl@0: // Initialise the cleanup stack. sl@0: // sl@0: LOCAL_C void setupCleanup() sl@0: { sl@0: TheTrapCleanup=CTrapCleanup::New(); sl@0: test(TheTrapCleanup!=NULL); sl@0: TRAPD(r,\ sl@0: {\ sl@0: for (TInt i=KTestCleanupStack;i>0;i--)\ sl@0: CleanupStack::PushL((TAny*)1);\ sl@0: test(r==KErrNone);\ sl@0: CleanupStack::Pop(KTestCleanupStack);\ sl@0: }); sl@0: test(r==KErrNone); sl@0: } sl@0: sl@0: LOCAL_C void DeleteDataFile(const TDesC& aFullName) sl@0: { sl@0: RFs fsSession; sl@0: TInt err = fsSession.Connect(); sl@0: if(err == KErrNone) sl@0: { sl@0: TEntry entry; sl@0: if(fsSession.Entry(aFullName, entry) == KErrNone) sl@0: { sl@0: RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName); sl@0: err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly); sl@0: if(err != KErrNone) sl@0: { sl@0: RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName); sl@0: } sl@0: err = fsSession.Delete(aFullName); sl@0: if(err != KErrNone) sl@0: { sl@0: RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName); sl@0: } sl@0: } sl@0: fsSession.Close(); sl@0: } sl@0: else sl@0: { sl@0: RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName); sl@0: } sl@0: } sl@0: sl@0: // sl@0: // Test file-based stream buffer. sl@0: // sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: test.Title(); sl@0: setupTestDirectory(); sl@0: setupCleanup(); sl@0: __UHEAP_MARK; sl@0: sl@0: test.Start(_L("Test file-based stream buffer")); sl@0: TRAPD(r,testWriteL()); sl@0: test(r==KErrNone); sl@0: TRAP(r,testReadL()); sl@0: test(r==KErrNone); sl@0: TRAP(r,testSkipL()); sl@0: test(r==KErrNone); sl@0: TRAP(r,testCopyL()); sl@0: test(r==KErrNone); sl@0: TRAP(r, DEF118202L()); sl@0: test(r==KErrNone); sl@0: TRAP(r, testReadWriteL()); sl@0: test(r==KErrNone); sl@0: sl@0: sl@0: //deletion of data files must be before call to .End() - DEF047652 sl@0: TDriveUnit drive(static_cast(RFs::GetSystemDrive())); sl@0: TParse parse; sl@0: parse.Set(drive.Name(), &KFileLocationSpec, NULL); sl@0: ::DeleteDataFile(parse.FullName()); sl@0: sl@0: test.End(); sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: delete TheTrapCleanup; sl@0: if (TheFs.Delete(TheTempFile)!=KErrNone) sl@0: test.Panic(_L("Deleting temp file")); sl@0: TheFs.Close(); sl@0: test.Close(); sl@0: return 0; sl@0: } sl@0: