First public contribution.
1 // Copyright (c) 2007-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 // N.B. Before running this test on WINS, ensure that the estart.txt file contains
15 // nothing but EFAT32 i.e. no EFAT - otherwise the FAT16 file system will be used
16 // On target ensure that the FAT32 filesystem is in the ROM instead of the FAT16 file system
17 // This test expects the following files to be present before running the test:
19 // 2147483647 \F32-TST\File2GBMinusOne.txt
20 // 2147483648 \F32-TST\File2GB.txt
21 // 3221225472 \F32-TST\File3GB.txt
22 // 4294967295 \F32-TST\File4GBMinusOne.txt // may be absent on an 8GB disk
23 // For verification purposes, Every 4 bytes of each file contains the current position, e.g.
28 // These files can be created using the BigFileWriter tool in f32test/tool
29 // If this test is run on the emulator and the __MOUNT_RAW_EXT__ macro is defined (see below) then
30 // the T_RAWEXT file system extension will be loaded; this extension allows reading and writing to
31 // a windows disk in "raw" format, thus allowing direct access to a windows disk. see f32test/ext/t_rawext
43 GLDEF_D RTest test(_L("T_BIGFILE"));
46 // enable this macro to mount the RAWEXT.FXT file system extension to test on a particular windows drive
47 #define __MOUNT_RAW_EXT__
50 #ifdef __MOUNT_RAW_EXT__
51 _LIT(KExtName,"RAWEXT");
53 _LIT(KFAT32FName,"EFAT32");
62 const TUint K1Kb = 1 << 10;
63 //const TUint K1Mb = 1 << 20;
64 const TUint K1Gb = 1 << 30;
65 const TUint K2Gb = 0x80000000;
66 const TUint K2GbMinusOne = 0x7FFFFFFF;
67 const TUint K3Gb = 0xC0000000;
68 const TUint K4GbMinusOne = 0xFFFFFFFF;
69 const TUint KPosMask = 0xFFFFFFFC;
71 //const TUint KBigFileSizeSigned = KMaxTInt32; // 2Gb -1
72 //const TUint KBigFileSizeUnsigned = KMaxTUint32; // 4Gb -1
74 const TInt KBufSize = (256 * K1Kb);
76 TPtr8 gBufPtr(NULL, 0, 0);
79 _LIT(KFile2GBMinusOne, "File2GBMinusOne.txt");
80 _LIT(KFile2GB, "File2GB.txt");
81 _LIT(KFile3GB, "File3GB.txt");
82 _LIT(KFile4GBMinusOne, "File4GBMinusOne.txt");
83 TInt gFilesInDirectory = 4;
86 // return ETrue if the specifiled file is present
87 TBool FilePresent(const TDesC& aFileName)
90 TInt r = TheFs.Entry(aFileName, entry);
91 return (r == KErrNone ? (TBool)ETrue : (TBool)EFalse);
94 class CFileManObserver : public CBase, public MFileManObserver
97 CFileManObserver(CFileMan* aFileMan);
99 TControl NotifyFileManStarted();
100 TControl NotifyFileManOperation();
101 TControl NotifyFileManEnded();
105 TInt iNotifyEndedSuccesses;
106 TInt iNotifyEndedFailures;
109 CFileManObserver::CFileManObserver(CFileMan* aFileMan)
111 __DECLARE_NAME(_S("CFileManObserver"));
115 MFileManObserver::TControl CFileManObserver::NotifyFileManStarted()
117 TInt lastError = iFileMan->GetLastError();
118 TFileName fileName = iFileMan->CurrentEntry().iName;
119 test.Printf(_L("NotifyFileManStarted(): Error %d File %S\n"),lastError, &fileName);
120 return(MFileManObserver::EContinue);
123 MFileManObserver::TControl CFileManObserver::NotifyFileManOperation()
125 TInt lastError = iFileMan->GetLastError();
126 TFileName fileName = iFileMan->CurrentEntry().iName;
127 test.Printf(_L("NotifyFileManOperation(): Error %d File %S\n"),lastError, &fileName);
128 return(MFileManObserver::EContinue);
131 MFileManObserver::TControl CFileManObserver::NotifyFileManEnded()
133 TInt lastError = iFileMan->GetLastError();
134 TFileName fileName = iFileMan->CurrentEntry().iName;
135 test.Printf(_L("NotifyFileManEnded(): Error %d File %S\n"),lastError, &fileName);
136 if (lastError == KErrNone)
137 iNotifyEndedSuccesses++;
139 iNotifyEndedFailures++;
140 return(MFileManObserver::EContinue);
145 //----------------------------------------------------------------------------------------------
146 //! @SYMTestCaseID PBASE-T_BIGFILE-0001
148 //! @SYMTestCaseDesc Test that 2GB-1 file can be opened and read
149 //! @SYMTestActions Open the file, seek to end-1K and read some data. Verify the results
150 //! @SYMTestExpectedResults Should succeed
151 //! @SYMTestPriority High
152 //! @SYMTestStatus Implemented
153 //----------------------------------------------------------------------------------------------
154 void OpenAndRead2GBMinusOne()
163 TPtr8 bufPtr = gBuf->Des();
164 bufPtr.SetLength(bufPtr.MaxLength());
166 const TFileName fname = KFile2GBMinusOne();
168 test.Next(_L("2GBMinusOne File: Open"));
170 r = f.Open(TheFs, fname, EFileRead);
173 testSize = K2GbMinusOne;
175 test.Next(_L("2GBMinusOne File: Read"));
177 r=f.Size((TInt&) size);
179 test(size == testSize);
181 r = TheFs.Entry(fname, entry);
183 test ((TUint) entry.iSize == testSize);
185 // seek to just below 2GB
186 testPos = (K2GbMinusOne - K1Kb) & KPosMask;
187 r = f.Seek(ESeekStart, (TInt&) testPos);
193 TUint posRead = * ((TUint*) &bufPtr[0]);
194 test.Printf(_L("position read %08X, expected %08X\n"), posRead, testPos);
195 test(posRead == testPos);
200 //----------------------------------------------------------------------------------------------
201 //! @SYMTestCaseID PBASE-T_BIGFILE-0002
203 //! @SYMTestCaseDesc Test that attempting to open a 2GB file fails
204 //! @SYMTestActions Open the file
205 //! @SYMTestExpectedResults KErrToBig
206 //! @SYMTestPriority High
207 //! @SYMTestStatus Implemented
208 //----------------------------------------------------------------------------------------------
216 TPtr8 bufPtr = gBuf->Des();
217 bufPtr.SetLength(bufPtr.MaxLength());
219 const TFileName fname = KFile2GB();
222 test.Next(_L("2GB File: Test the size with RFs::Entry"));
223 r = TheFs.Entry(fname, entry);
225 test ((TUint) entry.iSize == testSize);
227 test.Next(_L("2GB File: Attempt to open (should fail with KErrToBig)"));
229 r = f.Open(TheFs, fname, EFileRead);
233 //----------------------------------------------------------------------------------------------
234 //! @SYMTestCaseID PBASE-T_BIGFILE-0003
236 //! @SYMTestCaseDesc Test that attempting to open a 2GB file fails
237 //! @SYMTestActions Open the file
238 //! @SYMTestExpectedResults KErrToBig
239 //! @SYMTestPriority High
240 //! @SYMTestStatus Implemented
241 //----------------------------------------------------------------------------------------------
249 TPtr8 bufPtr = gBuf->Des();
250 bufPtr.SetLength(bufPtr.MaxLength());
252 const TFileName fname = KFile3GB();
255 test.Next(_L("3GB File: Test the size with RFs::Entry"));
256 r = TheFs.Entry(fname, entry);
258 test ((TUint) entry.iSize == testSize);
260 test.Next(_L("3GB File: Attempt to open (should fail with KErrToBig)"));
262 r = f.Open(TheFs, fname, EFileRead);
266 //----------------------------------------------------------------------------------------------
267 //! @SYMTestCaseID PBASE-T_BIGFILE-0004
269 //! @SYMTestCaseDesc Test that attempting to open a 4GB file fails
270 //! @SYMTestActions Open the file
271 //! @SYMTestExpectedResults KErrToBig
272 //! @SYMTestPriority High
273 //! @SYMTestStatus Implemented
274 //----------------------------------------------------------------------------------------------
282 TPtr8 bufPtr = gBuf->Des();
283 bufPtr.SetLength(bufPtr.MaxLength());
285 const TFileName fname = KFile4GBMinusOne();
286 testSize = K4GbMinusOne;
288 test.Next(_L("4GB File: Test the size with RFs::Entry"));
289 r = TheFs.Entry(fname, entry);
292 test ((TUint) entry.iSize == testSize);
294 test.Next(_L("4GB File: Attempt to open (should fail with KErrToBig)"));
296 r = f.Open(TheFs, fname, EFileRead);
300 //----------------------------------------------------------------------------------------------
301 //! @SYMTestCaseID PBASE-T_BIGFILE-0005
303 //! @SYMTestCaseDesc Attempt to append to the end of a 2GB-1 file
304 //! @SYMTestActions Open the file, seek to end and write one byte
305 //! @SYMTestExpectedResults RFile::Write(0 returns KErrToBig
306 //! @SYMTestPriority High
307 //! @SYMTestStatus Implemented
308 //----------------------------------------------------------------------------------------------
309 void Extend2GBMinusOne()
318 TPtr8 bufPtr = gBuf->Des();
319 bufPtr.SetLength(bufPtr.MaxLength());
321 const TFileName fname = KFile2GBMinusOne();
322 testSize = K2GbMinusOne;
324 test.Next(_L("2GBMinusOne File: Open"));
326 r = f.Open(TheFs, fname, EFileRead | EFileWrite);
330 test.Next(_L("2GBMinusOne File: Attempt to extend"));
332 r=f.Size((TInt&) size);
334 test(size == testSize);
336 r = TheFs.Entry(fname, entry);
338 test ((TUint) entry.iSize == testSize);
342 r = f.Seek(ESeekEnd, (TInt&) testPos);
352 //----------------------------------------------------------------------------------------------
353 //! @SYMTestCaseID PBASE-T_BIGFILE-0006
355 //! @SYMTestCaseDesc Check that deleting a large file frees cluster properly
356 //! @SYMTestActions Delete the passed file name, call RFs::CheckDisk
357 //! On windows, we could run chkdsk utility
358 //! @SYMTestExpectedResults RFs::CheckDisk returns success
359 //! @SYMTestPriority High
360 //! @SYMTestStatus Implemented
361 //----------------------------------------------------------------------------------------------
362 void DeleteLargeFile(const TDesC& aFileName)
364 test.Next(_L("Delete large file"));
365 test.Printf(_L("Deleting %S\n"), &aFileName);
367 TInt r = TheFs.Delete(aFileName);
374 //----------------------------------------------------------------------------------------------
375 //! @SYMTestCaseID PBASE-T_BIGFILE-0007
377 //! @SYMTestCaseDesc Check that we can get a valid directory listing of a directory
378 //! containing large files using RDir and then CDir
379 //! @SYMTestActions Open the directory using RDir and examine the results
380 //! On windows, we could run chkdsk utility
381 //! @SYMTestExpectedResults The expected number of files should exist with the correct sizes
382 //! @SYMTestPriority High
383 //! @SYMTestStatus Implemented
384 //----------------------------------------------------------------------------------------------
387 test.Next(_L("Read a directory containing large files using RDir"));
390 TInt r = dir.Open(TheFs, _L("*.*"), KEntryAttNormal);
391 test (r == KErrNone);
393 TEntryArray entryArray;
394 r = dir.Read(entryArray);
397 test(entryArray.Count() == gFilesInDirectory);
400 for (n=0; n<entryArray.Count(); n++)
402 const TEntry& entry = entryArray[n];
403 if (entry.iName.MatchF(KFile2GBMinusOne()) == 0)
405 test((TUint) entry.iSize == K2GbMinusOne);
407 else if (entry.iName.MatchF(KFile2GB()) == 0)
409 test((TUint) entry.iSize == K2Gb);
411 else if (entry.iName.MatchF(KFile3GB()) == 0)
413 test((TUint) entry.iSize == K3Gb);
415 else if (entry.iName.MatchF(KFile4GBMinusOne()) == 0)
417 test((TUint) entry.iSize == K4GbMinusOne);
425 test.Next(_L("Read a directory containing large files using CDir & sort by size"));
427 r=TheFs.GetDir(_L("*.*"), KEntryAttMaskSupported, ESortBySize, dirList);
429 test(dirList->Count() == gFilesInDirectory);
430 for (n=0; n<dirList->Count(); n++)
434 // test.Printf(_L("#%d: %08X %d %S"), n, entry.iSize, entry.iSize, &entry.iName);
435 if (entry.iName.MatchF(KFile2GBMinusOne()) == 0)
437 test((TUint) entry.iSize == K2GbMinusOne);
438 test(n == 0); // test entry has been sorted correctly (i.e. according to size)
440 else if (entry.iName.MatchF(KFile2GB()) == 0)
442 test((TUint) entry.iSize == K2Gb);
445 else if (entry.iName.MatchF(KFile3GB()) == 0)
447 test((TUint) entry.iSize == K3Gb);
450 else if (entry.iName.MatchF(KFile4GBMinusOne()) == 0)
452 test((TUint) entry.iSize == K4GbMinusOne);
464 //----------------------------------------------------------------------------------------------
465 //! @SYMTestCaseID PBASE-T_BIGFILE-0008
467 //! @SYMTestCaseDesc Check that we can a move a directory containing large files
468 //! Using CFileMan::Move()
469 //! @SYMTestActions Use CFileMan::Move() to move files from one directory to another
470 //! @SYMTestExpectedResults The files should be moved correctly
471 //! @SYMTestPriority High
472 //! @SYMTestStatus Implemented
473 //----------------------------------------------------------------------------------------------
476 test.Next(_L("Move a directory containing large files"));
478 CFileMan* fileMan = CFileMan::NewL(TheFs);
479 test(fileMan != NULL);
481 TPath filePathOld = gSessionPath;
482 filePathOld+= _L("*.*");
483 TPath filePathNew = _L("?:\\TEST\\");
485 TInt r=TheFs.DriveToChar(gDrive,driveLetter);
487 filePathNew[0] = (TText) driveLetter;
489 // move to new directory
490 r = fileMan->Move(filePathOld, filePathNew, CFileMan::ERecurse | CFileMan::EOverWrite);
493 // then move back again
494 r = fileMan->Move(filePathNew, filePathOld);
501 //----------------------------------------------------------------------------------------------
502 //! @SYMTestCaseID PBASE-T_BIGFILE-0009
504 //! @SYMTestCaseDesc Check that we can copy a directory containing large file(s)
505 //! Using CFileMan::Copy()
506 //! @SYMTestActions Use CFileMan::Copy() to copy files from one directory to another
507 //! @SYMTestExpectedResults The files should be copied correctly
508 //! @SYMTestPriority High
509 //! @SYMTestStatus Implemented
510 //----------------------------------------------------------------------------------------------
513 test.Next(_L("Copy a directory containing large files"));
514 CFileMan* fileMan = CFileMan::NewL(TheFs);
515 test(fileMan != NULL);
517 CFileManObserver* observer = new CFileManObserver(fileMan);
518 test(observer != NULL);
520 TPath filePathOld = gSessionPath;
521 filePathOld+= _L("*.*");
522 TPath filePathNew = _L("?:\\TEST\\");
524 TInt r = TheFs.DriveToChar(gDrive,driveLetter);
526 filePathNew[0] = (TText) driveLetter;
528 // create some small files in the source directory
529 // so that there is a combination of small files and one large files
531 _LIT(KFileSmall1, "FileSmallOne.txt");
532 _LIT(KFileSmall2, "FileSmallTwo.txt");
533 _LIT(KFileSmall3, "FileSmallThree.txt");
534 r = file.Create(TheFs, KFileSmall1(), EFileWrite | EFileShareAny);
536 r = file.Write(_L8("1"));
540 r = file.Create(TheFs, KFileSmall2(), EFileWrite | EFileShareAny);
542 r = file.Write(_L8("12"));
546 r = file.Create(TheFs, KFileSmall3(), EFileWrite | EFileShareAny);
548 r = file.Write(_L8("123"));
552 // copy to new directory
553 r = fileMan->Copy(filePathOld, filePathNew, CFileMan::ERecurse | CFileMan::EOverWrite);
554 test(r == KErrNone || r == KErrTooBig);
557 // check SMALL files have been copied
559 r = dir.Open(TheFs, filePathNew, KEntryAttNormal);
560 test (r == KErrNone);
561 TEntryArray entryArray;
562 r = dir.Read(entryArray);
564 test(entryArray.Count() == 3);
567 // then delete the new directory
568 r = fileMan->Delete(filePathNew);
572 // attempt to copy to new directory again - this time with an observer
573 fileMan->SetObserver(observer);
574 r = fileMan->Copy(filePathOld, filePathNew, CFileMan::ERecurse | CFileMan::EOverWrite);
575 test(r == KErrNone || r == KErrTooBig);
577 // test that 3 small files were copied and 1 or 2 large files failed to copy
578 // (For 8 GB disk, the 4GB file is missing)
579 test(observer->iNotifyEndedSuccesses == 3);
580 test(observer->iNotifyEndedFailures == 1 || observer->iNotifyEndedFailures == 2);
582 // check SMALL files have been copied
583 r = dir.Open(TheFs, filePathNew, KEntryAttNormal);
584 test (r == KErrNone);
585 r = dir.Read(entryArray);
587 test(entryArray.Count() == 3);
590 // then delete the new directory
591 r = fileMan->Delete(filePathNew);
599 //----------------------------------------------------------------------------------------------
600 //! @SYMTestCaseID PBASE-T_BIGFILE-000A
602 //! @SYMTestCaseDesc Check that CDirScan works correctly with a directory containing large file(s)
603 //! @SYMTestActions Use CFileMan::Copy() to copy files from one directory to another
604 //! @SYMTestExpectedResults The files should be copied correctly
605 //! @SYMTestPriority High
606 //! @SYMTestStatus Implemented
607 //----------------------------------------------------------------------------------------------
608 TInt ScanDir(const TDesC& aName, CDirScan::TScanDirection aDirection, TInt aError)
613 CDirScan* scanner = NULL;
614 TRAP(r, scanner = CDirScan::NewL(TheFs));
615 test(r == KErrNone && scanner);
617 TRAP(r, scanner->SetScanDataL(aName,KEntryAttDir,ESortByName|EAscending,aDirection));
620 CDir *entryList=NULL;
624 TRAP(r, scanner->NextL(entryList));
628 TInt count = entryList->Count();
631 TEntry data=(*entryList)[count];
632 TBuf<KMaxFileName> path=scanner->AbbreviatedPath();
634 dirName.Append(data.iName);
635 test.Printf(_L(" %S\n"),&dirName);
649 GLDEF_C void CallTestsL()
651 // Do tests relative to the session path
655 #if defined(__WINS__)
656 if (gSessionPath[0]=='C')
662 // don't test on NTFS
665 test.Printf(_L("Skipping test: Drive is NTFS\n"));
671 r = TheFs.CharToDrive(gDriveToTest, gDrive);
674 #ifdef __MOUNT_RAW_EXT__
675 r=TheFs.FileSystemName(gOldFsName, gDrive);
678 if (gOldFsName.CompareF(KFATName) != 0)
680 test.Printf(_L("Skipping test: Not a FAT drive\n"));
684 r = TheFs.AddExtension(KExtName);
685 test(r==KErrNone || r==KErrAlreadyExists);
686 r = TheFs.MountExtension(KExtName, gDrive);
687 test(r==KErrNone || r==KErrAlreadyExists);
691 test((r = TheFs.Volume(vi, gDrive)) == KErrNone);
692 test.Printf(_L("vi.iSize = %ld\n"), vi.iSize);
694 // don't test if media sise is less than 7GB
695 if (vi.iSize < TInt64(K1Gb) * TInt64(7))
697 test.Printf(_L("Skipping test: Drive is not big enough\n"));
699 if (!FilePresent(KFile2GB()))
701 test.Printf(_L("Skipping test: Test files not present on drive\n"));
705 gBuf = HBufC8::NewL(KBufSize);
707 User::Leave(KErrNoMemory);
708 gBufPtr = gBuf->Des();
713 // Test that RFs::CheckDisk() succeeds with large files present
716 test.Next(_L("Scan Drive"));
717 r = TheFs.ScanDrive(gSessionPath);
718 test (r == KErrNone);
720 // NB the 4GB file will not be present unless the disk is > 8GB (because it doesn't fit)
721 if (!FilePresent(KFile4GBMinusOne()))
725 // the number of files & directories found should be 5 or 4
726 TInt filesFound = ScanDir(_L("\\"), CDirScan::EScanUpTree, KErrNone);
727 test (filesFound == gFilesInDirectory+1);
728 filesFound = ScanDir(_L("\\"), CDirScan::EScanDownTree, KErrNone);
729 test (filesFound == gFilesInDirectory+1);
731 OpenAndRead2GBMinusOne();
735 // the 4GB file will not be present unless the disk is > 8GB
736 if (FilePresent(KFile4GBMinusOne()))
746 // delete the 2 smaller files to make some space
747 DeleteLargeFile(KFile2GB());
748 DeleteLargeFile(KFile2GBMinusOne());
752 // delete the 3GB file and check the disk
753 DeleteLargeFile(KFile3GB());
755 if (FilePresent(KFile4GBMinusOne()))
756 DeleteLargeFile(KFile4GBMinusOne());
758 // Finally check that we can format the drive...
762 #ifdef __MOUNT_RAW_EXT__
763 r = TheFs.DismountExtension(KExtName, gDrive);
766 r = TheFs.RemoveExtension(KExtName);
771 delete gBuf; gBuf = NULL;