os/kernelhwsrv/kerneltest/f32test/server/t_localtime.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // Declarations for the t_localtime test. This tests functionality introduced
    15 // in CR1084 ie. That removable (in practice this means FAT) file systems
    16 // can be made to use local time for timestamps.
    17 // 
    18 //
    19 
    20 /**
    21  @file
    22  @test
    23 */
    24 
    25 
    26 #ifndef T_LOCALTIME_H
    27 #define T_LOCALTIME_H
    28 
    29 #include <f32file.h>
    30 
    31 
    32 
    33 /**
    34 Provides a common test interface for files and directories.
    35 */
    36 class CFileSystemEntry : public CBase 
    37 	{
    38 	
    39 public:
    40 	virtual ~CFileSystemEntry()=0;
    41 	virtual TInt Delete();
    42 	virtual TInt Create()=0;
    43 	virtual void SetPath(const TDesC& aPath);
    44 	virtual void SetFileServer(RFs* aFs);
    45 	virtual TInt Open()=0;
    46 	virtual TInt DeleteCreate();	
    47 	virtual void Close();
    48 	virtual TTime ModificationTimeL()=0;
    49 	virtual TInt SetModificationTime(const TTime&)=0;
    50 	virtual TTime CreationTimeL();				
    51 	virtual CFileSystemEntry* CopyL()=0;
    52 	virtual const TDesC& Name() const;
    53 
    54 protected:
    55 	CFileSystemEntry(const TDesC& aPath, RFs* aFs);
    56 	RFs* iRFs; ///<A pointer to some external RFs
    57 	TFileName iFullPath; ///<Name of the file or directory.
    58 	TPtrC iName;
    59 	};
    60 
    61 _LIT(KTestDirectoryName, "Directory");
    62 /**
    63 Implementation of interface to directories
    64 */
    65 class CTestDirectory : public CFileSystemEntry
    66 	{
    67 public:
    68 	CTestDirectory(const TDesC& aPath, RFs* aFs = NULL);
    69 	virtual TInt Open();
    70 	virtual TInt Delete();
    71 	virtual TInt Create();
    72 	virtual TTime ModificationTimeL();
    73 	virtual TInt SetModificationTime(const TTime&);
    74 	virtual CFileSystemEntry* CopyL();
    75 	};
    76 
    77 _LIT(KTestFileRFile, "File - accessed with RFile");
    78 /**
    79 File interface, uses RFile to access mod time
    80 */
    81 class CTestFile : public CFileSystemEntry
    82 	{
    83 public:
    84 	CTestFile(const TDesC& aPath, RFs* aFs = NULL);
    85 	virtual TInt Open();
    86 	virtual TInt Create();
    87 	virtual void Close();
    88 	virtual TTime ModificationTimeL();
    89 	virtual TInt SetModificationTime(const TTime&);
    90 	virtual CFileSystemEntry* CopyL();
    91 	virtual ~CTestFile();
    92 
    93 protected:
    94 	RFile iRFile; ///< Handle to the file the class is wrapping.
    95 	};
    96 
    97 _LIT(KTestFileRFs, "File - accessed with RFs");
    98 /**
    99 File interface-uses RFs to access mod time
   100 */
   101 class CTestFileRFs : public CTestFile
   102 	{
   103 public:
   104 	CTestFileRFs(const TDesC& aPath, RFs* aFs = NULL);
   105 	virtual TTime ModificationTimeL();
   106 	virtual TInt SetModificationTime(const TTime&);
   107 	virtual ~CTestFileRFs();
   108 
   109 	};
   110 
   111 
   112 
   113 _LIT(KTestGroupName, "Local timestamps on removable media");
   114 
   115 _LIT(KTestDir, "F32-TST\\t_localtime");
   116 
   117 
   118 //For emulator
   119 _LIT(KNonRemovableDrive, "Y:\\");
   120 _LIT(KRemovableDrive, "X:\\");
   121 
   122 
   123 _LIT(KFile,"utc-test-file");
   124 _LIT(KDirectory,"utc-test-dir\\");
   125 _LIT(KRemMedia, "removable-media");
   126 _LIT(KNonRemMedia, "non-removable-media");
   127 
   128 
   129 _LIT(KFatFileSystem, "Fat");
   130 _LIT(KFat32FileSystem, "FAT32");
   131 _LIT(KFat16FileSystem, "FAT16");
   132 
   133 const TInt KSecondsPerHour(3600);
   134 const TInt KHoursOffset(6);
   135 const TTimeIntervalSeconds KTimeOffset(KHoursOffset*KSecondsPerHour);
   136 const TTimeIntervalSeconds KNullTimeOffset(0);
   137 const TTimeIntervalSeconds KModTimeThreshold(3); //FAT timestamp resolution is 2 seconds, +1 tolerence for delays. 
   138 
   139 /**
   140 Base class for the t_localtime tests. Defines generic test steps as well as utility
   141 functions. Subclassed tests implement RunTests to call specific test steps.
   142 
   143 */
   144 class CLocalTimeTest : public CBase
   145 	{
   146 public:
   147 	/**
   148 	Used as a parameter to tell test what type of drive to use
   149 	*/
   150 	enum TDriveType
   151 	{
   152 		ERemovable,
   153 		ENonRemovable
   154 	};
   155 
   156 	enum TBuild
   157 	{
   158 		EUdeb,
   159 		EUrel
   160 	};
   161 
   162 	enum TTestType
   163 	{
   164 		EPositive, ///< Times are expected to be translated
   165 		ENegative, ///<Times are expected to be preserved
   166 		ENoTest ///<Tests won't be carried out.
   167 	};
   168 	
   169 	static CLocalTimeTest* NewLC(RTest& aTest, const TDesC& aDriveLetter, TBuild aBuild);
   170 	virtual ~CLocalTimeTest();
   171 	
   172 	void RunTestsL(); ///<Defines what steps the test will carry out.
   173 	
   174 	/////// Generic test steps ///////////
   175 	void TestDebugInterfaceL();
   176 	void TestReadCreationTimeL(CFileSystemEntry* aFsEntry);
   177 	void TestReadModificationTimeL(CFileSystemEntry* aFsEntry);
   178 	void TestSetModificationTimeL(CFileSystemEntry* aFsEntry);
   179 	void TestCopyL(CFileSystemEntry* aFsEntry);
   180 	void TestCopyDirL();
   181 
   182 	////////Utility Functions/////////
   183 	static TBool FuzzyTimeMatch(const TTime& aTestTime, const TTime& aRefTime);
   184 	void LocalTimeForRemMediaOnL();
   185 	void LocalTimeForRemMediaOffL();
   186 	TBool IsLocalTimeOnRemMediaL();
   187 	void PrintTimeL(const TDesC& aMessg, const TTime& aTime) const;
   188 	const TDesC& DriveLetter() const;
   189 	TInt DriveNumber() const;
   190 	void PrintExpectedOffset() const;
   191 	void PrintDrive() const;
   192 	
   193 protected:
   194 	CLocalTimeTest(RTest& aTest, const TDesC& aDriveLetter, TBuild aBuild);
   195 	void ConstructL();
   196 	
   197 	void MakeTestPathL();
   198 	void SetTestTypeL();
   199 
   200 	TDriveType iDriveType; ///< Can be removable or non-removable
   201 	TInt iDrive; ///<Stores the number of the drive in use.
   202 	TBuf<1> iDriveLetter; ///<Stores the letter of the drive in use.
   203 	
   204 	CTestFile* iTestFile; ///<The file or directory to be used in the test
   205 	CTestFileRFs* iTestFileRFs;
   206 	CTestDirectory* iTestDirectory;
   207 
   208 	TPath iTestPath; ///<The absolute path of the test directory
   209 	RTest& iTest;	///<The test to be used
   210 	TTestType iTestType;
   211 	TBuild iBuild;
   212 	
   213 	/**
   214 	The expected time difference the test expects to see between files' or directories'
   215 	actual timestamps and the ones reported through the api. If local time timestamps are not in
   216 	use then this member will be 0.
   217 	*/	
   218 	TTimeIntervalSeconds iExpectedTimeStampOffset;
   219 
   220 	RFs iRFs; ///< File server handle for the test.
   221 	TBool iOriginalUseLocalTimeFlag; ///<Stored at begginng of test, must be restored at end
   222 	};
   223 
   224 
   225 /**
   226 Defines opcodes for RFs::ControlIO functions used. These definitions must match
   227 up with those in F32\sfat\inc\sl_std.h and F32\sfat32\inc\sl_std.h
   228 */
   229 enum TUTCControlIO
   230 	{
   231 	ELocalTimeForRemovableMediaOn=10, ///< 10
   232 	ELocalTimeForRemovableMediaOff=11, ///< 11
   233 	ELocalTimeUsedOnRemovableMedia=12, ///< 12
   234 	ECreationTime=13 ///<13
   235 	};
   236 
   237 
   238 
   239 #endif// T_LOCALTIME_H
   240