os/persistentdata/persistentstorage/store/TFILE/t_storfperm.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 1998-2010 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include <s32file.h>
sl@0
    17
#include <e32test.h>
sl@0
    18
sl@0
    19
const TInt KTestCleanupStack=0x20;
sl@0
    20
sl@0
    21
// This is a path specification and should not be used as is
sl@0
    22
_LIT(KFileLocationSpec, "Z:\\STOR-TST\\T_FPERM.DAT");
sl@0
    23
const TUint8* KTestData=_S8("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");
sl@0
    24
const TInt KTestLength=36;
sl@0
    25
const TInt KTestTotal=KTestLength*(KTestLength+1);
sl@0
    26
const TPtrC8 KTestDes(KTestData,KTestLength);
sl@0
    27
sl@0
    28
LOCAL_D CTrapCleanup* TheTrapCleanup;
sl@0
    29
LOCAL_D RTest test(_L("t_storfperm"));
sl@0
    30
LOCAL_D RFs TheFs;
sl@0
    31
LOCAL_D TFileName TheTempFile;
sl@0
    32
LOCAL_D TBuf8<KTestLength+1> TheBuf;
sl@0
    33
/**
sl@0
    34
@SYMTestCaseID          SYSLIB-STORE-CT-1152
sl@0
    35
@SYMTestCaseDesc	    Tests empty streams
sl@0
    36
@SYMTestPriority 	    High
sl@0
    37
@SYMTestActions  	    Tests for empty stream buffers.Check for end of file error,overflow error flags
sl@0
    38
@SYMTestExpectedResults Test must not fail
sl@0
    39
@SYMREQ                 REQ0000
sl@0
    40
*/
sl@0
    41
LOCAL_C void testEmptyL(CStreamStore& aStore)
sl@0
    42
	{
sl@0
    43
	test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1152 Stream created using 'extend' "));
sl@0
    44
	TStreamId empty=aStore.ExtendL();
sl@0
    45
	RStoreReadStream in;
sl@0
    46
	in.OpenL(aStore,empty);
sl@0
    47
	TUint8 b;
sl@0
    48
	test(in.Source()->ReadL(&b,1)==0);
sl@0
    49
	in.Source()->SeekL(0,KStreamBeginning);
sl@0
    50
	test(in.Source()->SeekL(MStreamBuf::ERead,EStreamMark)==KStreamBeginning);
sl@0
    51
	test(in.Source()->SizeL()==0);
sl@0
    52
	TRAPD(r,in.Source()->SeekL(MStreamBuf::ERead,EStreamBeginning,1));
sl@0
    53
	test(r==KErrEof);
sl@0
    54
	TRAP(r,in.Source()->SeekL(MStreamBuf::ERead,EStreamEnd,-1));
sl@0
    55
	test(r==KErrEof);
sl@0
    56
	in.Close();
sl@0
    57
	RStoreWriteStream out;
sl@0
    58
	out.OpenL(aStore,empty);
sl@0
    59
	out.Sink()->SeekL(0,KStreamBeginning);
sl@0
    60
	test(out.Sink()->SeekL(MStreamBuf::EWrite,EStreamMark)==KStreamBeginning);
sl@0
    61
	test(out.Sink()->SizeL()==0);
sl@0
    62
	TRAP(r,out.Sink()->SeekL(MStreamBuf::EWrite,EStreamBeginning,1));
sl@0
    63
	test(r==KErrEof);
sl@0
    64
	TRAP(r,out.Sink()->SeekL(MStreamBuf::EWrite,EStreamEnd,-1));
sl@0
    65
	test(r==KErrEof);
sl@0
    66
	TRAP(r,out.WriteUint8L(0));
sl@0
    67
	test(r==KErrOverflow);
sl@0
    68
	out.Close();
sl@0
    69
//
sl@0
    70
	test.Next(_L("Replacing empty with empty"));
sl@0
    71
	out.ReplaceL(aStore,empty);
sl@0
    72
	out.CommitL();
sl@0
    73
	out.Release();
sl@0
    74
	in.OpenL(aStore,empty);
sl@0
    75
	test(in.Source()->ReadL(&b,1)==0);
sl@0
    76
	in.Source()->SeekL(0,KStreamBeginning);
sl@0
    77
	test(in.Source()->SeekL(MStreamBuf::ERead,EStreamMark)==KStreamBeginning);
sl@0
    78
	test(in.Source()->SizeL()==0);
sl@0
    79
	TRAP(r,in.Source()->SeekL(MStreamBuf::ERead,EStreamBeginning,1));
sl@0
    80
	test(r==KErrEof);
sl@0
    81
	TRAP(r,in.Source()->SeekL(MStreamBuf::ERead,EStreamEnd,-1));
sl@0
    82
	test(r==KErrEof);
sl@0
    83
	in.Close();
sl@0
    84
	out.OpenL(aStore,empty);
sl@0
    85
	out.Sink()->SeekL(0,KStreamBeginning);
sl@0
    86
	test(out.Sink()->SeekL(MStreamBuf::EWrite,EStreamMark)==KStreamBeginning);
sl@0
    87
	test(out.Sink()->SizeL()==0);
sl@0
    88
	TRAP(r,out.Sink()->SeekL(MStreamBuf::EWrite,EStreamBeginning,1));
sl@0
    89
	test(r==KErrEof);
sl@0
    90
	TRAP(r,out.Sink()->SeekL(MStreamBuf::EWrite,EStreamEnd,-1));
sl@0
    91
	test(r==KErrEof);
sl@0
    92
	TRAP(r,out.WriteUint8L(0));
sl@0
    93
	test(r==KErrOverflow);
sl@0
    94
	out.Close();
sl@0
    95
	}
