os/persistentdata/loggingservices/eventlogger/test/src/t_logwrap.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 <bautils.h>
sl@0
    18
#include "t_logutil2.h"
sl@0
    19
sl@0
    20
RTest TheTest(_L("t_logwrap"));
sl@0
    21
sl@0
    22
_LIT(KTestRemoteParty, "Remote Party");
sl@0
    23
_LIT(KTestDirection, "Direction");
sl@0
    24
const TLogDurationType KTestDurationType = 1;
sl@0
    25
const TLogDuration KTestDuration = 0x1234;
sl@0
    26
_LIT(KTestStatus, "Status");
sl@0
    27
_LIT(KTestSubject, "Subject");
sl@0
    28
_LIT(KTestNumber, "Number");
sl@0
    29
const TLogContactItemId KTestContact = 0x1234;
sl@0
    30
const TLogLink KTestLink = 0x1234;
sl@0
    31
_LIT8(KTestData, "ABCDEFGH");
sl@0
    32
sl@0
    33
/**
sl@0
    34
@SYMTestCaseID          SYSLIB-LOGENG-CT-1011
sl@0
    35
@SYMTestCaseDesc	    Tests for the functionality of CLogEvent class
sl@0
    36
@SYMTestPriority 	    High
sl@0
    37
@SYMTestActions  	    Tests for adding,changing,deleting and getting event type functions on the logevent
sl@0
    38
                        Check for memory,KErrNone and KErrNotSupported error flags
sl@0
    39
@SYMTestExpectedResults Test must not fail
sl@0
    40
@SYMREQ                 REQ0000
sl@0
    41
*/
sl@0
    42
