os/kernelhwsrv/kerneltest/f32test/concur/t_cfsmain.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 1997-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
// Based on t_main.cpp as used for other tests.
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
//! @file f32test\concur\t_cfsmain.cpp
sl@0
    19
sl@0
    20
#include <f32file.h>
sl@0
    21
#include <e32test.h>
sl@0
    22
#include <e32hal.h>
sl@0
    23
#include <e32math.h>
sl@0
    24
#include <f32dbg.h>
sl@0
    25
sl@0
    26
#include "t_server.h"
sl@0
    27
#include "cfafsdlyif.h"
sl@0
    28
sl@0
    29
GLDEF_D	RFs TheFs;
sl@0
    30
GLDEF_D TFileName gSessionPath;
sl@0
    31
GLDEF_D TInt gAllocFailOff=KAllocFailureOff;
sl@0
    32
GLDEF_D TInt gAllocFailOn=KAllocFailureOff;
sl@0
    33
GLDEF_D TInt64 gSeed=51703;
sl@0
    34
sl@0
    35
GLDEF_D TChar   gDriveToTest;
sl@0
    36
GLDEF_D TUint32 gDebugFlags = 0;
sl@0
    37
sl@0
    38
GLDEF_D TPtrC gArgV[128];
sl@0
    39
GLDEF_D TInt  gArgC = 0;
sl@0
    40
sl@0
    41
LOCAL_D TTestType TheTestType=ENotifierNone;
sl@0
    42
LOCAL_D RSemaphore ControlIoSem;
sl@0
    43
sl@0
    44
TMediaPassword thePassword=_L8("abc");
sl@0
    45
sl@0
    46
enum TTestCode {ESimLockRemMed, EClearSimLockRemMed};
sl@0
    47
sl@0
    48
const TInt KControlIoRemMedLock=5;						//setflag
sl@0
    49
const TInt KControlClearMedLock=6;						//clears flag
sl@0
    50
const TInt KControIoRemMedRepeat=9;
sl@0
    51
sl@0
    52
_LIT(KNotifierHang,"Hang");
sl@0
    53
_LIT(KNotifierRepeat,"Repeat");
sl@0
    54
_LIT(KNotifierWithRepeat,"WithRepeat");	
sl@0
    55
_LIT(KPrivate, "\\Private\\");
sl@0
    56
sl@0
    57
GLDEF_C TBool IsTestTypeNotifyHang()
sl@0
    58
//
sl@0
    59
//
sl@0
    60
//
sl@0
    61
	{
sl@0
    62
	return(TheTestType==ENotifierHang);
sl@0
    63
	}
sl@0
    64
sl@0
    65
GLDEF_C TBool IsTestTypeNotifyRepeat()
sl@0
    66
//
sl@0
    67
//
sl@0
    68
//
sl@0
    69
	{
sl@0
    70
	return(TheTestType==ENotifierRepeat);
sl@0
    71
	}
sl@0
    72
sl@0
    73
GLDEF_C TBool IsTestTypeNotifyWithRepeat()
sl@0
    74
//
sl@0
    75
//
sl@0
    76
//
sl@0
    77
	{
sl@0
    78
	return(TheTestType==ENotifierWithRepeat);
sl@0
    79
	}
sl@0
    80
sl@0
    81
sl@0
    82
GLDEF_C TBool IsTestTypeStandard()
sl@0
    83
//
sl@0
    84
//
sl@0
    85
//
sl@0
    86
	{
sl@0
    87
	return(TheTestType==ENotifierNone);
sl@0
    88
	}
sl@0
    89
sl@0
    90
GLDEF_C TTestType TestType()
sl@0
    91
//
sl@0
    92
//
sl@0
    93
//
sl@0
    94
	{
sl@0
    95
	return(TheTestType);
sl@0
    96
	}
sl@0
    97
sl@0
    98
GLDEF_C void CreateShortName(TDes& aFileName,TInt64& aSeed)
sl@0
    99
//
sl@0
   100
// Create a random, dos legal 8.3 char name
sl@0
   101
