os/persistentdata/featuremgmt/featureregistry/test/helper/maketestconfig/maketestconfig.cpp
Update contrib.
1 // Copyright (c) 2005-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Puts some test feature registry configuration files - some corrupt, others legal -
15 // in the C: private data cage of the setup executable. Sets up test RProperties.
28 #include <e32property.h>
30 #include "featregcmn.h"
31 #include "maketestconfig.h"
33 // names of test configurations that can be set up by this exe, specified as
34 // command-line option:
35 _LIT(KFeatRegTestConfig_force_setup, "force_setup");
36 _LIT(KFeatRegTestConfig_reset, "reset");
37 _LIT(KFeatRegTestConfig_corrupt_missing, "corrupt_missing");
38 _LIT(KFeatRegTestConfig_corrupt_noheader, "corrupt_noheader");
39 _LIT(KFeatRegTestConfig_corrupt_incompleteheader, "corrupt_incompleteheader");
40 _LIT(KFeatRegTestConfig_corrupt_invalidtypeprefix, "corrupt_invalidtypeprefix");
41 _LIT(KFeatRegTestConfig_corrupt_badversionnumber, "corrupt_badversionnumber");
42 _LIT(KFeatRegTestConfig_corrupt_toomuchdata, "corrupt_toomuchdata");
43 _LIT(KFeatRegTestConfig_corrupt_toolittledata, "corrupt_toolittledata");
44 _LIT(KFeatRegTestConfig_corrupt_entryoutoforder, "corrupt_entryoutoforder");
45 _LIT(KFeatRegTestConfig_corrupt_entryrepeated, "corrupt_entryrepeated");
46 _LIT(KFeatRegTestConfig_corrupt_badrange, "corrupt_badrange");
47 _LIT(KFeatRegTestConfig_valid_nofeatures, "valid_nofeatures");
48 _LIT(KFeatRegTestConfig_valid_small, "valid_small");
49 _LIT(KFeatRegTestConfig_valid_large, "valid_large");
50 _LIT(KFeatRegTestConfig_valid_perf, "valid_perf_");
53 TConfigFileName ConfigFileName;
56 static TInt DefineTestFlagProperty()
59 // sanity check that feature property category in common header equals SID of this process
60 ASSERT(KFeaturePropCat == thisProcess.SecureId());
61 TSecurityPolicy readPolicy(TSecurityPolicy::EAlwaysPass);
62 TSecurityPolicy writePolicy(thisProcess.SecureId());
63 TInt result = RProperty::Define(KFeatRegConfigTestKey, RProperty::EInt, readPolicy, writePolicy);
64 if (result == KErrAlreadyExists)
71 static TInt WriteTestConfigFile(TUint32* aData, TInt aSize)
74 TInt result = fs.Connect();
75 if (result == KErrNone)
77 result = fs.MkDirAll(ConfigFileName);
78 if ((result == KErrNone) || (result == KErrAlreadyExists))
81 result = cfgFile.Replace(fs, ConfigFileName, EFileWrite|EFileStream);
82 if (result == KErrNone)
84 result = cfgFile.Write(TPtrC8(reinterpret_cast<const TUint8 *>(aData), aSize));
90 if (result == KErrNone)
92 result = DefineTestFlagProperty();
101 TFileName configName;
102 User::CommandLine(configName);
104 // construct config filename
105 GetSystemDrivePath(ConfigFileName);
107 // always delete feature property so featreg.dll re-loads it (note this
108 // executable has same UID3 as featreg setup:
109 TInt result = RProperty::Delete(KFeaturePropKey);
110 if (result == KErrNotFound)
114 if (result != KErrNone)
119 //--------------------
120 if (configName.Find(KFeatRegTestConfig_force_setup) >= 0)
123 // nothing to do; just ensures feature property is deleted so setup is run
125 //--------------------
126 else if (configName.Find(KFeatRegTestConfig_reset) >= 0)
129 // delete "test-flag" property so setup looks at true config info
130 result = RProperty::Delete(KFeatRegConfigTestKey);
131 if (result == KErrNotFound)
136 //--------------------
137 else if (configName.Find(KFeatRegTestConfig_corrupt_missing) >= 0)
141 result = fs.Connect();
142 if (result == KErrNone)
144 result = fs.Delete(ConfigFileName);
145 if ((result == KErrNotFound) || (result == KErrPathNotFound))
151 if (result == KErrNone)
153 result = DefineTestFlagProperty();
156 //--------------------
157 else if (configName.Find(KFeatRegTestConfig_corrupt_noheader) >= 0)
160 result = WriteTestConfigFile(NULL, 0);
162 //--------------------
163 else if (configName.Find(KFeatRegTestConfig_corrupt_incompleteheader) >= 0)
165 // header is not complete
166 TUint32 fileData1[] =
169 0, // version number, must be zero
171 // range count: missing
173 result = WriteTestConfigFile(fileData1, sizeof(fileData1));
175 //--------------------
176 else if (configName.Find(KFeatRegTestConfig_corrupt_invalidtypeprefix) >= 0)
178 // invalid type prefix
179 TUint32 fileData1[] =
181 invalidTypePrefix, // should be validTypePrefix
186 result = WriteTestConfigFile(fileData1, sizeof(fileData1));
189 //--------------------
190 else if (configName.Find(KFeatRegTestConfig_corrupt_badversionnumber) >= 0)
192 // bad file version header
193 TUint32 fileData1[] =
196 1, // version number: not zero
200 result = WriteTestConfigFile(fileData1, sizeof(fileData1));
202 //--------------------
203 else if (configName.Find(KFeatRegTestConfig_corrupt_toomuchdata) >= 0)
205 // corrupt: config file contains more data than required by header
206 TUint32 fileData2[] =
209 0, // version number, must be zero
212 0, // unexpected extra data
214 result = WriteTestConfigFile(fileData2, sizeof(fileData2));
216 //--------------------
217 else if (configName.Find(KFeatRegTestConfig_corrupt_toolittledata) >= 0)
219 // corrupt: config file contains less data than required by header
220 TUint32 fileData3[] =
223 0, // version number, must be zero
226 // should be 2 entries (2 words each) and 1 default range (2 words each)
228 result = WriteTestConfigFile(fileData3, sizeof(fileData3));
230 //--------------------
231 else if (configName.Find(KFeatRegTestConfig_corrupt_entryoutoforder) >= 0)
233 // corrupt: feature entries not ordered from lowest to highest UID
234 TUint32 fileData4[] =
237 0, // version number, must be zero
240 2, // Feature UID = 2
241 1, // status low-bit set -> present
242 5, // Feature UID = 5
243 1, // status low-bit set -> present
244 3, // Feature UID = 3: Feature UIDs not in strictly increasing order
245 1 // status low-bit set -> present
247 result = WriteTestConfigFile(fileData4, sizeof(fileData4));
249 //--------------------
250 else if (configName.Find(KFeatRegTestConfig_corrupt_entryrepeated) >= 0)
252 // corrupt: repeated feature UID
253 TUint32 fileData5[] =
256 0, // version number, must be zero
259 2, // Feature UID = 2
260 1, // status low-bit set -> present
261 5, // Feature UID = 5
262 1, // status low-bit set -> present
263 5, // Feature UID = 5: Feature UID repeated
264 1, // status low-bit set -> present
266 result = WriteTestConfigFile(fileData5, sizeof(fileData5));
268 //--------------------
269 else if (configName.Find(KFeatRegTestConfig_corrupt_badrange) >= 0)
271 // corrupt: default-supported range not listed in order lowUid-highUid
272 TUint32 fileData6[] =
275 0, // version number, must be zero
278 2, // Feature UID = 2
279 1, // status low-bit set -> present
280 5, // Range 1 low UID
282 88, // Range 2 low UID
283 76 // high UID: not >= lowUID
285 result = WriteTestConfigFile(fileData6, sizeof(fileData6));
287 //--------------------
288 else if (configName.Find(KFeatRegTestConfig_valid_nofeatures) >= 0)
290 #ifndef SYMBIAN_FEATURE_MANAGER
291 // valid: no features
292 TUint32 fileData7[] =
295 0, // version number, must be zero
300 // valid: no features
301 TUint32 fileData7[] =
304 0, // version number, must be zero
306 1, // range count: we have to provide at least one range, otherwise the file will be corrupt from the FeatMgr perspective
307 KFeatRegTest_DummyRangeId,
308 KFeatRegTest_DummyRangeId
311 result = WriteTestConfigFile(fileData7, sizeof(fileData7));
313 //--------------------
314 else if (configName.Find(KFeatRegTestConfig_valid_small) >= 0)
316 // valid: few features, one default=supported range
317 TUint32 fileData8[] =
320 0, // version number, must be zero
323 KFeatRegTest1_02_SNFeatId, // 1. feature UID
324 KFeatRegTest1_02_SNFeatSt, // status word; low bit set = supported
325 KFeatRegTest1_05_URFeatId, // 2. feature UID
326 KFeatRegTest1_05_URFeatSt, // status word; low-bit not set = not supported
327 KFeatRegTest1_03_LoFeatId, // low-feature-UID of default=supported range
328 KFeatRegTest1_04_HiFeatId // high-feature-UID of default=supported range
330 result = WriteTestConfigFile(fileData8, sizeof(fileData8));
332 //--------------------
333 else if (configName.Find(KFeatRegTestConfig_valid_large) >= 0)
335 // valid: many features, several default=supported ranges
336 TUint32 fileData9[2 + 2*KFeatRegTest2_04_numTestFeatures + 2*KFeatRegTest2_07_rangeCount];
337 TInt j = sizeof(TFeatureHeader) / sizeof(TUint32);
339 TUint32 id = KFeatRegTest2_01_FirstId;
341 for (TInt e = KFeatRegTest2_04_numTestFeatures; e > 0; e--)
343 TBool featureSupported = !(id & KFeatRegTest2_05_NotSupportedBit);
344 TBool inDefaultSupportedRange = id & KFeatRegTest2_06_DefSupportedBit;
345 // only need to list feature if support differs from default ranges
346 if (featureSupported && (!inDefaultSupportedRange))
349 fileData9[j++] = RFeatureRegistry::EStatusSupportBit;
352 else if ((!featureSupported) && inDefaultSupportedRange)
355 fileData9[j++] = 0; // specifically listed as not supported
358 id += KFeatRegTest2_03_IncrId;
360 // default=supported ranges
361 TUint32 lowId = KFeatRegTest2_06_DefSupportedBit;
362 for (TUint r = 0; r < KFeatRegTest2_07_rangeCount; r++)
364 fileData9[j++] = lowId;
365 fileData9[j++] = lowId + KFeatRegTest2_06_DefSupportedBit - 1;
366 lowId += 2*KFeatRegTest2_06_DefSupportedBit;
369 fileData9[0] = validTypePrefix,
370 fileData9[1] = 0; // version number, must be zero
371 fileData9[2] = entryCount;
372 fileData9[3] = KFeatRegTest2_07_rangeCount;
373 result = WriteTestConfigFile(fileData9, j*sizeof(TUint32));
375 else if (configName.Find(KFeatRegTestConfig_valid_perf) >= 0)
377 // extract the number of features to put into the file from the
378 // arguments supplied to the process from the script
380 TChar charItem(configName[digitchar]);
381 while (charItem.IsDigit() == EFalse)
382 charItem = configName[++digitchar];
383 if (digitchar >= configName.Length())
385 result = KErrArgument;
389 TPtrC16 counter = configName.Mid(digitchar);
393 // valid: allocate space for maximum number of features we would expect
394 TInt j = sizeof(TFeatureHeader) / sizeof(TUint32);
395 TUint32 fileData9[4 + 2*8001]; // j must == 4
397 TUint32 id = KFeatRegTest2_01_FirstId;
398 // create 'count' number of feature entries
399 for (TInt e = count; e > 0; e--)
402 fileData9[j++] = (e&0x01) ? RFeatureRegistry::EStatusSupportBit : 0;
404 id += KFeatRegTest2_03_IncrId;
406 #ifndef SYMBIAN_FEATURE_MANAGER
408 fileData9[0] = validTypePrefix,
409 fileData9[1] = 0; // version number, must be zero
410 fileData9[2] = entryCount;
413 //we have to provide at least one range, otherwise the file will be corrupt from the FeatMgr perspective
414 fileData9[j++] = KFeatRegTest_DummyRangeId;
415 fileData9[j++] = KFeatRegTest_DummyRangeId;
417 fileData9[0] = validTypePrefix,
418 fileData9[1] = 0; // version number, must be zero
419 fileData9[2] = entryCount;
422 result = WriteTestConfigFile(fileData9, j*sizeof(TUint32));
426 result = KErrArgument;