sl@0
    96
sl@0
    97
//
sl@0
    98
// Test writing to a store
sl@0
    99
//
sl@0
   100
LOCAL_C void testWriteL(CPersistentStore& aStore)
sl@0
   101
	{
sl@0
   102
	test.Next(_L("Writing..."));
sl@0
   103
	RStoreWriteStream out;
sl@0
   104
	TStreamId id=out.CreateLC(aStore);
sl@0
   105
	TStreamPos end=KStreamBeginning; //*
sl@0
   106
	for (TInt i=0;i<=KTestLength;++i)
sl@0
   107
		{
sl@0
   108
		test(out.Sink()->SeekL(MStreamBuf::EWrite,EStreamMark)==end); //*
sl@0
   109
		out.WriteL(KTestDes,i);
sl@0
   110
		test(out.Sink()->SeekL(0,EStreamEnd,-i)==end); //*
sl@0
   111
		out.WriteL(&KTestData[i],KTestLength-i);
sl@0
   112
		end+=KTestLength; //*
sl@0
   113
		}
sl@0
   114
//*	test(out.Sink()->SizeL()==end.Offset());
sl@0
   115
//*	out.WriteL(KTestDes,12);
sl@0
   116
//*	end+=12;
sl@0
   117
	test(out.Sink()->SizeL()==end.Offset()); //*
sl@0
   118
	out.CommitL();
sl@0
   119
	test(out.Sink()->SizeL()==end.Offset()); //*
sl@0
   120
	out.Close();
sl@0
   121
	aStore.SetRootL(out.CreateL(aStore));
sl@0
   122
	out<<KTestDes;
sl@0
   123
	out<<id;
sl@0
   124
	out.CommitL();
sl@0
   125
	CleanupStack::PopAndDestroy();
sl@0
   126
	}
sl@0
   127
sl@0
   128
//
sl@0
   129
// Test reading from a store
sl@0
   130
//
sl@0
   131
LOCAL_C void testReadL(RReadStream& aStream)
sl@0
   132
	{
sl@0
   133
	for (TInt i=KTestLength;i>=0;--i)
sl@0
   134
		{
sl@0
   135
		aStream.ReadL(TheBuf,i);
sl@0
   136
		test(TheBuf.Length()==i);
sl@0
   137
		TheBuf.SetMax();
sl@0
   138
		aStream.ReadL(&TheBuf[i],KTestLength-i);
sl@0
   139
		TheBuf.SetLength(KTestLength);
sl@0
   140
		test(TheBuf==KTestDes);
sl@0
   141
		}
sl@0
   142
	}
sl@0
   143
sl@0
   144
//
sl@0
   145
// Test reading from a store
sl@0
   146
//
sl@0
   147
LOCAL_C void testReadL(const CPersistentStore& aStore)
sl@0
   148
	{
sl@0
   149
	test.Next(_L("Reading..."));
sl@0
   150
	RStoreReadStream in;
sl@0
   151
	in.OpenLC(aStore,aStore.Root());
sl@0
   152
	in>>TheBuf;
sl@0
   153
	TStreamId id;
sl@0
   154
	in>>id;
sl@0
   155
	in.Close();
sl@0
   156
	in.OpenL(aStore,id);
sl@0
   157
	testReadL(in);
sl@0
   158
	CleanupStack::PopAndDestroy();
sl@0
   159
	}
sl@0
   160
sl@0
   161
//
sl@0
   162
// Test copying from one stream to another.
sl@0
   163
//
sl@0
   164
LOCAL_C void testCopyL(RWriteStream& aWriteStream,RReadStream& aReadStream)
sl@0
   165
	{
sl@0
   166
	test.Next(_L("Copying"));
sl@0
   167
	for (TInt i=KTestLength;i>=0;--i)
sl@0
   168
		{
sl@0
   169
		aWriteStream.WriteL(aReadStream,i);
sl@0
   170
		aReadStream.ReadL(aWriteStream,KTestLength-i);
sl@0
   171
		}
sl@0
   172
	}
sl@0
   173
/**
sl@0
   174
@SYMTestCaseID          SYSLIB-STORE-CT-1153
sl@0
   175
@SYMTestCaseDesc	    Tests for writing using a permanent file store
sl@0
   176
@SYMTestPriority 	    High
sl@0
   177
@SYMTestActions  	    Tests for memory and end of file error while creating the store.
sl@0
   178
                        Tests for writing to replaced,temporary,opened,created file.
sl@0
   179
						Tests for creating an already existing file.
sl@0
   180
						Tests for panic while deleting a file.
sl@0
   181
@SYMTestExpectedResults Test must not fail
sl@0
   182
@SYMREQ                 REQ0000
sl@0
   183
*/
sl@0
   184
LOCAL_C void testWriteL()
sl@0
   185
	{
sl@0
   186
	test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1153 Creating and failing to open 'ghost' file "));
sl@0
   187
	
sl@0
   188
	TDriveUnit drive(static_cast<TUint>(RFs::GetSystemDrive()));	
sl@0
   189
	TParse parse;
sl@0
   190
	parse.Set(drive.Name(), &KFileLocationSpec, NULL);
sl@0
   191
	
sl@0
   192
	TheFs.Delete(parse.NameAndExt());
sl@0
   193
	CFileStore* store=CPermanentFileStore::CreateLC(TheFs,parse.NameAndExt(),EFileWrite);
sl@0
   194
	CleanupStack::PopAndDestroy();
sl@0
   195
	store=NULL;
sl@0
   196
	TRAPD(r,store=CPermanentFileStore::OpenL(TheFs,parse.NameAndExt(),EFileRead|EFileWrite));
sl@0
   197
	test(store==NULL&&r==KErrEof);
sl@0
   198
//
sl@0
   199
	test.Next(_L("Empty tests on replaced file"));
sl@0
   200
	store=CPermanentFileStore::ReplaceLC(TheFs,parse.NameAndExt(),EFileWrite);
sl@0
   201
	store->SetTypeL(TUidType(KPermanentFileStoreLayoutUid,KPermanentFileStoreLayoutUid));
sl@0
   202
	testEmptyL(*store);
sl@0
   203
	CleanupStack::PopAndDestroy();
sl@0
   204
//
sl@0
   205
	test.Next(_L("Writing to temp file"));
sl@0
   206
	store=CPermanentFileStore::TempLC(TheFs,parse.DriveAndPath(),TheTempFile,EFileWrite);
sl@0
   207
	store->SetTypeL(TUidType(store->Layout(),KNullUid,KPermanentFileStoreLayoutUid));
sl@0
   208
	testWriteL(*store);
sl@0
   209
	store->CommitL();
sl@0
   210
	CleanupStack::PopAndDestroy();
sl@0
   211
	(void)TheFs.Delete(TheTempFile);
sl@0
   212
//
sl@0
   213
	test.Next(_L("Writing to temp file - 2"));
sl@0
   214
	store=CPermanentFileStore::TempL(TheFs,parse.DriveAndPath(),TheTempFile,EFileWrite);
sl@0
   215
	CleanupStack::PushL(store);
sl@0
   216
	store->SetTypeL(TUidType(store->Layout(),KNullUid,KPermanentFileStoreLayoutUid));
sl@0
   217
	testWriteL(*store);
sl@0
   218
	store->CommitL();
sl@0
   219
	CleanupStack::PopAndDestroy();
sl@0
   220
//
sl@0
   221
	test.Next(_L("Writing to opened file"));
sl@0
   222
	store=CPermanentFileStore::OpenLC(TheFs,parse.NameAndExt(),EFileRead|EFileWrite);
sl@0
   223
	testWriteL(*store);
sl@0
   224
	store->CommitL();
sl@0
   225
	CleanupStack::PopAndDestroy();
sl@0
   226
//
sl@0
   227
	test.Next(_L("Failing to create existing file"));
sl@0
   228
	store=NULL;
sl@0
   229
	TRAP(r,store=CPermanentFileStore::CreateL(TheFs,TheTempFile,EFileWrite));
sl@0
   230
	test(store==NULL&&r==KErrAlreadyExists);
sl@0
   231
	if (TheFs.Delete(parse.NameAndExt())!=KErrNone)
sl@0
   232
		test.Panic(_L("Deleting file"));
sl@0
   233
//
sl@0
   234
	test.Next(_L("Writing to created file"));
sl@0
   235
	RFile file;
sl@0
   236
	test(file.Create(TheFs,parse.NameAndExt(),EFileWrite)==KErrNone);
sl@0
   237
	store=CPermanentFileStore::NewLC(file);
sl@0
   238
	store->SetTypeL(KPermanentFileStoreLayoutUid);
sl@0
   239
	testWriteL(*store);
sl@0
   240
	store->CommitL();
sl@0
   241
	CleanupStack::PopAndDestroy();
sl@0
   242
	}
