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