//
sl@0
   102
	{
sl@0
   103
sl@0
   104
	TInt length=Math::Rand(aSeed)%11;
sl@0
   105
	if (length==0)
sl@0
   106
		length=1;
sl@0
   107
	else if (length==3)	// don't create three letter names like 'AUX' or 'PRN'
sl@0
   108
		length++;
sl@0
   109
	else if (length>8)	// end in '.' if no extension
sl@0
   110
		length++;
sl@0
   111
sl@0
   112
	aFileName.SetLength(length);
sl@0
   113
	for(TInt i=0;i<length;i++)
sl@0
   114
		{
sl@0
   115
		if (i==9)
sl@0
   116
			{
sl@0
   117
			aFileName[i]='.';
sl@0
   118
			continue;
sl@0
   119
			}
sl@0
   120
		TInt letter=Math::Rand(aSeed)%26;
sl@0
   121
		aFileName[i]=(TText)('A'+letter);
sl@0
   122
		}
sl@0
   123
	}
sl@0
   124
sl@0
   125
_LIT(KFatName,"Fat");
sl@0
   126
GLDEF_C TBool IsFileSystemFAT(RFs &aFsSession,TInt aDrive)
sl@0
   127
//
sl@0
   128
// return true if fat on aDrive
sl@0
   129
//
sl@0
   130
	{
sl@0
   131
	TFileName f;
sl@0
   132
	TInt r=aFsSession.FileSystemName(f,aDrive);
sl@0
   133
	test(r==KErrNone || r==KErrNotFound);
sl@0
   134
	return (f.CompareF(KFatName)==0);
sl@0
   135
	}
sl@0
   136
sl@0
   137
GLDEF_C void CreateLongName(TDes& aFileName,TInt64& aSeed,TInt aLength)
sl@0
   138
//
sl@0
   139
// Create a random, dos legal 8.3 char name
sl@0
   140
//
sl@0
   141
	{
sl@0
   142
sl@0
   143
	TInt length;
sl@0
   144
	if (aLength>0)
sl@0
   145
		length=aLength;
sl@0
   146
	else
sl@0
   147
		{
sl@0
   148
		length=Math::Rand(aSeed)%128;
sl@0
   149
		length+=Math::Rand(aSeed)%128;
sl@0
   150
		length+=Math::Rand(aSeed)%128;
sl@0
   151
		length+=Math::Rand(aSeed)%128;
sl@0
   152
		length-=256;
sl@0
   153
			length=Abs(length);
sl@0
   154
		if (length==0)
sl@0
   155
			length=1;
sl@0
   156
		if (length>220)
sl@0
   157
			length=31;
sl@0
   158
		}
sl@0
   159
	if (length==3)	// don't create three letter names like 'AUX' or 'PRN'
sl@0
   160
		length++;
sl@0
   161
sl@0
   162
	aFileName.SetLength(length);
sl@0
   163
	TInt spaceChar=-1;
sl@0
   164
	TInt i;
sl@0
   165
	for(i=0;i<length;i++)
sl@0
   166
		{
sl@0
   167
StartAgain:
sl@0
   168
		TChar letter=0;
sl@0
   169
		TBool illegalChar=ETrue;
sl@0
   170
sl@0
   171
		while(illegalChar)
sl@0
   172
			{
sl@0
   173
#if defined(__WINS__)
sl@0
   174
			if (gSessionPath[0]=='C')
sl@0
   175
				letter=(TChar)('A'+Math::Rand(aSeed)%26);
sl@0
   176
			else
sl@0
   177
				letter=(TChar)Math::Rand(aSeed)%256;
sl@0
   178
#else
sl@0
   179
			letter=(TChar)Math::Rand(aSeed)%256;
sl@0
   180
#endif
sl@0
   181
			TBool space=letter.IsSpace();
sl@0
   182
			if (space && spaceChar==-1)
sl@0
   183
				spaceChar=i;
sl@0
   184
			else if (!space && spaceChar!=-1)
sl@0
   185
				spaceChar=-1;
sl@0
   186
sl@0
   187
			switch(letter)
sl@0
   188
				{
sl@0
   189
			case '<':
sl@0
   190
			case '>':
sl@0
   191
			case ':':
sl@0
   192
			case '"':
sl@0
   193
			case '/':
sl@0
   194
			case '|':
sl@0
   195
			case '*':
sl@0
   196
			case '?':
sl@0
   197
			case '\\':
sl@0
   198
			case '\0':
sl@0
   199
				break;
sl@0
   200
			default:
sl@0
   201
				illegalChar=EFalse;
sl@0
   202
				};
sl@0
   203
			}
sl@0
   204
		aFileName[i]=(TText)letter;
sl@0
   205
		}
sl@0
   206
sl@0
   207
	if (spaceChar!=-1)
sl@0
   208
		{
sl@0
   209
		i=spaceChar;
sl@0
   210
		goto StartAgain;
sl@0
   211
		}
sl@0
   212
	}
