1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/baseapitest/basesvs/common/src/FileserverUtil.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,407 @@
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 "FileserverUtil.h"
1.23 +
1.24 +/**
1.25 + * @enum Constant Literals used.
1.26 + */
1.27 +
1.28 +/*@{*/
1.29 +
1.30 +// Parameters
1.31 +_LIT( KExpectedName, "expectedName" );
1.32 +_LIT( KExpectedSize, "expectedSize" );
1.33 +_LIT( KExpectedTime, "expectedTime" );
1.34 +_LIT( KExpectedUid1, "expectedUid1" );
1.35 +_LIT( KExpectedUid2, "expectedUid2" );
1.36 +_LIT( KExpectedUid3, "expectedUid3" );
1.37 +_LIT( KVolumeLabel, "volume_label" );
1.38 +_LIT( KVolumeSize, "volume_size");
1.39 +_LIT( KVolumeFreeSpace, "volume_free_space" );
1.40 +_LIT( KVolumeUniqueID, "volume_unique_id");
1.41 +_LIT( KExpectedMostDerivedUid, "expectedMostDerivedUid" );
1.42 +_LIT( KVolumeFileCacheFlags, "volume_File_Cache_Flags" );
1.43 +_LIT( KFileCacheReadEnabled, "EFileCacheReadEnabled" );
1.44 +_LIT( KFileCacheReadOn, "EFileCacheReadOn");
1.45 +_LIT( KFileCacheReadAheadEnabled, "EFileCacheReadAheadEnabled" );
1.46 +_LIT( KFileCacheReadAheadOn, "EFileCacheReadAheadOn" );
1.47 +_LIT( KFileCacheWriteEnabled, "EFileCacheWriteEnabled" );
1.48 +_LIT( KFileCacheWriteOn, "EFileCacheWriteOn" );
1.49 +
1.50 +// Attributes
1.51 +_LIT(KEntryAttNormalStr, "KEntryAttNormal");
1.52 +_LIT(KEntryAttReadOnlyStr, "KEntryAttReadOnly");
1.53 +_LIT(KEntryAttHiddenStr, "KEntryAttHidden");
1.54 +_LIT(KEntryAttSystemStr, "KEntryAttSystem");
1.55 +_LIT(KEntryAttVolumeStr, "KEntryAttVolume");
1.56 +_LIT(KEntryAttDirStr, "KEntryAttDir");
1.57 +_LIT(KEntryAttArchiveStr, "KEntryAttArchive");
1.58 +_LIT(KEntryAttXIPStr, "KEntryAttXIP");
1.59 +#if (!defined(__Symbian_OS_v9_1__))
1.60 +_LIT(KEntryAttRemoteStr, "KEntryAttRemote");
1.61 +_LIT(KEntryAttMaskFileSystemSpecificStr,"KEntryAttMaskFileSystemSpecific");
1.62 +#endif
1.63 +_LIT(KEntryAttMatchMaskStr, "KEntryAttMatchMask");
1.64 +_LIT(KEntryAttMaskSupportedStr, "KEntryAttMaskSupported");
1.65 +_LIT(KEntryAttMatchExclusiveStr, "KEntryAttMatchExclusive");
1.66 +_LIT(KEntryAttMatchExcludeStr, "KEntryAttMatchExclude");
1.67 +_LIT(KEntryAttAllowUidStr, "KEntryAttAllowUid");
1.68 +
1.69 +// constants
1.70 +const TInt KUid1Index = 0;
1.71 +const TInt KUid2Index = 1;
1.72 +const TInt KUid3Index = 2;
1.73 +
1.74 +const TInt KTimeFormatSize = 30;
1.75 +_LIT( KTimeFormat, "%D%M%Y%/0%1%/1%2%/2%3%/3 %-B%:0%J%:1%T%:2%S%:3%+B" );
1.76 +
1.77 +/*@}*/
1.78 +
1.79 +
1.80 +
1.81 +TBool FileserverUtil::VerifyTEntryDataFromIniL(CDataWrapper& aDataWrapper, const TDesC& aSection, TEntry& aEntry)
1.82 + {
1.83 + TBool ret = ETrue;
1.84 +
1.85 + aDataWrapper.INFO_PRINTF2(_L("Entry name = %S"), &aEntry.iName );
1.86 +
1.87 + TPtrC expectedStr;
1.88 + if ( aDataWrapper.GetStringFromConfig(aSection, KExpectedName(), expectedStr) )
1.89 + {
1.90 + if (aEntry.iName.CompareC(expectedStr, 0, NULL) != 0)
1.91 + {
1.92 + aDataWrapper.ERR_PRINTF3(_L("%S != %S"), &aEntry.iName, &expectedStr);
1.93 + ret = EFalse;
1.94 + }
1.95 + else
1.96 + {
1.97 + aDataWrapper.INFO_PRINTF3(_L("%S == %S"), &aEntry.iName, &expectedStr);
1.98 + }
1.99 + }
1.100 +
1.101 + TInt expectedInt = 0;
1.102 + if ( aDataWrapper.GetIntFromConfig(aSection, KExpectedSize(), expectedInt) )
1.103 + {
1.104 + aDataWrapper.INFO_PRINTF2(_L("Entry size = %d"), aEntry.iSize );
1.105 + if (aEntry.iSize != expectedInt)
1.106 + {
1.107 + aDataWrapper.ERR_PRINTF3(_L("Size from ini file not equal with size returned from function (%d != %d)"), expectedInt, aEntry.iSize);
1.108 + ret = EFalse;
1.109 + }
1.110 + }
1.111 +
1.112 + if ( aDataWrapper.GetStringFromConfig(aSection, KExpectedTime(), expectedStr) )
1.113 + {
1.114 + TBuf<KTimeFormatSize> dateString;
1.115 + aEntry.iModified.FormatL(dateString, KTimeFormat);
1.116 + aDataWrapper.INFO_PRINTF2(_L("Entry modified %S"), &dateString);
1.117 +
1.118 + TTime modificationTime;
1.119 + User::LeaveIfError(modificationTime.Set(expectedStr));
1.120 +
1.121 + if (aEntry.iModified != modificationTime)
1.122 + {
1.123 + aDataWrapper.ERR_PRINTF1(_L("Time from ini file not equal with time returned from function."));
1.124 + ret = EFalse;
1.125 + }
1.126 + }
1.127 +
1.128 + if ( aDataWrapper.GetIntFromConfig(aSection, KExpectedUid1(), expectedInt) )
1.129 + {
1.130 + TInt uid1 = aEntry.iType[KUid1Index].iUid;
1.131 + aDataWrapper.INFO_PRINTF2(_L("Entry UID1 = %d"), uid1 );
1.132 +
1.133 + if ( uid1 != expectedInt )
1.134 + {
1.135 + aDataWrapper.ERR_PRINTF3(_L("Entry UID1 %d != ini UID1 %d)"), uid1, expectedInt);
1.136 + ret = EFalse;
1.137 + }
1.138 + }
1.139 +
1.140 + if ( aDataWrapper.GetIntFromConfig(aSection, KExpectedUid2(), expectedInt) )
1.141 + {
1.142 + TInt uid2 = aEntry.iType[KUid2Index].iUid;
1.143 + aDataWrapper.INFO_PRINTF2(_L("Entry UID2 = %d"), uid2 );
1.144 +
1.145 + if ( uid2 != expectedInt )
1.146 + {
1.147 + aDataWrapper.ERR_PRINTF3(_L("Entry UID2 %d != ini UID1 %d)"), uid2, expectedInt);
1.148 + ret = EFalse;
1.149 + }
1.150 + }
1.151 +
1.152 + if ( aDataWrapper.GetIntFromConfig(aSection, KExpectedUid3(), expectedInt) )
1.153 + {
1.154 + TInt uid3 = aEntry.iType[KUid3Index].iUid;
1.155 + aDataWrapper.INFO_PRINTF2(_L("Entry UID3 = %d"), uid3 );
1.156 +
1.157 + if ( uid3 != expectedInt )
1.158 + {
1.159 + aDataWrapper.ERR_PRINTF3(_L("Entry UID3 %d != ini UID3 %d)"), uid3, expectedInt);
1.160 + ret = EFalse;
1.161 + }
1.162 + }
1.163 +
1.164 + if ( aDataWrapper.GetIntFromConfig(aSection, KExpectedMostDerivedUid(), expectedInt) )
1.165 + {
1.166 + TInt mostDerivedUid = aEntry.MostDerivedUid().iUid;
1.167 + aDataWrapper.INFO_PRINTF2(_L("MostDerivedUid = %d"), mostDerivedUid);
1.168 +
1.169 + if ( mostDerivedUid != expectedInt )
1.170 + {
1.171 + aDataWrapper.ERR_PRINTF3(_L("Entry MostDerivedUid %d != ini MostDerivedUid %d)"), mostDerivedUid, expectedInt);
1.172 + ret = EFalse;
1.173 + }
1.174 + }
1.175 +
1.176 +
1.177 + return ret;
1.178 + }
1.179 +
1.180 +
1.181 +
1.182 +TBool FileserverUtil::VerifyTVolumeInfoDataFromIniL(CDataWrapper& aDataWrapper, const TDesC& aSection, TVolumeInfo& aVolumeInfo)
1.183 + {
1.184 + TBool ret = ETrue;
1.185 +
1.186 + //Get volume name from config.
1.187 + TPtrC volumeLabel;
1.188 + if (aDataWrapper.GetStringFromConfig(aSection, KVolumeLabel(), volumeLabel))
1.189 + {
1.190 + //Checking that name of volume is equal to passed through config file.
1.191 + if (aVolumeInfo.iName.CompareC(volumeLabel, 0, NULL) != 0)
1.192 + {
1.193 + aDataWrapper.ERR_PRINTF1(_L("Volume name from ini file not equal with volume name returned from function"));
1.194 + ret = EFalse;
1.195 + }
1.196 + }
1.197 +
1.198 + TInt tmp;
1.199 + if (aDataWrapper.GetIntFromConfig(aSection, KVolumeSize(), tmp))
1.200 + {
1.201 + TInt64 volumeSize;
1.202 + volumeSize = tmp;
1.203 + //Checking that size of volume is equal to passed through config file.
1.204 + if (volumeSize != aVolumeInfo.iSize)
1.205 + {
1.206 + aDataWrapper.ERR_PRINTF1(_L("Volume size from ini file not equal with volume size returned from function"));
1.207 + ret = EFalse;
1.208 + }
1.209 + }
1.210 +
1.211 + if (aDataWrapper.GetIntFromConfig(aSection, KVolumeFreeSpace(), tmp))
1.212 + {
1.213 + TInt64 freeSpace;
1.214 + freeSpace = tmp;
1.215 + //Checking that free space of volume is equal to passed through config file.
1.216 + if (freeSpace != aVolumeInfo.iFree)
1.217 + {
1.218 + aDataWrapper.ERR_PRINTF1(_L("Volume free space amount from ini file not equal with volume free space amount returned from function"));
1.219 + ret = EFalse;
1.220 + }
1.221 + }
1.222 +
1.223 + if (aDataWrapper.GetIntFromConfig(aSection, KVolumeUniqueID(), tmp))
1.224 + {
1.225 + if(tmp<0)
1.226 + {
1.227 + aDataWrapper.ERR_PRINTF1(_L("ID in config should be not less than 0 "));
1.228 + ret = EFalse;
1.229 + }
1.230 + else
1.231 + {
1.232 + TUint volumeUniqueID;
1.233 + volumeUniqueID = (TUint)tmp;
1.234 + //Checking that Unique ID of volume is equal to passed through config file.
1.235 + if (volumeUniqueID != aVolumeInfo.iUniqueID)
1.236 + {
1.237 + aDataWrapper.ERR_PRINTF1(_L("Volume unique ID from ini file not equal with volume unique ID returned from function"));
1.238 + ret = EFalse;
1.239 + }
1.240 + }
1.241 + }
1.242 +
1.243 + TPtrC volumeFileCacheFlags;
1.244 + if (aDataWrapper.GetStringFromConfig(aSection, KVolumeFileCacheFlags(), volumeFileCacheFlags))
1.245 + {
1.246 + TFileCacheFlags tmpFileCacheFlags;
1.247 + if(volumeFileCacheFlags == KFileCacheReadEnabled())
1.248 + {
1.249 + tmpFileCacheFlags = EFileCacheReadEnabled;
1.250 + }
1.251 + else if(volumeFileCacheFlags == KFileCacheReadOn())
1.252 + {
1.253 + tmpFileCacheFlags = EFileCacheReadOn;
1.254 + }
1.255 + else if(volumeFileCacheFlags == KFileCacheReadAheadEnabled())
1.256 + {
1.257 + tmpFileCacheFlags = EFileCacheReadAheadEnabled;
1.258 + }
1.259 + else if(volumeFileCacheFlags == KFileCacheReadAheadOn())
1.260 + {
1.261 + tmpFileCacheFlags = EFileCacheReadAheadOn;
1.262 + }
1.263 + else if(volumeFileCacheFlags == KFileCacheWriteEnabled())
1.264 + {
1.265 + tmpFileCacheFlags = EFileCacheWriteEnabled;
1.266 + }
1.267 + else if(volumeFileCacheFlags == KFileCacheWriteOn())
1.268 + {
1.269 + tmpFileCacheFlags = EFileCacheWriteOn;
1.270 + }
1.271 + else
1.272 + {
1.273 + aDataWrapper.ERR_PRINTF1(_L("Volume file cache flags from ini file not equal with volume file cache flags returned from function"));
1.274 + ret = EFalse;
1.275 + }
1.276 +
1.277 + if(ret && (aVolumeInfo.iFileCacheFlags != tmpFileCacheFlags))
1.278 + {
1.279 + aDataWrapper.ERR_PRINTF1(_L("Volume file cache flags from ini file not equal with volume file cache flags returned from function"));
1.280 + ret = EFalse;
1.281 + }
1.282 + }
1.283 + return ret;
1.284 + }
1.285 +
1.286 +
1.287 +
1.288 +TBool FileserverUtil::GetAttMask(CDataWrapper& aDataWrapper, const TDesC& aSection, const TDesC& aParameterName, TUint& aAttMask)
1.289 + {
1.290 + TPtrC iniAttMaskStr;
1.291 + TBool ret = aDataWrapper.GetStringFromConfig(aSection, aParameterName, iniAttMaskStr);
1.292 + if ( ret )
1.293 + {
1.294 + if ( !ConvertToAttMask(iniAttMaskStr, aAttMask) )
1.295 + {
1.296 + TInt intTemp;
1.297 + ret = aDataWrapper.GetIntFromConfig(aSection, aParameterName, intTemp);
1.298 + if ( ret )
1.299 + {
1.300 + aAttMask = intTemp;
1.301 + }
1.302 + }
1.303 + }
1.304 +
1.305 + return ret;
1.306 + }
1.307 +
1.308 +
1.309 +
1.310 +TBool FileserverUtil::ConvertToAttMask(const TDesC& aAttMaskStr, TUint& aAttMask)
1.311 + {
1.312 + TBool ret = ETrue;
1.313 +
1.314 + if (aAttMaskStr == KEntryAttNormalStr)
1.315 + {
1.316 + aAttMask = KEntryAttNormal;
1.317 + }
1.318 + else if (aAttMaskStr == KEntryAttReadOnlyStr)
1.319 + {
1.320 + aAttMask = KEntryAttReadOnly;
1.321 + }
1.322 + else if (aAttMaskStr == KEntryAttHiddenStr)
1.323 + {
1.324 + aAttMask = KEntryAttHidden;
1.325 + }
1.326 + else if (aAttMaskStr == KEntryAttSystemStr)
1.327 + {
1.328 + aAttMask = KEntryAttSystem;
1.329 + }
1.330 + else if (aAttMaskStr == KEntryAttVolumeStr)
1.331 + {
1.332 + aAttMask = KEntryAttVolume;
1.333 + }
1.334 + else if (aAttMaskStr == KEntryAttDirStr)
1.335 + {
1.336 + aAttMask = KEntryAttDir;
1.337 + }
1.338 + else if (aAttMaskStr == KEntryAttArchiveStr)
1.339 + {
1.340 + aAttMask = KEntryAttArchive;
1.341 + }
1.342 + else if (aAttMaskStr == KEntryAttXIPStr)
1.343 + {
1.344 + aAttMask = KEntryAttXIP;
1.345 + }
1.346 +#if (!defined(__Symbian_OS_v9_1__))
1.347 + else if (aAttMaskStr == KEntryAttRemoteStr)
1.348 + {
1.349 + aAttMask = KEntryAttRemote;
1.350 + }
1.351 + else if (aAttMaskStr == KEntryAttMaskFileSystemSpecificStr)
1.352 + {
1.353 + aAttMask = KEntryAttMaskFileSystemSpecific;
1.354 + }
1.355 +#endif
1.356 + else if (aAttMaskStr == KEntryAttMatchMaskStr)
1.357 + {
1.358 + aAttMask = KEntryAttMatchMask;
1.359 + }
1.360 + else if (aAttMaskStr == KEntryAttMaskSupportedStr)
1.361 + {
1.362 + aAttMask = KEntryAttMaskSupported;
1.363 + }
1.364 + else if (aAttMaskStr == KEntryAttMatchExclusiveStr)
1.365 + {
1.366 + aAttMask = KEntryAttMatchExclusive;
1.367 + }
1.368 + else if (aAttMaskStr == KEntryAttMatchExcludeStr)
1.369 + {
1.370 + aAttMask = KEntryAttMatchExclude;
1.371 + }
1.372 + else if (aAttMaskStr == KEntryAttAllowUidStr)
1.373 + {
1.374 + aAttMask = KEntryAttAllowUid;
1.375 + }
1.376 + else if (aAttMaskStr.Match((_L("*|*"))) != KErrNotFound)
1.377 + {
1.378 + TUint tmpAttMask;
1.379 +
1.380 + TInt location = aAttMaskStr.Match(_L("*|*"));
1.381 + //Converting Left part of the data
1.382 + TPtrC left = aAttMaskStr.Left(location);
1.383 + if (ConvertToAttMask(left, tmpAttMask))
1.384 + {
1.385 + aAttMask = tmpAttMask;
1.386 + }
1.387 + else
1.388 + {
1.389 + ret = EFalse;
1.390 + }
1.391 +
1.392 + //Converting right data can be with another "|"
1.393 + TPtrC right = aAttMaskStr.Mid(location + 1);
1.394 + if (ConvertToAttMask(right, tmpAttMask))
1.395 + {
1.396 + aAttMask = aAttMask | tmpAttMask;
1.397 + }
1.398 + else
1.399 + {
1.400 + ret = EFalse;
1.401 + }
1.402 + }
1.403 + else
1.404 + {
1.405 + ret = EFalse;
1.406 + }
1.407 +
1.408 + return ret;
1.409 + }
1.410 +