sl@0
   243
/**
sl@0
   244
@SYMTestCaseID          SYSLIB-STORE-CT-1154
sl@0
   245
@SYMTestCaseDesc	    Tests for reading using a permanent file store.
sl@0
   246
@SYMTestPriority 	    High
sl@0
   247
@SYMTestActions  	    Read data from a stream
sl@0
   248
@SYMTestExpectedResults Test must not fail
sl@0
   249
@SYMREQ                 REQ0000
sl@0
   250
*/
sl@0
   251
LOCAL_C void testReadL()
sl@0
   252
	{
sl@0
   253
	test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1154 Reading from opened file "));
sl@0
   254
sl@0
   255
	TParsePtrC parse(KFileLocationSpec);
sl@0
   256
	
sl@0
   257
	RFile file;
sl@0
   258
	test(file.Open(TheFs,parse.NameAndExt(),EFileRead)==KErrNone);
sl@0
   259
	CFileStore* store=CFileStore::FromLC(file);
sl@0
   260
	testReadL(*store);
sl@0
   261
	store->CommitL();
sl@0
   262
	CleanupStack::PopAndDestroy();
sl@0
   263
//
sl@0
   264
	test.Next(_L("Reading from temp file"));
sl@0
   265
	test(file.Open(TheFs,TheTempFile,EFileRead)==KErrNone);
sl@0
   266
	store=CPermanentFileStore::FromLC(file);
sl@0
   267
	testReadL(*store);
sl@0
   268
	CleanupStack::PopAndDestroy();
sl@0
   269
	}
sl@0
   270
sl@0
   271
LOCAL_C void testRootL(CPersistentStore& aStore)
sl@0
   272
	{
sl@0
   273
	aStore.SetRootL(aStore.ExtendL());
sl@0
   274
	aStore.CommitL();
sl@0
   275
	}
sl@0
   276
sl@0
   277
LOCAL_C void testDummyL(CFileStore& aStore)
sl@0
   278
	{
sl@0
   279
	aStore.SetTypeL(aStore.Layout());
sl@0
   280
	aStore.CommitL();
sl@0
   281
	}
sl@0
   282
/**
sl@0
   283
@SYMTestCaseID          SYSLIB-STORE-CT-1155
sl@0
   284
@SYMTestCaseDesc	    Tests for recovery from write failures
sl@0
   285
@SYMTestPriority 	    High
sl@0
   286
@SYMTestActions  	    Tests for access denied error during writing,commit and update process
sl@0
   287
@SYMTestExpectedResults Test must not fail
sl@0
   288
@SYMREQ                 REQ0000
sl@0
   289
*/
sl@0
   290
