loggingservices/eventlogger/test/src/t_logplatformsecurity.cpp
changeset 0 08ec8eefde2f
child 11 667e88a979d7
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 
       
     2 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 // All rights reserved.
       
     4 // This component and the accompanying materials are made available
       
     5 // under the terms of "Eclipse Public License v1.0"
       
     6 // which accompanies this distribution, and is available
       
     7 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 //
       
     9 // Initial Contributors:
       
    10 // Nokia Corporation - initial contribution.
       
    11 //
       
    12 // Contributors:
       
    13 //
       
    14 // Description:
       
    15 //
       
    16 
       
    17 
       
    18 #include <s32file.h>
       
    19 #include <logcntdef.h>
       
    20 #include "TEST.H"
       
    21 #include <logview.h>
       
    22 
       
    23 #undef test  //there is a "test" macro which hides "RTest test" declaration.
       
    24 
       
    25 RTest test(_L("Log Client Platform Security Test Harness"));
       
    26 
       
    27 // If LOWCAP is defined in the .mmp file 'TheHiCapability' will be set to false.
       
    28 TBool TheHiCapability = ETrue;
       
    29 
       
    30 const TUid KTestEventUid = {0x10005393};
       
    31 _LIT(KTestEventDesc1, "Event Type Description");
       
    32 _LIT(KTestEventDesc2, "Changed Event Description");
       
    33 _LIT(KTestRemoteParty1, "Remote Party");
       
    34 _LIT(KTestDirection1, "Direction");
       
    35 const TLogDurationType KTestDurationType1 = 1;
       
    36 const TLogDuration KTestDuration1 = 0x1234;
       
    37 _LIT(KTestStatus1, "Status");
       
    38 _LIT(KTestSubject1, "Subject");
       
    39 _LIT(KTestNumber1, "Number");
       
    40 const TLogContactItemId KTestContact1 = 0x1234;
       
    41 const TLogContactItemId KTestContact2 = 0x1234567;
       
    42 const TLogLink KTestLink1 = 0x1234;
       
    43 _LIT8(KTestData1, "ABCDEFGH");
       
    44 const TLogSize KTestMaxLogSize = 0xFFF;
       
    45 const TLogRecentSize KTestMaxRecentLogSize = 0xF;
       
    46 const TLogAge KTestMaxEventAge = 0xFFFFFFF;
       
    47 
       
    48 
       
    49 /**
       
    50 @SYMTestCaseID SYSLIB-LOGENG-CT-0118
       
    51 @SYMTestCaseDesc The test aims to ensure that the log server starts in reponse 
       
    52 to a client request.
       
    53 @SYMTestPriority High
       
    54 @SYMTestActions The test asks the server for details of a built in event type.
       
    55 A successful server start-up is essential for the completion of subsequent tests.
       
    56 @SYMTestExpectedResults Success. (active->iStatus == 0) Regardless of the capability 
       
    57 of the process running this test, it should always succeed because the GetEventType 
       
    58 is not policed by platform security.
       
    59 @SYMREQ REQ3431
       
    60 */
       
    61 LOCAL_C void TestStartupL()
       
    62 	{
       
    63 	test.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0118 "));
       
    64 	CLogClient* client = CLogClient::NewL(theFs);
       
    65 	CleanupStack::PushL(client);
       
    66 
       
    67 	CTestActive* active = new(ELeave)CTestActive();
       
    68 	CleanupStack::PushL(active);
       
    69 
       
    70 	CLogEventType *type = CLogEventType::NewL();
       
    71 	CleanupStack::PushL(type);
       
    72 
       
    73 	type->SetUid(KLogCallEventTypeUid);
       
    74 	active->StartL();
       
    75 	client->GetEventType(*type, active->iStatus);
       
    76 	CActiveScheduler::Start();
       
    77 	TEST2(active->iStatus.Int(), KErrNone);
       
    78 		
       
    79 	CleanupStack::PopAndDestroy(3); // client, active, type
       
    80 	}
       
    81 
       
    82 
       
    83 
       
    84 
       
    85 /**
       
    86 @SYMTestCaseID SYSLIB-LOGENG-CT-0119
       
    87 @SYMTestCaseDesc Tests AddEvent, GetEvent, ChangeEvent and DeleteEvent.
       
    88 @SYMTestPriority High
       
    89 @SYMTestActions See the description and expected results.
       
    90 @SYMTestExpectedResults 
       
    91 
       
    92 1. a client with sufficient capability succeed in all cases would expect the following...
       
    93 AddEvent - KErrNone
       
    94 GetEvent - KErrNone
       
    95 ChangeEvent - KErrNone
       
    96 DeleteEvent - KErrNone
       
    97 
       
    98 2. a client with insufficient capability would expect the following results...
       
    99 AddEvent - KErrPermissionDenied
       
   100 GetEvent - KErrNone
       
   101 ChangeEvent - KErrPermissionDenied
       
   102 DeleteEvent - KErrPermissionDenied
       
   103 
       
   104 @SYMREQ REQ3431
       
   105 */
       
   106 LOCAL_C void TestBasicL(CLogClient& aClient)
       
   107 	{
       
   108 	test.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0119 "));
       
   109 	CTestActive* active = new(ELeave)CTestActive();
       
   110 	CleanupStack::PushL(active);
       
   111 
       
   112 	CLogEvent* event = CLogEvent::NewL();
       
   113 	CleanupStack::PushL(event);
       
   114 	
       
   115 	TTime now;
       
   116 	now.UniversalTime();
       
   117 
       
   118 	event->SetEventType(KLogCallEventTypeUid);
       
   119 
       
   120 	active->StartL();
       
   121 	aClient.AddEvent(*event, active->iStatus);
       
   122 	CActiveScheduler::Start();
       
   123 	TEST2(active->iStatus.Int(), TheHiCapability ? KErrNone : KErrPermissionDenied);
       
   124 
       
   125 	if(!TheHiCapability)
       
   126 		{
       
   127 		TInt eventId = TestUtils::AddEventL();
       
   128 		TEST(eventId >= 0);
       
   129 		event->SetId(eventId);
       
   130 		}
       
   131 
       
   132 
       
   133 	TEST(event->EventType() == KLogCallEventTypeUid);
       
   134 
       
   135 	now = event->Time();
       
   136 
       
   137 	TLogId id = event->Id();
       
   138 
       
   139 	event->SetRemoteParty(KTestRemoteParty1);
       
   140 	event->SetDirection(KTestDirection1);
       
   141 	event->SetDurationType(KTestDurationType1);
       
   142 	event->SetDuration(KTestDuration1);
       
   143 	event->SetStatus(KTestStatus1);
       
   144 	event->SetSubject(KTestSubject1);
       
   145 	event->SetNumber(KTestNumber1);
       
   146 	event->SetContact(KTestContact1);
       
   147 	event->SetLink(KTestLink1);
       
   148 	event->SetDataL(KTestData1);
       
   149 
       
   150 	active->StartL();
       
   151 	aClient.ChangeEvent(*event, active->iStatus);
       
   152 	CActiveScheduler::Start();
       
   153     test.Printf(_L("TestBasicL(), TheHiCapability=%d, event id=%d\r\n"), TheHiCapability, id);
       
   154 	TEST2(active->iStatus.Int(), TheHiCapability ? KErrNone : KErrPermissionDenied);
       
   155 
       
   156 	TEST(event->Id() == id );
       
   157 	TEST(event->EventType() == KLogCallEventTypeUid);
       
   158 
       
   159 	if(TheHiCapability)
       
   160 		{
       
   161 		TEST(event->Description().Length() > 0);
       
   162 		TEST(event->Time() == now);
       
   163 		TEST(event->RemoteParty() == KTestRemoteParty1);
       
   164 		TEST(event->Direction() == KTestDirection1);
       
   165 		TEST(event->DurationType() == KTestDurationType1);
       
   166 		TEST(event->Duration() == KTestDuration1);
       
   167 		TEST(event->Status() == KTestStatus1);
       
   168 		TEST(event->Subject() == KTestSubject1);
       
   169 		TEST(event->Number() == KTestNumber1);
       
   170 		TEST(event->Contact() == KTestContact1);
       
   171 		TEST(event->Link() == KTestLink1);
       
   172 		TEST(event->Data() == KTestData1);
       
   173 		}
       
   174 		
       
   175 	CleanupStack::PopAndDestroy(); // event;
       
   176 
       
   177 	event = CLogEvent::NewL();
       
   178 	CleanupStack::PushL(event);
       
   179 
       
   180 	event->SetId(id);
       
   181 
       
   182 	active->StartL();
       
   183 	aClient.GetEvent(*event, active->iStatus);
       
   184 	CActiveScheduler::Start();
       
   185 	TEST2(active->iStatus.Int(), TheHiCapability ? KErrNone : KErrPermissionDenied);
       
   186 
       
   187 	if(TheHiCapability)
       
   188 		{
       
   189 		TEST(event->Id() == id);
       
   190 		TEST(event->EventType() == KLogCallEventTypeUid);
       
   191 		TEST(event->Description().Length() > 0);
       
   192 		TEST(event->Time() == now);
       
   193 		TEST(event->RemoteParty() == KTestRemoteParty1);
       
   194 		TEST(event->Direction() == KTestDirection1);
       
   195 		TEST(event->DurationType() == KTestDurationType1);
       
   196 		TEST(event->Duration() == KTestDuration1);
       
   197 		TEST(event->Status() == KTestStatus1);
       
   198 		TEST(event->Subject() == KTestSubject1);
       
   199 		TEST(event->Number() == KTestNumber1);
       
   200 		TEST(event->Contact() == KTestContact1);
       
   201 		TEST(event->Link() == KTestLink1);
       
   202 		TEST(event->Data() == KTestData1);
       
   203 		}
       
   204 			
       
   205 	active->StartL();
       
   206 	aClient.DeleteEvent(id, active->iStatus);
       
   207 	CActiveScheduler::Start();
       
   208 	TEST2(active->iStatus.Int(), TheHiCapability ? KErrNone : KErrPermissionDenied);
       
   209 
       
   210 	active->StartL();
       
   211 	aClient.GetEvent(*event, active->iStatus);
       
   212 	CActiveScheduler::Start();
       
   213 	TEST2(active->iStatus.Int(), TheHiCapability ? KErrNotFound : KErrPermissionDenied);
       
   214 	
       
   215 	// try to delete a non-existent event...
       
   216 	active->StartL();
       
   217 	aClient.DeleteEvent(123, active->iStatus);
       
   218 	CActiveScheduler::Start();
       
   219 	TEST2(active->iStatus.Int(), KErrNotFound);
       
   220 
       
   221 	CleanupStack::PopAndDestroy(2); // event, active
       
   222 	}
       
   223 
       
   224 
       
   225 
       
   226 /**
       
   227 @SYMTestCaseID SYSLIB-LOGENG-CT-0120
       
   228 @SYMTestCaseDesc Test AddEventType for high and low capability clients
       
   229 @SYMTestPriority High
       
   230 @SYMTestActions 
       
   231 1.  For a clients of all capabilities...
       
   232 	a. Add a new event type
       
   233 	b. Fill a CLogEventType object with details of the new type
       
   234 	c. Try to add the new event type for a second time 
       
   235 
       
   236 @SYMTestExpectedResults 
       
   237 1.  For a client with sufficient capability...
       
   238 	Test a. - KErrNone - the new event type was added OK
       
   239 	Test b. - KErrNone - the new event type is fully visible
       
   240 	Test c. - KErrAlreadyExists - it was already added by test a. !
       
   241 
       
   242 2.  For a client with insufficient capability...
       
   243 	Test a. - KErrPermissionDenied - not allowed !
       
   244 	Test b. - KErrNotFound - allowed, but it isn't there because test a. failed.
       
   245 	Test c. - KErrPermissionDenied - exactly the same as test a.
       
   246 	
       
   247 @SYMREQ REQ3431
       
   248 */
       
   249 LOCAL_C void TestAddEventTypeL(CLogClient& aClient)
       
   250 	{
       
   251 	test.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0120 "));
       
   252 	CLogEventType* type = CLogEventType::NewL();
       
   253 	CleanupStack::PushL(type);
       
   254 
       
   255 	type->SetUid(KTestEventUid);
       
   256 	type->SetDescription(KTestEventDesc1);
       
   257 	type->SetLoggingEnabled(ETrue);
       
   258 
       
   259 	CTestActive* active = new(ELeave)CTestActive();
       
   260 	CleanupStack::PushL(active);
       
   261 
       
   262 	aClient.AddEventType(*type, active->iStatus);
       
   263 	active->StartL();
       
   264 	CActiveScheduler::Start();
       
   265 	TEST2(active->iStatus.Int(), TheHiCapability ? KErrNone : KErrPermissionDenied);
       
   266 		
       
   267 	active->StartL();
       
   268 	aClient.GetEventType(*type, active->iStatus);
       
   269 	CActiveScheduler::Start();
       
   270 	TEST2(active->iStatus.Int(), TheHiCapability ? KErrNone : KErrNotFound);
       
   271 			
       
   272 	active->StartL();
       
   273 	aClient.AddEventType(*type, active->iStatus);
       
   274 	CActiveScheduler::Start();
       
   275 	TEST2(active->iStatus.Int(), TheHiCapability ? KErrAlreadyExists : KErrPermissionDenied);
       
   276 
       
   277 	CleanupStack::PopAndDestroy(2); // active, type
       
   278 	}
       
   279 
       
   280 
       
   281 
       
   282 /**
       
   283 @SYMTestCaseID SYSLIB-LOGENG-CT-0121
       
   284 @SYMTestCaseDesc Try to populate an CLogEventType object with details of a 
       
   285 non built-in event type.
       
   286 @SYMTestPriority High
       
   287 @SYMTestActions Calls GetEventType(...)
       
   288 @SYMTestExpectedResults Always succeeds - all clients should be able to do this as
       
   289 the GetEventType operation is not policed by platform security.
       
   290 @SYMREQ REQ3431
       
   291 */
       
   292 LOCAL_C void TestGetEventTypeL(CLogClient& aClient)
       
   293 	//
       
   294 	// This test should succeed, regardless of capability
       
   295 	// GetEventType is not policed.
       
   296 	//
       
   297 	{
       
   298 	test.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0121 "));
       
   299 	CLogEventType* type = CLogEventType::NewL();
       
   300 	CleanupStack::PushL(type);
       
   301 
       
   302 	type->SetUid(KTestEventUid);
       
   303 
       
   304 	CTestActive* active = new(ELeave)CTestActive();
       
   305 	CleanupStack::PushL(active);
       
   306 
       
   307 	aClient.GetEventType(*type, active->iStatus);
       
   308 	active->StartL();
       
   309 	CActiveScheduler::Start();
       
   310 	TEST2(active->iStatus.Int(), KErrNone);
       
   311 
       
   312 	TEST(type->Uid() == KTestEventUid);
       
   313 	TEST(type->Description() == KTestEventDesc1);
       
   314 	TEST(type->LoggingEnabled());
       
   315 
       
   316 	CleanupStack::PopAndDestroy(2); // active, type
       
   317 	}
       
   318 
       
   319 
       
   320 
       
   321 
       
   322 /**
       
   323 @SYMTestCaseID SYSLIB-LOGENG-CT-0122
       
   324 @SYMTestCaseDesc Tries to change existing event types.
       
   325 @SYMTestActions See the description and expected results.
       
   326 @SYMTestPriority High
       
   327 @SYMTestExpectedResults Should always succeed
       
   328 @SYMREQ REQ3431
       
   329 */
       
   330 LOCAL_C void TestChangeEventTypeL(CLogClient& aClient)
       
   331 	{
       
   332 	test.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0122 "));
       
   333 	CTestActive* active = new(ELeave)CTestActive();
       
   334 	CleanupStack::PushL(active);
       
   335 
       
   336 	CLogEventType* type = CLogEventType::NewL();
       
   337 	CleanupStack::PushL(type);
       
   338 
       
   339 	type->SetUid(KTestEventUid);
       
   340 
       
   341 	type->SetDescription(KTestEventDesc1);
       
   342 	type->SetDescription(KTestEventDesc2);
       
   343 
       
   344 #ifdef _DEBUG
       
   345 	TInt failCount = 0;
       
   346 #endif
       
   347 
       
   348 	TBool finished = EFalse;
       
   349 	TInt error;
       
   350 
       
   351 	while(!finished)
       
   352 		{
       
   353 		error = KErrNone;
       
   354 
       
   355 		type->SetDescription(KTestEventDesc2);
       
   356 		type->SetLoggingEnabled(EFalse);
       
   357 
       
   358 		__UHEAP_FAILNEXT(failCount++);
       
   359 		
       
   360 		aClient.ChangeEventType(*type, active->iStatus);
       
   361 
       
   362 		active->StartL();
       
   363 		CActiveScheduler::Start();
       
   364 
       
   365 		if (active->iStatus == KErrNone)
       
   366 			finished = ETrue;
       
   367 		else
       
   368 			error = active->iStatus.Int();
       
   369 
       
   370 		__UHEAP_RESET;
       
   371 
       
   372 		if (error == KErrNoMemory)
       
   373 			{
       
   374 			active->StartL();
       
   375 			aClient.GetEventType(*type, active->iStatus);
       
   376 			CActiveScheduler::Start();
       
   377 			TEST2(active->iStatus.Int(), KErrNone);
       
   378 
       
   379 			TEST(type->Description() == KTestEventDesc1);
       
   380 			TEST(type->LoggingEnabled());
       
   381 			}
       
   382 		else
       
   383 			{
       
   384 			TEST2(error, TheHiCapability ? KErrNone : KErrPermissionDenied);
       
   385 			
       
   386 			if(!TheHiCapability)
       
   387 				finished = TRUE;
       
   388 			}
       
   389 		}
       
   390 
       
   391 	type->SetUid(KTestEventUid);
       
   392 
       
   393 	active->StartL();
       
   394 	aClient.GetEventType(*type, active->iStatus);
       
   395 	CActiveScheduler::Start();
       
   396 	TEST2(active->iStatus.Int(), KErrNone);
       
   397 
       
   398 	if(TheHiCapability)
       
   399 		{
       
   400 		TEST(type->Uid() == KTestEventUid);
       
   401 		TEST(type->Description() == KTestEventDesc2);
       
   402 		TEST(type->LoggingEnabled() == EFalse);
       
   403 		}
       
   404 	else
       
   405 		{
       
   406 		TEST(type->Uid() == KTestEventUid);
       
   407 		TEST(type->Description() == KTestEventDesc1);
       
   408 		TEST(type->LoggingEnabled());
       
   409 		}
       
   410 
       
   411 	CleanupStack::PopAndDestroy(2); // type, active
       
   412 	}
       
   413 
       
   414 
       
   415 
       
   416 
       
   417 /**
       
   418 @SYMTestCaseID SYSLIB-LOGENG-CT-0123
       
   419 @SYMTestCaseDesc Delete event types
       
   420 @SYMTestActions See the description and expected results.
       
   421 @SYMTestPriority High
       
   422 @SYMTestExpectedResults Should always succeed
       
   423 @SYMREQ REQ3431
       
   424 */
       
   425 LOCAL_C void TestDeleteEventTypeL(CLogClient& aClient)
       
   426 	{
       
   427 	test.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0123 "));
       
   428 	CTestActive* active = new(ELeave)CTestActive();
       
   429 	CleanupStack::PushL(active);
       
   430 
       
   431 	CLogEventType* type = CLogEventType::NewL();
       
   432 	CleanupStack::PushL(type);
       
   433 
       
   434 	type->SetUid(KTestEventUid);
       
   435 
       
   436 #ifdef _DEBUG
       
   437 	TInt failCount = 0;
       
   438 #endif
       
   439 
       
   440 	TBool finished = EFalse;
       
   441 	TInt error;
       
   442 
       
   443 	while(!finished)
       
   444 		{
       
   445 		error = KErrNone;
       
   446 
       
   447 		__UHEAP_FAILNEXT(failCount++);
       
   448 		aClient.DeleteEventType(KTestEventUid, active->iStatus);
       
   449 
       
   450 		active->StartL();
       
   451 		CActiveScheduler::Start();
       
   452 
       
   453 		if (active->iStatus == KErrNone)
       
   454 			finished = ETrue;
       
   455 		else
       
   456 			error = active->iStatus.Int();
       
   457 
       
   458 		__UHEAP_RESET;
       
   459 
       
   460 		if (error == KErrNoMemory)
       
   461 			{
       
   462 			active->StartL();
       
   463 			aClient.GetEventType(*type, active->iStatus);
       
   464 			CActiveScheduler::Start();
       
   465 			TEST2(active->iStatus.Int(), KErrNone);
       
   466 			}
       
   467 		else
       
   468 			{
       
   469 			TEST2(error, TheHiCapability ? KErrNone : KErrPermissionDenied);
       
   470 			
       
   471 			if(!TheHiCapability)
       
   472 				finished = TRUE;
       
   473 			}
       
   474 		}
       
   475 
       
   476 	active->StartL();
       
   477 	aClient.GetEventType(*type, active->iStatus);
       
   478 	CActiveScheduler::Start();
       
   479 	TEST2(active->iStatus.Int(), TheHiCapability ? KErrNotFound : KErrNone);
       
   480 
       
   481 	CleanupStack::PopAndDestroy(2); // type, active
       
   482 	}
       
   483 
       
   484 
       
   485 
       
   486 
       
   487 /**
       
   488 @SYMTestCaseID SYSLIB-LOGENG-CT-0124
       
   489 @SYMTestCaseDesc Try to delete built in event types
       
   490 @SYMTestPriority High
       
   491 @SYMTestActions No one is allowed to delete built in event types !
       
   492 @SYMTestExpectedResults Should always succeed
       
   493 @SYMREQ REQ3431
       
   494 */
       
   495 LOCAL_C void TestDeleteBuiltInEventTypeL(CLogClient& aClient)
       
   496 	{
       
   497 	test.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0124 "));
       
   498 	CTestActive* active = new(ELeave)CTestActive();
       
   499 	CleanupStack::PushL(active);
       
   500 
       
   501 	CLogEventType* type = CLogEventType::NewL();
       
   502 	CleanupStack::PushL(type);
       
   503 	
       
   504 	TUid someBuiltInTypes [] = 
       
   505 		{
       
   506 		KLogCallEventTypeUid, 
       
   507 		KLogDataEventTypeUid, 
       
   508 		KLogFaxEventTypeUid
       
   509 		};
       
   510 	
       
   511 	for (TInt i=0; i < 3; i++)
       
   512 		{
       
   513 		aClient.DeleteEventType(someBuiltInTypes [i], active->iStatus);
       
   514 		active->StartL();
       
   515 		CActiveScheduler::Start();
       
   516 		TEST2(active->iStatus.Int(), KErrPermissionDenied);
       
   517 
       
   518 		type->SetUid(someBuiltInTypes [i]);
       
   519 		active->StartL();
       
   520 		aClient.GetEventType(*type, active->iStatus);
       
   521 		CActiveScheduler::Start();
       
   522 		TEST2(active->iStatus.Int(), KErrNone);
       
   523 		TEST(type->Uid() == someBuiltInTypes [i]);
       
   524 		}
       
   525 
       
   526 	CleanupStack::PopAndDestroy(2); // type, active
       
   527 	}
       
   528 
       
   529 
       
   530 
       
   531 
       
   532 
       
   533 /**
       
   534 @SYMTestCaseID SYSLIB-LOGENG-CT-0125
       
   535 @SYMTestCaseDesc Get database configuration
       
   536 @SYMTestPriority High
       
   537 @SYMTestActions All clients are allowed to do this
       
   538 @SYMTestExpectedResults Should always succeed
       
   539 @SYMREQ REQ3431
       
   540 */
       
   541 LOCAL_C void TestGetConfigL(CLogClient& aClient)
       
   542 	{
       
   543 	test.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0125 "));
       
   544 	CTestActive* active = new(ELeave)CTestActive();
       
   545 	CleanupStack::PushL(active);
       
   546 
       
   547 	TLogConfig config;
       
   548 
       
   549 	TEST(config.iMaxEventAge == 0);
       
   550 	TEST(config.iMaxLogSize == 0);
       
   551 	TEST(config.iMaxRecentLogSize == 0);
       
   552 
       
   553 #ifdef _DEBUG
       
   554 	TInt failCount = 0;
       
   555 #endif
       
   556 
       
   557 	TBool finished = EFalse;
       
   558 
       
   559 	while(!finished)
       
   560 		{
       
   561 		__UHEAP_FAILNEXT(failCount++);
       
   562 		aClient.GetConfig(config, active->iStatus);
       
   563 
       
   564 		active->StartL();
       
   565 		CActiveScheduler::Start();
       
   566 
       
   567 		if (active->iStatus == KErrNone)
       
   568 			finished = ETrue;
       
   569 		else
       
   570 			TEST2(active->iStatus.Int(), KErrNoMemory);
       
   571 
       
   572 		__UHEAP_RESET;
       
   573 		}
       
   574 
       
   575 	TEST(config.iMaxEventAge > 0);
       
   576 	TEST(config.iMaxLogSize > 0);
       
   577 	TEST(config.iMaxRecentLogSize > 0);
       
   578 
       
   579 	CleanupStack::PopAndDestroy(); // active
       
   580 	}
       
   581 
       
   582 
       
   583 
       
   584 
       
   585 /**
       
   586 @SYMTestCaseID SYSLIB-LOGENG-CT-0126
       
   587 @SYMTestCaseDesc Change the database configuration
       
   588 @SYMTestPriority High
       
   589 @SYMTestActions Low capability clients can't do this
       
   590 @SYMTestExpectedResults Should always succeed
       
   591 @SYMREQ REQ3431
       
   592 */
       
   593 LOCAL_C void TestChangeConfigL(CLogClient& aClient)
       
   594 	{
       
   595 	test.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0126 "));
       
   596 	CTestActive* active = new(ELeave)CTestActive();
       
   597 	CleanupStack::PushL(active);
       
   598 
       
   599 	TLogConfig configOld;
       
   600 
       
   601 	active->StartL();
       
   602 	aClient.GetConfig(configOld, active->iStatus);
       
   603 	CActiveScheduler::Start();
       
   604 	TEST2(active->iStatus.Int(), KErrNone);
       
   605 
       
   606 	TLogConfig config;
       
   607 
       
   608 #ifdef _DEBUG
       
   609 	TInt failCount = 0;
       
   610 #endif
       
   611 
       
   612 	TBool finished = EFalse;
       
   613 	TInt error;
       
   614 
       
   615 	while(!finished)
       
   616 		{
       
   617 		error = KErrNone;
       
   618 
       
   619 		config.iMaxLogSize = KTestMaxLogSize;
       
   620 		config.iMaxRecentLogSize = KTestMaxRecentLogSize;
       
   621 		config.iMaxEventAge = KTestMaxEventAge;
       
   622 
       
   623 		__UHEAP_FAILNEXT(failCount++);
       
   624 		aClient.ChangeConfig(config, active->iStatus);
       
   625 
       
   626 		active->StartL();
       
   627 		CActiveScheduler::Start();
       
   628 
       
   629 		if (active->iStatus == KErrNone)
       
   630 			finished = ETrue;
       
   631 		else
       
   632 			error = active->iStatus.Int();
       
   633 		
       
   634 		__UHEAP_RESET;
       
   635 
       
   636 		if ((error == KErrNoMemory) || (error == KErrPermissionDenied))
       
   637 			{
       
   638 			active->StartL();
       
   639 			aClient.GetConfig(config, active->iStatus);
       
   640 			CActiveScheduler::Start();
       
   641 			TEST2(active->iStatus.Int(), KErrNone);
       
   642 
       
   643 			TEST(config.iMaxLogSize == configOld.iMaxLogSize);
       
   644 			TEST(config.iMaxRecentLogSize == configOld.iMaxRecentLogSize);
       
   645 			TEST(config.iMaxEventAge == configOld.iMaxEventAge);
       
   646 			}
       
   647 		else
       
   648 			{
       
   649 			TEST2(error, KErrNone);		
       
   650 			}
       
   651 			
       
   652 		if(! TheHiCapability)
       
   653 			finished = TRUE;
       
   654 						
       
   655 		}
       
   656 
       
   657 	if(TheHiCapability)
       
   658 		{
       
   659 		TEST(config.iMaxLogSize == KTestMaxLogSize);
       
   660 		TEST(config.iMaxRecentLogSize == KTestMaxRecentLogSize);
       
   661 		TEST(config.iMaxEventAge == KTestMaxEventAge);
       
   662 		}
       
   663 	else
       
   664 		{
       
   665 		TEST(config.iMaxLogSize == configOld.iMaxLogSize);
       
   666 		TEST(config.iMaxRecentLogSize == configOld.iMaxRecentLogSize);
       
   667 		TEST(config.iMaxEventAge == configOld.iMaxEventAge);
       
   668 		}
       
   669 		
       
   670 	CleanupStack::PopAndDestroy(); // active
       
   671 	}
       
   672 
       
   673 
       
   674 
       
   675 
       
   676 /**
       
   677 @SYMTestCaseID SYSLIB-LOGENG-CT-0127
       
   678 @SYMTestCaseDesc Clear the log
       
   679 @SYMTestPriority High
       
   680 @SYMTestActions Low capability clients can't do this
       
   681 @SYMTestExpectedResults Should always pass
       
   682 @SYMREQ REQ3431
       
   683 */
       
   684 void ClearLogL(CLogClient& aClient)
       
   685 	{
       
   686 	test.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0127 "));
       
   687 	CTestActive* active = new(ELeave)CTestActive();
       
   688 	CleanupStack::PushL(active);
       
   689 
       
   690 	TTime now;
       
   691 	now.UniversalTime();
       
   692 	
       
   693 	active->StartL();
       
   694 	aClient.ClearLog(now, active->iStatus);
       
   695 		
       
   696 	CActiveScheduler::Start();
       
   697 	TEST2(active->iStatus.Int(), TheHiCapability ? KErrNone : KErrPermissionDenied);
       
   698 	
       
   699 	CleanupStack::PopAndDestroy(); // active
       
   700 	}	
       
   701 
       
   702 /**
       
   703 @SYMTestCaseID SYSLIB-LOGENG-CT-0128
       
   704 @SYMTestCaseDesc Try to clear the recent event list
       
   705 @SYMTestPriority High
       
   706 @SYMTestActions Low capability clients will fail
       
   707 @SYMTestExpectedResults Should always succeed
       
   708 @SYMREQ REQ3431
       
   709 */
       
   710 void ClearRecentListL(CLogClient& aClient)
       
   711 	{
       
   712 	test.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0128 "));
       
   713 	CTestActive* active = new(ELeave)CTestActive();
       
   714 	CleanupStack::PushL(active);
       
   715 
       
   716 	TTime now;
       
   717 	now.UniversalTime();
       
   718 	
       
   719 	active->StartL();
       
   720 	aClient.ClearLog(KLogRecentIncomingCalls, active->iStatus);
       
   721 	
       
   722 	CActiveScheduler::Start();
       
   723 	TEST2(active->iStatus.Int(), TheHiCapability ? KErrNone : KErrPermissionDenied);
       
   724 	
       
   725 	CleanupStack::PopAndDestroy(); // active
       
   726 	}	
       
   727 
       
   728 #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM	
       
   729 
       
   730 /**
       
   731 @SYMTestCaseID			PDS-LOGENG-UT-4040
       
   732 @SYMTestCaseDesc		Clear log events with specific SimId - platform security test.
       
   733 						This test is called from two test applications: t_logHicapability 
       
   734 						and t_loglowcapabilty. As the names state, t_loghicapability has platsec capabilities to 
       
   735 						call CLogClient::CLearLog(), t_loglowcapabilty - hasn't.
       
   736 						When t_loghicapability calls ClearLogL(), "TheHiCapability" flag is true and it is expected
       
   737 						the CLogClient::ClearLog() call to complete successfully. 
       
   738 						When t_loglowcapability calls ClearLogL(), "TheHiCapability" flag is false and it is expected
       
   739 						the CLogClient::ClearLog() call to fail with KErrPermissionDenied. 
       
   740 @SYMTestActions			Clear log events with specific SimId - platform security test.
       
   741 @SYMTestExpectedResults Test must not fail
       
   742 @SYMTestPriority		High
       
   743 @SYMREQ					REQ12748
       
   744 */
       
   745 void ClearLogL(CLogClient& aClient, TSimId aSimId)
       
   746 	{//This test case is compiled only when SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM macro is defined.
       
   747 	CTestActive* active = new(ELeave)CTestActive();
       
   748 	CleanupStack::PushL(active);
       
   749 
       
   750 	TTime now;
       
   751 	now.UniversalTime();
       
   752 	
       
   753 	active->StartL();
       
   754 	aClient.ClearLog(now, aSimId, active->iStatus);
       
   755 		
       
   756 	CActiveScheduler::Start();
       
   757 	TEST2(active->iStatus.Int(), TheHiCapability ? KErrNone : KErrPermissionDenied);
       
   758 	
       
   759 	CleanupStack::PopAndDestroy(); // active
       
   760 	}	
       
   761 
       
   762 /**
       
   763 @SYMTestCaseID			PDS-LOGENG-UT-4041
       
   764 @SYMTestCaseDesc		Clear log events from the specified recent list with specific SimId - platform security test.
       
   765 						This test is called from two test applications: t_logHicapability 
       
   766 						and t_loglowcapabilty. As the names state, t_loghicapability has platsec capabilities to 
       
   767 						call CLogClient::CLearLog(), t_loglowcapabilty - hasn't.
       
   768 						When t_loghicapability calls ClearLogL(), "TheHiCapability" flag is true and it is expected
       
   769 						the CLogClient::ClearLog() call to complete successfully. 
       
   770 						When t_loglowcapability calls ClearLogL(), "TheHiCapability" flag is false and it is expected
       
   771 						the CLogClient::ClearLog() call to fail with KErrPermissionDenied. 
       
   772 @SYMTestActions			Clear log events from the specified recent list with specific SimId - platform security test.
       
   773 @SYMTestExpectedResults Test must not fail
       
   774 @SYMTestPriority		High
       
   775 @SYMREQ					REQ12748
       
   776 */
       
   777 void ClearRecentListL(CLogClient& aClient, TSimId aSimId)
       
   778 	{//This test case is compiled only when SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM macro is defined.
       
   779 	CTestActive* active = new(ELeave)CTestActive();
       
   780 	CleanupStack::PushL(active);
       
   781 
       
   782 	TTime now;
       
   783 	now.UniversalTime();
       
   784 	
       
   785 	active->StartL();
       
   786 	aClient.ClearLog(KLogRecentIncomingCalls, aSimId, active->iStatus);
       
   787 	
       
   788 	CActiveScheduler::Start();
       
   789 	TEST2(active->iStatus.Int(), TheHiCapability ? KErrNone : KErrPermissionDenied);
       
   790 	
       
   791 	CleanupStack::PopAndDestroy(); // active
       
   792 	}	
       
   793 
       
   794 #endif//SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM	
       
   795 
       
   796 /**
       
   797 @SYMTestCaseID SYSLIB-LOGENG-CT-0129
       
   798 @SYMTestCaseDesc Test that a view only contains events that are suitable for a clients cabability
       
   799 @SYMTestPriority High
       
   800 @SYMTestActions See comments in the trest code below for further info.
       
   801 @SYMTestExpectedResults Should always succeed
       
   802 @SYMREQ REQ3431
       
   803 */
       
   804 LOCAL_C void TestEventViewWithFilterL(CLogClient& aClient)
       
   805 	{
       
   806 	// TestUtils::AddTestEventsL() --> should be called before this function.
       
   807 	// It deletes the database, then...
       
   808 	// adds 8 events - 2 are visible to clients with no capabilities
       
   809 	// and 6 are of type KLogCallEventTypeUid, which is protected.
       
   810 	test.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0129 "));
       
   811 	CTestActive* active = new(ELeave)CTestActive;
       
   812 	CleanupStack::PushL(active);
       
   813 
       
   814 	CLogFilterList* list = new(ELeave)CLogFilterList;
       
   815 	CleanupStack::PushL(list);
       
   816 
       
   817 	CLogViewEvent* view = CLogViewEvent::NewL(aClient);
       
   818 	CleanupStack::PushL(view);
       
   819 
       
   820 	CLogFilter* filter = CLogFilter::NewL();
       
   821 	CleanupStack::PushL(filter);
       
   822 	
       
   823 	TLogString direction;
       
   824 	aClient.GetString(direction, R_LOG_DIR_IN);
       
   825 	
       
   826 	// Test 1.
       
   827 	// Of the 8 new events, 2 have KTestContact1 as the contact field
       
   828 	// One of them is a secure type and the other isn't.
       
   829 	// So, if running at hi capability, expect 2 events, else 1
       
   830 	TInt expectedEventCount = (TheHiCapability) ? 2 : 1;
       
   831 	filter->SetContact(KTestContact1);
       
   832 	list->AppendL(filter);
       
   833 	active->StartL();
       
   834 	TEST(view->SetFilterL(*list, active->iStatus));
       
   835 	CActiveScheduler::Start();
       
   836 	TEST(view->CountL() == expectedEventCount);
       
   837 	
       
   838 	// Test 2.
       
   839 	// Of the 8 new events, 6 have KTestContact2 as the contact field
       
   840 	// One of them is a secure type and the other isn't.
       
   841 	// The filters will be combined in the query, so expect
       
   842 	// 8 events if running at hi capability, else 2
       
   843 	expectedEventCount = (TheHiCapability) ? 8 : 2;
       
   844 	CleanupStack::Pop(); // filter
       
   845 	filter = CLogFilter::NewL();
       
   846 	CleanupStack::PushL(filter);
       
   847 	filter->SetContact(KTestContact2);
       
   848 	list->AppendL(filter);
       
   849 	active->StartL();
       
   850 	TEST(view->SetFilterL(*list, active->iStatus));
       
   851 	CActiveScheduler::Start();
       
   852 	TEST(view->CountL() == expectedEventCount);
       
   853 		
       
   854 	// Test 3.
       
   855 	// Of the 8 new events, 7 have R_LOG_DIR_IN as the direction field.
       
   856 	// Two of these are only visible for hi capability clients, the other one
       
   857 	// can be viewed by all clients.
       
   858 	expectedEventCount = (TheHiCapability) ? 7 : 1;
       
   859 	CleanupStack::Pop(); // filter
       
   860 	filter = CLogFilter::NewL();
       
   861 	CleanupStack::PushL(filter);
       
   862 	filter->SetDirection(direction);
       
   863 	list->AppendL(filter);
       
   864 	active->StartL();
       
   865 	TEST(view->SetFilterL(*list, active->iStatus));
       
   866 	CActiveScheduler::Start();
       
   867 	TEST(view->CountL() == expectedEventCount);
       
   868 	
       
   869 	// clear up...
       
   870 	list->ResetAndDestroy();
       
   871 	CleanupStack::Pop(); // filter
       
   872 	CleanupStack::PopAndDestroy(3);  // view, list, active
       
   873 	}
       
   874 
       
   875 
       
   876 
       
   877 
       
   878 /**
       
   879 @SYMTestCaseID SYSLIB-LOGENG-CT-0130
       
   880 @SYMTestCaseDesc Test the clients ability to view recent events
       
   881 @SYMTestActions See the description and expected results.
       
   882 @SYMTestPriority High
       
   883 @SYMTestExpectedResults Should always succeed
       
   884 @SYMREQ REQ3431
       
   885 */
       
   886 LOCAL_C void TestRecentViewL(CLogClient& aClient)
       
   887 	{
       
   888 	test.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0130 "));
       
   889 	CTestActive* active = new(ELeave)CTestActive();
       
   890 	CleanupStack::PushL(active);
       
   891 
       
   892 	CLogViewRecent* view = CLogViewRecent::NewL(aClient);
       
   893 	CleanupStack::PushL(view);
       
   894 
       
   895 	active->StartL();
       
   896 	
       
   897 	// will return FALSE if the view is empty, which should  be the case
       
   898 	// with low/no capability clients.
       
   899 	if (view->SetRecentListL(KLogRecentIncomingCalls, active->iStatus))
       
   900 		{
       
   901 		__ASSERT_ALWAYS(TheHiCapability, _L("TestRecentViewL"));
       
   902 		CActiveScheduler::Start();
       
   903 		TEST2(active->iStatus.Int(), KErrNone);
       
   904 		TEST(view->CountL() == 2);
       
   905 		TInt count = view->CountL();
       
   906 		}
       
   907 	else	// low capability client won't be able to see recent incoming calls
       
   908 		{
       
   909 		__ASSERT_ALWAYS(!TheHiCapability, _L("TestRecentViewL"));
       
   910 		active->Cancel();
       
   911 		}
       
   912 
       
   913 	CleanupStack::PopAndDestroy(2);	// view, active
       
   914 	}
       
   915 
       
   916 //.............................................................................
       
   917 
       
   918 void doTestsL()
       
   919 	{
       
   920 	TestUtils::Initialize(_L("T_LOGENGSECURITY"));
       
   921 	
       
   922 #ifdef LOWCAP	//  defined in mmp file
       
   923 	TheHiCapability = EFalse;
       
   924 #else
       
   925 	TheHiCapability = ETrue;
       
   926 #endif
       
   927 					
       
   928 	test.Start(_L("Starting tests..."));
       
   929 		
       
   930 	CLogClient* client = CLogClient::NewL(theFs);
       
   931 	CleanupStack::PushL(client);
       
   932 	
       
   933 	TestUtils::DeleteDatabaseL();
       
   934 	
       
   935 	test.Start(_L("Server startup"));
       
   936 	TestStartupL();
       
   937 	User::After(100000);
       
   938 
       
   939 	test.Next(_L("Test Add, Get, Change & Delete event"));
       
   940 	TestUtils::DeleteDatabaseL();
       
   941 	TestBasicL(*client);
       
   942 	theLog.Write(_L8("Basic tests OK\n"));
       
   943 
       
   944 	test.Next(_L("Add Event Type"));
       
   945 	TestAddEventTypeL(*client);
       
   946 	theLog.Write(_L8("Add Event Type test OK\n"));
       
   947 	
       
   948 	if(!TheHiCapability)
       
   949 		{	
       
   950 		// TestAddEventTypeL() will have failed to add an event type, so
       
   951 		// this will ensure one is present for the next tests.
       
   952 		TestUtils::AddEventTypeL();
       
   953 		}
       
   954 	
       
   955 	test.Next(_L("Get Event Type"));
       
   956 	TestGetEventTypeL(*client);
       
   957 	theLog.Write(_L8("Get Event Type test OK\n"));
       
   958 	
       
   959 	test.Next(_L("Change Event Type"));
       
   960 	TestChangeEventTypeL(*client);
       
   961 	theLog.Write(_L8("Change Event Type test OK\n"));
       
   962 	
       
   963 	test.Next(_L("Delete Event Type"));
       
   964 	TestDeleteEventTypeL(*client);
       
   965 	theLog.Write(_L8("Delete Event Type test OK\n"));
       
   966 	
       
   967 	test.Next(_L("Delete Built-in Event Type"));
       
   968 	TestDeleteBuiltInEventTypeL(*client);
       
   969 	theLog.Write(_L8("Delete Built-in Event Type test OK\n"));
       
   970 	
       
   971 	test.Next(_L("Get Server Configuration"));
       
   972 	TestGetConfigL(*client);
       
   973 	theLog.Write(_L8("Get Server Configuration test OK\n"));
       
   974 	
       
   975 	test.Next(_L("Change Server Configuration"));
       
   976 	TestChangeConfigL(*client);
       
   977 	theLog.Write(_L8("Change Server Configuration test OK\n"));
       
   978 	
       
   979 	test.Next(_L("Clear the Log test"));
       
   980 	ClearLogL(*client);
       
   981 	theLog.Write(_L8("Clear the Log test OK\n"));
       
   982 		
       
   983 	test.Next(_L("Clear Recent List test"));
       
   984 	ClearRecentListL(*client);
       
   985 	theLog.Write(_L8("Clear Recent List test OK\n"));
       
   986 	
       
   987 #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM	
       
   988 	const TSimId KSimId = 4000000000U;
       
   989 
       
   990 	test.Next(_L(" @SYMTestCaseID:PDS-LOGENG-UT-4040 Clear the \"Log + SimId\" test"));
       
   991 	ClearLogL(*client, KSimId);
       
   992 	theLog.Write(_L8("Clear the \"Log + SimId\" test OK\n"));
       
   993 
       
   994 	test.Next(_L(" @SYMTestCaseID:PDS-LOGENG-UT-4041 Clear \"Recent List + SimId\" test"));
       
   995 	ClearRecentListL(*client, KSimId);
       
   996 	theLog.Write(_L8("Clear \"Recent List + SimId\" test OK\n"));
       
   997 #endif
       
   998 	
       
   999 	//
       
  1000 	// View API tests below this
       
  1001 	//
       
  1002 	TestUtils::DeleteDatabaseL();
       
  1003 	
       
  1004 	// TestUtils::AddTestEventsL() -->  adds 8 events.
       
  1005 	// 2 are visible to clients with no capabilities
       
  1006 	// and 6 are of type KLogCallEventTypeUid, which is protected.
       
  1007 	TestUtils::AddViewTestEventsL();
       
  1008 	
       
  1009 	test.Next(_L("Event View with Filter list"));
       
  1010 	TestEventViewWithFilterL(*client);	
       
  1011 	theLog.Write(_L8("Event View with Filter list test OK\n"));
       
  1012 	
       
  1013 	test.Next(_L("Recent View"));
       
  1014 	TestRecentViewL(*client);
       
  1015 	theLog.Write(_L8("Recent View test OK\n"));
       
  1016 
       
  1017 	TestUtils::DeleteDatabaseL();	// ready for next test
       
  1018 
       
  1019 	test.End();
       
  1020 	CleanupStack::PopAndDestroy(); // client
       
  1021 	}