os/kernelhwsrv/kerneltest/f32test/server/t_bigfile.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) 2007-2009 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 the License "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
// N.B. Before running this test on WINS, ensure that the estart.txt file contains 
sl@0
    15
// nothing but  EFAT32 i.e. no EFAT - otherwise the FAT16 file system will be used
sl@0
    16
// On target ensure that the FAT32 filesystem is in the ROM instead of the FAT16 file system
sl@0
    17
// This test expects the following files to be present before running the test:
sl@0
    18
// size			name
sl@0
    19
// 2147483647	\F32-TST\File2GBMinusOne.txt
sl@0
    20
// 2147483648	\F32-TST\File2GB.txt
sl@0
    21
// 3221225472	\F32-TST\File3GB.txt
sl@0
    22
// 4294967295	\F32-TST\File4GBMinusOne.txt	// may be absent on an 8GB disk
sl@0
    23
// For verification purposes, Every 4 bytes of each file contains the current position, e.g.
sl@0
    24
// 0000: 00 00 00 00 
sl@0
    25
// 0004: 04 00 00 00
sl@0
    26
// 0008: 08 00 00 00
sl@0
    27
// .. etc
sl@0
    28
// These files can be created using the BigFileWriter tool in f32test/tool
sl@0
    29
// If this test is run on the emulator and the __MOUNT_RAW_EXT__ macro is defined (see below) then
sl@0
    30
// the T_RAWEXT file system extension will be loaded; this extension allows reading and writing to 
sl@0
    31
// a windows disk in "raw" format, thus allowing direct access to a windows disk. see f32test/ext/t_rawext
sl@0
    32
// for more details.
sl@0
    33
// 
sl@0
    34
//
sl@0
    35
sl@0
    36
sl@0
    37
#include <f32file.h>
sl@0
    38
#include <e32test.h>
sl@0
    39
#include <e32svr.h>
sl@0
    40
#include "t_server.h"
sl@0
    41
sl@0
    42
sl@0
    43
GLDEF_D RTest test(_L("T_BIGFILE"));
sl@0
    44
sl@0
    45
#ifdef __WINS__
sl@0
    46
// enable this macro to mount the RAWEXT.FXT file system extension to test on a particular windows drive
sl@0
    47
#define __MOUNT_RAW_EXT__
sl@0
    48
#endif
sl@0
    49
sl@0
    50
#ifdef __MOUNT_RAW_EXT__
sl@0
    51
_LIT(KExtName,"RAWEXT");
sl@0
    52
sl@0
    53
_LIT(KFAT32FName,"EFAT32");
sl@0
    54
_LIT(KFATName,"FAT");
sl@0
    55
sl@0
    56
TFullName gOldFsName;
sl@0
    57
#endif
sl@0
    58
sl@0
    59
TInt gDrive;
sl@0
    60
TBool gNTFS=EFalse;
sl@0
    61
sl@0
    62
const TUint K1Kb = 1 << 10;
sl@0
    63
//const TUint K1Mb = 1 << 20;
sl@0
    64
const TUint K1Gb = 1 << 30;
sl@0
    65
const TUint K2Gb = 0x80000000;
sl@0
    66
const TUint K2GbMinusOne = 0x7FFFFFFF;
sl@0
    67
const TUint K3Gb = 0xC0000000;
sl@0
    68
const TUint K4GbMinusOne = 0xFFFFFFFF;
sl@0
    69
const TUint KPosMask     = 0xFFFFFFFC;
sl@0
    70
sl@0
    71
//const TUint KBigFileSizeSigned = KMaxTInt32;		// 2Gb -1
sl@0
    72
//const TUint KBigFileSizeUnsigned = KMaxTUint32;	// 4Gb -1
sl@0
    73
sl@0
    74
const TInt KBufSize = (256 * K1Kb);
sl@0
    75
HBufC8* gBuf = NULL;
sl@0
    76
TPtr8 gBufPtr(NULL, 0, 0);
sl@0
    77
sl@0
    78
sl@0
    79
_LIT(KFile2GBMinusOne, "File2GBMinusOne.txt");
sl@0
    80
_LIT(KFile2GB, "File2GB.txt");
sl@0
    81
_LIT(KFile3GB, "File3GB.txt");
sl@0
    82
_LIT(KFile4GBMinusOne, "File4GBMinusOne.txt");
sl@0
    83
TInt gFilesInDirectory = 4;
sl@0
    84
sl@0
    85
sl@0
    86
// return ETrue if the specifiled file is present
sl@0
    87
TBool FilePresent(const TDesC& aFileName)
sl@0
    88
	{
sl@0
    89
	TEntry entry;
sl@0
    90
	TInt r = TheFs.Entry(aFileName, entry);
sl@0
    91
	return (r == KErrNone ? (TBool)ETrue : (TBool)EFalse);
sl@0
    92
	}
sl@0
    93
sl@0
    94
class CFileManObserver : public CBase, public MFileManObserver
sl@0
    95
	{
sl@0
    96
public:
sl@0
    97
	CFileManObserver(CFileMan* aFileMan);
sl@0
    98
sl@0
    99
	TControl NotifyFileManStarted();
sl@0
   100
	TControl NotifyFileManOperation();
sl@0
   101
	TControl NotifyFileManEnded();
sl@0
   102
private:
sl@0
   103
	CFileMan* iFileMan;
sl@0
   104
public:
sl@0
   105
	TInt iNotifyEndedSuccesses;
sl@0
   106
	TInt iNotifyEndedFailures;
sl@0
   107
	};
sl@0
   108
sl@0
   109
CFileManObserver::CFileManObserver(CFileMan* aFileMan)
sl@0
   110
	{
sl@0
   111
	__DECLARE_NAME(_S("CFileManObserver"));
sl@0
   112
	iFileMan=aFileMan;
sl@0
   113
	}
sl@0
   114
sl@0
   115
MFileManObserver::TControl CFileManObserver::NotifyFileManStarted()
sl@0
   116
	{
sl@0
   117
	TInt lastError = iFileMan->GetLastError();
sl@0
   118
	TFileName fileName = iFileMan->CurrentEntry().iName;
sl@0
   119
	test.Printf(_L("NotifyFileManStarted(): Error %d File %S\n"),lastError, &fileName);
sl@0
   120
	return(MFileManObserver::EContinue);
sl@0
   121
	}
sl@0
   122
sl@0
   123
MFileManObserver::TControl CFileManObserver::NotifyFileManOperation()
sl@0
   124
	{
sl@0
   125
	TInt lastError = iFileMan->GetLastError();
sl@0
   126
	TFileName fileName = iFileMan->CurrentEntry().iName;
sl@0
   127
	test.Printf(_L("NotifyFileManOperation(): Error %d File %S\n"),lastError, &fileName);
sl@0
   128
	return(MFileManObserver::EContinue);
sl@0
   129
	}
sl@0
   130
sl@0
   131
MFileManObserver::TControl CFileManObserver::NotifyFileManEnded()
sl@0
   132
	{
sl@0
   133
	TInt lastError = iFileMan->GetLastError();
sl@0
   134
	TFileName fileName = iFileMan->CurrentEntry().iName;
sl@0
   135
	test.Printf(_L("NotifyFileManEnded(): Error %d File %S\n"),lastError, &fileName);
sl@0
   136
	if (lastError == KErrNone)
sl@0
   137
		iNotifyEndedSuccesses++;
sl@0
   138
	else
sl@0
   139
		iNotifyEndedFailures++;
sl@0
   140
	return(MFileManObserver::EContinue);
sl@0
   141
	}
sl@0
   142
sl@0
   143
sl@0
   144
sl@0
   145
//----------------------------------------------------------------------------------------------
sl@0
   146
//! @SYMTestCaseID      PBASE-T_BIGFILE-0001
sl@0
   147
//! @SYMTestType        CIT
sl@0
   148
//! @SYMTestCaseDesc    Test that 2GB-1 file can be opened and read
sl@0
   149
//! @SYMTestActions     Open the file, seek to end-1K and read some data. Verify the results
sl@0
   150
//! @SYMTestExpectedResults Should succeed
sl@0
   151
//! @SYMTestPriority    High
sl@0
   152
//! @SYMTestStatus      Implemented
sl@0
   153
//----------------------------------------------------------------------------------------------
sl@0
   154
void OpenAndRead2GBMinusOne()
sl@0
   155
	{
sl@0
   156
	RFile f;
sl@0
   157
	TEntry entry;
sl@0
   158
	TUint testSize;
sl@0
   159
	TUint size;
sl@0
   160
	TUint testPos;
sl@0
   161
	TInt r;
sl@0
   162
sl@0
   163
	TPtr8 bufPtr = gBuf->Des();
sl@0
   164
	bufPtr.SetLength(bufPtr.MaxLength());
sl@0
   165
sl@0
   166
	const TFileName fname = KFile2GBMinusOne();
sl@0
   167
sl@0
   168
	test.Next(_L("2GBMinusOne File: Open"));
sl@0
   169
sl@0
   170
	r = f.Open(TheFs, fname, EFileRead);
sl@0
   171
	test(r==KErrNone);
sl@0
   172
sl@0
   173
	testSize = K2GbMinusOne;
sl@0
   174
	
sl@0
   175
	test.Next(_L("2GBMinusOne File: Read"));
sl@0
   176
sl@0
   177
	r=f.Size((TInt&) size);
sl@0
   178
	test(r==KErrNone);
sl@0
   179
	test(size == testSize);
sl@0
   180
	
sl@0
   181
	r = TheFs.Entry(fname, entry);
sl@0
   182
	test(r==KErrNone);
sl@0
   183
	test ((TUint) entry.iSize == testSize);
sl@0
   184
sl@0
   185
	// seek to just below 2GB
sl@0
   186
	testPos = (K2GbMinusOne - K1Kb) & KPosMask;
sl@0
   187
	r = f.Seek(ESeekStart, (TInt&) testPos);
sl@0
   188
	test(r==KErrNone);
sl@0
   189
sl@0
   190
	r = f.Read(bufPtr);
sl@0
   191
	test(r==KErrNone);
sl@0
   192
sl@0
   193
	TUint posRead =  * ((TUint*) &bufPtr[0]);
sl@0
   194
	test.Printf(_L("position read %08X, expected %08X\n"), posRead, testPos);
sl@0
   195
	test(posRead == testPos);
sl@0
   196
sl@0
   197
	f.Close();
sl@0
   198
	}
sl@0
   199
sl@0
   200
//----------------------------------------------------------------------------------------------
sl@0
   201
//! @SYMTestCaseID      PBASE-T_BIGFILE-0002
sl@0
   202
//! @SYMTestType        CIT
sl@0
   203
//! @SYMTestCaseDesc    Test that attempting to open a 2GB file fails
sl@0
   204
//! @SYMTestActions     Open the file
sl@0
   205
//! @SYMTestExpectedResults KErrToBig
sl@0
   206
//! @SYMTestPriority    High
sl@0
   207
//! @SYMTestStatus      Implemented
sl@0
   208
//----------------------------------------------------------------------------------------------
sl@0
   209
void Open2GB()
sl@0
   210
	{
sl@0
   211
	RFile f;
sl@0
   212
	TEntry entry;
sl@0
   213
	TUint testSize;
sl@0
   214
	TInt r;
sl@0
   215
sl@0
   216
	TPtr8 bufPtr = gBuf->Des();
sl@0
   217
	bufPtr.SetLength(bufPtr.MaxLength());
sl@0
   218
sl@0
   219
	const TFileName fname = KFile2GB();
sl@0
   220
	testSize = K2Gb;
sl@0
   221
sl@0
   222
	test.Next(_L("2GB File: Test the size with RFs::Entry"));
sl@0
   223
	r = TheFs.Entry(fname, entry);
sl@0
   224
	test(r==KErrNone);
sl@0
   225
	test ((TUint) entry.iSize == testSize);
sl@0
   226
sl@0
   227
	test.Next(_L("2GB File: Attempt to open (should fail with KErrToBig)"));
sl@0
   228
sl@0
   229
	r = f.Open(TheFs, fname, EFileRead);
sl@0
   230
	test(r==KErrTooBig);
sl@0
   231
	}
sl@0
   232
sl@0
   233
//----------------------------------------------------------------------------------------------
sl@0
   234
//! @SYMTestCaseID      PBASE-T_BIGFILE-0003
sl@0
   235
//! @SYMTestType        CIT
sl@0
   236
//! @SYMTestCaseDesc    Test that attempting to open a 2GB file fails
sl@0
   237
//! @SYMTestActions     Open the file
sl@0
   238
//! @SYMTestExpectedResults KErrToBig
sl@0
   239
//! @SYMTestPriority    High
sl@0
   240
//! @SYMTestStatus      Implemented
sl@0
   241
//----------------------------------------------------------------------------------------------
sl@0
   242
void Open3GB()
sl@0
   243
	{
sl@0
   244
	RFile f;
sl@0
   245
	TEntry entry;
sl@0
   246
	TUint testSize;
sl@0
   247
	TInt r;
sl@0
   248
sl@0
   249
	TPtr8 bufPtr = gBuf->Des();
sl@0
   250
	bufPtr.SetLength(bufPtr.MaxLength());
sl@0
   251
sl@0
   252
	const TFileName fname = KFile3GB();
sl@0
   253
	testSize = K3Gb;
sl@0
   254
sl@0
   255
	test.Next(_L("3GB File: Test the size with RFs::Entry"));
sl@0
   256
	r = TheFs.Entry(fname, entry);
sl@0
   257
	test(r==KErrNone);
sl@0
   258
	test ((TUint) entry.iSize == testSize);
sl@0
   259
sl@0
   260
	test.Next(_L("3GB File: Attempt to open (should fail with KErrToBig)"));
sl@0
   261
sl@0
   262
	r = f.Open(TheFs, fname, EFileRead);
sl@0
   263
	test(r==KErrTooBig);
sl@0
   264
	}
sl@0
   265
sl@0
   266
//----------------------------------------------------------------------------------------------
sl@0
   267
//! @SYMTestCaseID      PBASE-T_BIGFILE-0004
sl@0
   268
//! @SYMTestType        CIT
sl@0
   269
//! @SYMTestCaseDesc    Test that attempting to open a 4GB file fails
sl@0
   270
//! @SYMTestActions     Open the file
sl@0
   271
//! @SYMTestExpectedResults KErrToBig
sl@0
   272
//! @SYMTestPriority    High
sl@0
   273
//! @SYMTestStatus      Implemented
sl@0
   274
//----------------------------------------------------------------------------------------------
sl@0
   275
void Open4GB()
sl@0
   276
	{
sl@0
   277
	RFile f;
sl@0
   278
	TEntry entry;
sl@0
   279
	TUint testSize;
sl@0
   280
	TInt r;
sl@0
   281
sl@0
   282
	TPtr8 bufPtr = gBuf->Des();
sl@0
   283
	bufPtr.SetLength(bufPtr.MaxLength());
sl@0
   284
sl@0
   285
	const TFileName fname = KFile4GBMinusOne();
sl@0
   286
	testSize = K4GbMinusOne;
sl@0
   287
sl@0
   288
	test.Next(_L("4GB File: Test the size with RFs::Entry"));
sl@0
   289
	r = TheFs.Entry(fname, entry);
sl@0
   290
	
sl@0
   291
	test(r==KErrNone);
sl@0
   292
	test ((TUint) entry.iSize == testSize);
sl@0
   293
sl@0
   294
	test.Next(_L("4GB File: Attempt to open (should fail with KErrToBig)"));
sl@0
   295
sl@0
   296
	r = f.Open(TheFs, fname, EFileRead);
sl@0
   297
	test(r==KErrTooBig);
sl@0
   298
	}
