baseintegtests/baseintegrationtest/testsuites/fat32/src/basetestfat32readfile.cpp
branchanywhere
changeset 20 d63d727ee0a6
parent 19 f6d3d9676ee4
parent 16 6d8ad5bee44b
child 21 af091391d962
equal deleted inserted replaced
19:f6d3d9676ee4 20:d63d727ee0a6
     1 // Copyright (c) 2006-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 // Performs various actions related to reading a file
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "basetestfat32readfile.h"
       
    19 
       
    20 
       
    21 static RFile TheFile;
       
    22 
       
    23 /**
       
    24 Class Constructor
       
    25 */		    
       
    26 CBaseTestFat32ReadFile::CBaseTestFat32ReadFile() 
       
    27 	{
       
    28 	SetTestStepName(KTestStepReadFile);
       
    29 	}
       
    30 	
       
    31 /**
       
    32 Class Destructor
       
    33 */
       
    34 CBaseTestFat32ReadFile::~CBaseTestFat32ReadFile() 
       
    35 	{
       
    36 	}
       
    37 
       
    38 /** 
       
    39 The function performs the following actions:
       
    40 1. Get the file name and path from the ini file. 
       
    41 	-> If no file name is specified he create a file 
       
    42 	-> If no path is specified, use the session path. 
       
    43 2. Get the action that is required from the ini file
       
    44 3. Call the function that carries out that particular action
       
    45 
       
    46 @return EPass if test passes and EFail if test fails
       
    47 */ 
       
    48 TVerdict CBaseTestFat32ReadFile::doTestStepL()
       
    49 	{
       
    50 	SetTestStepResult(EFail);
       
    51 	TInt r = KErrNone;
       
    52 	_LIT(KFileName,"FileName");
       
    53 	_LIT(KCreatedFileName,"ReadTestFile.txt");
       
    54 	TBufC<255> fileName;
       
    55 	TPtrC16 filename = fileName;
       
    56 	_LIT(KPath,"Path");
       
    57 	TBufC<255> pathName;
       
    58 	TPtrC16 path = pathName;
       
    59 	_LIT(KReadAction,"ReadAction");
       
    60 	TBufC<255> readAction;
       
    61 	TPtrC16 readaction = readAction;
       
    62 	TBuf<255> fullPath;
       
    63 	TBool alright = GetStringFromConfig(ConfigSection(), KFileName, filename);
       
    64 	if(alright)
       
    65 		{
       
    66 		TBool alright2 = GetStringFromConfig(ConfigSection(), KPath, path);
       
    67 		if(alright2)
       
    68 			{
       
    69 			fullPath.Append(path);
       
    70 			}
       
    71 		else
       
    72 			{
       
    73 			fullPath.Append(iSessionPath);
       
    74 			}
       
    75 		fullPath.Append(filename);
       
    76 	
       
    77 		TBool alright3 = GetStringFromConfig(ConfigSection(), KReadAction, readaction);
       
    78 		if(alright3)
       
    79 			{
       
    80 			if (readaction == _L("OpenFile"))
       
    81 				{
       
    82 				r = OpenFile(fullPath);
       
    83 				}
       
    84 			if (readaction == _L("ReadFile"))
       
    85 				{
       
    86 				r = ReadFile(fullPath);
       
    87 				}
       
    88 			if (readaction == _L("GetModTime"))
       
    89 				{
       
    90 				INFO_PRINTF1(_L("Calling the function GetModTime"));
       
    91 				r = GetModTime(fullPath);
       
    92 				INFO_PRINTF2(_L("Finished the function GetModTime - r=%d"),r);
       
    93 				}
       
    94 			if (readaction == _L("GetModDate"))
       
    95 				{
       
    96 				INFO_PRINTF1(_L("Calling the function GetModDate"));
       
    97 				r = GetModDate(fullPath);
       
    98 				INFO_PRINTF2(_L("Finished the function GetModDate - r=%d"),r);
       
    99 				}
       
   100 		
       
   101 			if(r != KErrNone)
       
   102 				{
       
   103 				_LIT(KErrorReadFile, "Error with read action");
       
   104 				INFO_PRINTF1(KErrorReadFile);
       
   105 				SetTestStepResult(EFail);
       
   106 				return TestStepResult();
       
   107 				}
       
   108 			else
       
   109 				{
       
   110 				SetTestStepResult(EPass);
       
   111 				_LIT(KReadPass, "Read Action Passed");
       
   112 				INFO_PRINTF1(KReadPass);
       
   113 				return TestStepResult();
       
   114 				}
       
   115 			}
       
   116 		}
       
   117 	else
       
   118 		{
       
   119 		TInt r = TheFile.Replace(iTheFs,KCreatedFileName,EFileRead|EFileWrite);
       
   120 		if (r != KErrNone)
       
   121 			{
       
   122 			_LIT(KErrorCreateNewFile, "Cannot creat new file - Error code = %d");
       
   123 			INFO_PRINTF2(KErrorCreateNewFile,r);
       
   124 			SetTestStepResult(EFail);
       
   125 			return TestStepResult();	
       
   126 			}
       
   127 		else
       
   128 			{
       
   129 			TInt r = ReadFile(KCreatedFileName);
       
   130 			if(r != KErrNone)
       
   131 				{
       
   132 				_LIT(KErrorReadFile, "Error reading the file, Error Code = %d");
       
   133 				INFO_PRINTF2(KErrorReadFile, r);
       
   134 				SetTestStepResult(EFail);
       
   135 				return TestStepResult();
       
   136 				}
       
   137 			else
       
   138 				{
       
   139 				SetTestStepResult(EPass);
       
   140 				_LIT(KReadPass, "Read Passed");
       
   141 				INFO_PRINTF1(KReadPass);
       
   142 				return TestStepResult();
       
   143 				}
       
   144 			}
       
   145 		}
       
   146 	return TestStepResult();
       
   147 	}
       
   148 
       
   149 
       
   150 /** 
       
   151 Read the file
       
   152 
       
   153 @param aFile The name of the file to read 
       
   154 
       
   155 @return KErrNone if successfull
       
   156 */
       
   157 TInt CBaseTestFat32ReadFile::ReadFile(const TDesC16& aFile)
       
   158 	{
       
   159 	TBuf8<255> temp;
       
   160 	temp.Copy(aFile);
       
   161 	TInt r = KErrNone; 
       
   162 //	_LIT(KReadCheckCode,"ReadCheckCode");
       
   163 //	TInt readcheckcode;
       
   164 	r = TheFile.Open(iTheFs, aFile, EFileRead);
       
   165 	r = TheFile.Read(temp);
       
   166 	return r;
       
   167 	}
       
   168 
       
   169 /** 
       
   170 Open a file and check whether the error code returned is equal to that
       
   171 stated in the ini file
       
   172 
       
   173 @param aFile The name of the file to read 
       
   174 
       
   175 @return KErrNone if successfull
       
   176 */	
       
   177 TInt CBaseTestFat32ReadFile::OpenFile(const TDesC16& aFile)
       
   178 	{
       
   179 	TBuf8<255> temp;
       
   180 	temp.Copy(aFile);
       
   181 	_LIT(KReadCheckCode,"ReadCheckCode");
       
   182 	TInt readcheckcode;
       
   183 	TInt res = TheFile.Open(iTheFs, aFile, EFileRead);
       
   184 	TBool alright = GetIntFromConfig(ConfigSection(), KReadCheckCode, readcheckcode);
       
   185 	if(alright)
       
   186 		{
       
   187 		if (res == readcheckcode)
       
   188 			{
       
   189 			_LIT(KReadPass, "Check code for open file is correct res = %d");
       
   190 			INFO_PRINTF2(KReadPass, res);
       
   191 			return KErrNone;
       
   192 			}
       
   193 		else
       
   194 			{
       
   195 			_LIT(KReadFail, "Check code for open file is incorrect correct res = %d, correct return = %d");
       
   196 			INFO_PRINTF3(KReadFail, res, readcheckcode);
       
   197 			return KErrNone;
       
   198 			}
       
   199 			
       
   200 		}
       
   201 	else 
       
   202 		{
       
   203 		_LIT(KNoIni, "Unable to get ReadCheckCode from ini file");
       
   204 		INFO_PRINTF1(KNoIni);
       
   205 		return -1;
       
   206 		}
       
   207 
       
   208 	}
       
   209 
       
   210 /** 
       
   211 Check what error the RFs::Modified fuction should return from the ini file 
       
   212 and call RFs::Modified()
       
   213 
       
   214 @param aFile The name of the file to read 
       
   215 
       
   216 @return KErrNone if successfull
       
   217 */	
       
   218 TInt CBaseTestFat32ReadFile::GetModDate(const TDesC16& aFile)
       
   219 	{
       
   220 	TInt r = KErrNone;
       
   221 	TTime modifiedTime;
       
   222 	TBufC<9> checkDate;
       
   223 	TPtrC16 actualDate = checkDate;
       
   224 	_LIT(KCheckDate,"Date");
       
   225 	TBuf <255> date;
       
   226 	TBool alright = GetStringFromConfig(ConfigSection(), KCheckDate, actualDate);
       
   227 	if(alright)
       
   228 		{
       
   229 		INFO_PRINTF1(_L("Calling the function RFs::Modified within GetModTime"));
       
   230 		r = iTheFs.Modified(aFile, modifiedTime);
       
   231 		modifiedTime.FormatL(date, _L("%D%M%Y%1 %2 %3"));
       
   232 		INFO_PRINTF2(_L("Returned from RFs::Modified within the function GetModTime - r=%d"), r);
       
   233 		TPtrC16 readdate = date;
       
   234 		if (readdate == actualDate)
       
   235 			{
       
   236 			INFO_PRINTF1(_L("RFs::Modified returns the correct value "));
       
   237 			return KErrNone;
       
   238 			}
       
   239 		else 
       
   240 			{
       
   241 			INFO_PRINTF2(_L("RFs::Modified returns the incorrect value %S"), &date);
       
   242 			return -1;
       
   243 			}
       
   244 		}
       
   245 	return r;
       
   246 	}
       
   247 
       
   248 /** 
       
   249 Check what error the RFs::Modified fuction should return from the ini file 
       
   250 and call RFs::Modified()
       
   251 
       
   252 @param aFile The name of the file to read 
       
   253 
       
   254 @return KErrNone if successfull
       
   255 */
       
   256 TInt CBaseTestFat32ReadFile::GetModTime(const TDesC16& aFile)
       
   257 	{
       
   258 	TInt r = KErrNone;
       
   259 	TTime modifiedTime;
       
   260 	TBufC<9> checkTime;
       
   261 	TPtrC16 actualTime = checkTime;
       
   262 	_LIT(KCheckTime,"Time");
       
   263 	TBuf <255> time;
       
   264 	TBool alright = GetStringFromConfig(ConfigSection(), KCheckTime, actualTime);
       
   265 	if(alright)
       
   266 		{
       
   267 		INFO_PRINTF1(_L("Calling the function RFs::Modified within GetModTime"));
       
   268 		r = iTheFs.Modified(aFile, modifiedTime);
       
   269 		modifiedTime.FormatL(time, _L("%H%T%S"));
       
   270 		INFO_PRINTF2(_L("Returned from RFs::Modified within the function GetModTime - r=%d"), r);
       
   271 		TPtrC16 readtime = time;
       
   272 		if (readtime == actualTime)
       
   273 			{
       
   274 			INFO_PRINTF1(_L("RFs::Modified returns the correct value "));
       
   275 			return KErrNone;
       
   276 			}
       
   277 		else 
       
   278 			{
       
   279 			INFO_PRINTF2(_L("RFs::Modified returns the incorrect value %S"), &time);
       
   280 			return -1;
       
   281 			}
       
   282 		}
       
   283 		return r;
       
   284 	}