os/persistentdata/loggingservices/eventlogger/test/src/t_logwrap.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/loggingservices/eventlogger/test/src/t_logwrap.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,398 @@
     1.4 +// Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include <s32file.h>
    1.20 +#include <bautils.h>
    1.21 +#include "t_logutil2.h"
    1.22 +
    1.23 +RTest TheTest(_L("t_logwrap"));
    1.24 +
    1.25 +_LIT(KTestRemoteParty, "Remote Party");
    1.26 +_LIT(KTestDirection, "Direction");
    1.27 +const TLogDurationType KTestDurationType = 1;
    1.28 +const TLogDuration KTestDuration = 0x1234;
    1.29 +_LIT(KTestStatus, "Status");
    1.30 +_LIT(KTestSubject, "Subject");
    1.31 +_LIT(KTestNumber, "Number");
    1.32 +const TLogContactItemId KTestContact = 0x1234;
    1.33 +const TLogLink KTestLink = 0x1234;
    1.34 +_LIT8(KTestData, "ABCDEFGH");
    1.35 +
    1.36 +/**
    1.37 +@SYMTestCaseID          SYSLIB-LOGENG-CT-1011
    1.38 +@SYMTestCaseDesc	    Tests for the functionality of CLogEvent class
    1.39 +@SYMTestPriority 	    High
    1.40 +@SYMTestActions  	    Tests for adding,changing,deleting and getting event type functions on the logevent
    1.41 +                        Check for memory,KErrNone and KErrNotSupported error flags
    1.42 +@SYMTestExpectedResults Test must not fail
    1.43 +@SYMREQ                 REQ0000
    1.44 +*/
    1.45 +LOCAL_C void TestBasicL(CLogBase& aClient, TBool aClientAvailable)
    1.46 +	{
    1.47 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-1011 "));
    1.48 +	CTestActive* active = new(ELeave)CTestActive();
    1.49 +	CleanupStack::PushL(active);
    1.50 +
    1.51 +	CLogEvent* event = CLogEvent::NewL();
    1.52 +	CleanupStack::PushL(event);
    1.53 +
    1.54 +	TTime now;
    1.55 +	now.UniversalTime();
    1.56 +
    1.57 +	event->SetEventType(KLogCallEventTypeUid);
    1.58 +
    1.59 +	active->StartL();
    1.60 +	aClient.AddEvent(*event, active->iStatus);
    1.61 +	CActiveScheduler::Start();
    1.62 +	if(aClientAvailable)
    1.63 +		{
    1.64 +		TEST2(active->iStatus.Int(), KErrNone);
    1.65 +		}
    1.66 +	else
    1.67 +		{
    1.68 +		TEST2(active->iStatus.Int(), KErrNotSupported);
    1.69 +		}
    1.70 +
    1.71 +	if (aClientAvailable)
    1.72 +		{
    1.73 +		TEST(event->EventType() == KLogCallEventTypeUid);
    1.74 +		TEST(event->Description().Length() > 0);
    1.75 +		TEST(event->Time() >= now);
    1.76 +		now = event->Time();
    1.77 +		}
    1.78 +
    1.79 +	TLogId id = event->Id();
    1.80 +
    1.81 +	event->SetRemoteParty(KTestRemoteParty);
    1.82 +	event->SetDirection(KTestDirection);
    1.83 +	event->SetDurationType(KTestDurationType);
    1.84 +	event->SetDuration(KTestDuration);
    1.85 +	event->SetStatus(KTestStatus);
    1.86 +	event->SetSubject(KTestSubject);
    1.87 +	event->SetNumber(KTestNumber);
    1.88 +	event->SetContact(KTestContact);
    1.89 +	event->SetLink(KTestLink);
    1.90 +	event->SetDataL(KTestData);
    1.91 +
    1.92 +	active->StartL();
    1.93 +	aClient.ChangeEvent(*event, active->iStatus);
    1.94 +	CActiveScheduler::Start();
    1.95 +	if(aClientAvailable)
    1.96 +		{
    1.97 +		TEST2(active->iStatus.Int(), KErrNone);
    1.98 +		}
    1.99 +	else
   1.100 +		{
   1.101 +		TEST2(active->iStatus.Int(), KErrNotSupported);
   1.102 +		}
   1.103 +
   1.104 +	if (aClientAvailable)
   1.105 +		{
   1.106 +		TEST(event->Id() == id);
   1.107 +		TEST(event->EventType() == KLogCallEventTypeUid);
   1.108 +		TEST(event->Description().Length() > 0);
   1.109 +		TEST(event->Time() == now);
   1.110 +		TEST(event->RemoteParty() == KTestRemoteParty);
   1.111 +		TEST(event->Direction() == KTestDirection);
   1.112 +		TEST(event->DurationType() == KTestDurationType);
   1.113 +		TEST(event->Duration() == KTestDuration);
   1.114 +		TEST(event->Status() == KTestStatus);
   1.115 +		TEST(event->Subject() == KTestSubject);
   1.116 +		TEST(event->Number() == KTestNumber);
   1.117 +		TEST(event->Contact() == KTestContact);
   1.118 +		TEST(event->Link() == KTestLink);
   1.119 +		TEST(event->Data() == KTestData);
   1.120 +		}
   1.121 +
   1.122 +	CleanupStack::PopAndDestroy(); // event;
   1.123 +
   1.124 +	event = CLogEvent::NewL();
   1.125 +	CleanupStack::PushL(event);
   1.126 +
   1.127 +	event->SetId(id);
   1.128 +
   1.129 +	active->StartL();
   1.130 +	aClient.GetEvent(*event, active->iStatus);
   1.131 +	CActiveScheduler::Start();
   1.132 +	if(aClientAvailable)
   1.133 +		{
   1.134 +		TEST2(active->iStatus.Int(), KErrNone);
   1.135 +		}
   1.136 +	else
   1.137 +		{
   1.138 +		TEST2(active->iStatus.Int(), KErrNotSupported);
   1.139 +		}
   1.140 +
   1.141 +	if (aClientAvailable)
   1.142 +		{
   1.143 +		TEST(event->Id() == id);
   1.144 +		TEST(event->EventType() == KLogCallEventTypeUid);
   1.145 +		TEST(event->Description().Length() > 0);
   1.146 +		TEST(event->Time() == now);
   1.147 +		TEST(event->RemoteParty() == KTestRemoteParty);
   1.148 +		TEST(event->Direction() == KTestDirection);
   1.149 +		TEST(event->DurationType() == KTestDurationType);
   1.150 +		TEST(event->Duration() == KTestDuration);
   1.151 +		TEST(event->Status() == KTestStatus);
   1.152 +		TEST(event->Subject() == KTestSubject);
   1.153 +		TEST(event->Number() == KTestNumber);
   1.154 +		TEST(event->Contact() == KTestContact);
   1.155 +		TEST(event->Link() == KTestLink);
   1.156 +		TEST(event->Data() == KTestData);
   1.157 +		}
   1.158 +
   1.159 +	active->StartL();
   1.160 +	aClient.DeleteEvent(id, active->iStatus);
   1.161 +	CActiveScheduler::Start();
   1.162 +	if(aClientAvailable)
   1.163 +		{
   1.164 +		TEST2(active->iStatus.Int(), KErrNone);
   1.165 +		}
   1.166 +	else
   1.167 +		{
   1.168 +		TEST2(active->iStatus.Int(), KErrNotSupported);
   1.169 +		}
   1.170 +
   1.171 +	active->StartL();
   1.172 +	aClient.GetEvent(*event, active->iStatus);
   1.173 +	CActiveScheduler::Start();
   1.174 +	if(aClientAvailable)
   1.175 +		{
   1.176 +		TEST2(active->iStatus.Int(), KErrNotFound);
   1.177 +		}
   1.178 +	else
   1.179 +		{
   1.180 +		TEST2(active->iStatus.Int(), KErrNotSupported);
   1.181 +		}
   1.182 +
   1.183 +	CleanupStack::PopAndDestroy(2); // event, active
   1.184 +	}
   1.185 +
   1.186 +/**
   1.187 +@SYMTestCaseID          SYSLIB-LOGENG-CT-1012
   1.188 +@SYMTestCaseDesc	    Test for CLogWrapper::Log(),CLogWrapper::ClientAvailable() functions
   1.189 +@SYMTestPriority 	    High
   1.190 +@SYMTestActions  	    Execute basics event test on a log wrapper
   1.191 +@SYMTestExpectedResults Test must not fail
   1.192 +@SYMREQ                 REQ0000
   1.193 +*/
   1.194 +LOCAL_C void TestWrapperL()
   1.195 +	{
   1.196 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-1012 "));
   1.197 +	CTestActive* active = new(ELeave)CTestActive();
   1.198 +	CleanupStack::PushL(active);
   1.199 +
   1.200 +	CLogWrapper* wrapper = CLogWrapper::NewL(theFs);
   1.201 +	CleanupStack::PushL(wrapper);
   1.202 +
   1.203 +	CLogBase& logBase = wrapper->Log();
   1.204 +	TestBasicL(logBase, wrapper->ClientAvailable());
   1.205 +
   1.206 +	TBuf<KLogMaxSharedStringLength> buf;
   1.207 +	if (wrapper->ClientAvailable())
   1.208 +		{
   1.209 +		CLogBase& logBase2 = wrapper->Log();
   1.210 +		TEST2(logBase2.GetString(buf, R_LOG_DIR_IN), KErrNone);
   1.211 +		TEST(buf.Length() > 0);
   1.212 +		}
   1.213 +	else
   1.214 +		{
   1.215 +		CLogBase& logBase3 = wrapper->Log();
   1.216 +		TEST2(logBase3.GetString(buf, R_LOG_DIR_IN), KErrNotSupported);
   1.217 +		TEST(buf.Length() == 0);
   1.218 +		}
   1.219 +
   1.220 +	CleanupStack::PopAndDestroy(2); // wrapper, active
   1.221 +	}
   1.222 +
   1.223 +/**
   1.224 +@SYMTestCaseID          SYSLIB-LOGENG-CT-1013
   1.225 +@SYMTestCaseDesc	    Tests for out of memory errors on CLogWrapper::NewL() function call
   1.226 +@SYMTestPriority 	    High
   1.227 +@SYMTestActions  	    Check for no memory error condition
   1.228 +@SYMTestExpectedResults Test must not fail
   1.229 +@SYMREQ                 REQ0000
   1.230 +*/
   1.231 +LOCAL_C void TestHeapFailL()
   1.232 +	{
   1.233 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-1013 "));
   1.234 +	CLogWrapper* wrapper = NULL;
   1.235 +	
   1.236 +#ifdef _DEBUG
   1.237 +	TInt failCount = 0;
   1.238 +#endif
   1.239 +
   1.240 +	TBool finished = EFalse;
   1.241 +	TInt error;
   1.242 +	
   1.243 +	while(!finished)
   1.244 +		{
   1.245 +		__UHEAP_FAILNEXT(failCount++);
   1.246 +
   1.247 +		TRAP(error, wrapper = CLogWrapper::NewL(theFs));
   1.248 +
   1.249 +		__UHEAP_RESET;
   1.250 +
   1.251 +		if (error == KErrNone)
   1.252 +			{
   1.253 +			finished = ETrue;
   1.254 +			CLogBase& logBase = wrapper->Log();
   1.255 +			TestBasicL(logBase, wrapper->ClientAvailable());
   1.256 +			delete wrapper;
   1.257 +			}
   1.258 +		else
   1.259 +			TEST2(error, KErrNoMemory);
   1.260 +		}
   1.261 +	}
   1.262 +
   1.263 +/**
   1.264 +@SYMTestCaseID          SYSLIB-LOGENG-CT-1014
   1.265 +@SYMTestCaseDesc	    Tests for CLogWrapper::NewL() function 
   1.266 +@SYMTestPriority 	    High
   1.267 +@SYMTestActions  	    Create log wrapper on heap,if no error execute the basic event tests.
   1.268 +                        Check for general errors.
   1.269 +@SYMTestExpectedResults Test must not fail
   1.270 +@SYMREQ                 REQ0000
   1.271 +*/
   1.272 +LOCAL_C void TestFileFailL()
   1.273 +	{
   1.274 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-1014 "));
   1.275 +	CLogWrapper* wrapper = NULL;
   1.276 +	
   1.277 +	TInt failCount = 0;
   1.278 +	TBool finished = EFalse;
   1.279 +	TInt error;
   1.280 +	
   1.281 +	while(!finished)
   1.282 +		{
   1.283 +		TheTest.Printf(_L("%d  \r"), failCount);
   1.284 +		__FILE_FAILNEXT(KErrNoMemory, failCount++);
   1.285 +
   1.286 +		TRAP(error, wrapper = CLogWrapper::NewL(theFs));
   1.287 +
   1.288 +		__FILE_RESET;
   1.289 +
   1.290 +		if (error == KErrNone)
   1.291 +			{
   1.292 +			finished = ETrue;
   1.293 +			CLogBase& logBase = wrapper->Log();
   1.294 +			TestBasicL(logBase, wrapper->ClientAvailable());
   1.295 +			delete wrapper;
   1.296 +			}
   1.297 +		else
   1.298 +			{
   1.299 +			TEST2(error, KErrNoMemory);
   1.300 +			}
   1.301 +		}
   1.302 +	TheTest.Printf(_L("\r\nThe test has succeeded at iteration %d\n"), failCount);
   1.303 +	}
   1.304 +
   1.305 +/**
   1.306 +@SYMTestCaseID          SYSLIB-LOGENG-CT-1015
   1.307 +@SYMTestCaseDesc	    Tests for INC047632
   1.308 +@SYMTestPriority 	    High
   1.309 +@SYMTestActions  	    This test uses a stored copy of a corrupt database which is copied to z:\system\data.
   1.310 +						When this database ia accessed open returns an error KErrEof.
   1.311 +@SYMTestExpectedResults Test must not fail
   1.312 +@SYMREQ                 REQ0000
   1.313 +*/
   1.314 +LOCAL_C void Test4INC047632L()
   1.315 +	{
   1.316 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-1015 "));
   1.317 +#ifdef _DEBUG	
   1.318 +	TestUtils::CopyCorruptDbL();
   1.319 +
   1.320 +	// run basic test
   1.321 +	CLogWrapper* wrapper = NULL;
   1.322 +	
   1.323 +	TInt error = KErrNone;
   1.324 +	TRAP(error, wrapper = CLogWrapper::NewL(theFs));
   1.325 +
   1.326 +	if (error == KErrNone)
   1.327 +		{
   1.328 +		CLogBase& logBase = wrapper->Log();
   1.329 +		TestBasicL(logBase, wrapper->ClientAvailable());
   1.330 +		delete wrapper;
   1.331 +		}
   1.332 +#else
   1.333 +	RDebug::Print(_L("Test4INC047632L() can be executed only in debug mode. In release mode the LogEng server cannot be stopped.\n"));
   1.334 +#endif//_DEBUG
   1.335 +	}
   1.336 +/**
   1.337 +@SYMTestCaseID          SYSLIB-LOGENG-CT-4001
   1.338 +@SYMTestCaseDesc	    Tests for INC114909
   1.339 +@SYMTestPriority 	    High
   1.340 +@SYMTestActions  	    This test uses a stored copy of a corrupt damaged database which is 
   1.341 +						copied to z:\system\data.
   1.342 +						When an attempt is made to open the database the fault should be 
   1.343 +						recognised and the database deleted.
   1.344 +@SYMTestExpectedResults Test must not fail
   1.345 +@SYMDEF                 INC114909
   1.346 +*/
   1.347 +LOCAL_C void Test5INC114909L()
   1.348 +	{
   1.349 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-4001 "));
   1.350 +#ifdef _DEBUG	
   1.351 + 	// Copy over the damaged database to be used.
   1.352 +	TestUtils::CopyCorruptDamagedDbL();
   1.353 + 
   1.354 +	// run basic test
   1.355 +	CLogWrapper* wrapper = NULL;	
   1.356 +	TInt error = KErrNone;
   1.357 +	TRAP(error, wrapper = CLogWrapper::NewL(theFs));
   1.358 +	delete wrapper;
   1.359 +	
   1.360 +	// Without the code for this defect the error here will be KErrCorrupt.
   1.361 +	// and the log server will continually try to restart and be brought down
   1.362 +	// with KErrCorrupt 
   1.363 +	// With the fix the error with the database is detected on opening the database 
   1.364 +	// and the  database file is deleted and re-created.
   1.365 + 
   1.366 +	TEST(error == KErrNone);
   1.367 +	
   1.368 +	// Perform an extra check that the log server has not been brought down
   1.369 +	// as is the case without the defect fix.
   1.370 +	RLogTestSession theLogServ;
   1.371 +	error = theLogServ.Connect();
   1.372 + 	TEST(error == KErrNone);
   1.373 +#else
   1.374 +	RDebug::Print(_L("Test4INC047632L() can be executed only in debug mode. In release mode the LogEng server cannot be stopped.\n"));
   1.375 +#endif//_DEBUG
   1.376 +	}
   1.377 +
   1.378 +void doTestsL()
   1.379 +	{
   1.380 +	TestUtils::Initialize(_L("t_logwrap"));
   1.381 +
   1.382 +	TheTest.Start(_L("Wrapper"));
   1.383 +	TestWrapperL();
   1.384 +	theLog.Write(_L8("Test 1 OK\n"));
   1.385 +
   1.386 +	TheTest.Next(_L("Heap Failure"));
   1.387 +	TestHeapFailL();
   1.388 +	theLog.Write(_L8("Test 2 OK\n"));
   1.389 +
   1.390 +	TheTest.Next(_L("File Failure"));
   1.391 +	TestFileFailL();
   1.392 +	theLog.Write(_L8("Test 3 OK\n"));
   1.393 +
   1.394 +	TheTest.Next(_L("Test4 for INC047632 - corrupt Logdbu.dat returns KErrEoF"));
   1.395 +	Test4INC047632L();
   1.396 +	theLog.Write(_L8("Test 4 for INC047632 OK\n"));
   1.397 +	
   1.398 +	TheTest.Next(_L("Test5 for INC114909 - test damaged Logdbu.dat is dealt with correctly "));
   1.399 +	Test5INC114909L();
   1.400 +	theLog.Write(_L8("Test 5 for INC114909 OK\n"));
   1.401 +	}