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 the License "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 // t_prop_define.cpp.cpp
21 #include "t_property.h"
24 TBool IHaveWriteDeviceData;
26 _LIT(KSecurityOwnerName, "RProperty Security: Owner Basics");
28 class CPropSecurityOwner : public CTestProgram
31 CPropSecurityOwner(TUid aCategory, TUint aMasterKey, TUint aSlaveKey, RProperty::TType aType) :
32 CTestProgram(KSecurityOwnerName), iCategory(aCategory), iMasterKey(aMasterKey), iSlaveKey(aSlaveKey),
37 void Run(TUint aCount);
43 RProperty::TType iType;
46 void CPropSecurityOwner::Run(TUint aCount)
48 for (TUint i = 0; i < aCount; ++i)
50 // Delete() can only be called by the property owner, as defined by the process Security ID,
51 // any other process will get a KErrPermissionDenied error.
53 TInt r = mProp.Delete(iCategory, iMasterKey);
54 TF_ERROR(r, r == KErrPermissionDenied);
60 _LIT(KPropDefineSecurityName, "RProperty Security: Define category security");
62 class CPropDefineSecurity : public CTestProgram
65 CPropDefineSecurity(TUid aCategory, TUint aMasterKey, TUint aSlaveKey, RProperty::TType aType) :
66 CTestProgram(KPropDefineSecurityName), iCategory(aCategory), iMasterKey(aMasterKey), iSlaveKey(aSlaveKey),
71 void Run(TUint aCount);
77 RProperty::TType iType;
80 void CPropDefineSecurity::Run(TUint aCount)
82 for (TUint i = 0; i < aCount; ++i)
84 // Test defining in the system category
86 TInt r = prop.Define(KUidSystemCategory, iSlaveKey, iType, KPassPolicy, KPassPolicy);
87 RDebug::Printf("CPropDefineSecurity define with System Category returns %d",r);
88 TF_ERROR(r, r == IHaveWriteDeviceData ? KErrNone : KErrPermissionDenied);
91 r = prop.Delete(KUidSystemCategory, iSlaveKey);
92 TF_ERROR(r, r == KErrNone);
95 // Tesk defining properties with categories above and below security threshold
96 TUid categoryA = { KUidSecurityThresholdCategoryValue-1 };
97 r = prop.Define(categoryA, iSlaveKey, iType, KPassPolicy, KPassPolicy);
98 RDebug::Printf("CPropDefineSecurity define with Category A returns %d",r);
99 TF_ERROR(r, r == (categoryA==MySecureId || IHaveWriteDeviceData) ? KErrNone : KErrPermissionDenied);
102 r = prop.Delete(categoryA, iSlaveKey);
103 TF_ERROR(r, r == KErrNone);
105 TUid categoryB = { KUidSecurityThresholdCategoryValue };
106 r = prop.Define(categoryB, iSlaveKey, iType, KPassPolicy, KPassPolicy);
107 RDebug::Printf("CPropDefineSecurity define with Category B returns %d",r);
108 TF_ERROR(r, r == (categoryB==MySecureId) ? KErrNone : KErrPermissionDenied);
111 r = prop.Delete(categoryB, iSlaveKey);
112 TF_ERROR(r, r == KErrNone);
114 TUid categoryC = { KUidSecurityThresholdCategoryValue+1 };
115 r = prop.Define(categoryC, iSlaveKey, iType, KPassPolicy, KPassPolicy);
116 RDebug::Printf("CPropDefineSecurity define with Category C returns %d",r);
117 TF_ERROR(r, r == KErrPermissionDenied);
125 GLDEF_C TInt E32Main()
128 info.Set(RProcess());
129 MySecureId = info.iSecureId;
130 IHaveWriteDeviceData = info.iCaps.HasCapability(ECapabilityWriteDeviceData);
132 TInt len = User::CommandLineLength();
133 __ASSERT_ALWAYS(len, User::Panic(_L("t_prop_sec: bad args"), 0));
135 // Get arguments for the command line
136 TInt size = len * sizeof(TUint16);
137 HBufC8* hb = HBufC8::NewMax(size);
138 __ASSERT_ALWAYS(hb, User::Panic(_L("t_prop_sec: no memory"), 0));
139 TPtr cmd((TUint16*) hb->Ptr(), len);
140 User::CommandLine(cmd);
141 CPropSecurity::TArgs* args = (CPropSecurity::TArgs*) hb->Ptr();
143 CTestProgram::Start();
145 CTestProgram* progs[] =
147 new CPropSecurityOwner(args->iCategory, args->iMasterKey, args->iSlaveKeySlot, RProperty::EInt),
148 new CPropSecurityOwner(args->iCategory, args->iMasterKey, args->iSlaveKeySlot + 1, RProperty::EByteArray),
149 new CPropDefineSecurity(args->iCategory, args->iMasterKey, args->iSlaveKeySlot, RProperty::EInt),
154 TInt n = (sizeof(progs)/sizeof(*progs)) - 1;
155 for (i = 0; i < n; ++i)
157 __ASSERT_ALWAYS(progs[i], User::Panic(_L("t_property: no memory"), 0));
160 CTestProgram::LaunchGroup(progs, 2);
162 for (i = 0; i < n; ++i)