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: const TUint8* KTestData=_S8("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"); sl@0: const TInt KTestLength=36; sl@0: const TInt KTestTotal=KTestLength*(KTestLength+1); sl@0: const TPtrC8 KTestDes(KTestData,KTestLength); sl@0: const TInt KTestExpandSize=0x20; sl@0: const TInt KTestCopyExpandSize=17; sl@0: sl@0: LOCAL_D CTrapCleanup *TheTrapCleanup; sl@0: LOCAL_D RTest test(_L("t_stormemstrm")); sl@0: LOCAL_D TUint8 TheBuf[KTestTotal+1]; sl@0: sl@0: // sl@0: // Test writing to a stream. sl@0: // sl@0: LOCAL_C void testWriteL(RWriteStream& aStream) sl@0: { sl@0: test.Next(_L("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: // Test reading from a stream. sl@0: // sl@0: LOCAL_C void testReadL(RReadStream& aStream) sl@0: { sl@0: test.Next(_L("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: // Test skipping data on a stream. sl@0: // sl@0: LOCAL_C void testSkipL(RReadStream& aStream) sl@0: { sl@0: test.Next(_L("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: // Test a stream is at end-of-file. sl@0: // sl@0: LOCAL_C void testEofL(RReadStream& aStream) sl@0: { sl@0: test.Next(_L("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 memory stream. sl@0: // sl@0: LOCAL_C void testWriteL(TAny* aPtr) sl@0: { sl@0: test.Next(_L("Writing to constructed stream")); sl@0: RMemWriteStream out(aPtr,KTestTotal); sl@0: testWriteL(out); sl@0: out.CommitL(); sl@0: // sl@0: test.Next(_L("Writing one byte too many")); sl@0: TRAPD(r,out.WriteUint8L(0)); sl@0: test(r==KErrOverflow); sl@0: out.Close(); sl@0: // sl@0: test.Next(_L("Over-writing massively")); sl@0: out.Open(aPtr,KTestLength); sl@0: TRAP(r,testWriteL(out)); sl@0: test(r==KErrOverflow); sl@0: out.Open((TUint8*)aPtr+KTestLength,KTestTotal-KTestLength); sl@0: TRAP(r,testWriteL(out)); sl@0: test(r==KErrOverflow); sl@0: // sl@0: test.Next(_L("Writing to opened stream")); sl@0: out.Open(aPtr,KTestTotal); sl@0: testWriteL(out); sl@0: } sl@0: sl@0: // sl@0: // Test reading from a memory stream. sl@0: // sl@0: LOCAL_C void testReadL(const TAny* aPtr) sl@0: { sl@0: test.Next(_L("Reading from constructed stream")); sl@0: RMemReadStream in(KTestData,KTestLength); sl@0: TRAPD(r,testReadL(in)); sl@0: test(r==KErrEof); sl@0: testEofL(in); sl@0: in.Close(); sl@0: // sl@0: test.Next(_L("Reading from opened stream")); sl@0: in.Open(aPtr,KTestTotal); sl@0: testReadL(in); sl@0: testEofL(in); sl@0: } sl@0: sl@0: // sl@0: // Test skipping on a memory stream. sl@0: // sl@0: LOCAL_C void testSkipL(const TAny* aPtr) sl@0: { sl@0: test.Next(_L("Skipping using small transfers")); sl@0: RMemReadStream in(aPtr,KTestTotal); sl@0: testSkipL(in); sl@0: testEofL(in); sl@0: in.Close(); sl@0: // sl@0: test.Next(_L("Skipping using a single big transfer")); sl@0: in.Open(aPtr,KTestTotal); sl@0: in.ReadL(KTestTotal); sl@0: testEofL(in); sl@0: } sl@0: sl@0: // sl@0: // Test copying memory streams. sl@0: // sl@0: LOCAL_C void testCopyL(TAny* aPtr) sl@0: { sl@0: test.Next(_L("Copying using small transfers")); sl@0: TUint8 buf[KTestTotal]; sl@0: RMemReadStream in(KTestData,KTestLength); sl@0: RMemWriteStream out(buf,KTestTotal); sl@0: TRAPD(r,testCopyL(out,in)); sl@0: test(r==KErrEof); sl@0: testEofL(in); sl@0: in.Open(aPtr,KTestTotal); sl@0: TRAP(r,testCopyL(out,in)); sl@0: test(r==KErrOverflow); sl@0: in.Open(buf,KTestTotal); sl@0: testReadL(in); sl@0: testEofL(in); sl@0: in.Open(buf,KTestTotal); sl@0: out.Open(aPtr,KTestTotal); sl@0: testCopyL(out,in); sl@0: testEofL(in); sl@0: out.Close(); sl@0: in.Close(); sl@0: in.Open(aPtr,KTestTotal); sl@0: testReadL(in); sl@0: testEofL(in); sl@0: in.Close(); sl@0: // sl@0: test.Next(_L("Copying using a single big transfer")); sl@0: Mem::FillZ(buf,KTestTotal); sl@0: in.Open(KTestData,KTestLength); sl@0: out.Open(buf,KTestTotal); sl@0: TRAP(r,in.ReadL(out,KTestTotal)); sl@0: test(r==KErrEof); sl@0: testEofL(in); sl@0: in.Open(aPtr,KTestTotal); sl@0: TRAP(r,out.WriteL(in,KTestTotal)); sl@0: test(r==KErrOverflow); sl@0: in.Open(buf,KTestTotal); sl@0: testReadL(in); sl@0: testEofL(in); sl@0: in.Open(buf,KTestTotal); sl@0: out.Open(aPtr,KTestTotal); sl@0: in.ReadL(out,KTestTotal); sl@0: testEofL(in); sl@0: out.Close(); sl@0: in.Close(); sl@0: in.Open(aPtr,KTestTotal); sl@0: testReadL(in); sl@0: testEofL(in); sl@0: in.Close(); sl@0: // sl@0: test.Next(_L("Copying until end of file")); sl@0: Mem::FillZ(buf,KTestTotal); sl@0: in.Open(KTestData,KTestLength); sl@0: out.Open(buf,KTestTotal); sl@0: out.WriteL(in); sl@0: testEofL(in); sl@0: in.Open(aPtr,KTestTotal); sl@0: TRAP(r,in.ReadL(out)); sl@0: test(r==KErrOverflow); sl@0: in.Open(buf,KTestTotal); sl@0: testReadL(in); sl@0: testEofL(in); sl@0: in.Open(buf,KTestTotal); sl@0: out.Open(aPtr,KTestTotal); sl@0: out.WriteL(in); sl@0: testEofL(in); sl@0: out.CommitL(); sl@0: out.Close(); sl@0: in.Close(); sl@0: in.Open(aPtr,KTestTotal); sl@0: testReadL(in); sl@0: testEofL(in); sl@0: in.Close(); sl@0: } sl@0: sl@0: // sl@0: // Test writing to a descriptor stream. sl@0: // sl@0: LOCAL_C void testWriteL(TDes8& aDes) sl@0: { sl@0: test.Next(_L("Writing to constructed stream")); sl@0: RDesWriteStream out(aDes); sl@0: testWriteL(out); sl@0: // sl@0: test.Next(_L("Writing one byte too many")); sl@0: TRAPD(r,out.WriteUint8L(0)); sl@0: test(r==KErrOverflow); sl@0: out.Close(); sl@0: // sl@0: test.Next(_L("Over-writing massively")); sl@0: TPtr8 ptr((TUint8*)aDes.Ptr(),KTestLength); sl@0: out.Open(ptr); sl@0: TRAP(r,testWriteL(out)); sl@0: test(r==KErrOverflow); sl@0: ptr.Set((TUint8*)aDes.Ptr()+KTestLength,KTestLength,KTestTotal-KTestLength); sl@0: out.Open(ptr); sl@0: TRAP(r,testWriteL(out)); sl@0: test(r==KErrOverflow); sl@0: // sl@0: test.Next(_L("Writing to opened stream")); sl@0: out.Open(aDes); sl@0: testWriteL(out); sl@0: out.CommitL(); sl@0: } sl@0: sl@0: // sl@0: // Test reading from a descriptor stream. sl@0: // sl@0: LOCAL_C void testReadL(const TDesC8& aDes) sl@0: { sl@0: test.Next(_L("Reading from constructed stream")); sl@0: RDesReadStream in(KTestDes); sl@0: TRAPD(r,testReadL(in)); sl@0: test(r==KErrEof); sl@0: testEofL(in); sl@0: in.Close(); sl@0: // sl@0: test.Next(_L("Reading from opened stream")); sl@0: in.Open(aDes); sl@0: testReadL(in); sl@0: testEofL(in); sl@0: } sl@0: sl@0: // sl@0: // Test skipping on a descriptor stream. sl@0: // sl@0: LOCAL_C void testSkipL(const TDesC8& aDes) sl@0: { sl@0: test.Next(_L("Skipping using small transfers")); sl@0: RDesReadStream in(aDes); sl@0: testSkipL(in); sl@0: testEofL(in); sl@0: in.Close(); sl@0: // sl@0: test.Next(_L("Skipping using a single big transfer")); sl@0: in.Open(aDes); sl@0: in.ReadL(KTestTotal); sl@0: testEofL(in); sl@0: } sl@0: sl@0: // sl@0: // Test copying descriptor streams. sl@0: // sl@0: LOCAL_C void testCopyL(TDes8& aDes) sl@0: { sl@0: test.Next(_L("Copying using small transfers")); sl@0: TBuf8 buf; sl@0: RDesReadStream in(KTestDes); sl@0: RDesWriteStream out(buf); sl@0: TRAPD(r,testCopyL(out,in)); sl@0: test(r==KErrEof); sl@0: testEofL(in); sl@0: in.Open(aDes); sl@0: TRAP(r,testCopyL(out,in)); sl@0: test(r==KErrOverflow); sl@0: out.CommitL(); sl@0: testEofL(in); sl@0: in.Open(buf); sl@0: testReadL(in); sl@0: testEofL(in); sl@0: in.Open(buf); sl@0: out.Open(aDes); sl@0: testCopyL(out,in); sl@0: testEofL(in); sl@0: out.Close(); sl@0: in.Close(); sl@0: in.Open(aDes); sl@0: testReadL(in); sl@0: testEofL(in); sl@0: in.Close(); sl@0: // sl@0: test.Next(_L("Copying using a single big transfer")); sl@0: buf.FillZ(); sl@0: in.Open(KTestDes); sl@0: out.Open(buf); sl@0: TRAP(r,in.ReadL(out,KTestTotal)); sl@0: test(r==KErrEof); sl@0: testEofL(in); sl@0: in.Open(aDes); sl@0: TRAP(r,out.WriteL(in,KTestTotal)); sl@0: test(r==KErrOverflow); sl@0: out.CommitL(); sl@0: in.Open(buf); sl@0: testReadL(in); sl@0: testEofL(in); sl@0: in.Open(buf); sl@0: out.Open(aDes); sl@0: in.ReadL(out,KTestTotal); sl@0: testEofL(in); sl@0: out.Close(); sl@0: in.Close(); sl@0: in.Open(aDes); sl@0: testReadL(in); sl@0: testEofL(in); sl@0: in.Close(); sl@0: // sl@0: test.Next(_L("Copying until end of file")); sl@0: buf.FillZ(); sl@0: in.Open(KTestDes); sl@0: out.Open(buf); sl@0: out.WriteL(in); sl@0: testEofL(in); sl@0: in.Open(aDes); sl@0: TRAP(r,in.ReadL(out)); sl@0: test(r==KErrOverflow); sl@0: out.CommitL(); sl@0: in.Open(buf); sl@0: testReadL(in); sl@0: testEofL(in); sl@0: in.Open(buf); sl@0: out.Open(aDes); sl@0: out.WriteL(in); sl@0: testEofL(in); sl@0: out.CommitL(); sl@0: out.Close(); sl@0: in.Close(); sl@0: in.Open(aDes); sl@0: testReadL(in); sl@0: testEofL(in); sl@0: in.Close(); sl@0: } sl@0: sl@0: // sl@0: // Test writing to a buffer stream. sl@0: // sl@0: LOCAL_C void testWriteL(CBufBase& aBuf) sl@0: { sl@0: test.Next(_L("Writing to constructed stream")); sl@0: RBufWriteStream out(aBuf); sl@0: testWriteL(out); sl@0: out.CommitL(); sl@0: // sl@0: test.Next(_L("Writing to opened stream")); sl@0: out.Open(aBuf,KTestLength); sl@0: testWriteL(out); sl@0: // sl@0: test.Next(_L("Writing to inserting stream")); sl@0: out.Insert(aBuf,KTestLength); sl@0: testWriteL(out); sl@0: out.Close(); sl@0: out.Insert(aBuf,0); sl@0: testWriteL(out); sl@0: // sl@0: test.Next(_L("Writing to appending stream")); sl@0: out.Append(aBuf); sl@0: testWriteL(out); sl@0: // sl@0: test.Next(_L("Writing to truncating stream")); sl@0: out.Truncate(aBuf,KTestLength); sl@0: testWriteL(out); sl@0: out.Close(); sl@0: out.Truncate(aBuf); sl@0: testWriteL(out); sl@0: out.CommitL(); sl@0: } sl@0: sl@0: // sl@0: // Test reading from a buffer stream. sl@0: // sl@0: LOCAL_C void testReadL(const CBufBase& aBuf) sl@0: { sl@0: test.Next(_L("Reading from constructed stream")); sl@0: RBufReadStream in(aBuf,KTestLength); sl@0: TRAPD(r,testReadL(in)); sl@0: test(r==KErrEof); sl@0: testEofL(in); sl@0: in.Close(); sl@0: // sl@0: test.Next(_L("Reading from opened stream")); sl@0: in.Open(aBuf); sl@0: testReadL(in); sl@0: testEofL(in); sl@0: } sl@0: sl@0: // sl@0: // Test skipping on a buffer stream. sl@0: // sl@0: LOCAL_C void testSkipL(const CBufBase& aBuf) sl@0: { sl@0: test.Next(_L("Skipping using small transfers")); sl@0: RBufReadStream in(aBuf); sl@0: testSkipL(in); sl@0: testEofL(in); sl@0: in.Close(); sl@0: // sl@0: test.Next(_L("Skipping using a single big transfer")); sl@0: in.Open(aBuf); sl@0: in.ReadL(KTestTotal); sl@0: testEofL(in); sl@0: in.Close(); sl@0: } sl@0: sl@0: // sl@0: // Test copying buffer streams. sl@0: // sl@0: LOCAL_C void testCopyL(CBufBase& aBuf) sl@0: { sl@0: test.Next(_L("Copying using small transfers")); sl@0: CBufBase* buf=0; sl@0: TRAPD(r,buf=CBufFlat::NewL(KTestCopyExpandSize)); sl@0: if (r!=KErrNone) sl@0: test.Panic(_L("Allocating buffer")); sl@0: RBufReadStream in(aBuf); sl@0: RBufWriteStream out(*buf); sl@0: TRAP(r,testCopyL(out,in)); sl@0: test(r==KErrEof); sl@0: testEofL(in); sl@0: in.Open(aBuf,KTestTotal-2*KTestLength); sl@0: TRAP(r,testCopyL(out,in)); sl@0: test(r==KErrEof); sl@0: out.Close(); sl@0: testEofL(in); sl@0: in.Open(*buf); sl@0: out.Open(aBuf); sl@0: testCopyL(out,in); sl@0: testEofL(in); sl@0: out.CommitL(); sl@0: in.Open(aBuf); sl@0: testReadL(in); sl@0: testEofL(in); sl@0: delete buf; sl@0: TRAP(r,buf=CBufSeg::NewL(KTestCopyExpandSize)); sl@0: if (r!=KErrNone) sl@0: test.Panic(_L("Allocating buffer")); sl@0: in.Open(aBuf); sl@0: out.Open(*buf); sl@0: testCopyL(out,in); sl@0: testEofL(in); sl@0: out.CommitL(); sl@0: in.Open(*buf); sl@0: out.Open(aBuf); sl@0: testCopyL(out,in); sl@0: testEofL(in); sl@0: out.Close(); sl@0: in.Close(); sl@0: in.Open(aBuf); sl@0: testReadL(in); sl@0: testEofL(in); sl@0: in.Close(); sl@0: // sl@0: test.Next(_L("Copying using a single big transfer")); sl@0: in.Open(aBuf); sl@0: out.Truncate(*buf,KTestLength); sl@0: TRAP(r,in.ReadL(out,KTestTotal+KTestLength)); sl@0: test(r==KErrEof); sl@0: testEofL(in); sl@0: in.Open(aBuf,KTestTotal); sl@0: TRAP(r,out.WriteL(in,KTestTotal)); sl@0: test(r==KErrEof); sl@0: out.CommitL(); sl@0: testEofL(in); sl@0: in.Open(*buf); sl@0: testReadL(in); sl@0: in.ReadL(KTestLength); sl@0: testEofL(in); sl@0: delete buf; sl@0: TRAP(r,buf=CBufFlat::NewL(KTestExpandSize)); sl@0: if (r!=KErrNone) sl@0: test.Panic(_L("Allocating buffer")); sl@0: in.Open(aBuf); sl@0: out.Open(*buf); sl@0: testCopyL(out,in); sl@0: testEofL(in); sl@0: out.CommitL(); sl@0: in.Open(*buf); sl@0: out.Open(aBuf); sl@0: in.ReadL(out,KTestTotal); sl@0: testEofL(in); sl@0: out.Close(); sl@0: in.Close(); sl@0: in.Open(aBuf); sl@0: testReadL(in); sl@0: testEofL(in); sl@0: in.Close(); sl@0: // sl@0: test.Next(_L("Copying until end of file")); sl@0: in.Open(aBuf,KTestLength); sl@0: out.Truncate(*buf); sl@0: out.WriteL(in); sl@0: testEofL(in); sl@0: in.Open(aBuf,KTestTotal-KTestLength); sl@0: in.ReadL(out); sl@0: out.CommitL(); sl@0: testEofL(in); sl@0: in.Open(*buf); sl@0: testReadL(in); sl@0: testEofL(in); sl@0: delete buf; sl@0: TRAP(r,buf=CBufSeg::NewL(KTestExpandSize)); sl@0: if (r!=KErrNone) sl@0: test.Panic(_L("Allocating buffer")); sl@0: in.Open(aBuf); sl@0: out.Open(*buf); sl@0: testCopyL(out,in); sl@0: testEofL(in); sl@0: out.CommitL(); sl@0: in.Open(*buf); sl@0: out.Open(aBuf); sl@0: out.WriteL(in); sl@0: testEofL(in); sl@0: out.Close(); sl@0: in.Close(); sl@0: in.Open(aBuf); sl@0: testReadL(in); sl@0: testEofL(in); sl@0: in.Close(); sl@0: delete buf; sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-STORE-CT-1173 sl@0: @SYMTestCaseDesc Tests for defect number FER56EJNS sl@0: @SYMTestPriority High sl@0: @SYMTestActions Tests for MStreamBuf::SizeL() function returning zero length. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: LOCAL_C void test_defect_FER_56EJNS() sl@0: { sl@0: const TPtrC8 p; sl@0: test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1173 ")); sl@0: // don't replace p with TPtrC8() because gcc interprets it as a function declaration. sl@0: RDesReadStream s(p); sl@0: TInt sz=-1; sl@0: TRAPD(r,sz=s.Source()->SizeL()); sl@0: test (r==KErrNone); sl@0: test (sz==0); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-STORE-CT-1174 sl@0: @SYMTestCaseDesc Memory streams test sl@0: @SYMTestPriority High sl@0: @SYMTestActions Tests for writing,reading,skipping and copying on memory streams operations sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: LOCAL_C void testMemL() sl@0: { sl@0: test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1174 Test memory streams ")); sl@0: Mem::Fill(TheBuf,KTestTotal,'|'); sl@0: TheBuf[KTestTotal]=KMaxTUint8; sl@0: testWriteL(TheBuf); sl@0: testReadL(TheBuf); sl@0: testSkipL(TheBuf); sl@0: testCopyL(TheBuf); sl@0: test(TheBuf[KTestTotal]==KMaxTUint8); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-STORE-CT-1175 sl@0: @SYMTestCaseDesc Tests for read,write,copy operations on descriptor streams buffer sl@0: @SYMTestPriority High sl@0: @SYMTestActions Test for writing,reading,skipping and copying on descriptor streams operations sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: LOCAL_C void testDesL() sl@0: { sl@0: test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1175 Test descriptor streams ")); sl@0: Mem::Fill(TheBuf,KTestTotal,'|'); sl@0: TheBuf[KTestTotal]=KMaxTUint8; sl@0: TPtr8 des(TheBuf,KTestTotal); sl@0: testWriteL(des); sl@0: test(des.Length()==KTestTotal); sl@0: testReadL(des); sl@0: testSkipL(des); sl@0: des.SetLength(KTestTotal-KTestLength+1); sl@0: testCopyL(des); sl@0: test(des.Length()==KTestTotal); sl@0: test(TheBuf[KTestTotal]==KMaxTUint8); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-STORE-CT-1176 sl@0: @SYMTestCaseDesc Buffer streaming test sl@0: @SYMTestPriority High sl@0: @SYMTestActions Tests by writing,reading,skipping and copying on buffer streams sl@0: Tests for panic during creation of a new buffer sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: LOCAL_C void testBufL() sl@0: { sl@0: test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1176 Test buffer streams ")); sl@0: CBufBase* buf=0; sl@0: TRAPD(r,buf=CBufFlat::NewL(KTestExpandSize)); sl@0: if (r!=KErrNone) sl@0: test.Panic(_L("Allocating buffer")); sl@0: testWriteL(*buf); sl@0: test(buf->Size()==KTestTotal); sl@0: testReadL(*buf); sl@0: testSkipL(*buf); sl@0: buf->ResizeL(KTestTotal-KTestLength); sl@0: testCopyL(*buf); sl@0: test(buf->Size()==KTestTotal); sl@0: delete buf; sl@0: // sl@0: TRAP(r,buf=CBufSeg::NewL(KTestExpandSize)); sl@0: if (r!=KErrNone) sl@0: test.Panic(_L("Allocating buffer")); sl@0: testWriteL(*buf); sl@0: test(buf->Size()==KTestTotal); sl@0: testReadL(*buf); sl@0: testSkipL(*buf); sl@0: buf->ResizeL(KTestTotal-KTestLength); sl@0: testCopyL(*buf); sl@0: test(buf->Size()==KTestTotal); sl@0: delete buf; sl@0: } sl@0: sl@0: /** sl@0: DEF038720 - RBufReadStream Close/Re-Open doesn't return to initial open state sl@0: sl@0: @SYMTestCaseID SYSLIB-STORE-CT-1177 sl@0: @SYMTestCaseDesc Tests for defect number DEF038720 sl@0: RBufReadStream Close/Re-Open doesn't return to initial open state sl@0: @SYMTestPriority High sl@0: @SYMTestActions Write to buffer stream and read back,asserts if any problem while reading the buffer sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: LOCAL_C void test_DEF038720L() sl@0: { sl@0: test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1177 ")); sl@0: CBufFlat* buf = CBufFlat::NewL(0x20); sl@0: CleanupStack::PushL(buf); sl@0: buf->ExpandL(0, 0x20); sl@0: sl@0: RBufWriteStream writeStream(*buf); sl@0: writeStream.PushL(); sl@0: writeStream.WriteInt32L(1); sl@0: CleanupStack::PopAndDestroy(&writeStream); sl@0: sl@0: TInt temp; sl@0: RBufReadStream readStream; sl@0: for(TInt i=0; i<2; i++) sl@0: { sl@0: readStream.Open(*buf); sl@0: readStream.PushL(); sl@0: temp = readStream.ReadInt32L(); sl@0: __ASSERT_ALWAYS(temp==1, User::Invariant()); //Fails here 2nd time, if the defect is not fixed sl@0: CleanupStack::PopAndDestroy(&readStream); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(buf); 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: // sl@0: // Test memory-based streams. sl@0: // sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: test.Title(); sl@0: setupCleanup(); sl@0: __UHEAP_MARK; sl@0: // sl@0: test.Start(_L("Test memory-based streams")); sl@0: TRAPD(r,testMemL()); sl@0: test(r==KErrNone); sl@0: TRAP(r,testDesL()); sl@0: test(r==KErrNone); sl@0: TRAP(r,testBufL()); sl@0: test(r==KErrNone); sl@0: // sl@0: test.Next(_L("Test defect fixes")); sl@0: test_defect_FER_56EJNS(); sl@0: TRAP(r,::test_DEF038720L()); sl@0: test(r==KErrNone); sl@0: test.End(); sl@0: // sl@0: __UHEAP_MARKEND; sl@0: delete TheTrapCleanup; sl@0: test.Close(); sl@0: return 0; sl@0: } sl@0: