First public contribution.
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 the License "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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // f32test\server\t_rdsect.cpp
18 #define __E32TEST_EXTENSION__
27 #define WIN32_LEAN_AND_MEAN
28 #pragma warning (disable:4201) // warning C4201: nonstandard extension used : nameless struct/union
29 #pragma warning (default:4201) // warning C4201: nonstandard extension used : nameless struct/union
38 GLDEF_D RTest test(_L("T_RDSECT"));
41 TBuf<26> alphaBuffer=_L("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
42 TBuf<10> numberBuffer=_L("0123456789");
43 TBuf<14> humptyBuffer=_L("Humpty-Dumpty!");
44 TPtr8 alphaPtr((TText8*)alphaBuffer.Ptr(),alphaBuffer.Size(),alphaBuffer.Size());
45 TPtr8 numberPtr((TText8*)numberBuffer.Ptr(),numberBuffer.Size(),numberBuffer.Size());
46 TPtr8 humptyPtr((TText8*)humptyBuffer.Ptr(),humptyBuffer.Size(),humptyBuffer.Size());
51 What this test is for:
53 Tests the implementation of RFs::ReadFileSection() which has been designed
54 to allow reading from a file regardless of its lock state.
55 Under the EPOC FAT filesystem, the function accesses the raw file data without
56 opening the file using a share mode. This is obviously a dangerous activity
57 should the file be currently open for writing by another user - but the file
58 server makes no guarantees as to the data it returns! The function allows the
59 caller to specify the starting position in the file from which to read the data
60 and the length of data required.
62 This test creates a number of files and tests the use of the function when the
63 files are closed and when they are open in a number of access modes.
64 It also tests reading a UID from the files using this new function.
68 LOCAL_C void CreateTestFiles()
70 // Create files with uids for testing
74 test.Next(_L("Create test files"));
75 TInt r=TheFs.MkDir(_L("\\F32-TST\\"));
76 test(r==KErrNone || r==KErrAlreadyExists);
80 // Create \\gSessionPath\\UIDCHK.BLG - with uid no data
81 r=file.Replace(TheFs,_L("\\F32-TST\\UIDCHK.BLG"),EFileRead|EFileWrite);
83 TUidType uidType(TUid::Uid('U'),TUid::Uid('I'),TUid::Uid('D'));
84 TCheckedUid checkedUid(uidType);
85 TPtrC8 buf((TUint8*)&checkedUid,sizeof(TCheckedUid));
90 // Create \\gSessionPath\\UIDCHK.MSG - with uid and data
91 r=file.Replace(TheFs,_L("\\F32-TST\\UIDCHK.MSG"),EFileRead|EFileWrite);
93 TUidType uidType2(TUid::Uid('X'),TUid::Uid('Y'),TUid::Uid('Z'));
94 checkedUid.Set(uidType2);
95 buf.Set((TUint8*)&checkedUid,sizeof(TCheckedUid));
98 r=file.Write(_L8("More file data"));
102 // Create \\gSessionPath\\UIDCHK.DAT - uid stored only in the file
103 r=file.Replace(TheFs,_L("\\F32-TST\\UIDCHK.DAT"),EFileRead|EFileWrite);
105 TUidType uidType3(TUid::Uid('D'),TUid::Uid('A'),TUid::Uid('T'));
106 checkedUid.Set(uidType3);
107 buf.Set((TUint8*)&checkedUid,sizeof(TCheckedUid));
110 r=file.Write(_L8("More file data"));
114 // Make a few random files - these will be deleted before the test begins
115 // but are necessary to try to split file ReadFileSection into non-contiguous clusters
117 r=file.Replace(TheFs,_L("\\F32-TST\\Temp1.txt"),EFileRead|EFileWrite);
122 r=file.Replace(TheFs,_L("\\F32-TST\\Temp2.txt"),EFileRead|EFileWrite);
127 r=file.Replace(TheFs,_L("\\F32-TST\\Temp3.txt"),EFileRead|EFileWrite);
132 r=file.Replace(TheFs,_L("\\F32-TST\\Temp4.txt"),EFileRead|EFileWrite);
137 r=file.Replace(TheFs,_L("\\F32-TST\\Temp5.txt"),EFileRead|EFileWrite);
142 r=file.Replace(TheFs,_L("\\F32-TST\\Temp6.txt"),EFileRead|EFileWrite);
147 r=file.Replace(TheFs,_L("\\F32-TST\\Temp7.txt"),EFileRead|EFileWrite);
152 r=file.Replace(TheFs,_L("\\F32-TST\\Temp8.txt"),EFileRead|EFileWrite);
157 r=file.Replace(TheFs,_L("\\F32-TST\\Temp9.txt"),EFileRead|EFileWrite);
162 r=file.Replace(TheFs,_L("\\F32-TST\\Temp10.txt"),EFileRead|EFileWrite);
167 TheFs.Delete(_L("\\F32-TST\\Temp2.txt"));
168 TheFs.Delete(_L("\\F32-TST\\Temp4.txt"));
169 TheFs.Delete(_L("\\F32-TST\\Temp6.txt"));
170 TheFs.Delete(_L("\\F32-TST\\Temp8.txt"));
171 TheFs.Delete(_L("\\F32-TST\\Temp10.txt"));
173 r=file.Replace(TheFs,_L("\\F32-TST\\ReadFileSection1.txt"),EFileRead|EFileWrite);
176 // Write 5000 bytes of nonsense
181 r=file.Write(alphaPtr);
183 r=file.Write(numberPtr);
185 r=file.Write(humptyPtr);
191 TheFs.Delete(_L("\\F32-TST\\Temp1.txt"));
192 TheFs.Delete(_L("\\F32-TST\\Temp3.txt"));
193 TheFs.Delete(_L("\\F32-TST\\Temp5.txt"));
194 TheFs.Delete(_L("\\F32-TST\\Temp7.txt"));
195 TheFs.Delete(_L("\\F32-TST\\Temp9.txt"));
198 #if !defined(_UNICODE)
202 // Test RFs::ReadFileSection()
206 test.Next(_L("Use RFs::ReadFileSection() to read from a file"));
208 // First, test for non-existant file
210 TInt r=TheFs.ReadFileSection(_L("\\F32-tst\\NonExistantFile.txt"),0,testDes,52);
211 test(r==KErrNotFound);
212 test(testDes.Length()==0);
214 // Test with file closed
215 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),0,testDes,26);
217 test(testDes.Length()==26);
218 test(testDes==_L("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
220 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),26,testDes,10);
222 test(testDes==_L("0123456789"));
223 test(testDes.Length()==10);
225 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),36,testDes,14);
227 test(testDes==_L("Humpty-Dumpty!"));
228 test(testDes.Length()==14);
230 // Test with file open EFileShareAny|EFileRead
232 r=file.Open(TheFs,_L("\\F32-tst\\ReadFileSection1.txt"),EFileShareAny|EFileRead);
235 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),50,testDes,26);
237 test(testDes==_L("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
238 test(testDes.Length()==26);
240 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),76,testDes,10);
242 test(testDes==_L("0123456789"));
243 test(testDes.Length()==10);
245 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),86,testDes,14);
247 test(testDes==_L("Humpty-Dumpty!"));
248 test(testDes.Length()==14);
252 // Test with file open EFileShareExclusive|EFileRead
253 r=file.Open(TheFs,_L("\\F32-tst\\ReadFileSection1.txt"),EFileShareExclusive|EFileRead);
256 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),100,testDes,26);
258 test(testDes==_L("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
259 test(testDes.Length()==26);
261 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),126,testDes,10);
263 test(testDes==_L("0123456789"));
264 test(testDes.Length()==10);
266 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),136,testDes,14);
268 test(testDes==_L("Humpty-Dumpty!"));
269 test(testDes.Length()==14);
273 // Test with file open EFileShareExclusive|EFileWrite
274 r=file.Open(TheFs,_L("\\F32-tst\\ReadFileSection1.txt"),EFileShareExclusive|EFileWrite);
277 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),150,testDes,26);
279 test(testDes==_L("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
280 test(testDes.Length()==26);
282 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),176,testDes,10);
284 test(testDes==_L("0123456789"));
285 test(testDes.Length()==10);
287 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),186,testDes,14);
289 test(testDes==_L("Humpty-Dumpty!"));
290 test(testDes.Length()==14);
295 // Test with file open EFileShareReadersOnly|EFileRead
296 r=file.Open(TheFs,_L("\\F32-tst\\ReadFileSection1.txt"),EFileShareReadersOnly|EFileRead);
299 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),200,testDes,26);
301 test(testDes==_L("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
302 test(testDes.Length()==26);
304 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),226,testDes,10);
306 test(testDes==_L("0123456789"));
307 test(testDes.Length()==10);
309 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),236,testDes,14);
311 test(testDes==_L("Humpty-Dumpty!"));
312 test(testDes.Length()==14);
316 // Test with several accesses to a file EFileShareAny|EFileWrite
317 r=file.Open(TheFs,_L("\\F32-tst\\ReadFileSection1.txt"),EFileShareAny|EFileWrite);
321 r=secondFile.Open(TheFs,_L("\\F32-tst\\ReadFileSection1.txt"),EFileShareAny|EFileWrite);
325 r=thirdFile.Open(TheFs,_L("\\F32-tst\\ReadFileSection1.txt"),EFileShareAny|EFileWrite);
328 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),250,testDes,26);
330 test(testDes==_L("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
331 test(testDes.Length()==26);
333 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),276,testDes,10);
335 test(testDes==_L("0123456789"));
336 test(testDes.Length()==10);
338 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),286,testDes,14);
340 test(testDes==_L("Humpty-Dumpty!"));
341 test(testDes.Length()==14);
343 // Test across potential cluster boundaries
345 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),500,testDes,100);
347 test(testDes.Length()==100);
348 test(testDes==_L("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789Humpty-Dumpty!ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789Humpty-Dumpty!"));
350 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),1000,testDes,100);
352 test(testDes.Length()==100);
353 test(testDes==_L("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789Humpty-Dumpty!ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789Humpty-Dumpty!"));
355 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),1500,testDes,100);
357 test(testDes.Length()==100);
358 test(testDes==_L("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789Humpty-Dumpty!ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789Humpty-Dumpty!"));
360 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),2000,testDes,100);
362 test(testDes.Length()==100);
363 test(testDes==_L("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789Humpty-Dumpty!ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789Humpty-Dumpty!"));
373 // Test RFs::ReadFileSection() on UID reads
378 test.Next(_L("Use RFs::ReadFileSection() to read UIDs from files"));
380 TBuf8<sizeof(TCheckedUid)> uidBuf(sizeof(TCheckedUid));
381 TPtr uidPtr((TText*)uidBuf.Ptr(),sizeof(TCheckedUid),sizeof(TCheckedUid));
383 TInt r=TheFs.ReadFileSection(_L("\\F32-TST\\UIDCHK.BLG"),0,uidPtr,sizeof(TCheckedUid));
385 TCheckedUid uid(uidBuf);
386 TUidType uidType=uid.UidType();
387 test(uidType.IsValid());
389 test(uidType[0]==TUid::Uid('U') && uidType[1]==TUid::Uid('I') && uidType[2]==TUid::Uid('D'));
391 r=TheFs.ReadFileSection(_L("\\F32-TST\\UIDCHK.MSG"),0,uidBuf,sizeof(TCheckedUid));
394 uidType=uid.UidType();
395 test(uidType.IsValid());
396 test(uidType[0]==TUid::Uid('X') && uidType[1]==TUid::Uid('Y') && uidType[2]==TUid::Uid('Z'));
399 // Test for Null File length
401 test.Next(_L("Check for null file name"));
402 r=TheFs.ReadFileSection(_L(""),0,testDesN,26);
403 test(r==KErrBadName);
405 // Check the lentgh of descriptor.
406 TInt x = testDesN.Length();
409 test.Next(_L("Check for non existing file"));
410 r=TheFs.ReadFileSection(_L("sdfsd.dfg"),0,testDesN,26);
411 test.Printf(_L("Return %d"),r);
412 test((r==KErrNotFound) || (r == KErrPathNotFound));
414 // Check the lentgh of descriptor.
415 x = testDesN.Length();
418 r=TheFs.ReadFileSection(_L("\\F32-TST\\UIDCHK.DAT"),0,uidBuf,sizeof(TCheckedUid));
421 uidType=uid.UidType();
422 test(uidType.IsValid());
423 test(uidType[0]==TUid::Uid('D') && uidType[1]==TUid::Uid('A') && uidType[2]==TUid::Uid('T'));
430 // Test uid's can be read when the file is open
432 // EFileShareExclusive,EFileShareReadersOnly,EFileShareAny,
433 // EFileStream=0,EFileStreamText=0x100,
434 // EFileRead=0,EFileWrite=0x200
438 test.Next(_L("Test that UIDs can be read from open files"));
441 // Test with file open EFileShareExclusive|EFileRead
442 TInt r=file.Open(TheFs,_L("\\F32-TST\\UIDCHK.DAT"),EFileShareExclusive|EFileRead);
445 TBuf8<sizeof(TCheckedUid)> uidBuf;
447 r=TheFs.ReadFileSection(_L("\\F32-TST\\UIDCHK.DAT"),0,uidBuf,sizeof(TCheckedUid));
450 TCheckedUid uid(uidBuf);
451 TUidType uidType=uid.UidType();
452 test(uidType.IsValid());
453 test(uidType[0]==TUid::Uid('D') && uidType[1]==TUid::Uid('A') && uidType[2]==TUid::Uid('T'));
457 // Test with file open EFileShareExclusive|EFileWrite
458 r=file.Open(TheFs,_L("\\F32-TST\\UIDCHK.DAT"),EFileShareExclusive|EFileWrite);
461 r=TheFs.ReadFileSection(_L("\\F32-TST\\UIDCHK.DAT"),0,uidBuf,sizeof(TCheckedUid));
464 uidType=uid.UidType();
465 test(uidType.IsValid());
466 test(uidType[0]==TUid::Uid('D') && uidType[1]==TUid::Uid('A') && uidType[2]==TUid::Uid('T'));
470 // Test with file open EFileShareReadersOnly|EFileRead
471 r=file.Open(TheFs,_L("\\F32-TST\\UIDCHK.DAT"),EFileShareReadersOnly|EFileRead);
474 r=TheFs.ReadFileSection(_L("\\F32-TST\\UIDCHK.DAT"),0,uidBuf,sizeof(TCheckedUid));
477 uidType=uid.UidType();
478 test(uidType.IsValid());
479 test(uidType[0]==TUid::Uid('D') && uidType[1]==TUid::Uid('A') && uidType[2]==TUid::Uid('T'));
484 // Test with file open EFileShareAny|EFileRead
485 r=file.Open(TheFs,_L("\\F32-TST\\UIDCHK.DAT"),EFileShareAny|EFileRead);
488 r=TheFs.ReadFileSection(_L("\\F32-TST\\UIDCHK.DAT"),0,uidBuf,sizeof(TCheckedUid));
491 uidType=uid.UidType();
492 test(uidType.IsValid());
493 test(uidType[0]==TUid::Uid('D') && uidType[1]==TUid::Uid('A') && uidType[2]==TUid::Uid('T'));
497 // Test with several accesses to file open EFileShareAny|EFileWrite
498 r=file.Open(TheFs,_L("\\F32-TST\\UIDCHK.DAT"),EFileShareAny|EFileWrite);
502 r=secondFile.Open(TheFs,_L("\\F32-TST\\UIDCHK.DAT"),EFileShareAny|EFileWrite);
506 r=thirdFile.Open(TheFs,_L("\\F32-TST\\UIDCHK.DAT"),EFileShareAny|EFileRead);
509 r=TheFs.ReadFileSection(_L("\\F32-TST\\UIDCHK.DAT"),0,uidBuf,sizeof(TCheckedUid));
512 uidType=uid.UidType();
513 test(uidType.IsValid());
514 test(uidType[0]==TUid::Uid('D') && uidType[1]==TUid::Uid('A') && uidType[2]==TUid::Uid('T'));
523 LOCAL_C void TestErrors()
525 // Test errors and boundary conditions
529 test.Next(_L("Test Error handling"));
531 // Test that specifying a zero length section returns a zero length descriptor
533 TInt r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),25,testDes,0);
535 test(testDes.Length()==0);
537 // Test that specifying a negative starting position causes a panic
538 // r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),-1,testDes,10);
539 // This will panic: See RFs::ReadFileSection() code - relevant lines are
540 // __ASSERT_ALWAYS(aPos>=0,Panic(EPosNegative));
542 // Test that specifying a section of greater length than the descriptor to
543 // hold the data will cause a panic
544 // r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),0,testDes,45);
545 // This will panic: See RFs::ReadFileSection() code - relevant lines are
546 // __ASSERT_ALWAYS(aDes.MaxLength()>=aLength,Panic(EBadLength));
548 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),2000,testDes,-20);
549 test(r==KErrArgument);
551 // Test that specifying a position and length which extends beyond the end of
552 // the file returns a zero length descriptor and KErrNone
554 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),4993,testDes,20);
556 test(testDes.Length()==7);
557 test(testDes==_L("Dumpty!"));
559 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),4999,testDes,1);
561 test(testDes.Length()==1);
562 test(testDes==_L("!"));
564 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),5000,testDes,1);
566 test(testDes.Length()==0);
568 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),5550,testDes,20);
570 test(testDes.Length()==0);
572 // Test reading the whole file
573 HBufC* hDes=HBufC::New(5002);
575 User::Leave(KErrNoMemory);
576 TPtr pDes=hDes->Des();
578 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),0,pDes,5000);
580 test(pDes.Length()==5000);
582 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),0,pDes,5000);
584 test(pDes.Length()==5000);
586 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),0,pDes,5002);
588 test(pDes.Length()==5000);
590 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),2000,pDes,3000);
592 test(pDes.Length()==3000);
594 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),2000,pDes,4002);
596 test(pDes.Length()==3000);
598 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),5000,pDes,5002);
600 test(pDes.Length()==0);
608 // BEGINNING OF UNICODE TESTS
610 LOCAL_C void TestUnicode()
612 // Test RFs::ReadFileSection()
615 test.Next(_L("Use RFs::ReadFileSection() to read from a file"));
617 // First, test for non-existant file
619 TInt r=TheFs.ReadFileSection(_L("\\F32-tst\\NonExistantFile.txt"),0,testDes,52);
620 test(r==KErrNotFound);
621 test(testDes.Length()==0);
623 // Test with file closed
624 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),0,testDes,52);
626 test(testDes.Length()==52);
627 test(testDes==alphaPtr);
629 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),52,testDes,20);
631 test(testDes==numberPtr);
632 test(testDes.Length()==20);
634 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),72,testDes,28);
636 test(testDes==humptyPtr);
637 test(testDes.Length()==28);
639 // Test for Null File length
641 test.Next(_L("Check for null file name"));
642 r=TheFs.ReadFileSection(_L(""),0,testDesN,26);
643 test(r==KErrBadName);
645 // Check the lentgh of descriptor.
646 TInt x = testDesN.Length();
649 test.Next(_L("Check for non existing file"));
650 r=TheFs.ReadFileSection(_L("sdfsd.dfg"),0,testDesN,26);
651 test.Printf(_L("Return %d"),r);
652 test((r==KErrNotFound) || (r == KErrPathNotFound));
654 // Check the lentgh of descriptor.
655 x = testDesN.Length();
658 // Test for Empty directory
659 r=TheFs.ReadFileSection(_L("\\F32-tst\\"),0,testDesN,52);
660 test(r==KErrBadName);
661 test(testDesN.Length()==0);
663 // Test for File with wildcard name
664 r=TheFs.ReadFileSection(_L("\\F32-tst\\*.txt"),0,testDesN,52);
665 test(r==KErrBadName);
666 test(testDesN.Length()==0);
668 // Test for Folder with wildcard name
669 r=TheFs.ReadFileSection(_L("\\F32-tst*\\ReadFileSection1.txt"),0,testDesN,52);
670 test(r==KErrBadName);
671 test(testDesN.Length()==0);
673 // Test for Root directory
674 r=TheFs.ReadFileSection(_L("\\"),0,testDesN,52);
675 test(r==KErrBadName);
676 test(testDesN.Length()==0);
678 // Test for no file being specified.
679 r=TheFs.ReadFileSection(_L(""),0,testDesN,26);
680 test(r==KErrBadName);
681 test(testDesN.Length()==0);
684 // Test with file open EFileShareAny|EFileRead
686 r=file.Open(TheFs,_L("\\F32-tst\\ReadFileSection1.txt"),EFileShareAny|EFileRead);
689 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),100,testDes,52);
691 test(testDes==alphaPtr);
692 test(testDes.Length()==52);
694 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),152,testDes,20);
696 test(testDes==numberPtr);
697 test(testDes.Length()==20);
699 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),172,testDes,28);
701 test(testDes==humptyPtr);
702 test(testDes.Length()==28);
706 // Test with file open EFileShareExclusive|EFileRead
707 r=file.Open(TheFs,_L("\\F32-tst\\ReadFileSection1.txt"),EFileShareExclusive|EFileRead);
710 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),200,testDes,52);
712 test(testDes==alphaPtr);
713 test(testDes.Length()==52);
715 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),252,testDes,20);
717 test(testDes==numberPtr);
718 test(testDes.Length()==20);
720 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),272,testDes,28);
722 test(testDes==humptyPtr);
723 test(testDes.Length()==28);
727 // Test with file open EFileShareExclusive|EFileWrite
728 r=file.Open(TheFs,_L("\\F32-tst\\ReadFileSection1.txt"),EFileShareExclusive|EFileWrite);
731 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),300,testDes,52);
733 test(testDes==alphaPtr);
734 test(testDes.Length()==52);
736 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),352,testDes,20);
738 test(testDes==numberPtr);
739 test(testDes.Length()==20);
741 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),372,testDes,28);
743 test(testDes==humptyPtr);
744 test(testDes.Length()==28);
749 // Test with file open EFileShareReadersOnly|EFileRead
750 r=file.Open(TheFs,_L("\\F32-tst\\ReadFileSection1.txt"),EFileShareReadersOnly|EFileRead);
753 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),400,testDes,52);
755 test(testDes==alphaPtr);
756 test(testDes.Length()==52);
758 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),452,testDes,20);
760 test(testDes==numberPtr);
761 test(testDes.Length()==20);
763 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),472,testDes,28);
765 test(testDes==humptyPtr);
766 test(testDes.Length()==28);
770 // Test with several accesses to a file EFileShareAny|EFileWrite
771 r=file.Open(TheFs,_L("\\F32-tst\\ReadFileSection1.txt"),EFileShareAny|EFileWrite);
775 r=secondFile.Open(TheFs,_L("\\F32-tst\\ReadFileSection1.txt"),EFileShareAny|EFileWrite);
779 r=thirdFile.Open(TheFs,_L("\\F32-tst\\ReadFileSection1.txt"),EFileShareAny|EFileWrite);
782 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),500,testDes,52);
785 #if defined(__WINS__)
787 test(testDes==alphaPtr);
788 test(testDes.Length()==52);
791 test(testDes==alphaPtr);
792 test(testDes.Length()==52);
795 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),552,testDes,20);
797 test(testDes==numberPtr);
798 test(testDes.Length()==20);
800 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),572,testDes,28);
802 test(testDes==humptyPtr);
803 test(testDes.Length()==28);
805 // Test across potential cluster boundaries
807 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),1000,testDes,200);
809 test(testDes.Length()==200);
814 amalgam.Append(alphaPtr);
815 amalgam.Append(numberPtr);
816 amalgam.Append(humptyPtr);
819 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),1000,testDes,200);
821 test(testDes.Length()==200);
822 test(testDes==amalgam);
824 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),3000,testDes,200);
826 test(testDes.Length()==200);
827 test(testDes==amalgam);
829 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),4000,testDes,200);
831 test(testDes.Length()==200);
832 test(testDes==amalgam);
838 // Test errors and boundary conditions
839 test.Next(_L("Test Error handling"));
841 // Test that specifying a zero length section returns a zero length descriptor
843 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),50,testDes2,0);
845 test(testDes2.Length()==0);
847 // Test that specifying a negative starting position causes a panic
848 // r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),-1,testDes2,10);
849 // This will panic: See RFs::ReadFileSection() code - relevant lines are
850 // __ASSERT_ALWAYS(aPos>=0,Panic(EPosNegative));
852 // Test that specifying a section of greater length than the descriptor to
853 // hold the data will cause a panic
854 // r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),0,testDes2,45);
855 // This will panic: See RFs::ReadFileSection() code - relevant lines are
856 // __ASSERT_ALWAYS(aDes.MaxLength()>=aLength,Panic(EBadLength));
859 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),2000,testDes2,-20);
860 test(r==KErrArgument);
862 // Test that specifying a position and length which extends beyond the end of
863 // the file returns a zero length descriptor and KErrNone
865 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),9993,testDes2,30);
867 test(testDes2.Length()==7);
868 test(testDes2==humptyPtr.Right(7));
870 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),9999,testDes2,1);
872 test(testDes2.Length()==1);
873 test(testDes2==humptyPtr.Right(1));
875 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),10000,testDes2,1);
877 test(testDes2.Length()==0);
879 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),10550,testDes2,20);
881 test(testDes2.Length()==0);
883 // Test reading the whole file
884 HBufC8* hDes=HBufC8::New(10002);
886 User::Leave(KErrNoMemory);
887 TPtr8 pDes=hDes->Des();
889 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),0,pDes,10000);
891 test(pDes.Length()==10000);
893 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),0,pDes,10000);
895 test(pDes.Length()==10000);
897 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),0,pDes,10002);
899 test(pDes.Length()==10000);
901 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),4000,pDes,6000);
903 test(pDes.Length()==6000);
905 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),4000,pDes,8002);
907 test(pDes.Length()==6000);
909 r=TheFs.ReadFileSection(_L("\\F32-tst\\ReadFileSection1.txt"),10000,pDes,10002);
911 test(pDes.Length()==0);
921 // Test Rom filesystem
924 test.Next(_L("Use RFs::ReadFileSection() to read from a file on the ROM"));
925 #if defined (__WINS__)
926 // Requires a copy of t_rdsect.txt in z directory (\EPOC32\RELEASE\WINS\BUILD\Z\TEST)
927 // Initially, test with file closed
930 TInt r=TheFs.ReadFileSection(_L("Z:\\test\\t_rdsect.txt"),0,temp1,26);
932 test(temp1.Length()==26);
933 test(temp1==_L8("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
936 r=TheFs.ReadFileSection(_L("Z:\\test\\t_rdsect.txt"),26,temp2,10);
938 test(temp2==_L8("0123456789"));
939 test(temp2.Length()==10);
941 r=TheFs.ReadFileSection(_L("Z:\\test\\t_rdsect.txt"),36,testDes,14);
943 test(testDes==_L8("Humpty-Dumpty!"));
944 test(testDes.Length()==14);
946 // Test with file open EFileShareAny|EFileRead
948 r=file.Open(TheFs,_L("Z:\\test\\t_rdsect.txt"),EFileShareAny|EFileRead);
951 r=TheFs.ReadFileSection(_L("Z:\\test\\t_rdsect.txt"),50,testDes,26);
953 test(testDes==_L8("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
954 test(testDes.Length()==26);
956 r=TheFs.ReadFileSection(_L("Z:\\test\\t_rdsect.txt"),76,testDes,10);
958 test(testDes==_L8("0123456789"));
959 test(testDes.Length()==10);
961 r=TheFs.ReadFileSection(_L("Z:\\test\\t_rdsect.txt"),86,testDes,14);
963 test(testDes==_L8("Humpty-Dumpty!"));
964 test(testDes.Length()==14);
968 // Test for MARM builds - oby file puts file in ROM (z:\test\)
969 // The file is the ASCII version
971 test.Next(_L("read small descriptor\n"));
974 TInt r=TheFs.ReadFileSection(_L("Z:\\test\\T_RDSECT.txt"),0,temp1,26);
976 test(temp1.Length()==26);
977 test(temp1==_L8("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
980 r=TheFs.ReadFileSection(_L("Z:\\test\\T_RDSECT.txt"),26,temp2,10);
982 test(temp2.Length()==10);
983 #if !defined (UNICODE)
984 test(testDes==_L8("0123456789"));
986 r=TheFs.ReadFileSection(_L("Z:\\test\\T_RDSECT.txt"),36,testDes,14);
988 test(testDes.Length()==14);
989 #if !defined (UNICODE)
990 test(testDes==_L8("Humpty-Dumpty!"));
992 r=TheFs.ReadFileSection(_L("Z:\\test\\T_RDSECT.txt"),50,testDes,26);
994 test(testDes.Length()==26);
995 #if !defined (UNICODE)
996 test(testDes==_L8("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
998 r=TheFs.ReadFileSection(_L("Z:\\test\\T_RDSECT.txt"),76,testDes,10);
1000 test(testDes.Length()==10);
1001 #if !defined (UNICODE)
1002 test(testDes==_L8("0123456789"));
1004 r=TheFs.ReadFileSection(_L("Z:\\test\\T_RDSECT.txt"),86,testDes,14);
1006 test(testDes.Length()==14);
1007 #if !defined (UNICODE)
1008 test(testDes==_L8("Humpty-Dumpty!"));
1013 LOCAL_C void DoTestsL()
1019 #if !defined (_UNICODE)
1030 GLDEF_C void CallTestsL(void)
1037 test.Start(_L("Testing filesystem on default drive"));
1040 if (IsSessionDriveLFFS(TheFs,driveLetter))
1042 test.Printf(_L("CallTestsL: Skipped: test does not run on LFFS.\n"));