os/persistentdata/persistentstorage/store/TSTOR/t_stortoc.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/store/TSTOR/t_stortoc.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,651 @@
     1.4 +// Copyright (c) 2008-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 <e32test.h>
    1.20 +#include <s32file.h>
    1.21 +#include <s32fileiter.h>
    1.22 +
    1.23 +RTest TheTest(_L("t_storetoc test"));
    1.24 +RFs TheFs;
    1.25 +
    1.26 +TBuf<KMaxFileName> TheFileName;
    1.27 +
    1.28 +CPermanentFileStore* TheStore = NULL;
    1.29 +
    1.30 +void DeleteTestFiles()
    1.31 +	{
    1.32 +	delete TheStore;
    1.33 +	TheStore = NULL;
    1.34 +	(void)TheFs.Delete(TheFileName);
    1.35 +	}
    1.36 +
    1.37 +///////////////////////////////////////////////////////////////////////////////////////
    1.38 +///////////////////////////////////////////////////////////////////////////////////////
    1.39 +//Test macros and functions
    1.40 +void Check(TInt aValue, TInt aLine)
    1.41 +	{
    1.42 +	if(!aValue)
    1.43 +		{
    1.44 +		DeleteTestFiles();
    1.45 +		TheTest(EFalse, aLine);
    1.46 +		}
    1.47 +	}
    1.48 +void Check(TInt aValue, TInt aExpected, TInt aLine)
    1.49 +	{
    1.50 +	if(aValue != aExpected)
    1.51 +		{
    1.52 +		DeleteTestFiles();
    1.53 +		TheTest.Printf(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
    1.54 +		TheTest(EFalse, aLine);
    1.55 +		}
    1.56 +	}
    1.57 +#define TEST(arg) ::Check((arg), __LINE__)
    1.58 +#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
    1.59 +
    1.60 +///////////////////////////////////////////////////////////////////////////////////////
    1.61 +
    1.62 +void CreateTestEnv(TInt aDriveNo)
    1.63 +    {
    1.64 +    TChar ch;
    1.65 +	TInt err = TheFs.DriveToChar(aDriveNo, ch);
    1.66 +	TEST2(err, KErrNone);
    1.67 +    TBuf<2> drvName;
    1.68 +    drvName.SetLength(2);
    1.69 +    drvName[0] = ch;
    1.70 +    drvName[1] = TChar(':');
    1.71 +
    1.72 +	_LIT(KTestFile, "c:\\stor-tst\\t_storetoc.dat");
    1.73 +
    1.74 +    TParse parse;
    1.75 +    parse.Set(drvName, &KTestFile, 0);
    1.76 +	const TDesC& dbFilePath = parse.FullName();
    1.77 +	TheFileName.Copy(dbFilePath);
    1.78 +
    1.79 +	err = TheFs.MkDir(parse.DriveAndPath());
    1.80 +	TEST(err == KErrNone || err == KErrAlreadyExists);
    1.81 +	}
    1.82 +
    1.83 +///////////////////////////////////////////////////////////////////////////////////////
    1.84 +//////////////////////              TTocTestBase        ///////////////////////////////
    1.85 +///////////////////////////////////////////////////////////////////////////////////////
    1.86 +//Base TOC test class.
    1.87 +//It offers the folowing functions: Prepare(), Test() and Verify().
    1.88 +//The test algorithm is:
    1.89 +//  =================================
    1.90 +//  void TestFunc(TTocTestBase& aTestObj)
    1.91 +//  {
    1.92 +//	  aTestObj.Prepare();
    1.93 +//    [simulate file system error];
    1.94 +//	  TInt err = aTestObj.Test();
    1.95 +//    [clear file system error];
    1.96 +//	  aTestObj.Verify(err);
    1.97 +//  }
    1.98 +//  =================================
    1.99 +//The class has two private pure virtual methods, which have to be overriden in derived classes:
   1.100 +//  DoPrepareL() - instance specific test preparation;
   1.101 +//  DoVerify()   - instance specific test verification;
   1.102 +class TTocTestBase
   1.103 +	{
   1.104 +public:
   1.105 +	TTocTestBase()
   1.106 +		{
   1.107 +		TheStore = NULL;
   1.108 +		}
   1.109 +	void Prepare()
   1.110 +		{
   1.111 +		TEST(TheStore == NULL);
   1.112 +		TRAPD(err, DoPrepareL());
   1.113 +		TEST2(err, KErrNone);
   1.114 +		}
   1.115 +	TInt Test()
   1.116 +		{
   1.117 +		TEST(TheStore != NULL);
   1.118 +		TRAPD(err, {TheStore->CompactL(); TheStore->CommitL();});
   1.119 +		delete TheStore;
   1.120 +		TheStore = NULL;
   1.121 +		return err;
   1.122 +		}
   1.123 +	void Verify(TInt aTestErr)
   1.124 +		{
   1.125 +		TEST(TheStore == NULL);
   1.126 +		TRAPD(err, DoVerifyL(aTestErr));
   1.127 +		TEST2(err, KErrNone);
   1.128 +		}
   1.129 +
   1.130 +protected:
   1.131 +	TStreamId WriteNewStreamL(const TDesC8& aStreamData)
   1.132 +		{
   1.133 +		TEST(TheStore != NULL);
   1.134 +		RStoreWriteStream stream;
   1.135 +		TStreamId streamId = stream.CreateLC(*TheStore);
   1.136 +		stream.WriteL(aStreamData);
   1.137 +		stream.CommitL();
   1.138 +		TheStore->CommitL();
   1.139 +		CleanupStack::PopAndDestroy(&stream);
   1.140 +		return streamId;
   1.141 +		}
   1.142 +
   1.143 +private:
   1.144 +	virtual void DoPrepareL() = 0;
   1.145 +	virtual void DoVerifyL(TInt aTestErr) = 0;
   1.146 +
   1.147 +	};
   1.148 +
   1.149 +///////////////////////////////////////////////////////////////////////////////////////
   1.150 +//////////////////////                TBaseTocEntryTest        ////////////////////////
   1.151 +///////////////////////////////////////////////////////////////////////////////////////
   1.152 +
   1.153 +//Do not change/shift the next lines, because "new line/space" characters will be inserted in the string!
   1.154 +_LIT8(KStreamData1, "-01-ABCD-02-ABCD-03-ABCD-04-ABCD-05-ABCD-06-ABCD-07-ABCD-08-ABCD");
   1.155 +_LIT8(KStreamData1_2, "ABCDEFGH-41-ABCD-42-ABCD-43-A\
   1.156 +-33-ABCD-34-ABCD-35-ABCD-36-ABCD-37-ABCD-38-ABCD-39-ABCD-40-ABCD\
   1.157 +-25-ABCD-26-ABCD-27-ABCD-28-ABCD-29-ABCD-30-ABCD-31-ABCD-32-ABCD\
   1.158 +-17-ABCD-18-ABCD-19-ABCD-20-ABCD-21-ABCD-22-ABCD-23-ABCD-24-ABCD\
   1.159 +-09-ABCD-10-ABCD-11-ABCD-12-ABCD-13-ABCD-14-ABCD-15-ABCD-16-ABCD");
   1.160 +_LIT8(KStreamData1_3, "0123456789");
   1.161 +
   1.162 +//"Base TOC entry" test.
   1.163 +//When a stream is relocated, its base TOC entry needs 2 "file write" (for "atomic block write" media) operations, because
   1.164 +//the TOC entry is split over a block boundary.
   1.165 +//This test class uses a set of test data, which puts the TOC entry of the relocated stream at position
   1.166 +//510 in the file (TOC entry length - 5 bytes).
   1.167 +class TBaseTocEntryTest : public TTocTestBase
   1.168 +	{
   1.169 +public:
   1.170 +	TBaseTocEntryTest() :
   1.171 +		iStreamId1(KNullStreamIdValue),
   1.172 +		iStreamId2(KNullStreamIdValue),
   1.173 +		iStreamId3(KNullStreamIdValue)
   1.174 +		{
   1.175 +		}
   1.176 +
   1.177 +private:
   1.178 +	void DoPrepareL()
   1.179 +		{
   1.180 +		TheStore = CPermanentFileStore::ReplaceLC(TheFs, TheFileName, EFileWrite);
   1.181 +		TheStore->SetTypeL(TheStore->Layout());
   1.182 +		TheStore->CommitL();
   1.183 +
   1.184 +		iStreamId1 = WriteNewStreamL(KStreamData1);
   1.185 +		TheStore->SetRootL(iStreamId1);
   1.186 +		TheStore->CommitL();
   1.187 +		iStreamId2 = WriteNewStreamL(KStreamData1_2);
   1.188 +		iStreamId3 = WriteNewStreamL(KStreamData1_3);
   1.189 +
   1.190 +		TheStore->DeleteL(iStreamId2);
   1.191 +		TheStore->CommitL();
   1.192 +
   1.193 +		CleanupStack::Pop(TheStore);
   1.194 +		}
   1.195 +
   1.196 +	virtual void DoVerifyL(TInt)
   1.197 +		{
   1.198 +		TEST(TheStore == NULL);
   1.199 +		TheStore = CPermanentFileStore::OpenLC(TheFs, TheFileName, EFileWrite);
   1.200 +		RPermanentFileStoreIter iter;
   1.201 +		iter.ResetLC(*TheStore);
   1.202 +		//Stream 1
   1.203 +		TStreamId streamId = iter.NextL();
   1.204 +		TEST(streamId == iStreamId1);
   1.205 +		RStoreReadStream strm;
   1.206 +		strm.OpenLC(*TheStore, streamId);
   1.207 +		TEST2(strm.Source()->SizeL(), KStreamData1().Length());
   1.208 +		TBuf8<sizeof(KStreamData1)> buf;
   1.209 +		strm.ReadL(buf, KStreamData1().Length());
   1.210 +		TEST2(Mem::Compare(buf.Ptr(), buf.Length(), KStreamData1().Ptr(), KStreamData1().Length()), 0);
   1.211 +		CleanupStack::PopAndDestroy(&strm);
   1.212 +		//Stream 2
   1.213 +		streamId = iter.NextL();
   1.214 +		TEST(streamId == iStreamId3);
   1.215 +		strm.OpenLC(*TheStore, streamId);
   1.216 +		TEST2(strm.Source()->SizeL(), KStreamData1_3().Length());
   1.217 +		strm.ReadL(buf, KStreamData1_3().Length());
   1.218 +		TEST2(Mem::Compare(buf.Ptr(), buf.Length(), KStreamData1_3().Ptr(), KStreamData1_3().Length()), 0);
   1.219 +		CleanupStack::PopAndDestroy(&strm);
   1.220 +		//No more streams
   1.221 +		streamId = iter.NextL();
   1.222 +		TEST(streamId == KNullStreamIdValue);
   1.223 +		//Cleanup
   1.224 +		CleanupStack::PopAndDestroy(&iter);
   1.225 +		CleanupStack::PopAndDestroy(TheStore);
   1.226 +		TheStore = NULL;
   1.227 +		}
   1.228 +
   1.229 +private:
   1.230 +	TStreamId iStreamId1;
   1.231 +	TStreamId iStreamId2;
   1.232 +	TStreamId iStreamId3;
   1.233 +
   1.234 +	};
   1.235 +
   1.236 +///////////////////////////////////////////////////////////////////////////////////////
   1.237 +//////////////////////              TDeltaTocEntryTest        /////////////////////////
   1.238 +///////////////////////////////////////////////////////////////////////////////////////
   1.239 +
   1.240 +//Do not change/shift the next lines, because "new line/space" characters will be inserted in the string!
   1.241 +_LIT8(KStreamData2, "\
   1.242 +-01-ABCD-02-ABCD-03-ABCD-04-ABCD-05-ABCD-06-ABCD-07-ABCD-08-ABCD\
   1.243 +-09-ABCD-10-ABCD-11-ABCD-12");
   1.244 +_LIT8(KStreamData2_2, "ABC");
   1.245 +_LIT8(KStreamData2_3, "012345678");
   1.246 +
   1.247 +//"Delta TOC entry" test
   1.248 +//When a stream is relocated, its delta TOC entry needs 2 "file write" (for "atomic block write" media) operations, because
   1.249 +//the TOC entry is split over a block boundary.
   1.250 +//This test class uses a set of test data, which puts the TOC entry of the relocated stream at position
   1.251 +//507 in the file (TOC entry length - 8 bytes), so the last 4 bytes (stream offset) are split.
   1.252 +class TDeltaTocEntryTest : public TTocTestBase
   1.253 +	{
   1.254 +public:
   1.255 +	TDeltaTocEntryTest() :
   1.256 +		iStreamId1(KNullStreamIdValue),
   1.257 +		iStreamId2(KNullStreamIdValue),
   1.258 +		iStreamId3(KNullStreamIdValue),
   1.259 +		iStreamId4(KNullStreamIdValue),
   1.260 +		iStreamId5(KNullStreamIdValue)
   1.261 +		{
   1.262 +		}
   1.263 +
   1.264 +protected:
   1.265 +	virtual void DoPrepareL()
   1.266 +		{
   1.267 +		TheStore = CPermanentFileStore::ReplaceLC(TheFs, TheFileName, EFileWrite);
   1.268 +		TheStore->SetTypeL(TheStore->Layout());
   1.269 +		TheStore->CommitL();
   1.270 +
   1.271 +		iStreamId1 = WriteNewStreamL(KStreamData2);
   1.272 +		TheStore->SetRootL(iStreamId1);
   1.273 +		TheStore->CommitL();
   1.274 +		iStreamId2 = WriteNewStreamL(KStreamData2);
   1.275 +		iStreamId3 = WriteNewStreamL(KStreamData2().Left(KStreamData2().Length() - 1));
   1.276 +		iStreamId4 = WriteNewStreamL(KStreamData2_2);
   1.277 +		iStreamId5 = WriteNewStreamL(KStreamData2_3);
   1.278 +
   1.279 +		TheStore->DeleteL(iStreamId4);
   1.280 +		TheStore->CommitL();
   1.281 +
   1.282 +		CleanupStack::Pop(TheStore);
   1.283 +		}
   1.284 +
   1.285 +	virtual void DoVerifyL(TInt)
   1.286 +		{
   1.287 +		TEST(TheStore == NULL);
   1.288 +		TheStore = CPermanentFileStore::OpenLC(TheFs, TheFileName, EFileWrite);
   1.289 +		RPermanentFileStoreIter iter;
   1.290 +		iter.ResetLC(*TheStore);
   1.291 +		//Stream 1
   1.292 +		TStreamId streamId = iter.NextL();
   1.293 +		TEST(streamId == iStreamId1);
   1.294 +		RStoreReadStream strm;
   1.295 +		strm.OpenLC(*TheStore, streamId);
   1.296 +		TEST2(strm.Source()->SizeL(), KStreamData2().Length());
   1.297 +		TBuf8<sizeof(KStreamData2)> buf;
   1.298 +		strm.ReadL(buf, KStreamData2().Length());
   1.299 +		TEST2(Mem::Compare(buf.Ptr(), buf.Length(), KStreamData2().Ptr(), KStreamData2().Length()), 0);
   1.300 +		CleanupStack::PopAndDestroy(&strm);
   1.301 +		//Stream 2
   1.302 +		streamId = iter.NextL();
   1.303 +		TEST(streamId == iStreamId2);
   1.304 +		strm.OpenLC(*TheStore, streamId);
   1.305 +		TEST2(strm.Source()->SizeL(), KStreamData2().Length());
   1.306 +		strm.ReadL(buf, KStreamData2().Length());
   1.307 +		TEST2(Mem::Compare(buf.Ptr(), buf.Length(), KStreamData2().Ptr(), KStreamData2().Length()), 0);
   1.308 +		CleanupStack::PopAndDestroy(&strm);
   1.309 +		//Stream 3
   1.310 +		streamId = iter.NextL();
   1.311 +		TEST(streamId == iStreamId3);
   1.312 +		strm.OpenLC(*TheStore, streamId);
   1.313 +		TEST2(strm.Source()->SizeL(), KStreamData2().Length() - 1);
   1.314 +		strm.ReadL(buf, KStreamData2().Length() - 1);
   1.315 +		TEST2(Mem::Compare(buf.Ptr(), buf.Length(), KStreamData2().Ptr(), KStreamData2().Length() - 1), 0);
   1.316 +		CleanupStack::PopAndDestroy(&strm);
   1.317 +		//Stream 4
   1.318 +		streamId = iter.NextL();
   1.319 +		TEST(streamId == iStreamId5);
   1.320 +		strm.OpenLC(*TheStore, streamId);
   1.321 +		TEST2(strm.Source()->SizeL(), KStreamData2_3().Length());
   1.322 +		strm.ReadL(buf, KStreamData2_3().Length());
   1.323 +		TEST2(Mem::Compare(buf.Ptr(), buf.Length(), KStreamData2_3().Ptr(), KStreamData2_3().Length()), 0);
   1.324 +		CleanupStack::PopAndDestroy(&strm);
   1.325 +		//No more streams
   1.326 +		streamId = iter.NextL();
   1.327 +		TEST(streamId == KNullStreamIdValue);
   1.328 +		//Cleanup
   1.329 +		CleanupStack::PopAndDestroy(&iter);
   1.330 +		CleanupStack::PopAndDestroy(TheStore);
   1.331 +		TheStore = NULL;
   1.332 +		}
   1.333 +
   1.334 +private:
   1.335 +	TStreamId iStreamId1;
   1.336 +	TStreamId iStreamId2;
   1.337 +	TStreamId iStreamId3;
   1.338 +	TStreamId iStreamId4;
   1.339 +	TStreamId iStreamId5;
   1.340 +
   1.341 +	};
   1.342 +
   1.343 +///////////////////////////////////////////////////////////////////////////////////////
   1.344 +//////////////////////              TBaseTocReferenceTest        //////////////////////
   1.345 +///////////////////////////////////////////////////////////////////////////////////////
   1.346 +
   1.347 +//Do not change/shift the next lines, because "new line/space" characters will be inserted in the string!
   1.348 +_LIT8(KStreamData3, "\
   1.349 +-01-ABCD-02-ABCD-03-ABCD-04-ABCD-05-ABCD-06-ABCD-07-ABCD-08-ABCD\
   1.350 +-09-ABCD-10-ABCD-11-ABCD-12-ABCD");
   1.351 +_LIT8(KStreamData3_2, "ABCDEFGH");
   1.352 +_LIT8(KStreamData3_3, "0123456789");
   1.353 +
   1.354 +//"Base TOC reference" test.
   1.355 +//When the base TOC is relocated, the delta TOC reference to the base TOC has to be updated with
   1.356 +// 2 "file write" operations (for "atomic block write" media), because the reference is split over a block boundary.
   1.357 +//This test class uses a set of test data, which puts the delta TOC reference to the base TOC
   1.358 +//at position 511 in the file (reference length - 4 bytes)
   1.359 +class TBaseTocReferenceTest : public TTocTestBase
   1.360 +	{
   1.361 +public:
   1.362 +	TBaseTocReferenceTest() :
   1.363 +		iStreamId1(KNullStreamIdValue),
   1.364 +		iStreamId2(KNullStreamIdValue),
   1.365 +		iStreamId3(KNullStreamIdValue),
   1.366 +		iStreamId4(KNullStreamIdValue),
   1.367 +		iStreamId5(KNullStreamIdValue)
   1.368 +		{
   1.369 +		}
   1.370 +
   1.371 +protected:
   1.372 +	virtual void DoPrepareL()
   1.373 +		{
   1.374 +		TheStore = CPermanentFileStore::ReplaceLC(TheFs, TheFileName, EFileWrite);
   1.375 +		TheStore->SetTypeL(TheStore->Layout());
   1.376 +		TheStore->CommitL();
   1.377 +
   1.378 +		iStreamId1 = WriteNewStreamL(KStreamData3);
   1.379 +		TheStore->SetRootL(iStreamId1);
   1.380 +		TheStore->CommitL();
   1.381 +		iStreamId2 = WriteNewStreamL(KStreamData3);
   1.382 +		iStreamId3 = WriteNewStreamL(KStreamData3().Left(KStreamData3().Length() - 3));
   1.383 +		iStreamId4 = WriteNewStreamL(KStreamData3_2);
   1.384 +		iStreamId5 = WriteNewStreamL(KStreamData3_3);
   1.385 +
   1.386 +		TheStore->DeleteL(iStreamId4);
   1.387 +		TheStore->CommitL();
   1.388 +
   1.389 +		CleanupStack::Pop(TheStore);
   1.390 +		}
   1.391 +
   1.392 +	virtual void DoVerifyL(TInt)
   1.393 +		{
   1.394 +		TEST(TheStore == NULL);
   1.395 +		TheStore = CPermanentFileStore::OpenLC(TheFs, TheFileName, EFileWrite);
   1.396 +		RPermanentFileStoreIter iter;
   1.397 +		iter.ResetLC(*TheStore);
   1.398 +		//Stream 1
   1.399 +		TStreamId streamId = iter.NextL();
   1.400 +		TEST(streamId == iStreamId1);
   1.401 +		RStoreReadStream strm;
   1.402 +		strm.OpenLC(*TheStore, streamId);
   1.403 +		TEST2(strm.Source()->SizeL(), KStreamData3().Length());
   1.404 +		TBuf8<sizeof(KStreamData3)> buf;
   1.405 +		strm.ReadL(buf, KStreamData3().Length());
   1.406 +		TEST2(Mem::Compare(buf.Ptr(), buf.Length(), KStreamData3().Ptr(), KStreamData3().Length()), 0);
   1.407 +		CleanupStack::PopAndDestroy(&strm);
   1.408 +		//Stream 2
   1.409 +		streamId = iter.NextL();
   1.410 +		TEST(streamId == iStreamId2);
   1.411 +		strm.OpenLC(*TheStore, streamId);
   1.412 +		TEST2(strm.Source()->SizeL(), KStreamData3().Length());
   1.413 +		strm.ReadL(buf, KStreamData3().Length());
   1.414 +		TEST2(Mem::Compare(buf.Ptr(), buf.Length(), KStreamData3().Ptr(), KStreamData3().Length()), 0);
   1.415 +		CleanupStack::PopAndDestroy(&strm);
   1.416 +		//Stream 3
   1.417 +		streamId = iter.NextL();
   1.418 +		TEST(streamId == iStreamId3);
   1.419 +		strm.OpenLC(*TheStore, streamId);
   1.420 +		TEST2(strm.Source()->SizeL(), KStreamData3().Length() - 3);
   1.421 +		strm.ReadL(buf, KStreamData3().Length() - 3);
   1.422 +		TEST2(Mem::Compare(buf.Ptr(), buf.Length(), KStreamData3().Ptr(), KStreamData3().Length() - 3), 0);
   1.423 +		CleanupStack::PopAndDestroy(&strm);
   1.424 +		//Stream 4
   1.425 +		streamId = iter.NextL();
   1.426 +		TEST(streamId == iStreamId5);
   1.427 +		strm.OpenLC(*TheStore, streamId);
   1.428 +		TEST2(strm.Source()->SizeL(), KStreamData3_3().Length());
   1.429 +		strm.ReadL(buf, KStreamData3_3().Length());
   1.430 +		TEST2(Mem::Compare(buf.Ptr(), buf.Length(), KStreamData3_3().Ptr(), KStreamData3_3().Length()), 0);
   1.431 +		CleanupStack::PopAndDestroy(&strm);
   1.432 +		//No more streams
   1.433 +		streamId = iter.NextL();
   1.434 +		TEST(streamId == KNullStreamIdValue);
   1.435 +		//Cleanup
   1.436 +		CleanupStack::PopAndDestroy(&iter);
   1.437 +		CleanupStack::PopAndDestroy(TheStore);
   1.438 +		TheStore = NULL;
   1.439 +		}
   1.440 +
   1.441 +private:
   1.442 +	TStreamId iStreamId1;
   1.443 +	TStreamId iStreamId2;
   1.444 +	TStreamId iStreamId3;
   1.445 +	TStreamId iStreamId4;
   1.446 +	TStreamId iStreamId5;
   1.447 +
   1.448 +	};
   1.449 +
   1.450 +///////////////////////////////////////////////////////////////////////////////////////
   1.451 +///////////////////////////////////////////////////////////////////////////////////////
   1.452 +
   1.453 +void TocTest(TTocTestBase& aTestObj)
   1.454 +	{
   1.455 +	TInt err = KErrGeneral;
   1.456 +	for(TInt cnt=1;err!=KErrNone;++cnt)
   1.457 +		{
   1.458 +		TheTest.Printf(_L("%d\r"), cnt);
   1.459 +		aTestObj.Prepare();
   1.460 +		(void)TheFs.SetErrorCondition(KErrGeneral, cnt);
   1.461 +		err = aTestObj.Test();
   1.462 +		(void)TheFs.SetErrorCondition(KErrNone);
   1.463 +		aTestObj.Verify(err);
   1.464 +		}
   1.465 +	TheTest.Printf(_L("\n"));
   1.466 +	TEST2(err, KErrNone);
   1.467 +	aTestObj.Verify(err);
   1.468 +	}
   1.469 +
   1.470 +/**
   1.471 +@SYMTestCaseID          SYSLIB-STORE-CT-3481
   1.472 +@SYMTestCaseDesc        The test is performed on media, where atomic "block write" operations are guaranteed.
   1.473 +						In a "file I/O error" simulation loop:
   1.474 +						 - Creates a CPermanentStoreFile object, stores there carefully selected set of test data,
   1.475 +						   such that a base TOC entry is split over the block boundary;
   1.476 +						 - Compacts the store;
   1.477 +						 - Commits;
   1.478 +@SYMTestPriority        High
   1.479 +@SYMTestActions         Creates a CPermanentStoreFile object, stores there carefully selected set of test data,
   1.480 +						such that a base TOC entry is split over the block boundary. When the store is compacted
   1.481 +						and the used media supports atomic "block write" operations, the STORE will update
   1.482 +						the base TOC entry, which requires a "file write" operation crossing the block boundary.
   1.483 +@SYMTestExpectedResults The test should not fail or panic.
   1.484 +@SYMREQ                 REQ0000
   1.485 +*/
   1.486 +void BaseTocEntryTest()
   1.487 +	{
   1.488 +	TBaseTocEntryTest baseTocEntryTestObj;
   1.489 +	TocTest(baseTocEntryTestObj);
   1.490 +	}
   1.491 +
   1.492 +/**
   1.493 +@SYMTestCaseID          SYSLIB-STORE-CT-3482
   1.494 +@SYMTestCaseDesc        The test is performed on media, where atomic "block write" operations are guaranteed.
   1.495 +						In a "file I/O error" simulation loop:
   1.496 +						 - Creates a CPermanentStoreFile object, stores there carefully selected set of test data,
   1.497 +						   such that a delta TOC entry is split over the block boundary;
   1.498 +						 - Compacts the store;
   1.499 +						 - Commits;
   1.500 +@SYMTestPriority        High
   1.501 +@SYMTestActions         Creates a CPermanentStoreFile object, stores there carefully selected set of test data,
   1.502 +						such that a delta TOC entry is split over the block boundary. When the store is compacted
   1.503 +						and the used media supports atomic "block write" operations, the STORE will update
   1.504 +						the delta TOC entry, which requires a "file write" operation crossing the block boundary.
   1.505 +@SYMTestExpectedResults The test should not fail or panic.
   1.506 +@SYMREQ                 REQ0000
   1.507 +*/
   1.508 +void DeltaTocEntryTest()
   1.509 +	{
   1.510 +	TDeltaTocEntryTest deltaTocEntryTestObj;
   1.511 +	TocTest(deltaTocEntryTestObj);
   1.512 +	}
   1.513 +
   1.514 +/**
   1.515 +@SYMTestCaseID          SYSLIB-STORE-CT-3483
   1.516 +@SYMTestCaseDesc        The test is performed on media, where atomic "block write" operations are guaranteed.
   1.517 +						In a "file I/O error" simulation loop:
   1.518 +						 - Creates a CPermanentStoreFile object, stores there carefully selected set of test data,
   1.519 +						   such that a base TOC reference is split over the block boundary;
   1.520 +						 - Compacts the store;
   1.521 +						 - Commits;
   1.522 +@SYMTestPriority        High
   1.523 +@SYMTestActions         Creates a CPermanentStoreFile object, stores there carefully selected set of test data,
   1.524 +						such that a base TOC reference is split over the block boundary. When the store is compacted
   1.525 +						and the used media supports atomic "block write" operations, the STORE will update
   1.526 +						the base TOC reference, which requires a "file write" operation crossing the block boundary.
   1.527 +@SYMTestExpectedResults The test should not fail or panic.
   1.528 +@SYMREQ                 REQ0000
   1.529 +*/
   1.530 +void BaseTocReferenceTest()
   1.531 +	{
   1.532 +	TBaseTocReferenceTest baseTocReferenceTestObj;
   1.533 +	TocTest(baseTocReferenceTestObj);
   1.534 +	}
   1.535 +
   1.536 +///////////////////////////////////////////////////////////////////////////////////////
   1.537 +
   1.538 +void DoTests()
   1.539 +	{
   1.540 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-3481 Base TOC entry test "));
   1.541 +	BaseTocEntryTest();
   1.542 +
   1.543 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-3482 Delta TOC entry test "));
   1.544 +	DeltaTocEntryTest();
   1.545 +
   1.546 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-3483 Base TOC reference test "));
   1.547 +	BaseTocReferenceTest();
   1.548 +	}
   1.549 +
   1.550 +//The function returns true, if the file system guarantees atomic "block write" operations on aDriveNo.
   1.551 +TBool IsBlockAtomic(TInt aDriveNo)
   1.552 +	{
   1.553 +	__ASSERT_DEBUG(aDriveNo >= EDriveA && aDriveNo <= EDriveZ, User::Invariant());
   1.554 +
   1.555 +	TVolumeIOParamInfo volInfo;
   1.556 +	TInt err = TheFs.VolumeIOParam(aDriveNo, volInfo);
   1.557 +	//If VolumeIOParam() succeeds, the media block size is >= 512 bytes and the media block size is power of two - report
   1.558 +	//that the media supports atomic "block write" operations.
   1.559 +	const TInt KDefaultMediaBlockSize = 512;
   1.560 +	return err == KErrNone && volInfo.iBlockSize >= KDefaultMediaBlockSize && (volInfo.iBlockSize & (volInfo.iBlockSize - 1)) == 0;
   1.561 +	}
   1.562 +
   1.563 +//Returns the number of the drive on which atomic "block write" operations are supported.
   1.564 +TInt GetBlockAtomicDriveNo()
   1.565 +	{
   1.566 +	//Uncomment, if you want to do the test on drive C:
   1.567 +	//(but you will need also to uncomment 2 lines in CPermanentStoreCoord::FileQoSL())
   1.568 +	//return EDriveC;
   1.569 +	//
   1.570 +	for(TInt driveNo=EDriveA;driveNo<=EDriveZ;++driveNo)
   1.571 +		{
   1.572 +		TDriveInfo driveInfo;
   1.573 +		TInt err = TheFs.Drive(driveInfo, driveNo);
   1.574 +		if(err == KErrNone)
   1.575 +			{
   1.576 +			if(!(driveInfo.iDriveAtt & KDriveAttTransaction))
   1.577 +				{
   1.578 +#ifdef __X86GCC__
   1.579 +			TFSName thefsname;
   1.580 +			err = TheFs.FileSystemName (thefsname, driveNo);
   1.581 +
   1.582 +			if ((err == KErrNone) && (!(thefsname.MatchF(_L("NTFS"))))) // X86GCC doesn't (yet) support write operations on NTFS partitions
   1.583 +#endif
   1.584 +				if(IsBlockAtomic(driveNo))
   1.585 +					{
   1.586 +					return driveNo;
   1.587 +					}
   1.588 +				}
   1.589 +			}
   1.590 +		}
   1.591 +	return -1;
   1.592 +	}
   1.593 +
   1.594 +///////////////////////////////////////////////////////////////////////////////////////////////////////////////
   1.595 +// If you want to check that the atomic "block write" optimisation works and the code change is robust, then you
   1.596 +// have to:
   1.597 +// 1) Prove that if the the "file write" operations over a sector boundary are not done properly, the current test will crash
   1.598 +// 2) Prove that if the the "file write" operations over a sector boundary are done properly, the current test won't crash
   1.599 +// How this could be done:
   1.600 +// For (1) - Simulate that the file system for drive C: on the Emulator is transactional.
   1.601 +//    In order to do that:
   1.602 +//		- uncomment the "return EDriveC;" statement in the function above (GetBlockAtomicDriveNo());
   1.603 +//		- go to CPermanentStoreCoord::FileQoSL() function and uncomment the first two lines:
   1.604 +//			"iFileQos = ETransactional;"
   1.605 +//			"return iFileQos;"
   1.606 +//	  So, the result of your changes will be: STORE will try to optimize the "file write" operations on drive C:,
   1.607 +//	  because drive C: will be reported as a "transactional" drive. Since the drive C: does not really support "transactional"
   1.608 +//	  operations, the optimization will cause some failures in the current test, if the data block which has to be written,
   1.609 +//	  is split across a sector boundary. In order to make sure that the split will hapen - do step (2).
   1.610 +// 2) Declare SYSLIBS_TEST macro in the related variant.hrh file. This change will cause RFileBuf to split the "file write"
   1.611 +//	  operations in two separate operations, if the data block to be written has to be split over a sector boundary.
   1.612 +// After the changes, build STORE and run the current test. You must see that the test crashes.
   1.613 +//
   1.614 +// Then, for (2) (a) restore the original code in GetBlockAtomicDriveNo() and (b) CPermanentStoreCoord::FileQoSL() and rebuild STORE.
   1.615 +// Rerun the current test and the test must pass.
   1.616 +///////////////////////////////////////////////////////////////////////////////////////////////////////////////
   1.617 +
   1.618 +TInt E32Main()
   1.619 +	{
   1.620 +	TheTest.Title();
   1.621 +
   1.622 +	CTrapCleanup* tc = CTrapCleanup::New();
   1.623 +
   1.624 +	__UHEAP_MARK;
   1.625 +
   1.626 +	TInt err = TheFs.Connect();
   1.627 +	TheTest(err == KErrNone);
   1.628 +
   1.629 +	TheTest.Start(_L("Check for \"block atomic write\" drives"));
   1.630 +	TInt driveNo = GetBlockAtomicDriveNo();
   1.631 +	if(driveNo != -1)
   1.632 +		{
   1.633 +		TheTest.Printf(_L("Test drive - %c:\r\n"), 'A' + driveNo);
   1.634 +		TheTest.Printf(_L("The test expects that STORE component is built with SYSLIBS_TEST macro defined\r\n"));
   1.635 +		CreateTestEnv(driveNo);
   1.636 +		DoTests();
   1.637 +		DeleteTestFiles();
   1.638 +		}
   1.639 +	else
   1.640 +		{
   1.641 +		TheTest.Printf(_L("!!! No \"block atomic write\" drive found!\r\n"));
   1.642 +		}
   1.643 +	TheFs.Close();
   1.644 +
   1.645 +	__UHEAP_MARKEND;
   1.646 +
   1.647 +	TheTest.End();
   1.648 +	TheTest.Close();
   1.649 +
   1.650 +	delete tc;
   1.651 +
   1.652 +	User::Heap().Check();
   1.653 +	return KErrNone;
   1.654 +	}