LOCAL_C void TestBasicL(CLogBase& aClient, TBool aClientAvailable)
sl@0
    43
	{
sl@0
    44
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-1011 "));
sl@0
    45
	CTestActive* active = new(ELeave)CTestActive();
sl@0
    46
	CleanupStack::PushL(active);
sl@0
    47
sl@0
    48
	CLogEvent* event = CLogEvent::NewL();
sl@0
    49
	CleanupStack::PushL(event);
sl@0
    50
sl@0
    51
	TTime now;
sl@0
    52
	now.UniversalTime();
sl@0
    53
sl@0
    54
	event->SetEventType(KLogCallEventTypeUid);
sl@0
    55
sl@0
    56
	active->StartL();
sl@0
    57
	aClient.AddEvent(*event, active->iStatus);
sl@0
    58
	CActiveScheduler::Start();
sl@0
    59
	if(aClientAvailable)
sl@0
    60
		{
sl@0
    61
		TEST2(active->iStatus.Int(), KErrNone);
sl@0
    62
		}
sl@0
    63
	else
sl@0
    64
		{
sl@0
    65
		TEST2(active->iStatus.Int(), KErrNotSupported);
sl@0
    66
		}
sl@0
    67
sl@0
    68
	if (aClientAvailable)
sl@0
    69
		{
sl@0
    70
		TEST(event->EventType() == KLogCallEventTypeUid);
sl@0
    71
		TEST(event->Description().Length() > 0);
sl@0
    72
		TEST(event->Time() >= now);
sl@0
    73
		now = event->Time();
sl@0
    74
		}
sl@0
    75
sl@0
    76
	TLogId id = event->Id();
sl@0
    77
sl@0
    78
	event->SetRemoteParty(KTestRemoteParty);
sl@0
    79
	event->SetDirection(KTestDirection);
sl@0
    80
	event->SetDurationType(KTestDurationType);
sl@0
    81
	event->SetDuration(KTestDuration);
sl@0
    82
	event->SetStatus(KTestStatus);
sl@0
    83
	event->SetSubject(KTestSubject);
sl@0
    84
	event->SetNumber(KTestNumber);
sl@0
    85
	event->SetContact(KTestContact);
sl@0
    86
	event->SetLink(KTestLink);
sl@0
    87
	event->SetDataL(KTestData);
sl@0
    88
sl@0
    89
	active->StartL();
sl@0
    90
	aClient.ChangeEvent(*event, active->iStatus);
sl@0
    91
	CActiveScheduler::Start();
sl@0
    92
	if(aClientAvailable)
sl@0
    93
		{
sl@0
    94
		TEST2(active->iStatus.Int(), KErrNone);
sl@0
    95
		}
sl@0
    96
	else
sl@0
    97
		{
sl@0
    98
		TEST2(active->iStatus.Int(), KErrNotSupported);
sl@0
    99
		}
sl@0
   100
sl@0
   101
	if (aClientAvailable)
sl@0
   102
		{
sl@0
   103
		TEST(event->Id() == id);
sl@0
   104
		TEST(event->EventType() == KLogCallEventTypeUid);
sl@0
   105
		TEST(event->Description().Length() > 0);
sl@0
   106
		TEST(event->Time() == now);
sl@0
   107
		TEST(event->RemoteParty() == KTestRemoteParty);
sl@0
   108
		TEST(event->Direction() == KTestDirection);
sl@0
   109
		TEST(event->DurationType() == KTestDurationType);
sl@0
   110
		TEST(event->Duration() == KTestDuration);
sl@0
   111
		TEST(event->Status() == KTestStatus);
sl@0
   112
		TEST(event->Subject() == KTestSubject);
sl@0
   113
		TEST(event->Number() == KTestNumber);
sl@0
   114
		TEST(event->Contact() == KTestContact);
sl@0
   115
		TEST(event->Link() == KTestLink);
sl@0
   116
		TEST(event->Data() == KTestData);
sl@0
   117
		}
sl@0
   118
sl@0
   119
	CleanupStack::PopAndDestroy(); // event;
sl@0
   120
sl@0
   121
	event = CLogEvent::NewL();
sl@0
   122
	CleanupStack::PushL(event);
sl@0
   123
sl@0
   124
	event->SetId(id);
sl@0
   125
sl@0
   126
	active->StartL();
sl@0
   127
	aClient.GetEvent(*event, active->iStatus);
sl@0
   128
	CActiveScheduler::Start();
sl@0
   129
	if(aClientAvailable)
sl@0
   130
		{
sl@0
   131
		TEST2(active->iStatus.Int(), KErrNone);
sl@0
   132
		}
sl@0
   133
	else
sl@0
   134
		{
sl@0
   135
		TEST2(active->iStatus.Int(), KErrNotSupported);
sl@0
   136
		}
sl@0
   137
sl@0
   138
	if (aClientAvailable)
sl@0
   139
		{
sl@0
   140
		TEST(event->Id() == id);
sl@0
   141
		TEST(event->EventType() == KLogCallEventTypeUid);
sl@0
   142
		TEST(event->Description().Length() > 0);
sl@0
   143
		TEST(event->Time() == now);
sl@0
   144
		TEST(event->RemoteParty() == KTestRemoteParty);
sl@0
   145
		TEST(event->Direction() == KTestDirection);
sl@0
   146
		TEST(event->DurationType() == KTestDurationType);
sl@0
   147
		TEST(event->Duration() == KTestDuration);
sl@0
   148
		TEST(event->Status() == KTestStatus);
sl@0
   149
		TEST(event->Subject() == KTestSubject);
sl@0
   150
		TEST(event->Number() == KTestNumber);
sl@0
   151
		TEST(event->Contact() == KTestContact);
sl@0
   152
		TEST(event->Link() == KTestLink);
sl@0
   153
		TEST(event->Data() == KTestData);
sl@0
   154
		}
sl@0
   155
sl@0
   156
	active->StartL();
sl@0
   157
	aClient.DeleteEvent(id, active->iStatus);
sl@0
   158
	CActiveScheduler::Start();
sl@0
   159
	if(aClientAvailable)
sl@0
   160
		{
sl@0
   161
		TEST2(active->iStatus.Int(), KErrNone);
sl@0
   162
		}
sl@0
   163
	else
sl@0
   164
		{
sl@0
   165
		TEST2(active->iStatus.Int(), KErrNotSupported);
sl@0
   166
		}
sl@0
   167
sl@0
   168
	active->StartL();
sl@0
   169
	aClient.GetEvent(*event, active->iStatus);
sl@0
   170
	CActiveScheduler::Start();
sl@0
   171
	if(aClientAvailable)
sl@0
   172
		{
sl@0
   173
		TEST2(active->iStatus.Int(), KErrNotFound);
sl@0
   174
		}
sl@0
   175
	else
sl@0
   176
		{
sl@0
   177
		TEST2(active->iStatus.Int(), KErrNotSupported);
sl@0
   178
		}
sl@0
   179
sl@0
   180
	CleanupStack::PopAndDestroy(2); // event, active
sl@0
   181
	}