LOCAL_C void testRecoveryL()
sl@0
   291
	{
sl@0
   292
	test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1155 Recovering from write failures "));
sl@0
   293
	TParsePtrC parse(KFileLocationSpec);
sl@0
   294
	
sl@0
   295
	CFileStore* store=CPermanentFileStore::ReplaceLC(TheFs,parse.NameAndExt(),EFileWrite);
sl@0
   296
	store->SetTypeL(KPermanentFileStoreLayoutUid);
sl@0
   297
	testWriteL(*store);
sl@0
   298
	store->CommitL();
sl@0
   299
//
sl@0
   300
	store->File().Close();
sl@0
   301
	test(store->File().Open(TheFs,parse.NameAndExt(),EFileRead)==KErrNone);
sl@0
   302
// fail during writing
sl@0
   303
	TRAPD(r,store->SetTypeL(store->Type());testWriteL(*store));
sl@0
   304
	test(r==KErrAccessDenied);
sl@0
   305
	store->Revert();
sl@0
   306
	testReadL(*store);
sl@0
   307
// fail during commit
sl@0
   308
	TRAP(r,testRootL(*store));
sl@0
   309
	test(r==KErrAccessDenied);
sl@0
   310
	store->Revert();
sl@0
   311
	testReadL(*store);
sl@0
   312
// fail during dummy update
sl@0
   313
	TRAP(r,testDummyL(*store));
sl@0
   314
	test(r==KErrAccessDenied);
sl@0
   315
	store->Revert();
sl@0
   316
	testReadL(*store);
sl@0
   317
	CleanupStack::PopAndDestroy();
sl@0
   318
	}
sl@0
   319
/**
sl@0
   320
@SYMTestCaseID          SYSLIB-STORE-CT-1156
sl@0
   321
@SYMTestCaseDesc	    Tests copying in a single file store.
sl@0
   322
@SYMTestPriority 	    High
sl@0
   323
@SYMTestActions  	    Tests for copying using different buffer sizes
sl@0
   324
@SYMTestExpectedResults Test must not fail
sl@0
   325
@SYMREQ                 REQ0000
sl@0
   326
*/
sl@0
   327
LOCAL_C void testCopyL()
sl@0
   328
	{
sl@0
   329
	test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1156 Copying using small transfers "));
sl@0
   330
	TParsePtrC parse(KFileLocationSpec);
sl@0
   331
	
sl@0
   332
	CFileStore* store=CFileStore::OpenLC(TheFs,parse.NameAndExt(),EFileRead|EFileWrite);
sl@0
   333
	RStoreReadStream in;
sl@0
   334
	in.OpenLC(*store,store->Root());
sl@0
   335
	in>>TheBuf;
sl@0
   336
	TStreamId copyId;
sl@0
   337
	in>>copyId;
sl@0
   338
	in.Close();
sl@0
   339
	in.OpenL(*store,copyId);
sl@0
   340
	RStoreWriteStream out;
sl@0
   341
	TStreamId id=out.CreateLC(*store);
sl@0
   342
	testCopyL(out,in);
sl@0
   343
	out.CommitL();
sl@0
   344
	out.Close();
sl@0
   345
	in.Close();
sl@0
   346
	in.OpenL(*store,id);
sl@0
   347
	testReadL(in);
sl@0
   348
	in.Close();
sl@0
   349
//
sl@0
   350
	test.Next(_L("Copying using a single big transfer"));
sl@0
   351
	in.OpenL(*store,copyId);
sl@0
   352
	id=out.CreateL(*store);
sl@0
   353
	in.ReadL(out,KTestTotal);
sl@0
   354
	out.CommitL();
sl@0
   355
	out.Close();
sl@0
   356
	in.Close();
sl@0
   357
	in.OpenL(*store,id);
sl@0
   358
	testReadL(in);
sl@0
   359
	in.Close();
sl@0
   360
	in.OpenL(*store,copyId);
sl@0
   361
	id=out.CreateL(*store);
sl@0
   362
	out.WriteL(in,KTestTotal);
sl@0
   363
	out.CommitL();
sl@0
   364
	out.Close();
sl@0
   365
	in.Close();
sl@0
   366
	in.OpenL(*store,id);
sl@0
   367
	testReadL(in);
sl@0
   368
//
sl@0
   369
	CleanupStack::PopAndDestroy(3);
sl@0
   370
	}
sl@0
   371
sl@0
   372
//
sl@0
   373
// Test empty streams.
sl@0
   374
//
sl@0
   375
LOCAL_C void testEmptyL()
sl@0
   376
	{
sl@0
   377
	test.Next(_L("Empty tests on existing file"));
sl@0
   378
	TParsePtrC parse(KFileLocationSpec);
sl@0
   379
	CFileStore* store=CFileStore::OpenLC(TheFs,parse.NameAndExt(),EFileRead|EFileWrite);
sl@0
   380
	testEmptyL(*store);
sl@0
   381
//
sl@0
   382
	CleanupStack::PopAndDestroy();
sl@0
   383
	}
