81 { |
82 { |
82 |
83 |
83 TBuf<128> fileName=aBaseName; |
84 TBuf<128> fileName=aBaseName; |
84 fileName.AppendNum(aX); |
85 fileName.AppendNum(aX); |
85 TInt r=TheFs.Delete(fileName); |
86 TInt r=TheFs.Delete(fileName); |
86 test(r==KErrNone); |
87 test_KErrNone(r); |
87 // r=TheFs.CheckDisk(fileName); |
88 // r=TheFs.CheckDisk(fileName); |
88 // if (r!=KErrNone && r!=KErrNotSupported) |
89 // if (r!=KErrNone && r!=KErrNotSupported) |
89 // { |
90 // { |
90 // test.Printf(_L("ERROR:: CheckDisk returned %d\n"),r); |
91 // test.Printf(_L("ERROR:: CheckDisk returned %d\n"),r); |
91 // test(r==KErrNone); |
92 // test_KErrNone(r); |
92 // } |
93 // } |
93 test.Printf(_L("Deleted File %d\n"),aX); |
94 test.Printf(_L("Deleted File %d\n"),aX); |
94 return(KErrNone); |
95 return(KErrNone); |
95 } |
96 } |
96 |
97 |
101 { |
102 { |
102 TUint8* bufPtr=(TUint8*)testBuf.Ptr(); |
103 TUint8* bufPtr=(TUint8*)testBuf.Ptr(); |
103 testBuf.SetLength(testBuf.MaxSize()); |
104 testBuf.SetLength(testBuf.MaxSize()); |
104 Mem::Fill(bufPtr,testBuf.MaxSize(),aCluster); |
105 Mem::Fill(bufPtr,testBuf.MaxSize(),aCluster); |
105 TInt r=aFile.Write(testBuf); |
106 TInt r=aFile.Write(testBuf); |
106 test(r==KErrNone); |
107 test_KErrNone(r); |
107 } |
108 } |
108 |
109 |
109 LOCAL_C void SeekToCluster(RFile& aFile,TInt aCluster) |
110 LOCAL_C void SeekToCluster(RFile& aFile,TInt aCluster) |
110 // |
111 // |
111 // Seek to aCluster and check it is found correctly |
112 // Seek to aCluster and check it is found correctly |
112 // |
113 // |
113 { |
114 { |
114 TBuf8<508> seekBuf(508); |
115 TBuf8<508> seekBuf(508); |
115 TInt r=aFile.Read(aCluster*testBuf.MaxSize(),seekBuf); |
116 TInt r=aFile.Read(aCluster*testBuf.MaxSize(),seekBuf); |
116 test(r==KErrNone); |
117 test_KErrNone(r); |
117 test(seekBuf[0]==(TUint8)aCluster && seekBuf[507]==(TUint8)aCluster); |
118 test(seekBuf[0]==(TUint8)aCluster && seekBuf[507]==(TUint8)aCluster); |
118 } |
119 } |
119 |
120 |
120 LOCAL_C void SeekToCluster(RFile& aFile,TInt aCluster1,TInt aCluster2) |
121 LOCAL_C void SeekToCluster(RFile& aFile,TInt aCluster1,TInt aCluster2) |
121 // |
122 // |
122 // Seek to aCluster and check it is found correctly |
123 // Seek to aCluster and check it is found correctly |
123 // |
124 // |
124 { |
125 { |
125 TBuf8<508> seekBuf(508); |
126 TBuf8<508> seekBuf(508); |
126 TInt r=aFile.Read(aCluster1*testBuf.MaxSize(),seekBuf); |
127 TInt r=aFile.Read(aCluster1*testBuf.MaxSize(),seekBuf); |
127 test(r==KErrNone); |
128 test_KErrNone(r); |
128 test(seekBuf[0]==(TUint8)aCluster1 && seekBuf[507]==(TUint8)aCluster1); |
129 test(seekBuf[0]==(TUint8)aCluster1 && seekBuf[507]==(TUint8)aCluster1); |
129 r=aFile.Read(aCluster2*testBuf.MaxSize(),seekBuf); |
130 r=aFile.Read(aCluster2*testBuf.MaxSize(),seekBuf); |
130 test(r==KErrNone); |
131 test_KErrNone(r); |
131 test(seekBuf[0]==(TUint8)aCluster2 && seekBuf[507]==(TUint8)aCluster2); |
132 test(seekBuf[0]==(TUint8)aCluster2 && seekBuf[507]==(TUint8)aCluster2); |
132 } |
133 } |
133 |
134 |
134 LOCAL_C void ExhaustiveTest(RFile& aFile,TInt aCount1) |
135 LOCAL_C void ExhaustiveTest(RFile& aFile,TInt aCount1) |
135 // |
136 // |
156 { |
157 { |
157 test.Next(_L("Create interleaved files")); |
158 test.Next(_L("Create interleaved files")); |
158 RFile f1,f2; |
159 RFile f1,f2; |
159 |
160 |
160 TInt r=f1.Replace(TheFs,_L("BIGFILE1.TST"),EFileWrite); |
161 TInt r=f1.Replace(TheFs,_L("BIGFILE1.TST"),EFileWrite); |
161 test(r==KErrNone); |
162 test_KErrNone(r); |
162 r=f2.Replace(TheFs,_L("BIGFILE2.TST"),EFileWrite); |
163 r=f2.Replace(TheFs,_L("BIGFILE2.TST"),EFileWrite); |
163 test(r==KErrNone); |
164 test_KErrNone(r); |
164 |
165 |
165 TInt maxListLength=4; |
166 TInt maxListLength=4; |
166 TInt i=0,k=0; |
167 TInt i=0,k=0; |
167 TInt countf1=0; |
168 TInt countf1=0; |
168 TInt countf2=0; |
169 TInt countf2=0; |
218 { |
219 { |
219 test.Next(_L("Regression Protection")); |
220 test.Next(_L("Regression Protection")); |
220 RFile f1,f2; |
221 RFile f1,f2; |
221 |
222 |
222 TInt r=f1.Replace(TheFs,_L("BIGFILE1.TST"),EFileWrite); |
223 TInt r=f1.Replace(TheFs,_L("BIGFILE1.TST"),EFileWrite); |
223 test(r==KErrNone); |
224 test_KErrNone(r); |
224 r=f2.Replace(TheFs,_L("BIGFILE2.TST"),EFileWrite); |
225 r=f2.Replace(TheFs,_L("BIGFILE2.TST"),EFileWrite); |
225 test(r==KErrNone); |
226 test_KErrNone(r); |
226 |
227 |
227 WriteCluster(f1,0); |
228 WriteCluster(f1,0); |
228 WriteCluster(f1,1); |
229 WriteCluster(f1,1); |
229 WriteCluster(f1,2); |
230 WriteCluster(f1,2); |
230 WriteCluster(f1,3); |
231 WriteCluster(f1,3); |
271 SeekToCluster(f1,cluster2,cluster1); |
272 SeekToCluster(f1,cluster2,cluster1); |
272 } |
273 } |
273 |
274 |
274 test.Next(_L("Increase Size")); |
275 test.Next(_L("Increase Size")); |
275 r=f1.SetSize(1048577); |
276 r=f1.SetSize(1048577); |
276 test(r==KErrNone || r==KErrDiskFull); |
277 test_Value(r, r == KErrNone || r==KErrDiskFull); |
277 if (r==KErrDiskFull) |
278 if (r==KErrDiskFull) |
278 { |
279 { |
279 test.Printf(_L("File too big\n")); |
280 test.Printf(_L("File too big\n")); |
280 f1.Close(); |
281 f1.Close(); |
281 return; |
282 return; |
305 SeekToCluster(f1,cluster2,cluster1); |
306 SeekToCluster(f1,cluster2,cluster1); |
306 } |
307 } |
307 |
308 |
308 test.Next(_L("Reduce file size")); |
309 test.Next(_L("Reduce file size")); |
309 r=f1.SetSize(135000); |
310 r=f1.SetSize(135000); |
310 test(r==KErrNone); |
311 test_KErrNone(r); |
311 |
312 |
312 test.Next(_L("Test data still present")); |
313 test.Next(_L("Test data still present")); |
313 for (j=0;j<200;j++) |
314 for (j=0;j<200;j++) |
314 { |
315 { |
315 TInt cluster1=Math::Rand(TheSeed)%31; |
316 TInt cluster1=Math::Rand(TheSeed)%31; |
338 // |
339 // |
339 : iFile(*aFile), iPos(0) |
340 : iFile(*aFile), iPos(0) |
340 { |
341 { |
341 |
342 |
342 TInt r=iFile.Read(0,iData); |
343 TInt r=iFile.Read(0,iData); |
343 test(r==KErrNone); |
344 test_KErrNone(r); |
344 } |
345 } |
345 |
346 |
346 void TFileReader::Next(TUint8& aVal,TInt& aLength) |
347 void TFileReader::Next(TUint8& aVal,TInt& aLength) |
347 // |
348 // |
348 // Read aLength contiguous bytes with aVal |
349 // Read aLength contiguous bytes with aVal |
474 |
475 |
475 RFile f[KMaxFiles]; |
476 RFile f[KMaxFiles]; |
476 HBufC8* dataBuf=HBufC8::NewL(KMaxBufferLength); |
477 HBufC8* dataBuf=HBufC8::NewL(KMaxBufferLength); |
477 |
478 |
478 TInt r=f[0].Replace(TheFs,_L("TEST1.DAT"),EFileWrite); |
479 TInt r=f[0].Replace(TheFs,_L("TEST1.DAT"),EFileWrite); |
479 test(r==KErrNone); |
480 test_KErrNone(r); |
480 r=f[1].Replace(TheFs,_L("TEST2.DAT"),EFileWrite); |
481 r=f[1].Replace(TheFs,_L("TEST2.DAT"),EFileWrite); |
481 test(r==KErrNone); |
482 test_KErrNone(r); |
482 r=f[2].Replace(TheFs,_L("TEST3.DAT"),EFileWrite); |
483 r=f[2].Replace(TheFs,_L("TEST3.DAT"),EFileWrite); |
483 test(r==KErrNone); |
484 test_KErrNone(r); |
484 r=f[3].Replace(TheFs,_L("TEST4.DAT"),EFileWrite); |
485 r=f[3].Replace(TheFs,_L("TEST4.DAT"),EFileWrite); |
485 test(r==KErrNone); |
486 test_KErrNone(r); |
486 |
487 |
487 TInt size=0; |
488 TInt size=0; |
488 TInt iteration=0; |
489 TInt iteration=0; |
489 |
490 |
490 FOREVER |
491 FOREVER |
505 { |
506 { |
506 TInt fileNum=(order+i)%KMaxFiles; |
507 TInt fileNum=(order+i)%KMaxFiles; |
507 TInt s=len*mult[fileNum]; |
508 TInt s=len*mult[fileNum]; |
508 TInt filePos=pos*mult[fileNum]; |
509 TInt filePos=pos*mult[fileNum]; |
509 r=f[fileNum].Seek(ESeekStart,filePos); |
510 r=f[fileNum].Seek(ESeekStart,filePos); |
510 test(r==KErrNone); |
511 test_KErrNone(r); |
511 |
512 |
512 while(s>0) |
513 while(s>0) |
513 { |
514 { |
514 TInt l=(s>KMaxBufferLength) ? KMaxBufferLength : s; |
515 TInt l=(s>KMaxBufferLength) ? KMaxBufferLength : s; |
515 dataBuf->Des().SetLength(l); |
516 dataBuf->Des().SetLength(l); |
516 r=f[fileNum].Write(*dataBuf); |
517 r=f[fileNum].Write(*dataBuf); |
517 if (r==KErrDiskFull) |
518 if (r==KErrDiskFull) |
518 goto End; |
519 goto End; |
519 test(r==KErrNone); |
520 test_KErrNone(r); |
520 s-=l; |
521 s-=l; |
521 } |
522 } |
522 |
523 |
523 } |
524 } |
524 |
525 |
535 test.Printf(_L("\nReduceSize newsize=%d\n"),size); |
536 test.Printf(_L("\nReduceSize newsize=%d\n"),size); |
536 for (TInt i=0;i<KMaxFiles;i++) |
537 for (TInt i=0;i<KMaxFiles;i++) |
537 { |
538 { |
538 TInt fileNum=(order+i)%KMaxFiles; |
539 TInt fileNum=(order+i)%KMaxFiles; |
539 r=f[fileNum].SetSize(size*mult[fileNum]); |
540 r=f[fileNum].SetSize(size*mult[fileNum]); |
540 test(r==KErrNone); |
541 test_KErrNone(r); |
541 } |
542 } |
542 CheckFileContents(&f[0]); |
543 CheckFileContents(&f[0]); |
543 } |
544 } |
544 } |
545 } |
545 End: |
546 End: |
554 // Test filling the disk with files, and various manipulations thereof |
555 // Test filling the disk with files, and various manipulations thereof |
555 // |
556 // |
556 { |
557 { |
557 test.Start(_L("Test multiple file creation, deletion and resize operations")); |
558 test.Start(_L("Test multiple file creation, deletion and resize operations")); |
558 TInt r=TheFs.MkDirAll(_L("\\F32-TST\\BIGDIRECTORY\\")); |
559 TInt r=TheFs.MkDirAll(_L("\\F32-TST\\BIGDIRECTORY\\")); |
559 test(r==KErrNone || r==KErrAlreadyExists); |
560 test_Value(r, r == KErrNone || r==KErrAlreadyExists); |
560 TFileName sessionPath; |
561 TFileName sessionPath; |
561 r=TheFs.SessionPath(sessionPath); |
562 r=TheFs.SessionPath(sessionPath); |
562 test(r==KErrNone); |
563 test_KErrNone(r); |
563 |
564 |
564 TInt index=0; |
565 TInt index=0; |
565 TBuf<128> fileName=_L("\\F32-TST\\BIGDIRECTORY\\FILE"); |
566 TBuf<128> fileName=_L("\\F32-TST\\BIGDIRECTORY\\FILE"); |
566 |
567 |
567 for (;index<numberOfFiles;index++) |
568 for (;index<numberOfFiles;index++) |
568 { |
569 { |
569 r=CreateFileEx(fileName,index,anInitialSize); |
570 r=CreateFileEx(fileName,index,anInitialSize); |
570 if (r!=KErrNone) |
571 if (r!=KErrNone) |
571 break; |
572 break; |
572 |
573 |
573 test(r==KErrNone); |
574 test_KErrNone(r); |
574 |
575 |
575 #if defined(__WINS__) |
576 #if defined(__WINS__) |
576 if (index==32 && sessionPath[0]=='C') |
577 if (index==32 && sessionPath[0]=='C') |
577 break; |
578 break; |
578 #endif |
579 #endif |
599 for (index=0; index<halfCount; index++) |
600 for (index=0; index<halfCount; index++) |
600 { |
601 { |
601 baseName=fileName; |
602 baseName=fileName; |
602 baseName.AppendNum(index); |
603 baseName.AppendNum(index); |
603 r=file.Open(TheFs,baseName,EFileRead|EFileWrite); |
604 r=file.Open(TheFs,baseName,EFileRead|EFileWrite); |
604 test(r==KErrNone); |
605 test_KErrNone(r); |
605 test.Printf(_L("Resized %S from %d to %d\n"),&baseName,anInitialSize,anInitialSize*2); |
606 test.Printf(_L("Resized %S from %d to %d\n"),&baseName,anInitialSize,anInitialSize*2); |
606 r=file.SetSize(2*anInitialSize); |
607 r=file.SetSize(2*anInitialSize); |
607 test((r==KErrNone)||(r==KErrDiskFull)); |
608 test((r==KErrNone)||(r==KErrDiskFull)); |
608 file.Close(); |
609 file.Close(); |
609 } |
610 } |