sl@0
   182
sl@0
   183
/**
sl@0
   184
@SYMTestCaseID          SYSLIB-LOGENG-CT-1012
sl@0
   185
@SYMTestCaseDesc	    Test for CLogWrapper::Log(),CLogWrapper::ClientAvailable() functions
sl@0
   186
@SYMTestPriority 	    High
sl@0
   187
@SYMTestActions  	    Execute basics event test on a log wrapper
sl@0
   188
@SYMTestExpectedResults Test must not fail
sl@0
   189
@SYMREQ                 REQ0000
sl@0
   190
*/
sl@0
   191
LOCAL_C void TestWrapperL()
sl@0
   192
	{
sl@0
   193
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-1012 "));
sl@0
   194
	CTestActive* active = new(ELeave)CTestActive();
sl@0
   195
	CleanupStack::PushL(active);
sl@0
   196
sl@0
   197
	CLogWrapper* wrapper = CLogWrapper::NewL(theFs);
sl@0
   198
	CleanupStack::PushL(wrapper);
sl@0
   199
sl@0
   200
	CLogBase& logBase = wrapper->Log();
sl@0
   201
	TestBasicL(logBase, wrapper->ClientAvailable());
sl@0
   202
sl@0
   203
	TBuf<KLogMaxSharedStringLength> buf;
sl@0
   204
	if (wrapper->ClientAvailable())
sl@0
   205
		{
sl@0
   206
		CLogBase& logBase2 = wrapper->Log();
sl@0
   207
		TEST2(logBase2.GetString(buf, R_LOG_DIR_IN), KErrNone);
sl@0
   208
		TEST(buf.Length() > 0);
sl@0
   209
		}
sl@0
   210
	else
sl@0
   211
		{
sl@0
   212
		CLogBase& logBase3 = wrapper->Log();
sl@0
   213
		TEST2(logBase3.GetString(buf, R_LOG_DIR_IN), KErrNotSupported);
sl@0
   214
		TEST(buf.Length() == 0);
sl@0
   215
		}
sl@0
   216
sl@0
   217
	CleanupStack::PopAndDestroy(2); // wrapper, active
sl@0
   218
	}
sl@0
   219
sl@0
   220
/**
sl@0
   221
@SYMTestCaseID          SYSLIB-LOGENG-CT-1013
sl@0
   222
@SYMTestCaseDesc	    Tests for out of memory errors on CLogWrapper::NewL() function call
sl@0
   223
@SYMTestPriority 	    High
sl@0
   224
@SYMTestActions  	    Check for no memory error condition
sl@0
   225
@SYMTestExpectedResults Test must not fail
sl@0
   226
@SYMREQ                 REQ0000
sl@0
   227
*/
sl@0
   228
LOCAL_C void TestHeapFailL()
sl@0
   229
	{
sl@0
   230
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-1013 "));
sl@0
   231
	CLogWrapper* wrapper = NULL;
sl@0
   232
	
sl@0
   233
#ifdef _DEBUG
sl@0
   234
	TInt failCount = 0;
sl@0
   235
#endif
sl@0
   236
sl@0
   237
	TBool finished = EFalse;
sl@0
   238
	TInt error;
sl@0
   239
	
sl@0
   240
	while(!finished)
sl@0
   241
		{
sl@0
   242
		__UHEAP_FAILNEXT(failCount++);
sl@0
   243
sl@0
   244
		TRAP(error, wrapper = CLogWrapper::NewL(theFs));
sl@0
   245
sl@0
   246
		__UHEAP_RESET;
sl@0
   247
sl@0
   248
		if (error == KErrNone)
sl@0
   249
			{
sl@0
   250
			finished = ETrue;
sl@0
   251
			CLogBase& logBase = wrapper->Log();
sl@0
   252
			TestBasicL(logBase, wrapper->ClientAvailable());
sl@0
   253
			delete wrapper;
sl@0
   254
			}
sl@0
   255
		else
sl@0
   256
			TEST2(error, KErrNoMemory);
sl@0
   257
		}
sl@0
   258
	}
