baseintegtests/baseintegrationtest/testsuites/sd/src/sdbase.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) 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 // sdserver.cpp
       
    15 // Base class for all test steps
       
    16 // 
       
    17 //
       
    18 
       
    19 #include "sdbase.h"
       
    20 
       
    21 /** 
       
    22 Initialises the D_MMCID device driver that will let us access the very first
       
    23 sectors of the memory card. This driver is located in base/e32utils/pccd.
       
    24 
       
    25 @param none
       
    26 
       
    27 @return ETrue if OK, EFalse if not
       
    28 */
       
    29 
       
    30 TBool CBaseTestSDBase::InitDeviceDriver()
       
    31 	{
       
    32 	TInt r;
       
    33 	
       
    34 	// Load Device Driver that will let us read the hidden sectors
       
    35 	r = User::LoadLogicalDevice(_L("D_MMCIF"));
       
    36 	if (r == KErrNone)
       
    37 		{
       
    38 		INFO_PRINTF1(_L("D_MMCIF.LDD loaded"));
       
    39 		}
       
    40 	else if (r == KErrAlreadyExists)
       
    41 		{
       
    42 		INFO_PRINTF1(_L("D_MMCIF.LDD already loaded"));
       
    43 		}
       
    44 	else
       
    45 		{
       
    46 		ERR_PRINTF2(_L("Could not load D_MMCIF.LDD. Return value: %d"), r);
       
    47 		return EFalse;
       
    48 		}
       
    49 	
       
    50 	iDriver.Close();
       
    51 	r = iDriver.Open(0, iDriver.VersionRequired());
       
    52 	if (r != KErrNone)
       
    53 		{
       
    54 		ERR_PRINTF2(_L("Could not open device driver. Return value: %d"), r);
       
    55 		return EFalse;
       
    56 		}
       
    57 	
       
    58 	TRequestStatus rs;
       
    59 	iDriver.PwrUpAndInitStack(rs);
       
    60 	User::WaitForRequest(rs);
       
    61 	if (rs.Int() != KErrNone)
       
    62 		{
       
    63 		ERR_PRINTF2(_L("Could not power up SD stack. Return value: %d"), rs.Int());
       
    64 		return EFalse;
       
    65 		}
       
    66 	
       
    67 	TUint cardsPresentMask;
       
    68 	r = iDriver.StackInfo(cardsPresentMask);
       
    69 	if (r != KErrNone)
       
    70 		{
       
    71 		ERR_PRINTF2(_L("Could not determine number of present cards. Return value: %d"), r);
       
    72 		return EFalse;
       
    73 		}
       
    74 	
       
    75 	iDriver.SelectCard(0);
       
    76 	
       
    77 	r = iDriver.CardInfo(iCardInfo);
       
    78 	if (r != KErrNone)
       
    79 		{
       
    80 		ERR_PRINTF2(_L("Could not get card info. Return value: %d"), r);
       
    81 		return EFalse;
       
    82 		}
       
    83 	iCardSizeInSectors = I64LOW(iCardInfo.iCardSizeInBytes >> KSectorSizeShift);
       
    84 	return ETrue;
       
    85 	}
       
    86 
       
    87 /** 
       
    88 Starts a session with the File Server.
       
    89 
       
    90 @param none
       
    91 
       
    92 @return ETrue if OK, EFalse if not
       
    93 */
       
    94 
       
    95 TBool CBaseTestSDBase::InitFileServer()
       
    96 	{
       
    97 	// Connect to the File Server
       
    98 	TInt r;
       
    99 	r = iFs.Connect();
       
   100 	if (r != KErrNone)
       
   101 		{
       
   102 		ERR_PRINTF2(_L("Could not connect to the File Server. Return value: %d"), r);
       
   103 		return EFalse;
       
   104 		}
       
   105 	return ETrue;
       
   106 	}
       
   107 
       
   108 /** 
       
   109 Instantiate a CFileMan object.
       
   110 
       
   111 @param none
       
   112 
       
   113 @return ETrue if OK, EFalse if not
       
   114 */
       
   115 
       
   116 TBool CBaseTestSDBase::InitFileMan()
       
   117 	{
       
   118 	// Instantiate a File Manager
       
   119 	TInt r;
       
   120 	if (iFileMan != NULL)
       
   121 		{
       
   122 		ERR_PRINTF1(_L("iFileMan already instantiated"));
       
   123 		return EFalse;
       
   124 		}
       
   125 	TRAP(r, iFileMan = CFileMan::NewL(iFs));
       
   126 	if (r != KErrNone)
       
   127 		{
       
   128 		ERR_PRINTF2(_L("Could not instantiate CFileMan. Return value: %d"), r);
       
   129 		return EFalse;
       
   130 		}
       
   131 	return ETrue;
       
   132 	}
       
   133 
       
   134 /** 
       
   135 Read drive to test from INI file
       
   136 
       
   137 @param none
       
   138 
       
   139 @return ETrue if OK, EFalse if not
       
   140 */
       
   141 TBool CBaseTestSDBase::InitDriveLetter()
       
   142 	{
       
   143 	// Find out which drive is the removable media drive
       
   144 	TPtrC ptrDriveLetter;
       
   145 	TChar letter;
       
   146 	_LIT(KDriveLetter, "DriveLetter");
       
   147 	if (!GetStringFromConfig(_L("DefaultSection"), KDriveLetter, ptrDriveLetter))
       
   148 		{
       
   149 		ERR_PRINTF1(_L("INI File read error"));
       
   150 		return EFalse;
       
   151 		}
       
   152 	letter = ptrDriveLetter[0];
       
   153 	letter.UpperCase();
       
   154 	if ((letter >= 'A') && (letter <= 'Z'))
       
   155 		{
       
   156 		iDrive = (TUint) letter - 'A';
       
   157 		INFO_PRINTF2(_L("Drive to test: %c"), iDrive + 'A');
       
   158 		}
       
   159 	else
       
   160 		{
       
   161 		ERR_PRINTF2(_L("Invalid drive letter: %c"), ptrDriveLetter[0]);
       
   162 		return EFalse;
       
   163 		}
       
   164 	return ETrue;
       
   165 	}
       
   166 
       
   167 TVerdict CBaseTestSDBase::doTestStepPostambleL()
       
   168 	{
       
   169 	if (iFileMan != NULL)
       
   170 		{
       
   171 		delete iFileMan;
       
   172 		}
       
   173 	iFs.Close();
       
   174 	User::FreeLogicalDevice(_L("MmcIf"));
       
   175 	return TestStepResult();
       
   176 	}
       
   177 
       
   178 /** 
       
   179 Read a sector from the memory card
       
   180 
       
   181 @param aSector is the sector number
       
   182 @param aSectorBuffer 512-byte buffer the sector contents will be copied to
       
   183 
       
   184 @return KErrNone if successful, otherwise any other system-wide error coed
       
   185 */
       
   186 	
       
   187 TInt CBaseTestSDBase::ReadSector(TInt aSector, TDes8& aSectorBuffer)
       
   188 	{
       
   189 	TRequestStatus rs;
       
   190 	iDriver.ReadSector(rs, aSector, aSectorBuffer);
       
   191 	User::WaitForRequest(rs);
       
   192 	if (rs.Int() == KErrNone)
       
   193 		{
       
   194 		INFO_PRINTF3(_L("Read sector %08xh (%d)"), aSector, aSector);
       
   195 		}
       
   196 	else
       
   197 		{
       
   198 		ERR_PRINTF4(_L("Error during Read sector %08xh (%d): %d"), aSector, aSector, rs.Int());
       
   199 		}
       
   200 	return(rs.Int());
       
   201 	}
       
   202 
       
   203 /** 
       
   204 Write a sector to the memory card
       
   205 
       
   206 @param aSector is the sector number
       
   207 @param aSectorBuffer 512-byte buffer containing the data to write on this sector
       
   208 
       
   209 @return KErrNone if successful, otherwise any other system-wide error coed
       
   210 */
       
   211 
       
   212 TInt CBaseTestSDBase::WriteSector(TInt aSector, const TDesC8& aSectorBuffer)
       
   213 	{
       
   214 	TRequestStatus rs;
       
   215 	iDriver.WriteSector(rs, aSector, aSectorBuffer);
       
   216 	User::WaitForRequest(rs);
       
   217 	if (rs.Int() == KErrNone)
       
   218 		{
       
   219 		INFO_PRINTF3(_L("Write sector %08xh (%d)"), aSector, aSector);
       
   220 		}
       
   221 	else
       
   222 		{
       
   223 		ERR_PRINTF4(_L("Error during Write sector %08xh (%d): %d"), aSector, aSector, rs.Int());
       
   224 		}
       
   225 	return(rs.Int());
       
   226 	}