os/persistentdata/loggingservices/eventlogger/test/src/T_LogSecurity.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include <e32test.h>
sl@0
    17
#include <f32file.h>
sl@0
    18
#include "logservsecurity.h"
sl@0
    19
#include "LogServResourceInterpreter.h"
sl@0
    20
#include <logeng.h>
sl@0
    21
#include <logengevents.h>
sl@0
    22
#include "t_logsecuritypolicy.h"
sl@0
    23
#include "t_logutil.h"
sl@0
    24
sl@0
    25
RTest TheTest(_L("t_logsecurity"));
sl@0
    26
static RFs TheFileSess;
sl@0
    27
sl@0
    28
///////////////////////////////////////////////////////////////////////////////////////
sl@0
    29
//
sl@0
    30
sl@0
    31
//Check if supplied aPolicy parameter has aCapability capability.
sl@0
    32
static TBool HasCapability(const TCompiledSecurityPolicy& aPolicy, TCapability aCapability)
sl@0
    33
	{
sl@0
    34
	TInt maxCount = 0;
sl@0
    35
	if(aPolicy.Type() == TSecurityPolicy::ETypeS3 || 
sl@0
    36
	   aPolicy.Type() == TSecurityPolicy::ETypeV3 ||
sl@0
    37
	   aPolicy.Type() == TSecurityPolicy::ETypeC3)
sl@0
    38
		{
sl@0
    39
		maxCount = 3;	
sl@0
    40
		}
sl@0
    41
	else if(aPolicy.Type() == TSecurityPolicy::ETypeC7)
sl@0
    42
		{
sl@0
    43
		maxCount = 7;	
sl@0
    44
		}
sl@0
    45
	else
sl@0
    46
		{
sl@0
    47
		TEST(0);
sl@0
    48
		}
sl@0
    49
	for(TInt i=0;i<maxCount;++i)
sl@0
    50
		{
sl@0
    51
		if(aPolicy.Capability(i) == aCapability)
sl@0
    52
			{
sl@0
    53
			return ETrue;	
sl@0
    54
			}
sl@0
    55
		}
sl@0
    56
	return EFalse;
sl@0
    57
	}
sl@0
    58
sl@0
    59
///////////////////////////////////////////////////////////////////////////////////////
sl@0
    60
//
sl@0
    61
sl@0
    62
//Checks that all supported LogEngServer event types have the expected capabilities.
sl@0
    63
//See LogWrap.rss file
sl@0
    64