sl@0
   259
sl@0
   260
/**
sl@0
   261
@SYMTestCaseID          SYSLIB-LOGENG-CT-1014
sl@0
   262
@SYMTestCaseDesc	    Tests for CLogWrapper::NewL() function 
sl@0
   263
@SYMTestPriority 	    High
sl@0
   264
@SYMTestActions  	    Create log wrapper on heap,if no error execute the basic event tests.
sl@0
   265
                        Check for general errors.
sl@0
   266
@SYMTestExpectedResults Test must not fail
sl@0
   267
@SYMREQ                 REQ0000
sl@0
   268
*/
sl@0
   269
LOCAL_C void TestFileFailL()
sl@0
   270
	{
sl@0
   271
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-1014 "));
sl@0
   272
	CLogWrapper* wrapper = NULL;
sl@0
   273
	
sl@0
   274
	TInt failCount = 0;
sl@0
   275
	TBool finished = EFalse;
sl@0
   276
	TInt error;
sl@0
   277
	
sl@0
   278
	while(!finished)
sl@0
   279
		{
sl@0
   280
		TheTest.Printf(_L("%d  \r"), failCount);
sl@0
   281
		__FILE_FAILNEXT(KErrNoMemory, failCount++);
sl@0
   282
sl@0
   283
		TRAP(error, wrapper = CLogWrapper::NewL(theFs));
sl@0
   284
sl@0
   285
		__FILE_RESET;
sl@0
   286
sl@0
   287
		if (error == KErrNone)
sl@0
   288
			{
sl@0
   289
			finished = ETrue;
sl@0
   290
			CLogBase& logBase = wrapper->Log();
sl@0
   291
			TestBasicL(logBase, wrapper->ClientAvailable());
sl@0
   292
			delete wrapper;
sl@0
   293
			}
sl@0
   294
		else
sl@0
   295
			{
sl@0
   296
			TEST2(error, KErrNoMemory);
sl@0
   297
			}
sl@0
   298
		}
sl@0
   299
	TheTest.Printf(_L("\r\nThe test has succeeded at iteration %d\n"), failCount);
sl@0
   300
	}
sl@0
   301
sl@0
   302
/**
sl@0
   303
@SYMTestCaseID          SYSLIB-LOGENG-CT-1015
sl@0
   304
@SYMTestCaseDesc	    Tests for INC047632
sl@0
   305
@SYMTestPriority 	    High
sl@0
   306
@SYMTestActions  	    This test uses a stored copy of a corrupt database which is copied to z:\system\data.
sl@0
   307
						When this database ia accessed open returns an error KErrEof.
sl@0
   308
@SYMTestExpectedResults Test must not fail
sl@0
   309
@SYMREQ                 REQ0000
sl@0
   310
*/
sl@0
   311
LOCAL_C void Test4INC047632L()
sl@0
   312
	{
sl@0
   313
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-1015 "));
sl@0
   314
#ifdef _DEBUG	
sl@0
   315
	TestUtils::CopyCorruptDbL();
sl@0
   316
sl@0
   317
	// run basic test
sl@0
   318
	CLogWrapper* wrapper = NULL;
sl@0
   319
	
sl@0
   320
	TInt error = KErrNone;
sl@0
   321
	TRAP(error, wrapper = CLogWrapper::NewL(theFs));
sl@0
   322
sl@0
   323
	if (error == KErrNone)
sl@0
   324
		{
sl@0
   325
		CLogBase& logBase = wrapper->Log();
sl@0
   326
		TestBasicL(logBase, wrapper->ClientAvailable());
sl@0
   327
		delete wrapper;
sl@0
   328
		}
sl@0
   329
#else
sl@0
   330
	RDebug::Print(_L("Test4INC047632L() can be executed only in debug mode. In release mode the LogEng server cannot be stopped.\n"));
sl@0
   331
#endif//_DEBUG
sl@0
   332
	}
