sl@0: // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include "t_property.h" sl@0: sl@0: _LIT(KPropSetGetRaceName, "RProperty::Set/Get() Race"); sl@0: sl@0: CPropSetGetRace::CPropSetGetRace(TUid aCategory, TUint aKey) : sl@0: CTestProgram(KPropSetGetRaceName), iCategory(aCategory), iKey(aKey), sl@0: iBuf1(RProperty::KMaxPropertySize), iBuf2(RProperty::KMaxPropertySize) sl@0: { sl@0: } sl@0: sl@0: void CPropSetGetRace::Trublemaker(TDes8& aBuf) sl@0: { sl@0: RProperty prop; sl@0: TInt r = prop.Attach(iCategory, iKey, EOwnerThread); sl@0: TF_ERROR(r, r == KErrNone); sl@0: TBool attached = ETrue; sl@0: for(;;) sl@0: { sl@0: TBuf8 buf; sl@0: if (attached) sl@0: { sl@0: r = prop.Set(aBuf); sl@0: TF_ERROR(r, r == KErrNone); sl@0: r = prop.Get(buf); sl@0: TF_ERROR(r, r == KErrNone); sl@0: } sl@0: else sl@0: { sl@0: r = prop.Set(iCategory, iKey, aBuf); sl@0: TF_ERROR(r, r == KErrNone); sl@0: r = prop.Get(iCategory, iKey, buf); sl@0: TF_ERROR(r, r == KErrNone); sl@0: } sl@0: TF_ERROR(KErrGeneral, !(buf.Compare(iBuf1) && buf.Compare(iBuf2))); sl@0: User::After(1); sl@0: attached = !attached; sl@0: } sl@0: } sl@0: sl@0: TInt CPropSetGetRace::TrublemakerThreadEntry(TAny* ptr) sl@0: { sl@0: CPropSetGetRace* prog = (CPropSetGetRace*) ptr; sl@0: prog->Trublemaker(prog->iBuf2); sl@0: return KErrNone; sl@0: } sl@0: sl@0: void CPropSetGetRace::Run(TUint aCount) sl@0: { sl@0: RProperty prop; sl@0: sl@0: TInt r = prop.Define(iCategory, iKey, RProperty::EByteArray, KPassPolicy, KPassPolicy); sl@0: TF_ERROR(r, r == KErrNone); sl@0: r = prop.Attach(iCategory,iKey); sl@0: TF_ERROR(r, r == KErrNone); sl@0: sl@0: TUint i; sl@0: for(i = 0; i < RProperty::KMaxPropertySize; ++i) sl@0: { sl@0: iBuf1[i] = '1'; sl@0: iBuf2[i] = '2'; sl@0: } sl@0: sl@0: TRequestStatus status; sl@0: RThread thr; sl@0: r = thr.Create(KNullDesC, TrublemakerThreadEntry, 0x2000, NULL, this); sl@0: TF_ERROR(r, r == KErrNone); sl@0: thr.Logon(status); sl@0: thr.SetPriority(EPriorityMore); sl@0: thr.Resume(); sl@0: sl@0: TBool attached = ETrue; sl@0: for (i = 0; i < aCount; ++i) sl@0: { sl@0: TBuf8 buf; sl@0: if (attached) sl@0: { sl@0: r = prop.Set(iBuf1); sl@0: TF_ERROR(r, r == KErrNone); sl@0: r = prop.Get(buf); sl@0: TF_ERROR(r, r == KErrNone); sl@0: } sl@0: else sl@0: { sl@0: r = prop.Set(iCategory, iKey, iBuf1); sl@0: TF_ERROR(r, r == KErrNone); sl@0: r = prop.Get(iCategory, iKey, buf); sl@0: TF_ERROR(r, r == KErrNone); sl@0: } sl@0: TF_ERROR(KErrGeneral, !(buf.Compare(iBuf1) && buf.Compare(iBuf2))); sl@0: attached = !attached; sl@0: } sl@0: sl@0: thr.Kill(EExitKill); sl@0: thr.Close(); sl@0: sl@0: User::WaitForRequest(status); sl@0: TF_ERROR(status.Int(), status.Int() == EExitKill); sl@0: sl@0: prop.Delete(iCategory, iKey); sl@0: prop.Close(); sl@0: } sl@0: sl@0: sl@0: _LIT(KPropCancelRaceName, "RProperty::Cancel() Race"); sl@0: sl@0: CPropCancelRace::CPropCancelRace(TUid aCategory, TUint aKey) : sl@0: CTestProgram(KPropCancelRaceName), iCategory(aCategory), iKey(aKey) sl@0: { sl@0: } sl@0: sl@0: void CPropCancelRace::Trublemaker() sl@0: { sl@0: for(;;) sl@0: { sl@0: iProp.Cancel(); sl@0: User::After(1); sl@0: } sl@0: } sl@0: sl@0: TInt CPropCancelRace::TrublemakerThreadEntry(TAny* ptr) sl@0: { sl@0: CPropCancelRace* prog = (CPropCancelRace*) ptr; sl@0: prog->Trublemaker(); sl@0: return KErrNone; sl@0: } sl@0: sl@0: void CPropCancelRace::Run(TUint aCount) sl@0: { sl@0: TInt r = iProp.Define(iCategory, iKey, RProperty::EInt, KPassPolicy, KPassPolicy); sl@0: TF_ERROR(r, r == KErrNone); sl@0: r = iProp.Attach(iCategory,iKey); sl@0: TF_ERROR(r, r == KErrNone); sl@0: sl@0: TRequestStatus thrStatus; sl@0: RThread thr; sl@0: r = thr.Create(KNullDesC, TrublemakerThreadEntry, 0x2000, NULL, this); sl@0: TF_ERROR(r, r == KErrNone); sl@0: thr.Logon(thrStatus); sl@0: thr.SetPriority(EPriorityMore); sl@0: thr.Resume(); sl@0: sl@0: for (TUint i = 0; i < aCount; ++i) sl@0: { sl@0: TRequestStatus status; sl@0: iProp.Subscribe(status); sl@0: TInt st = status.Int(); sl@0: TF_ERROR(st, (st == KRequestPending) || (st == KErrCancel)); sl@0: iProp.Set(1); sl@0: User::WaitForRequest(status); sl@0: st = status.Int(); sl@0: TF_ERROR(st, (st == KErrNone) || (st == KErrCancel)); sl@0: } sl@0: sl@0: thr.Kill(EExitKill); sl@0: User::WaitForRequest(thrStatus); sl@0: TF_ERROR(thrStatus.Int(), thrStatus.Int() == EExitKill); sl@0: thr.Close(); sl@0: sl@0: iProp.Delete(iCategory, iKey); sl@0: iProp.Close(); sl@0: }