os/persistentdata/persistentstorage/store/TFILE/t_storfbuf.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/store/TFILE/t_storfbuf.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,685 @@
     1.4 +// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include <s32file.h>
    1.20 +#include <e32test.h>
    1.21 +
    1.22 +const TInt KTestCleanupStack=0x20;
    1.23 +
    1.24 +// This is a path specification and should not be used as is
    1.25 +_LIT(KFileLocationSpec, "Z:\\STOR-TST\\T_FBUF.DAT");
    1.26 +const TUint8* KTestData=_S8("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");
    1.27 +const TUint8* KTestDataLong=_S8("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0");
    1.28 +const TUint8* KTestData10Chars = _S8("0123456789");
    1.29 +
    1.30 +const TInt KTestLength=36;
    1.31 +const TInt KTestTotal=KTestLength*(KTestLength+1);
    1.32 +const TPtrC8 KTestDes(KTestData,KTestLength);
    1.33 +const TPtrC8 KTestDesLong(KTestDataLong,KTestLength+1);
    1.34 +const TInt KTestFileBufSize=7;
    1.35 +const TInt KTestWriteBufSize=5;
    1.36 +const TInt KTestReadBufSize=3;
    1.37 +const TInt KTestSkipBufSize=2;
    1.38 +const TInt KTestCopyBufSize=1;
    1.39 +
    1.40 +LOCAL_D CTrapCleanup* TheTrapCleanup;
    1.41 +LOCAL_D RTest test(_L("t_storfbuf"));
    1.42 +LOCAL_D RFs TheFs;
    1.43 +LOCAL_D TFileName TheTempFile;
    1.44 +
    1.45 +/**
    1.46 +@SYMTestCaseID          SYSLIB-STORE-CT-1136
    1.47 +@SYMTestCaseDesc	    Writing to a stream buffer test
    1.48 +@SYMTestPriority 	    High
    1.49 +@SYMTestActions  	    Tests for RWriteStream::WriteL() function
    1.50 +@SYMTestExpectedResults Test must not fail
    1.51 +@SYMREQ                 REQ0000
    1.52 +*/
    1.53 +LOCAL_C void testWriteL(RWriteStream& aStream)
    1.54 +	{
    1.55 +	test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1136 Writing... "));
    1.56 +	for (TInt i=0;i<=KTestLength;++i)
    1.57 +		{
    1.58 +		aStream.WriteL(KTestDes,i);
    1.59 +		aStream.WriteL(&KTestData[i],KTestLength-i);
    1.60 +		}
    1.61 +	}
    1.62 +
    1.63 +/**
    1.64 +@SYMTestCaseID          SYSLIB-STORE-CT-1137
    1.65 +@SYMTestCaseDesc	    Reading from a stream buffer test
    1.66 +@SYMTestPriority 	    High
    1.67 +@SYMTestActions  	    Tests for RReadStream::ReadL() function
    1.68 +@SYMTestExpectedResults Test must not fail
    1.69 +@SYMREQ                 REQ0000
    1.70 +*/
    1.71 +LOCAL_C void testReadL(RReadStream& aStream)
    1.72 +	{
    1.73 +	test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1137 Reading... "));
    1.74 +	for (TInt i=KTestLength;i>=0;--i)
    1.75 +		{
    1.76 +		TBuf8<KTestLength+1> buf;
    1.77 +		aStream.ReadL(buf,i);
    1.78 +		test(buf.Length()==i);
    1.79 +		buf.SetMax();
    1.80 +		aStream.ReadL(&buf[i],KTestLength-i);
    1.81 +		buf.SetLength(KTestLength);
    1.82 +		test(buf==KTestDes);
    1.83 +		}
    1.84 +	}
    1.85 +
    1.86 +/**
    1.87 +@SYMTestCaseID          SYSLIB-STORE-CT-1138
    1.88 +@SYMTestCaseDesc	    Skipping data on a stream buffer test.
    1.89 +@SYMTestPriority 	    High
    1.90 +@SYMTestActions  	    Tests skipping data while reading from a stream
    1.91 +@SYMTestExpectedResults Test must not fail
    1.92 +@SYMREQ                 REQ0000
    1.93 +*/
    1.94 +LOCAL_C void testSkipL(RReadStream& aStream)
    1.95 +	{
    1.96 +	test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1138 Skipping... "));
    1.97 +	for (TInt i=0;i<=KTestLength;++i)
    1.98 +		{
    1.99 +		aStream.ReadL(i);
   1.100 +		aStream.ReadL(KTestLength-i);
   1.101 +		}
   1.102 +	}
   1.103 +
   1.104 +/**
   1.105 +@SYMTestCaseID          SYSLIB-STORE-CT-1139
   1.106 +@SYMTestCaseDesc	    Tests a stream buffer is at end-of-file.
   1.107 +@SYMTestPriority 	    High
   1.108 +@SYMTestActions  	    Tests for end of file while reading from a stream buffer
   1.109 +@SYMTestExpectedResults Test must not fail
   1.110 +@SYMREQ                 REQ0000
   1.111 +*/
   1.112 +LOCAL_C void testEofL(RReadStream& aStream)
   1.113 +	{
   1.114 +	test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1139 At end "));
   1.115 +	TUint8 b;
   1.116 +	test(aStream.Source()->ReadL(&b,1)==0);
   1.117 +	}
   1.118 +
   1.119 +//
   1.120 +// Test copying from one stream to another.
   1.121 +//
   1.122 +LOCAL_C void testCopyL(RWriteStream& aWriteStream,RReadStream& aReadStream)
   1.123 +	{
   1.124 +	test.Next(_L("Copying"));
   1.125 +	for (TInt i=KTestLength;i>=0;--i)
   1.126 +		{
   1.127 +		aWriteStream.WriteL(aReadStream,i);
   1.128 +		aReadStream.ReadL(aWriteStream,KTestLength-i);
   1.129 +		}
   1.130 +	}
   1.131 +
   1.132 +//
   1.133 +// Test writing to a stream buffer.
   1.134 +//
   1.135 +LOCAL_C void testWriteL(MStreamBuf& aBuf)
   1.136 +	{
   1.137 +	RWriteStream stream(&aBuf);
   1.138 +	testWriteL(stream);
   1.139 +	}
   1.140 +
   1.141 +//
   1.142 +// Test reading from a stream buffer.
   1.143 +//
   1.144 +LOCAL_C void testReadL(MStreamBuf& aBuf)
   1.145 +	{
   1.146 +	RReadStream stream(&aBuf);
   1.147 +	testReadL(stream);
   1.148 +	}
   1.149 +
   1.150 +//
   1.151 +// Test skipping data on a stream buffer.
   1.152 +//
   1.153 +LOCAL_C void testSkipL(MStreamBuf& aBuf)
   1.154 +	{
   1.155 +	RReadStream stream(&aBuf);
   1.156 +	testSkipL(stream);
   1.157 +	}
   1.158 +
   1.159 +//
   1.160 +// Test a stream buffer is at end-of-file.
   1.161 +//
   1.162 +LOCAL_C void testEofL(MStreamBuf& aBuf)
   1.163 +	{
   1.164 +	RReadStream stream(&aBuf);
   1.165 +	testEofL(stream);
   1.166 +	}
   1.167 +
   1.168 +//
   1.169 +// Test copying from one stream buffer to another.
   1.170 +//
   1.171 +LOCAL_C void testCopyL(MStreamBuf& aSink,MStreamBuf& aSource)
   1.172 +	{
   1.173 +	RWriteStream out(&aSink);
   1.174 +	RReadStream in(&aSource);
   1.175 +	testCopyL(out,in);
   1.176 +	}
   1.177 +/**
   1.178 +@SYMTestCaseID          PDS-STORE-CT-4027
   1.179 +@SYMTestCaseDesc	    Writing to a stream buffer test
   1.180 +@SYMTestPriority 	    High
   1.181 +@SYMTestActions  	    Validate the MStreamBuf Write API
   1.182 +@SYMTestExpectedResults Test must not fail
   1.183 +@SYMDEF                 DEF135804
   1.184 +*/
   1.185 +LOCAL_C void testStreamBufWriteL(MStreamBuf& aBuf)
   1.186 +	{
   1.187 +	test.Next(_L(" @SYMTestCaseID:PDS-STORE-CT-4027 Writing... "));
   1.188 +	TRequestStatus status;
   1.189 +	aBuf.Write(KTestDes,status);
   1.190 +	User::WaitForRequest(status);
   1.191 +	
   1.192 +	aBuf.SeekL(aBuf.EWrite,EStreamBeginning,0);
   1.193 +	aBuf.WriteL(KTestDes,status);
   1.194 +	User::WaitForRequest(status);
   1.195 +	
   1.196 +	}
   1.197 +
   1.198 +/**
   1.199 +@SYMTestCaseID          PDS-STORE-CT-4026
   1.200 +@SYMTestCaseDesc	    Reading from a stream buffer test
   1.201 +@SYMTestPriority 	    High
   1.202 +@SYMTestActions  	    Validate the MStreamBuf Read API
   1.203 +@SYMTestExpectedResults Test must not fail
   1.204 +@SYMDEF                 DEF135804
   1.205 +*/
   1.206 +LOCAL_C void testStreamBufReadL(MStreamBuf& aBuf)
   1.207 +	{
   1.208 +	test.Next(_L(" @SYMTestCaseID:PDS-STORE-CT-4026 Reading... "));
   1.209 +	TRequestStatus status;
   1.210 +	
   1.211 +	TBuf8<KTestLength+1> buf;
   1.212 +	aBuf.Read(buf, KTestLength, status);
   1.213 +	User::WaitForRequest(status);
   1.214 +	test(buf.Length()==KTestLength);
   1.215 +	test(buf==KTestDes);
   1.216 +	
   1.217 +	aBuf.SeekL(aBuf.ERead,EStreamBeginning,0);
   1.218 +	aBuf.ReadL(buf, status);
   1.219 +	User::WaitForRequest(status);
   1.220 +	test(buf.Length()== KTestLength+1);
   1.221 +	test(buf==KTestDesLong);
   1.222 +
   1.223 +	aBuf.SeekL(aBuf.ERead,EStreamBeginning,0);
   1.224 +	aBuf.Read(buf, status);
   1.225 +	User::WaitForRequest(status);
   1.226 +	test(buf.Length()== KTestLength+1);
   1.227 +	test(buf==KTestDesLong);
   1.228 +
   1.229 +	}
   1.230 +/**
   1.231 +@SYMTestCaseID          SYSLIB-STORE-CT-1140
   1.232 +@SYMTestCaseDesc	    Write to a file buffer test.
   1.233 +@SYMTestPriority 	    High
   1.234 +@SYMTestActions  	    Tests for writing to an attached file,a replaced file,a temporary file,an opened file
   1.235 +						Tests for replacing an existing file,test for deleting a file.
   1.236 +						Tests for writing to a new file buffer after the deletion of old file.
   1.237 +@SYMTestExpectedResults Test must not fail
   1.238 +@SYMREQ                 REQ0000
   1.239 +*/
   1.240 +LOCAL_C void testWriteL()
   1.241 +	{
   1.242 +	test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1140 Writing to attached file "));
   1.243 +
   1.244 +	
   1.245 +	TDriveUnit drive(static_cast<TUint>(RFs::GetSystemDrive()));	
   1.246 +	TParse parse;
   1.247 +	parse.Set(drive.Name(), &KFileLocationSpec, NULL);
   1.248 +	
   1.249 +	
   1.250 +	
   1.251 +	RFile file;
   1.252 +	if (file.Replace(TheFs,parse.NameAndExt(),EFileWrite)!=KErrNone)
   1.253 +		test.Panic(_L("Replacing file"));
   1.254 +	RFileBuf rbuf(KTestWriteBufSize);
   1.255 +	RFile file2 = file;//Keep a copy in file2, because Attach() will clear the passed RFile parameter
   1.256 +	rbuf.Attach(file);
   1.257 +	rbuf.Detach();
   1.258 +	rbuf.Reattach(file2);
   1.259 +	testStreamBufWriteL(rbuf);
   1.260 +	rbuf.SynchL();
   1.261 +	rbuf.Close();
   1.262 +	if (TheFs.Delete(parse.NameAndExt())!=KErrNone)
   1.263 +			test.Panic(_L("Deleting file"));
   1.264 +
   1.265 +	if (file.Replace(TheFs,parse.NameAndExt(),EFileWrite)!=KErrNone)
   1.266 +			test.Panic(_L("Replacing file"));
   1.267 +	RFileBuf buf(KTestWriteBufSize);
   1.268 +	buf.Attach(file);
   1.269 +	testWriteL(buf);
   1.270 +	buf.SynchL();
   1.271 +	buf.Reset(KTestFileBufSize);
   1.272 +	test(buf.SizeL()==KTestTotal);
   1.273 +	test(buf.SeekL(buf.EWrite,EStreamBeginning,KTestTotal/2)==KStreamBeginning+KTestTotal/2);
   1.274 +	testWriteL(buf);
   1.275 +	buf.Close();
   1.276 +//
   1.277 +	test.Next(_L("Writing to replaced file"));
   1.278 +	test(buf.Replace(TheFs,parse.NameAndExt(),EFileWrite)==KErrNone);
   1.279 +	testWriteL(buf);
   1.280 +	buf.SynchL();
   1.281 +	buf.File().Close();
   1.282 +	buf.Detach();
   1.283 +//
   1.284 +	test.Next(_L("Writing to temp file"));
   1.285 +	test(buf.Temp(TheFs,parse.DriveAndPath(),TheTempFile,EFileWrite)==KErrNone);
   1.286 +	testWriteL(buf);
   1.287 +	buf.SynchL();
   1.288 +	buf.File().Close();
   1.289 +	buf.Close();
   1.290 +//
   1.291 +	test.Next(_L("Writing to opened file"));
   1.292 +	test(buf.Open(TheFs,parse.NameAndExt(),EFileRead|EFileWrite)==KErrNone);
   1.293 +	testWriteL(buf);
   1.294 +//
   1.295 +	test.Next(_L("Failing to create existing file"));
   1.296 +	test(buf.Create(TheFs,TheTempFile,EFileWrite)==KErrAlreadyExists);
   1.297 +//
   1.298 +	test.Next(_L("Write overtaking read mark"));
   1.299 +	test(buf.SeekL(buf.ERead,KTestLength)==KStreamBeginning+KTestLength);
   1.300 +	RReadStream in(&buf);
   1.301 +	in.ReadL(1);
   1.302 +	test(buf.TellL(buf.ERead)==KStreamBeginning+KTestLength+1);
   1.303 +	test(buf.SeekL(buf.EWrite,EStreamBeginning)==KStreamBeginning);
   1.304 +	testWriteL(buf);
   1.305 +	buf.Close();
   1.306 +	if (TheFs.Delete(parse.NameAndExt())!=KErrNone)
   1.307 +		test.Panic(_L("Deleting file"));
   1.308 +//
   1.309 +	test.Next(_L("Writing to created file"));
   1.310 +	test(buf.Create(TheFs,parse.NameAndExt(),EFileWrite)==KErrNone);
   1.311 +	testWriteL(buf);
   1.312 +	buf.SynchL();
   1.313 +	buf.Close();
   1.314 +	
   1.315 +
   1.316 +	}
   1.317 +/**
   1.318 +@SYMTestCaseID          SYSLIB-STORE-CT-1141
   1.319 +@SYMTestCaseDesc	    Reading from a file buffer test.
   1.320 +@SYMTestPriority 	    High
   1.321 +@SYMTestActions  	    Tests for reading from a file buffer.Tests for panic while opening a file.
   1.322 +                        Tests for reading from opened file,and a temporary file.
   1.323 +@SYMTestExpectedResults Test must not fail
   1.324 +@SYMREQ                 REQ0000
   1.325 +*/
   1.326 +LOCAL_C void testReadL()
   1.327 +	{
   1.328 +	test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1141 Reading from attached file "));
   1.329 +
   1.330 +	TParsePtrC parse(KFileLocationSpec);
   1.331 +	
   1.332 +	RFile file;
   1.333 +	if (file.Open(TheFs,parse.NameAndExt(),EFileRead)!=KErrNone)
   1.334 +		test.Panic(_L("Opening file"));
   1.335 +	RFileBuf buf(KTestReadBufSize);
   1.336 +	buf.Attach(file);
   1.337 +	test(buf.SeekL(buf.ERead,EStreamBeginning,KTestTotal)==KStreamBeginning+KTestTotal);
   1.338 +	testEofL(buf);
   1.339 +	test(buf.SeekL(buf.ERead,EStreamBeginning)==KStreamBeginning);
   1.340 +	testReadL(buf);
   1.341 +	testEofL(buf);
   1.342 +	buf.SynchL();
   1.343 +	buf.Reset(KTestFileBufSize);
   1.344 +	buf.SeekL(buf.ERead|buf.EWrite,KStreamBeginning);
   1.345 +	testReadL(buf);
   1.346 +	testEofL(buf);
   1.347 +	buf.SynchL();
   1.348 +	buf.Reset(KTestFileBufSize);
   1.349 +	buf.SeekL(buf.ERead|buf.EWrite,KStreamBeginning);
   1.350 +	testStreamBufReadL(buf);
   1.351 +	buf.Close();
   1.352 +	buf.Close();
   1.353 +//
   1.354 +	test.Next(_L("Reading from opened file"));
   1.355 +	test(buf.Open(TheFs,parse.NameAndExt(),EFileRead|EFileWrite)==KErrNone);
   1.356 +	test(buf.SeekL(buf.ERead,EStreamEnd)==KStreamBeginning+KTestTotal);
   1.357 +	testEofL(buf);
   1.358 +	test(buf.SeekL(buf.ERead,EStreamEnd,-KTestTotal)==KStreamBeginning);
   1.359 +	testReadL(buf);
   1.360 +	testEofL(buf);
   1.361 +//
   1.362 +	test.Next(_L("Read overtaking write mark"));
   1.363 +	test(buf.SeekL(buf.EWrite,KTestLength)==KStreamBeginning+KTestLength);
   1.364 +	RWriteStream out(&buf);
   1.365 +	out.WriteL(KTestData,1);
   1.366 +	test(buf.TellL(buf.EWrite)==KStreamBeginning+KTestLength+1);
   1.367 +	test(buf.SeekL(buf.ERead,EStreamBeginning)==KStreamBeginning);
   1.368 +	testReadL(buf);
   1.369 +	testEofL(buf);
   1.370 +	buf.Close();
   1.371 +//
   1.372 +	test.Next(_L("Reading from temp file"));
   1.373 +	test(buf.Open(TheFs,TheTempFile,EFileRead)==KErrNone);
   1.374 +	test(buf.SeekL(buf.ERead,EStreamMark,KTestTotal)==KStreamBeginning+KTestTotal);
   1.375 +	testEofL(buf);
   1.376 +	test(buf.SeekL(buf.ERead,-KTestTotal)==KStreamBeginning);
   1.377 +	testReadL(buf);
   1.378 +	testEofL(buf);
   1.379 +	buf.Close();
   1.380 +	}
   1.381 +/**
   1.382 +@SYMTestCaseID          SYSLIB-STORE-CT-1142
   1.383 +@SYMTestCaseDesc	    Tests for skipping on a file buffer.
   1.384 +@SYMTestPriority 	    High
   1.385 +@SYMTestActions  	    Tests for skipping data while reading.Test for end of file error
   1.386 +@SYMTestExpectedResults Test must not fail
   1.387 +@SYMREQ                 REQ0000
   1.388 +*/
   1.389 +LOCAL_C void testSkipL()
   1.390 +	{
   1.391 +	test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1142 Skipping using small transfers "));
   1.392 +
   1.393 +	TParsePtrC parse(KFileLocationSpec);
   1.394 +	
   1.395 +	RFileBuf buf(KTestSkipBufSize);
   1.396 +	test(buf.Open(TheFs,parse.NameAndExt(),EFileRead)==KErrNone);
   1.397 +	testSkipL(buf);
   1.398 +	testEofL(buf);
   1.399 +	buf.SynchL();
   1.400 +	buf.Reset(KTestFileBufSize);
   1.401 +	buf.SeekL(buf.ERead|buf.EWrite,KStreamBeginning);
   1.402 +	testSkipL(buf);
   1.403 +	testEofL(buf);
   1.404 +	buf.Close();
   1.405 +//
   1.406 +	test.Next(_L("Skipping using a single big transfer"));
   1.407 +	test(buf.Open(TheFs,parse.NameAndExt(),EFileRead)==KErrNone);
   1.408 +	RReadStream in(&buf);
   1.409 +	in.ReadL(KTestTotal);
   1.410 +	testEofL(buf);
   1.411 +	buf.Close();
   1.412 +	}
   1.413 +/**
   1.414 +@SYMTestCaseID          SYSLIB-STORE-CT-1143
   1.415 +@SYMTestCaseDesc	    Tests for copying within a single file buffer
   1.416 +@SYMTestPriority 	    High
   1.417 +@SYMTestActions  	    Tests for copying using a different buffer sizes.
   1.418 +@SYMTestExpectedResults Test must not fail
   1.419 +@SYMREQ                 REQ0000
   1.420 +*/
   1.421 +LOCAL_C void testCopyL()
   1.422 +	{
   1.423 +	test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1143 Copying using small transfers "));
   1.424 +
   1.425 +	TParsePtrC parse(KFileLocationSpec);
   1.426 +	
   1.427 +	RFileBuf buf(KTestCopyBufSize);
   1.428 +	test(buf.Open(TheFs,TheTempFile,EFileRead|EFileWrite)==KErrNone);
   1.429 +	testCopyL(buf,buf);
   1.430 +	testEofL(buf);
   1.431 +	buf.SynchL();
   1.432 +	buf.Reset(KTestFileBufSize);
   1.433 +	buf.SeekL(buf.ERead,KStreamBeginning);
   1.434 +	testCopyL(buf,buf);
   1.435 +	buf.SeekL(buf.ERead,KStreamBeginning);
   1.436 +	testReadL(buf);
   1.437 +	testReadL(buf);
   1.438 +	testEofL(buf);
   1.439 +	buf.Close();
   1.440 +//
   1.441 +	test.Next(_L("Copying using a single big transfer"));
   1.442 +	test(buf.Open(TheFs,parse.NameAndExt(),EFileRead|EFileWrite)==KErrNone);
   1.443 +	RWriteStream out(&buf);
   1.444 +	RReadStream in(&buf);
   1.445 +	in.ReadL(out,KTestTotal);
   1.446 +	testEofL(buf);
   1.447 +	buf.SeekL(buf.ERead|buf.EWrite,KStreamBeginning);
   1.448 +	out.WriteL(in,KTestTotal);
   1.449 +	testEofL(buf);
   1.450 +	buf.SeekL(buf.ERead|buf.EWrite,KStreamBeginning);
   1.451 +	testReadL(buf);
   1.452 +	testEofL(buf);
   1.453 +	buf.Close();
   1.454 +//
   1.455 +	test.Next(_L("Copying until end of file"));
   1.456 +	test(buf.Open(TheFs,parse.NameAndExt(),EFileRead|EFileWrite)==KErrNone);
   1.457 +	in.ReadL(out);
   1.458 +	testEofL(buf);
   1.459 +	buf.SeekL(buf.ERead|buf.EWrite,KStreamBeginning);
   1.460 +	out.WriteL(in);
   1.461 +	testEofL(buf);
   1.462 +	buf.SeekL(buf.ERead|buf.EWrite,KStreamBeginning);
   1.463 +	testReadL(buf);
   1.464 +	testEofL(buf);
   1.465 +	buf.Close();
   1.466 +	}
   1.467 +
   1.468 +/**
   1.469 +@SYMTestCaseID          SYSLIB-STORE-UT-4005
   1.470 +@SYMTestCaseDesc	    DEF118202 - STORE component, RFileBuf, truncate, file position set incorrectly.
   1.471 +						The test creates an RFileBuf object and writes 30 bytes to the underlying file then
   1.472 +						commits. The file size is checked and should be 30 bytes.
   1.473 +						Then the test writes to the file another 20 bytes, commits and sets the file size to
   1.474 +						be 30 bytes. Then the test checks that the file size is really 30 bytes using
   1.475 +						the RFielBuf::SizeL() function.
   1.476 +@SYMTestPriority 	    High
   1.477 +@SYMTestActions  	    DEF118202 - STORE component, RFileBuf, truncate, file position set incorrectly.
   1.478 +@SYMTestExpectedResults Test must not fail
   1.479 +@SYMDEF                 DEF118202
   1.480 +*/
   1.481 +LOCAL_C void DEF118202L()
   1.482 +	{ 
   1.483 +	test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-UT-4005 DEF118202 - STORE component, RFileBuf, truncate, file position set incorrectly "));
   1.484 +
   1.485 +	TParsePtrC parse(KFileLocationSpec);
   1.486 +	
   1.487 +	RFileBuf buf;
   1.488 +	CleanupClosePushL(buf);
   1.489 +	if(buf.Replace(TheFs, parse.NameAndExt(), EFileWrite) != KErrNone)
   1.490 +	     test.Panic(_L("Replacing file"));
   1.491 +	TInt size0 = buf.SizeL();
   1.492 +	test(size0 == 0);
   1.493 +
   1.494 +	buf.WriteL(KTestData10Chars, 10);
   1.495 +	buf.WriteL(KTestData10Chars, 10);
   1.496 +	buf.WriteL(KTestData10Chars, 10);
   1.497 +	buf.SynchL();
   1.498 +	TInt size1 = buf.SizeL();
   1.499 +
   1.500 +	buf.WriteL(KTestData10Chars, 10);
   1.501 +	buf.WriteL(KTestData10Chars, 10);
   1.502 +	buf.SynchL();
   1.503 +
   1.504 +	buf.SetSizeL(30);
   1.505 +	buf.SynchL();
   1.506 +	TInt size2 = buf.SizeL();
   1.507 +
   1.508 +	CleanupStack::PopAndDestroy(&buf);
   1.509 +	if (TheFs.Delete(parse.NameAndExt()) != KErrNone)
   1.510 +		test.Panic(_L("Deleting file"));
   1.511 +
   1.512 +	test(size1 == size2);
   1.513 +	}
   1.514 +
   1.515 +/**
   1.516 +@SYMTestCaseID          PDS-STORE-CT-4017
   1.517 +@SYMTestCaseDesc	    Operation read / write
   1.518 +@SYMTestPriority 	    High
   1.519 +@SYMTestActions  	    Reading and writing RFileBuf using protected API.
   1.520 +@SYMTestExpectedResults Data written must equal data read.
   1.521 +@SYMDEF                 DEF135804
   1.522 +*/
   1.523 +
   1.524 +class RFileBufNext: public RFileBuf
   1.525 +	{
   1.526 +	public:
   1.527 +		TInt DoReadL(TDes8& aDes,TInt aMaxLength,TRequestStatus& aStatus)
   1.528 +			{
   1.529 +			return RFileBuf::DoReadL(aDes,aMaxLength,aStatus);
   1.530 +			}
   1.531 +		TInt DoWriteL(const TDesC8& aDes,TInt aMaxLength,TRequestStatus& aStatus)
   1.532 +			{
   1.533 +			return RFileBuf::DoWriteL(aDes,aMaxLength,aStatus);
   1.534 +			}
   1.535 +		TInt Avail(TArea anArea) const
   1.536 +			{
   1.537 +			return TStreamBuf::Avail(anArea);
   1.538 +			}
   1.539 +		TUint8* End(TArea anArea) const
   1.540 +			{
   1.541 +			return TStreamBuf::End(anArea);
   1.542 +			}
   1.543 +		void SetEnd(TArea anArea,TUint8* anEnd)
   1.544 +			{
   1.545 +			TStreamBuf::SetEnd(anArea, anEnd);
   1.546 +			}
   1.547 +	};
   1.548 +
   1.549 +LOCAL_C void testReadWriteL()
   1.550 +	{
   1.551 +	test.Next(_L("@SYMTestCaseID PDS-STORE-CT-4017"));
   1.552 +	_LIT(KFileStore2, "c:\\STOR-TST\\T_FILESTORE.DAT");
   1.553 +	_LIT8(KTestTextBuf, "Ala ma kota, Ola ma psa a osa lata.");
   1.554 +	RFileBufNext fbuf;
   1.555 +	RFs fs;
   1.556 +	test( fs.Connect() == KErrNone );
   1.557 +	fs.Delete(KFileStore2);
   1.558 +	test( fbuf.Create(fs, KFileStore2, EFileWrite ) == KErrNone );
   1.559 +	TRequestStatus status;
   1.560 +	TRAPD(err, fbuf.DoWriteL(KTestTextBuf(),KTestTextBuf().Length(),status) );
   1.561 +	test(err == KErrNone);
   1.562 +	User::WaitForRequest(status);
   1.563 +	TRAP(err, fbuf.SeekL(MStreamBuf::ERead|MStreamBuf::EWrite, 0) );
   1.564 +	test(err == KErrNone);
   1.565 +	TBuf8<250> temp;
   1.566 +	fbuf.DoReadL(temp,temp.MaxLength(),status);
   1.567 +	User::WaitForRequest(status);
   1.568 +	test(temp.Compare(KTestTextBuf)==0);
   1.569 +	
   1.570 +	TInt av = fbuf.Avail(MStreamBuf::ERead);
   1.571 +	av = fbuf.Avail(MStreamBuf::EWrite);
   1.572 +	TUint8* end = fbuf.End(MStreamBuf::ERead);
   1.573 +	fbuf.SetEnd(MStreamBuf::ERead, end-1);
   1.574 +	end = fbuf.End(MStreamBuf::EWrite);
   1.575 +	fbuf.SetEnd(MStreamBuf::EWrite, end-1);
   1.576 +	
   1.577 +	fbuf.Close();
   1.578 +	fs.Delete(KFileStore2);
   1.579 +	fs.Close();
   1.580 +	}
   1.581 +
   1.582 +//
   1.583 +// Prepare the test directory.
   1.584 +//
   1.585 +LOCAL_C void setupTestDirectory()
   1.586 +    {
   1.587 +	TInt r=TheFs.Connect();
   1.588 +	test(r==KErrNone);
   1.589 +//
   1.590 +	TDriveUnit drive(static_cast<TUint>(RFs::GetSystemDrive()));	
   1.591 +	TParse parse;
   1.592 +	parse.Set(drive.Name(), &KFileLocationSpec, NULL);
   1.593 +	
   1.594 +	r=TheFs.MkDir(parse.DriveAndPath());
   1.595 +	test(r==KErrNone||r==KErrAlreadyExists);
   1.596 +	r=TheFs.SetSessionPath(parse.DriveAndPath());
   1.597 +	test(r==KErrNone);
   1.598 +	}
   1.599 +
   1.600 +//
   1.601 +// Initialise the cleanup stack.
   1.602 +//
   1.603 +LOCAL_C void setupCleanup()
   1.604 +    {
   1.605 +	TheTrapCleanup=CTrapCleanup::New();
   1.606 +	test(TheTrapCleanup!=NULL);
   1.607 +	TRAPD(r,\
   1.608 +		{\
   1.609 +		for (TInt i=KTestCleanupStack;i>0;i--)\
   1.610 +			CleanupStack::PushL((TAny*)1);\
   1.611 +		test(r==KErrNone);\
   1.612 +		CleanupStack::Pop(KTestCleanupStack);\
   1.613 +		});
   1.614 +	test(r==KErrNone);
   1.615 +	}
   1.616 +
   1.617 +LOCAL_C void DeleteDataFile(const TDesC& aFullName)
   1.618 +	{
   1.619 +	RFs fsSession;
   1.620 +	TInt err = fsSession.Connect();
   1.621 +	if(err == KErrNone)
   1.622 +		{
   1.623 +		TEntry entry;
   1.624 +		if(fsSession.Entry(aFullName, entry) == KErrNone)
   1.625 +			{
   1.626 +			RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
   1.627 +			err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
   1.628 +			if(err != KErrNone)
   1.629 +				{
   1.630 +				RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
   1.631 +				}
   1.632 +			err = fsSession.Delete(aFullName);
   1.633 +			if(err != KErrNone)
   1.634 +				{
   1.635 +				RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
   1.636 +				}
   1.637 +			}
   1.638 +		fsSession.Close();
   1.639 +		}
   1.640 +	else
   1.641 +		{
   1.642 +		RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
   1.643 +		}
   1.644 +	}
   1.645 +
   1.646 +//
   1.647 +// Test file-based stream buffer.
   1.648 +//
   1.649 +GLDEF_C TInt E32Main()
   1.650 +    {
   1.651 +	test.Title();
   1.652 +	setupTestDirectory();
   1.653 +	setupCleanup();
   1.654 +	__UHEAP_MARK;
   1.655 +
   1.656 +	test.Start(_L("Test file-based stream buffer"));
   1.657 +	TRAPD(r,testWriteL());
   1.658 +	test(r==KErrNone);
   1.659 +	TRAP(r,testReadL());
   1.660 +	test(r==KErrNone);
   1.661 +	TRAP(r,testSkipL());
   1.662 +	test(r==KErrNone);
   1.663 +	TRAP(r,testCopyL());
   1.664 +	test(r==KErrNone);
   1.665 +	TRAP(r, DEF118202L());
   1.666 +	test(r==KErrNone);
   1.667 +	TRAP(r, testReadWriteL());
   1.668 +	test(r==KErrNone);
   1.669 +	
   1.670 +	
   1.671 +	//deletion of data files must be before call to .End() - DEF047652
   1.672 +	TDriveUnit drive(static_cast<TUint>(RFs::GetSystemDrive()));	
   1.673 +	TParse parse;
   1.674 +	parse.Set(drive.Name(), &KFileLocationSpec, NULL);
   1.675 +	::DeleteDataFile(parse.FullName());
   1.676 +
   1.677 +	test.End(); 
   1.678 +	
   1.679 +	__UHEAP_MARKEND;
   1.680 +
   1.681 +	delete TheTrapCleanup;
   1.682 +	if (TheFs.Delete(TheTempFile)!=KErrNone)
   1.683 +		test.Panic(_L("Deleting temp file"));
   1.684 +	TheFs.Close();
   1.685 +	test.Close();
   1.686 +	return 0;
   1.687 +    }
   1.688 +