os/kernelhwsrv/kerneltest/e32test/property/t_basic.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) 2002-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 the License "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
//
sl@0
    15
sl@0
    16
#include <e32kpan.h>
sl@0
    17
#include "t_property.h"
sl@0
    18
sl@0
    19
_LIT(KDefineName, "RProperty::Define() Basics");
sl@0
    20
 
sl@0
    21
CPropDefine::CPropDefine(TUid aCategory, TUint aKey, RProperty::TType aType) : 
sl@0
    22
	  CTestProgram(KDefineName), iCategory(aCategory), iKey(aKey), iType(aType)
sl@0
    23
	{
sl@0
    24
	}
sl@0
    25
sl@0
    26
void CPropDefine::Run(TUint aCount)
sl@0
    27
	{
sl@0
    28
	TUid mySid;
sl@0
    29
	mySid.iUid = RProcess().SecureId();
sl@0
    30
sl@0
    31
	for(TUint i = 0; i < aCount; ++i)
sl@0
    32
		{
sl@0
    33
		RProperty prop;
sl@0
    34
sl@0
    35
		//	Defines the attributes and access control for a property. This can only be done 
sl@0
    36
		//	once for each property. Subsequent attempts to define the same property will return
sl@0
    37
		//	KErrAlreadyExists.
sl@0
    38
		TInt r = prop.Define(iCategory, iKey, iType, KPassPolicy, KPassPolicy);
sl@0
    39
		TF_ERROR(r, r == KErrNone);
sl@0
    40
		r = prop.Define(iCategory, iKey, iType, KPassPolicy, KPassPolicy);
sl@0
    41
		TF_ERROR(r, r == KErrAlreadyExists);
sl@0
    42
		r = prop.Delete(iCategory, iKey);
sl@0
    43
		TF_ERROR(r, r == KErrNone);
sl@0
    44
sl@0
    45
		// Test defining properties in the default category (==our SID)
sl@0
    46
		r = prop.Define(iKey, iType, KFailPolicy, KFailPolicy);
sl@0
    47
		TF_ERROR(r, r == KErrNone);
sl@0
    48
		r = prop.Define(iKey, iType, KFailPolicy, KFailPolicy);
sl@0
    49
		TF_ERROR(r, r == KErrAlreadyExists);
sl@0
    50
		r = prop.Define(mySid, iKey, iType, KFailPolicy, KFailPolicy);
sl@0
    51
		TF_ERROR(r, r == KErrAlreadyExists);
sl@0
    52
		r = prop.Delete(mySid, iKey);
sl@0
    53
		TF_ERROR(r, r == KErrNone);
sl@0
    54
sl@0
    55
		// Test re-definition doesn't change security settings
sl@0
    56
		// Defect DEF050961 - Re-defining an RProperty causes the security policy to be overwritten
sl@0
    57
		{
sl@0
    58
		TInt expectedResult = PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement)?KErrPermissionDenied:KErrNone;
sl@0
    59
		_LIT(KTestBytes,"abcd");
sl@0
    60
		r = prop.Define(iCategory, iKey, iType, KFailPolicy, KFailPolicy);
sl@0
    61
		TF_ERROR(r, r == KErrNone);
sl@0
    62
		r = prop.Attach(iCategory, iKey);
sl@0
    63
		TF_ERROR(r, r == KErrNone);
sl@0
    64
		if (iType == RProperty::EInt)
sl@0
    65
			r = prop.Set(1);
sl@0
    66
		else
sl@0
    67
			r = prop.Set(KTestBytes);
sl@0
    68
		TF_ERROR(r, r == expectedResult);
sl@0
    69
		r = prop.Define(iCategory, iKey, iType, KPassPolicy, KPassPolicy);
sl@0
    70
		TF_ERROR(r, r == KErrAlreadyExists);
sl@0
    71
		if (iType == RProperty::EInt)
sl@0
    72
			r = prop.Set(1);
sl@0
    73
		else
sl@0
    74
			r = prop.Set(KTestBytes);
sl@0
    75
		TF_ERROR(r, r == expectedResult);
sl@0
    76
		r = prop.Delete(iCategory, iKey);
sl@0
    77
		TF_ERROR(r, r == KErrNone);
sl@0
    78
		prop.Close();
sl@0
    79
		}
sl@0
    80
sl@0
    81
		// Define fails with KErrArgument if wrong type or attribute was specified.
sl@0
    82
		r = prop.Define(iCategory, iKey, RProperty::ETypeLimit, KPassPolicy, KPassPolicy);
sl@0
    83
		TF_ERROR(r, r == KErrArgument);
sl@0
    84
		const TInt removed_KPersistent_attribute = 0x100;
sl@0
    85
		r  = prop.Define(iCategory, iKey, iType | removed_KPersistent_attribute, KPassPolicy, KPassPolicy);
sl@0
    86
		TF_ERROR(r, r == KErrArgument);
sl@0
    87
sl@0
    88
		TSecurityPolicy badPolicy;
sl@0
    89
		*(TInt*)&badPolicy = -1;
sl@0
    90
		r = prop.Define(iCategory, iKey, iType, badPolicy, KPassPolicy);
sl@0
    91
		TF_ERROR(r, r == KErrArgument);
sl@0
    92
		r = prop.Define(iCategory, iKey, iType, KPassPolicy, badPolicy);
sl@0
    93
		TF_ERROR(r, r == KErrArgument);
sl@0
    94
sl@0
    95
		if (iType == RProperty::EInt)
sl@0
    96
			{
sl@0
    97
			// Define fails with KErrArgument if aType is TInt and aPreallocate is not 0
sl@0
    98
			r = prop.Define(iCategory, iKey, RProperty::EInt, KPassPolicy, KPassPolicy, 16);
sl@0
    99
			TF_ERROR(r, r == KErrArgument);
sl@0
   100
sl@0
   101
			// Following defintion the property has a default value, 0 for integer properties
sl@0
   102
			r = prop.Define(iCategory, iKey, RProperty::EInt, KPassPolicy, KPassPolicy);
sl@0
   103
			TF_ERROR(r, r == KErrNone);
sl@0
   104
			TInt value;
sl@0
   105
			r = prop.Get(iCategory, iKey, value);
sl@0
   106
			TF_ERROR(r, r == KErrNone);
sl@0
   107
			TF_ERROR(value, value == 0);
sl@0
   108
			r = prop.Delete(iCategory, iKey);
sl@0
   109
			TF_ERROR(r, r == KErrNone);
sl@0
   110
			}
sl@0
   111
		else 
sl@0
   112
			{
sl@0
   113
			// Defne fails with KErrTooBig if aPeallocate is grater than KMaxPropertySize.
sl@0
   114
			r = prop.Define(iCategory, iKey, RProperty::EByteArray, KPassPolicy, KPassPolicy, RProperty::KMaxPropertySize);
sl@0
   115
			TF_ERROR(r, r == KErrNone);
sl@0
   116
			r = prop.Delete(iCategory, iKey);
sl@0
   117
			TF_ERROR(r, r == KErrNone);
sl@0
   118
			r = prop.Define(iCategory, iKey, RProperty::EByteArray, KPassPolicy, KPassPolicy, RProperty::KMaxPropertySize + 1);
sl@0
   119
			TF_ERROR(r, r == KErrTooBig);
sl@0
   120
sl@0
   121
			// Following defintion the property has a default value, zero-length data for byte-array and text 
sl@0
   122
			// properties. 
sl@0
   123
			r = prop.Define(iCategory, iKey, RProperty::EByteArray, KPassPolicy, KPassPolicy);
sl@0
   124
			TF_ERROR(r, r == KErrNone);
sl@0
   125
			TBuf<16> buf;
sl@0
   126
			r = prop.Get(iCategory, iKey, buf);
sl@0
   127
			TF_ERROR(r, r == KErrNone);
sl@0
   128
			TF_ERROR(buf.Size(), buf.Size() == 0);
sl@0
   129
sl@0
   130
			TBuf8<16> buf8;
sl@0
   131
			r = prop.Get(iCategory, iKey, buf8);
sl@0
   132
			TF_ERROR(r, r == KErrNone);
sl@0
   133
			TF_ERROR(buf8.Size(), buf8.Size() == 0);
sl@0
   134
			r = prop.Delete(iCategory, iKey);
sl@0
   135
			TF_ERROR(r, r == KErrNone);
sl@0
   136
			}
sl@0
   137
sl@0
   138
		// Pending subscriptions for this property will not be completed until a new value is published.
sl@0
   139
		r = prop.Attach(iCategory, iKey);
sl@0
   140
		TF_ERROR(r, r == KErrNone);
sl@0
   141
		TRequestStatus status;
sl@0
   142
		prop.Subscribe(status);
sl@0
   143
		TF_ERROR(status.Int(), status.Int() == KRequestPending);
sl@0
   144
		r = prop.Define(iCategory, iKey, iType, KPassPolicy, KPassPolicy);
sl@0
   145
		TF_ERROR(r, r == KErrNone);
sl@0
   146
		TF_ERROR(status.Int(), status.Int() == KRequestPending);
sl@0
   147
		r = prop.Delete(iCategory, iKey);
sl@0
   148
		TF_ERROR(r, r == KErrNone);
sl@0
   149
		User::WaitForRequest(status);
sl@0
   150
		TF_ERROR(status.Int(), status.Int() == KErrNotFound);
sl@0
   151
		prop.Close();
sl@0
   152
		}
