os/persistentdata/loggingservices/eventlogger/test/src/t_logevent.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2002-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 //
    15 
    16 #include <s32file.h>
    17 #include "t_logutil2.h"
    18 #include <s32mem.h>
    19 
    20 RTest TheTest(_L("t_logevent"));
    21 
    22 TBool CompareEvents(const CLogEvent& aLeft, const CLogEvent& aRight)
    23 	{
    24 	TBool ret = aLeft.Data() == aRight.Data();
    25 	ret = ret && aLeft.Description() == aRight.Description();
    26 	ret = ret && aLeft.Direction() == aRight.Direction();
    27 	ret = ret && aLeft.Duration() == aRight.Duration();
    28 	ret = ret && aLeft.DurationType() == aRight.DurationType();
    29 	ret = ret && aLeft.EventType() == aRight.EventType();
    30 	ret = ret && aLeft.Flags() == aRight.Flags();
    31 	ret = ret && aLeft.Id() == aRight.Id();
    32 	ret = ret && aLeft.Link() == aRight.Link();
    33 	ret = ret && aLeft.Number() == aRight.Number();
    34 	ret = ret && aLeft.RemoteParty() == aRight.RemoteParty();
    35 	ret = ret && aLeft.Status() == aRight.Status();
    36 	ret = ret && aLeft.Subject() == aRight.Subject();
    37 	ret = ret && aLeft.Time() == aRight.Time();
    38 	return ret;
    39 	}
    40 
    41 void TestStoreL(const CLogEvent& aEvent)
    42 	{
    43 //	const TInt size = aEvent.Size();
    44 
    45 	//Store
    46 	CBufFlat* buf = CBufFlat::NewL(0x100);
    47 	CleanupStack::PushL(buf);
    48 	RBufWriteStream write(*buf);
    49 	write << aEvent;
    50 	write.CommitL();
    51 
    52 	//Restore
    53 	CLogEvent* event = CLogEvent::NewL();
    54 	CleanupStack::PushL(event);
    55 	RBufReadStream read(*buf);
    56 	read >> *event;
    57 
    58 	TBool ret = CompareEvents(aEvent, *event);
    59 	TEST(ret);
    60 
    61 	CleanupStack::PopAndDestroy(2);
    62 	}
    63 
    64 /**
    65 @SYMTestCaseID          SYSLIB-LOGENG-CT-1008
    66 @SYMTestCaseDesc	    Tests for writing different events to a store
    67 @SYMTestPriority 	    High
    68 @SYMTestActions  	    Calls up TestStoreL() function
    69 @SYMTestExpectedResults Test must not fail
    70 @SYMREQ                 REQ0000
    71 */
    72 LOCAL_C void TestEventL()
    73 	{
    74 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-1008 "));
    75 	CLogEvent* event1 = CLogEvent::NewL();
    76 	CleanupStack::PushL(event1);
    77 
    78 	// Event Id
    79 	TEST(event1->Id() == KLogNullId);
    80 	TestStoreL(*event1);
    81 
    82 	event1->SetId(0x12345678);
    83 	TEST(event1->Id() == 0x12345678);
    84 	TestStoreL(*event1);
    85 
    86 	event1->SetId(KMaxTInt32);
    87 	TEST(event1->Id() == KMaxTInt32);
    88 	TestStoreL(*event1);
    89 
    90 	event1->SetId(0);
    91 	TEST(event1->Id() == 0);
    92 	TestStoreL(*event1);
    93 
    94 	// Event type
    95 	event1->SetEventType(TUid::Null());
    96 	TestStoreL(*event1);
    97 
    98 	event1->SetEventType(TUid::Uid(0x12345678));
    99 	TEST(event1->EventType() == TUid::Uid(0x12345678));
   100 	TestStoreL(*event1);
   101 
   102 	event1->SetEventType(TUid::Uid(KMaxTInt32));
   103 	TEST(event1->EventType() == TUid::Uid(KMaxTInt32));
   104 	TestStoreL(*event1);
   105 
   106 	event1->SetEventType(TUid::Null());
   107 	TEST(event1->EventType() == TUid::Null());
   108 	TestStoreL(*event1);
   109 
   110 	// Remote Party
   111 	TEST(event1->RemoteParty() == KNullDesC);
   112 	TestStoreL(*event1);
   113 
   114 	HBufC* buf = TestUtils::CreateBufLC(KLogMaxRemotePartyLength / 2);
   115 	event1->SetRemoteParty(buf->Des());
   116 	TEST(event1->RemoteParty() == buf->Des());
   117 	CleanupStack::PopAndDestroy(); // buf
   118 	TestStoreL(*event1);
   119 
   120 	buf = TestUtils::CreateBufLC(KLogMaxRemotePartyLength);
   121 	event1->SetRemoteParty(buf->Des());
   122 	TEST(event1->RemoteParty() == buf->Des());
   123 	CleanupStack::PopAndDestroy(); // buf
   124 	TestStoreL(*event1);
   125 
   126 	buf = TestUtils::CreateBufLC(KLogMaxRemotePartyLength * 2);
   127 	event1->SetRemoteParty(buf->Des());
   128 	TEST(event1->RemoteParty() == buf->Des().Left(KLogMaxRemotePartyLength));
   129 	CleanupStack::PopAndDestroy(); // buf
   130 	TestStoreL(*event1);
   131 
   132 	event1->SetRemoteParty(KNullDesC);
   133 	TEST(event1->RemoteParty() == KNullDesC);
   134 	TestStoreL(*event1);
   135 
   136 	// Direction
   137 	TEST(event1->Direction() == KNullDesC);
   138 	TestStoreL(*event1);
   139 
   140 	buf = TestUtils::CreateBufLC(KLogMaxDirectionLength / 2);
   141 	event1->SetDirection(buf->Des());
   142 	TEST(event1->Direction() == buf->Des());
   143 	CleanupStack::PopAndDestroy(); // buf
   144 	TestStoreL(*event1);
   145 
   146 	buf = TestUtils::CreateBufLC(KLogMaxDirectionLength);
   147 	event1->SetDirection(buf->Des());
   148 	TEST(event1->Direction() == buf->Des());
   149 	CleanupStack::PopAndDestroy(); // buf
   150 	TestStoreL(*event1);
   151 
   152 	buf = TestUtils::CreateBufLC(KLogMaxDirectionLength * 2);
   153 	event1->SetDirection(buf->Des());
   154 	TEST(event1->Direction() == buf->Des().Left(KLogMaxDirectionLength));
   155 	CleanupStack::PopAndDestroy(); // buf
   156 	TestStoreL(*event1);
   157 
   158 	event1->SetDirection(KNullDesC);
   159 	TEST(event1->Direction() == KNullDesC);
   160 	TestStoreL(*event1);
   161 
   162 	// Time
   163 	TTime time;
   164 
   165 	time.UniversalTime();
   166 	event1->SetTime(time);
   167 	TEST(event1->Time() == time);
   168 	TestStoreL(*event1);
   169 
   170 	time.HomeTime();
   171 	event1->SetTime(time);
   172 	TEST(event1->Time() == time);
   173 	TestStoreL(*event1);
   174 
   175 	// Duration Type
   176 	TEST(event1->DurationType() == KLogNullDurationType);
   177 
   178 	event1->SetDurationType(0xf);
   179 	TEST(event1->DurationType() == 0xf);
   180 	TestStoreL(*event1);
   181 
   182 	event1->SetDurationType(KMaxTInt8);
   183 	TEST(event1->DurationType() == KMaxTInt8);
   184 	TestStoreL(*event1);
   185 
   186 	event1->SetDurationType(KLogNullDurationType);
   187 	TEST(event1->DurationType() == KLogNullDurationType);
   188 	TestStoreL(*event1);
   189 
   190 	// Duration
   191 	TEST(event1->Duration() == KLogNullDuration);
   192 
   193 	event1->SetDuration(0x12345678);
   194 	TEST(event1->Duration() == 0x12345678);
   195 	TestStoreL(*event1);
   196 
   197 	event1->SetDuration(KMaxTUint32);
   198 	TEST(event1->Duration() == KMaxTUint32);
   199 	TestStoreL(*event1);
   200 
   201 	event1->SetDuration(KLogNullDuration);
   202 	TEST(event1->Duration() == KLogNullDuration);
   203 	TestStoreL(*event1);
   204 
   205 	// Status
   206 	TEST(event1->Status() == KNullDesC);
   207 
   208 	buf = TestUtils::CreateBufLC(KLogMaxStatusLength / 2);
   209 	event1->SetStatus(buf->Des());
   210 	TEST(event1->Status() == buf->Des());
   211 	CleanupStack::PopAndDestroy(); // buf
   212 	TestStoreL(*event1);
   213 
   214 	buf = TestUtils::CreateBufLC(KLogMaxStatusLength);
   215 	event1->SetStatus(buf->Des());
   216 	TEST(event1->Status() == buf->Des());
   217 	CleanupStack::PopAndDestroy(); // buf
   218 	TestStoreL(*event1);
   219 
   220 	buf = TestUtils::CreateBufLC(KLogMaxStatusLength * 2);
   221 	event1->SetStatus(buf->Des());
   222 	TEST(event1->Status() == buf->Des().Left(KLogMaxStatusLength));
   223 	CleanupStack::PopAndDestroy(); // buf
   224 	TestStoreL(*event1);
   225 
   226 	event1->SetStatus(KNullDesC);
   227 	TEST(event1->Status() == KNullDesC);
   228 	TestStoreL(*event1);
   229 
   230 	// Subject
   231 	TEST(event1->Subject() == KNullDesC);
   232 
   233 	buf = TestUtils::CreateBufLC(KLogMaxSubjectLength / 2);
   234 	event1->SetSubject(buf->Des());
   235 	TEST(event1->Subject() == buf->Des());
   236 	CleanupStack::PopAndDestroy(); // buf
   237 	TestStoreL(*event1);
   238 
   239 	buf = TestUtils::CreateBufLC(KLogMaxSubjectLength);
   240 	event1->SetSubject(buf->Des());
   241 	TEST(event1->Subject() == buf->Des());
   242 	CleanupStack::PopAndDestroy(); // buf
   243 	TestStoreL(*event1);
   244 
   245 	buf = TestUtils::CreateBufLC(KLogMaxSubjectLength * 2);
   246 	event1->SetSubject(buf->Des());
   247 	TEST(event1->Subject() == buf->Des().Left(KLogMaxSubjectLength));
   248 	CleanupStack::PopAndDestroy(); // buf
   249 	TestStoreL(*event1);
   250 
   251 	event1->SetSubject(KNullDesC);
   252 	TEST(event1->Subject() == KNullDesC);
   253 	TestStoreL(*event1);
   254 
   255 	// Number
   256 	TEST(event1->Number() == KNullDesC);
   257 
   258 	buf = TestUtils::CreateBufLC(KLogMaxNumberLength / 2);
   259 	event1->SetNumber(buf->Des());
   260 	TEST(event1->Number() == buf->Des());
   261 	CleanupStack::PopAndDestroy(); // buf
   262 	TestStoreL(*event1);
   263 
   264 	buf = TestUtils::CreateBufLC(KLogMaxNumberLength);
   265 	event1->SetNumber(buf->Des());
   266 	TEST(event1->Number() == buf->Des());
   267 	CleanupStack::PopAndDestroy(); // buf
   268 	TestStoreL(*event1);
   269 
   270 	buf = TestUtils::CreateBufLC(KLogMaxNumberLength * 2);
   271 	event1->SetNumber(buf->Des());
   272 	TEST(event1->Number() == buf->Des().Left(KLogMaxNumberLength));
   273 	CleanupStack::PopAndDestroy(); // buf
   274 	TestStoreL(*event1);
   275 
   276 	event1->SetNumber(KNullDesC);
   277 	TEST(event1->Number() == KNullDesC);
   278 	TestStoreL(*event1);
   279 
   280 	// Contact
   281 	TEST(event1->Contact() == KLogNullContactId);
   282 
   283 	event1->SetContact(0x12345678);
   284 	TEST(event1->Contact() == 0x12345678);
   285 	TestStoreL(*event1);
   286 
   287 	event1->SetContact(KMaxTInt32);
   288 	TEST(event1->Contact() == KMaxTInt32);
   289 	TestStoreL(*event1);
   290 
   291 	event1->SetContact(KLogNullContactId);
   292 	TEST(event1->Contact() == KLogNullContactId);
   293 	TestStoreL(*event1);
   294 
   295 	event1->SetContact(KMinTInt32);
   296 	TEST(event1->Contact() == KMinTInt32);
   297 	TestStoreL(*event1);
   298 
   299 	// Link
   300 	TEST(event1->Link() == KLogNullLink);
   301 
   302 	event1->SetLink(0x12345678);
   303 	TEST(event1->Link() == 0x12345678);
   304 	TestStoreL(*event1);
   305 
   306 	event1->SetLink(KMaxTUint32);
   307 	TEST(event1->Link() == KMaxTUint32);
   308 	TestStoreL(*event1);
   309 
   310 	event1->SetLink(KLogNullLink);
   311 	TEST(event1->Link() == KLogNullLink);
   312 
   313 	// Description
   314 	TEST(event1->Description() == KNullDesC);
   315 
   316 	buf = TestUtils::CreateBufLC(KLogMaxDescriptionLength / 2);
   317 	event1->SetDescription(buf->Des());
   318 	TEST(event1->Description() == buf->Des());
   319 	CleanupStack::PopAndDestroy(); // buf
   320 	TestStoreL(*event1);
   321 
   322 	buf = TestUtils::CreateBufLC(KLogMaxDescriptionLength);
   323 	event1->SetDescription(buf->Des());
   324 	TEST(event1->Description() == buf->Des());
   325 	CleanupStack::PopAndDestroy(); // buf
   326 	TestStoreL(*event1);
   327 
   328 	buf = TestUtils::CreateBufLC(KLogMaxDescriptionLength * 2);
   329 	event1->SetDescription(buf->Des());
   330 	TEST(event1->Description() == buf->Des().Left(KLogMaxDescriptionLength));
   331 	CleanupStack::PopAndDestroy(); // buf
   332 	TestStoreL(*event1);
   333 
   334 	event1->SetDescription(KNullDesC);
   335 	TEST(event1->Description() == KNullDesC);
   336 
   337 	// Flags
   338 	TEST(event1->Flags() == KLogNullFlags);
   339 	event1->SetFlags(1);
   340 	TEST(event1->Flags() == 1);
   341 	TestStoreL(*event1);
   342 	event1->SetFlags(2);
   343 	TEST(event1->Flags() == 3);
   344 	event1->SetFlags(4);
   345 	TEST(event1->Flags() == 7);
   346 	event1->SetFlags(8);
   347 	TEST(event1->Flags() == KLogFlagsMask);
   348 	event1->ClearFlags(8);
   349 	TEST(event1->Flags() == 7);
   350 	event1->ClearFlags(4);
   351 	TEST(event1->Flags() == 3);
   352 	event1->ClearFlags(2);
   353 	TEST(event1->Flags() == 1);
   354 	event1->ClearFlags(1);
   355 	TEST(event1->Flags() == KLogNullFlags);
   356 
   357 	event1->SetFlags(1);
   358 	TEST(event1->Flags() == 1);
   359 	event1->SetFlags(3);
   360 	TEST(event1->Flags() == 3);
   361 	event1->SetFlags(7);
   362 	TEST(event1->Flags() == 7);
   363 	event1->SetFlags(15);
   364 	event1->SetFlags(KLogFlagsMask);
   365 	TEST(event1->Flags() == KLogFlagsMask);
   366 	event1->ClearFlags(KLogFlagsMask);
   367 	TEST(event1->Flags() == KLogNullFlags);
   368 
   369 	event1->SetFlags(0x5);
   370 	TEST(event1->Flags() == 0x5);
   371 	event1->SetFlags(0xA);
   372 	TEST(event1->Flags() == KLogFlagsMask);
   373 	event1->ClearFlags(0x5);
   374 	TEST(event1->Flags() == 0xA);
   375 	event1->ClearFlags(0xA);
   376 	TEST(event1->Flags() == KLogNullFlags);
   377 
   378 	// Data
   379 	TEST(event1->Data() == KNullDesC8);
   380 
   381 	HBufC8* buf8;
   382 
   383 	buf8 = TestUtils::CreateBuf8LC(100);
   384 	event1->SetDataL(buf8->Des());
   385 	TEST(event1->Data() == buf8->Des());
   386 	CleanupStack::PopAndDestroy();
   387 	TestStoreL(*event1);
   388 
   389 	buf8 = TestUtils::CreateBuf8LC(200);
   390 	event1->SetDataL(buf8->Des());
   391 	TEST(event1->Data() == buf8->Des());
   392 	CleanupStack::PopAndDestroy();
   393 	TestStoreL(*event1);
   394 
   395 	buf8 = TestUtils::CreateBuf8LC(400);
   396 	event1->SetDataL(buf8->Des());
   397 	TEST(event1->Data() == buf8->Des());
   398 	CleanupStack::PopAndDestroy();
   399 	TestStoreL(*event1);
   400 
   401 	event1->SetDataL(KNullDesC8);
   402 	TEST(event1->Data() == KNullDesC8);
   403 
   404 	// streaming
   405 	TFileName storename = _L("c:\\T_LOGEVENT_DATA");
   406 	TUid uid={0x12345678};
   407 
   408 	// create a store
   409 	theFs.Delete(storename);
   410 	CDictionaryFileStore* store = CDictionaryFileStore::OpenLC(theFs, storename, uid);
   411 	
   412 	RDictionaryWriteStream write;
   413 	RDictionaryReadStream read;
   414 
   415 	event1->SetDataL(KNullDesC8);
   416 
   417 	uid.iUid++;
   418 	write.AssignL(*store, uid);
   419 	write << event1->Data();
   420 	write.CommitL();
   421 	write.Close();
   422 
   423 	read.OpenL(*store, uid);
   424 	event1->SetDataL(read, 0);
   425 	read.Close();
   426 
   427 	TEST(event1->Data() == KNullDesC8);
   428 
   429 	buf8 = TestUtils::CreateBuf8LC(100);
   430 	event1->SetDataL(buf8->Des());
   431 
   432 	uid.iUid++;
   433 	write.AssignL(*store, uid);
   434 	write.WriteL(event1->Data());
   435 	write.CommitL();
   436 	write.Close();
   437 
   438 	read.OpenL(*store, uid);
   439 	event1->SetDataL(read, 100);
   440 	read.Close();
   441 
   442 	TEST(event1->Data() == buf8->Des());
   443 	CleanupStack::PopAndDestroy(); // buf8
   444 
   445 	buf8 = TestUtils::CreateBuf8LC(200);
   446 	event1->SetDataL(buf8->Des());
   447 
   448 	uid.iUid++;
   449 	write.AssignL(*store, uid);
   450 	write.WriteL(event1->Data());
   451 	write.CommitL();
   452 	write.Close();
   453 
   454 	read.OpenL(*store, uid);
   455 	event1->SetDataL(read, 200);
   456 	read.Close();
   457 
   458 	TEST(event1->Data() == buf8->Des());
   459 	CleanupStack::PopAndDestroy(); // buf8
   460 
   461 	buf8 = TestUtils::CreateBuf8LC(400);
   462 	event1->SetDataL(buf8->Des());
   463 
   464 	uid.iUid++;
   465 	write.AssignL(*store, uid);
   466 	write.WriteL(event1->Data());
   467 	write.CommitL();
   468 	write.Close();
   469 
   470 	read.OpenL(*store, uid);
   471 	event1->SetDataL(read, 400);
   472 	read.Close();
   473 
   474 	TEST(event1->Data() == buf8->Des());
   475 	CleanupStack::PopAndDestroy(2); // buf8, store
   476 
   477 	// Copying
   478 	event1->SetId(0x12345678);
   479 	event1->SetEventType(TUid::Uid(0x12345678));
   480 
   481 	buf = TestUtils::CreateBufLC(KLogMaxRemotePartyLength / 2);
   482 	event1->SetRemoteParty(buf->Des());
   483 	TEST(event1->RemoteParty() == buf->Des());
   484 	CleanupStack::PopAndDestroy(); // buf
   485 
   486 	buf = TestUtils::CreateBufLC(KLogMaxDirectionLength / 2);
   487 	event1->SetDirection(buf->Des());
   488 	TEST(event1->Direction() == buf->Des());
   489 	CleanupStack::PopAndDestroy(); // buf
   490 
   491 	event1->SetDurationType(0xf);
   492 	TEST(event1->DurationType() == 0xf);
   493 
   494 	event1->SetDuration(0x12345678);
   495 	TEST(event1->Duration() == 0x12345678);
   496 
   497 	buf = TestUtils::CreateBufLC(KLogMaxStatusLength / 2);
   498 	event1->SetStatus(buf->Des());
   499 	TEST(event1->Status() == buf->Des());
   500 	CleanupStack::PopAndDestroy(); // buf
   501 
   502 	buf = TestUtils::CreateBufLC(KLogMaxSubjectLength / 2);
   503 	event1->SetSubject(buf->Des());
   504 	TEST(event1->Subject() == buf->Des());
   505 	CleanupStack::PopAndDestroy(); // buf
   506 
   507 	buf = TestUtils::CreateBufLC(KLogMaxNumberLength / 2);
   508 	event1->SetNumber(buf->Des());
   509 	TEST(event1->Number() == buf->Des());
   510 	CleanupStack::PopAndDestroy(); // buf
   511 
   512 	event1->SetContact(0x12345678);
   513 	TEST(event1->Contact() == 0x12345678);
   514 
   515 	event1->SetLink(0x12345678);
   516 	TEST(event1->Link() == 0x12345678);
   517 
   518 	buf = TestUtils::CreateBufLC(KLogMaxDescriptionLength / 2);
   519 	event1->SetDescription(buf->Des());
   520 	TEST(event1->Description() == buf->Des());
   521 	CleanupStack::PopAndDestroy(); // buf
   522 
   523 	buf8 = TestUtils::CreateBuf8LC(200);
   524 	event1->SetDataL(buf8->Des());
   525 	TEST(event1->Data() == buf8->Des());
   526 	CleanupStack::PopAndDestroy();
   527 
   528 	CLogEvent* event2 = CLogEvent::NewL();
   529 	CleanupStack::PushL(event2);
   530 	TEST(!TestUtils::EventsEqual(*event1, *event2));
   531 
   532 	event2->CopyL(*event1);
   533 	TEST(TestUtils::EventsEqual(*event1, *event2));
   534 	
   535 	CleanupStack::PopAndDestroy(); // event2;
   536 
   537 	event2 = CLogEvent::NewL();
   538 	CleanupStack::PushL(event2);
   539 	TEST(!TestUtils::EventsEqual(*event1, *event2));
   540 
   541 	event1->CopyL(*event2);
   542 	TEST(TestUtils::EventsEqual(*event1, *event2));
   543 
   544 	CleanupStack::PopAndDestroy(2); // event1, event2;
   545 
   546 	::DeleteDataFile(storename);
   547 	}
   548 
   549 /**
   550 @SYMTestCaseID          SYSLIB-LOGENG-CT-1009
   551 @SYMTestCaseDesc	    Tests for CLogEvent::NewL(),SetDataL() functions
   552 @SYMTestPriority 	    High
   553 @SYMTestActions  	    Tests for creation of log event on heap and 
   554                         test for setting  event specific data from the specified stream and try to read the data back.
   555                         Check for memory errors
   556 @SYMTestExpectedResults Test must not fail
   557 @SYMREQ                 REQ0000
   558 */
   559 LOCAL_C void TestEventWithHeapFailL()
   560 	{
   561 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-1009 "));
   562 #ifdef _DEBUG
   563 	TInt failCount = 0;
   564 #endif
   565 	TInt error;
   566 	TBool finished = EFalse;
   567 
   568 	CLogEvent* event = NULL;
   569 
   570 	while(!finished)
   571 		{
   572 		__UHEAP_FAILNEXT(failCount++);
   573 
   574 		TRAP(error, event = CLogEvent::NewL());
   575 		
   576 		__UHEAP_RESET;
   577 
   578 		if (error == KErrNone)
   579 			{
   580 			finished = ETrue;
   581 			CleanupStack::PushL(event);
   582 			}
   583 		else
   584 			TEST2(error, KErrNoMemory);
   585 		}
   586 
   587 	_LIT8(KDataTest1, "01234567890123456789");
   588 	_LIT8(KDataTest2, "012345678901234567890123456789");
   589 
   590 	finished = EFalse;
   591 #ifdef _DEBUG
   592 	failCount = 0;
   593 #endif
   594 	event->SetDataL(KNullDesC8);
   595 
   596 	while(!finished)
   597 		{
   598 		__UHEAP_FAILNEXT(failCount++);
   599 
   600 		TRAP(error, event->SetDataL(KDataTest1));
   601 
   602 		__UHEAP_RESET;
   603 
   604 		if (error == KErrNone)
   605 			{
   606 			finished = ETrue;
   607 			TEST(event->Data() == KDataTest1);
   608 			}
   609 		else
   610 			{
   611 			TEST2(error, KErrNoMemory);
   612 			TEST(event->Data() == KNullDesC8);
   613 			}
   614 		}
   615 
   616 	finished = EFalse;
   617 #ifdef _DEBUG
   618 	failCount = 0;
   619 #endif
   620 	event->SetDataL(KNullDesC8);
   621 
   622 	while(!finished)
   623 		{
   624 		__UHEAP_FAILNEXT(failCount++);
   625 
   626 		TRAP(error, event->SetDataL(KDataTest2));
   627 
   628 		__UHEAP_RESET;
   629 
   630 		if (error == KErrNone)
   631 			{
   632 			finished = ETrue;
   633 			TEST(event->Data() == KDataTest2);
   634 			}
   635 		else
   636 			{
   637 			TEST2(error, KErrNoMemory);
   638 			TEST(event->Data() == KNullDesC8);
   639 			}
   640 		}
   641 
   642 	finished = EFalse;
   643 #ifdef _DEBUG
   644 	failCount = 0;
   645 #endif
   646 	event->SetDataL(KNullDesC8);
   647 
   648 	// Check we don't get any more failures
   649 	__UHEAP_FAILNEXT(0);
   650 	event->SetDataL(KDataTest2);
   651 	TEST(event->Data() == KDataTest2);
   652 	event->SetDataL(KDataTest1);
   653 	TEST(event->Data() == KDataTest1);
   654 	event->SetDataL(KNullDesC8);
   655 	TEST(event->Data() == KNullDesC8);
   656 	__UHEAP_RESET;
   657 
   658 	// streaming
   659 	TFileName storename = _L("c:\\T_BASIC_DATA");
   660 	TUid uid={0x12345678};
   661 
   662 	// create a store
   663 	theFs.Delete(storename);
   664 	CDictionaryFileStore* store = CDictionaryFileStore::OpenLC(theFs, storename, uid);
   665 	
   666 	RDictionaryWriteStream write;
   667 	RDictionaryReadStream read;
   668 
   669 	uid.iUid++;
   670 	write.AssignL(*store, uid);
   671 	write << KNullDesC8;
   672 	write.CommitL();
   673 	write.Close();
   674 
   675 	read.OpenL(*store, uid);
   676 
   677 #ifdef _DEBUG
   678 	failCount = 0;
   679 #endif
   680 	finished = EFalse;
   681 
   682 	__UHEAP_FAILNEXT(0);
   683 	event->SetDataL(read, 0);
   684 	__UHEAP_RESET;
   685 
   686 	read.Close();	
   687 	TEST(event->Data() == KNullDesC8);
   688 
   689 	HBufC8* buf8 = TestUtils::CreateBuf8LC(100);
   690 
   691 	uid.iUid++;
   692 	write.AssignL(*store, uid);
   693 	write.WriteL(buf8->Des());
   694 	write.CommitL();
   695 	write.Close();
   696 
   697 	read.OpenL(*store, uid);
   698 
   699 	while(!finished)
   700 		{
   701 		__UHEAP_FAILNEXT(failCount++);
   702 
   703 		TRAP(error, event->SetDataL(read, 100));
   704 
   705 		__UHEAP_RESET;
   706 
   707 		if (error == KErrNone)
   708 			{
   709 			TEST(event->Data() == buf8->Des());
   710 			read.Close();
   711 			finished = ETrue;
   712 			}
   713 		else
   714 			{
   715 			TEST2(error, KErrNoMemory);
   716 			TEST(event->Data() == KNullDesC8);
   717 			}
   718 		}
   719 
   720 	event->SetId(0x12345678);
   721 	event->SetEventType(TUid::Uid(0x12345678));
   722 
   723 	HBufC* buf = TestUtils::CreateBufLC(KLogMaxRemotePartyLength / 2);
   724 	event->SetRemoteParty(buf->Des());
   725 	CleanupStack::PopAndDestroy(); // buf
   726 
   727 	buf = TestUtils::CreateBufLC(KLogMaxDirectionLength / 2);
   728 	event->SetDirection(buf->Des());
   729 	CleanupStack::PopAndDestroy(); // buf
   730 
   731 	TTime time;
   732 
   733 	time.UniversalTime();
   734 	event->SetTime(time);
   735 	TEST(event->Time() == time);
   736 
   737 	event->SetDurationType(0xf);
   738 	event->SetDuration(0x12345678);
   739 
   740 	buf = TestUtils::CreateBufLC(KLogMaxStatusLength / 2);
   741 	event->SetStatus(buf->Des());
   742 	CleanupStack::PopAndDestroy(); // buf
   743 
   744 	buf = TestUtils::CreateBufLC(KLogMaxSubjectLength / 2);
   745 	event->SetSubject(buf->Des());
   746 	CleanupStack::PopAndDestroy(); // buf
   747 
   748 	buf = TestUtils::CreateBufLC(KLogMaxNumberLength / 2);
   749 	event->SetNumber(buf->Des());
   750 	CleanupStack::PopAndDestroy(); // buf
   751 
   752 	event->SetContact(0x12345678);
   753 	event->SetLink(0x12345678);
   754 
   755 	buf = TestUtils::CreateBufLC(KLogMaxDescriptionLength / 2);
   756 	event->SetDescription(buf->Des());
   757 	CleanupStack::PopAndDestroy(); // buf
   758 
   759 	event->SetFlags(0xA);
   760 
   761 	buf8 = TestUtils::CreateBuf8LC(100);
   762 	event->SetDataL(buf8->Des());
   763 	TEST(event->Data() == buf8->Des());
   764 	CleanupStack::PopAndDestroy(); // buf8
   765 
   766 	CLogEvent* event1 = CLogEvent::NewL();
   767 	CleanupStack::PushL(event1);
   768 
   769 	CLogEvent* event2 = CLogEvent::NewL();
   770 	CleanupStack::PushL(event2);
   771 
   772 	TEST(TestUtils::EventsEqual(*event1, *event2));
   773 
   774 	finished = EFalse;
   775 #ifdef _DEBUG
   776 	failCount = 0;
   777 #endif
   778 
   779 	while(!finished)
   780 		{
   781 		__UHEAP_FAILNEXT(failCount++);
   782 
   783 		TRAP(error, event1->CopyL(*event));
   784 
   785 		__UHEAP_RESET;
   786 
   787 		if (error == KErrNone)
   788 			{
   789 			TEST(!TestUtils::EventsEqual(*event1, *event2));
   790 			TEST(TestUtils::EventsEqual(*event1, *event));
   791 			finished = ETrue;
   792 			}
   793 		else
   794 			{
   795 			TEST2(error, KErrNoMemory);
   796 			TEST(TestUtils::EventsEqual(*event1, *event2));
   797 			TEST(!TestUtils::EventsEqual(*event1, *event));
   798 			}
   799 		}
   800 
   801 	CleanupStack::PopAndDestroy(5); // buf8, store, event, event1, event2
   802 	::DeleteDataFile(storename);
   803 	}
   804 
   805 /**
   806 @SYMTestCaseID          SYSLIB-LOGENG-CT-1010
   807 @SYMTestCaseDesc	    Tests for CLogEvent::NewL(),CLogEvent::SetDataL() functions
   808 @SYMTestPriority 	    High
   809 @SYMTestActions  	    Tests for setting event specific data read from the file and try to read the data back from the event.
   810                         Check for memory errors
   811 @SYMTestExpectedResults Test must not fail
   812 @SYMREQ                 REQ0000
   813 */
   814 LOCAL_C void TestEventWithFileFailL()
   815 	{
   816 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-1010 "));
   817 	CLogEvent* event = CLogEvent::NewL();
   818 	CleanupStack::PushL(event);
   819 
   820 	// streaming
   821 	TFileName storename = _L("c:\\T_BASIC_DATA");
   822 	TUid uid={0x12345678};
   823 
   824 	// create a store
   825 	theFs.Delete(storename);
   826 	CDictionaryFileStore* store = CDictionaryFileStore::OpenLC(theFs, storename, uid);
   827 	
   828 	RDictionaryWriteStream write;
   829 	RDictionaryReadStream read;
   830 
   831 	uid.iUid++;
   832 	write.AssignL(*store, uid);
   833 	write << KNullDesC8;
   834 	write.CommitL();
   835 	write.Close();
   836 
   837 	read.OpenL(*store, uid);
   838 
   839 	TInt failCount = 0;
   840 	TBool finished = EFalse;
   841 	TInt error;
   842 
   843 	theFs.SetErrorCondition(KErrGeneral, 0);
   844 	event->SetDataL(read, 0);
   845 	theFs.SetErrorCondition(KErrNone, 10000);
   846 
   847 	read.Close();
   848 	TEST(event->Data() == KNullDesC8);
   849 
   850 	HBufC8* buf8 = TestUtils::CreateBuf8LC(100);
   851 
   852 	uid.iUid++;
   853 	write.AssignL(*store, uid);
   854 	write.WriteL(buf8->Des());
   855 	write.CommitL();
   856 	write.Close();
   857 
   858 	while(!finished)
   859 		{
   860 		read.OpenL(*store, uid);
   861 		theFs.SetErrorCondition(KErrGeneral, failCount++);
   862 
   863 		TRAP(error, event->SetDataL(read, 100));
   864 
   865 		theFs.SetErrorCondition(KErrGeneral, 10000);
   866 
   867 		read.Close();
   868 
   869 		if (error == KErrNone)
   870 			{
   871 			TEST(event->Data() == buf8->Des());
   872 			finished = ETrue;
   873 			}
   874 		else
   875 			{
   876 			TEST2(error, KErrGeneral);
   877 			TEST(event->Data() == KNullDesC8);
   878 			}
   879 		}
   880 
   881 	CleanupStack::PopAndDestroy(3); // buf8, store, event
   882 	::DeleteDataFile(storename);
   883 	}
   884 
   885 void doTestsL()
   886 	{
   887 	TestUtils::Initialize(_L("t_logevent"));
   888 
   889 	TheTest.Start(_L("Event"));
   890 //	TestServerL();
   891 	
   892 
   893 	TestEventL();
   894 	theLog.Write(_L8("Test 1 OK\n"));
   895 
   896 	TheTest.Next(_L("Event with heap failure"));
   897 	TestEventWithHeapFailL();
   898 	theLog.Write(_L8("Test 2 OK\n"));
   899 
   900 	TheTest.Next(_L("Event with file failure"));
   901 	TestEventWithFileFailL();
   902 	theLog.Write(_L8("Test 3 OK\n"));
   903 	}
   904