sl@0
   213
sl@0
   214
GLDEF_C void CheckEntry(const TDesC& aName,TUint anAttributes,const TTime& aModified)
sl@0
   215
//
sl@0
   216
// Checks the values associated with an entry
sl@0
   217
//
sl@0
   218
	{
sl@0
   219
sl@0
   220
	TEntry entry;
sl@0
   221
	TInt r=TheFs.Entry(aName,entry);
sl@0
   222
	test(r==KErrNone);
sl@0
   223
	test(entry.iAtt==anAttributes);
sl@0
   224
	if (aModified!=TTime(0))
sl@0
   225
		test(entry.iModified==aModified);
sl@0
   226
	}
sl@0
   227
sl@0
   228
GLDEF_C void CheckDisk()
sl@0
   229
//
sl@0
   230
// Do a checkdisk and report failure
sl@0
   231
//
sl@0
   232
	{
sl@0
   233
	test.Next(_L("Check Disk"));
sl@0
   234
	TInt r=TheFs.CheckDisk(gSessionPath);
sl@0
   235
	if (r!=KErrNone && r!=KErrNotSupported && r!=KErrPermissionDenied)
sl@0
   236
		ReportCheckDiskFailure(r);
sl@0
   237
	}
sl@0
   238
sl@0
   239
GLDEF_C void ReportCheckDiskFailure(TInt aRet)
sl@0
   240
//
sl@0
   241
// Report the failure of checkdisk
sl@0
   242
//
sl@0
   243
	{
sl@0
   244
sl@0
   245
	test.Printf(_L("CHECKDISK FAILED: "));
sl@0
   246
	switch(aRet)
sl@0
   247
		{
sl@0
   248
	case 1:	test.Printf(_L("File cluster chain contains a bad value (<2 or >maxCluster)\n")); break;
sl@0
   249
	case 2:	test.Printf(_L("Two files are linked to the same cluster\n")); break;
sl@0
   250
	case 3:	test.Printf(_L("Unallocated cluster contains a value != 0\n"));	break;
sl@0
   251
	case 4:	test.Printf(_L("Size of file != number of clusters in chain\n")); break;
sl@0
   252
	default: test.Printf(_L("Undefined Error value %d\n"),aRet);
sl@0
   253
		}
sl@0
   254
	test(EFalse);
sl@0
   255
	}
sl@0
   256
sl@0
   257
GLDEF_C void TurnAllocFailureOff()
sl@0
   258
//
sl@0
   259
// Switch off all allocFailure
sl@0
   260
//
sl@0
   261
	{
sl@0
   262
sl@0
   263
	test.Printf(_L("Disable Alloc Failure\n"));
sl@0
   264
	TheFs.SetAllocFailure(gAllocFailOff);
sl@0
   265
	gAllocFailOn=KAllocFailureOff; // Disable gAllocFailOn
sl@0
   266
	}
sl@0
   267
sl@0
   268
GLDEF_C void TurnAllocFailureOn()
sl@0
   269
//
sl@0
   270
// Switch off all allocFailure
sl@0
   271
//
sl@0
   272
	{
sl@0
   273
sl@0
   274
	test.Printf(_L("Enable Alloc Failure\n"));
sl@0
   275
	gAllocFailOn=KAllocFailureOn; // Enable gAllocFailOn
sl@0
   276
	TheFs.SetAllocFailure(gAllocFailOn);
sl@0
   277
	}
sl@0
   278
sl@0
   279
GLDEF_C void MakeFile(const TDesC& aFileName,const TUidType& aUidType,const TDesC8& aFileContents)
sl@0
   280
//
sl@0
   281
// Make a file and write uid and data
sl@0
   282
//
sl@0
   283
	{
sl@0
   284
sl@0
   285
	RFile file;
sl@0
   286
	TInt r=file.Replace(TheFs,aFileName,0);
sl@0
   287
	test(r==KErrNone || r==KErrPathNotFound);
sl@0
   288
	if (r==KErrPathNotFound)
sl@0
   289
		{
sl@0
   290
		r=TheFs.MkDirAll(aFileName);
sl@0
   291
		test(r==KErrNone);
sl@0
   292
		r=file.Replace(TheFs,aFileName,0);
sl@0
   293
		test(r==KErrNone);
sl@0
   294
		}
sl@0
   295
	TCheckedUid checkedUid(aUidType);
sl@0
   296
	TPtrC8 uidData((TUint8*)&checkedUid,sizeof(TCheckedUid));
sl@0
   297
	r=file.Write(uidData);
sl@0
   298
	test(r==KErrNone);
sl@0
   299
	r=file.Write(aFileContents);
sl@0
   300
	test(r==KErrNone);
sl@0
   301
	file.Close();
sl@0
   302
	}
sl@0
   303
sl@0
   304
GLDEF_C void MakeFile(const TDesC& aFileName,const TDesC8& aFileContents)
sl@0
   305
//
sl@0
   306
// Make a file and write something in it
sl@0
   307
//
sl@0
   308
	{
sl@0
   309
sl@0
   310
	RFile file;
sl@0
   311
	TInt r=file.Replace(TheFs,aFileName,0);
sl@0
   312
	if(r!=KErrNone && r!=KErrPathNotFound)
sl@0
   313
		{
sl@0
   314
		test.Printf(_L("ERROR: r=%d"),r);
sl@0
   315
		test(EFalse);
sl@0
   316
		}
sl@0
   317
	test(r==KErrNone || r==KErrPathNotFound);
sl@0
   318
	if (r==KErrPathNotFound)
sl@0
   319
		{
sl@0
   320
		r=TheFs.MkDirAll(aFileName);
sl@0
   321
		test(r==KErrNone);
sl@0
   322
		r=file.Replace(TheFs,aFileName,0);
sl@0
   323
		test(r==KErrNone);
sl@0
   324
		}
sl@0
   325
	r=file.Write(aFileContents);
sl@0
   326
	test(r==KErrNone);
sl@0
   327
	file.Close();
sl@0
   328
	}
sl@0
   329
sl@0
   330
GLDEF_C void MakeFile(const TDesC& aFileName,TInt anAttributes)
sl@0
   331
//
sl@0
   332
// Make a file and write something in it
sl@0
   333
//
sl@0
   334
	{
sl@0
   335
sl@0
   336
	RFile file;
sl@0
   337
	TInt r=file.Replace(TheFs,aFileName,0);
sl@0
   338
	test(r==KErrNone || r==KErrPathNotFound);
sl@0
   339
	if (r==KErrPathNotFound)
sl@0
   340
		{
sl@0
   341
		r=TheFs.MkDirAll(aFileName);
sl@0
   342
		test(r==KErrNone);
sl@0
   343
		r=file.Replace(TheFs,aFileName,0);
sl@0
   344
		test(r==KErrNone);
sl@0
   345
		}
sl@0
   346
	file.Close();
sl@0
   347
	r=TheFs.SetAtt(aFileName,anAttributes,0);
sl@0
   348
	test(r==KErrNone);
sl@0
   349
	}
sl@0
   350
sl@0
   351
GLDEF_C void SetSessionPath(const TDesC& aPathName)
sl@0
   352
//
sl@0
   353
// Set the session path and update gSessionPath
sl@0
   354
//
sl@0
   355
	{
sl@0
   356
sl@0
   357
	TInt r=TheFs.SetSessionPath(aPathName);
sl@0
   358
	test(r==KErrNone);
sl@0
   359
	r=TheFs.SessionPath(gSessionPath);
sl@0
   360
	test(r==KErrNone);
sl@0
   361
	}
sl@0
   362
sl@0
   363
GLDEF_C void MakeFile(const TDesC& aFileName)
sl@0
   364
//
sl@0
   365
// Make a file
sl@0
   366
//
sl@0
   367
	{
sl@0
   368
	
sl@0
   369
	MakeFile(aFileName,_L8(""));
sl@0
   370
	}
sl@0
   371
sl@0
   372
GLDEF_C void MakeDir(const TDesC& aDirName)
sl@0
   373
//
sl@0
   374
// Make a directory
sl@0
   375
//
sl@0
   376
	{
sl@0
   377
sl@0
   378
	TInt r=TheFs.MkDirAll(aDirName);
sl@0
   379
	test(r==KErrNone || r==KErrAlreadyExists);
sl@0
   380
	}
sl@0
   381
sl@0
   382
GLDEF_C TInt CheckFileExists(const TDesC& aName,TInt aResult,TBool aCompRes/*=ETrue*/)
sl@0
   383
//
sl@0
   384
// Check aName exists
sl@0
   385
//
sl@0
   386
	{
sl@0
   387
sl@0
   388
	TEntry entry;
sl@0
   389
	TInt r=TheFs.Entry(aName,entry);
sl@0
   390
	test(r==aResult);
sl@0
   391
	if (aResult!=KErrNone)
sl@0
   392
		return(0);
sl@0
   393
	TParsePtrC nameParse(aName);
sl@0
   394
	TParsePtrC entryParse(entry.iName);
sl@0
   395
	TBool nameMatch=(entryParse.Name()==nameParse.Name());
sl@0
   396
	TBool extMatch=(entryParse.Ext()==nameParse.Ext()) || (entryParse.Ext().Length()<=1 && nameParse.Ext().Length()<=1);
sl@0
   397
	test((nameMatch && extMatch)==aCompRes);
sl@0
   398
	return(entry.iSize);
sl@0
   399
	}
sl@0
   400
sl@0
   401
GLDEF_C void CheckFileContents(const TDesC& aName,const TDesC8& aContents)
sl@0
   402
//
sl@0
   403
// Check contents of file
sl@0
   404
//
sl@0
   405
	{
sl@0
   406
sl@0
   407
	RFile f;
sl@0
   408
	TInt r=f.Open(TheFs,aName,EFileRead);
sl@0
   409
	test(r==KErrNone);
sl@0
   410
	HBufC8* testBuf=HBufC8::NewL(aContents.Length());
sl@0
   411
	test(testBuf!=NULL);
sl@0
   412
	TPtr8 bufPtr(testBuf->Des());
sl@0
   413
	r=f.Read(bufPtr);
sl@0
   414
	test(r==KErrNone);
sl@0
   415
	test(bufPtr==aContents);
sl@0
   416
	r=f.Read(bufPtr);
sl@0
   417
	test(r==KErrNone);
sl@0
   418
	test(bufPtr.Length()==0);
sl@0
   419
	f.Close();
sl@0
   420
	User::Free(testBuf);
sl@0
   421
	}
sl@0
   422
sl@0
   423
GLDEF_C void DeleteTestDirectory()
sl@0
   424
//
sl@0
   425
// Delete the leaf session path directory
sl@0
   426