sl@0
   153
	}
sl@0
   154
sl@0
   155
_LIT(KDeleteName, "RProperty::Delete() Basics");
sl@0
   156
 
sl@0
   157
CPropDelete::CPropDelete(TUid aCategory, TUint aKey, RProperty::TType aType) : 
sl@0
   158
	  CTestProgram(KDeleteName), iCategory(aCategory), iKey(aKey), iType(aType)
sl@0
   159
	{
sl@0
   160
	}
sl@0
   161
sl@0
   162
void CPropDelete::Run(TUint aCount)
sl@0
   163
	{
sl@0
   164
	TUid mySid;
sl@0
   165
	mySid.iUid = RProcess().SecureId();
sl@0
   166
	for(TUint i = 0; i < aCount; ++i)
sl@0
   167
		{
sl@0
   168
		RProperty prop;
sl@0
   169
sl@0
   170
		// If the property has not been defined Delete fails with KErrNotFound.
sl@0
   171
		TInt r = prop.Delete(iCategory, iKey);
sl@0
   172
		TF_ERROR(r, r == KErrNotFound);
sl@0
   173
	
sl@0
   174
		// Test deleting properties in the default category (==our SID)
sl@0
   175
		//deleting of property in the default category (==our SID) should fail until the property is defined
sl@0
   176
		r = prop.Delete(iKey);
sl@0
   177
		TF_ERROR(r, r == KErrNotFound);
sl@0
   178
		
sl@0
   179
		r = prop.Define(iKey, iType, KFailPolicy, KFailPolicy);
sl@0
   180
		TF_ERROR(r, r == KErrNone);
sl@0
   181
		r = prop.Delete(iKey);
sl@0
   182
		TF_ERROR(r, r == KErrNone);
sl@0
   183
				
sl@0
   184
		r = prop.Define(mySid, iKey, iType, KFailPolicy, KFailPolicy);
sl@0
   185
		TF_ERROR(r, r == KErrNone);
sl@0
   186
		r = prop.Delete(mySid, iKey);
sl@0
   187
		TF_ERROR(r, r == KErrNone);
sl@0
   188
		r = prop.Delete( iKey);
sl@0
   189
		TF_ERROR(r, r == KErrNotFound);
sl@0
   190
		
sl@0
   191
		r = prop.Define(mySid, iKey, iType, KFailPolicy, KFailPolicy);
sl@0
   192
		TF_ERROR(r, r == KErrNone);
sl@0
   193
		r = prop.Delete( iKey);
sl@0
   194
		TF_ERROR(r, r == KErrNone);
sl@0
   195
		r = prop.Delete(mySid, iKey);
sl@0
   196
		TF_ERROR(r, r == KErrNotFound);
sl@0
   197
	
sl@0
   198
		// Any pending subscriptions for this property will be completed with KErrNotFound.
sl@0
   199
		r = prop.Define(iCategory, iKey, iType, KPassPolicy, KPassPolicy);
sl@0
   200
		TF_ERROR(r, r == KErrNone);
sl@0
   201
		r = prop.Attach(iCategory, iKey);
sl@0
   202
		TF_ERROR(r, r == KErrNone);
sl@0
   203
		TRequestStatus status;
sl@0
   204
		prop.Subscribe(status);
sl@0
   205
		TF_ERROR(status.Int(), status.Int() == KRequestPending);
sl@0
   206
		r = prop.Delete(iCategory, iKey);
sl@0
   207
		TF_ERROR(r, r == KErrNone);
sl@0
   208
		User::WaitForRequest(status);
sl@0
   209
		TF_ERROR(status.Int(), status.Int() == KErrNotFound);
sl@0
   210
sl@0
   211
		// Any new request will not complete until the property is defined and published again.
sl@0
   212
		prop.Subscribe(status);
sl@0
   213
		TF_ERROR(status.Int(), status.Int() == KRequestPending);
sl@0
   214
		r = prop.Define(iCategory, iKey, iType, KPassPolicy, KPassPolicy);
sl@0
   215
		TF_ERROR(r, r == KErrNone);
sl@0
   216
		TF_ERROR(status.Int(), status.Int() == KRequestPending);
sl@0
   217
		if (iType == RProperty::EInt)
sl@0
   218
			{
sl@0
   219
			r = prop.Set(1);
sl@0
   220
			TF_ERROR(r, r == KErrNone);
sl@0
   221
			}
sl@0
   222
		else
sl@0
   223
			{
sl@0
   224
			r = prop.Set(_L("Foo"));
sl@0
   225
			TF_ERROR(r, r == KErrNone);
sl@0
   226
			}
sl@0
   227
		User::WaitForRequest(status);
sl@0
   228
		TF_ERROR(status.Int(), status.Int() == KErrNone);
sl@0
   229
		r = prop.Delete(iCategory, iKey);
sl@0
   230
		TF_ERROR(r, r == KErrNone);
sl@0
   231
		prop.Close();
sl@0
   232
		}
sl@0
   233
	}
sl@0
   234
sl@0
   235
_LIT(KPanicName, "RProperty Panics");
sl@0
   236
sl@0
   237
CPropPanic::CPropPanic(TUid aCategory, TUint aKey) : 
sl@0
   238
	  CTestProgram(KPanicName), iCategory(aCategory), iKey(aKey)
sl@0
   239
	{
sl@0
   240
	}
sl@0
   241
sl@0
   242
TInt CPropPanic::DoubleSubscribeThreadEntry(TAny* ptr)
sl@0
   243
	{
sl@0
   244
	CPropPanic* prog = (CPropPanic*) ptr;
sl@0
   245
	RProperty prop;
sl@0
   246
	TInt r = prop.Attach(prog->iCategory, prog->iKey, EOwnerThread);
sl@0
   247
	TF_ERROR_PROG(prog, r, r == KErrNone);
sl@0
   248
	TRequestStatus status;
sl@0
   249
	prop.Subscribe(status);
sl@0
   250
	// Next statement shall Panic.	
sl@0
   251
	prop.Subscribe(status);
sl@0
   252
	// Never get here
sl@0
   253
	return KErrNone;
sl@0
   254
	}
sl@0
   255
sl@0
   256
TInt CPropPanic::BadHandleSubscribeThreadEntry(TAny* /*ptr*/)
sl@0
   257
	{
sl@0
   258
	RProperty prop;
sl@0
   259
	TRequestStatus status;
sl@0
   260
	prop.Subscribe(status);
sl@0
   261
	return KErrNone;
sl@0
   262
	}
sl@0
   263
sl@0
   264
TInt CPropPanic::BadHandleCancelThreadEntry(TAny* /*ptr*/)
sl@0
   265
	{
sl@0
   266
	RProperty prop;
sl@0
   267
	prop.Cancel();
sl@0
   268
	return KErrNone;
sl@0
   269
	}
sl@0
   270
sl@0
   271
TInt CPropPanic::BadHandleGetIThreadEntry(TAny* /*ptr*/)
sl@0
   272
	{
sl@0
   273
	RProperty prop;
sl@0
   274
	TInt i;
sl@0
   275
	prop.Get(i);
sl@0
   276
	return KErrNone;
sl@0
   277
	}
sl@0
   278
sl@0
   279
TInt CPropPanic::BadHandleGetBThreadEntry(TAny* /*ptr*/)
sl@0
   280
	{
sl@0
   281
	RProperty prop;
sl@0
   282
	TBuf<64> buf;
sl@0
   283
	prop.Get(buf);
sl@0
   284
	return KErrNone;
sl@0
   285
	}
sl@0
   286
sl@0
   287
TInt CPropPanic::BadHandleSetIThreadEntry(TAny* /*ptr*/)
sl@0
   288
	{
sl@0
   289
	RProperty prop;
sl@0
   290
	TInt i = 1;
sl@0
   291
	prop.Set(i);
sl@0
   292
	return KErrNone;
sl@0
   293
	}
