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