os/persistentdata/featuremgmt/featureregistry/test/helper/maketestconfig/maketestconfig.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// Puts some test feature registry configuration files - some corrupt, others legal -
sl@0
    15
// in the C: private data cage of the setup executable. Sets up test RProperties.
sl@0
    16
// 
sl@0
    17
//
sl@0
    18
sl@0
    19
/**
sl@0
    20
 @file
sl@0
    21
 @internalComponent
sl@0
    22
 @test
sl@0
    23
*/
sl@0
    24
sl@0
    25
#include <e32cmn.h>
sl@0
    26
#include <e32base.h>
sl@0
    27
#include <f32file.h>
sl@0
    28
#include <e32property.h>
sl@0
    29
#include <featreg.h>
sl@0
    30
#include "featregcmn.h"
sl@0
    31
#include "maketestconfig.h"
sl@0
    32
sl@0
    33
// names of test configurations that can be set up by this exe, specified as
sl@0
    34
// command-line option:
sl@0
    35
_LIT(KFeatRegTestConfig_force_setup,				"force_setup");
sl@0
    36
_LIT(KFeatRegTestConfig_reset,						"reset");
sl@0
    37
_LIT(KFeatRegTestConfig_corrupt_missing,			"corrupt_missing");
sl@0
    38
_LIT(KFeatRegTestConfig_corrupt_noheader,			"corrupt_noheader");
sl@0
    39
_LIT(KFeatRegTestConfig_corrupt_incompleteheader,	"corrupt_incompleteheader");
sl@0
    40
_LIT(KFeatRegTestConfig_corrupt_invalidtypeprefix,	"corrupt_invalidtypeprefix");
sl@0
    41
_LIT(KFeatRegTestConfig_corrupt_badversionnumber,	"corrupt_badversionnumber");
sl@0
    42
_LIT(KFeatRegTestConfig_corrupt_toomuchdata,		"corrupt_toomuchdata");
sl@0
    43
_LIT(KFeatRegTestConfig_corrupt_toolittledata,		"corrupt_toolittledata");
sl@0
    44
_LIT(KFeatRegTestConfig_corrupt_entryoutoforder,	"corrupt_entryoutoforder");
sl@0
    45
_LIT(KFeatRegTestConfig_corrupt_entryrepeated,		"corrupt_entryrepeated");
sl@0
    46
_LIT(KFeatRegTestConfig_corrupt_badrange,			"corrupt_badrange");
sl@0
    47
_LIT(KFeatRegTestConfig_valid_nofeatures,			"valid_nofeatures");
sl@0
    48
_LIT(KFeatRegTestConfig_valid_small,				"valid_small");
sl@0
    49
_LIT(KFeatRegTestConfig_valid_large,				"valid_large");
sl@0
    50
_LIT(KFeatRegTestConfig_valid_perf,				    "valid_perf_");
sl@0
    51
sl@0
    52
sl@0
    53
TConfigFileName ConfigFileName;
sl@0
    54
sl@0
    55
sl@0
    56
static TInt DefineTestFlagProperty()
sl@0
    57
	{
sl@0
    58
	RProcess thisProcess;
sl@0
    59
	// sanity check that feature property category in common header equals SID of this process
sl@0
    60
	ASSERT(KFeaturePropCat == thisProcess.SecureId());
sl@0
    61
	TSecurityPolicy readPolicy(TSecurityPolicy::EAlwaysPass);
sl@0
    62
	TSecurityPolicy writePolicy(thisProcess.SecureId());
sl@0
    63
	TInt result = RProperty::Define(KFeatRegConfigTestKey, RProperty::EInt, readPolicy, writePolicy);
sl@0
    64
	if (result == KErrAlreadyExists)
sl@0
    65
		{
sl@0
    66
		result = KErrNone;
sl@0
    67
		}
sl@0
    68
	return result;
sl@0
    69
	}
sl@0
    70
sl@0
    71
