baseintegtests/baseintegrationtest/testsuites/fat32/src/basetestfat32clusterbound.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 // Attempts to access the disk outside the cluster bounds
       
    15 // 
       
    16 //
       
    17 
       
    18 
       
    19 #include "basetestfat32clusterbound.h"
       
    20 
       
    21 /**
       
    22 Class Constructor
       
    23 */		    
       
    24 CBaseTestFat32ClusterBound::CBaseTestFat32ClusterBound()
       
    25 	{
       
    26 	SetTestStepName(KTestStepClusterBound);
       
    27 	}
       
    28 	
       
    29 /**
       
    30 Class Destructor
       
    31 */	
       
    32 CBaseTestFat32ClusterBound::~CBaseTestFat32ClusterBound() 
       
    33 	{
       
    34 	}
       
    35 
       
    36 
       
    37 /** 
       
    38 This test should be performed once the disk has been filled to its max capacity. 
       
    39 Obtains the cluster bounds action from the configuration file and calls the function 
       
    40 that is required to be carried out
       
    41  
       
    42 @return EPass if test passes and EFail if test fails
       
    43 */ 		    
       
    44 TVerdict CBaseTestFat32ClusterBound::doTestStepL()
       
    45 	{
       
    46 	SetTestStepResult(EFail);
       
    47 	TInt r;
       
    48 	TBufC<20> clusterAction;
       
    49 	TPtrC16 clusteraction = clusterAction;
       
    50 	_LIT(KClusterAction,"ClusterAction");
       
    51 	TBool alright = GetStringFromConfig(ConfigSection(), KClusterAction, clusteraction);
       
    52 	if (alright)		
       
    53 		{			
       
    54 		if (clusteraction == _L("WriteToFile"))
       
    55 			{
       
    56 			r = TestClusterBoundsWriteFile();
       
    57 			if (r != KErrNone)
       
    58 				{
       
    59 				INFO_PRINTF1(_L("ClusterAction:WriteToFile failed"));
       
    60 				SetTestStepResult(EFail);
       
    61 				}
       
    62 			else
       
    63 				{
       
    64 				INFO_PRINTF1(_L("ClusterAction:WriteToFile passed"));
       
    65 				SetTestStepResult(EPass);
       
    66 				}
       
    67 			}
       
    68 		if (clusteraction == _L("CreateFiles"))
       
    69 			{
       
    70 			r = TestClusterBoundsCreateFiles();
       
    71 			if (r != KErrNone)
       
    72 				{
       
    73 				INFO_PRINTF1(_L("ClusterAction:CreateFiles failed"));
       
    74 				SetTestStepResult(EFail);
       
    75 				}
       
    76 			else
       
    77 				{
       
    78 				INFO_PRINTF1(_L("ClusterAction:CreateFiles passed"));
       
    79 				SetTestStepResult(EPass);
       
    80 				}
       
    81 			}
       
    82 		}
       
    83 	else 
       
    84 		{
       
    85 		INFO_PRINTF1(_L("No ClusterAction specified in ini file"));
       
    86 		SetTestStepResult(EFail);
       
    87 		}						
       
    88 	return TestStepResult();
       
    89 	}
       
    90 
       
    91 /** 
       
    92 Attepts to access out of bounds clusters by creating another file and 
       
    93 attempting to write to it.
       
    94 
       
    95 @return KErrNone if successfull, otherwise one of the other system-wide 
       
    96 error codes.
       
    97 */
       
    98 TInt CBaseTestFat32ClusterBound::TestClusterBoundsWriteFile()
       
    99 {
       
   100 	TInt r;
       
   101 	TVolumeInfo iInfo;
       
   102 	
       
   103 	TInt freeSpace;
       
   104 	RFile rFile;
       
   105 	
       
   106 	r = iTheFs.Volume(iInfo, CurrentDrive());
       
   107 	if(r != KErrNone)
       
   108 		{
       
   109 		INFO_PRINTF2(_L("Unable to obtain the volume information, error = %d"), r);
       
   110 		return r;
       
   111 		}
       
   112 	freeSpace = iInfo.iFree;
       
   113 	TBuf8<100> buffer3(freeSpace + 1); 
       
   114 	r = rFile.Replace(iTheFs, _L("TESTClusterBound.txt"), EFileWrite);
       
   115 	if(r != KErrNone)
       
   116 		{
       
   117 		INFO_PRINTF2(_L("Unable to create the file, error = %d"), r);
       
   118 		return r;
       
   119 		}				
       
   120 	r = rFile.Write(buffer3,freeSpace + 1);
       
   121 	if (r == KErrDiskFull)
       
   122 		{
       
   123 		INFO_PRINTF1(_L("Disk is Full - Attempting to access out of bounds clusters returns the correct error value"));
       
   124 		rFile.Close();
       
   125 		return KErrNone;
       
   126 		}
       
   127 	else 
       
   128 		{
       
   129 		INFO_PRINTF2(_L("Attempting to access out of bounds clusters returns the incorrect error value %d"), r);
       
   130 		rFile.Close();
       
   131 		return r;
       
   132 		}
       
   133 
       
   134 }
       
   135 
       
   136 /** 
       
   137 Attepts to access out of bounds clusters by creating empty files to fill
       
   138 the root directory and following this, attempting to create another empty file 
       
   139 
       
   140 @return KErrNone if successfull, otherwise one of the other system-wide 
       
   141 error codes.
       
   142 */
       
   143 TInt CBaseTestFat32ClusterBound::TestClusterBoundsCreateFiles()
       
   144 	{
       
   145 	RFile rFile;
       
   146 	_LIT(KFileName, "File%d.txt");
       
   147 	
       
   148 	TInt sizeOfShortDir = 16 * 4; //Short dir is 64 bytes long
       
   149 	TInt bytesPerSector = 512;
       
   150 	TInt sizeOfCluster = iBPB_SecPerClus * bytesPerSector;
       
   151 	TInt filesToCreate = sizeOfCluster / sizeOfShortDir;
       
   152 	filesToCreate = filesToCreate - 1;
       
   153 	
       
   154 	TInt r;
       
   155 	TInt i;
       
   156 	for (i = 0; i < filesToCreate; i++)
       
   157 		{
       
   158 		TBuf<20> fileName;
       
   159 		TInt fileNumber = i + 1;
       
   160 		fileName.Format(KFileName, fileNumber);
       
   161 		r= rFile.Replace(iTheFs,fileName , EFileWrite);
       
   162 		if (r == KErrDiskFull)
       
   163 		break;
       
   164 		rFile.Close(); 
       
   165 		}
       
   166 	
       
   167 
       
   168 	r = rFile.Replace(iTheFs, _L("TFile.txt") , EFileWrite);
       
   169 	if (r == KErrDiskFull)
       
   170 		{
       
   171 		INFO_PRINTF1(_L("Attempting to access out of bounds clusters returns the correct error value"));
       
   172 		return KErrNone;
       
   173 		}
       
   174 	else 
       
   175 		{
       
   176 		INFO_PRINTF2(_L("Attempting to access out of bounds clusters returns the incorrect error value %d"), r);
       
   177 		return r;
       
   178 		}
       
   179 	}