//
sl@0
   427
	{
sl@0
   428
sl@0
   429
	TheFs.SetAtt(_L("\\F32-TST\\SCANTEST\\Left\\Dir3\\Dir4\\Hidden"), 0, KEntryAttHidden);
sl@0
   430
	TheFs.SetAtt(_L("\\F32-TST\\SCANTEST\\Left\\Dir3\\Dir4\\Hidden\\HiddenFile"), 0, KEntryAttHidden);
sl@0
   431
	TheFs.SetAtt(_L("\\F32-TST\\SCANTEST\\Left\\Dir3\\Dir4\\Hidden\\System"), 0, KEntryAttSystem);
sl@0
   432
	test.Next(_L("Delete test directory"));
sl@0
   433
	CFileMan* fMan=CFileMan::NewL(TheFs);
sl@0
   434
	test(fMan!=NULL);
sl@0
   435
	TInt r=TheFs.SessionPath(gSessionPath);
sl@0
   436
	test(r==KErrNone);
sl@0
   437
	r=TheFs.CheckDisk(gSessionPath);
sl@0
   438
	if (r!=KErrNone && r!=KErrNotSupported)
sl@0
   439
		ReportCheckDiskFailure(r);
sl@0
   440
	r=fMan->RmDir(gSessionPath);
sl@0
   441
	test(r==KErrNone);
sl@0
   442
	delete fMan;
sl@0
   443
	}
sl@0
   444
sl@0
   445
GLDEF_C void CreateTestDirectory(const TDesC& aSessionPath)
sl@0
   446
//
sl@0
   447
// Create directory for test
sl@0
   448
//
sl@0
   449
	{
sl@0
   450
	TParsePtrC path(aSessionPath);
sl@0
   451
	test(path.DrivePresent()==EFalse);
sl@0
   452
sl@0
   453
	TInt r=TheFs.SetSessionPath(aSessionPath);
sl@0
   454
	test(r==KErrNone);
sl@0
   455
	r=TheFs.SessionPath(gSessionPath);
sl@0
   456
	test(r==KErrNone);
sl@0
   457
	r=TheFs.MkDirAll(gSessionPath);
sl@0
   458
	test(r==KErrNone || r==KErrAlreadyExists);
sl@0
   459
	}
sl@0
   460
sl@0
   461
GLDEF_C TInt CurrentDrive()
sl@0
   462
//
sl@0
   463
// Return the current drive number
sl@0
   464
//
sl@0
   465
	{
sl@0
   466
sl@0
   467
	TInt driveNum;
sl@0
   468
	TInt r=TheFs.CharToDrive(gSessionPath[0],driveNum);
sl@0
   469
	test(r==KErrNone);
sl@0
   470
	return(driveNum);
sl@0
   471
	}
sl@0
   472
sl@0
   473
GLDEF_C void Format(TInt aDrive)
sl@0
   474
//
sl@0
   475
// Format current drive
sl@0
   476
//
sl@0
   477
	{
sl@0
   478
sl@0
   479
	test.Next(_L("Format"));
sl@0
   480
	TBuf<4> driveBuf=_L("?:\\");
sl@0
   481
	driveBuf[0]=(TText)(aDrive+'A');
sl@0
   482
	RFormat format;
sl@0
   483
	TInt count;
sl@0
   484
	TInt r=format.Open(TheFs,driveBuf,EHighDensity,count);
sl@0
   485
	test(r==KErrNone);
sl@0
   486
	while(count)
sl@0
   487
		{
sl@0
   488
		TInt r=format.Next(count);
sl@0
   489
		test(r==KErrNone);
sl@0
   490
		}
sl@0
   491
	format.Close();
sl@0
   492
	}
sl@0
   493
sl@0
   494
LOCAL_C void PushLotsL()
sl@0
   495
//
sl@0
   496
// Expand the cleanup stack
sl@0
   497
//
sl@0
   498
	{
sl@0
   499
	TInt i;
sl@0
   500
	for(i=0;i<1000;i++)
sl@0
   501
		CleanupStack::PushL((CBase*)NULL);
sl@0
   502
	CleanupStack::Pop(1000);
sl@0
   503
	}
sl@0
   504
sl@0
   505
sl@0
   506
LOCAL_C void DoTests(TInt aDrive)
sl@0
   507
//
sl@0
   508
// Do testing on aDrive
sl@0
   509