sl@0
   294
sl@0
   295
TInt CPropPanic::BadHandleSetBThreadEntry(TAny* /*ptr*/)
sl@0
   296
	{
sl@0
   297
	RProperty prop;
sl@0
   298
	TBuf<64> buf;
sl@0
   299
	prop.Set(buf);
sl@0
   300
	return KErrNone;
sl@0
   301
	}
sl@0
   302
sl@0
   303
TThreadFunction CPropPanic::BadHandles[] = {
sl@0
   304
	CPropPanic::BadHandleSubscribeThreadEntry,
sl@0
   305
	CPropPanic::BadHandleCancelThreadEntry,
sl@0
   306
	CPropPanic::BadHandleGetIThreadEntry,
sl@0
   307
	CPropPanic::BadHandleGetBThreadEntry,
sl@0
   308
	CPropPanic::BadHandleSetIThreadEntry,
sl@0
   309
	CPropPanic::BadHandleSetBThreadEntry,
sl@0
   310
	NULL
sl@0
   311
};
sl@0
   312
sl@0
   313
void CPropPanic::Run(TUint /* aCount */)
sl@0
   314
	{
sl@0
   315
	// Only one subscriptoin per RProperty object is allowed, the caller will be paniced if
sl@0
   316
	// there is already a subscription on this object.
sl@0
   317
	TRequestStatus status;
sl@0
   318
	TExitType exit;
sl@0
   319
	RThread thr;
sl@0
   320
	TInt r = thr.Create(KNullDesC, DoubleSubscribeThreadEntry, 0x2000, NULL, this);
sl@0
   321
	TF_ERROR(r, r == KErrNone);
sl@0
   322
	thr.Logon(status);
sl@0
   323
sl@0
   324
	TBool jit = User::JustInTime();
sl@0
   325
	User::SetJustInTime(EFalse);
sl@0
   326
sl@0
   327
	thr.Resume();
sl@0
   328
	User::WaitForRequest(status);
sl@0
   329
	thr.Close();
sl@0
   330
sl@0
   331
	User::SetJustInTime(jit);
sl@0
   332
sl@0
   333
	TF_ERROR(status.Int(), status.Int() == ERequestAlreadyPending);	
sl@0
   334
sl@0
   335
	for (TInt i = 0; BadHandles[i]; ++i)
sl@0
   336
		{
sl@0
   337
		r = thr.Create(KNullDesC, BadHandles[i], 0x2000, NULL, this);
sl@0
   338
		TF_ERROR(r, r == KErrNone);
sl@0
   339
		thr.Logon(status);
sl@0
   340
sl@0
   341
		jit = User::JustInTime();
sl@0
   342
		User::SetJustInTime(EFalse);
sl@0
   343
sl@0
   344
		thr.Resume();
sl@0
   345
		User::WaitForRequest(status);
sl@0
   346
		exit = thr.ExitType();
sl@0
   347
		thr.Close();
sl@0
   348
sl@0
   349
		User::SetJustInTime(jit);
sl@0
   350
sl@0
   351
		TF_ERROR(status.Int(), status.Int() == EBadHandle);	
sl@0
   352
		TF_ERROR(exit, exit == EExitPanic);
sl@0
   353
		}
sl@0
   354
	}
sl@0
   355
sl@0
   356
_LIT(KSetGetName, "RProperty::Set()/Get() Basics");
sl@0
   357
sl@0
   358
CPropSetGet::CPropSetGet(TUid aCategory, TUint aKey, RProperty::TType aType) : 
sl@0
   359
	  CTestProgram(KSetGetName), iCategory(aCategory), iKey(aKey), iType(aType)
sl@0
   360
	{
sl@0
   361
	}
sl@0
   362
sl@0
   363
void CPropSetGet::Run(TUint aCount)
sl@0
   364
	{
sl@0
   365
	for(TUint i = 0; i < aCount; ++i)
sl@0
   366
		{
sl@0
   367
		TInt r;
sl@0
   368
		RProperty prop;
sl@0
   369
sl@0
   370
		r = prop.Attach(iCategory, iKey);
sl@0
   371
		TF_ERROR(r, r == KErrNone);
sl@0
   372
sl@0
   373
		// If the property has not been defined this fails with KErrNotFound.
sl@0
   374
			{
sl@0
   375
			TInt value;
sl@0
   376
			TBuf<16> buf;
sl@0
   377
			TBuf8<16> buf8;
sl@0
   378
			if (iType == RProperty::EInt)
sl@0
   379
				{
sl@0
   380
				r = prop.Get(iCategory, iKey, value);
sl@0
   381
				TF_ERROR(r, r == KErrNotFound);
sl@0
   382
				r = prop.Set(iCategory, iKey, value);
sl@0
   383
				TF_ERROR(r, r == KErrNotFound);
sl@0
   384
				}
sl@0
   385
			else
sl@0
   386
				{
sl@0
   387
				r = prop.Get(iCategory, iKey, buf);
sl@0
   388
				TF_ERROR(r, r == KErrNotFound);
sl@0
   389
				r = prop.Set(iCategory, iKey, buf);
sl@0
   390
				TF_ERROR(r, r == KErrNotFound);
sl@0
   391
				r = prop.Get(iCategory, iKey, buf8);
sl@0
   392
				TF_ERROR(r, r == KErrNotFound);
sl@0
   393
				r = prop.Set(iCategory, iKey, buf8);
sl@0
   394
				TF_ERROR(r, r == KErrNotFound);
sl@0
   395
				}
sl@0
   396
sl@0
   397
			if (iType == RProperty::EInt)
sl@0
   398
				{
sl@0
   399
				r = prop.Get(value);
sl@0
   400
				TF_ERROR(r, r == KErrNotFound);
sl@0
   401
				r = prop.Set(value);
sl@0
   402
				TF_ERROR(r, r == KErrNotFound);
sl@0
   403
				}
sl@0
   404
			else
sl@0
   405
				{
sl@0
   406
				r = prop.Get(buf);
sl@0
   407
				TF_ERROR(r, r == KErrNotFound);
sl@0
   408
				r = prop.Set(buf);
sl@0
   409
				TF_ERROR(r, r == KErrNotFound);
sl@0
   410
				r = prop.Get(buf8);
sl@0
   411
				TF_ERROR(r, r == KErrNotFound);
sl@0
   412
				r = prop.Set(buf8);
sl@0
   413
				TF_ERROR(r, r == KErrNotFound);
sl@0
   414
				}
sl@0
   415
			}
sl@0
   416
sl@0
   417
		r = prop.Define(iCategory, iKey, iType, KPassPolicy, KPassPolicy);
sl@0
   418
		TF_ERROR(r, r == KErrNone);
sl@0
   419
sl@0
   420
		// Can set property to zero length
sl@0
   421
			{
sl@0
   422
			if (iType ==  RProperty::EByteArray)
sl@0
   423
				{
sl@0
   424
				TBuf8<20> buf8(20);
sl@0
   425
				r = prop.Set(iCategory, iKey, KNullDesC8);
sl@0
   426
				TF_ERROR(r, r == KErrNone);
sl@0
   427
				r = prop.Get(iCategory, iKey, buf8);
sl@0
   428
				TF_ERROR(r, r == KErrNone);
sl@0
   429
				TF_ERROR(buf8.Length(), buf8.Length() == 0);
sl@0
   430
				}
sl@0
   431
			}
sl@0
   432
sl@0
   433
		// If the property is larger than KMaxPropertySize this fails with KErrTooBig
sl@0
   434
			{
sl@0
   435
			if (iType ==  RProperty::EByteArray)
sl@0
   436
				{
sl@0
   437
				TBuf<RProperty::KMaxPropertySize/2 + 1> buf(RProperty::KMaxPropertySize/2 + 1);
sl@0
   438
				TBuf8<RProperty::KMaxPropertySize + 1> buf8(RProperty::KMaxPropertySize + 1);
sl@0
   439
				r = prop.Set(iCategory, iKey, buf);
sl@0
   440
				TF_ERROR(r, r == KErrTooBig);
sl@0
   441
				r = prop.Set(iCategory, iKey, buf8);
sl@0
   442
				TF_ERROR(r, r == KErrTooBig);
sl@0
   443
				r = prop.Set(buf);
sl@0
   444
				TF_ERROR(r, r == KErrTooBig);
sl@0
   445
				r = prop.Set(buf8);
sl@0
   446
				TF_ERROR(r, r == KErrTooBig);
sl@0
   447
				}
sl@0
   448
			}
sl@0
   449
sl@0
   450
		// When type of operation mismatch with the property type this fails with KErrArgument.
sl@0
   451
			{
sl@0
   452
			TInt value;
sl@0
   453
			TBuf<16> buf;
sl@0
   454
			TBuf8<16> buf8;
sl@0
   455
			if (iType !=  RProperty::EInt)
sl@0
   456
				{
sl@0
   457
				r = prop.Get(iCategory, iKey, value);
sl@0
   458
				TF_ERROR(r, r == KErrArgument);
sl@0
   459
				r = prop.Set(iCategory, iKey, value);
sl@0
   460
				TF_ERROR(r, r == KErrArgument);
sl@0
   461
				r = prop.Get(value);
sl@0
   462
				TF_ERROR(r, r == KErrArgument);
sl@0
   463
				r = prop.Set(value);
sl@0
   464
				TF_ERROR(r, r == KErrArgument);
sl@0
   465
				}
sl@0
   466
			else
sl@0
   467
				{
sl@0
   468
				r = prop.Get(iCategory, iKey, buf);
sl@0
   469
				TF_ERROR(r, r == KErrArgument);
sl@0
   470
				r = prop.Set(iCategory, iKey, buf);
sl@0
   471
				TF_ERROR(r, r == KErrArgument);
sl@0
   472
				r = prop.Get(iCategory, iKey, buf8);
sl@0
   473
				TF_ERROR(r, r == KErrArgument);
sl@0
   474
				r = prop.Set(iCategory, iKey, buf8);
sl@0
   475
				TF_ERROR(r, r == KErrArgument);
sl@0
   476
				r = prop.Get(buf);
sl@0
   477
				TF_ERROR(r, r == KErrArgument);
sl@0
   478
				r = prop.Set(buf);
sl@0
   479
				TF_ERROR(r, r == KErrArgument);
sl@0
   480
				r = prop.Get(buf8);
sl@0
   481
				TF_ERROR(r, r == KErrArgument);
sl@0
   482
				r = prop.Set(buf8);
sl@0
   483
				TF_ERROR(r, r == KErrArgument);
sl@0
   484
				}
sl@0
   485
			}
sl@0
   486
sl@0
   487
		// Get/Set
sl@0
   488
		if (iType == RProperty::EInt)
sl@0
   489
			{
sl@0
   490
				{
sl@0
   491
				r = prop.Set(1);
sl@0
   492
				TF_ERROR(r, r == KErrNone);
sl@0
   493
				TInt value = 0;
sl@0
   494
				r = prop.Get(value);
sl@0
   495
				TF_ERROR(r, r == KErrNone);
sl@0
   496
				TF_ERROR(value, value == 1);
sl@0
   497
				}
sl@0
   498
				{
sl@0
   499
				TInt value = 0;
sl@0
   500
				r = prop.Set(iCategory, iKey, 1);
sl@0
   501
				TF_ERROR(r, r == KErrNone);
sl@0
   502
				r = prop.Get(iCategory, iKey, value);
sl@0
   503
				TF_ERROR(r, r == KErrNone);
sl@0
   504
				TF_ERROR(value, value == 1);
sl@0
   505
				}
sl@0
   506
			}
sl@0
   507
		else 
sl@0
   508
			{
sl@0
   509
				{
sl@0
   510
				TBuf<16> ibuf(_L("Foo"));
sl@0
   511
				TBuf<16> obuf;
sl@0
   512
				r = prop.Set(ibuf);
sl@0
   513
				TF_ERROR(r, r == KErrNone);
sl@0
   514
				r = prop.Get(obuf);
sl@0
   515
				TF_ERROR(r, r == KErrNone);
sl@0
   516
				r = obuf.Compare(ibuf);
sl@0
   517
				TF_ERROR(r, r == 0);
sl@0
   518
				}
sl@0
   519
				{
sl@0
   520
				TBuf8<16> ibuf8((TUint8*)"Foo");
sl@0
   521
				TBuf8<16> obuf8;
sl@0
   522
				r = prop.Set(ibuf8);
sl@0
   523
				TF_ERROR(r, r == KErrNone);
sl@0
   524
				r = prop.Get(obuf8);
sl@0
   525
				TF_ERROR(r, r == KErrNone);
sl@0
   526
				r = obuf8.Compare(ibuf8);
sl@0
   527
				TF_ERROR(r, r == 0);
sl@0
   528
				}
sl@0
   529
				{
sl@0
   530
				TBuf<16> ibuf(_L("Foo"));
sl@0
   531
				TBuf<16> obuf;
sl@0
   532
				r = prop.Set(iCategory, iKey, ibuf);
sl@0
   533
				TF_ERROR(r, r == KErrNone);
sl@0
   534
				r = prop.Get(iCategory, iKey, obuf);
sl@0
   535
				TF_ERROR(r, r == KErrNone);
sl@0
   536
				r = obuf.Compare(ibuf);
sl@0
   537
				TF_ERROR(r, r == 0);
sl@0
   538
				}
sl@0
   539
				{
sl@0
   540
				TBuf8<16> ibuf8((TUint8*)"Foo");
sl@0
   541
				TBuf8<16> obuf8;
sl@0
   542
				r = prop.Set(iCategory, iKey, ibuf8);
sl@0
   543
				TF_ERROR(r, r == KErrNone);
sl@0
   544
				r = prop.Get(iCategory, iKey, obuf8);
sl@0
   545
				TF_ERROR(r, r == KErrNone);
sl@0
   546
				r = obuf8.Compare(ibuf8);
sl@0
   547
				TF_ERROR(r, r == 0);
sl@0
   548
				}
sl@0
   549
			}
sl@0
   550
sl@0
   551
		// If the supplied buffer is too small this fails with KErrOverflow and the truncated value is reported.
sl@0
   552
		if (iType == RProperty::EByteArray)
sl@0
   553
			{
sl@0
   554
				{
sl@0
   555
				TBuf<16> ibuf(_L("0123456789012345"));
sl@0
   556
				TBuf<16> obuf(_L("abcdefghigklmnop"));
sl@0
   557
				TPtr optr((TUint16*) obuf.Ptr(), 0, 15);
sl@0
   558
				r = prop.Set(iCategory, iKey, ibuf);
sl@0
   559
				TF_ERROR(r, r == KErrNone);
sl@0
   560
				r = prop.Get(iCategory, iKey, optr);
sl@0
   561
				TF_ERROR(r, r == KErrOverflow);
sl@0
   562
				TF_ERROR(optr.Length(), optr.Length() == 15); 
sl@0
   563
				TF_ERROR(obuf[14], obuf[14] == TText('4')); 
sl@0
   564
				TF_ERROR(obuf[15], obuf[15] == TText('p'));
sl@0
   565
				}
sl@0
   566
				{
sl@0
   567
				TBuf8<16> ibuf8((TUint8*) "0123456789012345");
sl@0
   568
				TBuf8<16> obuf8((TUint8*) "abcdefghigklmnop");
sl@0
   569
				TPtr8 optr8((TUint8*) obuf8.Ptr(), 0, 15);
sl@0
   570
				r = prop.Set(iCategory, iKey, ibuf8);
sl@0
   571
				TF_ERROR(r, r == KErrNone);
sl@0
   572
				r = prop.Get(iCategory, iKey, optr8);
sl@0
   573
				TF_ERROR(r, r == KErrOverflow);
sl@0
   574
				TF_ERROR(optr8.Length(), optr8.Length() == 15); 
sl@0
   575
				TF_ERROR(obuf8[14], obuf8[14] == '4'); 
sl@0
   576
				TF_ERROR(obuf8[15], obuf8[15] == 'p');
sl@0
   577
				}
sl@0
   578
				{
sl@0
   579
				TBuf<16> ibuf(_L("0123456789012345"));
sl@0
   580
				TBuf<16> obuf(_L("abcdefghigklmnop"));
sl@0
   581
				TPtr optr((TUint16*) obuf.Ptr(), 0, 15);
sl@0
   582
				r = prop.Set(ibuf);
sl@0
   583
				TF_ERROR(r, r == KErrNone);
sl@0
   584
				r = prop.Get(optr);
sl@0
   585
				TF_ERROR(r, r == KErrOverflow);
sl@0
   586
				TF_ERROR(optr.Length(), optr.Length() == 15); 
sl@0
   587
				TF_ERROR(obuf[14], obuf[14] == TText('4')); 
sl@0
   588
				TF_ERROR(obuf[15], obuf[15] == TText('p')); 
sl@0
   589
				}
sl@0
   590
				{
sl@0
   591
				TBuf8<16> ibuf8((TUint8*) "0123456789012345");
sl@0
   592
				TBuf8<16> obuf8((TUint8*) "abcdefghigklmnop");
sl@0
   593
				TPtr8 optr8((TUint8*) obuf8.Ptr(), 0, 15);
sl@0
   594
				r = prop.Set(ibuf8);
sl@0
   595
				TF_ERROR(r, r == KErrNone);
sl@0
   596
				r = prop.Get(optr8);
sl@0
   597
				TF_ERROR(r, r == KErrOverflow);
sl@0
   598
				TF_ERROR(optr8.Length(), optr8.Length() == 15); 
sl@0
   599
				TF_ERROR(obuf8[14], obuf8[14] == '4'); 
sl@0
   600
				TF_ERROR(obuf8[15], obuf8[15] == 'p');
sl@0
   601
				}
sl@0
   602
			}
sl@0
   603
sl@0
   604
		// Get/Set zero-length data
sl@0
   605
		if (iType == RProperty::EByteArray)
sl@0
   606
			{
sl@0
   607
				{
sl@0
   608
				TBuf<16> ibuf(_L("Foo"));
sl@0
   609
				TBuf<16> obuf;
sl@0
   610
				TPtr nullbuf(NULL, 0);
sl@0
   611
sl@0
   612
				r = prop.Set(ibuf);
sl@0
   613
				TF_ERROR(r, r == KErrNone);
sl@0
   614
				r = prop.Get(nullbuf);
sl@0
   615
				TF_ERROR(r, r == KErrOverflow);
sl@0
   616
				TF_ERROR(nullbuf.Length(), (nullbuf.Length() == 0));
sl@0
   617
sl@0
   618
				r = prop.Set(nullbuf);
sl@0
   619
				TF_ERROR(r, r == KErrNone);
sl@0
   620
				r = prop.Get(obuf);
sl@0
   621
				TF_ERROR(r, r == KErrNone);
sl@0
   622
				TF_ERROR(obuf.Length(), (obuf.Length() == 0));
sl@0
   623
				}
sl@0
   624
				{
sl@0
   625
				TBuf8<16> ibuf((TUint8*) "Foo");
sl@0
   626
				TBuf8<16> obuf;
sl@0
   627
				TPtr8 nullbuf(NULL, 0);
sl@0
   628
sl@0
   629
				r = prop.Set(ibuf);
sl@0
   630
				TF_ERROR(r, r == KErrNone);
sl@0
   631
				r = prop.Get(nullbuf);
sl@0
   632
				TF_ERROR(r, r == KErrOverflow);
sl@0
   633
				TF_ERROR(nullbuf.Length(), (nullbuf.Length() == 0));
sl@0
   634
sl@0
   635
				r = prop.Set(nullbuf);
sl@0
   636
				TF_ERROR(r, r == KErrNone);
sl@0
   637
				r = prop.Get(obuf);
sl@0
   638
				TF_ERROR(r, r == KErrNone);
sl@0
   639
				TF_ERROR(obuf.Length(), (obuf.Length() == 0));
sl@0
   640
				}
sl@0
   641
			}
sl@0
   642
sl@0
   643
		r = prop.Delete(iCategory, iKey);
sl@0
   644
		TF_ERROR(r, r == KErrNone);
sl@0
   645
		prop.Close();
sl@0
   646
		}
sl@0
   647
	}
