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