sl@0: // Copyright (c) 1998-2010 Nokia Corporation and/or its subsidiary(-ies).
sl@0: // All rights reserved.
sl@0: // This component and the accompanying materials are made available
sl@0: // under the terms of "Eclipse Public License v1.0"
sl@0: // which accompanies this distribution, and is available
sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: //
sl@0: // Initial Contributors:
sl@0: // Nokia Corporation - initial contribution.
sl@0: //
sl@0: // Contributors:
sl@0: //
sl@0: // Description:
sl@0: //
sl@0: 
sl@0: #include <s32file.h>
sl@0: #include <e32test.h>
sl@0: 
sl@0: const TInt KTestCleanupStack=0x20;
sl@0: 
sl@0: // This is a path specification and should not be used as is
sl@0: _LIT(KFileLocationSpec, "Z:\\STOR-TST\\T_FPERM.DAT");
sl@0: const TUint8* KTestData=_S8("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");
sl@0: const TInt KTestLength=36;
sl@0: const TInt KTestTotal=KTestLength*(KTestLength+1);
sl@0: const TPtrC8 KTestDes(KTestData,KTestLength);
sl@0: 
sl@0: LOCAL_D CTrapCleanup* TheTrapCleanup;
sl@0: LOCAL_D RTest test(_L("t_storfperm"));
sl@0: LOCAL_D RFs TheFs;
sl@0: LOCAL_D TFileName TheTempFile;
sl@0: LOCAL_D TBuf8<KTestLength+1> TheBuf;
sl@0: /**
sl@0: @SYMTestCaseID          SYSLIB-STORE-CT-1152
sl@0: @SYMTestCaseDesc	    Tests empty streams
sl@0: @SYMTestPriority 	    High
sl@0: @SYMTestActions  	    Tests for empty stream buffers.Check for end of file error,overflow error flags
sl@0: @SYMTestExpectedResults Test must not fail
sl@0: @SYMREQ                 REQ0000
sl@0: */
sl@0: LOCAL_C void testEmptyL(CStreamStore& aStore)
sl@0: 	{
sl@0: 	test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1152 Stream created using 'extend' "));
sl@0: 	TStreamId empty=aStore.ExtendL();
sl@0: 	RStoreReadStream in;
sl@0: 	in.OpenL(aStore,empty);
sl@0: 	TUint8 b;
sl@0: 	test(in.Source()->ReadL(&b,1)==0);
sl@0: 	in.Source()->SeekL(0,KStreamBeginning);
sl@0: 	test(in.Source()->SeekL(MStreamBuf::ERead,EStreamMark)==KStreamBeginning);
sl@0: 	test(in.Source()->SizeL()==0);
sl@0: 	TRAPD(r,in.Source()->SeekL(MStreamBuf::ERead,EStreamBeginning,1));
sl@0: 	test(r==KErrEof);
sl@0: 	TRAP(r,in.Source()->SeekL(MStreamBuf::ERead,EStreamEnd,-1));
sl@0: 	test(r==KErrEof);
sl@0: 	in.Close();
sl@0: 	RStoreWriteStream out;
sl@0: 	out.OpenL(aStore,empty);
sl@0: 	out.Sink()->SeekL(0,KStreamBeginning);
sl@0: 	test(out.Sink()->SeekL(MStreamBuf::EWrite,EStreamMark)==KStreamBeginning);
sl@0: 	test(out.Sink()->SizeL()==0);
sl@0: 	TRAP(r,out.Sink()->SeekL(MStreamBuf::EWrite,EStreamBeginning,1));
sl@0: 	test(r==KErrEof);
sl@0: 	TRAP(r,out.Sink()->SeekL(MStreamBuf::EWrite,EStreamEnd,-1));
sl@0: 	test(r==KErrEof);
sl@0: 	TRAP(r,out.WriteUint8L(0));
sl@0: 	test(r==KErrOverflow);
sl@0: 	out.Close();
sl@0: //
sl@0: 	test.Next(_L("Replacing empty with empty"));
sl@0: 	out.ReplaceL(aStore,empty);
sl@0: 	out.CommitL();
sl@0: 	out.Release();
sl@0: 	in.OpenL(aStore,empty);
sl@0: 	test(in.Source()->ReadL(&b,1)==0);
sl@0: 	in.Source()->SeekL(0,KStreamBeginning);
sl@0: 	test(in.Source()->SeekL(MStreamBuf::ERead,EStreamMark)==KStreamBeginning);
sl@0: 	test(in.Source()->SizeL()==0);
sl@0: 	TRAP(r,in.Source()->SeekL(MStreamBuf::ERead,EStreamBeginning,1));
sl@0: 	test(r==KErrEof);
sl@0: 	TRAP(r,in.Source()->SeekL(MStreamBuf::ERead,EStreamEnd,-1));
sl@0: 	test(r==KErrEof);
sl@0: 	in.Close();
sl@0: 	out.OpenL(aStore,empty);
sl@0: 	out.Sink()->SeekL(0,KStreamBeginning);
sl@0: 	test(out.Sink()->SeekL(MStreamBuf::EWrite,EStreamMark)==KStreamBeginning);
sl@0: 	test(out.Sink()->SizeL()==0);
sl@0: 	TRAP(r,out.Sink()->SeekL(MStreamBuf::EWrite,EStreamBeginning,1));
sl@0: 	test(r==KErrEof);
sl@0: 	TRAP(r,out.Sink()->SeekL(MStreamBuf::EWrite,EStreamEnd,-1));
sl@0: 	test(r==KErrEof);
sl@0: 	TRAP(r,out.WriteUint8L(0));
sl@0: 	test(r==KErrOverflow);
sl@0: 	out.Close();
sl@0: 	}
sl@0: 
sl@0: //
sl@0: // Test writing to a store
sl@0: //
sl@0: LOCAL_C void testWriteL(CPersistentStore& aStore)
sl@0: 	{
sl@0: 	test.Next(_L("Writing..."));
sl@0: 	RStoreWriteStream out;
sl@0: 	TStreamId id=out.CreateLC(aStore);
sl@0: 	TStreamPos end=KStreamBeginning; //*
sl@0: 	for (TInt i=0;i<=KTestLength;++i)
sl@0: 		{
sl@0: 		test(out.Sink()->SeekL(MStreamBuf::EWrite,EStreamMark)==end); //*
sl@0: 		out.WriteL(KTestDes,i);
sl@0: 		test(out.Sink()->SeekL(0,EStreamEnd,-i)==end); //*
sl@0: 		out.WriteL(&KTestData[i],KTestLength-i);
sl@0: 		end+=KTestLength; //*
sl@0: 		}
sl@0: //*	test(out.Sink()->SizeL()==end.Offset());
sl@0: //*	out.WriteL(KTestDes,12);
sl@0: //*	end+=12;
sl@0: 	test(out.Sink()->SizeL()==end.Offset()); //*
sl@0: 	out.CommitL();
sl@0: 	test(out.Sink()->SizeL()==end.Offset()); //*
sl@0: 	out.Close();
sl@0: 	aStore.SetRootL(out.CreateL(aStore));
sl@0: 	out<<KTestDes;
sl@0: 	out<<id;
sl@0: 	out.CommitL();
sl@0: 	CleanupStack::PopAndDestroy();
sl@0: 	}
sl@0: 
sl@0: //
sl@0: // Test reading from a store
sl@0: //
sl@0: LOCAL_C void testReadL(RReadStream& aStream)
sl@0: 	{
sl@0: 	for (TInt i=KTestLength;i>=0;--i)
sl@0: 		{
sl@0: 		aStream.ReadL(TheBuf,i);
sl@0: 		test(TheBuf.Length()==i);
sl@0: 		TheBuf.SetMax();
sl@0: 		aStream.ReadL(&TheBuf[i],KTestLength-i);
sl@0: 		TheBuf.SetLength(KTestLength);
sl@0: 		test(TheBuf==KTestDes);
sl@0: 		}
sl@0: 	}
sl@0: 
sl@0: //
sl@0: // Test reading from a store
sl@0: //
sl@0: LOCAL_C void testReadL(const CPersistentStore& aStore)
sl@0: 	{
sl@0: 	test.Next(_L("Reading..."));
sl@0: 	RStoreReadStream in;
sl@0: 	in.OpenLC(aStore,aStore.Root());
sl@0: 	in>>TheBuf;
sl@0: 	TStreamId id;
sl@0: 	in>>id;
sl@0: 	in.Close();
sl@0: 	in.OpenL(aStore,id);
sl@0: 	testReadL(in);
sl@0: 	CleanupStack::PopAndDestroy();
sl@0: 	}
sl@0: 
sl@0: //
sl@0: // Test copying from one stream to another.
sl@0: //
sl@0: LOCAL_C void testCopyL(RWriteStream& aWriteStream,RReadStream& aReadStream)
sl@0: 	{
sl@0: 	test.Next(_L("Copying"));
sl@0: 	for (TInt i=KTestLength;i>=0;--i)
sl@0: 		{
sl@0: 		aWriteStream.WriteL(aReadStream,i);
sl@0: 		aReadStream.ReadL(aWriteStream,KTestLength-i);
sl@0: 		}
sl@0: 	}
sl@0: /**
sl@0: @SYMTestCaseID          SYSLIB-STORE-CT-1153
sl@0: @SYMTestCaseDesc	    Tests for writing using a permanent file store
sl@0: @SYMTestPriority 	    High
sl@0: @SYMTestActions  	    Tests for memory and end of file error while creating the store.
sl@0:                         Tests for writing to replaced,temporary,opened,created file.
sl@0: 						Tests for creating an already existing file.
sl@0: 						Tests for panic while deleting a file.
sl@0: @SYMTestExpectedResults Test must not fail
sl@0: @SYMREQ                 REQ0000
sl@0: */
sl@0: LOCAL_C void testWriteL()
sl@0: 	{
sl@0: 	test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1153 Creating and failing to open 'ghost' file "));
sl@0: 	
sl@0: 	TDriveUnit drive(static_cast<TUint>(RFs::GetSystemDrive()));	
sl@0: 	TParse parse;
sl@0: 	parse.Set(drive.Name(), &KFileLocationSpec, NULL);
sl@0: 	
sl@0: 	TheFs.Delete(parse.NameAndExt());
sl@0: 	CFileStore* store=CPermanentFileStore::CreateLC(TheFs,parse.NameAndExt(),EFileWrite);
sl@0: 	CleanupStack::PopAndDestroy();
sl@0: 	store=NULL;
sl@0: 	TRAPD(r,store=CPermanentFileStore::OpenL(TheFs,parse.NameAndExt(),EFileRead|EFileWrite));
sl@0: 	test(store==NULL&&r==KErrEof);
sl@0: //
sl@0: 	test.Next(_L("Empty tests on replaced file"));
sl@0: 	store=CPermanentFileStore::ReplaceLC(TheFs,parse.NameAndExt(),EFileWrite);
sl@0: 	store->SetTypeL(TUidType(KPermanentFileStoreLayoutUid,KPermanentFileStoreLayoutUid));
sl@0: 	testEmptyL(*store);
sl@0: 	CleanupStack::PopAndDestroy();
sl@0: //
sl@0: 	test.Next(_L("Writing to temp file"));
sl@0: 	store=CPermanentFileStore::TempLC(TheFs,parse.DriveAndPath(),TheTempFile,EFileWrite);
sl@0: 	store->SetTypeL(TUidType(store->Layout(),KNullUid,KPermanentFileStoreLayoutUid));
sl@0: 	testWriteL(*store);
sl@0: 	store->CommitL();
sl@0: 	CleanupStack::PopAndDestroy();
sl@0: 	(void)TheFs.Delete(TheTempFile);
sl@0: //
sl@0: 	test.Next(_L("Writing to temp file - 2"));
sl@0: 	store=CPermanentFileStore::TempL(TheFs,parse.DriveAndPath(),TheTempFile,EFileWrite);
sl@0: 	CleanupStack::PushL(store);
sl@0: 	store->SetTypeL(TUidType(store->Layout(),KNullUid,KPermanentFileStoreLayoutUid));
sl@0: 	testWriteL(*store);
sl@0: 	store->CommitL();
sl@0: 	CleanupStack::PopAndDestroy();
sl@0: //
sl@0: 	test.Next(_L("Writing to opened file"));
sl@0: 	store=CPermanentFileStore::OpenLC(TheFs,parse.NameAndExt(),EFileRead|EFileWrite);
sl@0: 	testWriteL(*store);
sl@0: 	store->CommitL();
sl@0: 	CleanupStack::PopAndDestroy();
sl@0: //
sl@0: 	test.Next(_L("Failing to create existing file"));
sl@0: 	store=NULL;
sl@0: 	TRAP(r,store=CPermanentFileStore::CreateL(TheFs,TheTempFile,EFileWrite));
sl@0: 	test(store==NULL&&r==KErrAlreadyExists);
sl@0: 	if (TheFs.Delete(parse.NameAndExt())!=KErrNone)
sl@0: 		test.Panic(_L("Deleting file"));
sl@0: //
sl@0: 	test.Next(_L("Writing to created file"));
sl@0: 	RFile file;
sl@0: 	test(file.Create(TheFs,parse.NameAndExt(),EFileWrite)==KErrNone);
sl@0: 	store=CPermanentFileStore::NewLC(file);
sl@0: 	store->SetTypeL(KPermanentFileStoreLayoutUid);
sl@0: 	testWriteL(*store);
sl@0: 	store->CommitL();
sl@0: 	CleanupStack::PopAndDestroy();
sl@0: 	}
sl@0: /**
sl@0: @SYMTestCaseID          SYSLIB-STORE-CT-1154
sl@0: @SYMTestCaseDesc	    Tests for reading using a permanent file store.
sl@0: @SYMTestPriority 	    High
sl@0: @SYMTestActions  	    Read data from a stream
sl@0: @SYMTestExpectedResults Test must not fail
sl@0: @SYMREQ                 REQ0000
sl@0: */
sl@0: LOCAL_C void testReadL()
sl@0: 	{
sl@0: 	test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1154 Reading from opened file "));
sl@0: 
sl@0: 	TParsePtrC parse(KFileLocationSpec);
sl@0: 	
sl@0: 	RFile file;
sl@0: 	test(file.Open(TheFs,parse.NameAndExt(),EFileRead)==KErrNone);
sl@0: 	CFileStore* store=CFileStore::FromLC(file);
sl@0: 	testReadL(*store);
sl@0: 	store->CommitL();
sl@0: 	CleanupStack::PopAndDestroy();
sl@0: //
sl@0: 	test.Next(_L("Reading from temp file"));
sl@0: 	test(file.Open(TheFs,TheTempFile,EFileRead)==KErrNone);
sl@0: 	store=CPermanentFileStore::FromLC(file);
sl@0: 	testReadL(*store);
sl@0: 	CleanupStack::PopAndDestroy();
sl@0: 	}
sl@0: 
sl@0: LOCAL_C void testRootL(CPersistentStore& aStore)
sl@0: 	{
sl@0: 	aStore.SetRootL(aStore.ExtendL());
sl@0: 	aStore.CommitL();
sl@0: 	}
sl@0: 
sl@0: LOCAL_C void testDummyL(CFileStore& aStore)
sl@0: 	{
sl@0: 	aStore.SetTypeL(aStore.Layout());
sl@0: 	aStore.CommitL();
sl@0: 	}
sl@0: /**
sl@0: @SYMTestCaseID          SYSLIB-STORE-CT-1155
sl@0: @SYMTestCaseDesc	    Tests for recovery from write failures
sl@0: @SYMTestPriority 	    High
sl@0: @SYMTestActions  	    Tests for access denied error during writing,commit and update process
sl@0: @SYMTestExpectedResults Test must not fail
sl@0: @SYMREQ                 REQ0000
sl@0: */
sl@0: LOCAL_C void testRecoveryL()
sl@0: 	{
sl@0: 	test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1155 Recovering from write failures "));
sl@0: 	TParsePtrC parse(KFileLocationSpec);
sl@0: 	
sl@0: 	CFileStore* store=CPermanentFileStore::ReplaceLC(TheFs,parse.NameAndExt(),EFileWrite);
sl@0: 	store->SetTypeL(KPermanentFileStoreLayoutUid);
sl@0: 	testWriteL(*store);
sl@0: 	store->CommitL();
sl@0: //
sl@0: 	store->File().Close();
sl@0: 	test(store->File().Open(TheFs,parse.NameAndExt(),EFileRead)==KErrNone);
sl@0: // fail during writing
sl@0: 	TRAPD(r,store->SetTypeL(store->Type());testWriteL(*store));
sl@0: 	test(r==KErrAccessDenied);
sl@0: 	store->Revert();
sl@0: 	testReadL(*store);
sl@0: // fail during commit
sl@0: 	TRAP(r,testRootL(*store));
sl@0: 	test(r==KErrAccessDenied);
sl@0: 	store->Revert();
sl@0: 	testReadL(*store);
sl@0: // fail during dummy update
sl@0: 	TRAP(r,testDummyL(*store));
sl@0: 	test(r==KErrAccessDenied);
sl@0: 	store->Revert();
sl@0: 	testReadL(*store);
sl@0: 	CleanupStack::PopAndDestroy();
sl@0: 	}
sl@0: /**
sl@0: @SYMTestCaseID          SYSLIB-STORE-CT-1156
sl@0: @SYMTestCaseDesc	    Tests copying in a single file store.
sl@0: @SYMTestPriority 	    High
sl@0: @SYMTestActions  	    Tests for copying using different buffer sizes
sl@0: @SYMTestExpectedResults Test must not fail
sl@0: @SYMREQ                 REQ0000
sl@0: */
sl@0: LOCAL_C void testCopyL()
sl@0: 	{
sl@0: 	test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1156 Copying using small transfers "));
sl@0: 	TParsePtrC parse(KFileLocationSpec);
sl@0: 	
sl@0: 	CFileStore* store=CFileStore::OpenLC(TheFs,parse.NameAndExt(),EFileRead|EFileWrite);
sl@0: 	RStoreReadStream in;
sl@0: 	in.OpenLC(*store,store->Root());
sl@0: 	in>>TheBuf;
sl@0: 	TStreamId copyId;
sl@0: 	in>>copyId;
sl@0: 	in.Close();
sl@0: 	in.OpenL(*store,copyId);
sl@0: 	RStoreWriteStream out;
sl@0: 	TStreamId id=out.CreateLC(*store);
sl@0: 	testCopyL(out,in);
sl@0: 	out.CommitL();
sl@0: 	out.Close();
sl@0: 	in.Close();
sl@0: 	in.OpenL(*store,id);
sl@0: 	testReadL(in);
sl@0: 	in.Close();
sl@0: //
sl@0: 	test.Next(_L("Copying using a single big transfer"));
sl@0: 	in.OpenL(*store,copyId);
sl@0: 	id=out.CreateL(*store);
sl@0: 	in.ReadL(out,KTestTotal);
sl@0: 	out.CommitL();
sl@0: 	out.Close();
sl@0: 	in.Close();
sl@0: 	in.OpenL(*store,id);
sl@0: 	testReadL(in);
sl@0: 	in.Close();
sl@0: 	in.OpenL(*store,copyId);
sl@0: 	id=out.CreateL(*store);
sl@0: 	out.WriteL(in,KTestTotal);
sl@0: 	out.CommitL();
sl@0: 	out.Close();
sl@0: 	in.Close();
sl@0: 	in.OpenL(*store,id);
sl@0: 	testReadL(in);
sl@0: //
sl@0: 	CleanupStack::PopAndDestroy(3);
sl@0: 	}
sl@0: 
sl@0: //
sl@0: // Test empty streams.
sl@0: //
sl@0: LOCAL_C void testEmptyL()
sl@0: 	{
sl@0: 	test.Next(_L("Empty tests on existing file"));
sl@0: 	TParsePtrC parse(KFileLocationSpec);
sl@0: 	CFileStore* store=CFileStore::OpenLC(TheFs,parse.NameAndExt(),EFileRead|EFileWrite);
sl@0: 	testEmptyL(*store);
sl@0: //
sl@0: 	CleanupStack::PopAndDestroy();
sl@0: 	}
sl@0: /**
sl@0: @SYMTestCaseID          SYSLIB-STORE-CT-1157
sl@0: @SYMTestCaseDesc	    Tests for detaching file from store
sl@0: @SYMTestPriority 	    High
sl@0: @SYMTestActions  	    Detach the file and discard the store
sl@0: @SYMTestExpectedResults Test must not fail
sl@0: @SYMREQ                 REQ0000
sl@0: */
sl@0: LOCAL_C void testDetachL()
sl@0: 	{
sl@0: 	test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1157 Writing a file store "));
sl@0: 	TParsePtrC parse(KFileLocationSpec);
sl@0: 	
sl@0: 	CFileStore* store=CPermanentFileStore::ReplaceLC(TheFs,parse.NameAndExt(),EFileWrite|EFileRead);
sl@0: 	store->SetTypeL(KPermanentFileStoreLayoutUid);
sl@0: 	testWriteL(*store);
sl@0: 	store->CommitL();
sl@0: //
sl@0: 	test.Next(_L("Detach the file and discard the store"));
sl@0: 	RFile file=store->File();
sl@0: 	store->Detach();
sl@0: 	store->Reattach(file);
sl@0: 	RFile& file2 = store->File();
sl@0: 	test(file2.SubSessionHandle() != KNullHandle);
sl@0: 	store->Detach();
sl@0: 	CleanupStack::PopAndDestroy();
sl@0: //
sl@0: 	test.Next(_L("Re-construct the store and check the contents"));
sl@0: 	store=CFileStore::FromLC(file);
sl@0: 	testReadL(*store);
sl@0: 	store->Reset();
sl@0: 	CleanupStack::PopAndDestroy();
sl@0: 	}
sl@0: /**
sl@0: @SYMTestCaseID          SYSLIB-STORE-CT-1158
sl@0: @SYMTestCaseDesc	    Tests for defect No 039456
sl@0:                         Permanent File Store allows code to open and read from deleted streams
sl@0: @SYMTestPriority 	    High
sl@0: @SYMTestActions  	    Create four streams,delete last three and close the store.
sl@0:                         Open the store and test for reading the first stream.
sl@0: @SYMTestExpectedResults Test must not fail
sl@0: @SYMREQ                 REQ0000
sl@0: */
sl@0: LOCAL_C void testDef039456L()
sl@0: {
sl@0: 	_LIT(KMsvDrivelessTestPath, ":\\t_storperm.dat");
sl@0: 	TFileName msvTestPath;
sl@0: 	msvTestPath.Append(RFs::GetSystemDriveChar());
sl@0: 	msvTestPath.Append(KMsvDrivelessTestPath);
sl@0: 	
sl@0: 	_LIT(KStringOne, "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111");
sl@0: 	_LIT(KStringTwo, "2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222");
sl@0: 
sl@0: 	test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1158 "));
sl@0: 	TheFs.Delete(msvTestPath);
sl@0: 	CPermanentFileStore* testStore = CPermanentFileStore::CreateLC(TheFs, msvTestPath, EFileWrite|EFileShareAny);
sl@0: 	testStore->SetTypeL(KPermanentFileStoreLayoutUid);
sl@0: 
sl@0: 	// create four streams,
sl@0: 	RStoreWriteStream wstream;
sl@0: 	TStreamId stream_one=wstream.CreateLC(*testStore);
sl@0: 	wstream << KStringOne;
sl@0: 	wstream.CommitL();
sl@0: 	CleanupStack::PopAndDestroy(&wstream);
sl@0: 	testStore->CommitL();
sl@0: 	TStreamId stream_two=wstream.CreateLC(*testStore);
sl@0: 	wstream << KStringTwo;
sl@0: 	wstream.CommitL();
sl@0: 	CleanupStack::PopAndDestroy(&wstream);
sl@0: 	testStore->CommitL();
sl@0: 	TStreamId stream_three=wstream.CreateLC(*testStore);
sl@0: 	wstream << KStringOne;
sl@0: 	wstream.CommitL();
sl@0: 	CleanupStack::PopAndDestroy(&wstream);
sl@0: 	testStore->CommitL();
sl@0: 	TStreamId stream_four=wstream.CreateLC(*testStore);
sl@0: 	wstream << KStringOne;
sl@0: 	wstream.CommitL();
sl@0: 	CleanupStack::PopAndDestroy(&wstream);
sl@0: 	testStore->CommitL();
sl@0: 
sl@0: 	// delete last three streams added (not in the order added)
sl@0: 	testStore->DeleteL(stream_four);
sl@0: 	testStore->CommitL();
sl@0: 	testStore->DeleteL(stream_three);
sl@0: 	testStore->CommitL();
sl@0: 	testStore->DeleteL(stream_two);
sl@0: 	testStore->CommitL();
sl@0: 
sl@0: 	// close the store
sl@0: 	CleanupStack::PopAndDestroy(testStore);
sl@0: 
sl@0: 	// open store, try and read each of the streams, only stream_one should be present
sl@0: 	testStore = CPermanentFileStore::OpenLC(TheFs, msvTestPath, EFileWrite|EFileShareAny);
sl@0: 	RStoreReadStream rstream1, rstream2;
sl@0: 
sl@0: 	// check stream_one ok
sl@0: 	TRAPD(error_stream_one,rstream1.OpenL(*testStore,stream_one));
sl@0: 	test(error_stream_one==KErrNone);
sl@0: 	rstream1.Close();
sl@0: 
sl@0: 	// shouldn't be able to open this stream as we deleted it....
sl@0: 	TRAPD(error_stream_two,rstream2.OpenL(*testStore,stream_two));
sl@0: 	test(error_stream_two==KErrNotFound);
sl@0: 
sl@0: 	CleanupStack::PopAndDestroy(testStore);
sl@0: 	
sl@0: 	(void)TheFs.Delete(msvTestPath);
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: @SYMTestCaseID          PDS-STORE-UT-4059
sl@0: @SYMTestCaseDesc        Tests for defect No ou1cimx1#422232
sl@0:                         The installed help topics are not organized to Application help topics.
sl@0: @SYMTestPriority        High
sl@0: @SYMTestActions         Tests that the EFileWriteDirectIO is appended only when necessary, also
sl@0:                         test that any EFileWriteBuffered is unset (no error occurs when this is
sl@0:                         passed in)
sl@0: @SYMTestExpectedResults Test must not fail
sl@0: @SYMDEF                 ou1cimx1#422232
sl@0: */
sl@0: LOCAL_C void testOpenL()
sl@0:     {    
sl@0:     _LIT(KFileName,"C:\\t_storfperm.dat");
sl@0:     
sl@0:     test.Next(_L("@SYMTestCaseID:PDS-STORE-UT-4059: CPermanentFileStore::ReplaceL() test"));
sl@0:     CPermanentFileStore* testStore = CPermanentFileStore::ReplaceL(TheFs, KFileName, EFileWrite|EFileWriteBuffered);
sl@0:     delete testStore;
sl@0:     
sl@0:     (void)TheFs.Delete(KFileName);
sl@0:     }
sl@0: 
sl@0: //
sl@0: // Prepare the test directory.
sl@0: //
sl@0: LOCAL_C void setupTestDirectory()
sl@0:     {
sl@0: 	TInt r=TheFs.Connect();
sl@0: 	test(r==KErrNone);
sl@0: //
sl@0: 	TDriveUnit drive(static_cast<TUint>(RFs::GetSystemDrive()));	
sl@0: 	TParse parse;
sl@0: 	parse.Set(drive.Name(), &KFileLocationSpec, NULL);
sl@0: 	
sl@0: 	r=TheFs.MkDir(parse.DriveAndPath());
sl@0: 	test(r==KErrNone||r==KErrAlreadyExists);
sl@0: 	r=TheFs.SetSessionPath(parse.DriveAndPath());
sl@0: 	test(r==KErrNone);
sl@0: 	}
sl@0: 
sl@0: //
sl@0: // Initialise the cleanup stack.
sl@0: //
sl@0: LOCAL_C void setupCleanup()
sl@0:     {
sl@0: 	TheTrapCleanup=CTrapCleanup::New();
sl@0: 	test(TheTrapCleanup!=NULL);
sl@0: 	TRAPD(r,\
sl@0: 		{\
sl@0: 		for (TInt i=KTestCleanupStack;i>0;i--)\
sl@0: 			CleanupStack::PushL((TAny*)0);\
sl@0: 		CleanupStack::Pop(KTestCleanupStack);\
sl@0: 		});
sl@0: 	test(r==KErrNone);
sl@0: 	}
sl@0: 
sl@0: LOCAL_C void DeleteDataFile(const TDesC& aFullName)
sl@0: 	{
sl@0: 	RFs fsSession;
sl@0: 	TInt err = fsSession.Connect();
sl@0: 	if(err == KErrNone)
sl@0: 		{
sl@0: 		TEntry entry;
sl@0: 		if(fsSession.Entry(aFullName, entry) == KErrNone)
sl@0: 			{
sl@0: 			RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
sl@0: 			err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
sl@0: 			if(err != KErrNone)
sl@0: 				{
sl@0: 				RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
sl@0: 				}
sl@0: 			err = fsSession.Delete(aFullName);
sl@0: 			if(err != KErrNone)
sl@0: 				{
sl@0: 				RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
sl@0: 				}
sl@0: 			}
sl@0: 		fsSession.Close();
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 		RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
sl@0: 		}
sl@0: 	}
sl@0: 
sl@0: //
sl@0: // Test permanent file store.
sl@0: //
sl@0: GLDEF_C TInt E32Main()
sl@0:     {
sl@0: 	test.Title();
sl@0: 	setupTestDirectory();
sl@0: 	setupCleanup();
sl@0: 	__UHEAP_MARK;
sl@0: //
sl@0: 	test.Start(_L("Test permanent file store"));
sl@0: 	TRAPD(r,testWriteL());
sl@0: 	test(r==KErrNone);
sl@0: 	TRAP(r,testReadL());
sl@0: 	test(r==KErrNone);
sl@0: 	TRAP(r,testRecoveryL());
sl@0: 	test(r==KErrNone);
sl@0: 	TRAP(r,testCopyL());
sl@0: 	test(r==KErrNone);
sl@0: 	TRAP(r,testEmptyL());
sl@0: 	test(r==KErrNone);
sl@0: 	TRAP(r,testDetachL());
sl@0: 	test(r==KErrNone);
sl@0: 	TRAP(r,testDef039456L());
sl@0: 	test(r==KErrNone);
sl@0: 	TRAP(r,testOpenL());
sl@0: 	test(r==KErrNone);
sl@0: 	
sl@0: 	//deletion of data files must be before call to .End() - DEF047652
sl@0: 	TDriveUnit drive(static_cast<TUint>(RFs::GetSystemDrive()));	
sl@0: 	TParse parse;
sl@0: 	parse.Set(drive.Name(), &KFileLocationSpec, NULL);
sl@0: 	::DeleteDataFile(parse.FullName());
sl@0: 
sl@0: 	test.End();
sl@0: //
sl@0: 	__UHEAP_MARKEND;
sl@0: 
sl@0: 	delete TheTrapCleanup;
sl@0: 	if (TheFs.Delete(TheTempFile)!=KErrNone)
sl@0: 		test.Panic(_L("Deleting temp file"));
sl@0: 	TheFs.Close();
sl@0: 	test.Close();
sl@0: 	return 0;
sl@0:     }
sl@0: