os/kernelhwsrv/kerneltest/f32test/server/t_localtime.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
// Implementation of the t_localtime test. This tests functionality introduced
sl@0
    15
// in CR1084 ie. That removable (in practice this means FAT) file systems
sl@0
    16
// can be made to use local time for timestamps.
sl@0
    17
// 
sl@0
    18
//
sl@0
    19
sl@0
    20
/**
sl@0
    21
 @file
sl@0
    22
 @test
sl@0
    23
*/
sl@0
    24
#define __E32TEST_EXTENSION__
sl@0
    25
#include <e32test.h>
sl@0
    26
sl@0
    27
#include "t_localtime.h"
sl@0
    28
#include "t_server.h"
sl@0
    29
sl@0
    30
RTest test(KTestGroupName);
sl@0
    31
sl@0
    32
/**
sl@0
    33
Constructor for generic test.
sl@0
    34
@param aTest The RTest handle to use.
sl@0
    35
@param aDriveLetter The drive to be tested.
sl@0
    36
@param aBuild Specifies whether tests or being run under UDEB or UREL
sl@0
    37
*/
sl@0
    38
CLocalTimeTest::CLocalTimeTest(RTest& aTest, const TDesC& aDriveLetter, TBuild aBuild) 
sl@0
    39
	:iDriveLetter(aDriveLetter), iTest(aTest), iBuild(aBuild), iOriginalUseLocalTimeFlag(EFalse)
sl@0
    40
	{
sl@0
    41
	
sl@0
    42
	}
sl@0
    43
sl@0
    44
/**
sl@0
    45
Factory function for test.
sl@0
    46
@param aTest The RTest handle to use.
sl@0
    47
@param aDriveLetter The drive to be tested.
sl@0
    48
@param aBuild Specifies whether tests or being run under UDEB or UREL
sl@0
    49
@return A test object
sl@0
    50
*/
sl@0
    51
CLocalTimeTest* CLocalTimeTest::NewLC(RTest& aTest, const TDesC& aDriveLetter, TBuild aBuild)
sl@0
    52
	{
sl@0
    53
	CLocalTimeTest* self = new(ELeave) CLocalTimeTest(aTest, aDriveLetter, aBuild);
sl@0
    54
	CleanupStack::PushL(self);
sl@0
    55
	self->ConstructL();
sl@0
    56
	return self;
sl@0
    57
	}
sl@0
    58
sl@0
    59
/** 
sl@0
    60
Connect the test to the File server
sl@0
    61
*/
sl@0
    62
void CLocalTimeTest::ConstructL()
sl@0
    63
	{
sl@0
    64
	User::LeaveIfError(iRFs.Connect() );
sl@0
    65
	iRFs.CharToDrive(iDriveLetter[0], iDrive);
sl@0
    66
	
sl@0
    67
	SetTestTypeL();
sl@0
    68
	if(iTestType !=ENoTest)
sl@0
    69
		{
sl@0
    70
		MakeTestPathL();
sl@0
    71
		
sl@0
    72
		iTestFile = new (ELeave) CTestFile(KFile, &iRFs);
sl@0
    73
		iTestFile->SetPath(iTestPath);
sl@0
    74
		iTestFileRFs = new (ELeave) CTestFileRFs(KFile, &iRFs );
sl@0
    75
		iTestFileRFs->SetPath(iTestPath);
sl@0
    76
		iTestDirectory = new (ELeave) CTestDirectory(KDirectory, &iRFs);
sl@0
    77
		iTestDirectory->SetPath(iTestPath);
sl@0
    78
		
sl@0
    79
		if(iBuild==EUdeb)
sl@0
    80
			iOriginalUseLocalTimeFlag=IsLocalTimeOnRemMediaL(); //store initial setting
sl@0
    81
		}
sl@0
    82
sl@0
    83
	if(iTestType==EPositive)
sl@0
    84
		iExpectedTimeStampOffset=KTimeOffset;
sl@0
    85
	else
sl@0
    86
		iExpectedTimeStampOffset=KNullTimeOffset;
sl@0
    87
	}
sl@0
    88
sl@0
    89
sl@0
    90
sl@0
    91
sl@0
    92
CLocalTimeTest::~CLocalTimeTest()
sl@0
    93
	{
sl@0
    94
	if(iTestType!=ENoTest && iBuild==EUdeb) //restore flag to original value
sl@0
    95
		{
sl@0
    96
		TRAPD(err,
sl@0
    97
			{
sl@0
    98
			if(iOriginalUseLocalTimeFlag)
sl@0
    99
				LocalTimeForRemMediaOnL();
sl@0
   100
			else
sl@0
   101
				LocalTimeForRemMediaOffL();
sl@0
   102
			}
sl@0
   103
		);
sl@0
   104
		__ASSERT_ALWAYS(err==KErrNone, User::PanicUnexpectedLeave());
sl@0
   105
		}
sl@0
   106
sl@0
   107
	if(iTestFile)
sl@0
   108
		delete iTestFile;
sl@0
   109
	if(iTestFileRFs)
sl@0
   110
		delete iTestFileRFs;
sl@0
   111
	if(iTestDirectory)
sl@0
   112
		delete iTestDirectory;
sl@0
   113
	}
sl@0
   114
sl@0
   115
/**
sl@0
   116
Check that the test can read and modify the flag within
sl@0
   117
the FAT or FAT32 plugin.
sl@0
   118
*/
sl@0
   119
void CLocalTimeTest::TestDebugInterfaceL()
sl@0
   120
	{
sl@0
   121
	iTest.Start(_L("Checking debug interface"));
sl@0
   122
		
sl@0
   123
	TBool localTimeEnabled(EFalse);
sl@0
   124
	localTimeEnabled = IsLocalTimeOnRemMediaL();
sl@0
   125
	iTest.Printf(_L("Use localtime enable intially? %d\n"), localTimeEnabled);
sl@0
   126
	
sl@0
   127
	LocalTimeForRemMediaOffL();
sl@0
   128
	localTimeEnabled=IsLocalTimeOnRemMediaL();
sl@0
   129
	iTest.Next(_L("Disabling flag..."));
sl@0
   130
	iTest(!localTimeEnabled);
sl@0
   131
	
sl@0
   132
	LocalTimeForRemMediaOnL();
sl@0
   133
	localTimeEnabled=IsLocalTimeOnRemMediaL();
sl@0
   134
	iTest.Next(_L("Enabling flag..."));
sl@0
   135
	iTest(localTimeEnabled);
sl@0
   136
	
sl@0
   137
	iTest.End();
sl@0
   138
	}
sl@0
   139
sl@0
   140
/**
sl@0
   141
Test that after creating a file or directory its creation time
sl@0
   142
has been offset (or not) as expected.
sl@0
   143
*/
sl@0
   144
void CLocalTimeTest::TestReadCreationTimeL(CFileSystemEntry* aFsEntry)
sl@0
   145
	{
sl@0
   146
	iTest.Next(_L("Read creation time"));
sl@0
   147
	iTest.Printf(_L("Testing on %S"), &aFsEntry->Name());
sl@0
   148
#if defined(_DEBUG)	
sl@0
   149
	LocalTimeForRemMediaOnL();
sl@0
   150
	TTime now;
sl@0
   151
	test_KErrNone(aFsEntry->DeleteCreate());
sl@0
   152
	now.UniversalTime(); //hopefuly "now" will be within the 2-second error allowed.
sl@0
   153
				
sl@0
   154
	aFsEntry->Close();
sl@0
   155
	TTime creationTimeLocal = aFsEntry->CreationTimeL();
sl@0
   156
	
sl@0
   157
	PrintTimeL(_L("Current UTC time"), now);
sl@0
   158
	PrintExpectedOffset();
sl@0
   159
	
sl@0
   160
	PrintTimeL(_L("creation time"), creationTimeLocal);
sl@0
   161
	iTest(CLocalTimeTest::FuzzyTimeMatch(creationTimeLocal, now+iExpectedTimeStampOffset));
sl@0
   162
sl@0
   163
#else
sl@0
   164
	test.Printf(_L("Creation times cannot be accessed in release build\n"));
sl@0
   165
sl@0
   166
#endif
sl@0
   167
	}
sl@0
   168
sl@0
   169
/**
sl@0
   170
Test that when reading a modification time it has been translated (or not)
sl@0
   171
as expected.
sl@0
   172
@param aFsEntry A file or directory to be tested
sl@0
   173
*/ 
sl@0
   174
void CLocalTimeTest::TestReadModificationTimeL(CFileSystemEntry* aFsEntry)
sl@0
   175
	{
sl@0
   176
	TInt r= KErrNone;
sl@0
   177
	iTest.Next(_L("Reading modification time - offset should be subtracted from timestamp "));
sl@0
   178
	iTest.Printf(_L("Testing on %S \n"), &aFsEntry->Name());
sl@0
   179
	LocalTimeForRemMediaOffL();
sl@0
   180
	r = aFsEntry->DeleteCreate();
sl@0
   181
	test_KErrNone(r);
sl@0
   182
	TTime now;
sl@0
   183
	now.UniversalTime();
sl@0
   184
	PrintTimeL(_L("Current UTC time"), now);
sl@0
   185
	//timestamp on disk will be UTC
sl@0
   186
	r = aFsEntry->SetModificationTime(now);
sl@0
   187
	test_KErrNone(r);
sl@0
   188
	aFsEntry->Close();
sl@0
   189
	LocalTimeForRemMediaOnL();
sl@0
   190
	r = aFsEntry->Open();
sl@0
   191
	test_KErrNone(r);
sl@0
   192
	
sl@0
   193
	TTime modTime = aFsEntry->ModificationTimeL();
sl@0
   194
	test_KErrNone(r);
sl@0
   195
	
sl@0
   196
	PrintExpectedOffset();
sl@0
   197
	PrintTimeL(_L("modification time"), modTime);
sl@0
   198
	iTest(CLocalTimeTest::FuzzyTimeMatch(modTime, now - iExpectedTimeStampOffset));
sl@0
   199
	aFsEntry->Close();
sl@0
   200
	}
sl@0
   201
sl@0
   202
/**
sl@0
   203
Test that when setting a modification time it is modified as expected.
sl@0
   204
@param aFsEntry A file or directory to be tested
sl@0
   205
*/
sl@0
   206
void CLocalTimeTest::TestSetModificationTimeL(CFileSystemEntry* aFsEntry)
sl@0
   207
	{
sl@0
   208
	iTest.Next(_L("Setting modification time - offset should be added to timestamp"));
sl@0
   209
	iTest.Printf(_L("Testing on %S \n"), &aFsEntry->Name());		
sl@0
   210
	TTime now;
sl@0
   211
	now.UniversalTime();
sl@0
   212
	PrintTimeL(_L("Modification time set"), now);
sl@0
   213
	LocalTimeForRemMediaOnL();
sl@0
   214
	TInt r = KErrNone;
sl@0
   215
	r = aFsEntry->DeleteCreate();
sl@0
   216
	test_KErrNone(r);
sl@0
   217
sl@0
   218
	//timestamp on disk will be local
sl@0
   219
	r = aFsEntry->SetModificationTime(now);
sl@0
   220
	test_KErrNone(r);
sl@0
   221
	aFsEntry->Close();
sl@0
   222
	
sl@0
   223
	LocalTimeForRemMediaOffL();
sl@0
   224
	aFsEntry->Open();
sl@0
   225
	
sl@0
   226
	TTime modTime = aFsEntry->ModificationTimeL();
sl@0
   227
	
sl@0
   228
	PrintExpectedOffset();
sl@0
   229
	PrintTimeL(_L("Modification time read"), modTime);
sl@0
   230
	iTest(CLocalTimeTest::FuzzyTimeMatch(modTime, now+iExpectedTimeStampOffset));
sl@0
   231
	
sl@0
   232
	aFsEntry->Close();
sl@0
   233
	}
sl@0
   234
/**
sl@0
   235
Check that modification times of copied files are preserved
sl@0
   236
@param aFsEntry A file or directory to be tested
sl@0
   237
*/
sl@0
   238
void CLocalTimeTest::TestCopyL(CFileSystemEntry* aFsEntry)
sl@0
   239
	{
sl@0
   240
	LocalTimeForRemMediaOnL();
sl@0
   241
		
sl@0
   242
	iTest.Next(_L("Test copying"));
sl@0
   243
	iTest.Printf(_L("Testing on %S \n"), &aFsEntry->Name());
sl@0
   244
	aFsEntry->DeleteCreate();
sl@0
   245
	TTime mtime = aFsEntry->ModificationTimeL();
sl@0
   246
	PrintTimeL(_L("Original mtime"), mtime);
sl@0
   247
	
sl@0
   248
	
sl@0
   249
	CFileSystemEntry* file2 = aFsEntry->CopyL();
sl@0
   250
	file2->Close();
sl@0
   251
	CleanupStack::PushL(file2);
sl@0
   252
	
sl@0
   253
	file2->Open();
sl@0
   254
	TTime mtime2 = file2->ModificationTimeL();
sl@0
   255
	
sl@0
   256
	
sl@0
   257
	iTest.Printf(_L("Modification times should be preserved\n"));
sl@0
   258
	
sl@0
   259
	PrintTimeL(_L("Copy's mtime"), mtime2 );
sl@0
   260
	iTest(FuzzyTimeMatch(mtime2, mtime) ); //mod time should always be preserved on copy
sl@0
   261
	
sl@0
   262
	CleanupStack::PopAndDestroy(file2);
sl@0
   263
	aFsEntry->Close();
sl@0
   264
	}
sl@0
   265
sl@0
   266
/**
sl@0
   267
Check that modification times of copied directories are preserved
sl@0
   268
*/
sl@0
   269
void CLocalTimeTest::TestCopyDirL()
sl@0
   270
	{
sl@0
   271
	LocalTimeForRemMediaOnL();
sl@0
   272
	
sl@0
   273
	iTest.Next(_L("Test copying directory - modtimes should be preserved"));
sl@0
   274
	_LIT(KSubDir, "SubDir\\");
sl@0
   275
	TPath parentDir(iTestPath);
sl@0
   276
	parentDir+=KDirectory;
sl@0
   277
	parentDir.Delete(parentDir.Length()-1, 1);
sl@0
   278
	
sl@0
   279
	TPath subDir(parentDir);
sl@0
   280
	subDir.Append(KPathDelimiter);
sl@0
   281
	subDir+=KSubDir;
sl@0
   282
	
sl@0
   283
	
sl@0
   284
	TPath destDir(iTestPath);
sl@0
   285
	destDir+=_L("copyDir");
sl@0
   286
	destDir.Append(KPathDelimiter);
sl@0
   287
		
sl@0
   288
	iRFs.RmDir(subDir);
sl@0
   289
	iRFs.MkDirAll(subDir);
sl@0
   290
	
sl@0
   291
	TPath destSubDir(destDir);
sl@0
   292
	destSubDir+=KSubDir;
sl@0
   293
	iRFs.RmDir(destSubDir);
sl@0
   294
	
sl@0
   295
	CFileMan* fMan = CFileMan::NewL(iRFs);
sl@0
   296
	CleanupStack::PushL(fMan );
sl@0
   297
	
sl@0
   298
	
sl@0
   299
	
sl@0
   300
	fMan->Copy(parentDir, destDir , CFileMan::EOverWrite|CFileMan::ERecurse);
sl@0
   301
	
sl@0
   302
	TTime originalModtime;
sl@0
   303
	TTime newDirModtime;
sl@0
   304
	
sl@0
   305
	test_KErrNone(iRFs.Modified(subDir, originalModtime) );
sl@0
   306
	test_KErrNone(iRFs.Modified(destSubDir, newDirModtime));
sl@0
   307
	PrintTimeL(_L("Orginal modtime"), originalModtime);
sl@0
   308
	PrintTimeL(_L("Copy's modtime"), newDirModtime);
sl@0
   309
	
sl@0
   310
	iRFs.RmDir(subDir);
sl@0
   311
	iRFs.RmDir(destSubDir);
sl@0
   312
	
sl@0
   313
sl@0
   314
	iTest(FuzzyTimeMatch(originalModtime,newDirModtime) );
sl@0
   315
	
sl@0
   316
	CleanupStack::PopAndDestroy(fMan);
sl@0
   317
	}
sl@0
   318
sl@0
   319
/**
sl@0
   320
Checks whether two times match, to a certain tolerance. By default allow for a 2 second error.
sl@0
   321
@param aTestTime One time
sl@0
   322
@param aRefTime Second time.
sl@0
   323
@return Whether the times matched.
sl@0
   324
*/
sl@0
   325
TBool CLocalTimeTest::FuzzyTimeMatch(const TTime& aTestTime, const TTime& aRefTime)
sl@0
   326
	{
sl@0
   327
	return(aTestTime>=(aRefTime-KModTimeThreshold) && aTestTime<=(aRefTime+KModTimeThreshold));
sl@0
   328
	}
sl@0
   329
sl@0
   330
/**
sl@0
   331
If on UDEB will switch on the flag held in the CFatMountCB object to
sl@0
   332
use localtimes on removable media.
sl@0
   333
If on UREL will just set the UTC offset on.
sl@0
   334
*/
sl@0
   335
void CLocalTimeTest::LocalTimeForRemMediaOnL()
sl@0
   336
	{
sl@0
   337
#if defined(_DEBUG)
sl@0
   338
	User::LeaveIfError(iRFs.ControlIo(iDrive, ELocalTimeForRemovableMediaOn,NULL ,NULL) );
sl@0
   339
#else
sl@0
   340
	User::SetUTCOffset(KTimeOffset);
sl@0
   341
#endif
sl@0
   342
	}
sl@0
   343
sl@0
   344
/**
sl@0
   345
If on UDEB will switch off the flag held in the CFatMountCB object to
sl@0
   346
use localtimes on removable media.
sl@0
   347
If on UREL will just set the UTC offset to nothing,
sl@0
   348
so that no time conversions are carried out.
sl@0
   349
*/
sl@0
   350
void CLocalTimeTest::LocalTimeForRemMediaOffL()
sl@0
   351
	{
sl@0
   352
sl@0
   353
#if defined(_DEBUG)
sl@0
   354
	User::LeaveIfError(iRFs.ControlIo(iDrive, ELocalTimeForRemovableMediaOff,NULL ,NULL) );
sl@0
   355
#else
sl@0
   356
	User::SetUTCOffset(KNullTimeOffset);
sl@0
   357
#endif
sl@0
   358
	}
sl@0
   359
sl@0
   360
TBool CLocalTimeTest::IsLocalTimeOnRemMediaL()
sl@0
   361
	{
sl@0
   362
#if defined(_DEBUG)
sl@0
   363
	TBool flag(EFalse);
sl@0
   364
	TPckg<TBool> flagPckg(flag);
sl@0
   365
	User::LeaveIfError( iRFs.ControlIo(iDrive, ELocalTimeUsedOnRemovableMedia, flagPckg) );
sl@0
   366
	return flagPckg();
sl@0
   367
#else
sl@0
   368
	return( User::UTCOffset()==KTimeOffset );
sl@0
   369
#endif
sl@0
   370
	}
sl@0
   371
sl@0
   372
void CLocalTimeTest::SetTestTypeL()
sl@0
   373
	{
sl@0
   374
	TDriveInfo info;
sl@0
   375
	
sl@0
   376
	TFSName fileSystem;
sl@0
   377
	TInt err;
sl@0
   378
	err = iRFs.FileSystemName(fileSystem, iDrive);
sl@0
   379
sl@0
   380
	User::LeaveIfError(err);
sl@0
   381
	
sl@0
   382
	//not currently testing on urel due to lack of support for configuration file/estart.txt  managment
sl@0
   383
	if(iBuild==EUrel)
sl@0
   384
		{
sl@0
   385
		iTestType=ENoTest;
sl@0
   386
		return;
sl@0
   387
		}
sl@0
   388
sl@0
   389
	if(fileSystem != KFatFileSystem)
sl@0
   390
		{
sl@0
   391
		iTestType=ENoTest;
sl@0
   392
		return;
sl@0
   393
		}
sl@0
   394
	err = iRFs.Drive(info, iDrive);
sl@0
   395
	User::LeaveIfError(err);
sl@0
   396
sl@0
   397
	if(info.iDriveAtt&KDriveAttRemovable)
sl@0
   398
		{
sl@0
   399
		iTestType=EPositive;
sl@0
   400
		}
sl@0
   401
	else
sl@0
   402
		{
sl@0
   403
		iTestType=ENegative;
sl@0
   404
		}
sl@0
   405
	return;
sl@0
   406
	}
sl@0
   407
sl@0
   408
sl@0
   409
sl@0
   410
/**
sl@0
   411
@return Drive letter being tested
sl@0
   412
*/
sl@0
   413
const TDesC& CLocalTimeTest::DriveLetter() const
sl@0
   414
	{
sl@0
   415
	return iDriveLetter;
sl@0
   416
	}
sl@0
   417
/**
sl@0
   418
@return Drive number of test.
sl@0
   419
*/
sl@0
   420
TInt CLocalTimeTest::DriveNumber() const
sl@0
   421
	{
sl@0
   422
	return iDrive;
sl@0
   423
	}
sl@0
   424
sl@0
   425
/**
sl@0
   426
Print the drive number and letter of the test to the RTest console.
sl@0
   427
*/
sl@0
   428
void CLocalTimeTest::PrintDrive() const
sl@0
   429
	{
sl@0
   430
	TFSName fileSystem;
sl@0
   431
	TInt err;
sl@0
   432
	err = iRFs.FileSystemSubType(iDrive, fileSystem);
sl@0
   433
	test_KErrNone(err);
sl@0
   434
	test.Printf(_L("Using drive %d %S: Fs Type: %S\n"), DriveNumber(), &DriveLetter(), &fileSystem );
sl@0
   435
	}
sl@0
   436
sl@0
   437
void CLocalTimeTest::PrintExpectedOffset() const
sl@0
   438
	{
sl@0
   439
	iTest.Printf(_L("Expected offset: %d hours\n"), iExpectedTimeStampOffset.Int()/KSecondsPerHour);
sl@0
   440
	}
sl@0
   441
sl@0
   442
/**
sl@0
   443
Create directories for the test if necessary.
sl@0
   444
*/
sl@0
   445
void CLocalTimeTest::MakeTestPathL()
sl@0
   446
	{
sl@0
   447
	iTestPath.Append(iDriveLetter);
sl@0
   448
	iTestPath.Append(KDriveDelimiter);
sl@0
   449
	iTestPath.Append(KPathDelimiter);
sl@0
   450
	iTestPath.Append(KTestDir);
sl@0
   451
	iTestPath.Append(KPathDelimiter);
sl@0
   452
		
sl@0
   453
	TInt err=iRFs.MkDirAll(iTestPath);
sl@0
   454
	if(err!=KErrNone && err!=KErrAlreadyExists)
sl@0
   455
		User::Leave(err);
sl@0
   456
	iRFs.SetSessionPath(iTestPath);
sl@0
   457
	}
sl@0
   458
sl@0
   459
void CLocalTimeTest::PrintTimeL(const TDesC& aMessg, const TTime& aTime) const
sl@0
   460
	{
sl@0
   461
	TBuf<32> timeBuf;
sl@0
   462
	_LIT(KTimeFormat, "%F%H:%T:%S");
sl@0
   463
	aTime.FormatL(timeBuf, KTimeFormat);
sl@0
   464
sl@0
   465
	iTest.Printf(_L("%S: %S\n"), &aMessg, &timeBuf);
sl@0
   466
	}
sl@0
   467
sl@0
   468
sl@0
   469
/**
sl@0
   470
A callback function passed into a TCleanupItem to restore the system's UTC offset at the end
sl@0
   471
of the test.
sl@0
   472
*/
sl@0
   473
void RestoreOffset(TAny* aOffset)
sl@0
   474
	{
sl@0
   475
	User::SetUTCOffset(*static_cast<TTimeIntervalSeconds*>(aOffset) );
sl@0
   476
	}
sl@0
   477
sl@0
   478
sl@0
   479
sl@0
   480
sl@0
   481
sl@0
   482
sl@0
   483
////////////////////////////////////////////////
sl@0
   484
//////////CFileSystemEntry/////////////////////
sl@0
   485
////////////////////////////////////////////////
sl@0
   486
sl@0
   487
/**
sl@0
   488
@param aPath Name or full path for entry.
sl@0
   489
@param aFs the RFs handle to be used.
sl@0
   490
*/
sl@0
   491
CFileSystemEntry::CFileSystemEntry(const TDesC& aPath, RFs* aFs )
sl@0
   492
	: iRFs(aFs), iFullPath(aPath)
sl@0
   493
	{
sl@0
   494
	}
sl@0
   495
sl@0
   496
CFileSystemEntry::~CFileSystemEntry()
sl@0
   497
	{}
sl@0
   498
sl@0
   499
/**
sl@0
   500
Prepends a path to the existing name or path.
sl@0
   501
@param aPath The path to use.
sl@0
   502
*/
sl@0
   503
void CFileSystemEntry::SetPath(const TDesC& aPath)
sl@0
   504
	{
sl@0
   505
	iFullPath.Insert(0, aPath);
sl@0
   506
	}
sl@0
   507
sl@0
   508
void CFileSystemEntry::SetFileServer(RFs* aFs)
sl@0
   509
	{
sl@0
   510
	iRFs = aFs;	
sl@0
   511
	}
sl@0
   512
sl@0
   513
/**
sl@0
   514
Close and delete the entry.
sl@0
   515
@return An error code indicating success or failure.
sl@0
   516
*/
sl@0
   517
TInt CFileSystemEntry::Delete()
sl@0
   518
	{
sl@0
   519
	Close();
sl@0
   520
	return iRFs->Delete(iFullPath);
sl@0
   521
	}
sl@0
   522
sl@0
   523
/**
sl@0
   524
Delete and then make a new file/directory of the same name
sl@0
   525
@return An error code indicating success or failure.
sl@0
   526
*/
sl@0
   527
TInt CFileSystemEntry::DeleteCreate()
sl@0
   528
	{
sl@0
   529
	Delete();
sl@0
   530
	return Create();
sl@0
   531
	}
sl@0
   532
sl@0
   533
void CFileSystemEntry::Close()
sl@0
   534
	{	
sl@0
   535
	}
sl@0
   536
sl@0
   537
/**
sl@0
   538
@return The creation time of the entry.
sl@0
   539
*/
sl@0
   540
TTime CFileSystemEntry::CreationTimeL()
sl@0
   541
	{
sl@0
   542
	TParsePtrC parse(iFullPath);
sl@0
   543
	//check there is a drive specified
sl@0
   544
	if(!parse.DrivePresent() )
sl@0
   545
		User::Panic(KTestGroupName, KErrBadName);
sl@0
   546
	
sl@0
   547
	TInt driveNumber(0); 
sl@0
   548
	User::LeaveIfError(iRFs->CharToDrive(parse.Drive()[0], driveNumber) );
sl@0
   549
sl@0
   550
	TBuf8<KMaxPath> narrowPath;
sl@0
   551
	narrowPath.Copy(parse.Path() );
sl@0
   552
	narrowPath.Append(parse.NameAndExt() );
sl@0
   553
	
sl@0
   554
	//remove trailing slash if present
sl@0
   555
	if(narrowPath[narrowPath.Length()-1]==KPathDelimiter)
sl@0
   556
		narrowPath.Delete(narrowPath.Length()-1, 1);
sl@0
   557
sl@0
   558
	TTime creationTime=0;
sl@0
   559
	TPckg<TTime> timePckg(creationTime);
sl@0
   560
sl@0
   561
	User::LeaveIfError(iRFs->ControlIo(driveNumber, ECreationTime, narrowPath, timePckg) );
sl@0
   562
sl@0
   563
	return timePckg();
sl@0
   564
	}
sl@0
   565
sl@0
   566
const TDesC& CFileSystemEntry::Name() const
sl@0
   567
	{
sl@0
   568
	return iName;
sl@0
   569
	}
sl@0
   570
sl@0
   571
sl@0
   572
////////////////////////////////////////////////
sl@0
   573
//////////CTestDirectory////////////////////////
sl@0
   574
////////////////////////////////////////////////
sl@0
   575
sl@0
   576
CTestDirectory::CTestDirectory(const TDesC& aPath, RFs* aFs)
sl@0
   577
:CFileSystemEntry(aPath, aFs)
sl@0
   578
	{
sl@0
   579
	iName.Set(KTestDirectoryName);
sl@0
   580
	}
sl@0
   581
sl@0
   582
TInt CTestDirectory::Open()
sl@0
   583
	{
sl@0
   584
	return KErrNone; //directories can't be opened.
sl@0
   585
	}
sl@0
   586
sl@0
   587
TInt CTestDirectory::Create()
sl@0
   588
	{
sl@0
   589
	return iRFs->MkDir(iFullPath);
sl@0
   590
	}
sl@0
   591
sl@0
   592
