os/persistentdata/featuremgmt/featureregistry/test/helper/maketestconfig/maketestconfig.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/featuremgmt/featureregistry/test/helper/maketestconfig/maketestconfig.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,434 @@
1.4 +// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// Puts some test feature registry configuration files - some corrupt, others legal -
1.18 +// in the C: private data cage of the setup executable. Sets up test RProperties.
1.19 +//
1.20 +//
1.21 +
1.22 +/**
1.23 + @file
1.24 + @internalComponent
1.25 + @test
1.26 +*/
1.27 +
1.28 +#include <e32cmn.h>
1.29 +#include <e32base.h>
1.30 +#include <f32file.h>
1.31 +#include <e32property.h>
1.32 +#include <featreg.h>
1.33 +#include "featregcmn.h"
1.34 +#include "maketestconfig.h"
1.35 +
1.36 +// names of test configurations that can be set up by this exe, specified as
1.37 +// command-line option:
1.38 +_LIT(KFeatRegTestConfig_force_setup, "force_setup");
1.39 +_LIT(KFeatRegTestConfig_reset, "reset");
1.40 +_LIT(KFeatRegTestConfig_corrupt_missing, "corrupt_missing");
1.41 +_LIT(KFeatRegTestConfig_corrupt_noheader, "corrupt_noheader");
1.42 +_LIT(KFeatRegTestConfig_corrupt_incompleteheader, "corrupt_incompleteheader");
1.43 +_LIT(KFeatRegTestConfig_corrupt_invalidtypeprefix, "corrupt_invalidtypeprefix");
1.44 +_LIT(KFeatRegTestConfig_corrupt_badversionnumber, "corrupt_badversionnumber");
1.45 +_LIT(KFeatRegTestConfig_corrupt_toomuchdata, "corrupt_toomuchdata");
1.46 +_LIT(KFeatRegTestConfig_corrupt_toolittledata, "corrupt_toolittledata");
1.47 +_LIT(KFeatRegTestConfig_corrupt_entryoutoforder, "corrupt_entryoutoforder");
1.48 +_LIT(KFeatRegTestConfig_corrupt_entryrepeated, "corrupt_entryrepeated");
1.49 +_LIT(KFeatRegTestConfig_corrupt_badrange, "corrupt_badrange");
1.50 +_LIT(KFeatRegTestConfig_valid_nofeatures, "valid_nofeatures");
1.51 +_LIT(KFeatRegTestConfig_valid_small, "valid_small");
1.52 +_LIT(KFeatRegTestConfig_valid_large, "valid_large");
1.53 +_LIT(KFeatRegTestConfig_valid_perf, "valid_perf_");
1.54 +
1.55 +
1.56 +TConfigFileName ConfigFileName;
1.57 +
1.58 +
1.59 +static TInt DefineTestFlagProperty()
1.60 + {
1.61 + RProcess thisProcess;
1.62 + // sanity check that feature property category in common header equals SID of this process
1.63 + ASSERT(KFeaturePropCat == thisProcess.SecureId());
1.64 + TSecurityPolicy readPolicy(TSecurityPolicy::EAlwaysPass);
1.65 + TSecurityPolicy writePolicy(thisProcess.SecureId());
1.66 + TInt result = RProperty::Define(KFeatRegConfigTestKey, RProperty::EInt, readPolicy, writePolicy);
1.67 + if (result == KErrAlreadyExists)
1.68 + {
1.69 + result = KErrNone;
1.70 + }
1.71 + return result;
1.72 + }
1.73 +
1.74 +static TInt WriteTestConfigFile(TUint32* aData, TInt aSize)
1.75 + {
1.76 + RFs fs;
1.77 + TInt result = fs.Connect();
1.78 + if (result == KErrNone)
1.79 + {
1.80 + result = fs.MkDirAll(ConfigFileName);
1.81 + if ((result == KErrNone) || (result == KErrAlreadyExists))
1.82 + {
1.83 + RFile cfgFile;
1.84 + result = cfgFile.Replace(fs, ConfigFileName, EFileWrite|EFileStream);
1.85 + if (result == KErrNone)
1.86 + {
1.87 + result = cfgFile.Write(TPtrC8(reinterpret_cast<const TUint8 *>(aData), aSize));
1.88 + cfgFile.Close();
1.89 + }
1.90 + }
1.91 + fs.Close();
1.92 + }
1.93 + if (result == KErrNone)
1.94 + {
1.95 + result = DefineTestFlagProperty();
1.96 + }
1.97 + return result;
1.98 + }
1.99 +
1.100 +TInt E32Main()
1.101 + {
1.102 + __UHEAP_MARK;
1.103 +
1.104 + TFileName configName;
1.105 + User::CommandLine(configName);
1.106 +
1.107 + // construct config filename
1.108 + GetSystemDrivePath(ConfigFileName);
1.109 +
1.110 + // always delete feature property so featreg.dll re-loads it (note this
1.111 + // executable has same UID3 as featreg setup:
1.112 + TInt result = RProperty::Delete(KFeaturePropKey);
1.113 + if (result == KErrNotFound)
1.114 + {
1.115 + result = KErrNone;
1.116 + }
1.117 + if (result != KErrNone)
1.118 + {
1.119 + goto cleanupReturn;
1.120 + }
1.121 +
1.122 + //--------------------
1.123 + if (configName.Find(KFeatRegTestConfig_force_setup) >= 0)
1.124 + {
1.125 + // force setup
1.126 + // nothing to do; just ensures feature property is deleted so setup is run
1.127 + }
1.128 + //--------------------
1.129 + else if (configName.Find(KFeatRegTestConfig_reset) >= 0)
1.130 + {
1.131 + // reset
1.132 + // delete "test-flag" property so setup looks at true config info
1.133 + result = RProperty::Delete(KFeatRegConfigTestKey);
1.134 + if (result == KErrNotFound)
1.135 + {
1.136 + result = KErrNone;
1.137 + }
1.138 + }
1.139 + //--------------------
1.140 + else if (configName.Find(KFeatRegTestConfig_corrupt_missing) >= 0)
1.141 + {
1.142 + // no header
1.143 + RFs fs;
1.144 + result = fs.Connect();
1.145 + if (result == KErrNone)
1.146 + {
1.147 + result = fs.Delete(ConfigFileName);
1.148 + if ((result == KErrNotFound) || (result == KErrPathNotFound))
1.149 + {
1.150 + result = KErrNone;
1.151 + }
1.152 + fs.Close();
1.153 + }
1.154 + if (result == KErrNone)
1.155 + {
1.156 + result = DefineTestFlagProperty();
1.157 + }
1.158 + }
1.159 + //--------------------
1.160 + else if (configName.Find(KFeatRegTestConfig_corrupt_noheader) >= 0)
1.161 + {
1.162 + // no header
1.163 + result = WriteTestConfigFile(NULL, 0);
1.164 + }
1.165 + //--------------------
1.166 + else if (configName.Find(KFeatRegTestConfig_corrupt_incompleteheader) >= 0)
1.167 + {
1.168 + // header is not complete
1.169 + TUint32 fileData1[] =
1.170 + {
1.171 + validTypePrefix,
1.172 + 0, // version number, must be zero
1.173 + 0 // entry count
1.174 + // range count: missing
1.175 + };
1.176 + result = WriteTestConfigFile(fileData1, sizeof(fileData1));
1.177 + }
1.178 + //--------------------
1.179 + else if (configName.Find(KFeatRegTestConfig_corrupt_invalidtypeprefix) >= 0)
1.180 + {
1.181 + // invalid type prefix
1.182 + TUint32 fileData1[] =
1.183 + {
1.184 + invalidTypePrefix, // should be validTypePrefix
1.185 + 0, // version number
1.186 + 0, // entry count
1.187 + 0 // range count
1.188 + };
1.189 + result = WriteTestConfigFile(fileData1, sizeof(fileData1));
1.190 + }
1.191 +
1.192 + //--------------------
1.193 + else if (configName.Find(KFeatRegTestConfig_corrupt_badversionnumber) >= 0)
1.194 + {
1.195 + // bad file version header
1.196 + TUint32 fileData1[] =
1.197 + {
1.198 + validTypePrefix,
1.199 + 1, // version number: not zero
1.200 + 0, // entry count
1.201 + 0 // range count
1.202 + };
1.203 + result = WriteTestConfigFile(fileData1, sizeof(fileData1));
1.204 + }
1.205 + //--------------------
1.206 + else if (configName.Find(KFeatRegTestConfig_corrupt_toomuchdata) >= 0)
1.207 + {
1.208 + // corrupt: config file contains more data than required by header
1.209 + TUint32 fileData2[] =
1.210 + {
1.211 + validTypePrefix,
1.212 + 0, // version number, must be zero
1.213 + 0, // entry count
1.214 + 0, // range count
1.215 + 0, // unexpected extra data
1.216 + };
1.217 + result = WriteTestConfigFile(fileData2, sizeof(fileData2));
1.218 + }
1.219 + //--------------------
1.220 + else if (configName.Find(KFeatRegTestConfig_corrupt_toolittledata) >= 0)
1.221 + {
1.222 + // corrupt: config file contains less data than required by header
1.223 + TUint32 fileData3[] =
1.224 + {
1.225 + validTypePrefix,
1.226 + 0, // version number, must be zero
1.227 + 2, // entry count
1.228 + 1 // range count
1.229 + // should be 2 entries (2 words each) and 1 default range (2 words each)
1.230 + };
1.231 + result = WriteTestConfigFile(fileData3, sizeof(fileData3));
1.232 + }
1.233 + //--------------------
1.234 + else if (configName.Find(KFeatRegTestConfig_corrupt_entryoutoforder) >= 0)
1.235 + {
1.236 + // corrupt: feature entries not ordered from lowest to highest UID
1.237 + TUint32 fileData4[] =
1.238 + {
1.239 + validTypePrefix,
1.240 + 0, // version number, must be zero
1.241 + 3, // entry count
1.242 + 0, // range count
1.243 + 2, // Feature UID = 2
1.244 + 1, // status low-bit set -> present
1.245 + 5, // Feature UID = 5
1.246 + 1, // status low-bit set -> present
1.247 + 3, // Feature UID = 3: Feature UIDs not in strictly increasing order
1.248 + 1 // status low-bit set -> present
1.249 + };
1.250 + result = WriteTestConfigFile(fileData4, sizeof(fileData4));
1.251 + }
1.252 + //--------------------
1.253 + else if (configName.Find(KFeatRegTestConfig_corrupt_entryrepeated) >= 0)
1.254 + {
1.255 + // corrupt: repeated feature UID
1.256 + TUint32 fileData5[] =
1.257 + {
1.258 + validTypePrefix,
1.259 + 0, // version number, must be zero
1.260 + 3, // entry count
1.261 + 0, // range count
1.262 + 2, // Feature UID = 2
1.263 + 1, // status low-bit set -> present
1.264 + 5, // Feature UID = 5
1.265 + 1, // status low-bit set -> present
1.266 + 5, // Feature UID = 5: Feature UID repeated
1.267 + 1, // status low-bit set -> present
1.268 + };
1.269 + result = WriteTestConfigFile(fileData5, sizeof(fileData5));
1.270 + }
1.271 + //--------------------
1.272 + else if (configName.Find(KFeatRegTestConfig_corrupt_badrange) >= 0)
1.273 + {
1.274 + // corrupt: default-supported range not listed in order lowUid-highUid
1.275 + TUint32 fileData6[] =
1.276 + {
1.277 + validTypePrefix,
1.278 + 0, // version number, must be zero
1.279 + 1, // entry count
1.280 + 2, // range count
1.281 + 2, // Feature UID = 2
1.282 + 1, // status low-bit set -> present
1.283 + 5, // Range 1 low UID
1.284 + 9, // high UID
1.285 + 88, // Range 2 low UID
1.286 + 76 // high UID: not >= lowUID
1.287 + };
1.288 + result = WriteTestConfigFile(fileData6, sizeof(fileData6));
1.289 + }
1.290 + //--------------------
1.291 + else if (configName.Find(KFeatRegTestConfig_valid_nofeatures) >= 0)
1.292 + {
1.293 +#ifndef SYMBIAN_FEATURE_MANAGER
1.294 + // valid: no features
1.295 + TUint32 fileData7[] =
1.296 + {
1.297 + validTypePrefix,
1.298 + 0, // version number, must be zero
1.299 + 0, // entry count
1.300 + 0 // range count
1.301 + };
1.302 +#else
1.303 + // valid: no features
1.304 + TUint32 fileData7[] =
1.305 + {
1.306 + validTypePrefix,
1.307 + 0, // version number, must be zero
1.308 + 0, // entry count
1.309 + 1, // range count: we have to provide at least one range, otherwise the file will be corrupt from the FeatMgr perspective
1.310 + KFeatRegTest_DummyRangeId,
1.311 + KFeatRegTest_DummyRangeId
1.312 + };
1.313 +#endif
1.314 + result = WriteTestConfigFile(fileData7, sizeof(fileData7));
1.315 + }
1.316 + //--------------------
1.317 + else if (configName.Find(KFeatRegTestConfig_valid_small) >= 0)
1.318 + {
1.319 + // valid: few features, one default=supported range
1.320 + TUint32 fileData8[] =
1.321 + {
1.322 + validTypePrefix,
1.323 + 0, // version number, must be zero
1.324 + 2, // entry count
1.325 + 1, // range count
1.326 + KFeatRegTest1_02_SNFeatId, // 1. feature UID
1.327 + KFeatRegTest1_02_SNFeatSt, // status word; low bit set = supported
1.328 + KFeatRegTest1_05_URFeatId, // 2. feature UID
1.329 + KFeatRegTest1_05_URFeatSt, // status word; low-bit not set = not supported
1.330 + KFeatRegTest1_03_LoFeatId, // low-feature-UID of default=supported range
1.331 + KFeatRegTest1_04_HiFeatId // high-feature-UID of default=supported range
1.332 + };
1.333 + result = WriteTestConfigFile(fileData8, sizeof(fileData8));
1.334 + }
1.335 + //--------------------
1.336 + else if (configName.Find(KFeatRegTestConfig_valid_large) >= 0)
1.337 + {
1.338 + // valid: many features, several default=supported ranges
1.339 + TUint32 fileData9[2 + 2*KFeatRegTest2_04_numTestFeatures + 2*KFeatRegTest2_07_rangeCount];
1.340 + TInt j = sizeof(TFeatureHeader) / sizeof(TUint32);
1.341 + TInt entryCount = 0;
1.342 + TUint32 id = KFeatRegTest2_01_FirstId;
1.343 + // feature entries
1.344 + for (TInt e = KFeatRegTest2_04_numTestFeatures; e > 0; e--)
1.345 + {
1.346 + TBool featureSupported = !(id & KFeatRegTest2_05_NotSupportedBit);
1.347 + TBool inDefaultSupportedRange = id & KFeatRegTest2_06_DefSupportedBit;
1.348 + // only need to list feature if support differs from default ranges
1.349 + if (featureSupported && (!inDefaultSupportedRange))
1.350 + {
1.351 + fileData9[j++] = id;
1.352 + fileData9[j++] = RFeatureRegistry::EStatusSupportBit;
1.353 + entryCount++;
1.354 + }
1.355 + else if ((!featureSupported) && inDefaultSupportedRange)
1.356 + {
1.357 + fileData9[j++] = id;
1.358 + fileData9[j++] = 0; // specifically listed as not supported
1.359 + entryCount++;
1.360 + }
1.361 + id += KFeatRegTest2_03_IncrId;
1.362 + }
1.363 + // default=supported ranges
1.364 + TUint32 lowId = KFeatRegTest2_06_DefSupportedBit;
1.365 + for (TUint r = 0; r < KFeatRegTest2_07_rangeCount; r++)
1.366 + {
1.367 + fileData9[j++] = lowId;
1.368 + fileData9[j++] = lowId + KFeatRegTest2_06_DefSupportedBit - 1;
1.369 + lowId += 2*KFeatRegTest2_06_DefSupportedBit;
1.370 + }
1.371 + // header
1.372 + fileData9[0] = validTypePrefix,
1.373 + fileData9[1] = 0; // version number, must be zero
1.374 + fileData9[2] = entryCount;
1.375 + fileData9[3] = KFeatRegTest2_07_rangeCount;
1.376 + result = WriteTestConfigFile(fileData9, j*sizeof(TUint32));
1.377 + }
1.378 + else if (configName.Find(KFeatRegTestConfig_valid_perf) >= 0)
1.379 + {
1.380 + // extract the number of features to put into the file from the
1.381 + // arguments supplied to the process from the script
1.382 + TInt digitchar = 0;
1.383 + TChar charItem(configName[digitchar]);
1.384 + while (charItem.IsDigit() == EFalse)
1.385 + charItem = configName[++digitchar];
1.386 + if (digitchar >= configName.Length())
1.387 + {
1.388 + result = KErrArgument;
1.389 + goto cleanupReturn;
1.390 + }
1.391 +
1.392 + TPtrC16 counter = configName.Mid(digitchar);
1.393 + TLex lex1(counter);
1.394 + TInt count = 0;
1.395 + lex1.Val(count);
1.396 + // valid: allocate space for maximum number of features we would expect
1.397 + TInt j = sizeof(TFeatureHeader) / sizeof(TUint32);
1.398 + TUint32 fileData9[4 + 2*8001]; // j must == 4
1.399 + TInt entryCount = 0;
1.400 + TUint32 id = KFeatRegTest2_01_FirstId;
1.401 + // create 'count' number of feature entries
1.402 + for (TInt e = count; e > 0; e--)
1.403 + {
1.404 + fileData9[j++] = id;
1.405 + fileData9[j++] = (e&0x01) ? RFeatureRegistry::EStatusSupportBit : 0;
1.406 + entryCount++;
1.407 + id += KFeatRegTest2_03_IncrId;
1.408 + }
1.409 +#ifndef SYMBIAN_FEATURE_MANAGER
1.410 + // header
1.411 + fileData9[0] = validTypePrefix,
1.412 + fileData9[1] = 0; // version number, must be zero
1.413 + fileData9[2] = entryCount;
1.414 + fileData9[3] = 0;
1.415 +#else
1.416 + //we have to provide at least one range, otherwise the file will be corrupt from the FeatMgr perspective
1.417 + fileData9[j++] = KFeatRegTest_DummyRangeId;
1.418 + fileData9[j++] = KFeatRegTest_DummyRangeId;
1.419 + // header
1.420 + fileData9[0] = validTypePrefix,
1.421 + fileData9[1] = 0; // version number, must be zero
1.422 + fileData9[2] = entryCount;
1.423 + fileData9[3] = 1;
1.424 +#endif
1.425 + result = WriteTestConfigFile(fileData9, j*sizeof(TUint32));
1.426 + }
1.427 + else
1.428 + {
1.429 + result = KErrArgument;
1.430 + }
1.431 +
1.432 +cleanupReturn:
1.433 + __UHEAP_MARKEND;
1.434 +
1.435 + return result;
1.436 + }
1.437 +