//
sl@0
   510
	{
sl@0
   511
sl@0
   512
	gSessionPath=_L("?:\\F32-TST\\");
sl@0
   513
	TChar driveLetter;
sl@0
   514
	TInt r=TheFs.DriveToChar(aDrive,driveLetter);
sl@0
   515
	test(r==KErrNone);
sl@0
   516
	gSessionPath[0]=(TText)driveLetter;
sl@0
   517
	r=TheFs.SetSessionPath(gSessionPath);
sl@0
   518
	test(r==KErrNone);
sl@0
   519
sl@0
   520
// !!! Disable platform security tests until we get the new APIs
sl@0
   521
//	if(User::Capability() & KCapabilityRoot)
sl@0
   522
//		CheckMountLFFS(TheFs,driveLetter);
sl@0
   523
sl@0
   524
	r=TheFs.MkDirAll(gSessionPath);
sl@0
   525
	TheFs.ResourceCountMarkStart();
sl@0
   526
sl@0
   527
	TRAP(r,CallTestsL());
sl@0
   528
	
sl@0
   529
	if (r==KErrNone)
sl@0
   530
		TheFs.ResourceCountMarkEnd();
sl@0
   531
	else
sl@0
   532
		{
sl@0
   533
		test.Printf(_L("Error: Leave %d\n"),r);
sl@0
   534
		test(EFalse);
sl@0
   535
		}
sl@0
   536
sl@0
   537
	TestingLFFS(EFalse);
sl@0
   538
	}
sl@0
   539
sl@0
   540
void ParseCommandArguments()
sl@0
   541
//
sl@0
   542
// Parse command line.  Put the parameters into global array gArgv for
sl@0
   543
// use by the tests, strip out flags starting with / or - and interpret
sl@0
   544
// them to set debug flags.
sl@0
   545
//
sl@0
   546
	{
sl@0
   547
	LOCAL_D TBuf<0x100> cmd;
sl@0
   548
	User::CommandLine(cmd);
sl@0
   549
	TLex lex(cmd);
sl@0
   550
	TPtrC token=lex.NextToken();
sl@0
   551
	TFileName thisfile=RProcess().FileName();
sl@0
   552
	if (token.MatchF(thisfile)==0)
sl@0
   553
		{
sl@0
   554
		token.Set(lex.NextToken());
sl@0
   555
		}
sl@0
   556
	// set up parameter list (offset zero is the filename)
sl@0
   557
	gArgC = 0;
sl@0
   558
	gArgV[gArgC++].Set(thisfile);
sl@0
   559
	while (token.Length() != 0)
sl@0
   560
		{
sl@0
   561
		TChar ch = token[0];
sl@0
   562
		// strip out (and interpret) flags starting with - or /
sl@0
   563
		if (ch == '-' || ch == '/')
sl@0
   564
			{
sl@0
   565
			for (TInt i = 1; i < token.Length(); i++)
sl@0
   566
				{
sl@0
   567
				switch (User::UpperCase(token[i]))
sl@0
   568
					{
sl@0
   569
					case 'D':
sl@0
   570
						gDebugFlags |= KDLYFAST;
sl@0
   571
						break;
sl@0
   572
					case 'F':
sl@0
   573
						gDebugFlags |= KFSYS;
sl@0
   574
						break;
sl@0
   575
					case 'I':
sl@0
   576
						gDebugFlags |= KISO9660;
sl@0
   577
						break;
sl@0
   578
					case 'L':
sl@0
   579
						gDebugFlags |= KFLDR;
sl@0
   580
						break;
sl@0
   581
#ifdef __CONCURRENT_FILE_ACCESS__
sl@0
   582
					case 'M':
sl@0
   583
						gDebugFlags |= KTHRD;
sl@0
   584
						break;
sl@0
   585
#endif
sl@0
   586
					case 'N':
sl@0
   587
						gDebugFlags |= KNTFS;
sl@0
   588
						break;
sl@0
   589
					case 'S':
sl@0
   590
						gDebugFlags |= KFSERV;
sl@0
   591
						break;
sl@0
   592
					case 'T':
sl@0
   593
						gDebugFlags |= KLFFS;
sl@0
   594
						break;
sl@0
   595
					case 'Y':
sl@0
   596
						gDebugFlags |= KDLYTRC;
sl@0
   597
						break;
sl@0
   598
					}
sl@0
   599
				}
sl@0
   600
			}
sl@0
   601
		else
sl@0
   602
			gArgV[gArgC++].Set(token);
sl@0
   603
		token.Set(lex.NextToken());
sl@0
   604
		}
sl@0
   605
sl@0
   606
	// set up drive to test
sl@0
   607
	gDriveToTest = 'C';
sl@0
   608
	if (gArgC > 1)
sl@0
   609
		{
sl@0
   610
		gDriveToTest = gArgV[1][0];
sl@0
   611
		gDriveToTest.UpperCase();
sl@0
   612
		}
sl@0
   613
	}