TInt CTestDirectory::Delete()
sl@0
   593
	{
sl@0
   594
	return iRFs->RmDir(iFullPath );
sl@0
   595
	}
sl@0
   596
sl@0
   597
TTime CTestDirectory::ModificationTimeL()
sl@0
   598
	{
sl@0
   599
	TTime time;
sl@0
   600
	User::LeaveIfError( iRFs->Modified(iFullPath, time) );
sl@0
   601
	return time;
sl@0
   602
	}
sl@0
   603
TInt CTestDirectory::SetModificationTime(const TTime& aTime)
sl@0
   604
	{
sl@0
   605
	return iRFs->SetModified(iFullPath, aTime);
sl@0
   606
	}
sl@0
   607
CFileSystemEntry* CTestDirectory::CopyL()
sl@0
   608
	{
sl@0
   609
	return NULL;
sl@0
   610
	}
sl@0
   611
sl@0
   612
sl@0
   613
////////////////////////////////////////////////
sl@0
   614
//////////CTestFile/////////////////////////////
sl@0
   615
////////////////////////////////////////////////
sl@0
   616
sl@0
   617
CTestFile::CTestFile(const TDesC& aPath, RFs* aFs)
sl@0
   618
:CFileSystemEntry(aPath, aFs)
sl@0
   619
	{
sl@0
   620
	iName.Set(KTestFileRFile);
sl@0
   621
	}
sl@0
   622
sl@0
   623
CTestFile::~CTestFile()
sl@0
   624
	{
sl@0
   625
	Close();
sl@0
   626
	}
sl@0
   627
sl@0
   628
TInt CTestFile::Open()
sl@0
   629
	{
sl@0
   630
	return iRFile.Open(*iRFs, iFullPath, EFileShareExclusive|EFileWrite);
sl@0
   631
	}
sl@0
   632
sl@0
   633
TInt CTestFile::Create()
sl@0
   634
	{
sl@0
   635
	return iRFile.Replace(*iRFs, iFullPath, EFileShareExclusive|EFileWrite);	
sl@0
   636
	}
sl@0
   637
void CTestFile::Close()
sl@0
   638
	{
sl@0
   639
	iRFile.Close();
sl@0
   640
	}
sl@0
   641
sl@0
   642
TTime CTestFile::ModificationTimeL()
sl@0
   643
	{
sl@0
   644
	TTime time;
sl@0
   645
	User::LeaveIfError(iRFile.Modified(time) );
sl@0
   646
	return time;
sl@0
   647
	}
sl@0
   648
sl@0
   649
TInt CTestFile::SetModificationTime(const TTime& aTime)
sl@0
   650
	{
sl@0
   651
	return iRFile.SetModified(aTime);
sl@0
   652
	}
sl@0
   653
sl@0
   654
CFileSystemEntry* CTestFile::CopyL()
sl@0
   655
	{
sl@0
   656
	CFileMan* fMan = CFileMan::NewL(*iRFs);
sl@0
   657
	CleanupStack::PushL(fMan);
sl@0
   658
	
sl@0
   659
	TFileName newName(iFullPath);
sl@0
   660
	newName.Append(_L("~"));
sl@0
   661
	CFileSystemEntry* copy= new(ELeave) CTestFile(newName, iRFs);
sl@0
   662
	CleanupStack::PushL(copy);
sl@0
   663
	copy->Delete(); //delete anything at the path already
sl@0
   664
	Close();
sl@0
   665
	User::LeaveIfError(fMan->Copy(iFullPath,newName) );
sl@0
   666
	
sl@0
   667
	CleanupStack::Pop(copy);
sl@0
   668
	CleanupStack::PopAndDestroy(fMan);
sl@0
   669
	return copy;
sl@0
   670
	}
sl@0
   671
sl@0
   672
////////////////////////////////////////////////
sl@0
   673
////////////CTestFileRFs////////////////////////
sl@0
   674
////////////////////////////////////////////////
sl@0
   675
CTestFileRFs::CTestFileRFs(const TDesC& aPath, RFs* aFs) : CTestFile(aPath, aFs)
sl@0
   676
	{
sl@0
   677
	iName.Set(KTestFileRFs);
sl@0
   678
	}
sl@0
   679
TTime CTestFileRFs::ModificationTimeL()
sl@0
   680
	{
sl@0
   681
	TBool isOpen=KErrNone;
sl@0
   682
	test_KErrNone(iRFs->IsFileOpen(iFullPath, isOpen));
sl@0
   683
	if(isOpen)
sl@0
   684
		Close();
sl@0
   685
	TTime time;
sl@0
   686
	User::LeaveIfError(iRFs->Modified(iFullPath,time) );
sl@0
   687
	if(isOpen)
sl@0
   688
		Open();
sl@0
   689
	return time;
sl@0
   690
	
sl@0
   691
	}
sl@0
   692
sl@0
   693
