1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/property/t_basic.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,791 @@
1.4 +// Copyright (c) 2002-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 the License "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 +//
1.18 +
1.19 +#include <e32kpan.h>
1.20 +#include "t_property.h"
1.21 +
1.22 +_LIT(KDefineName, "RProperty::Define() Basics");
1.23 +
1.24 +CPropDefine::CPropDefine(TUid aCategory, TUint aKey, RProperty::TType aType) :
1.25 + CTestProgram(KDefineName), iCategory(aCategory), iKey(aKey), iType(aType)
1.26 + {
1.27 + }
1.28 +
1.29 +void CPropDefine::Run(TUint aCount)
1.30 + {
1.31 + TUid mySid;
1.32 + mySid.iUid = RProcess().SecureId();
1.33 +
1.34 + for(TUint i = 0; i < aCount; ++i)
1.35 + {
1.36 + RProperty prop;
1.37 +
1.38 + // Defines the attributes and access control for a property. This can only be done
1.39 + // once for each property. Subsequent attempts to define the same property will return
1.40 + // KErrAlreadyExists.
1.41 + TInt r = prop.Define(iCategory, iKey, iType, KPassPolicy, KPassPolicy);
1.42 + TF_ERROR(r, r == KErrNone);
1.43 + r = prop.Define(iCategory, iKey, iType, KPassPolicy, KPassPolicy);
1.44 + TF_ERROR(r, r == KErrAlreadyExists);
1.45 + r = prop.Delete(iCategory, iKey);
1.46 + TF_ERROR(r, r == KErrNone);
1.47 +
1.48 + // Test defining properties in the default category (==our SID)
1.49 + r = prop.Define(iKey, iType, KFailPolicy, KFailPolicy);
1.50 + TF_ERROR(r, r == KErrNone);
1.51 + r = prop.Define(iKey, iType, KFailPolicy, KFailPolicy);
1.52 + TF_ERROR(r, r == KErrAlreadyExists);
1.53 + r = prop.Define(mySid, iKey, iType, KFailPolicy, KFailPolicy);
1.54 + TF_ERROR(r, r == KErrAlreadyExists);
1.55 + r = prop.Delete(mySid, iKey);
1.56 + TF_ERROR(r, r == KErrNone);
1.57 +
1.58 + // Test re-definition doesn't change security settings
1.59 + // Defect DEF050961 - Re-defining an RProperty causes the security policy to be overwritten
1.60 + {
1.61 + TInt expectedResult = PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement)?KErrPermissionDenied:KErrNone;
1.62 + _LIT(KTestBytes,"abcd");
1.63 + r = prop.Define(iCategory, iKey, iType, KFailPolicy, KFailPolicy);
1.64 + TF_ERROR(r, r == KErrNone);
1.65 + r = prop.Attach(iCategory, iKey);
1.66 + TF_ERROR(r, r == KErrNone);
1.67 + if (iType == RProperty::EInt)
1.68 + r = prop.Set(1);
1.69 + else
1.70 + r = prop.Set(KTestBytes);
1.71 + TF_ERROR(r, r == expectedResult);
1.72 + r = prop.Define(iCategory, iKey, iType, KPassPolicy, KPassPolicy);
1.73 + TF_ERROR(r, r == KErrAlreadyExists);
1.74 + if (iType == RProperty::EInt)
1.75 + r = prop.Set(1);
1.76 + else
1.77 + r = prop.Set(KTestBytes);
1.78 + TF_ERROR(r, r == expectedResult);
1.79 + r = prop.Delete(iCategory, iKey);
1.80 + TF_ERROR(r, r == KErrNone);
1.81 + prop.Close();
1.82 + }
1.83 +
1.84 + // Define fails with KErrArgument if wrong type or attribute was specified.
1.85 + r = prop.Define(iCategory, iKey, RProperty::ETypeLimit, KPassPolicy, KPassPolicy);
1.86 + TF_ERROR(r, r == KErrArgument);
1.87 + const TInt removed_KPersistent_attribute = 0x100;
1.88 + r = prop.Define(iCategory, iKey, iType | removed_KPersistent_attribute, KPassPolicy, KPassPolicy);
1.89 + TF_ERROR(r, r == KErrArgument);
1.90 +
1.91 + TSecurityPolicy badPolicy;
1.92 + *(TInt*)&badPolicy = -1;
1.93 + r = prop.Define(iCategory, iKey, iType, badPolicy, KPassPolicy);
1.94 + TF_ERROR(r, r == KErrArgument);
1.95 + r = prop.Define(iCategory, iKey, iType, KPassPolicy, badPolicy);
1.96 + TF_ERROR(r, r == KErrArgument);
1.97 +
1.98 + if (iType == RProperty::EInt)
1.99 + {
1.100 + // Define fails with KErrArgument if aType is TInt and aPreallocate is not 0
1.101 + r = prop.Define(iCategory, iKey, RProperty::EInt, KPassPolicy, KPassPolicy, 16);
1.102 + TF_ERROR(r, r == KErrArgument);
1.103 +
1.104 + // Following defintion the property has a default value, 0 for integer properties
1.105 + r = prop.Define(iCategory, iKey, RProperty::EInt, KPassPolicy, KPassPolicy);
1.106 + TF_ERROR(r, r == KErrNone);
1.107 + TInt value;
1.108 + r = prop.Get(iCategory, iKey, value);
1.109 + TF_ERROR(r, r == KErrNone);
1.110 + TF_ERROR(value, value == 0);
1.111 + r = prop.Delete(iCategory, iKey);
1.112 + TF_ERROR(r, r == KErrNone);
1.113 + }
1.114 + else
1.115 + {
1.116 + // Defne fails with KErrTooBig if aPeallocate is grater than KMaxPropertySize.
1.117 + r = prop.Define(iCategory, iKey, RProperty::EByteArray, KPassPolicy, KPassPolicy, RProperty::KMaxPropertySize);
1.118 + TF_ERROR(r, r == KErrNone);
1.119 + r = prop.Delete(iCategory, iKey);
1.120 + TF_ERROR(r, r == KErrNone);
1.121 + r = prop.Define(iCategory, iKey, RProperty::EByteArray, KPassPolicy, KPassPolicy, RProperty::KMaxPropertySize + 1);
1.122 + TF_ERROR(r, r == KErrTooBig);
1.123 +
1.124 + // Following defintion the property has a default value, zero-length data for byte-array and text
1.125 + // properties.
1.126 + r = prop.Define(iCategory, iKey, RProperty::EByteArray, KPassPolicy, KPassPolicy);
1.127 + TF_ERROR(r, r == KErrNone);
1.128 + TBuf<16> buf;
1.129 + r = prop.Get(iCategory, iKey, buf);
1.130 + TF_ERROR(r, r == KErrNone);
1.131 + TF_ERROR(buf.Size(), buf.Size() == 0);
1.132 +
1.133 + TBuf8<16> buf8;
1.134 + r = prop.Get(iCategory, iKey, buf8);
1.135 + TF_ERROR(r, r == KErrNone);
1.136 + TF_ERROR(buf8.Size(), buf8.Size() == 0);
1.137 + r = prop.Delete(iCategory, iKey);
1.138 + TF_ERROR(r, r == KErrNone);
1.139 + }
1.140 +
1.141 + // Pending subscriptions for this property will not be completed until a new value is published.
1.142 + r = prop.Attach(iCategory, iKey);
1.143 + TF_ERROR(r, r == KErrNone);
1.144 + TRequestStatus status;
1.145 + prop.Subscribe(status);
1.146 + TF_ERROR(status.Int(), status.Int() == KRequestPending);
1.147 + r = prop.Define(iCategory, iKey, iType, KPassPolicy, KPassPolicy);
1.148 + TF_ERROR(r, r == KErrNone);
1.149 + TF_ERROR(status.Int(), status.Int() == KRequestPending);
1.150 + r = prop.Delete(iCategory, iKey);
1.151 + TF_ERROR(r, r == KErrNone);
1.152 + User::WaitForRequest(status);
1.153 + TF_ERROR(status.Int(), status.Int() == KErrNotFound);
1.154 + prop.Close();
1.155 + }
1.156 + }
1.157 +
1.158 +_LIT(KDeleteName, "RProperty::Delete() Basics");
1.159 +
1.160 +CPropDelete::CPropDelete(TUid aCategory, TUint aKey, RProperty::TType aType) :
1.161 + CTestProgram(KDeleteName), iCategory(aCategory), iKey(aKey), iType(aType)
1.162 + {
1.163 + }
1.164 +
1.165 +void CPropDelete::Run(TUint aCount)
1.166 + {
1.167 + TUid mySid;
1.168 + mySid.iUid = RProcess().SecureId();
1.169 + for(TUint i = 0; i < aCount; ++i)
1.170 + {
1.171 + RProperty prop;
1.172 +
1.173 + // If the property has not been defined Delete fails with KErrNotFound.
1.174 + TInt r = prop.Delete(iCategory, iKey);
1.175 + TF_ERROR(r, r == KErrNotFound);
1.176 +
1.177 + // Test deleting properties in the default category (==our SID)
1.178 + //deleting of property in the default category (==our SID) should fail until the property is defined
1.179 + r = prop.Delete(iKey);
1.180 + TF_ERROR(r, r == KErrNotFound);
1.181 +
1.182 + r = prop.Define(iKey, iType, KFailPolicy, KFailPolicy);
1.183 + TF_ERROR(r, r == KErrNone);
1.184 + r = prop.Delete(iKey);
1.185 + TF_ERROR(r, r == KErrNone);
1.186 +
1.187 + r = prop.Define(mySid, iKey, iType, KFailPolicy, KFailPolicy);
1.188 + TF_ERROR(r, r == KErrNone);
1.189 + r = prop.Delete(mySid, iKey);
1.190 + TF_ERROR(r, r == KErrNone);
1.191 + r = prop.Delete( iKey);
1.192 + TF_ERROR(r, r == KErrNotFound);
1.193 +
1.194 + r = prop.Define(mySid, iKey, iType, KFailPolicy, KFailPolicy);
1.195 + TF_ERROR(r, r == KErrNone);
1.196 + r = prop.Delete( iKey);
1.197 + TF_ERROR(r, r == KErrNone);
1.198 + r = prop.Delete(mySid, iKey);
1.199 + TF_ERROR(r, r == KErrNotFound);
1.200 +
1.201 + // Any pending subscriptions for this property will be completed with KErrNotFound.
1.202 + r = prop.Define(iCategory, iKey, iType, KPassPolicy, KPassPolicy);
1.203 + TF_ERROR(r, r == KErrNone);
1.204 + r = prop.Attach(iCategory, iKey);
1.205 + TF_ERROR(r, r == KErrNone);
1.206 + TRequestStatus status;
1.207 + prop.Subscribe(status);
1.208 + TF_ERROR(status.Int(), status.Int() == KRequestPending);
1.209 + r = prop.Delete(iCategory, iKey);
1.210 + TF_ERROR(r, r == KErrNone);
1.211 + User::WaitForRequest(status);
1.212 + TF_ERROR(status.Int(), status.Int() == KErrNotFound);
1.213 +
1.214 + // Any new request will not complete until the property is defined and published again.
1.215 + prop.Subscribe(status);
1.216 + TF_ERROR(status.Int(), status.Int() == KRequestPending);
1.217 + r = prop.Define(iCategory, iKey, iType, KPassPolicy, KPassPolicy);
1.218 + TF_ERROR(r, r == KErrNone);
1.219 + TF_ERROR(status.Int(), status.Int() == KRequestPending);
1.220 + if (iType == RProperty::EInt)
1.221 + {
1.222 + r = prop.Set(1);
1.223 + TF_ERROR(r, r == KErrNone);
1.224 + }
1.225 + else
1.226 + {
1.227 + r = prop.Set(_L("Foo"));
1.228 + TF_ERROR(r, r == KErrNone);
1.229 + }
1.230 + User::WaitForRequest(status);
1.231 + TF_ERROR(status.Int(), status.Int() == KErrNone);
1.232 + r = prop.Delete(iCategory, iKey);
1.233 + TF_ERROR(r, r == KErrNone);
1.234 + prop.Close();
1.235 + }
1.236 + }
1.237 +
1.238 +_LIT(KPanicName, "RProperty Panics");
1.239 +
1.240 +CPropPanic::CPropPanic(TUid aCategory, TUint aKey) :
1.241 + CTestProgram(KPanicName), iCategory(aCategory), iKey(aKey)
1.242 + {
1.243 + }
1.244 +
1.245 +TInt CPropPanic::DoubleSubscribeThreadEntry(TAny* ptr)
1.246 + {
1.247 + CPropPanic* prog = (CPropPanic*) ptr;
1.248 + RProperty prop;
1.249 + TInt r = prop.Attach(prog->iCategory, prog->iKey, EOwnerThread);
1.250 + TF_ERROR_PROG(prog, r, r == KErrNone);
1.251 + TRequestStatus status;
1.252 + prop.Subscribe(status);
1.253 + // Next statement shall Panic.
1.254 + prop.Subscribe(status);
1.255 + // Never get here
1.256 + return KErrNone;
1.257 + }
1.258 +
1.259 +TInt CPropPanic::BadHandleSubscribeThreadEntry(TAny* /*ptr*/)
1.260 + {
1.261 + RProperty prop;
1.262 + TRequestStatus status;
1.263 + prop.Subscribe(status);
1.264 + return KErrNone;
1.265 + }
1.266 +
1.267 +TInt CPropPanic::BadHandleCancelThreadEntry(TAny* /*ptr*/)
1.268 + {
1.269 + RProperty prop;
1.270 + prop.Cancel();
1.271 + return KErrNone;
1.272 + }
1.273 +
1.274 +TInt CPropPanic::BadHandleGetIThreadEntry(TAny* /*ptr*/)
1.275 + {
1.276 + RProperty prop;
1.277 + TInt i;
1.278 + prop.Get(i);
1.279 + return KErrNone;
1.280 + }
1.281 +
1.282 +TInt CPropPanic::BadHandleGetBThreadEntry(TAny* /*ptr*/)
1.283 + {
1.284 + RProperty prop;
1.285 + TBuf<64> buf;
1.286 + prop.Get(buf);
1.287 + return KErrNone;
1.288 + }
1.289 +
1.290 +TInt CPropPanic::BadHandleSetIThreadEntry(TAny* /*ptr*/)
1.291 + {
1.292 + RProperty prop;
1.293 + TInt i = 1;
1.294 + prop.Set(i);
1.295 + return KErrNone;
1.296 + }
1.297 +
1.298 +TInt CPropPanic::BadHandleSetBThreadEntry(TAny* /*ptr*/)
1.299 + {
1.300 + RProperty prop;
1.301 + TBuf<64> buf;
1.302 + prop.Set(buf);
1.303 + return KErrNone;
1.304 + }
1.305 +
1.306 +TThreadFunction CPropPanic::BadHandles[] = {
1.307 + CPropPanic::BadHandleSubscribeThreadEntry,
1.308 + CPropPanic::BadHandleCancelThreadEntry,
1.309 + CPropPanic::BadHandleGetIThreadEntry,
1.310 + CPropPanic::BadHandleGetBThreadEntry,
1.311 + CPropPanic::BadHandleSetIThreadEntry,
1.312 + CPropPanic::BadHandleSetBThreadEntry,
1.313 + NULL
1.314 +};
1.315 +
1.316 +void CPropPanic::Run(TUint /* aCount */)
1.317 + {
1.318 + // Only one subscriptoin per RProperty object is allowed, the caller will be paniced if
1.319 + // there is already a subscription on this object.
1.320 + TRequestStatus status;
1.321 + TExitType exit;
1.322 + RThread thr;
1.323 + TInt r = thr.Create(KNullDesC, DoubleSubscribeThreadEntry, 0x2000, NULL, this);
1.324 + TF_ERROR(r, r == KErrNone);
1.325 + thr.Logon(status);
1.326 +
1.327 + TBool jit = User::JustInTime();
1.328 + User::SetJustInTime(EFalse);
1.329 +
1.330 + thr.Resume();
1.331 + User::WaitForRequest(status);
1.332 + thr.Close();
1.333 +
1.334 + User::SetJustInTime(jit);
1.335 +
1.336 + TF_ERROR(status.Int(), status.Int() == ERequestAlreadyPending);
1.337 +
1.338 + for (TInt i = 0; BadHandles[i]; ++i)
1.339 + {
1.340 + r = thr.Create(KNullDesC, BadHandles[i], 0x2000, NULL, this);
1.341 + TF_ERROR(r, r == KErrNone);
1.342 + thr.Logon(status);
1.343 +
1.344 + jit = User::JustInTime();
1.345 + User::SetJustInTime(EFalse);
1.346 +
1.347 + thr.Resume();
1.348 + User::WaitForRequest(status);
1.349 + exit = thr.ExitType();
1.350 + thr.Close();
1.351 +
1.352 + User::SetJustInTime(jit);
1.353 +
1.354 + TF_ERROR(status.Int(), status.Int() == EBadHandle);
1.355 + TF_ERROR(exit, exit == EExitPanic);
1.356 + }
1.357 + }
1.358 +
1.359 +_LIT(KSetGetName, "RProperty::Set()/Get() Basics");
1.360 +
1.361 +CPropSetGet::CPropSetGet(TUid aCategory, TUint aKey, RProperty::TType aType) :
1.362 + CTestProgram(KSetGetName), iCategory(aCategory), iKey(aKey), iType(aType)
1.363 + {
1.364 + }
1.365 +
1.366 +void CPropSetGet::Run(TUint aCount)
1.367 + {
1.368 + for(TUint i = 0; i < aCount; ++i)
1.369 + {
1.370 + TInt r;
1.371 + RProperty prop;
1.372 +
1.373 + r = prop.Attach(iCategory, iKey);
1.374 + TF_ERROR(r, r == KErrNone);
1.375 +
1.376 + // If the property has not been defined this fails with KErrNotFound.
1.377 + {
1.378 + TInt value;
1.379 + TBuf<16> buf;
1.380 + TBuf8<16> buf8;
1.381 + if (iType == RProperty::EInt)
1.382 + {
1.383 + r = prop.Get(iCategory, iKey, value);
1.384 + TF_ERROR(r, r == KErrNotFound);
1.385 + r = prop.Set(iCategory, iKey, value);
1.386 + TF_ERROR(r, r == KErrNotFound);
1.387 + }
1.388 + else
1.389 + {
1.390 + r = prop.Get(iCategory, iKey, buf);
1.391 + TF_ERROR(r, r == KErrNotFound);
1.392 + r = prop.Set(iCategory, iKey, buf);
1.393 + TF_ERROR(r, r == KErrNotFound);
1.394 + r = prop.Get(iCategory, iKey, buf8);
1.395 + TF_ERROR(r, r == KErrNotFound);
1.396 + r = prop.Set(iCategory, iKey, buf8);
1.397 + TF_ERROR(r, r == KErrNotFound);
1.398 + }
1.399 +
1.400 + if (iType == RProperty::EInt)
1.401 + {
1.402 + r = prop.Get(value);
1.403 + TF_ERROR(r, r == KErrNotFound);
1.404 + r = prop.Set(value);
1.405 + TF_ERROR(r, r == KErrNotFound);
1.406 + }
1.407 + else
1.408 + {
1.409 + r = prop.Get(buf);
1.410 + TF_ERROR(r, r == KErrNotFound);
1.411 + r = prop.Set(buf);
1.412 + TF_ERROR(r, r == KErrNotFound);
1.413 + r = prop.Get(buf8);
1.414 + TF_ERROR(r, r == KErrNotFound);
1.415 + r = prop.Set(buf8);
1.416 + TF_ERROR(r, r == KErrNotFound);
1.417 + }
1.418 + }
1.419 +
1.420 + r = prop.Define(iCategory, iKey, iType, KPassPolicy, KPassPolicy);
1.421 + TF_ERROR(r, r == KErrNone);
1.422 +
1.423 + // Can set property to zero length
1.424 + {
1.425 + if (iType == RProperty::EByteArray)
1.426 + {
1.427 + TBuf8<20> buf8(20);
1.428 + r = prop.Set(iCategory, iKey, KNullDesC8);
1.429 + TF_ERROR(r, r == KErrNone);
1.430 + r = prop.Get(iCategory, iKey, buf8);
1.431 + TF_ERROR(r, r == KErrNone);
1.432 + TF_ERROR(buf8.Length(), buf8.Length() == 0);
1.433 + }
1.434 + }
1.435 +
1.436 + // If the property is larger than KMaxPropertySize this fails with KErrTooBig
1.437 + {
1.438 + if (iType == RProperty::EByteArray)
1.439 + {
1.440 + TBuf<RProperty::KMaxPropertySize/2 + 1> buf(RProperty::KMaxPropertySize/2 + 1);
1.441 + TBuf8<RProperty::KMaxPropertySize + 1> buf8(RProperty::KMaxPropertySize + 1);
1.442 + r = prop.Set(iCategory, iKey, buf);
1.443 + TF_ERROR(r, r == KErrTooBig);
1.444 + r = prop.Set(iCategory, iKey, buf8);
1.445 + TF_ERROR(r, r == KErrTooBig);
1.446 + r = prop.Set(buf);
1.447 + TF_ERROR(r, r == KErrTooBig);
1.448 + r = prop.Set(buf8);
1.449 + TF_ERROR(r, r == KErrTooBig);
1.450 + }
1.451 + }
1.452 +
1.453 + // When type of operation mismatch with the property type this fails with KErrArgument.
1.454 + {
1.455 + TInt value;
1.456 + TBuf<16> buf;
1.457 + TBuf8<16> buf8;
1.458 + if (iType != RProperty::EInt)
1.459 + {
1.460 + r = prop.Get(iCategory, iKey, value);
1.461 + TF_ERROR(r, r == KErrArgument);
1.462 + r = prop.Set(iCategory, iKey, value);
1.463 + TF_ERROR(r, r == KErrArgument);
1.464 + r = prop.Get(value);
1.465 + TF_ERROR(r, r == KErrArgument);
1.466 + r = prop.Set(value);
1.467 + TF_ERROR(r, r == KErrArgument);
1.468 + }
1.469 + else
1.470 + {
1.471 + r = prop.Get(iCategory, iKey, buf);
1.472 + TF_ERROR(r, r == KErrArgument);
1.473 + r = prop.Set(iCategory, iKey, buf);
1.474 + TF_ERROR(r, r == KErrArgument);
1.475 + r = prop.Get(iCategory, iKey, buf8);
1.476 + TF_ERROR(r, r == KErrArgument);
1.477 + r = prop.Set(iCategory, iKey, buf8);
1.478 + TF_ERROR(r, r == KErrArgument);
1.479 + r = prop.Get(buf);
1.480 + TF_ERROR(r, r == KErrArgument);
1.481 + r = prop.Set(buf);
1.482 + TF_ERROR(r, r == KErrArgument);
1.483 + r = prop.Get(buf8);
1.484 + TF_ERROR(r, r == KErrArgument);
1.485 + r = prop.Set(buf8);
1.486 + TF_ERROR(r, r == KErrArgument);
1.487 + }
1.488 + }
1.489 +
1.490 + // Get/Set
1.491 + if (iType == RProperty::EInt)
1.492 + {
1.493 + {
1.494 + r = prop.Set(1);
1.495 + TF_ERROR(r, r == KErrNone);
1.496 + TInt value = 0;
1.497 + r = prop.Get(value);
1.498 + TF_ERROR(r, r == KErrNone);
1.499 + TF_ERROR(value, value == 1);
1.500 + }
1.501 + {
1.502 + TInt value = 0;
1.503 + r = prop.Set(iCategory, iKey, 1);
1.504 + TF_ERROR(r, r == KErrNone);
1.505 + r = prop.Get(iCategory, iKey, value);
1.506 + TF_ERROR(r, r == KErrNone);
1.507 + TF_ERROR(value, value == 1);
1.508 + }
1.509 + }
1.510 + else
1.511 + {
1.512 + {
1.513 + TBuf<16> ibuf(_L("Foo"));
1.514 + TBuf<16> obuf;
1.515 + r = prop.Set(ibuf);
1.516 + TF_ERROR(r, r == KErrNone);
1.517 + r = prop.Get(obuf);
1.518 + TF_ERROR(r, r == KErrNone);
1.519 + r = obuf.Compare(ibuf);
1.520 + TF_ERROR(r, r == 0);
1.521 + }
1.522 + {
1.523 + TBuf8<16> ibuf8((TUint8*)"Foo");
1.524 + TBuf8<16> obuf8;
1.525 + r = prop.Set(ibuf8);
1.526 + TF_ERROR(r, r == KErrNone);
1.527 + r = prop.Get(obuf8);
1.528 + TF_ERROR(r, r == KErrNone);
1.529 + r = obuf8.Compare(ibuf8);
1.530 + TF_ERROR(r, r == 0);
1.531 + }
1.532 + {
1.533 + TBuf<16> ibuf(_L("Foo"));
1.534 + TBuf<16> obuf;
1.535 + r = prop.Set(iCategory, iKey, ibuf);
1.536 + TF_ERROR(r, r == KErrNone);
1.537 + r = prop.Get(iCategory, iKey, obuf);
1.538 + TF_ERROR(r, r == KErrNone);
1.539 + r = obuf.Compare(ibuf);
1.540 + TF_ERROR(r, r == 0);
1.541 + }
1.542 + {
1.543 + TBuf8<16> ibuf8((TUint8*)"Foo");
1.544 + TBuf8<16> obuf8;
1.545 + r = prop.Set(iCategory, iKey, ibuf8);
1.546 + TF_ERROR(r, r == KErrNone);
1.547 + r = prop.Get(iCategory, iKey, obuf8);
1.548 + TF_ERROR(r, r == KErrNone);
1.549 + r = obuf8.Compare(ibuf8);
1.550 + TF_ERROR(r, r == 0);
1.551 + }
1.552 + }
1.553 +
1.554 + // If the supplied buffer is too small this fails with KErrOverflow and the truncated value is reported.
1.555 + if (iType == RProperty::EByteArray)
1.556 + {
1.557 + {
1.558 + TBuf<16> ibuf(_L("0123456789012345"));
1.559 + TBuf<16> obuf(_L("abcdefghigklmnop"));
1.560 + TPtr optr((TUint16*) obuf.Ptr(), 0, 15);
1.561 + r = prop.Set(iCategory, iKey, ibuf);
1.562 + TF_ERROR(r, r == KErrNone);
1.563 + r = prop.Get(iCategory, iKey, optr);
1.564 + TF_ERROR(r, r == KErrOverflow);
1.565 + TF_ERROR(optr.Length(), optr.Length() == 15);
1.566 + TF_ERROR(obuf[14], obuf[14] == TText('4'));
1.567 + TF_ERROR(obuf[15], obuf[15] == TText('p'));
1.568 + }
1.569 + {
1.570 + TBuf8<16> ibuf8((TUint8*) "0123456789012345");
1.571 + TBuf8<16> obuf8((TUint8*) "abcdefghigklmnop");
1.572 + TPtr8 optr8((TUint8*) obuf8.Ptr(), 0, 15);
1.573 + r = prop.Set(iCategory, iKey, ibuf8);
1.574 + TF_ERROR(r, r == KErrNone);
1.575 + r = prop.Get(iCategory, iKey, optr8);
1.576 + TF_ERROR(r, r == KErrOverflow);
1.577 + TF_ERROR(optr8.Length(), optr8.Length() == 15);
1.578 + TF_ERROR(obuf8[14], obuf8[14] == '4');
1.579 + TF_ERROR(obuf8[15], obuf8[15] == 'p');
1.580 + }
1.581 + {
1.582 + TBuf<16> ibuf(_L("0123456789012345"));
1.583 + TBuf<16> obuf(_L("abcdefghigklmnop"));
1.584 + TPtr optr((TUint16*) obuf.Ptr(), 0, 15);
1.585 + r = prop.Set(ibuf);
1.586 + TF_ERROR(r, r == KErrNone);
1.587 + r = prop.Get(optr);
1.588 + TF_ERROR(r, r == KErrOverflow);
1.589 + TF_ERROR(optr.Length(), optr.Length() == 15);
1.590 + TF_ERROR(obuf[14], obuf[14] == TText('4'));
1.591 + TF_ERROR(obuf[15], obuf[15] == TText('p'));
1.592 + }
1.593 + {
1.594 + TBuf8<16> ibuf8((TUint8*) "0123456789012345");
1.595 + TBuf8<16> obuf8((TUint8*) "abcdefghigklmnop");
1.596 + TPtr8 optr8((TUint8*) obuf8.Ptr(), 0, 15);
1.597 + r = prop.Set(ibuf8);
1.598 + TF_ERROR(r, r == KErrNone);
1.599 + r = prop.Get(optr8);
1.600 + TF_ERROR(r, r == KErrOverflow);
1.601 + TF_ERROR(optr8.Length(), optr8.Length() == 15);
1.602 + TF_ERROR(obuf8[14], obuf8[14] == '4');
1.603 + TF_ERROR(obuf8[15], obuf8[15] == 'p');
1.604 + }
1.605 + }
1.606 +
1.607 + // Get/Set zero-length data
1.608 + if (iType == RProperty::EByteArray)
1.609 + {
1.610 + {
1.611 + TBuf<16> ibuf(_L("Foo"));
1.612 + TBuf<16> obuf;
1.613 + TPtr nullbuf(NULL, 0);
1.614 +
1.615 + r = prop.Set(ibuf);
1.616 + TF_ERROR(r, r == KErrNone);
1.617 + r = prop.Get(nullbuf);
1.618 + TF_ERROR(r, r == KErrOverflow);
1.619 + TF_ERROR(nullbuf.Length(), (nullbuf.Length() == 0));
1.620 +
1.621 + r = prop.Set(nullbuf);
1.622 + TF_ERROR(r, r == KErrNone);
1.623 + r = prop.Get(obuf);
1.624 + TF_ERROR(r, r == KErrNone);
1.625 + TF_ERROR(obuf.Length(), (obuf.Length() == 0));
1.626 + }
1.627 + {
1.628 + TBuf8<16> ibuf((TUint8*) "Foo");
1.629 + TBuf8<16> obuf;
1.630 + TPtr8 nullbuf(NULL, 0);
1.631 +
1.632 + r = prop.Set(ibuf);
1.633 + TF_ERROR(r, r == KErrNone);
1.634 + r = prop.Get(nullbuf);
1.635 + TF_ERROR(r, r == KErrOverflow);
1.636 + TF_ERROR(nullbuf.Length(), (nullbuf.Length() == 0));
1.637 +
1.638 + r = prop.Set(nullbuf);
1.639 + TF_ERROR(r, r == KErrNone);
1.640 + r = prop.Get(obuf);
1.641 + TF_ERROR(r, r == KErrNone);
1.642 + TF_ERROR(obuf.Length(), (obuf.Length() == 0));
1.643 + }
1.644 + }
1.645 +
1.646 + r = prop.Delete(iCategory, iKey);
1.647 + TF_ERROR(r, r == KErrNone);
1.648 + prop.Close();
1.649 + }
1.650 + }
1.651 +
1.652 +
1.653 +_LIT(KSubsCancelName, "RProperty::Subscribe()/Cancel() Basics");
1.654 +
1.655 +CPropSubsCancel::CPropSubsCancel(TUid aCategory, TUint aKey, RProperty::TType aType) :
1.656 + CTestProgram(KSubsCancelName), iCategory(aCategory), iKey(aKey), iType(aType)
1.657 + {
1.658 + }
1.659 +
1.660 +
1.661 +void CPropSubsCancel::Run(TUint aCount)
1.662 + {
1.663 +
1.664 + for(TUint i = 0; i < aCount; ++i)
1.665 + {
1.666 + TRequestStatus status;
1.667 + RProperty prop;
1.668 +
1.669 + TInt r = prop.Attach(iCategory, iKey);
1.670 + TF_ERROR(r, r == KErrNone);
1.671 +
1.672 + // The calling thread will have the specified request status signalled when the property is next updated.
1.673 + r = prop.Define(iCategory, iKey, iType, KPassPolicy, KPassPolicy);
1.674 + TF_ERROR(r, r == KErrNone);
1.675 + prop.Subscribe(status);
1.676 + TF_ERROR(status.Int(), status.Int() == KRequestPending);
1.677 + if (iType == RProperty::EInt)
1.678 + {
1.679 + r = prop.Set(1);
1.680 + TF_ERROR(r, r == KErrNone);
1.681 + }
1.682 + else
1.683 + {
1.684 + r = prop.Set(_L("Foo"));
1.685 + TF_ERROR(r, r == KErrNone);
1.686 + }
1.687 + User::WaitForRequest(status);
1.688 + TF_ERROR(status.Int(), status.Int() == KErrNone);
1.689 + r = prop.Delete(iCategory, iKey);
1.690 + TF_ERROR(r, r == KErrNone);
1.691 +
1.692 + // If the property has not been defined, the request will not complete until the property
1.693 + // is defined and published.
1.694 + prop.Subscribe(status);
1.695 + TF_ERROR(status.Int(), status.Int() == KRequestPending);
1.696 + r = prop.Define(iCategory, iKey, iType, KPassPolicy, KPassPolicy);
1.697 + TF_ERROR(r, r == KErrNone);
1.698 + TF_ERROR(status.Int(), status.Int() == KRequestPending);
1.699 + if (iType == RProperty::EInt)
1.700 + {
1.701 + r = prop.Set(1);
1.702 + TF_ERROR(r, r == KErrNone);
1.703 + }
1.704 + else
1.705 + {
1.706 + r = prop.Set(_L("Foo"));
1.707 + TF_ERROR(r, r == KErrNone);
1.708 + }
1.709 + User::WaitForRequest(status);
1.710 + TF_ERROR(status.Int(), status.Int() == KErrNone);
1.711 + r = prop.Delete(iCategory, iKey);
1.712 + TF_ERROR(r, r == KErrNone);
1.713 +
1.714 + // Cancel an outstanding subscription request for this property handle.
1.715 + // If it has not already completed, the request is completed with KErrCancelled.
1.716 + prop.Subscribe(status);
1.717 + TF_ERROR(status.Int(), status.Int() == KRequestPending);
1.718 + prop.Cancel();
1.719 + User::WaitForRequest(status);
1.720 + TF_ERROR(status.Int(), status.Int() == KErrCancel);
1.721 +
1.722 + r = prop.Define(iCategory, iKey, iType, KPassPolicy, KPassPolicy);
1.723 + TF_ERROR(r, r == KErrNone);
1.724 + prop.Subscribe(status);
1.725 + TF_ERROR(status.Int(), status.Int() == KRequestPending);
1.726 + if (iType == RProperty::EInt)
1.727 + {
1.728 + r = prop.Set(1);
1.729 + TF_ERROR(r, r == KErrNone);
1.730 + }
1.731 + else
1.732 + {
1.733 + r = prop.Set(_L("Foo"));
1.734 + TF_ERROR(r, r == KErrNone);
1.735 + }
1.736 + User::WaitForRequest(status);
1.737 + TF_ERROR(status.Int(), status.Int() == KErrNone);
1.738 + prop.Cancel();
1.739 + TF_ERROR(status.Int(), status.Int() == KErrNone);
1.740 +
1.741 + prop.Subscribe(status);
1.742 + TF_ERROR(status.Int(), status.Int() == KRequestPending);
1.743 + prop.Cancel();
1.744 + User::WaitForRequest(status);
1.745 + TF_ERROR(status.Int(), status.Int() == KErrCancel);
1.746 +
1.747 + r = prop.Delete(iCategory, iKey);
1.748 + TF_ERROR(r, r == KErrNone);
1.749 +
1.750 + prop.Close();
1.751 + }
1.752 + }
1.753 +
1.754 +_LIT(KSecurityName, "RProperty Security Basics (Master)");
1.755 +
1.756 +CPropSecurity::CPropSecurity(TUid aCategory, TUint aMasterKey, RProperty::TType aType, TUint aSlaveKeySlot) :
1.757 + CTestProgram(KSecurityName), iCategory(aCategory), iMasterKey(aMasterKey),
1.758 + iSlaveKeySlot(aSlaveKeySlot), iType(aType)
1.759 + {
1.760 + }
1.761 +
1.762 +_LIT(KSecuritySlavePath, "t_prop_sec.exe");
1.763 +
1.764 +void CPropSecurity::Run(TUint aCount)
1.765 + {
1.766 + for(TInt i=0; i<ECapability_Limit; i++)
1.767 + if(!PlatSec::IsCapabilityEnforced((TCapability)i))
1.768 + {
1.769 + // System isn't configured with platform security enforced
1.770 + // so don't bother running tests
1.771 + return;
1.772 + }
1.773 +
1.774 + TArgs args;
1.775 + args.iCount = aCount;
1.776 + args.iCategory = iCategory;
1.777 + args.iMasterKey = iMasterKey;
1.778 + args.iSlaveKeySlot = iSlaveKeySlot;
1.779 +
1.780 + RProperty prop;
1.781 +
1.782 + TInt r = prop.Define(iCategory, iMasterKey, iType, KPassPolicy, KPassPolicy);
1.783 + TF_ERROR(r, r == KErrNone);
1.784 +
1.785 + Exec(KSecuritySlavePath, &args, sizeof(args));
1.786 +
1.787 + Exec(_L("t_prop_define0.exe"), &args, sizeof(args));
1.788 + Exec(_L("t_prop_define1.exe"), &args, sizeof(args));
1.789 + Exec(_L("t_prop_define2.exe"), &args, sizeof(args));
1.790 + Exec(_L("t_prop_define3.exe"), &args, sizeof(args));
1.791 +
1.792 + r = prop.Delete(iCategory, iMasterKey);
1.793 + TF_ERROR(r, r == KErrNone);
1.794 + }