sl@0
   384
/**
sl@0
   385
@SYMTestCaseID          SYSLIB-STORE-CT-1157
sl@0
   386
@SYMTestCaseDesc	    Tests for detaching file from store
sl@0
   387
@SYMTestPriority 	    High
sl@0
   388
@SYMTestActions  	    Detach the file and discard the store
sl@0
   389
@SYMTestExpectedResults Test must not fail
sl@0
   390
@SYMREQ                 REQ0000
sl@0
   391
*/
sl@0
   392
LOCAL_C void testDetachL()
sl@0
   393
	{
sl@0
   394
	test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1157 Writing a file store "));
sl@0
   395
	TParsePtrC parse(KFileLocationSpec);
sl@0
   396
	
sl@0
   397
	CFileStore* store=CPermanentFileStore::ReplaceLC(TheFs,parse.NameAndExt(),EFileWrite|EFileRead);
sl@0
   398
	store->SetTypeL(KPermanentFileStoreLayoutUid);
sl@0
   399
	testWriteL(*store);
sl@0
   400
	store->CommitL();
sl@0
   401
//
sl@0
   402
	test.Next(_L("Detach the file and discard the store"));
sl@0
   403
	RFile file=store->File();
sl@0
   404
	store->Detach();
sl@0
   405
	store->Reattach(file);
sl@0
   406
	RFile& file2 = store->File();
sl@0
   407
	test(file2.SubSessionHandle() != KNullHandle);
sl@0
   408
	store->Detach();
sl@0
   409
	CleanupStack::PopAndDestroy();
sl@0
   410
//
sl@0
   411
	test.Next(_L("Re-construct the store and check the contents"));
sl@0
   412
	store=CFileStore::FromLC(file);
sl@0
   413
	testReadL(*store);
sl@0
   414
	store->Reset();
sl@0
   415
	CleanupStack::PopAndDestroy();
sl@0
   416
	}
sl@0
   417
/**
sl@0
   418
@SYMTestCaseID          SYSLIB-STORE-CT-1158
sl@0
   419
@SYMTestCaseDesc	    Tests for defect No 039456
sl@0
   420
                        Permanent File Store allows code to open and read from deleted streams
sl@0
   421
@SYMTestPriority 	    High
sl@0
   422
@SYMTestActions  	    Create four streams,delete last three and close the store.
sl@0
   423
                        Open the store and test for reading the first stream.
sl@0
   424
@SYMTestExpectedResults Test must not fail
sl@0
   425
@SYMREQ                 REQ0000
sl@0
   426
*/
sl@0
   427