sl@0
   614
sl@0
   615
sl@0
   616
GLDEF_C TInt E32Main()
sl@0
   617
    {
sl@0
   618
	CTrapCleanup* cleanup;
sl@0
   619
	cleanup=CTrapCleanup::New();
sl@0
   620
	TRAPD(r,PushLotsL());
sl@0
   621
	__UHEAP_MARK;
sl@0
   622
sl@0
   623
	test.Title();
sl@0
   624
	test.Start(_L("Starting tests..."));
sl@0
   625
sl@0
   626
	r=TheFs.Connect();
sl@0
   627
	test(r==KErrNone);
sl@0
   628
sl@0
   629
	ParseCommandArguments(); //need this for drive letter to test
sl@0
   630
sl@0
   631
	TheFs.SetAllocFailure(gAllocFailOn);
sl@0
   632
	TTime timerC;
sl@0
   633
	timerC.HomeTime();
sl@0
   634
	TFileName sessionp;
sl@0
   635
	TheFs.SessionPath(sessionp);
sl@0
   636
sl@0
   637
	TBuf<30> privatedir;
sl@0
   638
	privatedir = KPrivate;
sl@0
   639
sl@0
   640
	TUid thisUID = RProcess().Identity();
sl@0
   641
	privatedir.AppendFormat(_L("%08x"),thisUID.iUid);
sl@0
   642
	privatedir.Append(_L("\\"));
sl@0
   643
sl@0
   644
	test(privatedir == sessionp.Mid(2,sessionp.Length()-2));
sl@0
   645
sl@0
   646
	test.Printf(_L("sp=%S"),&sessionp);
sl@0
   647
	sessionp[0]=(TText)gDriveToTest;
sl@0
   648
	test.Printf(_L("sp1=%S"),&sessionp);
sl@0
   649
sl@0
   650
	TInt theDrive;
sl@0
   651
	r=TheFs.CharToDrive(gDriveToTest,theDrive);
sl@0
   652
	test(r==KErrNone);
sl@0
   653
	
sl@0
   654
	// set up debug register
sl@0
   655
	test.Printf(_L("debug register = 0x%X"), gDebugFlags);
sl@0
   656
	TheFs.SetDebugRegister(gDebugFlags);
sl@0
   657
sl@0
   658
	// actually do the tests!
sl@0
   659
	DoTests(theDrive);
sl@0
   660
	
sl@0
   661
	// reset the debug register
sl@0
   662
	TheFs.SetDebugRegister(0);
sl@0
   663
sl@0
   664
	TTime endTimeC;
sl@0
   665
	endTimeC.HomeTime();
sl@0
   666
	TTimeIntervalSeconds timeTakenC;
sl@0
   667
	r=endTimeC.SecondsFrom(timerC,timeTakenC);
sl@0
   668
	test(r==KErrNone);
sl@0
   669
	test.Printf(_L("Time taken for test = %d seconds\n"),timeTakenC);
sl@0
   670
	TheFs.SetAllocFailure(gAllocFailOff);
sl@0
   671
	TheFs.Close();
sl@0
   672
	test.End();
sl@0
   673
	test.Close();
sl@0
   674
	__UHEAP_MARKEND;
sl@0
   675
	delete cleanup;
sl@0
   676
	return(KErrNone);
sl@0
   677
    }