sl@0
   299
sl@0
   300
//----------------------------------------------------------------------------------------------
sl@0
   301
//! @SYMTestCaseID      PBASE-T_BIGFILE-0005
sl@0
   302
//! @SYMTestType        CIT
sl@0
   303
//! @SYMTestCaseDesc    Attempt to append to the end of a 2GB-1 file
sl@0
   304
//! @SYMTestActions     Open the file, seek to end and write one byte
sl@0
   305
//! @SYMTestExpectedResults RFile::Write(0 returns KErrToBig
sl@0
   306
//! @SYMTestPriority    High
sl@0
   307
//! @SYMTestStatus      Implemented
sl@0
   308
//----------------------------------------------------------------------------------------------
sl@0
   309
void Extend2GBMinusOne()
sl@0
   310
	{
sl@0
   311
	RFile f;
sl@0
   312
	TEntry entry;
sl@0
   313
	TUint testSize;
sl@0
   314
	TUint size;
sl@0
   315
	TUint testPos;
sl@0
   316
	TInt r;
sl@0
   317
sl@0
   318
	TPtr8 bufPtr = gBuf->Des();
sl@0
   319
	bufPtr.SetLength(bufPtr.MaxLength());
sl@0
   320
sl@0
   321
	const TFileName fname = KFile2GBMinusOne();
sl@0
   322
	testSize = K2GbMinusOne;
sl@0
   323
sl@0
   324
	test.Next(_L("2GBMinusOne File: Open"));
sl@0
   325
sl@0
   326
	r = f.Open(TheFs, fname, EFileRead | EFileWrite);
sl@0
   327
	test(r==KErrNone);
sl@0
   328
sl@0
   329
	
sl@0
   330
	test.Next(_L("2GBMinusOne File: Attempt to extend"));
sl@0
   331
sl@0
   332
	r=f.Size((TInt&) size);
sl@0
   333
	test(r==KErrNone);
sl@0
   334
	test(size == testSize);
sl@0
   335
	
sl@0
   336
	r = TheFs.Entry(fname, entry);
sl@0
   337
	test(r==KErrNone);
sl@0
   338
	test ((TUint) entry.iSize == testSize);
sl@0
   339
sl@0
   340
	// seek to end
sl@0
   341
	testPos = 0;
sl@0
   342
	r = f.Seek(ESeekEnd, (TInt&) testPos);
sl@0
   343
	test(r==KErrNone);
sl@0
   344
sl@0
   345
	bufPtr.SetLength(1);
sl@0
   346
	r = f.Write(bufPtr);
sl@0
   347
	test(r==KErrTooBig);
sl@0
   348
sl@0
   349
	f.Close();
sl@0
   350
	}
sl@0
   351
sl@0
   352
//----------------------------------------------------------------------------------------------
sl@0
   353
//! @SYMTestCaseID      PBASE-T_BIGFILE-0006
sl@0
   354
//! @SYMTestType        CIT
sl@0
   355
//! @SYMTestCaseDesc    Check that deleting a large file frees cluster properly
sl@0
   356
//! @SYMTestActions     Delete the passed file name, call RFs::CheckDisk
sl@0
   357
//!						On windows, we could run chkdsk utility 
sl@0
   358
//! @SYMTestExpectedResults RFs::CheckDisk returns success
sl@0
   359
//! @SYMTestPriority    High
sl@0
   360
//! @SYMTestStatus      Implemented
sl@0
   361
//----------------------------------------------------------------------------------------------
sl@0
   362
void DeleteLargeFile(const TDesC& aFileName)
sl@0
   363
	{
sl@0
   364
	test.Next(_L("Delete large file"));
sl@0
   365
	test.Printf(_L("Deleting %S\n"), &aFileName);
sl@0
   366
sl@0
   367
	TInt r = TheFs.Delete(aFileName);
sl@0
   368
	test(r==KErrNone);
sl@0
   369
sl@0
   370
	CheckDisk();
sl@0
   371
	}
sl@0
   372
sl@0
   373
sl@0
   374
//----------------------------------------------------------------------------------------------
sl@0
   375
//! @SYMTestCaseID      PBASE-T_BIGFILE-0007
sl@0
   376
//! @SYMTestType        CIT
sl@0
   377
//! @SYMTestCaseDesc    Check that we can get a valid directory listing of a directory 
sl@0
   378
//!						containing large files using RDir and then CDir
sl@0
   379
//! @SYMTestActions     Open the directory using RDir and examine the results
sl@0
   380
//!						On windows, we could run chkdsk utility 
sl@0
   381
//! @SYMTestExpectedResults The expected number of files should exist with the correct sizes
sl@0
   382
//! @SYMTestPriority    High
sl@0
   383
//! @SYMTestStatus      Implemented
sl@0
   384