LOCAL_C void testDef039456L()
sl@0
   428
{
sl@0
   429
	_LIT(KMsvDrivelessTestPath, ":\\t_storperm.dat");
sl@0
   430
	TFileName msvTestPath;
sl@0
   431
	msvTestPath.Append(RFs::GetSystemDriveChar());
sl@0
   432
	msvTestPath.Append(KMsvDrivelessTestPath);
sl@0
   433
	
sl@0
   434
	_LIT(KStringOne, "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111");
sl@0
   435
	_LIT(KStringTwo, "2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222");
sl@0
   436
sl@0
   437
	test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1158 "));
sl@0
   438
	TheFs.Delete(msvTestPath);
sl@0
   439
	CPermanentFileStore* testStore = CPermanentFileStore::CreateLC(TheFs, msvTestPath, EFileWrite|EFileShareAny);
sl@0
   440
	testStore->SetTypeL(KPermanentFileStoreLayoutUid);
sl@0
   441
sl@0
   442
	// create four streams,
sl@0
   443
	RStoreWriteStream wstream;
sl@0
   444
	TStreamId stream_one=wstream.CreateLC(*testStore);
sl@0
   445
	wstream << KStringOne;
sl@0
   446
	wstream.CommitL();
sl@0
   447
	CleanupStack::PopAndDestroy(&wstream);
sl@0
   448
	testStore->CommitL();
sl@0
   449
	TStreamId stream_two=wstream.CreateLC(*testStore);
sl@0
   450
	wstream << KStringTwo;
sl@0
   451
	wstream.CommitL();
sl@0
   452
	CleanupStack::PopAndDestroy(&wstream);
sl@0
   453
	testStore->CommitL();
sl@0
   454
	TStreamId stream_three=wstream.CreateLC(*testStore);
sl@0
   455
	wstream << KStringOne;
sl@0
   456
	wstream.CommitL();
sl@0
   457
	CleanupStack::PopAndDestroy(&wstream);
sl@0
   458
	testStore->CommitL();
sl@0
   459
	TStreamId stream_four=wstream.CreateLC(*testStore);
sl@0
   460
	wstream << KStringOne;
sl@0
   461
	wstream.CommitL();
sl@0
   462
	CleanupStack::PopAndDestroy(&wstream);
sl@0
   463
	testStore->CommitL();
sl@0
   464
sl@0
   465
	// delete last three streams added (not in the order added)
sl@0
   466
	testStore->DeleteL(stream_four);
sl@0
   467
	testStore->CommitL();
sl@0
   468
	testStore->DeleteL(stream_three);
sl@0
   469
	testStore->CommitL();
sl@0
   470
	testStore->DeleteL(stream_two);
sl@0
   471
	testStore->CommitL();
sl@0
   472
sl@0
   473
	// close the store
sl@0
   474
	CleanupStack::PopAndDestroy(testStore);
sl@0
   475
sl@0
   476
	// open store, try and read each of the streams, only stream_one should be present
sl@0
   477
	testStore = CPermanentFileStore::OpenLC(TheFs, msvTestPath, EFileWrite|EFileShareAny);
sl@0
   478
	RStoreReadStream rstream1, rstream2;
sl@0
   479
sl@0
   480
	// check stream_one ok
sl@0
   481
	TRAPD(error_stream_one,rstream1.OpenL(*testStore,stream_one));
sl@0
   482
	test(error_stream_one==KErrNone);
sl@0
   483
	rstream1.Close();
sl@0
   484
sl@0
   485
	// shouldn't be able to open this stream as we deleted it....
sl@0
   486
	TRAPD(error_stream_two,rstream2.OpenL(*testStore,stream_two));
sl@0
   487
	test(error_stream_two==KErrNotFound);
sl@0
   488
sl@0
   489
	CleanupStack::PopAndDestroy(testStore);
sl@0
   490
	
sl@0
   491
	(void)TheFs.Delete(msvTestPath);
sl@0
   492
	}
sl@0
   493
sl@0
   494
/**
sl@0
   495
@SYMTestCaseID          PDS-STORE-UT-4059
sl@0
   496
@SYMTestCaseDesc        Tests for defect No ou1cimx1#422232
sl@0
   497
                        The installed help topics are not organized to Application help topics.
sl@0
   498
@SYMTestPriority        High
sl@0
   499
@SYMTestActions         Tests that the EFileWriteDirectIO is appended only when necessary, also
sl@0
   500
                        test that any EFileWriteBuffered is unset (no error occurs when this is
sl@0
   501
                        passed in)
sl@0
   502
@SYMTestExpectedResults Test must not fail
sl@0
   503
@SYMDEF                 ou1cimx1#422232
sl@0
   504
*/
sl@0
   505
LOCAL_C void testOpenL()
sl@0
   506
    {    
sl@0
   507
    _LIT(KFileName,"C:\\t_storfperm.dat");
sl@0
   508
    
sl@0
   509
    test.Next(_L("@SYMTestCaseID:PDS-STORE-UT-4059: CPermanentFileStore::ReplaceL() test"));
sl@0
   510
    CPermanentFileStore* testStore = CPermanentFileStore::ReplaceL(TheFs, KFileName, EFileWrite|EFileWriteBuffered);
sl@0
   511
    delete testStore;
sl@0
   512
    
sl@0
   513
    (void)TheFs.Delete(KFileName);
sl@0
   514
    }
sl@0
   515
sl@0
   516
//
sl@0
   517
// Prepare the test directory.
sl@0
   518
//
sl@0
   519
LOCAL_C void setupTestDirectory()
sl@0
   520
    {
sl@0
   521
	TInt r=TheFs.Connect();
sl@0
   522
	test(r==KErrNone);
sl@0
   523
//
sl@0
   524
	TDriveUnit drive(static_cast<TUint>(RFs::GetSystemDrive()));	
sl@0
   525
	TParse parse;
sl@0
   526
	parse.Set(drive.Name(), &KFileLocationSpec, NULL);
sl@0
   527
	
sl@0
   528
	r=TheFs.MkDir(parse.DriveAndPath());
sl@0
   529
	test(r==KErrNone||r==KErrAlreadyExists);
sl@0
   530
	r=TheFs.SetSessionPath(parse.DriveAndPath());
sl@0
   531
	test(r==KErrNone);
sl@0
   532
	}
