1 // Copyright (c) 2004-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 // test code for INC045441 - Log Engine does not return events in sequence order |
|
15 // |
|
16 // |
|
17 |
|
18 #include <s32file.h> |
|
19 #include <e32math.h> |
|
20 #include <logview.h> |
|
21 #include "TEST.H" |
|
22 |
|
23 RTest test( _L( "Test sequence order of returned events" ) ); |
|
24 |
|
25 _LIT( KTestNumber1, "11111" ); |
|
26 _LIT( KTestNumber2, "22222" ); |
|
27 _LIT( KTestNumber3, "33333" ); |
|
28 |
|
29 #undef test //there is a "test" macro which hides "RTest test" declaration. |
|
30 |
|
31 /** |
|
32 Add an event to the log engine database. |
|
33 The event ID assigned by logengine is store in gTheId |
|
34 |
|
35 @param aClient |
|
36 @param aNumber The number that the event should contain |
|
37 @return The index for the event added. |
|
38 |
|
39 */ |
|
40 LOCAL_C TInt AddEventL( CLogClient& aClient, CLogEvent& aEvent, CTestActive& aActive, TInt aIndex ) |
|
41 { |
|
42 TInt returnId = KLogNullId; |
|
43 |
|
44 // Reset |
|
45 TTime now; |
|
46 now.UniversalTime(); |
|
47 |
|
48 aEvent.SetContact( aIndex ); |
|
49 |
|
50 // load the event with test values |
|
51 switch (aIndex) |
|
52 { |
|
53 case 1: |
|
54 aEvent.SetNumber( KTestNumber1 ); |
|
55 break; |
|
56 case 2: |
|
57 aEvent.SetNumber( KTestNumber2 ); |
|
58 break; |
|
59 case 3: |
|
60 aEvent.SetNumber( KTestNumber3 ); |
|
61 break; |
|
62 } |
|
63 |
|
64 // add the event to the logeng database |
|
65 aActive.StartL(); |
|
66 aClient.AddEvent( aEvent, aActive.iStatus ); |
|
67 CActiveScheduler::Start(); |
|
68 TEST2(aActive.iStatus.Int(), KErrNone); |
|
69 |
|
70 // check that an ID has been assigned |
|
71 returnId = aEvent.Id(); |
|
72 TEST( returnId != KLogNullId ); |
|
73 TEST( aEvent.Time() >= now ); |
|
74 |
|
75 // return the event id which has been assigned by the |
|
76 // log engine |
|
77 return returnId; |
|
78 } |
|
79 |
|
80 |
|
81 /** |
|
82 Get the event from the log engine database. |
|
83 |
|
84 @param aClient |
|
85 @param aTheId Unique id for the event to be fetch |
|
86 @param aNumber The number that the event should contain |
|
87 */ |
|
88 LOCAL_C void TestGetEventL( CLogClient& aClient, TInt aTheId, TInt aIndex ) |
|
89 |
|
90 { |
|
91 CTestActive* active = new( ELeave )CTestActive(); |
|
92 CleanupStack::PushL( active ); |
|
93 |
|
94 CLogEvent* event = CLogEvent::NewL(); |
|
95 CleanupStack::PushL( event ); |
|
96 |
|
97 event->SetId( aTheId ); |
|
98 |
|
99 active->StartL(); |
|
100 aClient.GetEvent( *event, active->iStatus ); |
|
101 CActiveScheduler::Start(); |
|
102 TEST2(active->iStatus.Int(), KErrNone); |
|
103 |
|
104 // check we got the right one back |
|
105 TEST( event->Contact() == aIndex ); |
|
106 |
|
107 TPtrC eventNumber = event->Number(); |
|
108 |
|
109 TBuf<30> dateString; |
|
110 _LIT( KDateString5, "%-B%:0%J%:1%T%:2%S%:3%+B" ); |
|
111 event->Time().FormatL( dateString, KDateString5 ); |
|
112 TPtrC eventDate = dateString.Ptr(); |
|
113 test.Printf( _L( "Id:%d No:%S Time:%S \n" ), event->Id(), &eventNumber, &eventDate ); |
|
114 |
|
115 CleanupStack::PopAndDestroy( 2 ); // event, active |
|
116 } |
|
117 |
|
118 /** |
|
119 Test code for INC045441 - Log Engine does not return events in sequence order |
|
120 |
|
121 @SYMTestCaseID SYSLIB-LOGENG-CT-1020 |
|
122 @SYMTestCaseDesc Tests for checking the sequence order on events returned by log engine |
|
123 @SYMTestPriority High |
|
124 @SYMTestActions Test for getting the event in order as they were added to the log |
|
125 Check for memory and no error |
|
126 @SYMTestExpectedResults Test must not fail |
|
127 @SYMREQ REQ0000 |
|
128 */ |
|
129 LOCAL_C void TestRecentViewOrderingL( CLogClient& aClient ) |
|
130 // |
|
131 // |
|
132 // |
|
133 { |
|
134 test.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-1020 ")); |
|
135 CLogEvent* event = CLogEvent::NewL(); |
|
136 CleanupStack::PushL(event); |
|
137 |
|
138 CTestActive* active = new( ELeave )CTestActive(); |
|
139 CleanupStack::PushL( active ); |
|
140 |
|
141 CLogViewRecent* view = CLogViewRecent::NewL( aClient ); |
|
142 CleanupStack::PushL( view ); |
|
143 |
|
144 TBuf<KLogMaxDirectionLength> buf; |
|
145 aClient.GetString(buf, R_LOG_DIR_MISSED); |
|
146 |
|
147 event->SetEventType( KLogCallEventTypeUid ); |
|
148 event->SetDirection( buf ); |
|
149 |
|
150 TEST( !view->SetRecentListL( KLogRecentMissedCalls, active->iStatus ) ); |
|
151 TEST( view->CountL() == 0 ); |
|
152 |
|
153 TTime time; |
|
154 test.Next( _L( "add new event 1" ) ); |
|
155 TInt eventId1 = AddEventL( aClient, *event, *active, 1 ); |
|
156 TestGetEventL( aClient, eventId1, 1 ); |
|
157 |
|
158 test.Next( _L( "time plus 10 mins - add new event 2" ) ); |
|
159 time.HomeTime(); |
|
160 TTimeIntervalMinutes timeTravelForward( 10 ); |
|
161 time += timeTravelForward; |
|
162 User::SetHomeTime( time ); |
|
163 TInt eventId2 = AddEventL( aClient, *event, *active, 2 ); |
|
164 TestGetEventL( aClient, eventId2, 2 ); |
|
165 |
|
166 test.Next( _L( "time minus 5 mins - add new event 3" ) ); |
|
167 time.HomeTime(); |
|
168 TTimeIntervalMinutes timeTravelBackward( 5 ); |
|
169 time -= timeTravelBackward; |
|
170 User::SetHomeTime( time ); |
|
171 TInt eventId3 = AddEventL( aClient, *event, *active, 3 ); |
|
172 TestGetEventL( aClient, eventId3, 3 ); |
|
173 |
|
174 TEST( view->CountL() == 3 ); |
|
175 |
|
176 active->StartL(); |
|
177 // Get most recent |
|
178 TEST( view->FirstL( active->iStatus ) ); |
|
179 CActiveScheduler::Start(); |
|
180 TEST2(active->iStatus.Int(), KErrNone); |
|
181 |
|
182 TInt id3 = view->Event().Id(); |
|
183 // Get the one before that |
|
184 active->StartL(); |
|
185 TEST( view->NextL( active->iStatus ) ); |
|
186 CActiveScheduler::Start(); |
|
187 TEST2(active->iStatus.Int(), KErrNone); |
|
188 TInt id2 = view->Event().Id(); |
|
189 |
|
190 // Get the one before that |
|
191 active->StartL(); |
|
192 TEST( view->NextL( active->iStatus ) ); |
|
193 CActiveScheduler::Start(); |
|
194 TEST2(active->iStatus.Int(), KErrNone); |
|
195 TInt id1 = view->Event().Id(); |
|
196 |
|
197 TEST( id1 == eventId1 ); |
|
198 TEST( id2 == eventId2 ); |
|
199 TEST( id3 == eventId3 ); |
|
200 |
|
201 CleanupStack::PopAndDestroy( 3 ); // view, active, event |
|
202 theLog.Write( _L8( "Test 1.1 OK\n" ) ); |
|
203 } |
|
204 |
|
205 |
|
206 |
|
207 void doTestsL() |
|
208 { |
|
209 TestUtils::Initialize( _L( "T_OrderById" ) ); |
|
210 TestUtils::DeleteDatabaseL(); |
|
211 |
|
212 CLogClient* client = CLogClient::NewL( theFs ); |
|
213 CleanupStack::PushL( client ); |
|
214 |
|
215 CLogChangeNotifier* notifier = CLogChangeNotifier::NewL(); |
|
216 CleanupStack::PushL( notifier ); |
|
217 |
|
218 test.Start( _L( "Recent view sorts by Id not ETime" ) ); |
|
219 TestRecentViewOrderingL( *client ); |
|
220 theLog.Write( _L8( "Test 1 OK\n" ) ); |
|
221 |
|
222 CleanupStack::PopAndDestroy( 2 ); // notifier, client; |
|
223 } |
|