sl@0
   333
/**
sl@0
   334
@SYMTestCaseID          SYSLIB-LOGENG-CT-4001
sl@0
   335
@SYMTestCaseDesc	    Tests for INC114909
sl@0
   336
@SYMTestPriority 	    High
sl@0
   337
@SYMTestActions  	    This test uses a stored copy of a corrupt damaged database which is 
sl@0
   338
						copied to z:\system\data.
sl@0
   339
						When an attempt is made to open the database the fault should be 
sl@0
   340
						recognised and the database deleted.
sl@0
   341
@SYMTestExpectedResults Test must not fail
sl@0
   342
@SYMDEF                 INC114909
sl@0
   343
*/
sl@0
   344
LOCAL_C void Test5INC114909L()
sl@0
   345
	{
sl@0
   346
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-4001 "));
sl@0
   347
#ifdef _DEBUG	
sl@0
   348
 	// Copy over the damaged database to be used.
sl@0
   349
	TestUtils::CopyCorruptDamagedDbL();
sl@0
   350
 
sl@0
   351
	// run basic test
sl@0
   352
	CLogWrapper* wrapper = NULL;	
sl@0
   353
	TInt error = KErrNone;
sl@0
   354
	TRAP(error, wrapper = CLogWrapper::NewL(theFs));
sl@0
   355
	delete wrapper;
sl@0
   356
	
sl@0
   357
	// Without the code for this defect the error here will be KErrCorrupt.
sl@0
   358
	// and the log server will continually try to restart and be brought down
sl@0
   359
	// with KErrCorrupt 
sl@0
   360
	// With the fix the error with the database is detected on opening the database 
sl@0
   361
	// and the  database file is deleted and re-created.
sl@0
   362
 
sl@0
   363
	TEST(error == KErrNone);
sl@0
   364
	
sl@0
   365
	// Perform an extra check that the log server has not been brought down
sl@0
   366
	// as is the case without the defect fix.
sl@0
   367
	RLogTestSession theLogServ;
sl@0
   368
	error = theLogServ.Connect();
sl@0
   369
 	TEST(error == KErrNone);
sl@0
   370
#else
sl@0
   371
	RDebug::Print(_L("Test4INC047632L() can be executed only in debug mode. In release mode the LogEng server cannot be stopped.\n"));
sl@0
   372
#endif//_DEBUG
sl@0
   373
	}
sl@0
   374
sl@0
   375
void doTestsL()
sl@0
   376
	{
sl@0
   377
	TestUtils::Initialize(_L("t_logwrap"));
sl@0
   378
sl@0
   379
	TheTest.Start(_L("Wrapper"));
sl@0
   380
	TestWrapperL();
sl@0
   381
	theLog.Write(_L8("Test 1 OK\n"));
sl@0
   382
sl@0
   383
	TheTest.Next(_L("Heap Failure"));
sl@0
   384
	TestHeapFailL();
sl@0
   385
	theLog.Write(_L8("Test 2 OK\n"));
sl@0
   386
sl@0
   387
	TheTest.Next(_L("File Failure"));
sl@0
   388
	TestFileFailL();
sl@0
   389
	theLog.Write(_L8("Test 3 OK\n"));
sl@0
   390
sl@0
   391
	TheTest.Next(_L("Test4 for INC047632 - corrupt Logdbu.dat returns KErrEoF"));
sl@0
   392
	Test4INC047632L();
sl@0
   393
	theLog.Write(_L8("Test 4 for INC047632 OK\n"));
sl@0
   394
	
sl@0
   395
	TheTest.Next(_L("Test5 for INC114909 - test damaged Logdbu.dat is dealt with correctly "));
sl@0
   396
	Test5INC114909L();
sl@0
   397
	theLog.Write(_L8("Test 5 for INC114909 OK\n"));
sl@0
   398
	}