static TInt WriteTestConfigFile(TUint32* aData, TInt aSize)
sl@0
    72
	{
sl@0
    73
	RFs fs;
sl@0
    74
	TInt result = fs.Connect();
sl@0
    75
	if (result == KErrNone)
sl@0
    76
		{
sl@0
    77
		result = fs.MkDirAll(ConfigFileName);
sl@0
    78
		if ((result == KErrNone) || (result == KErrAlreadyExists))
sl@0
    79
			{
sl@0
    80
			RFile cfgFile;
sl@0
    81
			result = cfgFile.Replace(fs, ConfigFileName, EFileWrite|EFileStream);
sl@0
    82
			if (result == KErrNone)
sl@0
    83
				{
sl@0
    84
				result = cfgFile.Write(TPtrC8(reinterpret_cast<const TUint8 *>(aData), aSize));
sl@0
    85
				cfgFile.Close();
sl@0
    86
				}
sl@0
    87
			}
sl@0
    88
		fs.Close();
sl@0
    89
		}
sl@0
    90
	if (result == KErrNone)
sl@0
    91
		{
sl@0
    92
		result = DefineTestFlagProperty();
sl@0
    93
		}
sl@0
    94
	return result;
sl@0
    95
	}
sl@0
    96
sl@0
    97
TInt E32Main()
sl@0
    98
	{
sl@0
    99
	__UHEAP_MARK;
sl@0
   100
sl@0
   101
	TFileName configName;
sl@0
   102
	User::CommandLine(configName);
sl@0
   103
sl@0
   104
	// construct config filename
sl@0
   105
	GetSystemDrivePath(ConfigFileName);
sl@0
   106
sl@0
   107
	// always delete feature property so featreg.dll re-loads it (note this
sl@0
   108
	// executable has same UID3 as featreg setup:
sl@0
   109
	TInt result = RProperty::Delete(KFeaturePropKey);
sl@0
   110
	if (result == KErrNotFound)
sl@0
   111
		{
sl@0
   112
		result = KErrNone;
sl@0
   113
		}
sl@0
   114
	if (result != KErrNone)
sl@0
   115
		{
sl@0
   116
		goto cleanupReturn;
sl@0
   117
		}
sl@0
   118
sl@0
   119
	//--------------------
sl@0
   120
	if (configName.Find(KFeatRegTestConfig_force_setup) >= 0)
sl@0
   121
		{
sl@0
   122
		// force setup
sl@0
   123
		// nothing to do; just ensures feature property is deleted so setup is run
sl@0
   124
		}
sl@0
   125
	//--------------------
sl@0
   126
	else if (configName.Find(KFeatRegTestConfig_reset) >= 0)
sl@0
   127
		{
sl@0
   128
		// reset
sl@0
   129
		// delete "test-flag" property so setup looks at true config info
sl@0
   130
		result = RProperty::Delete(KFeatRegConfigTestKey);
sl@0
   131
		if (result == KErrNotFound)
sl@0
   132
			{
sl@0
   133
			result = KErrNone;
sl@0
   134
			}
sl@0
   135
		}
sl@0
   136
	//--------------------
sl@0
   137
	else if (configName.Find(KFeatRegTestConfig_corrupt_missing) >= 0)
sl@0
   138
		{
sl@0
   139
		// no header
sl@0
   140
		RFs fs;
sl@0
   141
		result = fs.Connect();
sl@0
   142
		if (result == KErrNone)
sl@0
   143
			{
sl@0
   144
			result = fs.Delete(ConfigFileName);
sl@0
   145
			if ((result == KErrNotFound) || (result == KErrPathNotFound))
sl@0
   146
				{
sl@0
   147
				result = KErrNone;
sl@0
   148
				}
sl@0
   149
			fs.Close();
sl@0
   150
			}
sl@0
   151
		if (result == KErrNone)
sl@0
   152
			{
sl@0
   153
			result = DefineTestFlagProperty();
sl@0
   154
			}
sl@0
   155
		}
sl@0
   156
	//--------------------
sl@0
   157
	else if (configName.Find(KFeatRegTestConfig_corrupt_noheader) >= 0)
sl@0
   158
		{
sl@0
   159
		// no header
sl@0
   160
		result = WriteTestConfigFile(NULL, 0);
sl@0
   161
		}
sl@0
   162
	//--------------------
sl@0
   163
	else if (configName.Find(KFeatRegTestConfig_corrupt_incompleteheader) >= 0)
sl@0
   164
		{
sl@0
   165
		// header is not complete
sl@0
   166
		TUint32 fileData1[] =
sl@0
   167
			{
sl@0
   168
			validTypePrefix,
sl@0
   169
			0,	// version number, must be zero
sl@0
   170
			0	// entry count
sl@0
   171
				// range count: missing
sl@0
   172
			};
sl@0
   173
		result = WriteTestConfigFile(fileData1, sizeof(fileData1));
sl@0
   174
		}
sl@0
   175
	//--------------------
sl@0
   176
	else if (configName.Find(KFeatRegTestConfig_corrupt_invalidtypeprefix) >= 0)
sl@0
   177
		{
sl@0
   178
		// invalid type prefix
sl@0
   179
		TUint32 fileData1[] =
sl@0
   180
			{
sl@0
   181
			invalidTypePrefix,	 // should be validTypePrefix
sl@0
   182
			0,	// version number
sl@0
   183
			0,	// entry count
sl@0
   184
			0	// range count
sl@0
   185
			};
sl@0
   186
		result = WriteTestConfigFile(fileData1, sizeof(fileData1));
sl@0
   187
		}
sl@0
   188
sl@0
   189
	//--------------------
sl@0
   190
	else if (configName.Find(KFeatRegTestConfig_corrupt_badversionnumber) >= 0)
sl@0
   191
		{
sl@0
   192
		// bad file version header
sl@0
   193
		TUint32 fileData1[] =
sl@0
   194
			{
sl@0
   195
			validTypePrefix,
sl@0
   196
			1,	// version number: not zero
sl@0
   197
			0,	// entry count
sl@0
   198
			0	// range count
sl@0
   199
			};
sl@0
   200
		result = WriteTestConfigFile(fileData1, sizeof(fileData1));
sl@0
   201
		}
sl@0
   202
	//--------------------
sl@0
   203
	else if (configName.Find(KFeatRegTestConfig_corrupt_toomuchdata) >= 0)
sl@0
   204
		{
sl@0
   205
		// corrupt: config file contains more data than required by header
sl@0
   206
		TUint32 fileData2[] =
sl@0
   207
			{
sl@0
   208
			validTypePrefix,
sl@0
   209
			0,	// version number, must be zero
sl@0
   210
			0,	// entry count
sl@0
   211
			0,	// range count
sl@0
   212
			0,	// unexpected extra data
sl@0
   213
			};
sl@0
   214
		result = WriteTestConfigFile(fileData2, sizeof(fileData2));
sl@0
   215
		}
sl@0
   216
	//--------------------
sl@0
   217
	else if (configName.Find(KFeatRegTestConfig_corrupt_toolittledata) >= 0)
sl@0
   218
		{
sl@0
   219
		// corrupt: config file contains less data than required by header
sl@0
   220
		TUint32 fileData3[] =
sl@0
   221
			{
sl@0
   222
			validTypePrefix,
sl@0
   223
			0,	// version number, must be zero
sl@0
   224
			2,	// entry count
sl@0
   225
			1	// range count
sl@0
   226
				// should be 2 entries (2 words each) and 1 default range (2 words each)
sl@0
   227
			};
sl@0
   228
		result = WriteTestConfigFile(fileData3, sizeof(fileData3));
sl@0
   229
		}
sl@0
   230
	//--------------------
sl@0
   231
	else if (configName.Find(KFeatRegTestConfig_corrupt_entryoutoforder) >= 0)
sl@0
   232
		{
sl@0
   233
		// corrupt: feature entries not ordered from lowest to highest UID
sl@0
   234
		TUint32 fileData4[] =
sl@0
   235
			{
sl@0
   236
			validTypePrefix,
sl@0
   237
			0,	// version number, must be zero
sl@0
   238
			3,	// entry count
sl@0
   239
			0,	// range count
sl@0
   240
			2,	// Feature UID = 2
sl@0
   241
			1,	//   status low-bit set -> present
sl@0
   242
			5,	// Feature UID = 5
sl@0
   243
			1,	//   status low-bit set -> present
sl@0
   244
			3,	// Feature UID = 3: Feature UIDs not in strictly increasing order
sl@0
   245
			1	//   status low-bit set -> present
sl@0
   246
			};
sl@0
   247
		result = WriteTestConfigFile(fileData4, sizeof(fileData4));
sl@0
   248
		}
sl@0
   249
	//--------------------
sl@0
   250
	else if (configName.Find(KFeatRegTestConfig_corrupt_entryrepeated) >= 0)
sl@0
   251
		{
sl@0
   252
		// corrupt: repeated feature UID
sl@0
   253
		TUint32 fileData5[] =
sl@0
   254
			{
sl@0
   255
			validTypePrefix,
sl@0
   256
			0,	// version number, must be zero
sl@0
   257
			3,	// entry count
sl@0
   258
			0,	// range count
sl@0
   259
			2,	// Feature UID = 2
sl@0
   260
			1,	//   status low-bit set -> present
sl@0
   261
			5,	// Feature UID = 5
sl@0
   262
			1,	//   status low-bit set -> present
sl@0
   263
			5,	// Feature UID = 5: Feature UID repeated
sl@0
   264
			1,	//   status low-bit set -> present
sl@0
   265
			};
sl@0
   266
		result = WriteTestConfigFile(fileData5, sizeof(fileData5));
sl@0
   267
		}
sl@0
   268
	//--------------------
sl@0
   269
	else if (configName.Find(KFeatRegTestConfig_corrupt_badrange) >= 0)
sl@0
   270
		{
sl@0
   271
		// corrupt: default-supported range not listed in order lowUid-highUid
sl@0
   272
		TUint32 fileData6[] =
sl@0
   273
			{
sl@0
   274
			validTypePrefix,
sl@0
   275
			0,	// version number, must be zero
sl@0
   276
			1,	// entry count
sl@0
   277
			2,	// range count
sl@0
   278
			2,	// Feature UID = 2
sl@0
   279
			1,	//   status low-bit set -> present
sl@0
   280
			5,	// Range 1 low UID
sl@0
   281
			9,	//         high UID
sl@0
   282
			88,	// Range 2 low UID
sl@0
   283
			76	//         high UID: not >= lowUID
sl@0
   284
			};
sl@0
   285
		result = WriteTestConfigFile(fileData6, sizeof(fileData6));
sl@0
   286
		}
sl@0
   287
	//--------------------
sl@0
   288
	else if (configName.Find(KFeatRegTestConfig_valid_nofeatures) >= 0)
sl@0
   289
		{
sl@0
   290
#ifndef SYMBIAN_FEATURE_MANAGER
sl@0
   291
		// valid: no features
sl@0
   292
				TUint32 fileData7[] =
sl@0
   293
					{
sl@0
   294
					validTypePrefix,
sl@0
   295
					0,	// version number, must be zero
sl@0
   296
					0,	// entry count
sl@0
   297
					0	// range count
sl@0
   298
					};
sl@0
   299
#else	
sl@0
   300
		// valid: no features
sl@0
   301
				TUint32 fileData7[] =
sl@0
   302
					{
sl@0
   303
					validTypePrefix,
sl@0
   304
					0,	// version number, must be zero
sl@0
   305
					0,	// entry count
sl@0
   306
					1,	// range count: we have to provide at least one range, otherwise the file will be corrupt from the FeatMgr perspective
sl@0
   307
					KFeatRegTest_DummyRangeId,
sl@0
   308
					KFeatRegTest_DummyRangeId
sl@0
   309
					};		
sl@0
   310
#endif	
sl@0
   311
		result = WriteTestConfigFile(fileData7, sizeof(fileData7));
sl@0
   312
		}
sl@0
   313
	//--------------------
sl@0
   314
	else if (configName.Find(KFeatRegTestConfig_valid_small) >= 0)
sl@0
   315
		{
sl@0
   316
		// valid: few features, one default=supported range
sl@0
   317
		TUint32 fileData8[] =
sl@0
   318
			{
sl@0
   319
			validTypePrefix,
sl@0
   320
			0,	// version number, must be zero
sl@0
   321
			2,	// entry count
sl@0
   322
			1,	// range count
sl@0
   323
			KFeatRegTest1_02_SNFeatId,	// 1. feature UID
sl@0
   324
			KFeatRegTest1_02_SNFeatSt,	//    status word; low bit set = supported
sl@0
   325
			KFeatRegTest1_05_URFeatId,	// 2. feature UID
sl@0
   326
			KFeatRegTest1_05_URFeatSt,	//    status word; low-bit not set = not supported
sl@0
   327
			KFeatRegTest1_03_LoFeatId,	// low-feature-UID of default=supported range
sl@0
   328
			KFeatRegTest1_04_HiFeatId	// high-feature-UID of default=supported range
sl@0
   329
			};
sl@0
   330
		result = WriteTestConfigFile(fileData8, sizeof(fileData8));
sl@0
   331
		}
sl@0
   332
	//--------------------
sl@0
   333
	else if (configName.Find(KFeatRegTestConfig_valid_large) >= 0)
sl@0
   334
		{
sl@0
   335
		// valid: many features, several default=supported ranges
sl@0
   336
		TUint32 fileData9[2 + 2*KFeatRegTest2_04_numTestFeatures + 2*KFeatRegTest2_07_rangeCount];
sl@0
   337
		TInt j = sizeof(TFeatureHeader) / sizeof(TUint32);
sl@0
   338
		TInt entryCount = 0;
sl@0
   339
		TUint32 id = KFeatRegTest2_01_FirstId;
sl@0
   340
		// feature entries
sl@0
   341
		for (TInt e = KFeatRegTest2_04_numTestFeatures; e > 0; e--)
sl@0
   342
			{
sl@0
   343
			TBool featureSupported = !(id & KFeatRegTest2_05_NotSupportedBit);
sl@0
   344
			TBool inDefaultSupportedRange = id & KFeatRegTest2_06_DefSupportedBit;
sl@0
   345
			// only need to list feature if support differs from default ranges
sl@0
   346
			if (featureSupported && (!inDefaultSupportedRange))
sl@0
   347
				{
sl@0
   348
				fileData9[j++] = id;
sl@0
   349
				fileData9[j++] = RFeatureRegistry::EStatusSupportBit;
sl@0
   350
				entryCount++;
sl@0
   351
				}
sl@0
   352
			else if ((!featureSupported) && inDefaultSupportedRange)
sl@0
   353
				{
sl@0
   354
				fileData9[j++] = id;
sl@0
   355
				fileData9[j++] = 0;	// specifically listed as not supported
sl@0
   356
				entryCount++;
sl@0
   357
				}
sl@0
   358
			id += KFeatRegTest2_03_IncrId;
sl@0
   359
			}
sl@0
   360
		// default=supported ranges
sl@0
   361
		TUint32 lowId = KFeatRegTest2_06_DefSupportedBit;
sl@0
   362
		for (TUint r = 0; r < KFeatRegTest2_07_rangeCount; r++)
sl@0
   363
			{
sl@0
   364
			fileData9[j++] = lowId;
sl@0
   365
			fileData9[j++] = lowId + KFeatRegTest2_06_DefSupportedBit - 1;
sl@0
   366
			lowId += 2*KFeatRegTest2_06_DefSupportedBit;
sl@0
   367
			}
sl@0
   368
		// header
sl@0
   369
		fileData9[0] = validTypePrefix,
sl@0
   370
		fileData9[1] = 0;	// version number, must be zero
sl@0
   371
		fileData9[2] = entryCount;
sl@0
   372
		fileData9[3] = KFeatRegTest2_07_rangeCount;
sl@0
   373
		result = WriteTestConfigFile(fileData9, j*sizeof(TUint32));
sl@0
   374
		}
sl@0
   375
	else if (configName.Find(KFeatRegTestConfig_valid_perf) >= 0)
sl@0
   376
		{
sl@0
   377
		// extract the number of features to put into the file from the
sl@0
   378
		// arguments supplied to the process from the script
sl@0
   379
	    TInt digitchar = 0;
sl@0
   380
	    TChar charItem(configName[digitchar]);
sl@0
   381
	    while (charItem.IsDigit() == EFalse)
sl@0
   382
           charItem = configName[++digitchar]; 
sl@0
   383
	    if (digitchar >= configName.Length())
sl@0
   384
	    	{
sl@0
   385
	    	result = KErrArgument;
sl@0
   386
	    	goto cleanupReturn;
sl@0
   387
	    	}
sl@0
   388
	    
sl@0
   389
		TPtrC16 counter = configName.Mid(digitchar);
sl@0
   390
		TLex lex1(counter);
sl@0
   391
		TInt count = 0;
sl@0
   392
        lex1.Val(count);
sl@0
   393
		// valid: allocate space for maximum number of features we would expect
sl@0
   394
		TInt j = sizeof(TFeatureHeader) / sizeof(TUint32);
sl@0
   395
		TUint32 fileData9[4 + 2*8001]; // j must == 4
sl@0
   396
		TInt entryCount = 0;
sl@0
   397
		TUint32 id = KFeatRegTest2_01_FirstId;
sl@0
   398
		// create 'count' number of feature entries
sl@0
   399
		for (TInt e = count; e > 0; e--)
sl@0
   400
			{
sl@0
   401
			fileData9[j++] = id;
sl@0
   402
			fileData9[j++] = (e&0x01) ? RFeatureRegistry::EStatusSupportBit : 0;
sl@0
   403
			entryCount++;
sl@0
   404
			id += KFeatRegTest2_03_IncrId;
sl@0
   405
			}
sl@0
   406
#ifndef SYMBIAN_FEATURE_MANAGER
sl@0
   407
		// header
sl@0
   408
		fileData9[0] = validTypePrefix,
sl@0
   409
		fileData9[1] = 0;	// version number, must be zero
sl@0
   410
		fileData9[2] = entryCount;
sl@0
   411
		fileData9[3] = 0;
sl@0
   412
#else
sl@0
   413
		//we have to provide at least one range, otherwise the file will be corrupt from the FeatMgr perspective 
sl@0
   414
		fileData9[j++] = KFeatRegTest_DummyRangeId;
sl@0
   415
		fileData9[j++] = KFeatRegTest_DummyRangeId;
sl@0
   416
		// header
sl@0
   417
		fileData9[0] = validTypePrefix,
sl@0
   418
		fileData9[1] = 0;	// version number, must be zero
sl@0
   419
		fileData9[2] = entryCount;
sl@0
   420
		fileData9[3] = 1;		
sl@0
   421
#endif		
sl@0
   422
		result = WriteTestConfigFile(fileData9, j*sizeof(TUint32));		
sl@0
   423
		}
sl@0
   424
	else
sl@0
   425
		{
sl@0
   426
		result = KErrArgument;
sl@0
   427
		}
sl@0
   428
sl@0
   429
cleanupReturn:
sl@0
   430
	__UHEAP_MARKEND;
sl@0
   431
sl@0
   432
	return result;
sl@0
   433
	}
sl@0
   434