//----------------------------------------------------------------------------------------------
sl@0
   385
void ReadDirectory()
sl@0
   386
	{
sl@0
   387
	test.Next(_L("Read a directory containing large files using RDir"));
sl@0
   388
sl@0
   389
	RDir dir;
sl@0
   390
	TInt r = dir.Open(TheFs, _L("*.*"), KEntryAttNormal);
sl@0
   391
	test (r == KErrNone);
sl@0
   392
	
sl@0
   393
	TEntryArray entryArray;
sl@0
   394
	r = dir.Read(entryArray);
sl@0
   395
	test (r == KErrEof);
sl@0
   396
sl@0
   397
	test(entryArray.Count() == gFilesInDirectory);
sl@0
   398
sl@0
   399
	TInt n;
sl@0
   400
	for (n=0; n<entryArray.Count(); n++)
sl@0
   401
		{
sl@0
   402
		const TEntry& entry = entryArray[n];
sl@0
   403
		if (entry.iName.MatchF(KFile2GBMinusOne()) == 0)
sl@0
   404
			{
sl@0
   405
			test((TUint) entry.iSize == K2GbMinusOne);
sl@0
   406
			}
sl@0
   407
		else if (entry.iName.MatchF(KFile2GB()) == 0)
sl@0
   408
			{
sl@0
   409
			test((TUint) entry.iSize == K2Gb);
sl@0
   410
			}
sl@0
   411
		else if (entry.iName.MatchF(KFile3GB()) == 0)
sl@0
   412
			{
sl@0
   413
			test((TUint) entry.iSize == K3Gb);
sl@0
   414
			}
sl@0
   415
		else if (entry.iName.MatchF(KFile4GBMinusOne()) == 0)
sl@0
   416
			{
sl@0
   417
			test((TUint) entry.iSize == K4GbMinusOne);
sl@0
   418
			}
sl@0
   419
		else
sl@0
   420
			test(EFalse);
sl@0
   421
		}
sl@0
   422
sl@0
   423
	dir.Close();
sl@0
   424
sl@0
   425
	test.Next(_L("Read a directory containing large files using CDir & sort by size"));
sl@0
   426
	CDir* dirList;
sl@0
   427
	r=TheFs.GetDir(_L("*.*"), KEntryAttMaskSupported, ESortBySize, dirList);
sl@0
   428
	test(r==KErrNone);
sl@0
   429
	test(dirList->Count() == gFilesInDirectory);
sl@0
   430
	for (n=0; n<dirList->Count(); n++)
sl@0
   431
		{
sl@0
   432
		TEntry entry;
sl@0
   433
		entry=(*dirList)[n];
sl@0
   434
		// test.Printf(_L("#%d: %08X %d %S"), n, entry.iSize, entry.iSize, &entry.iName);
sl@0
   435
		if (entry.iName.MatchF(KFile2GBMinusOne()) == 0)
sl@0
   436
			{
sl@0
   437
			test((TUint) entry.iSize == K2GbMinusOne);
sl@0
   438
			test(n == 0);	// test entry has been sorted correctly (i.e. according to size)
sl@0
   439
			}
sl@0
   440
		else if (entry.iName.MatchF(KFile2GB()) == 0)
sl@0
   441
			{
sl@0
   442
			test((TUint) entry.iSize == K2Gb);
sl@0
   443
			test(n == 1);
sl@0
   444
			}
sl@0
   445
		else if (entry.iName.MatchF(KFile3GB()) == 0)
sl@0
   446
			{
sl@0
   447
			test((TUint) entry.iSize == K3Gb);
sl@0
   448
			test(n == 2);
sl@0
   449
			}
sl@0
   450
		else if (entry.iName.MatchF(KFile4GBMinusOne()) == 0)
sl@0
   451
			{
sl@0
   452
			test((TUint) entry.iSize == K4GbMinusOne);
sl@0
   453
			test(n == 3);
sl@0
   454
			}
sl@0
   455
		else
sl@0
   456
			test(EFalse);
sl@0
   457
		}
sl@0
   458
sl@0
   459
	delete dirList;
sl@0
   460
sl@0
   461
	
sl@0
   462
	}
sl@0
   463
sl@0
   464
//----------------------------------------------------------------------------------------------
sl@0
   465
//! @SYMTestCaseID      PBASE-T_BIGFILE-0008
sl@0
   466
//! @SYMTestType        CIT
sl@0
   467
//! @SYMTestCaseDesc    Check that we can a move a directory containing large files 
sl@0
   468
//!						Using CFileMan::Move()	
sl@0
   469
//! @SYMTestActions     Use CFileMan::Move() to move files from one directory to another
sl@0
   470
//! @SYMTestExpectedResults The files should be moved correctly
sl@0
   471
//! @SYMTestPriority    High
sl@0
   472
//! @SYMTestStatus      Implemented
sl@0
   473
//----------------------------------------------------------------------------------------------
sl@0
   474
