os/persistentdata/persistentstorage/store/TPAGE/t_storpage.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/store/TPAGE/t_storpage.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,671 @@
     1.4 +// Copyright (c) 1998-2010 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 <s32cont.h>
    1.20 +#include <s32file.h>
    1.21 +#include <s32crypt.h>
    1.22 +#include <e32test.h>
    1.23 +#include <pbe.h>
    1.24 +#include "UP_STD.H"
    1.25 +
    1.26 +const TInt KTestCleanupStack=0x20;
    1.27 +
    1.28 +// This is a path specification and should not be used as is
    1.29 +_LIT(KFileLocationSpec, "Z:\\STOR-TST\\T_SPAGE.DAT");
    1.30 +_LIT(KPageFilePath, "C:\\TestSTOR\\T_SPAGEFILE.PAG");
    1.31 +_LIT(KPageFilePathOnly, "C:\\TestSTOR\\");
    1.32 +
    1.33 +LOCAL_D CTrapCleanup* TheTrapCleanup;
    1.34 +LOCAL_D RTest TheTest(_L("t_storpage"));
    1.35 +LOCAL_D RFs TheFs;
    1.36 +LOCAL_D CFileStore* TheStore;
    1.37 +
    1.38 +///////////////////////////////////////////////////////////////////////////////////////
    1.39 +///////////////////////////////////////////////////////////////////////////////////////
    1.40 +//Tests macros and functions.
    1.41 +//If (!aValue) then the test will be panicked, the test data files will be deleted.
    1.42 +static void Check(TInt aValue, TInt aLine)
    1.43 +	{
    1.44 +	if(!aValue)
    1.45 +		{
    1.46 +		TheTest.Printf(_L("*** Boolean expression evaluated to false!\r\n"));
    1.47 +		TheTest(EFalse, aLine);
    1.48 +		}
    1.49 +	}
    1.50 +//If (aValue != aExpected) then the test will be panicked, the test data files will be deleted.
    1.51 +static void Check(TInt aValue, TInt aExpected, TInt aLine)
    1.52 +	{
    1.53 +	if(aValue != aExpected)
    1.54 +		{
    1.55 +		TheTest.Printf(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
    1.56 +		TheTest(EFalse, aLine);
    1.57 +		}
    1.58 +	}
    1.59 +//Use these to test conditions.
    1.60 +#define TEST(arg) ::Check((arg), __LINE__)
    1.61 +#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
    1.62 +
    1.63 +///////////////////////////////////////////////////////////////////////////////////////
    1.64 +
    1.65 +/**
    1.66 +@SYMTestCaseID          SYSLIB-STORE-CT-1178
    1.67 +@SYMTestCaseDesc	    TPagedSet functionality test
    1.68 +@SYMTestPriority 	    High
    1.69 +@SYMTestActions  	    Tests for insert,delete,contains,with and without duplicates operations
    1.70 +@SYMTestExpectedResults Test must not fail
    1.71 +@SYMREQ                 REQ0000
    1.72 +*/
    1.73 +LOCAL_C void test1L(MPagePool& aPagePool)
    1.74 +	{
    1.75 +	const TInt KEntryCount=200;
    1.76 +
    1.77 +	TPagedSet<TInt32> set;
    1.78 +	set.Connect(&aPagePool);
    1.79 +	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1178 Insertion & Deletion "));
    1.80 +
    1.81 +	TInt32 it=0;
    1.82 +	set.InsertL(it);
    1.83 +	TEST2(set.Count(), 1);
    1.84 +	TRAPD(r,set.InsertL(it));
    1.85 +	TEST2(r, KErrAlreadyExists);
    1.86 +	TEST2(set.Count(), 1);
    1.87 +	TEST(set.ContainsL(it));
    1.88 +	set.DeleteL(it);
    1.89 +	TEST2(set.Count(), 0);
    1.90 +	TRAP(r,set.DeleteL(it));
    1.91 +	TEST2(r, KErrNotFound);
    1.92 +	TEST2(set.Count(), 0);
    1.93 +	TEST(!set.ContainsL(it));
    1.94 +
    1.95 +	TheTest.Next(_L("No duplicates"));
    1.96 +	TInt ii;
    1.97 +	for (ii=0;ii<KEntryCount;++ii)
    1.98 +		{
    1.99 +		it=ii;
   1.100 +		set.InsertL(it);
   1.101 +		}
   1.102 +	for (ii=0;ii<KEntryCount;++ii)
   1.103 +		{
   1.104 +		it=ii;
   1.105 +		TEST(set.ContainsL(it));
   1.106 +		}
   1.107 +	TEST2(set.Count(), KEntryCount);
   1.108 +
   1.109 +	TheTest.Next(_L("Empty the set"));
   1.110 +	set.ClearL();
   1.111 +	TEST2(set.Count(), 0);
   1.112 +	for (ii=0;ii<KEntryCount;++ii)
   1.113 +		{
   1.114 +		it=ii;
   1.115 +		TEST(!set.ContainsL(it));
   1.116 +		}
   1.117 +
   1.118 +	TheTest.End();
   1.119 +	}
   1.120 +
   1.121 +struct TTest
   1.122 +	{
   1.123 +	inline TTest() {Mem::FillZ(this,sizeof(*this));}
   1.124 +	TUint32 iVal;
   1.125 +	TUint32 iPadding[14];
   1.126 +	};
   1.127 +
   1.128 +/**
   1.129 +@SYMTestCaseID          SYSLIB-STORE-CT-1179
   1.130 +@SYMTestCaseDesc	    Tests for large set of TUint32
   1.131 +@SYMTestPriority 	    High
   1.132 +@SYMTestActions  	    Tests for inserting,contains,iteration,deletion operations
   1.133 +@SYMTestExpectedResults Test must not fail
   1.134 +@SYMREQ                 REQ0000
   1.135 +*/
   1.136 +LOCAL_C void test2L(MPagePool& aPagePool)
   1.137 +	{
   1.138 +	const TInt KEntryCount=500;
   1.139 +
   1.140 +	TPagedSet<TTest> set;
   1.141 +	set.Connect(&aPagePool);
   1.142 +	TTest item;
   1.143 +
   1.144 +	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1179 Add items "));
   1.145 +	TUint32 jj=0;
   1.146 +	TInt32 ii;
   1.147 +	for (ii=KEntryCount;ii>0;--ii)
   1.148 +		{
   1.149 +		jj=(jj+17)%KEntryCount;
   1.150 +		item.iVal=jj;
   1.151 +		set.InsertL(item);
   1.152 +		}
   1.153 +	TEST2(set.Count(), KEntryCount);
   1.154 +
   1.155 +	TheTest.Next(_L("Check contents"));
   1.156 +	for (ii=0;ii<KEntryCount;++ii)
   1.157 +		{
   1.158 +		item.iVal=ii;
   1.159 +		TEST(set.ContainsL(item));
   1.160 +		}
   1.161 +
   1.162 +	TheTest.Next(_L("Iterate over items"));
   1.163 +	TUint8 *checkMap=(TUint8*)User::AllocLC(KEntryCount);
   1.164 +	Mem::FillZ(checkMap,KEntryCount);
   1.165 +	TPagedSetIter<TTest> iter(set);
   1.166 +	if (iter.ResetL())
   1.167 +		do	++checkMap[iter.AtL().iVal]; while (iter.NextL());
   1.168 +	for (ii=0;ii<KEntryCount;++ii)
   1.169 +		TEST2(checkMap[ii], 1);
   1.170 +	CleanupStack::PopAndDestroy();
   1.171 +
   1.172 +	TheTest.Next(_L("Delete items"));
   1.173 +	jj=0;
   1.174 +	for (ii=KEntryCount;ii>KEntryCount/2;--ii)
   1.175 +		{
   1.176 +		jj=(jj+17)%KEntryCount;
   1.177 +		item.iVal=jj;
   1.178 +		set.DeleteL(item);
   1.179 +		}
   1.180 +	TEST2(set.Count(), KEntryCount/2);
   1.181 +
   1.182 +	TheTest.Next(_L("Check contents"));
   1.183 +	for (;ii>0;--ii)
   1.184 +		{
   1.185 +		jj=(jj+17)%KEntryCount;
   1.186 +		item.iVal=jj;
   1.187 +		TEST(set.ContainsL(item));
   1.188 +		}
   1.189 +	jj=0;
   1.190 +	for (ii=KEntryCount;ii>KEntryCount/2;--ii)
   1.191 +		{
   1.192 +		jj=(jj+17)%KEntryCount;
   1.193 +		item.iVal=jj;
   1.194 +		TEST(!set.ContainsL(item));
   1.195 +		}
   1.196 +
   1.197 +	TheTest.Next(_L("Delete items"));
   1.198 +	for (;ii>1;--ii)
   1.199 +		{
   1.200 +		jj=(jj+17)%KEntryCount;
   1.201 +		item.iVal=jj;
   1.202 +		set.DeleteL(item);
   1.203 +		}
   1.204 +	TEST2(set.Count(), 1);
   1.205 +
   1.206 +	TheTest.Next(_L("Check contents"));
   1.207 +	jj=(jj+17)%KEntryCount;
   1.208 +	TPagedSetBiIter<TTest> biter(set);
   1.209 +	TEST(biter.FirstL());
   1.210 +	TEST2(biter.AtL().iVal, jj);
   1.211 +	TEST(!biter.NextL());
   1.212 +	TEST(biter.LastL());
   1.213 +	TEST2(biter.AtL().iVal ,jj);
   1.214 +	TEST(!biter.PreviousL());
   1.215 +	TPagedSetRIter<TTest> riter(set);
   1.216 +	TEST(riter.ResetL());
   1.217 +	TEST2(riter.AtL().iVal, jj);
   1.218 +	TEST(!riter.NextL());
   1.219 +
   1.220 +	item.iVal=jj;
   1.221 +	set.DeleteL(item);
   1.222 +	TEST(!iter.ResetL());
   1.223 +	TEST2(set.Count(), 0);
   1.224 +
   1.225 +	TheTest.End();
   1.226 +	}
   1.227 +
   1.228 +/**
   1.229 +@SYMTestCaseID          SYSLIB-STORE-CT-1180
   1.230 +@SYMTestCaseDesc	    Streaming tests
   1.231 +@SYMTestPriority 	    High
   1.232 +@SYMTestActions  	    Tests for read and write operations on the streams
   1.233 +@SYMTestExpectedResults Test must not fail
   1.234 +@SYMREQ                 REQ0000
   1.235 +*/
   1.236 +LOCAL_C void test3L(RStorePagePool& aPool)
   1.237 +	{
   1.238 +	const TInt KEntryCount=1000;
   1.239 +	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1180 Build set and stream out "));
   1.240 +	aPool.Create(*TheStore);
   1.241 +	TBool rc = aPool.HasAvailable();
   1.242 +	TEST(!rc);
   1.243 +	rc = aPool.IsEmpty();
   1.244 +	TEST(rc);
   1.245 +	TStorePagePoolToken token2(TStorePagePoolToken::EEmpty);
   1.246 +	token2 = aPool.Token();
   1.247 +	rc = token2.IsEmpty();
   1.248 +	TEST(rc);
   1.249 +	rc = token2.HasAvailable();
   1.250 +	TEST(!rc);
   1.251 +	
   1.252 +	TPagedSet<TInt32> set1;
   1.253 +	set1.Connect(&aPool);
   1.254 +
   1.255 +	TInt ii;
   1.256 +	for (ii=0;ii<KEntryCount;ii++)
   1.257 +		{
   1.258 +		TInt32 it=ii;
   1.259 +		set1.InsertL(it);
   1.260 +		}
   1.261 +	aPool.FlushL();
   1.262 +	
   1.263 +	RStoreWriteStream out;
   1.264 +	TStreamId id=out.CreateLC(*TheStore);
   1.265 +	out<<aPool.Token();
   1.266 +	out<<set1.Token();
   1.267 +	out.CommitL();
   1.268 +	CleanupStack::PopAndDestroy();	// out
   1.269 +	aPool.Close();
   1.270 +//
   1.271 +	TheTest.Next(_L("Stream in and test set"));
   1.272 +	RStoreReadStream in;
   1.273 +	in.OpenLC(*TheStore,id);
   1.274 +	TStorePagePoolToken ptoken;
   1.275 +	in>>ptoken;
   1.276 +	aPool.Open(*TheStore,ptoken);
   1.277 +	TEST(!aPool.IsDirty());
   1.278 +	TPagedSetToken token;
   1.279 +	in>>token;
   1.280 +	TPagedSet<TInt32> set2(token);
   1.281 +	set2.Connect(&aPool);
   1.282 +	TEST(set2.IsIntact());
   1.283 +	CleanupStack::PopAndDestroy();	// in
   1.284 +
   1.285 +	TEST2(set2.Count(), KEntryCount);
   1.286 +	for (ii=0;ii<KEntryCount;ii++)
   1.287 +		{
   1.288 +		TInt32 it=ii;
   1.289 +		set2.DeleteL(it);
   1.290 +		}
   1.291 +	TEST2(set2.Count(), 0);
   1.292 +	aPool.FlushL();
   1.293 +	aPool.Discard();
   1.294 +	aPool.ReclaimAllL();
   1.295 +	aPool.Close();
   1.296 +	TheTest.End();
   1.297 +	}
   1.298 +
   1.299 +/**
   1.300 +@SYMTestCaseID          PDS-STORE-CT-4009
   1.301 +@SYMTestCaseDesc	    RFilePagePool tests
   1.302 +@SYMTestPriority 	    High
   1.303 +@SYMTestActions  	    Tests for creating and opening RFilePagePool
   1.304 +@SYMTestExpectedResults RFilePagePool needs to be correctly created, replaced and opened.
   1.305 +@SYMDEF                 DEF135804
   1.306 +*/
   1.307 +LOCAL_C void test4L()
   1.308 +	{
   1.309 +	RFilePagePool testPage;
   1.310 +	TFileName tempPageFileName;
   1.311 +	RFs fs;
   1.312 +	TInt err;
   1.313 +	fs.Connect();
   1.314 +	err = fs.MkDirAll(KPageFilePathOnly);
   1.315 +	TEST(err==KErrNone||err==KErrAlreadyExists);
   1.316 +	err = fs.Delete(KPageFilePath);
   1.317 +	TEST(err==KErrNone||err==KErrNotFound);
   1.318 +	CPageCache* pcache = CPageCache::NewLC(2);
   1.319 +	//creating file
   1.320 +	TheTest.Printf(_L("Creating file for the page pool"));
   1.321 +	err = testPage.Create(fs, KPageFilePath, EFileWrite);
   1.322 +	TEST2(err, KErrNone);
   1.323 +	testPage.Set(*pcache);
   1.324 +	TheTest.Printf(_L("-> File created -> Closing "));
   1.325 +	testPage.Close();
   1.326 +	TheTest.Printf(_L("-> Closed "));
   1.327 +	//opening file, file should be present after successful creation
   1.328 +	TheTest.Printf(_L("Opening file for the page pool"));
   1.329 +	err = testPage.Open(fs,KPageFilePath, EFileWrite);
   1.330 +	TEST2(err, KErrNone);
   1.331 +	testPage.Set(*pcache);
   1.332 +	TheTest.Printf(_L("-> File opened -> Closing "));
   1.333 +	testPage.Close();
   1.334 +	TheTest.Printf(_L("-> Closed "));
   1.335 +	//try to replace already existing file
   1.336 +	//file should exist after successful creation
   1.337 +	TheTest.Printf(_L("Replacing file for the page pool"));
   1.338 +	err = testPage.Replace(fs, KPageFilePath, EFileWrite);
   1.339 +	TEST2(err, KErrNone);
   1.340 +	testPage.Set(*pcache);
   1.341 +	TheTest.Printf(_L("-> File replaced -> Closing "));
   1.342 +	testPage.Close();
   1.343 +	TheTest.Printf(_L("-> Closed "));
   1.344 +	//try to create temp file with unique name
   1.345 +	TheTest.Printf(_L("Creating temp unique file "));
   1.346 +	err = testPage.Temp(fs, KPageFilePathOnly, tempPageFileName, EFileWrite);
   1.347 +	TEST2(err, KErrNone);
   1.348 +	testPage.Set(*pcache);
   1.349 +	TheTest.Printf(_L("-> File created -> Closing "));
   1.350 +	testPage.Close();
   1.351 +	TheTest.Printf(_L("-> Closed "));
   1.352 +	//if file was propertly created we should be able to open it
   1.353 +	TheTest.Printf(_L("Opening temp unique file "));
   1.354 +	err = testPage.Open(fs, tempPageFileName, EFileWrite);
   1.355 +	TEST2(err, KErrNone);
   1.356 +	TheTest.Printf(_L("-> File opened -> Releasing "));
   1.357 +	testPage.Release();
   1.358 +	TheTest.Printf(_L("-> Released "));
   1.359 +	
   1.360 +	//open and flush temp file
   1.361 +	RFilePagePool testPage2(*pcache);
   1.362 +	err = testPage2.Open(fs, tempPageFileName, EFileWrite);
   1.363 +	TEST2(err, KErrNone);
   1.364 +	err = testPage2.Flush();
   1.365 +	TEST2(err, KErrNone);
   1.366 +	TRAP(err, testPage2.FlushL());
   1.367 +	TEST2(err, KErrNone);
   1.368 +	
   1.369 +	RFile& file = const_cast<RFile&>(testPage2.File());
   1.370 +	TFileName testIsSameFile;
   1.371 +	file.FullName(testIsSameFile);
   1.372 +	TEST2( testIsSameFile.Compare(tempPageFileName), 0);
   1.373 +	testPage2.Detach();
   1.374 +	file.Close();
   1.375 +	
   1.376 +	//attach and detach file
   1.377 +	file.Open(fs, testIsSameFile, EFileWrite|EFileShareReadersOrWriters);
   1.378 +	testPage2.Attach(file);
   1.379 +	testPage2.Detach();
   1.380 +	file.Close();
   1.381 +	testPage2.Close();
   1.382 +	
   1.383 +	CleanupStack::PopAndDestroy(pcache);
   1.384 +	fs.Close();
   1.385 +	}
   1.386 +
   1.387 +/**
   1.388 + * Struct needed in test5()
   1.389 + */
   1.390 +struct SCachePage
   1.391 +	{
   1.392 +	TCachePage iPage[1];
   1.393 +	TUint8 iData[KPoolPageSize];
   1.394 +	};
   1.395 +/**
   1.396 + * Class specially created to test protected API from RFilePagePool
   1.397 + */
   1.398 +class RFilePagePoolTestClass: public RFilePagePool
   1.399 +	{
   1.400 +public:
   1.401 +	void CallProtectedWriteL(SCachePage& page)
   1.402 +		{
   1.403 +		TPageChange change=page.iPage[0].iChange;
   1.404 +		WriteL(page.iPage[0].iRef,&page.iPage[1],change);
   1.405 +		}
   1.406 +	void CallProtectedReadL(SCachePage& page)
   1.407 +		{
   1.408 +		ReadL(page.iPage[0].iRef,&page.iPage[1]);
   1.409 +		}
   1.410 +	TPageRef CallProtectedExtendL(SCachePage& page)
   1.411 +		{
   1.412 +		ExtendL(&page.iPage[1],EPageReclaimable);
   1.413 +		return page.iPage[0].iRef;
   1.414 +		}
   1.415 +	};
   1.416 +
   1.417 +/**
   1.418 +@SYMTestCaseID          PDS-STORE-CT-4010
   1.419 +@SYMTestCaseDesc	    RFilePagePool protected API tests
   1.420 +@SYMTestPriority 	    High
   1.421 +@SYMTestActions  	    Tests for read and write and extend operations
   1.422 +@SYMTestExpectedResults Cache pages should be properly written and properly read from RFilePagePoolTestClass
   1.423 +@SYMDEF                 DEF135804
   1.424 +*/
   1.425 +LOCAL_C void test5L()
   1.426 +	{
   1.427 +	SCachePage page;
   1.428 +	page.iPage[0].iRef = 1;
   1.429 +	page.iPage[0].iChange=EPageNoChange;
   1.430 +	
   1.431 +	RFilePagePoolTestClass fpp;
   1.432 +	RFs fs;
   1.433 +	fs.Connect();
   1.434 +	fs.MkDirAll(KPageFilePathOnly);
   1.435 +	fs.Delete(KPageFilePath);
   1.436 +	CPageCache* pcache = CPageCache::NewLC(2);
   1.437 +	//creating file
   1.438 +	TheTest.Printf(_L("Creating file "));
   1.439 +	TInt err = fpp.Create(fs, KPageFilePath, EFileWrite);
   1.440 +	TEST2(err, KErrNone);
   1.441 +	fpp.Set(*pcache);
   1.442 +	TheTest.Printf(_L("-> File created -> Testing protected API "));
   1.443 +	TRAP(err, fpp.CallProtectedWriteL(page));
   1.444 +	TEST2(err, KErrNone);
   1.445 +	TheTest.Printf(_L("-> CallProtectedWriteL() done "));
   1.446 +	TRAP(err, fpp.CallProtectedReadL(page));
   1.447 +	TEST2(err, KErrNone);
   1.448 +	TheTest.Printf(_L("-> CallProtectedReadL() done "));
   1.449 +	TRAP(err, fpp.CallProtectedExtendL(page));
   1.450 +	TEST2(err, KErrNone);
   1.451 +	TheTest.Printf(_L("-> CallProtectedExtendL() done -> Closing"));
   1.452 +	fpp.Close();
   1.453 +	TheTest.Printf(_L("-> Closed "));
   1.454 +	CleanupStack::PopAndDestroy(pcache);
   1.455 +	fs.Close();
   1.456 +	}
   1.457 +
   1.458 +const TInt KCachePages=16;
   1.459 +
   1.460 +LOCAL_C void testallL(RStorePagePool& aPool)
   1.461 +	{
   1.462 +	TheTest.Start(_L("Connecting page pool"));
   1.463 +	aPool.Set(*CPageCache::NewLC(KCachePages));
   1.464 +	aPool.Create(*TheStore);
   1.465 +	TheTest.Next(_L("Basic operations"));
   1.466 +	test1L(aPool);
   1.467 +	TheTest.Next(_L("Large set TUint32"));
   1.468 +	test2L(aPool);
   1.469 +	aPool.Discard();
   1.470 +	aPool.ReclaimAllL();
   1.471 +	aPool.Close();
   1.472 +	TheTest.Next(_L("Tokens and streaming"));
   1.473 +	test3L(aPool);
   1.474 +	CleanupStack::PopAndDestroy();	//cache
   1.475 +	TheTest.Next(_L("PDS-STORE-CT-4009: RFilePagePool tests"));
   1.476 +	test4L();
   1.477 +	TheTest.Next(_L("PDS-STORE-CT-4010: RFilePagePool protected API tests"));
   1.478 +	test5L();
   1.479 +	TheTest.End();
   1.480 +	}
   1.481 +
   1.482 +/**
   1.483 +@SYMTestCaseID          PDS-STORE-CT-4021
   1.484 +@SYMTestCaseDesc	    RStorePagePool protected API tests
   1.485 +@SYMTestPriority 	    High
   1.486 +@SYMTestActions  	    Tests for different constructors
   1.487 +@SYMTestExpectedResults Objects must be created successfully
   1.488 +@SYMDEF                 DEF135804
   1.489 +*/
   1.490 +LOCAL_C void testconstructionL(CPBEncryptSet* aKey)
   1.491 +	{
   1.492 +	TheTest.Next(_L("PDS-STORE-CT-4021: RStorePagePool protected API tests"));
   1.493 +	CPageCache* pcache = CPageCache::NewLC(KCachePages);
   1.494 +	TStorePagePoolToken token;
   1.495 +	RStorePagePool poolcached(*pcache);
   1.496 +	poolcached.Create(*TheStore);
   1.497 +	test1L(poolcached);
   1.498 +	poolcached.Discard();
   1.499 +	poolcached.ReclaimAllL();
   1.500 +	poolcached.Close();	
   1.501 +	RStorePagePool poolstream(*TheStore);
   1.502 +	poolstream.Set(*pcache);
   1.503 +	test1L(poolstream);
   1.504 +	poolstream.Discard();
   1.505 +	poolstream.ReclaimAllL();
   1.506 +	poolstream.Close();
   1.507 +	RStorePagePool poolstreamtoken(*TheStore, token);
   1.508 +	poolstreamtoken.Set(*pcache);
   1.509 +	test1L(poolstreamtoken);	
   1.510 +	poolstreamtoken.Close();
   1.511 +	RSecureStorePagePool securepoolcached( *pcache, *aKey );
   1.512 +	securepoolcached.Create(*TheStore);
   1.513 +	test1L(securepoolcached);
   1.514 +	securepoolcached.Discard();
   1.515 +	securepoolcached.ReclaimAllL();
   1.516 +	securepoolcached.Close();
   1.517 +	
   1.518 +	
   1.519 +	CleanupStack::PopAndDestroy();
   1.520 +	
   1.521 +	}
   1.522 +
   1.523 +LOCAL_C void doMainL()
   1.524 +	{
   1.525 +	TheTest.Start(_L("Store PagePool"));
   1.526 +	TParsePtrC parse(KFileLocationSpec);
   1.527 +	
   1.528 +	TheStore=CPermanentFileStore::ReplaceLC(TheFs,parse.NameAndExt(),EFileRead|EFileWrite);
   1.529 +	TheStore->SetTypeL(TheStore->Layout());
   1.530 +	RStorePagePool pool1;
   1.531 +	testallL(pool1);
   1.532 +	TheTest.Next(_L("Secure PagePool"));
   1.533 +
   1.534 +	CPBEncryptSet* key = CPBEncryptSet::NewLC(_L("the password"));
   1.535 +	RSecureStorePagePool pool2(*key);
   1.536 +	testallL(pool2);
   1.537 +
   1.538 +
   1.539 +	testconstructionL(key);
   1.540 +	
   1.541 +	CleanupStack::PopAndDestroy(key);
   1.542 +	TheStore->CommitL();
   1.543 +	CleanupStack::PopAndDestroy();	// store
   1.544 +	}
   1.545 +
   1.546 +//
   1.547 +// Prepare the test directory.
   1.548 +//
   1.549 +LOCAL_C void setupTestDirectory()
   1.550 +    {
   1.551 +	TInt r=TheFs.Connect();
   1.552 +	TEST2(r, KErrNone);
   1.553 +//
   1.554 +	TDriveUnit drive(static_cast<TUint>(RFs::GetSystemDrive()));	
   1.555 +	TParse parse;
   1.556 +	parse.Set(drive.Name(), &KFileLocationSpec, NULL);
   1.557 +	
   1.558 +	r=TheFs.MkDir(parse.DriveAndPath());
   1.559 +	TEST(r==KErrNone||r==KErrAlreadyExists);
   1.560 +	r=TheFs.SetSessionPath(parse.DriveAndPath());
   1.561 +	TEST2(r, KErrNone);
   1.562 +	}
   1.563 +
   1.564 +//
   1.565 +// Initialise the cleanup stack.
   1.566 +//
   1.567 +LOCAL_C void setupCleanup()
   1.568 +    {
   1.569 +	TheTrapCleanup=CTrapCleanup::New();
   1.570 +	TEST(TheTrapCleanup!=NULL);
   1.571 +	TRAPD(r,\
   1.572 +		{\
   1.573 +		for (TInt i=KTestCleanupStack;i>0;i--)\
   1.574 +			CleanupStack::PushL((TAny*)1);\
   1.575 +		TEST2(r, KErrNone);\
   1.576 +		CleanupStack::Pop(KTestCleanupStack);\
   1.577 +		});
   1.578 +	TEST2(r, KErrNone);
   1.579 +	}
   1.580 +
   1.581 +
   1.582 +
   1.583 +LOCAL_C void DeleteTestFiles()
   1.584 +	{
   1.585 +
   1.586 +	RFs fs;
   1.587 +	TInt err = fs.Connect();
   1.588 +	if(err == KErrNone)
   1.589 +		{
   1.590 +		CDir* dir;
   1.591 +		fs.GetDir(KPageFilePathOnly, KEntryAttNormal , ESortNone, dir);
   1.592 +		for(TInt i=0; i< dir->Count();i++)
   1.593 +			{
   1.594 +			CDir& rdir = *dir;
   1.595 +			TFileName tf (KPageFilePathOnly);
   1.596 +			tf.Append(rdir[i].iName);
   1.597 +			err = fs.Delete( tf );
   1.598 +			if (err != KErrNone)
   1.599 +				{
   1.600 +				RDebug::Print(_L("Error %d deleting file \"%S\".\n"), err, &(rdir[i].iName));
   1.601 +				}
   1.602 +			else
   1.603 +				RDebug::Print(_L("File \"%S\" removed.\n"), &(rdir[i].iName));
   1.604 +			}
   1.605 +		delete dir;
   1.606 +		err = fs.RmDir(KPageFilePathOnly);
   1.607 +		if (err != KErrNone)
   1.608 +			{
   1.609 +			RDebug::Print(_L("Error %d deleting folder \"%S\".\n"), err, &KPageFilePathOnly);
   1.610 +			}
   1.611 +		fs.Close();
   1.612 +		}
   1.613 +	else
   1.614 +		{
   1.615 +		RDebug::Print(_L("Error %d connecting file session.\n"), err);
   1.616 +		}
   1.617 +	}
   1.618 +
   1.619 +LOCAL_C void DeleteDataFile(const TDesC& aFullName)
   1.620 +	{
   1.621 +	RFs fsSession;
   1.622 +	TInt err = fsSession.Connect();
   1.623 +	if(err == KErrNone)
   1.624 +		{
   1.625 +		TEntry entry;
   1.626 +		if(fsSession.Entry(aFullName, entry) == KErrNone)
   1.627 +			{
   1.628 +			RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
   1.629 +			err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
   1.630 +			if(err != KErrNone)
   1.631 +				{
   1.632 +				RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
   1.633 +				}
   1.634 +			err = fsSession.Delete(aFullName);
   1.635 +			if(err != KErrNone)
   1.636 +				{
   1.637 +				RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
   1.638 +				}
   1.639 +			}
   1.640 +		fsSession.Close();
   1.641 +		}
   1.642 +	else
   1.643 +		{
   1.644 +		RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
   1.645 +		}
   1.646 +	}
   1.647 +
   1.648 +GLDEF_C TInt E32Main()
   1.649 +	{
   1.650 +	TheTest.Title();
   1.651 +	setupTestDirectory();
   1.652 +	setupCleanup();
   1.653 +	__UHEAP_MARK;
   1.654 +//
   1.655 +	TRAPD(r,doMainL());
   1.656 +	TEST2(r, KErrNone);
   1.657 +
   1.658 +	//deletion of data files must be before call to .End() - DEF047652
   1.659 +	TDriveUnit drive(static_cast<TUint>(RFs::GetSystemDrive()));	
   1.660 +		TParse parse;
   1.661 +		parse.Set(drive.Name(), &KFileLocationSpec, NULL);
   1.662 +		::DeleteDataFile(parse.FullName());
   1.663 +		::DeleteTestFiles();
   1.664 +		
   1.665 +	TheTest.End();
   1.666 +//
   1.667 +	__UHEAP_MARKEND;
   1.668 +
   1.669 +	delete TheTrapCleanup;
   1.670 +	TheFs.Close();
   1.671 +	TheTest.Close();
   1.672 +	return 0;
   1.673 +	}
   1.674 +