1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/baseapitest/basesvs/validation/f32/sfsrv/src/T_FindFileData.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,464 @@
1.4 +/*
1.5 +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +#include "T_FindFileData.h"
1.23 +
1.24 +// Commands
1.25 +_LIT( KCmdDelete, "~" );
1.26 +_LIT( KCmdNew, "new" );
1.27 +_LIT( KCmdFile, "File" );
1.28 +_LIT( KCmdFind, "Find" );
1.29 +_LIT( KCmdFindByDir, "FindByDir" );
1.30 +_LIT( KCmdFindByPath, "FindByPath" );
1.31 +_LIT( KCmdFindWild, "FindWild" );
1.32 +_LIT( KCmdFindWildByDir, "FindWildByDir" );
1.33 +_LIT( KCmdFindWildByPath, "FindWildByPath" );
1.34 +_LIT( KCmdSetFindMask, "SetFindMask" );
1.35 +
1.36 +// Parameters
1.37 +_LIT( KParamFileName, "filename" );
1.38 +_LIT( KParamFileSession, "FileSession" );
1.39 +_LIT( KParamExpected, "expected" );
1.40 +_LIT( KParamPathList, "pathlist" );
1.41 +_LIT( KDriveAtt, "drive_att");
1.42 +_LIT( KDirWrapper, "dir_wrapper");
1.43 +
1.44 +// Utility variables
1.45 +_LIT(KDriveAttLocalStr, "KDriveAttLocal");
1.46 +_LIT(KDriveAttRomStr, "KDriveAttRom");
1.47 +_LIT(KDriveAttRedirectedStr, "KDriveAttRedirected");
1.48 +_LIT(KDriveAttSubstedStr, "KDriveAttSubsted");
1.49 +_LIT(KDriveAttInternalStr, "KDriveAttInternal");
1.50 +_LIT(KDriveAttRemovableStr, "KDriveAttRemovable");
1.51 +
1.52 +
1.53 +CT_FindFileData* CT_FindFileData::NewL()
1.54 +/**
1.55 +* Two phase constructor
1.56 +*/
1.57 + {
1.58 + CT_FindFileData* ret = new (ELeave) CT_FindFileData();
1.59 + CleanupStack::PushL( ret );
1.60 + ret->ConstructL();
1.61 + CleanupStack::Pop( ret );
1.62 + return ret;
1.63 + }
1.64 +
1.65 +CT_FindFileData::CT_FindFileData()
1.66 +: iFindFile(NULL)
1.67 +/**
1.68 +* Protected constructor. First phase construction
1.69 +*/
1.70 + {
1.71 + }
1.72 +
1.73 +void CT_FindFileData::ConstructL()
1.74 +/**
1.75 +* Protected constructor. Second phase construction
1.76 +*/
1.77 + {
1.78 + }
1.79 +
1.80 +CT_FindFileData::~CT_FindFileData()
1.81 +/**
1.82 +* Destructor.
1.83 +*/
1.84 + {
1.85 + DoCleanup();
1.86 + }
1.87 +
1.88 +TAny* CT_FindFileData::GetObject()
1.89 +/**
1.90 +* Return a pointer to the object that the data wraps
1.91 +*
1.92 +* @return pointer to the object that the data wraps
1.93 +*/
1.94 + {
1.95 + return iFindFile;
1.96 + }
1.97 +
1.98 +TBool CT_FindFileData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/ )
1.99 +/**
1.100 +* Process a command read from the ini file
1.101 +*
1.102 +* @param aCommand the command to process
1.103 +* @param aSection the entry in the ini file requiring the command to be processed
1.104 +*
1.105 +* @return ETrue if the command is processed
1.106 +*/
1.107 + {
1.108 + TBool retVal = ETrue;
1.109 +
1.110 + if ( aCommand == KCmdDelete )
1.111 + {
1.112 + DoCleanup();
1.113 + }
1.114 + else if ( aCommand == KCmdFile )
1.115 + {
1.116 + DoCmdFile( aSection );
1.117 + }
1.118 + else if ( aCommand == KCmdFind )
1.119 + {
1.120 + DoCmdFind( aSection );
1.121 + }
1.122 + else if ( aCommand == KCmdFindByDir )
1.123 + {
1.124 + DoCmdFindByDir( aSection );
1.125 + }
1.126 + else if ( aCommand == KCmdFindByPath )
1.127 + {
1.128 + DoCmdFindByPath( aSection );
1.129 + }
1.130 + else if ( aCommand == KCmdFindWild )
1.131 + {
1.132 + DoCmdFindWildL( aSection );
1.133 + }
1.134 + else if ( aCommand == KCmdFindWildByDir )
1.135 + {
1.136 + DoCmdFindWildByDirL( aSection );
1.137 + }
1.138 + else if ( aCommand == KCmdFindWildByPath )
1.139 + {
1.140 + DoCmdFindWildByPathL( aSection );
1.141 + }
1.142 + else if ( aCommand == KCmdNew )
1.143 + {
1.144 + DoCmdNew( aSection);
1.145 + }
1.146 + else if ( aCommand == KCmdSetFindMask )
1.147 + {
1.148 + DoCmdSetFindMask( aSection);
1.149 + }
1.150 + else
1.151 + {
1.152 + retVal = EFalse;
1.153 + }
1.154 +
1.155 + return retVal;
1.156 + }
1.157 +
1.158 +void CT_FindFileData::DoCleanup()
1.159 +/** Deletes TFindFile class instance */
1.160 + {
1.161 + INFO_PRINTF1( _L( "Delete TFindFile class instance" ) );
1.162 + delete iFindFile;
1.163 + iFindFile = NULL;
1.164 + }
1.165 +
1.166 +void CT_FindFileData::DoCmdFile( const TDesC& aSection )
1.167 +/** calls File() and comaperes the result with the expected */
1.168 + {
1.169 + TPtrC strResult;
1.170 + strResult.Set( iFindFile->File() );
1.171 + INFO_PRINTF2( _L( "File(): %S" ), &strResult );
1.172 +
1.173 + TPtrC strExpected;
1.174 + if ( GET_OPTIONAL_STRING_PARAMETER (KParamExpected, aSection, strExpected) )
1.175 + {
1.176 + if ( strExpected.CompareF(strResult) )
1.177 + {
1.178 + ERR_PRINTF3( _L( "File returned %S, expected %S") , &strResult, &strExpected );
1.179 + SetBlockResult( EFail );
1.180 + }
1.181 + }
1.182 + }
1.183 +
1.184 +void CT_FindFileData::DoCmdFind( const TDesC& /*aSection*/ )
1.185 +/** performs a search of a file using Find */
1.186 + {
1.187 + TInt result = iFindFile->Find();
1.188 +
1.189 + if( result != KErrNone)
1.190 + {
1.191 + ERR_PRINTF2( _L( "Find() return error = %d"), result );
1.192 + SetError(result);
1.193 + }
1.194 + }
1.195 +
1.196 +void CT_FindFileData::DoCmdFindByDir( const TDesC& aSection )
1.197 +/** performs a search of a file using FindByDir */
1.198 + {
1.199 + TPtrC fileName;
1.200 + if( GET_MANDATORY_STRING_PARAMETER( KParamFileName, aSection, fileName ) &&
1.201 + GET_MANDATORY_STRING_PARAMETER( KParamPathList, aSection, iPathList ) )
1.202 + {
1.203 + TInt err = iFindFile->FindByDir( fileName, iPathList );
1.204 +
1.205 + if( err != KErrNone)
1.206 + {
1.207 + ERR_PRINTF2( _L( "FindByDir() return error = %d"), err );
1.208 + SetError(err);
1.209 + }
1.210 + }
1.211 + }
1.212 +
1.213 +void CT_FindFileData::DoCmdFindByPath( const TDesC& aSection )
1.214 +/** performs a search of a file using FindByPath */
1.215 + {
1.216 + TPtrC fileName;
1.217 + if( GET_MANDATORY_STRING_PARAMETER( KParamFileName, aSection, fileName ) &&
1.218 + GET_MANDATORY_STRING_PARAMETER( KParamPathList, aSection, iPathList ) )
1.219 + {
1.220 + TInt err = iFindFile->FindByPath( fileName, &iPathList );
1.221 +
1.222 + if( err != KErrNone)
1.223 + {
1.224 + ERR_PRINTF2( _L( "FindByPath() return error = %d"), err );
1.225 + SetError(err);
1.226 + }
1.227 +
1.228 + }
1.229 +
1.230 + }
1.231 +
1.232 +void CT_FindFileData::DoCmdFindWildL( const TDesC& aSection)
1.233 +/** performs a search of a file using FindWild */
1.234 + {
1.235 + TPtrC dirWrapperName;
1.236 + if (GET_MANDATORY_STRING_PARAMETER(KDirWrapper, aSection, dirWrapperName))
1.237 + {
1.238 + CT_DirData *dirWrapper = NULL;
1.239 + TRAPD( error, dirWrapper = static_cast<CT_DirData*>(GetDataWrapperL(dirWrapperName)))
1.240 +
1.241 + if( dirWrapper && (error == KErrNone) )
1.242 + {
1.243 + CDir* dir = NULL;
1.244 + TInt err = iFindFile->FindWild( dir );
1.245 +
1.246 + if( err != KErrNone)
1.247 + {
1.248 + ERR_PRINTF2( _L( "FindWild() return error = %d"), err );
1.249 + SetError(err);
1.250 + }
1.251 + else
1.252 + {
1.253 + dirWrapper->SetObjectL(dir);
1.254 + }
1.255 + }
1.256 + else
1.257 + {
1.258 + ERR_PRINTF2( _L( "Wrong CDir wrapper name %S"), &dirWrapperName );
1.259 + SetBlockResult( EFail );
1.260 + }
1.261 + }
1.262 + }
1.263 +
1.264 +void CT_FindFileData::DoCmdFindWildByDirL( const TDesC& aSection )
1.265 +/** performs a search of a file using FindWildByDir */
1.266 + {
1.267 + TPtrC fileName;
1.268 + TPtrC dirWrapperName;
1.269 + if( GET_MANDATORY_STRING_PARAMETER( KParamFileName, aSection, fileName ) &&
1.270 + GET_MANDATORY_STRING_PARAMETER( KParamPathList, aSection, iPathList ) &&
1.271 + GET_MANDATORY_STRING_PARAMETER( KDirWrapper, aSection, dirWrapperName) )
1.272 + {
1.273 + CT_DirData *dirWrapper = NULL;
1.274 + TRAPD( error, dirWrapper = static_cast<CT_DirData*>(GetDataWrapperL(dirWrapperName)))
1.275 +
1.276 + if(dirWrapper && (error == KErrNone) )
1.277 + {
1.278 + CDir* dir = NULL;
1.279 + TInt err = iFindFile->FindWildByDir( fileName, iPathList, dir );
1.280 +
1.281 + if( err != KErrNone)
1.282 + {
1.283 + ERR_PRINTF2( _L( "FindWildByDir() return error = %d"), err );
1.284 + SetError(err);
1.285 + }
1.286 + else
1.287 + {
1.288 + dirWrapper->SetObjectL(dir);
1.289 + }
1.290 + }
1.291 + else
1.292 + {
1.293 + ERR_PRINTF2( _L( "Wrong CDir wrapper name %S"), &dirWrapperName );
1.294 + SetBlockResult( EFail );
1.295 + }
1.296 + }
1.297 + }
1.298 +
1.299 +void CT_FindFileData::DoCmdFindWildByPathL( const TDesC& aSection )
1.300 +/** performs a search of a file using FindWildByPath */
1.301 + {
1.302 + TPtrC fileName;
1.303 + TPtrC dirWrapperName;
1.304 + if( GET_MANDATORY_STRING_PARAMETER( KParamFileName, aSection, fileName ) &&
1.305 + GET_MANDATORY_STRING_PARAMETER( KParamPathList, aSection, iPathList ) &&
1.306 + GET_MANDATORY_STRING_PARAMETER( KDirWrapper, aSection, dirWrapperName) )
1.307 + {
1.308 + CT_DirData *dirWrapper = NULL;
1.309 + TRAPD( error, dirWrapper = static_cast<CT_DirData*>(GetDataWrapperL(dirWrapperName)))
1.310 +
1.311 + if( dirWrapper && (error == KErrNone))
1.312 + {
1.313 + CDir* dir = NULL;
1.314 + TInt err = iFindFile->FindWildByPath( fileName, &iPathList, dir );
1.315 +
1.316 + if( err != KErrNone)
1.317 + {
1.318 + ERR_PRINTF2( _L( "FindWildByPath() return error = %d"), err );
1.319 + SetError(err);
1.320 + }
1.321 + else
1.322 + {
1.323 + dirWrapper->SetObjectL(dir);
1.324 + }
1.325 + }
1.326 + else
1.327 + {
1.328 + ERR_PRINTF2( _L( "Wrong CDir wrapper name %S"), &dirWrapperName );
1.329 + SetBlockResult( EFail );
1.330 + }
1.331 + }
1.332 +
1.333 + }
1.334 +
1.335 +
1.336 +void CT_FindFileData::DoCmdNew( const TDesC& aSection )
1.337 +/** Creates new TFindFile class instance */
1.338 + {
1.339 + DoCleanup();
1.340 +
1.341 + TPtrC fsObjectName;
1.342 + if( GET_MANDATORY_STRING_PARAMETER( KParamFileSession, aSection, fsObjectName ) )
1.343 + {
1.344 + RFs* fsObject = NULL;
1.345 + TRAPD( err, fsObject = (RFs*)GetDataObjectL(fsObjectName));
1.346 + if ( err == KErrNone )
1.347 + {
1.348 + INFO_PRINTF1( _L( "Create new TFindFile class instance." ) );
1.349 + TRAP( err, iFindFile = new (ELeave) TFindFile( *fsObject ) );
1.350 + if ( err != KErrNone )
1.351 + {
1.352 + ERR_PRINTF3( _L( "new TFindFile(%S) error %d" ), &fsObjectName, err );
1.353 + SetBlockResult( EFail );
1.354 + }
1.355 + }
1.356 + else
1.357 + {
1.358 + ERR_PRINTF3( _L( "Unrecognized object name parameter value: %S. Error %d"), &fsObjectName, err );
1.359 + SetBlockResult( EFail );
1.360 + }
1.361 + }
1.362 + }
1.363 +
1.364 +void CT_FindFileData::DoCmdSetFindMask( const TDesC& aSection )
1.365 +/** Specify a combination of drive attributes */
1.366 + {
1.367 + TUint iniMask;
1.368 + if( GetDriveAttsFromConfig( aSection, iniMask ) )
1.369 + {
1.370 + INFO_PRINTF2( _L( "Mask is %d"), iniMask );
1.371 + TInt err = iFindFile->SetFindMask( iniMask );
1.372 +
1.373 + if ( err != KErrNone)
1.374 + {
1.375 + ERR_PRINTF2( _L( "SetFindMask return error = %d"), err );
1.376 + SetError( err );
1.377 + }
1.378 + else
1.379 + {
1.380 + INFO_PRINTF1( _L( "SetFindMask OK"));
1.381 + }
1.382 + }
1.383 + }
1.384 +
1.385 +
1.386 +TBool CT_FindFileData::ConvertToDriveAtts(const TDesC& aDriveAttStr, TUint& aDriveAtt)
1.387 +/** Convert string to mask */
1.388 + {
1.389 + TBool ret = ETrue;
1.390 + if ( aDriveAttStr==KDriveAttLocalStr )
1.391 + {
1.392 + aDriveAtt=KDriveAttLocal;
1.393 + }
1.394 + else if ( aDriveAttStr==KDriveAttRomStr )
1.395 + {
1.396 + aDriveAtt=KDriveAttRom;
1.397 + }
1.398 + else if ( aDriveAttStr==KDriveAttRedirectedStr )
1.399 + {
1.400 + aDriveAtt=KDriveAttRedirected;
1.401 + }
1.402 + else if ( aDriveAttStr==KDriveAttSubstedStr )
1.403 + {
1.404 + aDriveAtt=KDriveAttSubsted;
1.405 + }
1.406 + else if ( aDriveAttStr==KDriveAttInternalStr )
1.407 + {
1.408 + aDriveAtt=KDriveAttInternal;
1.409 + }
1.410 + else if ( aDriveAttStr==KDriveAttRemovableStr )
1.411 + {
1.412 + aDriveAtt=KDriveAttRemovable;
1.413 + }
1.414 + else
1.415 + {
1.416 + TInt location = aDriveAttStr.Match(_L("*|*"));
1.417 + if( location!=KErrNotFound )
1.418 + {
1.419 + //Converting Left part of the data
1.420 + TPtrC tempStr = aDriveAttStr.Left(location);
1.421 + ret=ConvertToDriveAtts(tempStr, aDriveAtt);
1.422 +
1.423 + //Converting right data can be with another "|"
1.424 + tempStr.Set(aDriveAttStr.Mid(location+1));
1.425 +
1.426 + TUint driveAttTmp;
1.427 + if ( ConvertToDriveAtts(tempStr, driveAttTmp) )
1.428 + {
1.429 + aDriveAtt=aDriveAtt|driveAttTmp;
1.430 + }
1.431 + else
1.432 + {
1.433 + ret=EFalse;
1.434 + }
1.435 + }
1.436 + else
1.437 + {
1.438 + ret=EFalse;
1.439 + }
1.440 + }
1.441 +
1.442 + return ret;
1.443 + }
1.444 +
1.445 +
1.446 +TBool CT_FindFileData::GetDriveAttsFromConfig(const TDesC& aSection, TUint& aDriveAtt)
1.447 + {
1.448 + TPtrC driveAttStr;
1.449 + TBool ret = GET_MANDATORY_STRING_PARAMETER(KDriveAtt(), aSection, driveAttStr);
1.450 + if ( ret )
1.451 + {
1.452 + aDriveAtt = 0;
1.453 + if ( !ConvertToDriveAtts(driveAttStr, aDriveAtt) )
1.454 + {
1.455 + TInt intTemp;
1.456 + ret=GET_MANDATORY_INT_PARAMETER(KDriveAtt(), aSection, intTemp);
1.457 + if ( ret )
1.458 + {
1.459 + aDriveAtt=intTemp;
1.460 + }
1.461 + }
1.462 + }
1.463 +
1.464 + return ret;
1.465 + }
1.466 +
1.467 +