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