static void CheckEventSecurityPolicies(CLogServSecurity& aLogServSecurity)
sl@0
    65
	{
sl@0
    66
	TSecurityPolicy plc1r = aLogServSecurity.SecurityPolicy(KLogCallEventTypeUid, EReadOp);
sl@0
    67
	TEST(::HasCapability(plc1r, ECapabilityReadUserData));
sl@0
    68
	
sl@0
    69
	TSecurityPolicy plc1w = aLogServSecurity.SecurityPolicy(KLogCallEventTypeUid, EWriteOp);
sl@0
    70
	TEST(::HasCapability(plc1w, ECapabilityWriteUserData));
sl@0
    71
	
sl@0
    72
	TSecurityPolicy plc2r = aLogServSecurity.SecurityPolicy(KLogDataEventTypeUid, EReadOp);
sl@0
    73
	TEST(::HasCapability(plc2r, ECapabilityReadUserData));
sl@0
    74
	
sl@0
    75
	TSecurityPolicy plc2w = aLogServSecurity.SecurityPolicy(KLogDataEventTypeUid, EWriteOp);
sl@0
    76
	TEST(::HasCapability(plc2w, ECapabilityWriteUserData));
sl@0
    77
	
sl@0
    78
	TSecurityPolicy plc3r = aLogServSecurity.SecurityPolicy(KLogFaxEventTypeUid, EReadOp);
sl@0
    79
	TEST(::HasCapability(plc3r, ECapabilityReadUserData));
sl@0
    80
	
sl@0
    81
	TSecurityPolicy plc3w = aLogServSecurity.SecurityPolicy(KLogFaxEventTypeUid, EWriteOp);
sl@0
    82
	TEST(::HasCapability(plc3w, ECapabilityWriteUserData));
sl@0
    83
	
sl@0
    84
	TSecurityPolicy plc4r = aLogServSecurity.SecurityPolicy(KLogShortMessageEventTypeUid, EReadOp);
sl@0
    85
	TEST(::HasCapability(plc4r, ECapabilityReadUserData));
sl@0
    86
	
sl@0
    87
	TSecurityPolicy plc4w = aLogServSecurity.SecurityPolicy(KLogShortMessageEventTypeUid, EWriteOp);
sl@0
    88
	TEST(::HasCapability(plc4w, ECapabilityWriteUserData));
sl@0
    89
	
sl@0
    90
	TSecurityPolicy plc5r = aLogServSecurity.SecurityPolicy(KLogMailEventTypeUid, EReadOp);
sl@0
    91
	TEST(TCompiledSecurityPolicy(plc5r).Type() == TSecurityPolicy::EAlwaysPass);
sl@0
    92
	
sl@0
    93
	TSecurityPolicy plc5w = aLogServSecurity.SecurityPolicy(KLogMailEventTypeUid, EWriteOp);
sl@0
    94
	TEST(TCompiledSecurityPolicy(plc5w).Type() == TSecurityPolicy::EAlwaysPass);
sl@0
    95
	
sl@0
    96
	TSecurityPolicy plc6r = aLogServSecurity.SecurityPolicy(KLogTaskSchedulerEventTypeUid, EReadOp);
sl@0
    97
	TEST(::HasCapability(plc6r, ECapabilityReadUserData));
sl@0
    98
	
sl@0
    99
	TSecurityPolicy plc6w = aLogServSecurity.SecurityPolicy(KLogTaskSchedulerEventTypeUid, EWriteOp);
sl@0
   100
	TEST(!::HasCapability(plc6w, ECapabilityWriteUserData));
sl@0
   101
	
sl@0
   102
	TSecurityPolicy plc7r = aLogServSecurity.SecurityPolicy(KLogPacketDataEventTypeUid, EReadOp);
sl@0
   103
	TEST(::HasCapability(plc7r, ECapabilityReadUserData));
sl@0
   104
	
sl@0
   105
	TSecurityPolicy plc7w = aLogServSecurity.SecurityPolicy(KLogPacketDataEventTypeUid, EWriteOp);
sl@0
   106
	TEST(::HasCapability(plc7w, ECapabilityWriteUserData));
sl@0
   107
	
sl@0
   108
	
sl@0
   109
	TSecurityPolicy plc8r = aLogServSecurity.SecurityPolicy(KLogLbsSelfLocateEventTypeUid, EReadOp);
sl@0
   110
	TEST(::HasCapability(plc8r, ECapabilityReadDeviceData));
sl@0
   111
	
sl@0
   112
	TSecurityPolicy plc8w = aLogServSecurity.SecurityPolicy(KLogLbsSelfLocateEventTypeUid, EWriteOp);
sl@0
   113
	TEST(::HasCapability(plc8w, ECapabilityWriteDeviceData));
sl@0
   114
	
sl@0
   115
	TSecurityPolicy plc9r = aLogServSecurity.SecurityPolicy(KLogLbsExternalLocateEventTypeUid, EReadOp);
sl@0
   116
	TEST(::HasCapability(plc9r, ECapabilityReadDeviceData));
sl@0
   117
	
sl@0
   118
	TSecurityPolicy plc9w = aLogServSecurity.SecurityPolicy(KLogLbsExternalLocateEventTypeUid, EWriteOp);
sl@0
   119
	TEST(::HasCapability(plc9w, ECapabilityWriteDeviceData));
sl@0
   120
	
sl@0
   121
	TSecurityPolicy plc10r = aLogServSecurity.SecurityPolicy(KLogLbsTransmitLocationEventTypeUid, EReadOp);
sl@0
   122
	TEST(::HasCapability(plc10r, ECapabilityReadDeviceData));
sl@0
   123
	
sl@0
   124
	TSecurityPolicy plc10w = aLogServSecurity.SecurityPolicy(KLogLbsTransmitLocationEventTypeUid, EWriteOp);
sl@0
   125
	TEST(::HasCapability(plc10w, ECapabilityWriteDeviceData));
sl@0
   126
	
sl@0
   127
	TSecurityPolicy plc11r = aLogServSecurity.SecurityPolicy(KLogLbsNetworkLocateEventTypeUid, EReadOp);
sl@0
   128
	TEST(::HasCapability(plc11r, ECapabilityReadDeviceData));
sl@0
   129
	
sl@0
   130
	TSecurityPolicy plc11w = aLogServSecurity.SecurityPolicy(KLogLbsNetworkLocateEventTypeUid, EWriteOp);
sl@0
   131
	TEST(::HasCapability(plc11w, ECapabilityWriteDeviceData));
sl@0
   132
	
sl@0
   133
	TSecurityPolicy plc12r = aLogServSecurity.SecurityPolicy(KLogLbsAssistanceDataEventTypeUid, EReadOp);
sl@0
   134
	TEST(::HasCapability(plc12r, ECapabilityReadDeviceData));
sl@0
   135
	
sl@0
   136
	TSecurityPolicy plc12w = aLogServSecurity.SecurityPolicy(KLogLbsAssistanceDataEventTypeUid, EWriteOp);
sl@0
   137
	TEST(::HasCapability(plc12w, ECapabilityWriteDeviceData));
sl@0
   138
	}
