os/persistentdata/loggingservices/eventlogger/test/src/t_logmaxnumlen.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_logmaxnumlen.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,242 @@
     1.4 +// Copyright (c) 2005-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 +// test code for INC041118 - Numberfield in logdatabase/engine is too small
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <s32file.h>
    1.22 +#include <e32math.h>
    1.23 +#include <bautils.h>
    1.24 +#include "t_logutil2.h"
    1.25 +
    1.26 +RTest TheTest(_L("t_logmaxnumlen"));
    1.27 +
    1.28 +_LIT(KTestEventDesc1, "Event Type Description");
    1.29 +_LIT(KTestRemoteParty1, "Remote Party");
    1.30 +_LIT(KTestDirection1, "Direction");
    1.31 +_LIT(KTestStatus1, "Status");
    1.32 +_LIT(KTestSubject1, "Subject");
    1.33 +
    1.34 +
    1.35 +// These values are stored in "oldLogdb.dat"
    1.36 +_LIT(KTestEvent0, "00000");
    1.37 +_LIT(KTestEvent1, "11111");
    1.38 +_LIT(KTestEvent2, "22222");
    1.39 +
    1.40 +const TUid KTestEventUid = {0x10005393};
    1.41 +const TLogDurationType KTestDurationType1 = 1;
    1.42 +const TLogDuration KTestDuration1 = 0x1234;
    1.43 +const TLogContactItemId KTestContact1 = 0x1234;
    1.44 +const TLogLink KTestLink1 = 0x1234;
    1.45 +_LIT8(KTestData1, "ABCDEFGH");
    1.46 +const TLogFlags KTestFlags1 = 0x5;
    1.47 +
    1.48 +
    1.49 +// with this value the test will ONLY pass with the new database
    1.50 +_LIT(KTestNumberMax, 
    1.51 +	"0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789");
    1.52 +
    1.53 +// This test needs a number > 32 to check that database has been converted
    1.54 +_LIT(KTestNumber50, "01234567890123456789012345678901234567890123456789");
    1.55 +_LIT(KTestNumberMin, "0");
    1.56 +
    1.57 +// this coresponds to an event already stored in oldLogDb.dat 
    1.58 +const TInt KoldId = 3;
    1.59 +_LIT(KTestOldDbNumber, "012345678901234567");
    1.60 +
    1.61 +
    1.62 +/**
    1.63 +@SYMTestCaseID          SYSLIB-LOGENG-CT-1336
    1.64 +@SYMTestCaseDesc	    Tests for adding events to the log engine database
    1.65 +@SYMTestPriority 	    High
    1.66 +@SYMTestActions  	    Check for event ID assigned by log engine
    1.67 +@SYMTestExpectedResults Test must not fail
    1.68 +@SYMREQ                 REQ0000
    1.69 +*/
    1.70 +TInt TestAddEventL(CLogClient& aClient, const TDesC &aNumber)
    1.71 +	{
    1.72 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-1336 "));
    1.73 +	TInt returnId = KLogNullId;
    1.74 +
    1.75 +	CTestActive* active = new(ELeave)CTestActive();
    1.76 +	CleanupStack::PushL(active);
    1.77 +
    1.78 +	// create a new event
    1.79 +	CLogEvent* event = CLogEvent::NewL();
    1.80 +	CleanupStack::PushL(event);
    1.81 +
    1.82 +	// Reset
    1.83 +	TTime now;
    1.84 +	now.UniversalTime();
    1.85 +
    1.86 +	// load the event with test values
    1.87 +	event->SetEventType(KTestEventUid);
    1.88 +	event->SetRemoteParty(KTestRemoteParty1);
    1.89 +	event->SetDirection(KTestDirection1);
    1.90 +	event->SetDurationType(KTestDurationType1);
    1.91 +	event->SetDuration(KTestDuration1);
    1.92 +	event->SetStatus(KTestStatus1);
    1.93 +	event->SetSubject(KTestSubject1);
    1.94 +	event->SetNumber(aNumber);
    1.95 +	event->SetContact(KTestContact1);
    1.96 +	event->SetLink(KTestLink1);
    1.97 +	event->SetDataL(KTestData1);
    1.98 +	event->SetFlags(KTestFlags1);
    1.99 +
   1.100 +	// add the event to the logeng database
   1.101 +	active->StartL();
   1.102 +	aClient.AddEvent(*event, active->iStatus);
   1.103 +
   1.104 +	CActiveScheduler::Start();
   1.105 +	TEST(!active->IsActive());
   1.106 +	aClient.Cancel();
   1.107 +	TEST2(active->iStatus.Int(), KErrNone);
   1.108 +
   1.109 +	// check that an ID has been assigned
   1.110 +	returnId = event->Id();
   1.111 +	TEST(returnId != KLogNullId);
   1.112 +	
   1.113 +	TEST(event->Time() >= now);
   1.114 +	TEST(event->Description() == KTestEventDesc1);
   1.115 +	
   1.116 +	CleanupStack::PopAndDestroy(2); // event, active
   1.117 +	
   1.118 +	// return the event id which has been assigned by the 
   1.119 +	// log engine
   1.120 +	return returnId;
   1.121 +	}
   1.122 +
   1.123 +/**
   1.124 +@SYMTestCaseID          SYSLIB-LOGENG-CT-1337
   1.125 +@SYMTestCaseDesc	    Tests for getting the event from the log engine database
   1.126 +@SYMTestPriority 	    High
   1.127 +@SYMTestActions  	    Tests for CLogClient::GetEvent() function
   1.128 +@SYMTestExpectedResults Test must not fail
   1.129 +@SYMREQ                 REQ0000
   1.130 +*/
   1.131 +void TestGetEventL(CLogClient& aClient, TInt aTheId, const TDesC& aNumber)
   1.132 +
   1.133 +	{
   1.134 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-1337 "));
   1.135 +	CTestActive* active = new(ELeave)CTestActive();
   1.136 +	CleanupStack::PushL(active);
   1.137 +
   1.138 +	CLogEvent* event = CLogEvent::NewL();
   1.139 +	CleanupStack::PushL(event);
   1.140 +
   1.141 +	// set the id of the event to be fetched
   1.142 +	event->SetId(aTheId);
   1.143 +
   1.144 +	active->StartL();
   1.145 +	aClient.GetEvent(*event, active->iStatus);
   1.146 +	CActiveScheduler::Start();
   1.147 +	aClient.Cancel();
   1.148 +	TEST2(active->iStatus.Int(), KErrNone);
   1.149 +		
   1.150 +	TEST(event->Id() == aTheId);
   1.151 +	TEST(event->Time() > TTime(0));
   1.152 +	TEST(event->Description() == KTestEventDesc1);
   1.153 +	TEST(event->EventType() == KTestEventUid);
   1.154 +	TEST(event->RemoteParty() == KTestRemoteParty1);
   1.155 +	TEST(event->Direction() == KTestDirection1);
   1.156 +	TEST(event->DurationType() == KTestDurationType1);
   1.157 +	TEST(event->Duration() == KTestDuration1);
   1.158 +	TEST(event->Status() == KTestStatus1);
   1.159 +	TEST(event->Subject() == KTestSubject1);
   1.160 +	TEST(event->Contact() == KTestContact1);
   1.161 +	TEST(event->Link() == KTestLink1);
   1.162 +	TEST(event->Data() == KTestData1);
   1.163 +	TEST(event->Flags() == KTestFlags1);
   1.164 +
   1.165 +	// this is the important test
   1.166 +	// check the number has not been truncated
   1.167 +	TEST(event->Number() == aNumber);
   1.168 +
   1.169 +	TPtrC eventStatus = event->Subject();
   1.170 +	TPtrC eventNumber = event->Number();
   1.171 +	TheTest.Printf(_L("Id:%d No:%S Sub:%S Con:0x%x \n"), 
   1.172 +		event->Id(), &eventNumber, &eventStatus, event->Contact());
   1.173 +	
   1.174 +	CleanupStack::PopAndDestroy(2); // event, active
   1.175 +	}
   1.176 +
   1.177 +
   1.178 +/**
   1.179 +Test code for INC041118 - Numberfield in logdatabase/engine is too small
   1.180 +This is the main part of the test
   1.181 +
   1.182 +@SYMTestCaseID          SYSLIB-LOGENG-CT-1019
   1.183 +@SYMTestCaseDesc	    Tests for number field in logdatabase/engine is too small
   1.184 +@SYMTestPriority 	    High
   1.185 +@SYMTestActions  	    Add an event to the log engine database.When the database is opened it should be
   1.186 +                        converted to new format.Check by reading the event and checking the number length
   1.187 +                        Check with maximum and minimum number field
   1.188 +@SYMTestExpectedResults Test must not fail
   1.189 +@SYMREQ                 REQ0000
   1.190 +*/
   1.191 +void TestStartupL()
   1.192 +	{
   1.193 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-1019 "));
   1.194 +	TestUtils::CopyOldDbL();
   1.195 +	
   1.196 +	// add an event to the log engine database.
   1.197 +	// When the database is opened it should be checked for the old numberfield length
   1.198 +	// and converted to the new format if required. (It will be required, as old db has been copied)
   1.199 +	CLogClient* client = CLogClient::NewL(theFs);
   1.200 +	CleanupStack::PushL(client);
   1.201 +	User::After(1000000);
   1.202 +	TheTest.Next(_L("check database conversion"));
   1.203 +	TInt eventId = TestAddEventL(*client, KTestNumber50 );
   1.204 +
   1.205 +	// check that the database has been converted to the new format
   1.206 +	// by reading back an event the checking that number is the
   1.207 +	// correct length
   1.208 +	TestGetEventL(*client, eventId, KTestNumber50);
   1.209 +	
   1.210 +	// check using Max
   1.211 +	TheTest.Next(_L("check a maxium length number"));
   1.212 +	eventId = TestAddEventL(*client, KTestNumberMax );
   1.213 +	TestGetEventL(*client, eventId, KTestNumberMax);
   1.214 +
   1.215 +	// check using Min
   1.216 +	TheTest.Next(_L("check a mimium length number"));
   1.217 +	eventId = TestAddEventL(*client, KTestNumberMin );
   1.218 +	TestGetEventL(*client, eventId, KTestNumberMin);
   1.219 +
   1.220 +	// When OldLogdbu.dat was created, using TestBuildTestDbL() below,
   1.221 +	// 4 events were stored.  Check that these can still be accessed.
   1.222 +	// Note: There was a problem here with old events being purged after 30 days
   1.223 +	// This was fixed by setting TLogConfig::iMaxEventAge = 0 in OldLogdb.dat 
   1.224 +	TheTest.Next(_L("check all events in the old database"));
   1.225 +	TestGetEventL(*client, 0, KTestEvent0);
   1.226 +	TestGetEventL(*client, 1, KTestEvent1);
   1.227 +	TestGetEventL(*client, 2, KTestEvent2);
   1.228 +	TestGetEventL(*client, KoldId, KTestOldDbNumber);
   1.229 +
   1.230 +	CleanupStack::PopAndDestroy(); // client
   1.231 +	}
   1.232 +
   1.233 +// Test code for INC041118 - Numberfield in logdatabase/engine is too small
   1.234 +void doTestsL()
   1.235 +	{
   1.236 +	TestUtils::Initialize(_L("t_logmaxnumlen"));
   1.237 +#ifdef _DEBUG	
   1.238 +	TheTest.Start(_L("T_MaxNumberLength Set/Check Phone Number Maximum Length"));
   1.239 +
   1.240 +	TestStartupL();
   1.241 +	theLog.Write(_L8("Test T_MAXNUMBERLENGTH OK\n"));
   1.242 +#else
   1.243 +	TheTest.Start(_L("This test works only in debug mode, otherwise the LogEng server cannot be stopped. See TestUtils::CopyOldDbL()"));
   1.244 +#endif//_DEBUG	
   1.245 +	}