sl@0
   648
sl@0
   649
		
sl@0
   650
_LIT(KSubsCancelName, "RProperty::Subscribe()/Cancel() Basics");
sl@0
   651
 
sl@0
   652
CPropSubsCancel::CPropSubsCancel(TUid aCategory, TUint aKey, RProperty::TType aType) : 
sl@0
   653
	  CTestProgram(KSubsCancelName), iCategory(aCategory), iKey(aKey), iType(aType)
sl@0
   654
	{
sl@0
   655
	}
sl@0
   656
sl@0
   657
sl@0
   658
void CPropSubsCancel::Run(TUint aCount)
sl@0
   659
	{
sl@0
   660
sl@0
   661
	for(TUint i = 0; i < aCount; ++i)
sl@0
   662
		{
sl@0
   663
		TRequestStatus status;
sl@0
   664
		RProperty prop;
sl@0
   665
sl@0
   666
		TInt r = prop.Attach(iCategory, iKey);
sl@0
   667
		TF_ERROR(r, r == KErrNone);
sl@0
   668
sl@0
   669
		// The calling thread will have the specified request status signalled when the property is next updated.
sl@0
   670
		r = prop.Define(iCategory, iKey, iType, KPassPolicy, KPassPolicy);
sl@0
   671
		TF_ERROR(r, r == KErrNone);
sl@0
   672
		prop.Subscribe(status);
sl@0
   673
		TF_ERROR(status.Int(), status.Int() == KRequestPending);
sl@0
   674
		if (iType == RProperty::EInt)
sl@0
   675
			{
sl@0
   676
			r = prop.Set(1);
sl@0
   677
			TF_ERROR(r, r == KErrNone);
sl@0
   678
			}
sl@0
   679
		else
sl@0
   680
			{
sl@0
   681
			r = prop.Set(_L("Foo"));
sl@0
   682
			TF_ERROR(r, r == KErrNone);
sl@0
   683
			}
sl@0
   684
		User::WaitForRequest(status);
sl@0
   685
		TF_ERROR(status.Int(), status.Int() == KErrNone);
sl@0
   686
		r = prop.Delete(iCategory, iKey);
sl@0
   687
		TF_ERROR(r, r == KErrNone);
sl@0
   688
	
sl@0
   689
		// If the property has not been defined, the request will not complete until the property
sl@0
   690
		// is defined and published.
sl@0
   691
		prop.Subscribe(status);
sl@0
   692
		TF_ERROR(status.Int(), status.Int() == KRequestPending);
sl@0
   693
		r = prop.Define(iCategory, iKey, iType, KPassPolicy, KPassPolicy);
sl@0
   694
		TF_ERROR(r, r == KErrNone);
sl@0
   695
		TF_ERROR(status.Int(), status.Int() == KRequestPending);
sl@0
   696
		if (iType == RProperty::EInt)
sl@0
   697
			{
sl@0
   698
			r = prop.Set(1);
sl@0
   699
			TF_ERROR(r, r == KErrNone);
sl@0
   700
			}
sl@0
   701
		else
sl@0
   702
			{
sl@0
   703
			r = prop.Set(_L("Foo"));
sl@0
   704
			TF_ERROR(r, r == KErrNone);
sl@0
   705
			}
sl@0
   706
		User::WaitForRequest(status);
sl@0
   707
		TF_ERROR(status.Int(), status.Int() == KErrNone);
sl@0
   708
		r = prop.Delete(iCategory, iKey);
sl@0
   709
		TF_ERROR(r, r == KErrNone);
sl@0
   710
sl@0
   711
		// Cancel an outstanding subscription request for this property handle. 
sl@0
   712
		// If it has not already completed, the request is completed with KErrCancelled.
sl@0
   713
		prop.Subscribe(status);
sl@0
   714
		TF_ERROR(status.Int(), status.Int() == KRequestPending);
sl@0
   715
		prop.Cancel();		
sl@0
   716
		User::WaitForRequest(status);
sl@0
   717
		TF_ERROR(status.Int(), status.Int() == KErrCancel);
sl@0
   718
sl@0
   719
		r = prop.Define(iCategory, iKey, iType, KPassPolicy, KPassPolicy);
sl@0
   720
		TF_ERROR(r, r == KErrNone);
sl@0
   721
		prop.Subscribe(status);
sl@0
   722
		TF_ERROR(status.Int(), status.Int() == KRequestPending);
sl@0
   723
		if (iType == RProperty::EInt)
sl@0
   724
			{
sl@0
   725
			r = prop.Set(1);
sl@0
   726
			TF_ERROR(r, r == KErrNone);
sl@0
   727
			}
sl@0
   728
		else
sl@0
   729
			{
sl@0
   730
			r = prop.Set(_L("Foo"));
sl@0
   731
			TF_ERROR(r, r == KErrNone);
sl@0
   732
			}
sl@0
   733
		User::WaitForRequest(status);
sl@0
   734
		TF_ERROR(status.Int(), status.Int() == KErrNone);
sl@0
   735
		prop.Cancel();		
sl@0
   736
		TF_ERROR(status.Int(), status.Int() == KErrNone);
sl@0
   737
sl@0
   738
		prop.Subscribe(status);
sl@0
   739
		TF_ERROR(status.Int(), status.Int() == KRequestPending);
sl@0
   740
		prop.Cancel();		
sl@0
   741
		User::WaitForRequest(status);
sl@0
   742
		TF_ERROR(status.Int(), status.Int() == KErrCancel);
sl@0
   743
sl@0
   744
		r = prop.Delete(iCategory, iKey);
sl@0
   745
		TF_ERROR(r, r == KErrNone);
sl@0
   746
sl@0
   747
		prop.Close();
sl@0
   748
		}
sl@0
   749
	}
