os/persistentdata/loggingservices/eventlogger/test/src/T_LogSecurity.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/loggingservices/eventlogger/test/src/T_LogSecurity.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,216 @@
     1.4 +// Copyright (c) 2005-2010 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 "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 <e32test.h>
    1.20 +#include <f32file.h>
    1.21 +#include "logservsecurity.h"
    1.22 +#include "LogServResourceInterpreter.h"
    1.23 +#include <logeng.h>
    1.24 +#include <logengevents.h>
    1.25 +#include "t_logsecuritypolicy.h"
    1.26 +#include "t_logutil.h"
    1.27 +
    1.28 +RTest TheTest(_L("t_logsecurity"));
    1.29 +static RFs TheFileSess;
    1.30 +
    1.31 +///////////////////////////////////////////////////////////////////////////////////////
    1.32 +//
    1.33 +
    1.34 +//Check if supplied aPolicy parameter has aCapability capability.
    1.35 +static TBool HasCapability(const TCompiledSecurityPolicy& aPolicy, TCapability aCapability)
    1.36 +	{
    1.37 +	TInt maxCount = 0;
    1.38 +	if(aPolicy.Type() == TSecurityPolicy::ETypeS3 || 
    1.39 +	   aPolicy.Type() == TSecurityPolicy::ETypeV3 ||
    1.40 +	   aPolicy.Type() == TSecurityPolicy::ETypeC3)
    1.41 +		{
    1.42 +		maxCount = 3;	
    1.43 +		}
    1.44 +	else if(aPolicy.Type() == TSecurityPolicy::ETypeC7)
    1.45 +		{
    1.46 +		maxCount = 7;	
    1.47 +		}
    1.48 +	else
    1.49 +		{
    1.50 +		TEST(0);
    1.51 +		}
    1.52 +	for(TInt i=0;i<maxCount;++i)
    1.53 +		{
    1.54 +		if(aPolicy.Capability(i) == aCapability)
    1.55 +			{
    1.56 +			return ETrue;	
    1.57 +			}
    1.58 +		}
    1.59 +	return EFalse;
    1.60 +	}
    1.61 +
    1.62 +///////////////////////////////////////////////////////////////////////////////////////
    1.63 +//
    1.64 +
    1.65 +//Checks that all supported LogEngServer event types have the expected capabilities.
    1.66 +//See LogWrap.rss file
    1.67 +static void CheckEventSecurityPolicies(CLogServSecurity& aLogServSecurity)
    1.68 +	{
    1.69 +	TSecurityPolicy plc1r = aLogServSecurity.SecurityPolicy(KLogCallEventTypeUid, EReadOp);
    1.70 +	TEST(::HasCapability(plc1r, ECapabilityReadUserData));
    1.71 +	
    1.72 +	TSecurityPolicy plc1w = aLogServSecurity.SecurityPolicy(KLogCallEventTypeUid, EWriteOp);
    1.73 +	TEST(::HasCapability(plc1w, ECapabilityWriteUserData));
    1.74 +	
    1.75 +	TSecurityPolicy plc2r = aLogServSecurity.SecurityPolicy(KLogDataEventTypeUid, EReadOp);
    1.76 +	TEST(::HasCapability(plc2r, ECapabilityReadUserData));
    1.77 +	
    1.78 +	TSecurityPolicy plc2w = aLogServSecurity.SecurityPolicy(KLogDataEventTypeUid, EWriteOp);
    1.79 +	TEST(::HasCapability(plc2w, ECapabilityWriteUserData));
    1.80 +	
    1.81 +	TSecurityPolicy plc3r = aLogServSecurity.SecurityPolicy(KLogFaxEventTypeUid, EReadOp);
    1.82 +	TEST(::HasCapability(plc3r, ECapabilityReadUserData));
    1.83 +	
    1.84 +	TSecurityPolicy plc3w = aLogServSecurity.SecurityPolicy(KLogFaxEventTypeUid, EWriteOp);
    1.85 +	TEST(::HasCapability(plc3w, ECapabilityWriteUserData));
    1.86 +	
    1.87 +	TSecurityPolicy plc4r = aLogServSecurity.SecurityPolicy(KLogShortMessageEventTypeUid, EReadOp);
    1.88 +	TEST(::HasCapability(plc4r, ECapabilityReadUserData));
    1.89 +	
    1.90 +	TSecurityPolicy plc4w = aLogServSecurity.SecurityPolicy(KLogShortMessageEventTypeUid, EWriteOp);
    1.91 +	TEST(::HasCapability(plc4w, ECapabilityWriteUserData));
    1.92 +	
    1.93 +	TSecurityPolicy plc5r = aLogServSecurity.SecurityPolicy(KLogMailEventTypeUid, EReadOp);
    1.94 +	TEST(TCompiledSecurityPolicy(plc5r).Type() == TSecurityPolicy::EAlwaysPass);
    1.95 +	
    1.96 +	TSecurityPolicy plc5w = aLogServSecurity.SecurityPolicy(KLogMailEventTypeUid, EWriteOp);
    1.97 +	TEST(TCompiledSecurityPolicy(plc5w).Type() == TSecurityPolicy::EAlwaysPass);
    1.98 +	
    1.99 +	TSecurityPolicy plc6r = aLogServSecurity.SecurityPolicy(KLogTaskSchedulerEventTypeUid, EReadOp);
   1.100 +	TEST(::HasCapability(plc6r, ECapabilityReadUserData));
   1.101 +	
   1.102 +	TSecurityPolicy plc6w = aLogServSecurity.SecurityPolicy(KLogTaskSchedulerEventTypeUid, EWriteOp);
   1.103 +	TEST(!::HasCapability(plc6w, ECapabilityWriteUserData));
   1.104 +	
   1.105 +	TSecurityPolicy plc7r = aLogServSecurity.SecurityPolicy(KLogPacketDataEventTypeUid, EReadOp);
   1.106 +	TEST(::HasCapability(plc7r, ECapabilityReadUserData));
   1.107 +	
   1.108 +	TSecurityPolicy plc7w = aLogServSecurity.SecurityPolicy(KLogPacketDataEventTypeUid, EWriteOp);
   1.109 +	TEST(::HasCapability(plc7w, ECapabilityWriteUserData));
   1.110 +	
   1.111 +	
   1.112 +	TSecurityPolicy plc8r = aLogServSecurity.SecurityPolicy(KLogLbsSelfLocateEventTypeUid, EReadOp);
   1.113 +	TEST(::HasCapability(plc8r, ECapabilityReadDeviceData));
   1.114 +	
   1.115 +	TSecurityPolicy plc8w = aLogServSecurity.SecurityPolicy(KLogLbsSelfLocateEventTypeUid, EWriteOp);
   1.116 +	TEST(::HasCapability(plc8w, ECapabilityWriteDeviceData));
   1.117 +	
   1.118 +	TSecurityPolicy plc9r = aLogServSecurity.SecurityPolicy(KLogLbsExternalLocateEventTypeUid, EReadOp);
   1.119 +	TEST(::HasCapability(plc9r, ECapabilityReadDeviceData));
   1.120 +	
   1.121 +	TSecurityPolicy plc9w = aLogServSecurity.SecurityPolicy(KLogLbsExternalLocateEventTypeUid, EWriteOp);
   1.122 +	TEST(::HasCapability(plc9w, ECapabilityWriteDeviceData));
   1.123 +	
   1.124 +	TSecurityPolicy plc10r = aLogServSecurity.SecurityPolicy(KLogLbsTransmitLocationEventTypeUid, EReadOp);
   1.125 +	TEST(::HasCapability(plc10r, ECapabilityReadDeviceData));
   1.126 +	
   1.127 +	TSecurityPolicy plc10w = aLogServSecurity.SecurityPolicy(KLogLbsTransmitLocationEventTypeUid, EWriteOp);
   1.128 +	TEST(::HasCapability(plc10w, ECapabilityWriteDeviceData));
   1.129 +	
   1.130 +	TSecurityPolicy plc11r = aLogServSecurity.SecurityPolicy(KLogLbsNetworkLocateEventTypeUid, EReadOp);
   1.131 +	TEST(::HasCapability(plc11r, ECapabilityReadDeviceData));
   1.132 +	
   1.133 +	TSecurityPolicy plc11w = aLogServSecurity.SecurityPolicy(KLogLbsNetworkLocateEventTypeUid, EWriteOp);
   1.134 +	TEST(::HasCapability(plc11w, ECapabilityWriteDeviceData));
   1.135 +	
   1.136 +	TSecurityPolicy plc12r = aLogServSecurity.SecurityPolicy(KLogLbsAssistanceDataEventTypeUid, EReadOp);
   1.137 +	TEST(::HasCapability(plc12r, ECapabilityReadDeviceData));
   1.138 +	
   1.139 +	TSecurityPolicy plc12w = aLogServSecurity.SecurityPolicy(KLogLbsAssistanceDataEventTypeUid, EWriteOp);
   1.140 +	TEST(::HasCapability(plc12w, ECapabilityWriteDeviceData));
   1.141 +	}
   1.142 +
   1.143 +
   1.144 +static void DoOOMTestL()
   1.145 +	{
   1.146 +  CLogServResourceInterpreter* logServRsc = CLogServResourceInterpreter::NewL(TheFileSess);
   1.147 +	CleanupStack::PushL(logServRsc);
   1.148 +	
   1.149 +	CLogServSecurity* logServSecurity = CLogServSecurity::NewL(*logServRsc);
   1.150 +	CleanupStack::PushL(logServSecurity);
   1.151 +
   1.152 +	::CheckEventSecurityPolicies(*logServSecurity);
   1.153 +
   1.154 +	CleanupStack::PopAndDestroy(logServSecurity);
   1.155 +	CleanupStack::PopAndDestroy(logServRsc);
   1.156 +	}
   1.157 +
   1.158 +// CLogServSecurity instance creation - OOM test
   1.159 +static void OOMTest()
   1.160 +	{
   1.161 +	for(TInt count=1;;++count)
   1.162 +		{
   1.163 +		__UHEAP_FAILNEXT(count);
   1.164 +		__UHEAP_MARK;
   1.165 +		TRAPD(err, ::DoOOMTestL());
   1.166 +
   1.167 +		if(err == KErrNoMemory)
   1.168 +			{
   1.169 +			__UHEAP_MARKEND;
   1.170 +			}
   1.171 +		else if(err == KErrNone)
   1.172 +			{
   1.173 +			__UHEAP_MARKEND;
   1.174 +			TheTest.Printf(_L("The test succeeded at heap failure rate=%d.\n"), count);
   1.175 +			break;
   1.176 +			}
   1.177 +		else 
   1.178 +			{
   1.179 +			__UHEAP_MARKEND;
   1.180 +			TEST2(err, KErrNone);
   1.181 +			}
   1.182 +		}
   1.183 +	__UHEAP_RESET;
   1.184 +	}
   1.185 +	
   1.186 +///////////////////////////////////////////////////////////////////////////////////////
   1.187 +//
   1.188 +
   1.189 +static void MainL()
   1.190 +	{
   1.191 +	TheTest.Start(_L(" @SYMTestCaseID:SYSLIBS-LOGENG-LEGACY-T_LOGSECURITY-0001 OOM test "));
   1.192 +	::OOMTest();
   1.193 +	}
   1.194 +
   1.195 +TInt E32Main()
   1.196 +	{
   1.197 +	__UHEAP_MARK;
   1.198 +
   1.199 +	CTrapCleanup* tc = CTrapCleanup::New();
   1.200 +	TEST(tc != NULL);
   1.201 +	
   1.202 +	TEST2(TheFileSess.Connect(), KErrNone);
   1.203 +
   1.204 +	TheTest.Title();
   1.205 +	TRAPD(err, ::MainL());
   1.206 +	TEST2(err, KErrNone);
   1.207 +	
   1.208 +	TheTest.End();
   1.209 +	TheTest.Close();
   1.210 +
   1.211 +	TheFileSess.Close();
   1.212 +	
   1.213 +	delete tc;
   1.214 +
   1.215 +	__UHEAP_MARKEND;
   1.216 +
   1.217 +	User::Heap().Check();
   1.218 +	return KErrNone;
   1.219 +	}