void MoveDirectory()
sl@0
   475
	{
sl@0
   476
	test.Next(_L("Move a directory containing large files"));
sl@0
   477
sl@0
   478
	CFileMan* fileMan = CFileMan::NewL(TheFs);
sl@0
   479
	test(fileMan != NULL);
sl@0
   480
	
sl@0
   481
	TPath filePathOld = gSessionPath;
sl@0
   482
	filePathOld+= _L("*.*");
sl@0
   483
	TPath filePathNew =	_L("?:\\TEST\\");
sl@0
   484
	TChar driveLetter;
sl@0
   485
	TInt r=TheFs.DriveToChar(gDrive,driveLetter);
sl@0
   486
	test(r==KErrNone);
sl@0
   487
	filePathNew[0] = (TText) driveLetter;
sl@0
   488
sl@0
   489
	// move to new directory
sl@0
   490
	r = fileMan->Move(filePathOld, filePathNew, CFileMan::ERecurse | CFileMan::EOverWrite);
sl@0
   491
	test(r == KErrNone);
sl@0
   492
sl@0
   493
	// then move back again
sl@0
   494
	r = fileMan->Move(filePathNew, filePathOld);
sl@0
   495
	test(r == KErrNone);
sl@0
   496
sl@0
   497
	delete fileMan;
sl@0
   498
	}
sl@0
   499
sl@0
   500
sl@0
   501
//----------------------------------------------------------------------------------------------
sl@0
   502
//! @SYMTestCaseID      PBASE-T_BIGFILE-0009
sl@0
   503
//! @SYMTestType        CIT
sl@0
   504
//! @SYMTestCaseDesc    Check that we can copy a directory containing large file(s)
sl@0
   505
//!						Using CFileMan::Copy()	
sl@0
   506
//! @SYMTestActions     Use CFileMan::Copy() to copy files from one directory to another
sl@0
   507
//! @SYMTestExpectedResults The files should be copied correctly
sl@0
   508
//! @SYMTestPriority    High
sl@0
   509
//! @SYMTestStatus      Implemented
sl@0
   510
//----------------------------------------------------------------------------------------------
sl@0
   511
void CopyDirectory()
sl@0
   512
	{
sl@0
   513
	test.Next(_L("Copy a directory containing large files"));
sl@0
   514
	CFileMan* fileMan = CFileMan::NewL(TheFs);
sl@0
   515
	test(fileMan != NULL);
sl@0
   516
	
sl@0
   517
	CFileManObserver* observer = new CFileManObserver(fileMan);
sl@0
   518
	test(observer != NULL);
sl@0
   519
sl@0
   520
	TPath filePathOld = gSessionPath;
sl@0
   521
	filePathOld+= _L("*.*");
sl@0
   522
	TPath filePathNew =	_L("?:\\TEST\\");
sl@0
   523
	TChar driveLetter;
sl@0
   524
	TInt r = TheFs.DriveToChar(gDrive,driveLetter);
sl@0
   525
	test(r == KErrNone);
sl@0
   526
	filePathNew[0] = (TText) driveLetter;
sl@0
   527
sl@0
   528
	// create some small files in the source directory 
sl@0
   529
	// so that there is a combination of small files and one large files
sl@0
   530
	RFile file;
sl@0
   531
	_LIT(KFileSmall1, "FileSmallOne.txt");
sl@0
   532
	_LIT(KFileSmall2, "FileSmallTwo.txt");
sl@0
   533
	_LIT(KFileSmall3, "FileSmallThree.txt");
sl@0
   534
	r = file.Create(TheFs, KFileSmall1(), EFileWrite | EFileShareAny);
sl@0
   535
	test(r == KErrNone);
sl@0
   536
	r = file.Write(_L8("1"));
sl@0
   537
	test(r == KErrNone);
sl@0
   538
	file.Close();
sl@0
   539
sl@0
   540
	r = file.Create(TheFs, KFileSmall2(), EFileWrite | EFileShareAny);
sl@0
   541
	test(r == KErrNone);
sl@0
   542
	r = file.Write(_L8("12"));
sl@0
   543
	test(r == KErrNone);
sl@0
   544
	file.Close();
sl@0
   545
sl@0
   546
	r = file.Create(TheFs, KFileSmall3(), EFileWrite | EFileShareAny);
sl@0
   547
	test(r == KErrNone);
sl@0
   548
	r = file.Write(_L8("123"));
sl@0
   549
	test(r == KErrNone);
sl@0
   550
	file.Close();
sl@0
   551
sl@0
   552
	// copy to new directory
sl@0
   553
	r = fileMan->Copy(filePathOld, filePathNew, CFileMan::ERecurse | CFileMan::EOverWrite);
sl@0
   554
	test(r == KErrNone || r == KErrTooBig);
sl@0
   555
sl@0
   556
sl@0
   557
	// check SMALL files have been copied
sl@0
   558
	RDir dir;
sl@0
   559
	r = dir.Open(TheFs, filePathNew, KEntryAttNormal);
sl@0
   560
	test (r == KErrNone);
sl@0
   561
	TEntryArray entryArray;
sl@0
   562
	r = dir.Read(entryArray);
sl@0
   563
	test (r == KErrEof);
sl@0
   564
	test(entryArray.Count() == 3);
sl@0
   565
	dir.Close();
sl@0
   566
	
sl@0
   567
	// then delete the new directory
sl@0
   568
	r = fileMan->Delete(filePathNew);
sl@0
   569
	test(r == KErrNone);
sl@0
   570
sl@0
   571
	
sl@0
   572
	// attempt to copy to new directory again - this time with an observer
sl@0
   573
	fileMan->SetObserver(observer);
sl@0
   574
	r = fileMan->Copy(filePathOld, filePathNew, CFileMan::ERecurse | CFileMan::EOverWrite);
sl@0
   575
	test(r == KErrNone || r == KErrTooBig);
sl@0
   576
	
sl@0
   577
	// test that 3 small files were copied and 1 or 2 large files failed to copy
sl@0
   578
	// (For 8 GB disk, the 4GB file is missing)
sl@0
   579
	test(observer->iNotifyEndedSuccesses == 3);
sl@0
   580
	test(observer->iNotifyEndedFailures == 1 || observer->iNotifyEndedFailures == 2);
sl@0
   581
sl@0
   582
	// check SMALL files have been copied
sl@0
   583
	r = dir.Open(TheFs, filePathNew, KEntryAttNormal);
sl@0
   584
	test (r == KErrNone);
sl@0
   585
	r = dir.Read(entryArray);
sl@0
   586
	test (r == KErrEof);
sl@0
   587
	test(entryArray.Count() == 3);
sl@0
   588
	dir.Close();
sl@0
   589
	
sl@0
   590
	// then delete the new directory
sl@0
   591
	r = fileMan->Delete(filePathNew);
sl@0
   592
	test(r == KErrNone);
sl@0
   593
sl@0
   594
	delete observer;
sl@0
   595
	delete fileMan;
sl@0
   596
	}
