loggingservices/eventlogger/test/src/t_logmaxnumlen.cpp
branchRCL_3
changeset 9 667e88a979d7
equal deleted inserted replaced
8:fa9941cf3867 9:667e88a979d7
       
     1 // Copyright (c) 2005-2010 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 // test code for INC041118 - Numberfield in logdatabase/engine is too small
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <s32file.h>
       
    19 #include <e32math.h>
       
    20 #include <bautils.h>
       
    21 #include "t_logutil2.h"
       
    22 
       
    23 RTest TheTest(_L("t_logmaxnumlen"));
       
    24 
       
    25 _LIT(KTestEventDesc1, "Event Type Description");
       
    26 _LIT(KTestRemoteParty1, "Remote Party");
       
    27 _LIT(KTestDirection1, "Direction");
       
    28 _LIT(KTestStatus1, "Status");
       
    29 _LIT(KTestSubject1, "Subject");
       
    30 
       
    31 
       
    32 // These values are stored in "oldLogdb.dat"
       
    33 _LIT(KTestEvent0, "00000");
       
    34 _LIT(KTestEvent1, "11111");
       
    35 _LIT(KTestEvent2, "22222");
       
    36 
       
    37 const TUid KTestEventUid = {0x10005393};
       
    38 const TLogDurationType KTestDurationType1 = 1;
       
    39 const TLogDuration KTestDuration1 = 0x1234;
       
    40 const TLogContactItemId KTestContact1 = 0x1234;
       
    41 const TLogLink KTestLink1 = 0x1234;
       
    42 _LIT8(KTestData1, "ABCDEFGH");
       
    43 const TLogFlags KTestFlags1 = 0x5;
       
    44 
       
    45 
       
    46 // with this value the test will ONLY pass with the new database
       
    47 _LIT(KTestNumberMax, 
       
    48 	"0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789");
       
    49 
       
    50 // This test needs a number > 32 to check that database has been converted
       
    51 _LIT(KTestNumber50, "01234567890123456789012345678901234567890123456789");
       
    52 _LIT(KTestNumberMin, "0");
       
    53 
       
    54 // this coresponds to an event already stored in oldLogDb.dat 
       
    55 const TInt KoldId = 3;
       
    56 _LIT(KTestOldDbNumber, "012345678901234567");
       
    57 
       
    58 
       
    59 /**
       
    60 @SYMTestCaseID          SYSLIB-LOGENG-CT-1336
       
    61 @SYMTestCaseDesc	    Tests for adding events to the log engine database
       
    62 @SYMTestPriority 	    High
       
    63 @SYMTestActions  	    Check for event ID assigned by log engine
       
    64 @SYMTestExpectedResults Test must not fail
       
    65 @SYMREQ                 REQ0000
       
    66 */
       
    67 TInt TestAddEventL(CLogClient& aClient, const TDesC &aNumber)
       
    68 	{
       
    69 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-1336 "));
       
    70 	TInt returnId = KLogNullId;
       
    71 
       
    72 	CTestActive* active = new(ELeave)CTestActive();
       
    73 	CleanupStack::PushL(active);
       
    74 
       
    75 	// create a new event
       
    76 	CLogEvent* event = CLogEvent::NewL();
       
    77 	CleanupStack::PushL(event);
       
    78 
       
    79 	// Reset
       
    80 	TTime now;
       
    81 	now.UniversalTime();
       
    82 
       
    83 	// load the event with test values
       
    84 	event->SetEventType(KTestEventUid);
       
    85 	event->SetRemoteParty(KTestRemoteParty1);
       
    86 	event->SetDirection(KTestDirection1);
       
    87 	event->SetDurationType(KTestDurationType1);
       
    88 	event->SetDuration(KTestDuration1);
       
    89 	event->SetStatus(KTestStatus1);
       
    90 	event->SetSubject(KTestSubject1);
       
    91 	event->SetNumber(aNumber);
       
    92 	event->SetContact(KTestContact1);
       
    93 	event->SetLink(KTestLink1);
       
    94 	event->SetDataL(KTestData1);
       
    95 	event->SetFlags(KTestFlags1);
       
    96 
       
    97 	// add the event to the logeng database
       
    98 	active->StartL();
       
    99 	aClient.AddEvent(*event, active->iStatus);
       
   100 
       
   101 	CActiveScheduler::Start();
       
   102 	TEST(!active->IsActive());
       
   103 	aClient.Cancel();
       
   104 	TEST2(active->iStatus.Int(), KErrNone);
       
   105 
       
   106 	// check that an ID has been assigned
       
   107 	returnId = event->Id();
       
   108 	TEST(returnId != KLogNullId);
       
   109 	
       
   110 	TEST(event->Time() >= now);
       
   111 	TEST(event->Description() == KTestEventDesc1);
       
   112 	
       
   113 	CleanupStack::PopAndDestroy(2); // event, active
       
   114 	
       
   115 	// return the event id which has been assigned by the 
       
   116 	// log engine
       
   117 	return returnId;
       
   118 	}
       
   119 
       
   120 /**
       
   121 @SYMTestCaseID          SYSLIB-LOGENG-CT-1337
       
   122 @SYMTestCaseDesc	    Tests for getting the event from the log engine database
       
   123 @SYMTestPriority 	    High
       
   124 @SYMTestActions  	    Tests for CLogClient::GetEvent() function
       
   125 @SYMTestExpectedResults Test must not fail
       
   126 @SYMREQ                 REQ0000
       
   127 */
       
   128 void TestGetEventL(CLogClient& aClient, TInt aTheId, const TDesC& aNumber)
       
   129 
       
   130 	{
       
   131 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-1337 "));
       
   132 	CTestActive* active = new(ELeave)CTestActive();
       
   133 	CleanupStack::PushL(active);
       
   134 
       
   135 	CLogEvent* event = CLogEvent::NewL();
       
   136 	CleanupStack::PushL(event);
       
   137 
       
   138 	// set the id of the event to be fetched
       
   139 	event->SetId(aTheId);
       
   140 
       
   141 	active->StartL();
       
   142 	aClient.GetEvent(*event, active->iStatus);
       
   143 	CActiveScheduler::Start();
       
   144 	aClient.Cancel();
       
   145 	TEST2(active->iStatus.Int(), KErrNone);
       
   146 		
       
   147 	TEST(event->Id() == aTheId);
       
   148 	TEST(event->Time() > TTime(0));
       
   149 	TEST(event->Description() == KTestEventDesc1);
       
   150 	TEST(event->EventType() == KTestEventUid);
       
   151 	TEST(event->RemoteParty() == KTestRemoteParty1);
       
   152 	TEST(event->Direction() == KTestDirection1);
       
   153 	TEST(event->DurationType() == KTestDurationType1);
       
   154 	TEST(event->Duration() == KTestDuration1);
       
   155 	TEST(event->Status() == KTestStatus1);
       
   156 	TEST(event->Subject() == KTestSubject1);
       
   157 	TEST(event->Contact() == KTestContact1);
       
   158 	TEST(event->Link() == KTestLink1);
       
   159 	TEST(event->Data() == KTestData1);
       
   160 	TEST(event->Flags() == KTestFlags1);
       
   161 
       
   162 	// this is the important test
       
   163 	// check the number has not been truncated
       
   164 	TEST(event->Number() == aNumber);
       
   165 
       
   166 	TPtrC eventStatus = event->Subject();
       
   167 	TPtrC eventNumber = event->Number();
       
   168 	TheTest.Printf(_L("Id:%d No:%S Sub:%S Con:0x%x \n"), 
       
   169 		event->Id(), &eventNumber, &eventStatus, event->Contact());
       
   170 	
       
   171 	CleanupStack::PopAndDestroy(2); // event, active
       
   172 	}
       
   173 
       
   174 
       
   175 /**
       
   176 Test code for INC041118 - Numberfield in logdatabase/engine is too small
       
   177 This is the main part of the test
       
   178 
       
   179 @SYMTestCaseID          SYSLIB-LOGENG-CT-1019
       
   180 @SYMTestCaseDesc	    Tests for number field in logdatabase/engine is too small
       
   181 @SYMTestPriority 	    High
       
   182 @SYMTestActions  	    Add an event to the log engine database.When the database is opened it should be
       
   183                         converted to new format.Check by reading the event and checking the number length
       
   184                         Check with maximum and minimum number field
       
   185 @SYMTestExpectedResults Test must not fail
       
   186 @SYMREQ                 REQ0000
       
   187 */
       
   188 void TestStartupL()
       
   189 	{
       
   190 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-1019 "));
       
   191 	TestUtils::CopyOldDbL();
       
   192 	
       
   193 	// add an event to the log engine database.
       
   194 	// When the database is opened it should be checked for the old numberfield length
       
   195 	// and converted to the new format if required. (It will be required, as old db has been copied)
       
   196 	CLogClient* client = CLogClient::NewL(theFs);
       
   197 	CleanupStack::PushL(client);
       
   198 	User::After(1000000);
       
   199 	TheTest.Next(_L("check database conversion"));
       
   200 	TInt eventId = TestAddEventL(*client, KTestNumber50 );
       
   201 
       
   202 	// check that the database has been converted to the new format
       
   203 	// by reading back an event the checking that number is the
       
   204 	// correct length
       
   205 	TestGetEventL(*client, eventId, KTestNumber50);
       
   206 	
       
   207 	// check using Max
       
   208 	TheTest.Next(_L("check a maxium length number"));
       
   209 	eventId = TestAddEventL(*client, KTestNumberMax );
       
   210 	TestGetEventL(*client, eventId, KTestNumberMax);
       
   211 
       
   212 	// check using Min
       
   213 	TheTest.Next(_L("check a mimium length number"));
       
   214 	eventId = TestAddEventL(*client, KTestNumberMin );
       
   215 	TestGetEventL(*client, eventId, KTestNumberMin);
       
   216 
       
   217 	// When OldLogdbu.dat was created, using TestBuildTestDbL() below,
       
   218 	// 4 events were stored.  Check that these can still be accessed.
       
   219 	// Note: There was a problem here with old events being purged after 30 days
       
   220 	// This was fixed by setting TLogConfig::iMaxEventAge = 0 in OldLogdb.dat 
       
   221 	TheTest.Next(_L("check all events in the old database"));
       
   222 	TestGetEventL(*client, 0, KTestEvent0);
       
   223 	TestGetEventL(*client, 1, KTestEvent1);
       
   224 	TestGetEventL(*client, 2, KTestEvent2);
       
   225 	TestGetEventL(*client, KoldId, KTestOldDbNumber);
       
   226 
       
   227 	CleanupStack::PopAndDestroy(); // client
       
   228 	}
       
   229 
       
   230 // Test code for INC041118 - Numberfield in logdatabase/engine is too small
       
   231 void doTestsL()
       
   232 	{
       
   233 	TestUtils::Initialize(_L("t_logmaxnumlen"));
       
   234 #ifdef _DEBUG	
       
   235 	TheTest.Start(_L("T_MaxNumberLength Set/Check Phone Number Maximum Length"));
       
   236 
       
   237 	TestStartupL();
       
   238 	theLog.Write(_L8("Test T_MAXNUMBERLENGTH OK\n"));
       
   239 #else
       
   240 	TheTest.Start(_L("This test works only in debug mode, otherwise the LogEng server cannot be stopped. See TestUtils::CopyOldDbL()"));
       
   241 #endif//_DEBUG	
       
   242 	}