sl@0
   139
sl@0
   140
sl@0
   141
static void DoOOMTestL()
sl@0
   142
	{
sl@0
   143
  CLogServResourceInterpreter* logServRsc = CLogServResourceInterpreter::NewL(TheFileSess);
sl@0
   144
	CleanupStack::PushL(logServRsc);
sl@0
   145
	
sl@0
   146
	CLogServSecurity* logServSecurity = CLogServSecurity::NewL(*logServRsc);
sl@0
   147
	CleanupStack::PushL(logServSecurity);
sl@0
   148
sl@0
   149
	::CheckEventSecurityPolicies(*logServSecurity);
sl@0
   150
sl@0
   151
	CleanupStack::PopAndDestroy(logServSecurity);
sl@0
   152
	CleanupStack::PopAndDestroy(logServRsc);
sl@0
   153
	}
sl@0
   154
sl@0
   155
// CLogServSecurity instance creation - OOM test
sl@0
   156
static void OOMTest()
sl@0
   157
	{
sl@0
   158
	for(TInt count=1;;++count)
sl@0
   159
		{
sl@0
   160
		__UHEAP_FAILNEXT(count);
sl@0
   161
		__UHEAP_MARK;
sl@0
   162
		TRAPD(err, ::DoOOMTestL());
sl@0
   163
sl@0
   164
		if(err == KErrNoMemory)
sl@0
   165
			{
sl@0
   166
			__UHEAP_MARKEND;
sl@0
   167
			}
sl@0
   168
		else if(err == KErrNone)
sl@0
   169
			{
sl@0
   170
			__UHEAP_MARKEND;
sl@0
   171
			TheTest.Printf(_L("The test succeeded at heap failure rate=%d.\n"), count);
sl@0
   172
			break;
sl@0
   173
			}
sl@0
   174
		else 
sl@0
   175
			{
sl@0
   176
			__UHEAP_MARKEND;
sl@0
   177
			TEST2(err, KErrNone);
sl@0
   178
			}
sl@0
   179
		}
sl@0
   180
	__UHEAP_RESET;
sl@0
   181
	}
sl@0
   182
	
sl@0
   183
///////////////////////////////////////////////////////////////////////////////////////
sl@0
   184
//
sl@0
   185
sl@0
   186
static void MainL()
sl@0
   187
	{
sl@0
   188
	TheTest.Start(_L(" @SYMTestCaseID:SYSLIBS-LOGENG-LEGACY-T_LOGSECURITY-0001 OOM test "));
sl@0
   189
	::OOMTest();
sl@0
   190
	}
sl@0
   191
sl@0
   192
TInt E32Main()
sl@0
   193
	{
sl@0
   194
	__UHEAP_MARK;
sl@0
   195
sl@0
   196
	CTrapCleanup* tc = CTrapCleanup::New();
sl@0
   197
	TEST(tc != NULL);
sl@0
   198
	
sl@0
   199
	TEST2(TheFileSess.Connect(), KErrNone);
sl@0
   200
sl@0
   201
	TheTest.Title();
sl@0
   202
	TRAPD(err, ::MainL());
sl@0
   203
	TEST2(err, KErrNone);
sl@0
   204
	
sl@0
   205
	TheTest.End();
sl@0
   206
	TheTest.Close();
sl@0
   207
sl@0
   208
	TheFileSess.Close();
sl@0
   209
	
sl@0
   210
	delete tc;
sl@0
   211
sl@0
   212
	__UHEAP_MARKEND;
sl@0
   213
sl@0
   214
	User::Heap().Check();
sl@0
   215
	return KErrNone;
sl@0
   216
	}