os/persistentdata/persistentstorage/store/TFILE/t_storfbuf.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #include <s32file.h>
    17 #include <e32test.h>
    18 
    19 const TInt KTestCleanupStack=0x20;
    20 
    21 // This is a path specification and should not be used as is
    22 _LIT(KFileLocationSpec, "Z:\\STOR-TST\\T_FBUF.DAT");
    23 const TUint8* KTestData=_S8("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");
    24 const TUint8* KTestDataLong=_S8("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0");
    25 const TUint8* KTestData10Chars = _S8("0123456789");
    26 
    27 const TInt KTestLength=36;
    28 const TInt KTestTotal=KTestLength*(KTestLength+1);
    29 const TPtrC8 KTestDes(KTestData,KTestLength);
    30 const TPtrC8 KTestDesLong(KTestDataLong,KTestLength+1);
    31 const TInt KTestFileBufSize=7;
    32 const TInt KTestWriteBufSize=5;
    33 const TInt KTestReadBufSize=3;
    34 const TInt KTestSkipBufSize=2;
    35 const TInt KTestCopyBufSize=1;
    36 
    37 LOCAL_D CTrapCleanup* TheTrapCleanup;
    38 LOCAL_D RTest test(_L("t_storfbuf"));
    39 LOCAL_D RFs TheFs;
    40 LOCAL_D TFileName TheTempFile;
    41 
    42 /**
    43 @SYMTestCaseID          SYSLIB-STORE-CT-1136
    44 @SYMTestCaseDesc	    Writing to a stream buffer test
    45 @SYMTestPriority 	    High
    46 @SYMTestActions  	    Tests for RWriteStream::WriteL() function
    47 @SYMTestExpectedResults Test must not fail
    48 @SYMREQ                 REQ0000
    49 */
    50 LOCAL_C void testWriteL(RWriteStream& aStream)
    51 	{
    52 	test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1136 Writing... "));
    53 	for (TInt i=0;i<=KTestLength;++i)
    54 		{
    55 		aStream.WriteL(KTestDes,i);
    56 		aStream.WriteL(&KTestData[i],KTestLength-i);
    57 		}
    58 	}
    59 
    60 /**
    61 @SYMTestCaseID          SYSLIB-STORE-CT-1137
    62 @SYMTestCaseDesc	    Reading from a stream buffer test
    63 @SYMTestPriority 	    High
    64 @SYMTestActions  	    Tests for RReadStream::ReadL() function
    65 @SYMTestExpectedResults Test must not fail
    66 @SYMREQ                 REQ0000
    67 */
    68 LOCAL_C void testReadL(RReadStream& aStream)
    69 	{
    70 	test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1137 Reading... "));
    71 	for (TInt i=KTestLength;i>=0;--i)
    72 		{
    73 		TBuf8<KTestLength+1> buf;
    74 		aStream.ReadL(buf,i);
    75 		test(buf.Length()==i);
    76 		buf.SetMax();
    77 		aStream.ReadL(&buf[i],KTestLength-i);
    78 		buf.SetLength(KTestLength);
    79 		test(buf==KTestDes);
    80 		}
    81 	}
    82 
    83 /**
    84 @SYMTestCaseID          SYSLIB-STORE-CT-1138
    85 @SYMTestCaseDesc	    Skipping data on a stream buffer test.
    86 @SYMTestPriority 	    High
    87 @SYMTestActions  	    Tests skipping data while reading from a stream
    88 @SYMTestExpectedResults Test must not fail
    89 @SYMREQ                 REQ0000
    90 */
    91 LOCAL_C void testSkipL(RReadStream& aStream)
    92 	{
    93 	test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1138 Skipping... "));
    94 	for (TInt i=0;i<=KTestLength;++i)
    95 		{
    96 		aStream.ReadL(i);
    97 		aStream.ReadL(KTestLength-i);
    98 		}
    99 	}
   100 
   101 /**
   102 @SYMTestCaseID          SYSLIB-STORE-CT-1139
   103 @SYMTestCaseDesc	    Tests a stream buffer is at end-of-file.
   104 @SYMTestPriority 	    High
   105 @SYMTestActions  	    Tests for end of file while reading from a stream buffer
   106 @SYMTestExpectedResults Test must not fail
   107 @SYMREQ                 REQ0000
   108 */
   109 LOCAL_C void testEofL(RReadStream& aStream)
   110 	{
   111 	test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1139 At end "));
   112 	TUint8 b;
   113 	test(aStream.Source()->ReadL(&b,1)==0);
   114 	}
   115 
   116 //
   117 // Test copying from one stream to another.
   118 //
   119 LOCAL_C void testCopyL(RWriteStream& aWriteStream,RReadStream& aReadStream)
   120 	{
   121 	test.Next(_L("Copying"));
   122 	for (TInt i=KTestLength;i>=0;--i)
   123 		{
   124 		aWriteStream.WriteL(aReadStream,i);
   125 		aReadStream.ReadL(aWriteStream,KTestLength-i);
   126 		}
   127 	}
   128 
   129 //
   130 // Test writing to a stream buffer.
   131 //
   132 LOCAL_C void testWriteL(MStreamBuf& aBuf)
   133 	{
   134 	RWriteStream stream(&aBuf);
   135 	testWriteL(stream);
   136 	}
   137 
   138 //
   139 // Test reading from a stream buffer.
   140 //
   141 LOCAL_C void testReadL(MStreamBuf& aBuf)
   142 	{
   143 	RReadStream stream(&aBuf);
   144 	testReadL(stream);
   145 	}
   146 
   147 //
   148 // Test skipping data on a stream buffer.
   149 //
   150 LOCAL_C void testSkipL(MStreamBuf& aBuf)
   151 	{
   152 	RReadStream stream(&aBuf);
   153 	testSkipL(stream);
   154 	}
   155 
   156 //
   157 // Test a stream buffer is at end-of-file.
   158 //
   159 LOCAL_C void testEofL(MStreamBuf& aBuf)
   160 	{
   161 	RReadStream stream(&aBuf);
   162 	testEofL(stream);
   163 	}
   164 
   165 //
   166 // Test copying from one stream buffer to another.
   167 //
   168 LOCAL_C void testCopyL(MStreamBuf& aSink,MStreamBuf& aSource)
   169 	{
   170 	RWriteStream out(&aSink);
   171 	RReadStream in(&aSource);
   172 	testCopyL(out,in);
   173 	}
   174 /**
   175 @SYMTestCaseID          PDS-STORE-CT-4027
   176 @SYMTestCaseDesc	    Writing to a stream buffer test
   177 @SYMTestPriority 	    High
   178 @SYMTestActions  	    Validate the MStreamBuf Write API
   179 @SYMTestExpectedResults Test must not fail
   180 @SYMDEF                 DEF135804
   181 */
   182 LOCAL_C void testStreamBufWriteL(MStreamBuf& aBuf)
   183 	{
   184 	test.Next(_L(" @SYMTestCaseID:PDS-STORE-CT-4027 Writing... "));
   185 	TRequestStatus status;
   186 	aBuf.Write(KTestDes,status);
   187 	User::WaitForRequest(status);
   188 	
   189 	aBuf.SeekL(aBuf.EWrite,EStreamBeginning,0);
   190 	aBuf.WriteL(KTestDes,status);
   191 	User::WaitForRequest(status);
   192 	
   193 	}
   194 
   195 /**
   196 @SYMTestCaseID          PDS-STORE-CT-4026
   197 @SYMTestCaseDesc	    Reading from a stream buffer test
   198 @SYMTestPriority 	    High
   199 @SYMTestActions  	    Validate the MStreamBuf Read API
   200 @SYMTestExpectedResults Test must not fail
   201 @SYMDEF                 DEF135804
   202 */
   203 LOCAL_C void testStreamBufReadL(MStreamBuf& aBuf)
   204 	{
   205 	test.Next(_L(" @SYMTestCaseID:PDS-STORE-CT-4026 Reading... "));
   206 	TRequestStatus status;
   207 	
   208 	TBuf8<KTestLength+1> buf;
   209 	aBuf.Read(buf, KTestLength, status);
   210 	User::WaitForRequest(status);
   211 	test(buf.Length()==KTestLength);
   212 	test(buf==KTestDes);
   213 	
   214 	aBuf.SeekL(aBuf.ERead,EStreamBeginning,0);
   215 	aBuf.ReadL(buf, status);
   216 	User::WaitForRequest(status);
   217 	test(buf.Length()== KTestLength+1);
   218 	test(buf==KTestDesLong);
   219 
   220 	aBuf.SeekL(aBuf.ERead,EStreamBeginning,0);
   221 	aBuf.Read(buf, status);
   222 	User::WaitForRequest(status);
   223 	test(buf.Length()== KTestLength+1);
   224 	test(buf==KTestDesLong);
   225 
   226 	}
   227 /**
   228 @SYMTestCaseID          SYSLIB-STORE-CT-1140
   229 @SYMTestCaseDesc	    Write to a file buffer test.
   230 @SYMTestPriority 	    High
   231 @SYMTestActions  	    Tests for writing to an attached file,a replaced file,a temporary file,an opened file
   232 						Tests for replacing an existing file,test for deleting a file.
   233 						Tests for writing to a new file buffer after the deletion of old file.
   234 @SYMTestExpectedResults Test must not fail
   235 @SYMREQ                 REQ0000
   236 */
   237 LOCAL_C void testWriteL()
   238 	{
   239 	test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1140 Writing to attached file "));
   240 
   241 	
   242 	TDriveUnit drive(static_cast<TUint>(RFs::GetSystemDrive()));	
   243 	TParse parse;
   244 	parse.Set(drive.Name(), &KFileLocationSpec, NULL);
   245 	
   246 	
   247 	
   248 	RFile file;
   249 	if (file.Replace(TheFs,parse.NameAndExt(),EFileWrite)!=KErrNone)
   250 		test.Panic(_L("Replacing file"));
   251 	RFileBuf rbuf(KTestWriteBufSize);
   252 	RFile file2 = file;//Keep a copy in file2, because Attach() will clear the passed RFile parameter
   253 	rbuf.Attach(file);
   254 	rbuf.Detach();
   255 	rbuf.Reattach(file2);
   256 	testStreamBufWriteL(rbuf);
   257 	rbuf.SynchL();
   258 	rbuf.Close();
   259 	if (TheFs.Delete(parse.NameAndExt())!=KErrNone)
   260 			test.Panic(_L("Deleting file"));
   261 
   262 	if (file.Replace(TheFs,parse.NameAndExt(),EFileWrite)!=KErrNone)
   263 			test.Panic(_L("Replacing file"));
   264 	RFileBuf buf(KTestWriteBufSize);
   265 	buf.Attach(file);
   266 	testWriteL(buf);
   267 	buf.SynchL();
   268 	buf.Reset(KTestFileBufSize);
   269 	test(buf.SizeL()==KTestTotal);
   270 	test(buf.SeekL(buf.EWrite,EStreamBeginning,KTestTotal/2)==KStreamBeginning+KTestTotal/2);
   271 	testWriteL(buf);
   272 	buf.Close();
   273 //
   274 	test.Next(_L("Writing to replaced file"));
   275 	test(buf.Replace(TheFs,parse.NameAndExt(),EFileWrite)==KErrNone);
   276 	testWriteL(buf);
   277 	buf.SynchL();
   278 	buf.File().Close();
   279 	buf.Detach();
   280 //
   281 	test.Next(_L("Writing to temp file"));
   282 	test(buf.Temp(TheFs,parse.DriveAndPath(),TheTempFile,EFileWrite)==KErrNone);
   283 	testWriteL(buf);
   284 	buf.SynchL();
   285 	buf.File().Close();
   286 	buf.Close();
   287 //
   288 	test.Next(_L("Writing to opened file"));
   289 	test(buf.Open(TheFs,parse.NameAndExt(),EFileRead|EFileWrite)==KErrNone);
   290 	testWriteL(buf);
   291 //
   292 	test.Next(_L("Failing to create existing file"));
   293 	test(buf.Create(TheFs,TheTempFile,EFileWrite)==KErrAlreadyExists);
   294 //
   295 	test.Next(_L("Write overtaking read mark"));
   296 	test(buf.SeekL(buf.ERead,KTestLength)==KStreamBeginning+KTestLength);
   297 	RReadStream in(&buf);
   298 	in.ReadL(1);
   299 	test(buf.TellL(buf.ERead)==KStreamBeginning+KTestLength+1);
   300 	test(buf.SeekL(buf.EWrite,EStreamBeginning)==KStreamBeginning);
   301 	testWriteL(buf);
   302 	buf.Close();
   303 	if (TheFs.Delete(parse.NameAndExt())!=KErrNone)
   304 		test.Panic(_L("Deleting file"));
   305 //
   306 	test.Next(_L("Writing to created file"));
   307 	test(buf.Create(TheFs,parse.NameAndExt(),EFileWrite)==KErrNone);
   308 	testWriteL(buf);
   309 	buf.SynchL();
   310 	buf.Close();
   311 	
   312 
   313 	}
   314 /**
   315 @SYMTestCaseID          SYSLIB-STORE-CT-1141
   316 @SYMTestCaseDesc	    Reading from a file buffer test.
   317 @SYMTestPriority 	    High
   318 @SYMTestActions  	    Tests for reading from a file buffer.Tests for panic while opening a file.
   319                         Tests for reading from opened file,and a temporary file.
   320 @SYMTestExpectedResults Test must not fail
   321 @SYMREQ                 REQ0000
   322 */
   323 LOCAL_C void testReadL()
   324 	{
   325 	test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1141 Reading from attached file "));
   326 
   327 	TParsePtrC parse(KFileLocationSpec);
   328 	
   329 	RFile file;
   330 	if (file.Open(TheFs,parse.NameAndExt(),EFileRead)!=KErrNone)
   331 		test.Panic(_L("Opening file"));
   332 	RFileBuf buf(KTestReadBufSize);
   333 	buf.Attach(file);
   334 	test(buf.SeekL(buf.ERead,EStreamBeginning,KTestTotal)==KStreamBeginning+KTestTotal);
   335 	testEofL(buf);
   336 	test(buf.SeekL(buf.ERead,EStreamBeginning)==KStreamBeginning);
   337 	testReadL(buf);
   338 	testEofL(buf);
   339 	buf.SynchL();
   340 	buf.Reset(KTestFileBufSize);
   341 	buf.SeekL(buf.ERead|buf.EWrite,KStreamBeginning);
   342 	testReadL(buf);
   343 	testEofL(buf);
   344 	buf.SynchL();
   345 	buf.Reset(KTestFileBufSize);
   346 	buf.SeekL(buf.ERead|buf.EWrite,KStreamBeginning);
   347 	testStreamBufReadL(buf);
   348 	buf.Close();
   349 	buf.Close();
   350 //
   351 	test.Next(_L("Reading from opened file"));
   352 	test(buf.Open(TheFs,parse.NameAndExt(),EFileRead|EFileWrite)==KErrNone);
   353 	test(buf.SeekL(buf.ERead,EStreamEnd)==KStreamBeginning+KTestTotal);
   354 	testEofL(buf);
   355 	test(buf.SeekL(buf.ERead,EStreamEnd,-KTestTotal)==KStreamBeginning);
   356 	testReadL(buf);
   357 	testEofL(buf);
   358 //
   359 	test.Next(_L("Read overtaking write mark"));
   360 	test(buf.SeekL(buf.EWrite,KTestLength)==KStreamBeginning+KTestLength);
   361 	RWriteStream out(&buf);
   362 	out.WriteL(KTestData,1);
   363 	test(buf.TellL(buf.EWrite)==KStreamBeginning+KTestLength+1);
   364 	test(buf.SeekL(buf.ERead,EStreamBeginning)==KStreamBeginning);
   365 	testReadL(buf);
   366 	testEofL(buf);
   367 	buf.Close();
   368 //
   369 	test.Next(_L("Reading from temp file"));
   370 	test(buf.Open(TheFs,TheTempFile,EFileRead)==KErrNone);
   371 	test(buf.SeekL(buf.ERead,EStreamMark,KTestTotal)==KStreamBeginning+KTestTotal);
   372 	testEofL(buf);
   373 	test(buf.SeekL(buf.ERead,-KTestTotal)==KStreamBeginning);
   374 	testReadL(buf);
   375 	testEofL(buf);
   376 	buf.Close();
   377 	}
   378 /**
   379 @SYMTestCaseID          SYSLIB-STORE-CT-1142
   380 @SYMTestCaseDesc	    Tests for skipping on a file buffer.
   381 @SYMTestPriority 	    High
   382 @SYMTestActions  	    Tests for skipping data while reading.Test for end of file error
   383 @SYMTestExpectedResults Test must not fail
   384 @SYMREQ                 REQ0000
   385 */
   386 LOCAL_C void testSkipL()
   387 	{
   388 	test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1142 Skipping using small transfers "));
   389 
   390 	TParsePtrC parse(KFileLocationSpec);
   391 	
   392 	RFileBuf buf(KTestSkipBufSize);
   393 	test(buf.Open(TheFs,parse.NameAndExt(),EFileRead)==KErrNone);
   394 	testSkipL(buf);
   395 	testEofL(buf);
   396 	buf.SynchL();
   397 	buf.Reset(KTestFileBufSize);
   398 	buf.SeekL(buf.ERead|buf.EWrite,KStreamBeginning);
   399 	testSkipL(buf);
   400 	testEofL(buf);
   401 	buf.Close();
   402 //
   403 	test.Next(_L("Skipping using a single big transfer"));
   404 	test(buf.Open(TheFs,parse.NameAndExt(),EFileRead)==KErrNone);
   405 	RReadStream in(&buf);
   406 	in.ReadL(KTestTotal);
   407 	testEofL(buf);
   408 	buf.Close();
   409 	}
   410 /**
   411 @SYMTestCaseID          SYSLIB-STORE-CT-1143
   412 @SYMTestCaseDesc	    Tests for copying within a single file buffer
   413 @SYMTestPriority 	    High
   414 @SYMTestActions  	    Tests for copying using a different buffer sizes.
   415 @SYMTestExpectedResults Test must not fail
   416 @SYMREQ                 REQ0000
   417 */
   418 LOCAL_C void testCopyL()
   419 	{
   420 	test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1143 Copying using small transfers "));
   421 
   422 	TParsePtrC parse(KFileLocationSpec);
   423 	
   424 	RFileBuf buf(KTestCopyBufSize);
   425 	test(buf.Open(TheFs,TheTempFile,EFileRead|EFileWrite)==KErrNone);
   426 	testCopyL(buf,buf);
   427 	testEofL(buf);
   428 	buf.SynchL();
   429 	buf.Reset(KTestFileBufSize);
   430 	buf.SeekL(buf.ERead,KStreamBeginning);
   431 	testCopyL(buf,buf);
   432 	buf.SeekL(buf.ERead,KStreamBeginning);
   433 	testReadL(buf);
   434 	testReadL(buf);
   435 	testEofL(buf);
   436 	buf.Close();
   437 //
   438 	test.Next(_L("Copying using a single big transfer"));
   439 	test(buf.Open(TheFs,parse.NameAndExt(),EFileRead|EFileWrite)==KErrNone);
   440 	RWriteStream out(&buf);
   441 	RReadStream in(&buf);
   442 	in.ReadL(out,KTestTotal);
   443 	testEofL(buf);
   444 	buf.SeekL(buf.ERead|buf.EWrite,KStreamBeginning);
   445 	out.WriteL(in,KTestTotal);
   446 	testEofL(buf);
   447 	buf.SeekL(buf.ERead|buf.EWrite,KStreamBeginning);
   448 	testReadL(buf);
   449 	testEofL(buf);
   450 	buf.Close();
   451 //
   452 	test.Next(_L("Copying until end of file"));
   453 	test(buf.Open(TheFs,parse.NameAndExt(),EFileRead|EFileWrite)==KErrNone);
   454 	in.ReadL(out);
   455 	testEofL(buf);
   456 	buf.SeekL(buf.ERead|buf.EWrite,KStreamBeginning);
   457 	out.WriteL(in);
   458 	testEofL(buf);
   459 	buf.SeekL(buf.ERead|buf.EWrite,KStreamBeginning);
   460 	testReadL(buf);
   461 	testEofL(buf);
   462 	buf.Close();
   463 	}
   464 
   465 /**
   466 @SYMTestCaseID          SYSLIB-STORE-UT-4005
   467 @SYMTestCaseDesc	    DEF118202 - STORE component, RFileBuf, truncate, file position set incorrectly.
   468 						The test creates an RFileBuf object and writes 30 bytes to the underlying file then
   469 						commits. The file size is checked and should be 30 bytes.
   470 						Then the test writes to the file another 20 bytes, commits and sets the file size to
   471 						be 30 bytes. Then the test checks that the file size is really 30 bytes using
   472 						the RFielBuf::SizeL() function.
   473 @SYMTestPriority 	    High
   474 @SYMTestActions  	    DEF118202 - STORE component, RFileBuf, truncate, file position set incorrectly.
   475 @SYMTestExpectedResults Test must not fail
   476 @SYMDEF                 DEF118202
   477 */
   478 LOCAL_C void DEF118202L()
   479 	{ 
   480 	test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-UT-4005 DEF118202 - STORE component, RFileBuf, truncate, file position set incorrectly "));
   481 
   482 	TParsePtrC parse(KFileLocationSpec);
   483 	
   484 	RFileBuf buf;
   485 	CleanupClosePushL(buf);
   486 	if(buf.Replace(TheFs, parse.NameAndExt(), EFileWrite) != KErrNone)
   487 	     test.Panic(_L("Replacing file"));
   488 	TInt size0 = buf.SizeL();
   489 	test(size0 == 0);
   490 
   491 	buf.WriteL(KTestData10Chars, 10);
   492 	buf.WriteL(KTestData10Chars, 10);
   493 	buf.WriteL(KTestData10Chars, 10);
   494 	buf.SynchL();
   495 	TInt size1 = buf.SizeL();
   496 
   497 	buf.WriteL(KTestData10Chars, 10);
   498 	buf.WriteL(KTestData10Chars, 10);
   499 	buf.SynchL();
   500 
   501 	buf.SetSizeL(30);
   502 	buf.SynchL();
   503 	TInt size2 = buf.SizeL();
   504 
   505 	CleanupStack::PopAndDestroy(&buf);
   506 	if (TheFs.Delete(parse.NameAndExt()) != KErrNone)
   507 		test.Panic(_L("Deleting file"));
   508 
   509 	test(size1 == size2);
   510 	}
   511 
   512 /**
   513 @SYMTestCaseID          PDS-STORE-CT-4017
   514 @SYMTestCaseDesc	    Operation read / write
   515 @SYMTestPriority 	    High
   516 @SYMTestActions  	    Reading and writing RFileBuf using protected API.
   517 @SYMTestExpectedResults Data written must equal data read.
   518 @SYMDEF                 DEF135804
   519 */
   520 
   521 class RFileBufNext: public RFileBuf
   522 	{
   523 	public:
   524 		TInt DoReadL(TDes8& aDes,TInt aMaxLength,TRequestStatus& aStatus)
   525 			{
   526 			return RFileBuf::DoReadL(aDes,aMaxLength,aStatus);
   527 			}
   528 		TInt DoWriteL(const TDesC8& aDes,TInt aMaxLength,TRequestStatus& aStatus)
   529 			{
   530 			return RFileBuf::DoWriteL(aDes,aMaxLength,aStatus);
   531 			}
   532 		TInt Avail(TArea anArea) const
   533 			{
   534 			return TStreamBuf::Avail(anArea);
   535 			}
   536 		TUint8* End(TArea anArea) const
   537 			{
   538 			return TStreamBuf::End(anArea);
   539 			}
   540 		void SetEnd(TArea anArea,TUint8* anEnd)
   541 			{
   542 			TStreamBuf::SetEnd(anArea, anEnd);
   543 			}
   544 	};
   545 
   546 LOCAL_C void testReadWriteL()
   547 	{
   548 	test.Next(_L("@SYMTestCaseID PDS-STORE-CT-4017"));
   549 	_LIT(KFileStore2, "c:\\STOR-TST\\T_FILESTORE.DAT");
   550 	_LIT8(KTestTextBuf, "Ala ma kota, Ola ma psa a osa lata.");
   551 	RFileBufNext fbuf;
   552 	RFs fs;
   553 	test( fs.Connect() == KErrNone );
   554 	fs.Delete(KFileStore2);
   555 	test( fbuf.Create(fs, KFileStore2, EFileWrite ) == KErrNone );
   556 	TRequestStatus status;
   557 	TRAPD(err, fbuf.DoWriteL(KTestTextBuf(),KTestTextBuf().Length(),status) );
   558 	test(err == KErrNone);
   559 	User::WaitForRequest(status);
   560 	TRAP(err, fbuf.SeekL(MStreamBuf::ERead|MStreamBuf::EWrite, 0) );
   561 	test(err == KErrNone);
   562 	TBuf8<250> temp;
   563 	fbuf.DoReadL(temp,temp.MaxLength(),status);
   564 	User::WaitForRequest(status);
   565 	test(temp.Compare(KTestTextBuf)==0);
   566 	
   567 	TInt av = fbuf.Avail(MStreamBuf::ERead);
   568 	av = fbuf.Avail(MStreamBuf::EWrite);
   569 	TUint8* end = fbuf.End(MStreamBuf::ERead);
   570 	fbuf.SetEnd(MStreamBuf::ERead, end-1);
   571 	end = fbuf.End(MStreamBuf::EWrite);
   572 	fbuf.SetEnd(MStreamBuf::EWrite, end-1);
   573 	
   574 	fbuf.Close();
   575 	fs.Delete(KFileStore2);
   576 	fs.Close();
   577 	}
   578 
   579 //
   580 // Prepare the test directory.
   581 //
   582 LOCAL_C void setupTestDirectory()
   583     {
   584 	TInt r=TheFs.Connect();
   585 	test(r==KErrNone);
   586 //
   587 	TDriveUnit drive(static_cast<TUint>(RFs::GetSystemDrive()));	
   588 	TParse parse;
   589 	parse.Set(drive.Name(), &KFileLocationSpec, NULL);
   590 	
   591 	r=TheFs.MkDir(parse.DriveAndPath());
   592 	test(r==KErrNone||r==KErrAlreadyExists);
   593 	r=TheFs.SetSessionPath(parse.DriveAndPath());
   594 	test(r==KErrNone);
   595 	}
   596 
   597 //
   598 // Initialise the cleanup stack.
   599 //
   600 LOCAL_C void setupCleanup()
   601     {
   602 	TheTrapCleanup=CTrapCleanup::New();
   603 	test(TheTrapCleanup!=NULL);
   604 	TRAPD(r,\
   605 		{\
   606 		for (TInt i=KTestCleanupStack;i>0;i--)\
   607 			CleanupStack::PushL((TAny*)1);\
   608 		test(r==KErrNone);\
   609 		CleanupStack::Pop(KTestCleanupStack);\
   610 		});
   611 	test(r==KErrNone);
   612 	}
   613 
   614 LOCAL_C void DeleteDataFile(const TDesC& aFullName)
   615 	{
   616 	RFs fsSession;
   617 	TInt err = fsSession.Connect();
   618 	if(err == KErrNone)
   619 		{
   620 		TEntry entry;
   621 		if(fsSession.Entry(aFullName, entry) == KErrNone)
   622 			{
   623 			RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
   624 			err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
   625 			if(err != KErrNone)
   626 				{
   627 				RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
   628 				}
   629 			err = fsSession.Delete(aFullName);
   630 			if(err != KErrNone)
   631 				{
   632 				RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
   633 				}
   634 			}
   635 		fsSession.Close();
   636 		}
   637 	else
   638 		{
   639 		RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
   640 		}
   641 	}
   642 
   643 //
   644 // Test file-based stream buffer.
   645 //
   646 GLDEF_C TInt E32Main()
   647     {
   648 	test.Title();
   649 	setupTestDirectory();
   650 	setupCleanup();
   651 	__UHEAP_MARK;
   652 
   653 	test.Start(_L("Test file-based stream buffer"));
   654 	TRAPD(r,testWriteL());
   655 	test(r==KErrNone);
   656 	TRAP(r,testReadL());
   657 	test(r==KErrNone);
   658 	TRAP(r,testSkipL());
   659 	test(r==KErrNone);
   660 	TRAP(r,testCopyL());
   661 	test(r==KErrNone);
   662 	TRAP(r, DEF118202L());
   663 	test(r==KErrNone);
   664 	TRAP(r, testReadWriteL());
   665 	test(r==KErrNone);
   666 	
   667 	
   668 	//deletion of data files must be before call to .End() - DEF047652
   669 	TDriveUnit drive(static_cast<TUint>(RFs::GetSystemDrive()));	
   670 	TParse parse;
   671 	parse.Set(drive.Name(), &KFileLocationSpec, NULL);
   672 	::DeleteDataFile(parse.FullName());
   673 
   674 	test.End(); 
   675 	
   676 	__UHEAP_MARKEND;
   677 
   678 	delete TheTrapCleanup;
   679 	if (TheFs.Delete(TheTempFile)!=KErrNone)
   680 		test.Panic(_L("Deleting temp file"));
   681 	TheFs.Close();
   682 	test.Close();
   683 	return 0;
   684     }
   685