sl@0
   597
sl@0
   598
sl@0
   599
//----------------------------------------------------------------------------------------------
sl@0
   600
//! @SYMTestCaseID      PBASE-T_BIGFILE-000A
sl@0
   601
//! @SYMTestType        CIT
sl@0
   602
//! @SYMTestCaseDesc    Check that CDirScan works correctly with a directory containing large file(s)
sl@0
   603
//! @SYMTestActions     Use CFileMan::Copy() to copy files from one directory to another
sl@0
   604
//! @SYMTestExpectedResults The files should be copied correctly
sl@0
   605
//! @SYMTestPriority    High
sl@0
   606
//! @SYMTestStatus      Implemented
sl@0
   607
//----------------------------------------------------------------------------------------------
sl@0
   608
TInt ScanDir(const TDesC& aName, CDirScan::TScanDirection aDirection, TInt aError)
sl@0
   609
	{
sl@0
   610
	TInt r;
sl@0
   611
	TFileName dirName;
sl@0
   612
sl@0
   613
	CDirScan* scanner = NULL;
sl@0
   614
	TRAP(r, scanner = CDirScan::NewL(TheFs));
sl@0
   615
	test(r == KErrNone && scanner);
sl@0
   616
sl@0
   617
	TRAP(r, scanner->SetScanDataL(aName,KEntryAttDir,ESortByName|EAscending,aDirection));
sl@0
   618
	test(r == KErrNone);
sl@0
   619
	
sl@0
   620
	CDir *entryList=NULL;
sl@0
   621
	TInt filesFound = 0;
sl@0
   622
	for (;;)
sl@0
   623
		{
sl@0
   624
		TRAP(r, scanner->NextL(entryList));
sl@0
   625
		test(r == aError);
sl@0
   626
		if (entryList==NULL)
sl@0
   627
			break;
sl@0
   628
		TInt count = entryList->Count();
sl@0
   629
		while (count--)
sl@0
   630
			{
sl@0
   631
			TEntry data=(*entryList)[count];
sl@0
   632
			TBuf<KMaxFileName> path=scanner->AbbreviatedPath();
sl@0
   633
			dirName = path;
sl@0
   634
			dirName.Append(data.iName);
sl@0
   635
			test.Printf(_L("    %S\n"),&dirName);
sl@0
   636
			filesFound++;
sl@0
   637
			}
sl@0
   638
sl@0
   639
		delete entryList;
sl@0
   640
		entryList=NULL;
sl@0
   641
		}
sl@0
   642
	delete scanner;
sl@0
   643
sl@0
   644
	return filesFound;
sl@0
   645
	}
sl@0
   646
sl@0
   647
sl@0
   648
sl@0
   649
GLDEF_C void CallTestsL()
sl@0
   650
//
sl@0
   651
// Do tests relative to the session path
sl@0
   652
