os/persistentdata/loggingservices/eventlogger/test/src/t_logapi2.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2009-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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // t_logapi2.cpp - LogEng API tests 
    15 // 
    16 //
    17 #include <s32file.h>
    18 #include <s32mem.h>
    19 #include <e32math.h>
    20 #include <bautils.h>
    21 #include <logview.h>
    22 #include "t_logutil2.h"
    23 #include "LogServSqlStrings.h"
    24 
    25 RTest TheTest(_L("t_logapi2"));
    26 
    27 _LIT(KTestRemoteParty1, "Remote Party");
    28 _LIT(KTestDirection1, "Direction");
    29 _LIT(KTestStatus1, "Status");
    30 _LIT(KTestSubject1, "Subject");
    31 const TUid KTestEventUid = {0x10005393};
    32 const TLogDurationType KTestDurationType1 = 1;
    33 const TLogDuration KTestDuration1 = 0x1234;
    34 const TLogContactItemId KTestContact1 = 0x1234;
    35 const TLogLink KTestLink1 = 0x1234;
    36 _LIT8(KTestData1, "ABCDEFGH");
    37 const TLogFlags KTestFlags1 = 0x5;
    38 _LIT(KEvNumber1, "11119999");
    39 _LIT(KEvNumber2, "22226666");
    40 const TLogDurationType KEvDurationType1 = 1;
    41 const TLogDurationType KEvDurationType2 = 2;
    42 const TLogContactItemId KEvContact1 = 1010;
    43 const TLogLink KEvLink1 = 2000;
    44 _LIT(KEvDesc1, "Event Type Description 1");
    45 
    46 #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM	
    47 const TSimId KEvSimId1 = 3000000910U;//Bigger than KMaxTInt, to check that SQL statement formatting works as expected
    48 const TSimId KEvSimId2 = 2911;
    49 #endif
    50 
    51 const TInt KDiffEvCount = 10;
    52 
    53 //KEvDirection2 used together with KEvTypeUid guarantees that the properties of the event being changed
    54 //match the conditions of one the LogEng server recent lists and thus the "recent list" related functionality 
    55 //on the server side will be used.
    56 _LIT(KEvDirection2, "Incoming");
    57 
    58 const TUid KEvTypeUid = {KLogCallEventType};
    59 const TUid KEvTypeUidLoggingDisabled = {0x447422};
    60 
    61 enum TLogAddEventOps {ELogOpAddEvent, ELogOpAddEventInvalidType, ELogOpAddEventLoggingDisabled};
    62 enum TLogGetEventOps {ELogOpGetEvent, ELogOpGetEventZeroId, ELogOpGetEventNotExists};
    63 
    64 TLogId TheEvId = -1;
    65 TInt TheAddedEventCount = -1;
    66 TInt TheMaxLogSize = -1;
    67 
    68 //The default max log size is 1000. But the test timeouts on hardware with max log size of 1000.
    69 const TInt KMaxLogSize = 200;
    70 const TInt KMaxRecentLogSize = 10; // Default recent log size is 20
    71 const TInt KMaxPlusEvCount = 100; //Added events count on top of the max log size
    72 
    73 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    74 
    75 //Add a new event type with "logging disabled"
    76 void DoAddEventTypeL(CLogClient& aClient, CTestActive& aActive)
    77 	{
    78 	CLogEventType* type = CLogEventType::NewL();
    79 	CleanupStack::PushL(type);
    80 
    81 	type->SetUid(KEvTypeUidLoggingDisabled);
    82 	type->SetDescription(_L("110111011011"));
    83 	type->SetLoggingEnabled(EFalse);
    84 
    85 	aClient.AddEventType(*type, aActive.iStatus);
    86 	aActive.StartL();
    87 	CActiveScheduler::Start();
    88 	TEST2(aActive.iStatus.Int(), KErrNone);
    89 
    90 	CleanupStack::PopAndDestroy(type);
    91 	}
    92 
    93 void DoSetNewMaxLogSizeL(CLogClient& aClient, CTestActive& aActive)
    94 	{
    95 	//Check what is the max log size.
    96 	TLogConfig config;
    97 	aActive.StartL();
    98 	aClient.GetConfig(config, aActive.iStatus);
    99 	CActiveScheduler::Start();
   100 	TEST2(aActive.iStatus.Int(), KErrNone);
   101 	//Set new max log size
   102 	config.iMaxLogSize = KMaxLogSize;
   103 	aActive.StartL();
   104 	aClient.ChangeConfig(config, aActive.iStatus);
   105 	CActiveScheduler::Start();
   106 	TEST2(aActive.iStatus.Int(), KErrNone);
   107 	//Test the new max log size
   108 	aActive.StartL();
   109 	aClient.GetConfig(config, aActive.iStatus);
   110 	CActiveScheduler::Start();
   111 	TEST2(aActive.iStatus.Int(), KErrNone);
   112 	TEST2(config.iMaxLogSize, KMaxLogSize);
   113 	//
   114 	TheMaxLogSize = config.iMaxLogSize;
   115 	TheAddedEventCount = config.iMaxLogSize + KMaxPlusEvCount;
   116 	}
   117 
   118 void DoAddEventsL()
   119 	{
   120 	CLogClient* client = CLogClient::NewL(theFs);
   121 	CleanupStack::PushL(client);
   122 	CTestActive* active = new(ELeave)CTestActive();
   123 	CleanupStack::PushL(active);
   124 	
   125 	//Set new max log size
   126 	DoSetNewMaxLogSizeL(*client, *active);
   127 
   128 	//Add TheAddedEventCount events. Some of them with SimId, some - not.
   129 	//This certainly will involve some log purging operations when the log size reaches the max.
   130 	CLogEvent* event = CLogEvent::NewL();
   131 	CleanupStack::PushL(event);
   132 	event->SetEventType(KLogCallEventTypeUid);
   133 	event->SetRemoteParty(KTestRemoteParty1);
   134 	event->SetDirection(KTestDirection1);
   135 	event->SetDurationType(KEvDurationType1);
   136 	event->SetDuration(KTestDuration1);
   137 	event->SetStatus(KTestStatus1);
   138 	event->SetSubject(KTestSubject1);
   139 	event->SetNumber(KEvNumber1);
   140 	event->SetContact(KEvContact1);
   141 	event->SetLink(KEvLink1);
   142 	event->SetDescription(KEvDesc1);
   143 	event->SetFlags(KTestFlags1);
   144 	event->SetDataL(KTestData1);
   145 	
   146 	TTime st_time;
   147 	st_time.UniversalTime();
   148 	
   149 	TheTest.Printf(_L("Added events:\n"));
   150 	TInt diffEvCount = KDiffEvCount;
   151 	for(TInt i=0;i<TheAddedEventCount;++i)
   152 		{
   153 #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM	
   154 		event->SetSimId(KLogNullSimId);
   155 #endif		
   156 		event->SetDurationType(KEvDurationType1);
   157 		event->SetNumber(KEvNumber1);
   158 		if((i %2) == 0)
   159 			{
   160 #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM	
   161 			event->SetSimId(KEvSimId1);
   162 #endif			
   163 			if((i > TheMaxLogSize / 2 + 1) && (i % 10) == 0 && --diffEvCount >= 0)
   164 				{//Add after the second half because when the log grows above the max log size, the first events will be deleted
   165 				event->SetDurationType(KEvDurationType2);
   166 				event->SetNumber(KEvNumber2);
   167 				}
   168 			}
   169 		active->StartL();
   170 		client->AddEvent(*event, active->iStatus);
   171 		CActiveScheduler::Start();
   172 		TEST(!active->IsActive());
   173 		TEST2(active->iStatus.Int(), KErrNone);
   174 		if((i % 50) == 0 && i > 0)
   175 			{
   176 			TheTest.Printf(_L("%d\r"), i);
   177 			}
   178 		}
   179 	TheTest.Printf(_L("%d\n"), TheAddedEventCount);
   180 	
   181 	TTime end_time;
   182 	end_time.UniversalTime();
   183 	
   184 	CleanupStack::PopAndDestroy(event);
   185 	
   186 	CleanupStack::PopAndDestroy(active);
   187 	CleanupStack::PopAndDestroy(client);
   188 	
   189 	TTimeIntervalMicroSeconds us = end_time.MicroSecondsFrom(st_time);
   190 	TheTest.Printf(_L("%d events added. Time: %ld milliseconds\n"), TheAddedEventCount, us.Int64() / 1000);
   191 	}
   192 
   193 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   194 
   195 /**
   196 @SYMTestCaseID			PDS-LOGENG-UT-4042
   197 @SYMTestCaseDesc		"Cancel operation" test.
   198 						The test uses RLogTestSession to establish a connection with the EventViewer server.
   199 						The the test initializes an "Add Event" opertaion.
   200 						But instead of completing the operation the test cancels it. 
   201 @SYMTestActions			"Cancel operation" test.
   202 @SYMTestExpectedResults Test must not fail
   203 @SYMTestPriority		Medium
   204 @SYMREQ					REQ12747
   205 */
   206 void CancelOperationTest()
   207 	{
   208 	RLogTestSession sess;
   209 	TInt err = sess.Connect();
   210 	TEST2(err, KErrNone);
   211 	
   212 	CLogEvent* event = NULL;
   213 	TRAP(err, event = CLogEvent::NewL());
   214 	TEST2(err, KErrNone);
   215 	event->SetEventType(KTestEventUid);
   216 	event->SetRemoteParty(KTestRemoteParty1);
   217 	event->SetDirection(KTestDirection1);
   218 	event->SetDurationType(KTestDurationType1);
   219 	event->SetDuration(KTestDuration1);
   220 	event->SetStatus(KTestStatus1);
   221 	event->SetSubject(KTestSubject1);
   222 	event->SetContact(KTestContact1);
   223 	event->SetLink(KTestLink1);
   224 	TRAP(err, event->SetDataL(KTestData1));
   225 	TEST2(err, KErrNone);
   226 	event->SetFlags(KTestFlags1);
   227 	
   228 	TBuf8<1024> buf;
   229 	RDesWriteStream strm(buf);
   230 	TRAP(err, event->ExternalizeL(strm));
   231 	TEST2(err, KErrNone);
   232 	TRAP(err, strm.CommitL());
   233 	TEST2(err, KErrNone);
   234 	
   235 	TPckgBuf<TLogClientServerData> data;
   236 	data().iOperationType = ELogOperationEventAdd;
   237 	data().iOperationId = KLogNullOperationId;
   238 	
   239 	TRequestStatus stat;
   240 	TIpcArgs args1(&data, &buf);
   241 	sess.Send(ELogOperationInitiate, args1, stat);
   242 	TEST2(stat.Int(), KRequestPending);
   243 	TIpcArgs args2(&data);
   244 	err = sess.Send(ELogOperationCancel, args2);
   245 	TEST2(err, KErrCancel);
   246 	User::WaitForRequest(stat);
   247 	err = stat.Int();
   248 	TEST2(err, KErrCancel);
   249 	
   250 	strm.Close();
   251 	delete event;
   252 	sess.Close();
   253 	}
   254 
   255 /**
   256 @SYMTestCaseID			PDS-LOGENG-UT-4029
   257 @SYMTestCaseDesc		AddEvent() server side OOM test.
   258 						This test uses the results from the previous test cases that
   259 						the LogEng database contains TheMaxLogSize events.
   260 						This ensures that the "purge main" functionality on the server side 
   261 						will be used.
   262 						The properties of the event being added are such (KEvDirection1 and KEvTypeUid) that 
   263 						one of the LogServ recent lists will be used. This ensures that the "purge recent"
   264 						LogEng server functionality will be used.
   265 						The test, as any other of the LogEng server OOM tests, does not fully cover the used on the
   266 						server side functions, because:
   267 						1) CLogAddEvent will set the iEventAdded flag right after adding the event to the database.
   268 						   After that, any OOM failure that occurs for example in "purge recent" related calls, will be
   269 						   ignored.
   270 						2) CLogEvent will use the CLogDuplicate active object for the "purge recent" action.
   271 						   When CLogDuplicate fails with KErrNoMemory in DoRunL(), the error is ignored and not reported
   272 						   back.
   273 @SYMTestActions			AddEvent() server side OOM test.
   274 @SYMTestExpectedResults Test must not fail
   275 @SYMTestPriority		Medium
   276 @SYMREQ					REQ12746
   277 */
   278 void AddEventOomTestL(TLogAddEventOps aLogAddEventOp, TInt aExpectedError)
   279 	{
   280 	CLogClient* client = CLogClient::NewL(theFs);
   281 	CleanupStack::PushL(client);
   282 	CTestActive* active = new(ELeave)CTestActive();
   283 	CleanupStack::PushL(active);
   284 	CLogEvent* event = CLogEvent::NewL();
   285 	CleanupStack::PushL(event);
   286 
   287 	if(aLogAddEventOp == ELogOpAddEventLoggingDisabled)
   288 		{
   289 		DoAddEventTypeL(*client, *active);
   290 		}
   291 	
   292 	TTime now;
   293 	now.UniversalTime();
   294 
   295 	TUid eventType = KEvTypeUid;
   296 	if(aLogAddEventOp == ELogOpAddEventInvalidType)
   297 		{
   298 		eventType = TUid::Uid(0x445972);
   299 		}
   300 	else if(aLogAddEventOp == ELogOpAddEventLoggingDisabled)
   301 		{
   302 		eventType = KEvTypeUidLoggingDisabled;
   303 		}
   304 
   305 	event->SetEventType(eventType);
   306 	event->SetRemoteParty(KTestRemoteParty1);
   307 	event->SetDirection(KTestDirection1);
   308 	event->SetDurationType(KEvDurationType1);
   309 	event->SetDuration(KTestDuration1);
   310 	event->SetStatus(KTestStatus1);
   311 	event->SetSubject(KTestSubject1);
   312 	event->SetNumber(KEvNumber1);
   313 	event->SetContact(KEvContact1);
   314 	event->SetLink(KEvLink1);
   315 	event->SetDescription(KEvDesc1);
   316 	event->SetFlags(KTestFlags1);
   317 	event->SetDataL(KTestData1);
   318 #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM	
   319 	event->SetSimId(KEvSimId1);
   320 #endif	
   321 	
   322 	TInt failCount = 0;
   323 	TBool finished = EFalse;
   324 
   325 	while(!finished)
   326 		{
   327 		__LOGSERV_UHEAP_FAILNEXT(++failCount);
   328 		client->AddEvent(*event, active->iStatus);
   329 		active->StartL();
   330 		CActiveScheduler::Start();
   331 
   332 		if(active->iStatus.Int() == aExpectedError)
   333 			{
   334 			finished = ETrue;
   335 			}
   336 		
   337 		__LOGSERV_UHEAP_RESET;
   338 
   339 		if(active->iStatus.Int() != aExpectedError)
   340 			{
   341 			TEST2(active->iStatus.Int(), KErrNoMemory);
   342 			}
   343 		}
   344 
   345 	TEST2(active->iStatus.Int(), aExpectedError);
   346 	if(aLogAddEventOp == ELogOpAddEvent)
   347 		{
   348 		TEST(event->Time() >= now);
   349 		active->StartL();
   350 		client->GetEvent(*event, active->iStatus);
   351 		CActiveScheduler::Start();
   352 		TEST2(active->iStatus.Int(), KErrNone);
   353 		TheEvId = event->Id();
   354 		TEST(TheEvId > 0);
   355 		}
   356 
   357 	CleanupStack::PopAndDestroy(event);
   358 	CleanupStack::PopAndDestroy(active);
   359 	CleanupStack::PopAndDestroy(client);
   360 	
   361 	TheTest.Printf(_L("===CLogClient::AddEvent() server side OOM test succeeded at iteration %d\n"), failCount);
   362 	}
   363 
   364 /**
   365 @SYMTestCaseID			PDS-LOGENG-UT-4030
   366 @SYMTestCaseDesc		ChangeEvent() server side OOM test.
   367 						This test uses the results from the previous test cases that
   368 						the LogEng database contains TheMaxLogSize events.
   369 						This ensures that the "purge main" functionality on the server side 
   370 						will be used.
   371 						The properties of the event being changed are such (KEvDirection2 and KEvTypeUid) that 
   372 						one of the LogServ recent lists will be used. This ensures that the "purge recent"
   373 						LogEng server functionality will be used.
   374 @SYMTestActions			ChangeEvent() server side OOM test.
   375 @SYMTestExpectedResults Test must not fail
   376 @SYMTestPriority		Medium
   377 @SYMREQ					REQ12746
   378 */
   379 void ChangeEventOomTestL(TBool aEventExists)
   380 	{
   381 	CLogClient* client = CLogClient::NewL(theFs);
   382 	CleanupStack::PushL(client);
   383 	CTestActive* active = new(ELeave)CTestActive();
   384 	CleanupStack::PushL(active);
   385 	CLogEvent* event = CLogEvent::NewL();
   386 	CleanupStack::PushL(event);
   387 	
   388 	event->SetId(TheEvId);
   389 	active->StartL();
   390 	client->GetEvent(*event, active->iStatus);
   391 	CActiveScheduler::Start();
   392 	TEST2(active->iStatus.Int(), KErrNone);
   393 	TEST2(TheEvId, event->Id());
   394 	event->SetDirection(KEvDirection2);
   395 #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM	
   396 	event->SetSimId(KEvSimId2);
   397 #endif	
   398 	
   399 	TInt failCount = 0;
   400 	TBool finished = EFalse;
   401 
   402 	if(!aEventExists)
   403 		{//Search for a non-existing event in the OOM loop
   404 		event->SetId(TheEvId + 5678);
   405 		}
   406 	
   407 	while(!finished)
   408 		{
   409 		__LOGSERV_UHEAP_FAILNEXT(++failCount);
   410 		client->ChangeEvent(*event, active->iStatus);
   411 		active->StartL();
   412 		CActiveScheduler::Start();
   413 
   414 		TInt err = active->iStatus.Int();
   415 		if(err == (aEventExists ? KErrNone : KErrNotFound))
   416 			{
   417 			finished = ETrue;
   418 			}
   419 		
   420 		__LOGSERV_UHEAP_RESET;
   421 
   422 		if(err != (aEventExists ? KErrNone : KErrNotFound))
   423 			{
   424 			TEST2(err, KErrNoMemory);
   425 			}
   426 		}
   427 
   428 	active->StartL();
   429 	client->GetEvent(*event, active->iStatus);
   430 	CActiveScheduler::Start();
   431 	if(aEventExists)
   432 		{
   433 		TEST2(active->iStatus.Int(), KErrNone);
   434 #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM	
   435 		TEST2(event->SimId(), KEvSimId2);
   436 #endif		
   437 		}
   438 	else
   439 		{
   440 		TEST2(active->iStatus.Int(), KErrNotFound);
   441 		}
   442 
   443 	CleanupStack::PopAndDestroy(event);
   444 	CleanupStack::PopAndDestroy(active);
   445 	CleanupStack::PopAndDestroy(client);
   446 	
   447 	TheTest.Printf(_L("===CLogClient::ChangeEvent() server side OOM test succeeded at iteration %d\n"), failCount);
   448 	}
   449 
   450 /**
   451 @SYMTestCaseID			PDS-LOGENG-UT-4031
   452 @SYMTestCaseDesc		DeleteEvent() server side OOM test.
   453 						This test uses the results from the previous test cases that
   454 						the LogEng database contains TheMaxLogSize events.
   455 						This ensures that the "purge main" functionality on the server side 
   456 						will be used.
   457 @SYMTestActions			DeleteEvent() server side OOM test.
   458 @SYMTestExpectedResults Test must not fail
   459 @SYMTestPriority		Medium
   460 @SYMREQ					REQ12746
   461 */
   462 void DeleteEventOomTestL(TBool aEventExists)
   463 	{
   464 	CLogClient* client = CLogClient::NewL(theFs);
   465 	CleanupStack::PushL(client);
   466 	CTestActive* active = new(ELeave)CTestActive();
   467 	CleanupStack::PushL(active);
   468 	
   469 	TInt failCount = 0;
   470 	TBool finished = EFalse;
   471 
   472 	while(!finished)
   473 		{
   474 		__LOGSERV_UHEAP_FAILNEXT(++failCount);
   475 		client->DeleteEvent(TheEvId, active->iStatus);
   476 		active->StartL();
   477 		CActiveScheduler::Start();
   478 
   479 		TInt err = active->iStatus.Int();
   480 		if(err == (aEventExists ? KErrNone : KErrNotFound))
   481 			{
   482 			finished = ETrue;
   483 			}
   484 		
   485 		__LOGSERV_UHEAP_RESET;
   486 
   487 		if(err != (aEventExists ? KErrNone : KErrNotFound))
   488 			{
   489 			TEST2(err, KErrNoMemory);
   490 			}
   491 		}
   492 
   493 	CLogEvent* event = CLogEvent::NewL();
   494 	CleanupStack::PushL(event);
   495 	event->SetId(TheEvId);
   496 	active->StartL();
   497 	client->GetEvent(*event, active->iStatus);
   498 	CActiveScheduler::Start();
   499 	TEST2(active->iStatus.Int(), KErrNotFound);
   500 	CleanupStack::PopAndDestroy(event);
   501 	
   502 	CleanupStack::PopAndDestroy(active);
   503 	CleanupStack::PopAndDestroy(client);
   504 	
   505 	TheTest.Printf(_L("===CLogClient::DeleteEvent() server side OOM test succeeded at iteration %d\n"), failCount);
   506 	}
   507 
   508 /**
   509 @SYMTestCaseID			PDS-LOGENG-UT-4032
   510 @SYMTestCaseDesc		GetEvent() server side OOM test.
   511 						This test uses the results from the previous test cases that
   512 						the LogEng database contains TheMaxLogSize events.
   513 						GetEvent() is executed in OOM loop.
   514 @SYMTestActions			GetEvent() server side OOM test.
   515 @SYMTestExpectedResults Test must not fail
   516 @SYMTestPriority		Medium
   517 @SYMREQ					REQ12746
   518 */
   519 void GetEventOomTestL(TLogGetEventOps aGetEventOp, TInt aExpectedError)
   520 	{
   521 	CLogClient* client = CLogClient::NewL(theFs);
   522 	CleanupStack::PushL(client);
   523 	CTestActive* active = new(ELeave)CTestActive();
   524 	CleanupStack::PushL(active);
   525 	CLogEvent* event = CLogEvent::NewL();
   526 	CleanupStack::PushL(event);
   527 	
   528 	event->SetId(aGetEventOp == ELogOpGetEvent ? TheEvId : (aGetEventOp == ELogOpGetEventNotExists ? 0x932271F : 0x0));
   529 	
   530 	TInt failCount = 0;
   531 	TBool finished = EFalse;
   532 
   533 	while(!finished)
   534 		{
   535 		__LOGSERV_UHEAP_FAILNEXT(++failCount);
   536 		client->GetEvent(*event, active->iStatus);
   537 		active->StartL();
   538 		CActiveScheduler::Start();
   539 
   540 		if(active->iStatus.Int() == aExpectedError)
   541 			{
   542 			finished = ETrue;
   543 			}
   544 		
   545 		__LOGSERV_UHEAP_RESET;
   546 
   547 		if(active->iStatus.Int() != aExpectedError)
   548 			{
   549 			TEST2(active->iStatus.Int(), KErrNoMemory);
   550 			}
   551 		}
   552 	
   553 	TEST2(active->iStatus.Int(), aExpectedError);
   554 #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM	
   555 	if(aGetEventOp == ELogOpGetEvent)
   556 		{
   557 		TEST2(event->SimId(), KEvSimId2);
   558 		}
   559 #endif
   560 	
   561 	CleanupStack::PopAndDestroy(event);
   562 	CleanupStack::PopAndDestroy(active);
   563 	CleanupStack::PopAndDestroy(client);
   564 	
   565 	TheTest.Printf(_L("===CLogClient::GetEvent() server side OOM test succeeded at iteration %d\n"), failCount);
   566 	}
   567 
   568 /**
   569 @SYMTestCaseID			PDS-LOGENG-UT-4033
   570 @SYMTestCaseDesc		Change Event Type test.
   571 						The test attempts to change the type of an existing event.
   572 						The attempt must fails with KErrPermissionDenied error. 
   573 @SYMTestActions			Change Event Type test.
   574 @SYMTestExpectedResults Test must not fail
   575 @SYMTestPriority		Medium
   576 @SYMREQ					REQ12746
   577 */
   578 void ChangeStandardEventTypeTestL()
   579 	{
   580 	CLogClient* client = CLogClient::NewL(theFs);
   581 	CleanupStack::PushL(client);
   582 	CTestActive* active = new(ELeave)CTestActive();
   583 	CleanupStack::PushL(active);
   584 	
   585 	CLogEventType* evType = CLogEventType::NewL(); 
   586 	CleanupStack::PushL(evType);
   587 	TUid uid = {KLogCallEventType};
   588 	evType->SetUid(uid);
   589 	evType->SetDescription(_L("aaaaaaaa"));
   590 
   591 	active->StartL();
   592 	client->ChangeEventType(*evType, active->iStatus);
   593 	CActiveScheduler::Start();
   594 	TEST2(active->iStatus.Int(), KErrPermissionDenied);
   595 	
   596 	CleanupStack::PopAndDestroy(evType);
   597 	
   598 	CleanupStack::PopAndDestroy(active);
   599 	CleanupStack::PopAndDestroy(client);
   600 	}
   601 
   602 CLogFilter* DoCreateFilter1LC()
   603 	{
   604 	CLogFilter* filter = CLogFilter::NewL();
   605 	CleanupStack::PushL(filter);
   606 	
   607 #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM	
   608 	filter->SetSimId(KEvSimId2);
   609 #endif	
   610 	filter->SetDurationType(KEvDurationType2);
   611 	filter->SetNumber(KEvNumber2);
   612 	filter->SetStatus(KTestStatus1);
   613 	filter->SetDirection(KTestDirection1);
   614 	
   615 	return filter;
   616 	}
   617 
   618 CLogFilter* DoCreateFilter2LC()
   619 	{
   620 	CLogFilter* filter = CLogFilter::NewL();
   621 	CleanupStack::PushL(filter);
   622 
   623 #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM	
   624 	filter->SetSimId(KEvSimId1);
   625 #endif	
   626 	filter->SetDurationType(KEvDurationType1);
   627 	filter->SetNumber(KEvNumber1);
   628 	filter->SetStatus(KTestStatus1);
   629 	filter->SetDirection(KTestDirection1);
   630 	filter->SetEventType(KEvTypeUid);
   631 	filter->SetRemoteParty(KTestRemoteParty1);
   632 	filter->SetNullFields(ELogFlagsField);
   633 
   634 	return filter;
   635 	}
   636 
   637 CLogFilter* DoCreateFilter3LC()
   638 	{
   639 	CLogFilter* filter = CLogFilter::NewL();
   640 	CleanupStack::PushL(filter);
   641 
   642 #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM	
   643 	filter->SetSimId(KEvSimId1);
   644 #endif	
   645 	filter->SetDurationType(KEvDurationType1);
   646 	filter->SetNumber(KEvNumber1);
   647 	filter->SetStatus(KTestStatus1);
   648 	filter->SetDirection(KTestDirection1);
   649 	filter->SetEventType(KEvTypeUid);
   650 	filter->SetRemoteParty(KTestRemoteParty1);
   651 	filter->SetContact(KEvContact1);
   652 	filter->SetNullFields(ELogFlagsField);
   653 
   654 	return filter;
   655 	}
   656 
   657 /**
   658 @SYMTestCaseID			PDS-LOGENG-UT-4034
   659 @SYMTestCaseDesc		Complex view filter set test.
   660 						The test creates a set of filters using all event properties and duplicating some of them
   661 						in the filters. Then sets the set of filters to a view and iterates over the view's events.
   662 						The idea is to test as much as possible the server side filter processing in TLogFilterExprBuilder
   663 						class implementation.
   664 @SYMTestActions			Complex view filter set test.
   665 @SYMTestExpectedResults Test must not fail
   666 @SYMTestPriority		Medium
   667 @SYMREQ					REQ12746
   668 */
   669 void ComplexFilterSetTestL()
   670 	{
   671 	CLogClient* client = CLogClient::NewL(theFs);
   672 	CleanupStack::PushL(client);
   673 	CTestActive* active = new(ELeave)CTestActive();
   674 	CleanupStack::PushL(active);
   675 	CLogViewEvent* view = CLogViewEvent::NewL(*client);
   676 	CleanupStack::PushL(view);
   677 	CLogFilter* filter1 = DoCreateFilter1LC();
   678 	CLogFilter* filter2 = DoCreateFilter2LC();
   679 	CLogFilter* filter3 = DoCreateFilter3LC();
   680 	CLogFilterList* filterList = new(ELeave)CLogFilterList;
   681 	CleanupStack::PushL(filterList);
   682 	filterList->AppendL(filter1);
   683 	filterList->AppendL(filter2);
   684 	filterList->AppendL(filter3);
   685 	
   686 	//Check the "copy filter list" operations
   687 	CLogFilterList* filterList2 = filterList->CopyL();
   688 	TEST2(filterList2->Count(), filterList->Count());
   689 	delete filterList2;
   690 	CLogFilterList* filterList3 = filterList->CopyLC();
   691 	TEST2(filterList3->Count(), filterList->Count());
   692 	CleanupStack::PopAndDestroy(filterList3);
   693 	
   694 	TTime st_time;
   695 	st_time.UniversalTime();
   696 	TBool res = view->SetFilterL(*filterList, active->iStatus);
   697 	TEST(res);
   698 	active->StartL();
   699 	CActiveScheduler::Start();
   700 	TEST2(active->iStatus.Int(), KErrNone);
   701 	TInt count = view->CountL();
   702 	TheTest.Printf(_L("===Events count: %d\n"), count);
   703 	TTime end_time;
   704 	end_time.UniversalTime();
   705 	TTimeIntervalMicroSeconds us = end_time.MicroSecondsFrom(st_time);
   706 	TheTest.Printf(_L("SetFilter(). Time: %ld milliseconds\n"), us.Int64() / 1000);
   707 
   708 	st_time.UniversalTime();
   709 	if(view->FirstL(active->iStatus))
   710 		{
   711 		count = 0; 
   712 		do
   713 			{
   714 			active->StartL();
   715 			CActiveScheduler::Start();
   716 			TEST2(active->iStatus.Int(), KErrNone);
   717 			++count;
   718 			}
   719 		while(view->NextL(active->iStatus));
   720 		}
   721 	end_time.UniversalTime();
   722 	us = end_time.MicroSecondsFrom(st_time);
   723 	TheTest.Printf(_L("Event view walk completed. Events count: %d. Time: %ld milliseconds\n"), count, us.Int64() / 1000);
   724 		
   725 	CleanupStack::PopAndDestroy(filterList);
   726 	CleanupStack::PopAndDestroy(filter3);
   727 	CleanupStack::PopAndDestroy(filter2);
   728 	CleanupStack::PopAndDestroy(filter1);
   729 	CleanupStack::PopAndDestroy(view);
   730 	CleanupStack::PopAndDestroy(active);
   731 	CleanupStack::PopAndDestroy(client);
   732 	}
   733 
   734 #ifdef _DEBUG
   735 static void StopLogServerL()
   736     {
   737     static RLogTestSession logServSession;
   738     //this function doesn't have any effect on UREL builds as LogEng server doesn't 
   739     //support the transient mode in UREL builds 
   740     //Used for LogEng server side heap failure testing.
   741     TInt error = KErrNone;
   742       
   743     if(!logServSession.Handle())
   744         {
   745         error = logServSession.Connect();
   746         }
   747       
   748     // Is the server running?
   749     if(error == KErrNotFound)
   750         {
   751         return;
   752         }
   753     LEAVE_IF_ERROR(error);
   754       
   755     // Make the server transient
   756     TInt p0 = 1;
   757     TIpcArgs  ipcArgs(p0);
   758     LEAVE_IF_ERROR(logServSession.Send(ELogMakeTransient, ipcArgs));
   759       
   760     logServSession.Close();
   761       
   762     User::After(6 * 1000000); // Enough time for the server to exit
   763     }
   764 #else//_DEBUG
   765 static void StopLogServerL()
   766     {
   767     TheTest.Printf(_L("StopLogServerL(): the LogEng server cannot be stopped in release mode. ELogMakeTransient is a debug message.\n"));
   768     }
   769 #endif//_DEBUG
   770 
   771 /**
   772 @SYMTestCaseID          PDS-LOGENG-UT-4047
   773 @SYMTestCaseDesc        Configuration value update test.
   774                         The test changes the configuration values & thne stops the log server. Start the 
   775                         server again & check if the configuration values are updated. 
   776                         Again restores the original value back. 
   777 @SYMTestActions         Configuration value update test.
   778 @SYMTestExpectedResults Test must not fail
   779 @SYMTestPriority        Medium
   780 @SYMREQ                 DEF142142
   781 */
   782 void DoCheckUpdateConfigL()
   783     {
   784  
   785     CLogClient* client = CLogClient::NewL(theFs);
   786     CleanupStack::PushL(client);
   787     CTestActive* active = new(ELeave)CTestActive();
   788     CleanupStack::PushL(active);
   789 
   790     //Check for updated configurations.
   791     TLogConfig config;
   792     active->StartL();
   793     client->GetConfig(config, active->iStatus);
   794     CActiveScheduler::Start();
   795     TEST2(active->iStatus.Int(), KErrNone);
   796     
   797     //Set new max log size
   798     TLogSize tmpMaxLogSize = config.iMaxLogSize;
   799     config.iMaxLogSize = KMaxLogSize;
   800     config.iMaxRecentLogSize = KMaxRecentLogSize;
   801     active->StartL();
   802     client->ChangeConfig(config, active->iStatus);
   803     CActiveScheduler::Start();
   804     TEST2(active->iStatus.Int(), KErrNone);
   805     
   806     //Stop the Server
   807     StopLogServerL();
   808     
   809     //Test the new max log size
   810     active->StartL();
   811     client->GetConfig(config, active->iStatus);
   812     CActiveScheduler::Start();
   813     TEST2(active->iStatus.Int(), KErrNone);
   814     TEST2(config.iMaxLogSize, KMaxLogSize);
   815     
   816     //Set original max log size
   817     config.iMaxLogSize = tmpMaxLogSize;
   818     active->StartL();
   819     client->ChangeConfig(config, active->iStatus);
   820     CActiveScheduler::Start();
   821     TEST2(active->iStatus.Int(), KErrNone);
   822     
   823     CleanupStack::PopAndDestroy(active);
   824     CleanupStack::PopAndDestroy(client);
   825     }
   826 
   827 //////////////////////////////////////////////////////////////////////////////////////////////////////
   828 #ifdef SYSLIBS_TEST
   829 
   830 TLogId DoAddEvent2TestRecentListL(CLogClient& aClient, CTestActive& aActive)
   831 	{
   832 	CLogEvent* event = CLogEvent::NewL();
   833 	CleanupStack::PushL(event);
   834 	
   835 	event->SetEventType(KLogCallEventTypeUid);
   836 	event->SetRemoteParty(KLogRctTListRemoteParty);
   837 	event->SetDirection(KLogRctTListDirection);
   838 	event->SetDurationType(KLogRctTListDurationType);
   839 	event->SetDuration(KTestDuration1);
   840 	event->SetStatus(KLogRctTListStatus);
   841 	event->SetSubject(KTestSubject1);
   842 	event->SetNumber(KLogRctTListNumber);
   843 	event->SetContact(KEvContact1);
   844 	event->SetLink(KEvLink1);
   845 	event->SetDescription(KEvDesc1);
   846 	event->SetFlags(KLogRctTListFlags);
   847 	event->SetDataL(KTestData1);
   848 #ifdef SYMBIAN_ENABLE_EVENTLOGGER_DUALSIM	
   849 	event->SetSimId(KLogRctTListSimId);
   850 #endif	
   851 	
   852 	aActive.StartL();
   853 	aClient.AddEvent(*event, aActive.iStatus);
   854 	CActiveScheduler::Start();
   855 	TEST(!aActive.IsActive());
   856 	TEST2(aActive.iStatus.Int(), KErrNone);
   857 	TLogId logId = event->Id();
   858 	
   859 	//Get the just added event
   860 	aActive.StartL();
   861 	aClient.GetEvent(*event, aActive.iStatus);
   862 	CActiveScheduler::Start();
   863 	TEST2(aActive.iStatus.Int(), KErrNone);
   864 	
   865 	CleanupStack::PopAndDestroy(event);
   866 	
   867 	return logId;
   868 	}
   869 
   870 TLogId DoAddEvent2TestRecentListL()
   871 	{
   872 	CLogClient* client = CLogClient::NewL(theFs);
   873 	CleanupStack::PushL(client);
   874 	CTestActive* active = new(ELeave)CTestActive();
   875 	CleanupStack::PushL(active);
   876 
   877 	TLogId logId = DoAddEvent2TestRecentListL(*client, *active);
   878 
   879 	CleanupStack::PopAndDestroy(active);
   880 	CleanupStack::PopAndDestroy(client);
   881 	
   882 	return logId;
   883 	}
   884 
   885 struct TLogViewTestObserver : public MLogViewChangeObserver
   886 	{
   887 	TLogViewTestObserver() : 
   888 		iIdAdded(-1),
   889 		iIdChanged(-1),
   890 		iIdDeleted(-1)
   891 		{
   892 		}
   893 	virtual void HandleLogViewChangeEventAddedL(TLogId aId, TInt, TInt, TInt)
   894 		{
   895 		iIdAdded = aId;
   896 		}
   897 	virtual void HandleLogViewChangeEventChangedL(TLogId aId, TInt, TInt, TInt)
   898 		{
   899 		iIdChanged = aId;
   900 		}
   901 	virtual void HandleLogViewChangeEventDeletedL(TLogId aId, TInt, TInt, TInt)
   902 		{
   903 		iIdDeleted = aId;
   904 		}
   905 	TLogId iIdAdded;
   906 	TLogId iIdChanged;
   907 	TLogId iIdDeleted;
   908 	};
   909 	
   910 void DoViewEventFromTestRecentListL(TLogId aId1, TLogId aId2)
   911 	{
   912 	CLogClient* client = CLogClient::NewL(theFs);
   913 	CleanupStack::PushL(client);
   914 	CTestActive* active = new(ELeave)CTestActive();
   915 	CleanupStack::PushL(active);
   916 	CLogViewRecent* view = CLogViewRecent::NewL(*client);
   917 	CleanupStack::PushL(view);
   918 	TLogViewTestObserver observer;
   919 	CLogViewDuplicate* duplicate = CLogViewDuplicate::NewL(*client, observer);
   920 	CleanupStack::PushL(duplicate);
   921 	
   922 	TBool rc = view->SetRecentListL(KLogRctTListId, active->iStatus);
   923 	active->StartL();
   924 	CActiveScheduler::Start();
   925 	TEST2(active->iStatus.Int(), KErrNone);
   926 	
   927 	TInt count = 0; 
   928 	if(view->FirstL(active->iStatus))
   929 		{
   930 		do
   931 			{
   932 			active->StartL();
   933 			CActiveScheduler::Start();
   934 			TEST2(active->iStatus.Int(), KErrNone);
   935 			const CLogEvent& e = view->Event();
   936 			TEST2(aId2, e.Id());
   937 			++count;
   938 			}
   939 		while(view->NextL(active->iStatus));
   940 		}
   941 	TEST2(count, 1);//The second event is a duplicate => not in the list
   942 		
   943 	//Check duplicates 
   944 	active->StartL();
   945 	rc = view->DuplicatesL(*duplicate, active->iStatus);
   946 	TEST(rc);
   947 	CActiveScheduler::Start();
   948 	TEST2(active->iStatus.Int(), KErrNone);
   949 	TEST2(duplicate->CountL(), 1);
   950 	
   951 	//Test the duplicated event
   952 	rc = duplicate->FirstL(active->iStatus);
   953 	TEST(rc);
   954 	active->StartL();
   955 	CActiveScheduler::Start();
   956 	TEST2(active->iStatus.Int(), KErrNone);
   957 	const CLogEvent& e2 = duplicate->Event();
   958 	TEST2(aId1, e2.Id());
   959 
   960 	//Get the event
   961 	CLogEvent* event = CLogEvent::NewL();
   962 	CleanupStack::PushL(event);
   963 	event->SetId(aId1);
   964 	active->StartL();
   965 	client->GetEvent(*event, active->iStatus);
   966 	CActiveScheduler::Start();
   967 	TEST2(active->iStatus.Int(), KErrNone);
   968 	
   969 	//Change the event. The observer should register the change. 
   970 	event->SetDataL(_L8("123444555"));
   971 	client->ChangeEvent(*event, active->iStatus);
   972 	active->StartL();
   973 	CActiveScheduler::Start();
   974 	TEST2(active->iStatus.Int(), KErrNone);
   975 	TEST2(observer.iIdChanged, event->Id());
   976 
   977 	//Add  a new event to the recent list. This operation should be detected as a "delete" one by the observer 
   978 	//and the existing event should be cleared from the recent list.
   979 	TLogId logId = DoAddEvent2TestRecentListL(*client, *active);
   980 	TEST2(observer.iIdDeleted, aId1);
   981 	TEST(logId != observer.iIdDeleted);
   982 	//No added events detected by the observer
   983 	TEST2(observer.iIdAdded, -1);
   984 	
   985 	//Cleanup
   986 	CleanupStack::PopAndDestroy(event);
   987 	CleanupStack::PopAndDestroy(duplicate);
   988 	CleanupStack::PopAndDestroy(view);
   989 	CleanupStack::PopAndDestroy(active);
   990 	CleanupStack::PopAndDestroy(client);
   991 	}
   992 
   993 /**
   994 @SYMTestCaseID			PDS-LOGENG-UT-4035
   995 @SYMTestCaseDesc		Complex recent list test.
   996 						The test works only if SYSLIBS_TEST macro is defined, in which case the server side will
   997 						create a recent list with a lot of fields.
   998 						The test case will add 2 events with the same properties, such that both will be added
   999 						to that test recent list. Because the second event is a match of the first one and matches 
  1000 						the recent list "duplicates" mask, the second event will be marked as a duplicate of the
  1001 						first one. After adding the events a view is used to check for their presence.
  1002 @SYMTestActions			Complex recent list test.
  1003 @SYMTestExpectedResults Test must not fail
  1004 @SYMTestPriority		Medium
  1005 @SYMREQ					REQ12747
  1006 */
  1007 void ComplexRecentListTestL()
  1008 	{
  1009 	TLogId logId1 = DoAddEvent2TestRecentListL();
  1010 	TLogId logId2 = DoAddEvent2TestRecentListL();
  1011 	DoViewEventFromTestRecentListL(logId1, logId2);
  1012 	}
  1013 
  1014 #endif//SYSLIBS_TEST
  1015 //////////////////////////////////////////////////////////////////////////////////////////////////////
  1016 
  1017 void doTestsL()
  1018 	{
  1019     TestUtils::Initialize(_L("t_logapi2"));
  1020 	TestUtils::DeleteDatabaseL();
  1021 	//
  1022 	TheTest.Start(_L("Preparation. Adding 200 events..."));
  1023 	DoAddEventsL();
  1024 	TheTest.Next(_L(" @SYMTestCaseID:PDS-LOGENG-UT-4029: AddEvent() server side OOM test when logged events count is max (200)"));
  1025 	AddEventOomTestL(ELogOpAddEvent, KErrNone);
  1026 	TheTest.Next(_L(" @SYMTestCaseID:PDS-LOGENG-UT-4029: AddEvent() server side OOM test when logged events count is max (200). Invalid event type."));
  1027 	AddEventOomTestL(ELogOpAddEventInvalidType, KErrNotFound);
  1028 	TheTest.Next(_L(" @SYMTestCaseID:PDS-LOGENG-UT-4030: AddEvent() server side OOM test when logged events count is max (200). Logging disabled."));
  1029 	AddEventOomTestL(ELogOpAddEventLoggingDisabled, KErrNotSupported);
  1030 	TheTest.Next(_L(" @SYMTestCaseID:PDS-LOGENG-UT-4030: ChangeEvent() server side OOM test when logged events count is max (200). The event does exist."));
  1031 	ChangeEventOomTestL(ETrue);
  1032 	TheTest.Next(_L(" @SYMTestCaseID:PDS-LOGENG-UT-4030: ChangeEvent() server side OOM test when logged events count is max (200). The event does not exist."));
  1033 	ChangeEventOomTestL(EFalse);
  1034 	TheTest.Next(_L(" @SYMTestCaseID:PDS-LOGENG-UT-4032: GetEvent() server side OOM test when logged events count is max (200)."));
  1035 	GetEventOomTestL(ELogOpGetEvent, KErrNone);
  1036 	TheTest.Next(_L(" @SYMTestCaseID:PDS-LOGENG-UT-4032: GetEvent() server side OOM test when logged events count is max (200). The event does not exist."));
  1037 	GetEventOomTestL(ELogOpGetEventNotExists, KErrNotFound);
  1038 	TheTest.Next(_L(" @SYMTestCaseID:PDS-LOGENG-UT-4032: GetEvent() server side OOM test when logged events count is max (200). The event id is 0."));
  1039 	GetEventOomTestL(ELogOpGetEventZeroId, KErrNotFound);
  1040 	TheTest.Next(_L(" @SYMTestCaseID:PDS-LOGENG-UT-4031: DeleteEvent() server side OOM test when logged events count is max (200). The event does exist."));
  1041 	DeleteEventOomTestL(ETrue);
  1042 	TheTest.Next(_L(" @SYMTestCaseID:PDS-LOGENG-UT-4031: DeleteEvent() server side OOM test when logged events count is max (200). The event does not exist."));
  1043 	DeleteEventOomTestL(EFalse);
  1044 	TheTest.Next(_L(" @SYMTestCaseID:PDS-LOGENG-UT-4033: Attempt to change one of the standard event types."));
  1045 	ChangeStandardEventTypeTestL();
  1046 	TheTest.Next(_L(" @SYMTestCaseID:PDS-LOGENG-UT-4042: \"Cancel Operation\" test"));
  1047 	CancelOperationTest();
  1048 	TheTest.Next(_L(" @SYMTestCaseID:PDS-LOGENG-UT-4034: Complex filter set test."));
  1049 	ComplexFilterSetTestL();
  1050 	TheTest.Next(_L(" @SYMTestCaseID:PDS-LOGENG-UT-4047: Check for updated configuration values"));
  1051 	DoCheckUpdateConfigL();
  1052 #ifdef SYSLIBS_TEST
  1053 	TheTest.Next(_L(" @SYMTestCaseID:PDS-LOGENG-UT-4035: Complex recent list test."));
  1054 	ComplexRecentListTestL();
  1055 #endif
  1056 	//
  1057 	TestUtils::DeleteDatabaseL();
  1058 	}