sl@0
   750
sl@0
   751
_LIT(KSecurityName, "RProperty Security Basics (Master)");
sl@0
   752
 
sl@0
   753
CPropSecurity::CPropSecurity(TUid aCategory, TUint aMasterKey, RProperty::TType aType, TUint aSlaveKeySlot) : 
sl@0
   754
		CTestProgram(KSecurityName), iCategory(aCategory), iMasterKey(aMasterKey), 
sl@0
   755
		iSlaveKeySlot(aSlaveKeySlot), iType(aType)
sl@0
   756
	{
sl@0
   757
	}
sl@0
   758
sl@0
   759
_LIT(KSecuritySlavePath, "t_prop_sec.exe");
sl@0
   760
sl@0
   761
void CPropSecurity::Run(TUint aCount)
sl@0
   762
	{
sl@0
   763
	for(TInt i=0; i<ECapability_Limit; i++)
sl@0
   764
		if(!PlatSec::IsCapabilityEnforced((TCapability)i))
sl@0
   765
			{
sl@0
   766
			// System isn't configured with platform security enforced
sl@0
   767
			// so don't bother running tests
sl@0
   768
			return;
sl@0
   769
			}
sl@0
   770
sl@0
   771
	TArgs args;
sl@0
   772
	args.iCount = aCount;
sl@0
   773
	args.iCategory = iCategory;
sl@0
   774
	args.iMasterKey = iMasterKey;
sl@0
   775
	args.iSlaveKeySlot = iSlaveKeySlot;
sl@0
   776
sl@0
   777
	RProperty prop;
sl@0
   778
sl@0
   779
	TInt r = prop.Define(iCategory, iMasterKey, iType, KPassPolicy, KPassPolicy);
sl@0
   780
	TF_ERROR(r, r == KErrNone);
sl@0
   781
sl@0
   782
	Exec(KSecuritySlavePath, &args, sizeof(args));
sl@0
   783
sl@0
   784
	Exec(_L("t_prop_define0.exe"), &args, sizeof(args));
sl@0
   785
	Exec(_L("t_prop_define1.exe"), &args, sizeof(args));
sl@0
   786
	Exec(_L("t_prop_define2.exe"), &args, sizeof(args));
sl@0
   787
	Exec(_L("t_prop_define3.exe"), &args, sizeof(args));
sl@0
   788
sl@0
   789
	r = prop.Delete(iCategory, iMasterKey);
sl@0
   790
	TF_ERROR(r, r == KErrNone);
sl@0
   791
	}