Update contrib.
1 // Copyright (c) 2005-2010 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 "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.
18 #include "logservsecurity.h"
19 #include "LogServResourceInterpreter.h"
21 #include <logengevents.h>
22 #include "t_logsecuritypolicy.h"
23 #include "t_logutil.h"
25 RTest TheTest(_L("t_logsecurity"));
26 static RFs TheFileSess;
28 ///////////////////////////////////////////////////////////////////////////////////////
31 //Check if supplied aPolicy parameter has aCapability capability.
32 static TBool HasCapability(const TCompiledSecurityPolicy& aPolicy, TCapability aCapability)
35 if(aPolicy.Type() == TSecurityPolicy::ETypeS3 ||
36 aPolicy.Type() == TSecurityPolicy::ETypeV3 ||
37 aPolicy.Type() == TSecurityPolicy::ETypeC3)
41 else if(aPolicy.Type() == TSecurityPolicy::ETypeC7)
49 for(TInt i=0;i<maxCount;++i)
51 if(aPolicy.Capability(i) == aCapability)
59 ///////////////////////////////////////////////////////////////////////////////////////
62 //Checks that all supported LogEngServer event types have the expected capabilities.
63 //See LogWrap.rss file
64 static void CheckEventSecurityPolicies(CLogServSecurity& aLogServSecurity)
66 TSecurityPolicy plc1r = aLogServSecurity.SecurityPolicy(KLogCallEventTypeUid, EReadOp);
67 TEST(::HasCapability(plc1r, ECapabilityReadUserData));
69 TSecurityPolicy plc1w = aLogServSecurity.SecurityPolicy(KLogCallEventTypeUid, EWriteOp);
70 TEST(::HasCapability(plc1w, ECapabilityWriteUserData));
72 TSecurityPolicy plc2r = aLogServSecurity.SecurityPolicy(KLogDataEventTypeUid, EReadOp);
73 TEST(::HasCapability(plc2r, ECapabilityReadUserData));
75 TSecurityPolicy plc2w = aLogServSecurity.SecurityPolicy(KLogDataEventTypeUid, EWriteOp);
76 TEST(::HasCapability(plc2w, ECapabilityWriteUserData));
78 TSecurityPolicy plc3r = aLogServSecurity.SecurityPolicy(KLogFaxEventTypeUid, EReadOp);
79 TEST(::HasCapability(plc3r, ECapabilityReadUserData));
81 TSecurityPolicy plc3w = aLogServSecurity.SecurityPolicy(KLogFaxEventTypeUid, EWriteOp);
82 TEST(::HasCapability(plc3w, ECapabilityWriteUserData));
84 TSecurityPolicy plc4r = aLogServSecurity.SecurityPolicy(KLogShortMessageEventTypeUid, EReadOp);
85 TEST(::HasCapability(plc4r, ECapabilityReadUserData));
87 TSecurityPolicy plc4w = aLogServSecurity.SecurityPolicy(KLogShortMessageEventTypeUid, EWriteOp);
88 TEST(::HasCapability(plc4w, ECapabilityWriteUserData));
90 TSecurityPolicy plc5r = aLogServSecurity.SecurityPolicy(KLogMailEventTypeUid, EReadOp);
91 TEST(TCompiledSecurityPolicy(plc5r).Type() == TSecurityPolicy::EAlwaysPass);
93 TSecurityPolicy plc5w = aLogServSecurity.SecurityPolicy(KLogMailEventTypeUid, EWriteOp);
94 TEST(TCompiledSecurityPolicy(plc5w).Type() == TSecurityPolicy::EAlwaysPass);
96 TSecurityPolicy plc6r = aLogServSecurity.SecurityPolicy(KLogTaskSchedulerEventTypeUid, EReadOp);
97 TEST(::HasCapability(plc6r, ECapabilityReadUserData));
99 TSecurityPolicy plc6w = aLogServSecurity.SecurityPolicy(KLogTaskSchedulerEventTypeUid, EWriteOp);
100 TEST(!::HasCapability(plc6w, ECapabilityWriteUserData));
102 TSecurityPolicy plc7r = aLogServSecurity.SecurityPolicy(KLogPacketDataEventTypeUid, EReadOp);
103 TEST(::HasCapability(plc7r, ECapabilityReadUserData));
105 TSecurityPolicy plc7w = aLogServSecurity.SecurityPolicy(KLogPacketDataEventTypeUid, EWriteOp);
106 TEST(::HasCapability(plc7w, ECapabilityWriteUserData));
109 TSecurityPolicy plc8r = aLogServSecurity.SecurityPolicy(KLogLbsSelfLocateEventTypeUid, EReadOp);
110 TEST(::HasCapability(plc8r, ECapabilityReadDeviceData));
112 TSecurityPolicy plc8w = aLogServSecurity.SecurityPolicy(KLogLbsSelfLocateEventTypeUid, EWriteOp);
113 TEST(::HasCapability(plc8w, ECapabilityWriteDeviceData));
115 TSecurityPolicy plc9r = aLogServSecurity.SecurityPolicy(KLogLbsExternalLocateEventTypeUid, EReadOp);
116 TEST(::HasCapability(plc9r, ECapabilityReadDeviceData));
118 TSecurityPolicy plc9w = aLogServSecurity.SecurityPolicy(KLogLbsExternalLocateEventTypeUid, EWriteOp);
119 TEST(::HasCapability(plc9w, ECapabilityWriteDeviceData));
121 TSecurityPolicy plc10r = aLogServSecurity.SecurityPolicy(KLogLbsTransmitLocationEventTypeUid, EReadOp);
122 TEST(::HasCapability(plc10r, ECapabilityReadDeviceData));
124 TSecurityPolicy plc10w = aLogServSecurity.SecurityPolicy(KLogLbsTransmitLocationEventTypeUid, EWriteOp);
125 TEST(::HasCapability(plc10w, ECapabilityWriteDeviceData));
127 TSecurityPolicy plc11r = aLogServSecurity.SecurityPolicy(KLogLbsNetworkLocateEventTypeUid, EReadOp);
128 TEST(::HasCapability(plc11r, ECapabilityReadDeviceData));
130 TSecurityPolicy plc11w = aLogServSecurity.SecurityPolicy(KLogLbsNetworkLocateEventTypeUid, EWriteOp);
131 TEST(::HasCapability(plc11w, ECapabilityWriteDeviceData));
133 TSecurityPolicy plc12r = aLogServSecurity.SecurityPolicy(KLogLbsAssistanceDataEventTypeUid, EReadOp);
134 TEST(::HasCapability(plc12r, ECapabilityReadDeviceData));
136 TSecurityPolicy plc12w = aLogServSecurity.SecurityPolicy(KLogLbsAssistanceDataEventTypeUid, EWriteOp);
137 TEST(::HasCapability(plc12w, ECapabilityWriteDeviceData));
141 static void DoOOMTestL()
143 CLogServResourceInterpreter* logServRsc = CLogServResourceInterpreter::NewL(TheFileSess);
144 CleanupStack::PushL(logServRsc);
146 CLogServSecurity* logServSecurity = CLogServSecurity::NewL(*logServRsc);
147 CleanupStack::PushL(logServSecurity);
149 ::CheckEventSecurityPolicies(*logServSecurity);
151 CleanupStack::PopAndDestroy(logServSecurity);
152 CleanupStack::PopAndDestroy(logServRsc);
155 // CLogServSecurity instance creation - OOM test
156 static void OOMTest()
158 for(TInt count=1;;++count)
160 __UHEAP_FAILNEXT(count);
162 TRAPD(err, ::DoOOMTestL());
164 if(err == KErrNoMemory)
168 else if(err == KErrNone)
171 TheTest.Printf(_L("The test succeeded at heap failure rate=%d.\n"), count);
177 TEST2(err, KErrNone);
183 ///////////////////////////////////////////////////////////////////////////////////////
188 TheTest.Start(_L(" @SYMTestCaseID:SYSLIBS-LOGENG-LEGACY-T_LOGSECURITY-0001 OOM test "));
196 CTrapCleanup* tc = CTrapCleanup::New();
199 TEST2(TheFileSess.Connect(), KErrNone);
202 TRAPD(err, ::MainL());
203 TEST2(err, KErrNone);
214 User::Heap().Check();