sl@0
   533
sl@0
   534
//
sl@0
   535
// Initialise the cleanup stack.
sl@0
   536
//
sl@0
   537
LOCAL_C void setupCleanup()
sl@0
   538
    {
sl@0
   539
	TheTrapCleanup=CTrapCleanup::New();
sl@0
   540
	test(TheTrapCleanup!=NULL);
sl@0
   541
	TRAPD(r,\
sl@0
   542
		{\
sl@0
   543
		for (TInt i=KTestCleanupStack;i>0;i--)\
sl@0
   544
			CleanupStack::PushL((TAny*)0);\
sl@0
   545
		CleanupStack::Pop(KTestCleanupStack);\
sl@0
   546
		});
sl@0
   547
	test(r==KErrNone);
sl@0
   548
	}
sl@0
   549
sl@0
   550
LOCAL_C void DeleteDataFile(const TDesC& aFullName)
sl@0
   551
	{
sl@0
   552
	RFs fsSession;
sl@0
   553
	TInt err = fsSession.Connect();
sl@0
   554
	if(err == KErrNone)
sl@0
   555
		{
sl@0
   556
		TEntry entry;
sl@0
   557
		if(fsSession.Entry(aFullName, entry) == KErrNone)
sl@0
   558
			{
sl@0
   559
			RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
sl@0
   560
			err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
sl@0
   561
			if(err != KErrNone)
sl@0
   562
				{
sl@0
   563
				RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
sl@0
   564
				}
sl@0
   565
			err = fsSession.Delete(aFullName);
sl@0
   566
			if(err != KErrNone)
sl@0
   567
				{
sl@0
   568
				RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
sl@0
   569
				}
sl@0
   570
			}
sl@0
   571
		fsSession.Close();
sl@0
   572
		}
sl@0
   573
	else
sl@0
   574
		{
sl@0
   575
		RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
sl@0
   576
		}
sl@0
   577
	}
sl@0
   578
sl@0
   579
//
sl@0
   580
// Test permanent file store.
sl@0
   581
//
sl@0
   582
GLDEF_C TInt E32Main()
sl@0
   583
    {
sl@0
   584
	test.Title();
sl@0
   585
	setupTestDirectory();
sl@0
   586
	setupCleanup();
sl@0
   587
	__UHEAP_MARK;
sl@0
   588
//
sl@0
   589
	test.Start(_L("Test permanent file store"));
sl@0
   590
	TRAPD(r,testWriteL());
sl@0
   591
	test(r==KErrNone);
sl@0
   592
	TRAP(r,testReadL());
sl@0
   593
	test(r==KErrNone);
sl@0
   594
	TRAP(r,testRecoveryL());
sl@0
   595
	test(r==KErrNone);
sl@0
   596
	TRAP(r,testCopyL());
sl@0
   597
	test(r==KErrNone);
sl@0
   598
	TRAP(r,testEmptyL());
sl@0
   599
	test(r==KErrNone);
sl@0
   600
	TRAP(r,testDetachL());
sl@0
   601
	test(r==KErrNone);
sl@0
   602
	TRAP(r,testDef039456L());
sl@0
   603
	test(r==KErrNone);
sl@0
   604
	TRAP(r,testOpenL());
sl@0
   605
	test(r==KErrNone);
sl@0
   606
	
sl@0
   607
	//deletion of data files must be before call to .End() - DEF047652
sl@0
   608
	TDriveUnit drive(static_cast<TUint>(RFs::GetSystemDrive()));	
sl@0
   609
	TParse parse;
sl@0
   610
	parse.Set(drive.Name(), &KFileLocationSpec, NULL);
sl@0
   611
	::DeleteDataFile(parse.FullName());
sl@0
   612
sl@0
   613
	test.End();
sl@0
   614
//
sl@0
   615
	__UHEAP_MARKEND;
sl@0
   616
sl@0
   617
	delete TheTrapCleanup;
sl@0
   618
	if (TheFs.Delete(TheTempFile)!=KErrNone)
sl@0
   619
		test.Panic(_L("Deleting temp file"));
sl@0
   620
	TheFs.Close();
sl@0
   621
	test.Close();
sl@0
   622
	return 0;
sl@0
   623
    }
sl@0
   624