//
sl@0
   653
	{
sl@0
   654
	
sl@0
   655
#if defined(__WINS__)
sl@0
   656
	if (gSessionPath[0]=='C')
sl@0
   657
		gNTFS=ETrue;
sl@0
   658
	else
sl@0
   659
		gNTFS=EFalse;
sl@0
   660
#endif
sl@0
   661
sl@0
   662
	// don't test on NTFS
sl@0
   663
	if (gNTFS)
sl@0
   664
		{
sl@0
   665
		test.Printf(_L("Skipping test: Drive is NTFS\n"));
sl@0
   666
		return;
sl@0
   667
		}
sl@0
   668
sl@0
   669
	TInt r;
sl@0
   670
sl@0
   671
	r = TheFs.CharToDrive(gDriveToTest, gDrive);
sl@0
   672
	test(r==KErrNone);
sl@0
   673
sl@0
   674
#ifdef __MOUNT_RAW_EXT__
sl@0
   675
	r=TheFs.FileSystemName(gOldFsName, gDrive);
sl@0
   676
	test(r==KErrNone);
sl@0
   677
sl@0
   678
	if (gOldFsName.CompareF(KFATName) != 0)
sl@0
   679
		{
sl@0
   680
		test.Printf(_L("Skipping test: Not a FAT drive\n"));
sl@0
   681
		return;
sl@0
   682
		}
sl@0
   683
sl@0
   684
    r = TheFs.AddExtension(KExtName);
sl@0
   685
    test(r==KErrNone || r==KErrAlreadyExists);
sl@0
   686
    r = TheFs.MountExtension(KExtName, gDrive);
sl@0
   687
    test(r==KErrNone || r==KErrAlreadyExists);
sl@0
   688
#endif
sl@0
   689
sl@0
   690
	TVolumeInfo vi;
sl@0
   691
	test((r = TheFs.Volume(vi, gDrive)) == KErrNone);
sl@0
   692
	test.Printf(_L("vi.iSize = %ld\n"), vi.iSize);
sl@0
   693
	
sl@0
   694
	// don't test if media sise is less than 7GB
sl@0
   695
	if (vi.iSize < TInt64(K1Gb) * TInt64(7))
sl@0
   696
		{
sl@0
   697
		test.Printf(_L("Skipping test: Drive is not big enough\n"));
sl@0
   698
		}
sl@0
   699
	if (!FilePresent(KFile2GB()))
sl@0
   700
		{
sl@0
   701
		test.Printf(_L("Skipping test: Test files not present on drive\n"));
sl@0
   702
		}
sl@0
   703
	else
sl@0
   704
		{
sl@0
   705
		gBuf = HBufC8::NewL(KBufSize);
sl@0
   706
		if (gBuf == NULL)
sl@0
   707
			User::Leave(KErrNoMemory);
sl@0
   708
		gBufPtr = gBuf->Des();
sl@0
   709
sl@0
   710
sl@0
   711
		TInt r;
sl@0
   712
sl@0
   713
		// Test that RFs::CheckDisk() succeeds with large files present
sl@0
   714
		CheckDisk();
sl@0
   715
		
sl@0
   716
		test.Next(_L("Scan Drive"));
sl@0
   717
		r = TheFs.ScanDrive(gSessionPath);
sl@0
   718
		test (r == KErrNone);
sl@0
   719
sl@0
   720
		// NB the 4GB file will not be present unless the disk is > 8GB (because it doesn't fit)
sl@0
   721
		if (!FilePresent(KFile4GBMinusOne()))
sl@0
   722
			gFilesInDirectory--;
sl@0
   723
sl@0
   724
		// test CDirScan
sl@0
   725
		// the number of files & directories found should be 5 or 4
sl@0
   726
		TInt filesFound = ScanDir(_L("\\"), CDirScan::EScanUpTree, KErrNone);
sl@0
   727
		test (filesFound == gFilesInDirectory+1);
sl@0
   728
		filesFound = ScanDir(_L("\\"), CDirScan::EScanDownTree, KErrNone);
sl@0
   729
		test (filesFound == gFilesInDirectory+1);
sl@0
   730
sl@0
   731
		OpenAndRead2GBMinusOne();
sl@0
   732
		Open2GB();
sl@0
   733
		Open3GB();
sl@0
   734
sl@0
   735
		// the 4GB file will not be present unless the disk is > 8GB
sl@0
   736
		if (FilePresent(KFile4GBMinusOne()))
sl@0
   737
			Open4GB();
sl@0
   738
sl@0
   739
		Extend2GBMinusOne();
sl@0
   740
sl@0
   741
		ReadDirectory();
sl@0
   742
sl@0
   743
		MoveDirectory();
sl@0
   744
sl@0
   745
		
sl@0
   746
		// delete the 2 smaller files to make some space
sl@0
   747
		DeleteLargeFile(KFile2GB());
sl@0
   748
		DeleteLargeFile(KFile2GBMinusOne());
sl@0
   749
		
sl@0
   750
		CopyDirectory();
sl@0
   751
		
sl@0
   752
		// delete the 3GB file and check the disk
sl@0
   753
		DeleteLargeFile(KFile3GB());
sl@0
   754
sl@0
   755
		if (FilePresent(KFile4GBMinusOne()))
sl@0
   756
			DeleteLargeFile(KFile4GBMinusOne());
sl@0
   757
sl@0
   758
		// Finally check that we can format the drive...
sl@0
   759
		Format (gDrive);
sl@0
   760
		}
sl@0
   761
sl@0
   762
#ifdef __MOUNT_RAW_EXT__
sl@0
   763
	r = TheFs.DismountExtension(KExtName, gDrive);
sl@0
   764
	test(r==KErrNone);
sl@0
   765
sl@0
   766
	r = TheFs.RemoveExtension(KExtName);
sl@0
   767
	test(r==KErrNone);
sl@0
   768
sl@0
   769
#endif
sl@0
   770
sl@0
   771
	delete gBuf; gBuf = NULL;
sl@0
   772
	}
sl@0
   773