messagingfw/msgtestfw/TestActions/Sms/src/CMtfTestActionSetDiskSpace.cpp
changeset 0 8e480a14352b
equal deleted inserted replaced
-1:000000000000 0:8e480a14352b
       
     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 "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 // __ACTION_INFO_BEGIN__ 
       
    15 // [Action Name]
       
    16 // LoadSmsSettings
       
    17 // [Action Parameters]
       
    18 // newFreeValue     input 		TInt
       
    19 // [Action Description]
       
    20 // Setting the Disk space
       
    21 // __ACTION_INFO_END__
       
    22 // 
       
    23 //
       
    24 
       
    25 #include <f32file.h>
       
    26 
       
    27 #include "CMtfTestCase.h"
       
    28 #include "CMtfTestActionParameters.h"
       
    29 #include "CMtfTestActionSetDiskSpace.h"
       
    30 
       
    31 // Location of directory for reserving disk space
       
    32 _LIT(KTempDiskSpaceDirName, "C:\\sms\\temp\\");
       
    33 
       
    34 
       
    35 /**
       
    36   Function		: NewL
       
    37   Description	: 
       
    38   @internalTechnology
       
    39   @param		: aTestCase - CMtfTestCase for the CMtfTestAction base class
       
    40   @param		: aActionParams - CMtfTestActionParameters 
       
    41   @return		: CMtfTestAction* - a base class pointer to the newly created CMtfTestActionSetDiskSpace object
       
    42   @pre none
       
    43   @post none
       
    44 */
       
    45 CMtfTestAction* CMtfTestActionSetDiskSpace::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters)
       
    46 	{
       
    47 	CMtfTestActionSetDiskSpace* self = new (ELeave) CMtfTestActionSetDiskSpace(aTestCase);
       
    48 	CleanupStack::PushL(self);
       
    49 	self->ConstructL(aActionParameters);
       
    50 	CleanupStack::Pop(self);
       
    51 	return self;
       
    52 	}
       
    53 
       
    54 /**
       
    55   Function		: CMtfTestActionSetDiskSpace
       
    56   Description	: Constructor
       
    57   @internalTechnology
       
    58   @param		: aTestCase - CMtfTestCase for the CMtfTestAction base class
       
    59   @return		: N/A
       
    60   @pre none
       
    61   @post none
       
    62 */
       
    63 CMtfTestActionSetDiskSpace::CMtfTestActionSetDiskSpace(CMtfTestCase& aTestCase) : CMtfSynchronousTestAction(aTestCase)
       
    64 	{
       
    65 	}
       
    66 	
       
    67 /**
       
    68   Function		: ~CMtfTestActionSetDiskSpace
       
    69   Description	: Destructor
       
    70   @internalTechnology
       
    71   @param		:
       
    72   @return		: 
       
    73   @pre 
       
    74   @post 
       
    75 */
       
    76 CMtfTestActionSetDiskSpace::~CMtfTestActionSetDiskSpace()
       
    77 	{
       
    78 	}
       
    79 
       
    80 /**
       
    81   Function		: ExecuteActionL
       
    82   Description	: Entry point for the this test action in the test framework
       
    83   @internalTechnology
       
    84   @param		: none
       
    85   @return		: void
       
    86   @pre none 
       
    87   @post none
       
    88 */
       
    89 void CMtfTestActionSetDiskSpace::ExecuteActionL()
       
    90 	{
       
    91 	TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionSetDiskSpace );
       
    92 	
       
    93 	RFs fs;
       
    94 	User::LeaveIfError(fs.Connect());
       
    95 
       
    96 	TInt newFreeValue = ObtainValueParameterL<TInt>(TestCase(),ActionParameters().Parameter(0));
       
    97 
       
    98 	TestCase().INFO_PRINTF2(_L("Setting Drive C free disk space to %ld bytes."), newFreeValue);
       
    99 
       
   100 	//
       
   101 	// Check the current disk space available level...
       
   102 	//
       
   103 	TVolumeInfo  volumeInfo;
       
   104 	
       
   105 	User::LeaveIfError(fs.Volume(volumeInfo, EDriveC));
       
   106 	TestCase().INFO_PRINTF2(_L("  Drive C currently has %ld bytes free."), volumeInfo.iFree);
       
   107 
       
   108 	//
       
   109 	// Check that this is possible...
       
   110 	//	
       
   111 	if (volumeInfo.iFree < newFreeValue)
       
   112 		{
       
   113 		TestCase().INFO_PRINTF1(_L("  Drive C already has too little free space!"));
       
   114 		User::Leave(KErrArgument);
       
   115 		}
       
   116 
       
   117 	//
       
   118 	// Ensure the temporary directory exists...
       
   119 	//
       
   120 	TInt ret;
       
   121 	
       
   122 	ret = fs.MkDir(KTempDiskSpaceDirName);
       
   123 	if (ret != KErrNone  &&  ret != KErrAlreadyExists)
       
   124 		{
       
   125 		User::Leave(ret);
       
   126 		}
       
   127 
       
   128 	//
       
   129 	// Work out how many files to create and their sizes. A full temp file is
       
   130 	// 1GB in size, the last temp file will handle the remainder. Then loop
       
   131 	// through and create them all...
       
   132 	//
       
   133 	TInt64  maxSizeOfTempFile  = (1024*1024*1024); 
       
   134 	TInt64  diskSpaceToReserve = volumeInfo.iFree - newFreeValue;
       
   135 	TInt64  numOfFullTempFiles = (diskSpaceToReserve / maxSizeOfTempFile);
       
   136 	TInt64  lastTempFileSize   = (diskSpaceToReserve % maxSizeOfTempFile);
       
   137 	TBuf<32>  tempFileName;
       
   138 	RFile  file;
       
   139 
       
   140 	for(TInt fileNum = 1;  fileNum <= numOfFullTempFiles;  fileNum++)
       
   141 		{
       
   142 		tempFileName.Copy(KTempDiskSpaceDirName);
       
   143 		tempFileName.AppendFormat(_L("reserved.%d"), fileNum);
       
   144 
       
   145 		TestCase().INFO_PRINTF3(_L("  Creating %S of %ld bytes."), &tempFileName, maxSizeOfTempFile);
       
   146 
       
   147 		User::LeaveIfError(file.Replace(fs, tempFileName, EFileWrite));
       
   148 		User::LeaveIfError(file.SetSize(maxSizeOfTempFile));	
       
   149 		file.Close();
       
   150 		}
       
   151 
       
   152 	if (lastTempFileSize > 0)
       
   153 		{
       
   154 		User::LeaveIfError(fs.Volume(volumeInfo, EDriveC));
       
   155 		TestCase().INFO_PRINTF2(_L("  Drive C now has %ld bytes free."), volumeInfo.iFree);
       
   156 		
       
   157 		if( lastTempFileSize > volumeInfo.iFree )
       
   158 			{	
       
   159 			lastTempFileSize = volumeInfo.iFree;
       
   160 			}
       
   161 		
       
   162 		
       
   163 		tempFileName.Copy(KTempDiskSpaceDirName);
       
   164 		tempFileName.AppendFormat(_L("reserved.%d"), numOfFullTempFiles+1);
       
   165 
       
   166 		TestCase().INFO_PRINTF3(_L("  Creating %S of %ld bytes."), &tempFileName, lastTempFileSize);
       
   167 
       
   168 		User::LeaveIfError(file.Replace(fs, tempFileName, EFileWrite));
       
   169 		User::LeaveIfError(file.SetSize(lastTempFileSize));	
       
   170 		file.Close();
       
   171 		}
       
   172 
       
   173 	//
       
   174 	// Recheck the free space now...
       
   175 	//	
       
   176 	User::LeaveIfError(fs.Volume(volumeInfo, EDriveC));
       
   177 	TestCase().INFO_PRINTF2(_L("  Drive C now has %ld bytes free."), volumeInfo.iFree);
       
   178 
       
   179 
       
   180 	fs.Close();
       
   181 
       
   182 	TestCase().INFO_PRINTF2( _L("Test Action %S completed."), &KTestActionSetDiskSpace );
       
   183 	TestCase().ActionCompletedL( *this );	
       
   184 	}
       
   185 
       
   186