TInt CTestFileRFs::SetModificationTime(const TTime& aTime)
sl@0
   694
	{
sl@0
   695
	TBool isOpen=KErrNone;
sl@0
   696
	test_KErrNone(iRFs->IsFileOpen(iFullPath, isOpen));
sl@0
   697
	if(isOpen)
sl@0
   698
		Close();
sl@0
   699
	TInt err = iRFs->SetModified(iFullPath, aTime);
sl@0
   700
	if(isOpen)
sl@0
   701
		Open();
sl@0
   702
sl@0
   703
	return err;
sl@0
   704
	}
sl@0
   705
sl@0
   706
CTestFileRFs::~CTestFileRFs()
sl@0
   707
	{
sl@0
   708
	Close();
sl@0
   709
	}
sl@0
   710
sl@0
   711
sl@0
   712
////////////////////////////////////////////////////
sl@0
   713
//////////Entry point and main//////////////////////
sl@0
   714
////////////////////////////////////////////////////
sl@0
   715
sl@0
   716
/**
sl@0
   717
Construct and run the various tests.
sl@0
   718
*/
sl@0
   719
void CallTestsL()
sl@0
   720
	{
sl@0
   721
	test.Start(KTestGroupName);
sl@0
   722
#if defined(_DEBUG)
sl@0
   723
	CLocalTimeTest::TBuild build = CLocalTimeTest::EUdeb;
sl@0
   724
#else
sl@0
   725
	CLocalTimeTest::TBuild build = CLocalTimeTest::EUrel;
sl@0
   726
#endif
sl@0
   727
	TPtrC drive((TUint16*)&gDriveToTest, 1);
sl@0
   728
	
sl@0
   729
	CLocalTimeTest* timeTest= CLocalTimeTest::NewLC(test, drive , build);
sl@0
   730
	timeTest->RunTestsL();
sl@0
   731
	CleanupStack::PopAndDestroy(timeTest);
sl@0
   732
sl@0
   733
	test.End();
sl@0
   734
	}
sl@0
   735
sl@0
   736
void CLocalTimeTest::RunTestsL()
sl@0
   737
	{
sl@0
   738
	PrintDrive();
sl@0
   739
	if(iTestType==ENoTest)
sl@0
   740
		{
sl@0
   741
		iTest.Printf(_L("Not runnning tests on this drive\n"));
sl@0
   742
		return;
sl@0
   743
		}
sl@0
   744
	
sl@0
   745
	iTest.Start(_L("Running tests")); 
sl@0
   746
sl@0
   747
	//Be able to restore to original timezone after test
sl@0
   748
	TTimeIntervalSeconds savedUTCOffset = User::UTCOffset();
sl@0
   749
	TCleanupItem restoreOffset(RestoreOffset, &savedUTCOffset);
sl@0
   750
	CleanupStack::PushL(restoreOffset);
sl@0
   751
	
sl@0
   752
	//This functionallity must be tested with a non-zero GMT offset.
sl@0
   753
	test.Printf(_L("Setting UTC offset to %d hours\n"), KHoursOffset);
sl@0
   754
	User::SetUTCOffset(KTimeOffset);
sl@0
   755
	
sl@0
   756
	if(iBuild==EUdeb)
sl@0
   757
		iTest.Printf(_L("Testing on UDEB build\n"));
sl@0
   758
	else if(iBuild==EUrel)
sl@0
   759
		iTest.Printf(_L("Testing on UREL build\n"));
sl@0
   760
sl@0
   761
	if(iTestType==EPositive)
sl@0
   762
		iTest.Printf(_L("Drive is removable, running positive tests\n"));
sl@0
   763
	else if(iTestType==ENegative)
sl@0
   764
		iTest.Printf(_L("Drive is non-removable, running negative tests\n"));
sl@0
   765
			
sl@0
   766
	
sl@0
   767
	if(iBuild==EUdeb) //these tests cannot be used without ControlIO
sl@0
   768
		{
sl@0
   769
		TestDebugInterfaceL();
sl@0
   770
		TestReadCreationTimeL(iTestFile);
sl@0
   771
		TestReadCreationTimeL(iTestFileRFs);
sl@0
   772
		TestReadCreationTimeL(iTestDirectory);
sl@0
   773
		}
sl@0
   774
	
sl@0
   775
	TestReadModificationTimeL(iTestFile);
sl@0
   776
	TestReadModificationTimeL(iTestFileRFs);
sl@0
   777
	TestReadModificationTimeL(iTestDirectory);
sl@0
   778
sl@0
   779
	TestSetModificationTimeL(iTestFile);
sl@0
   780
	TestSetModificationTimeL(iTestFileRFs);
sl@0
   781
	TestSetModificationTimeL(iTestDirectory);
sl@0
   782
	
sl@0
   783
	TestCopyL(iTestFile);
sl@0
   784
	TestCopyL(iTestFileRFs);
sl@0
   785
	TestCopyDirL();
sl@0
   786
sl@0
   787
	CleanupStack::PopAndDestroy(&savedUTCOffset);
sl@0
   788
	iTest.End();
sl@0
   789
	}