|
1 // Copyright (c) 2000-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 // |
|
15 |
|
16 #include <e32std.h> |
|
17 #include <e32math.h> |
|
18 #include <e32test.h> |
|
19 #include <cntdb.h> |
|
20 #include <cntitem.h> |
|
21 #include <cntfldst.h> |
|
22 #include "t_utils2.h" |
|
23 #include <cntview.h> |
|
24 #include <cntviewbase.h> |
|
25 |
|
26 #include "t_groupviewmodifiedContact.h" |
|
27 |
|
28 // Test Macro |
|
29 LOCAL_D RTest test(_L("T_GROUPVIEWMODIFIEDCONTACT")); |
|
30 |
|
31 // |
|
32 // Constants. |
|
33 // |
|
34 _LIT(KTestName,"@SYMTESTCaseID:PIM-T-GROUPVIEWMODIFIEDCONTACT-0001 t_groupviewmodifiedcontact"); |
|
35 _LIT(KLogFileName,"t_groupviewmodifiedcontact.log"); |
|
36 |
|
37 _LIT(KDbFileName,"c:t_groupview.cdb"); |
|
38 |
|
39 _LIT(KGroupOneName,"GroupOne"); |
|
40 |
|
41 |
|
42 // |
|
43 // CTestConductor. |
|
44 // |
|
45 |
|
46 CTestConductor* CTestConductor::NewL() |
|
47 { |
|
48 CTestConductor* self=new(ELeave) CTestConductor(); |
|
49 CleanupStack::PushL(self); |
|
50 self->ConstructL(); |
|
51 self->RunTestsL(); |
|
52 CleanupStack::Pop(); |
|
53 return self; |
|
54 } |
|
55 |
|
56 CTestConductor::~CTestConductor() |
|
57 { |
|
58 delete iLog; |
|
59 delete iDb; |
|
60 TRAP_IGNORE(CContactDatabase::DeleteDatabaseL(KDbFileName)); |
|
61 iFs.Close(); |
|
62 } |
|
63 |
|
64 CTestConductor::CTestConductor() |
|
65 { |
|
66 } |
|
67 |
|
68 void CTestConductor::ConstructL() |
|
69 { |
|
70 User::LeaveIfError(iFs.Connect()); |
|
71 iLog=CLog::NewL(test,KLogFileName); |
|
72 iDb=CContactDatabase::ReplaceL(KDbFileName); |
|
73 } |
|
74 |
|
75 |
|
76 void CTestConductor::RunTestsL() |
|
77 { |
|
78 CGroupViewTester* tester=CGroupViewTester::NewL(*iLog, this, *iDb); |
|
79 CleanupStack::PushL(tester); |
|
80 CActiveScheduler::Start(); |
|
81 CleanupStack::Pop(tester); |
|
82 // error from CGroupViewTester? |
|
83 User::LeaveIfError(iTestError); |
|
84 } |
|
85 |
|
86 void CTestConductor::SetTestError(TInt aTestError) |
|
87 { |
|
88 iTestError = aTestError; |
|
89 } |
|
90 |
|
91 |
|
92 // |
|
93 // CGroupViewTester. |
|
94 // |
|
95 |
|
96 CGroupViewTester* CGroupViewTester::NewL(CLog& aLog, CTestConductor* aTestConductor, CContactDatabase& aDb) |
|
97 { |
|
98 CGroupViewTester* self=new(ELeave) CGroupViewTester(aLog, aTestConductor, aDb); |
|
99 CleanupStack::PushL(self); |
|
100 self->ConstructL(); |
|
101 CleanupStack::Pop(); |
|
102 return self; |
|
103 } |
|
104 |
|
105 CGroupViewTester::~CGroupViewTester() |
|
106 { |
|
107 iGroupViewOne->Close(*this); |
|
108 |
|
109 iLocalView->Close(*this); |
|
110 iSortOrder_1.Close(); |
|
111 |
|
112 delete iGroupOne; |
|
113 } |
|
114 |
|
115 CGroupViewTester::CGroupViewTester(CLog& aLog, CTestConductor* aTestConductor, CContactDatabase& aDb) |
|
116 : CActive(EPriorityStandard),iLog(aLog),iTestConductor(aTestConductor),iDb(aDb),iCurrentTest(-1) |
|
117 { |
|
118 CActiveScheduler::Add(this); |
|
119 } |
|
120 |
|
121 void CGroupViewTester::ConstructL() |
|
122 { |
|
123 iSortOrder_1.AppendL(KUidContactFieldGivenName); |
|
124 iSortOrder_1.AppendL(KUidContactFieldFamilyName); |
|
125 iSortOrder_1.AppendL(KUidContactFieldCompanyName); |
|
126 NextTest(); |
|
127 } |
|
128 |
|
129 |
|
130 void CGroupViewTester::RunL() |
|
131 { |
|
132 switch (iCurrentTest) |
|
133 { |
|
134 case ECreateLocalView: |
|
135 iLog.LogLine(_L("=== Create local view")); |
|
136 iLocalView=CContactLocalView::NewL(*this,iDb,iSortOrder_1,EContactAndGroups/*EContactsOnly*/); |
|
137 break; |
|
138 |
|
139 case ECreateGroupOne: |
|
140 iLog.LogLine(_L("==== Create Group \n")); |
|
141 iGroupOne = STATIC_CAST(CContactGroup*,iDb.CreateContactGroupL(KGroupOneName)); |
|
142 iGroupOneId = iGroupOne->Id(); |
|
143 delete iGroupOne; |
|
144 iGroupOne = NULL; |
|
145 iGroupOne = STATIC_CAST(CContactGroup*,iDb.ReadContactL(iGroupOneId)); |
|
146 |
|
147 break; |
|
148 |
|
149 case ECreateGroupOneView: |
|
150 { |
|
151 iLog.LogLine(_L("=== GroupOneView")); |
|
152 iGroupViewOne=CContactGroupView::NewL(iDb,*iLocalView,*this,iGroupOne->Id(),CContactGroupView::EShowContactsInGroup); |
|
153 } |
|
154 break; |
|
155 |
|
156 |
|
157 case EAddContact: |
|
158 { |
|
159 iLog.LogLine(_L("==== Add Contact \n")); |
|
160 CContactTemplate* templateContact=STATIC_CAST(CContactTemplate*,iDb.ReadContactL(iDb.TemplateId())); |
|
161 CleanupStack::PushL(templateContact); |
|
162 CTestContact* contact=CTestContact::NewLC(*templateContact); |
|
163 |
|
164 contact->SetFirstNameL(_L("FirstName")); |
|
165 |
|
166 contact->SetLastNameL(_L("LastName")); |
|
167 |
|
168 contact->SetCompanyNameL(_L("CompanyName")); |
|
169 |
|
170 contact->SetWorkPhoneL(_L("02079460090")); |
|
171 |
|
172 contact->SetWorkMobileL(_L("02079460789")); |
|
173 |
|
174 contact->SetHomePhoneL(_L("02079460987")); |
|
175 |
|
176 contact->SetWorkEmailAddressL(_L("work@email.com")); |
|
177 |
|
178 iSingleContactId = iDb.AddNewContactL(contact->ContactItem()); |
|
179 |
|
180 CleanupStack::PopAndDestroy(contact); |
|
181 CleanupStack::PopAndDestroy(templateContact); |
|
182 iNumNotificationExpected = 2; // Once for the total view, one for the group view. |
|
183 } |
|
184 |
|
185 break; |
|
186 |
|
187 case EAddContactToGroupOne: // since we've only one contact anyway - we can be sure it's id will be 1. |
|
188 iLog.LogLine(_L("==== Assign contact to Group \n")); |
|
189 iDb.AddContactToGroupL(iSingleContactId,iGroupOne->Id()); |
|
190 iNumNotificationExpected = 6; |
|
191 break; |
|
192 |
|
193 case EModifyContactInGroupOne: |
|
194 { |
|
195 iLog.LogLine(_L("==== Modify Contact \n")); |
|
196 CContactItem* contactToModify = iDb.OpenContactL(iSingleContactId); |
|
197 CleanupStack::PushL(contactToModify); |
|
198 CTestContact* testContactToModify = CTestContact::NewLC(*contactToModify); |
|
199 |
|
200 CContactItemFieldSet& fields = contactToModify->CardFields(); |
|
201 CContactItemField& lastNameField = fields[fields.Find(KUidContactFieldFamilyName)]; |
|
202 CContactTextField* lastNameTextField = static_cast<CContactTextField*>(lastNameField.Storage()); |
|
203 lastNameTextField->SetText(_L("modified_lastname").AllocL()); |
|
204 |
|
205 iDb.CommitContactL(*contactToModify); |
|
206 iDb.CloseContactL(1); |
|
207 CleanupStack::PopAndDestroy(testContactToModify); |
|
208 CleanupStack::PopAndDestroy(contactToModify); |
|
209 iNumNotificationExpected = 4; |
|
210 } |
|
211 |
|
212 break; |
|
213 |
|
214 case ENumTests: |
|
215 iLog.LogLine(_L("==== Group View Modified Contact Tests Finished, All Passed...\n")); |
|
216 CActiveScheduler::Stop(); |
|
217 delete this; |
|
218 break; |
|
219 default: |
|
220 ASSERT(EFalse); |
|
221 break; |
|
222 } |
|
223 } |
|
224 |
|
225 TInt CGroupViewTester::RunError(TInt aError) |
|
226 { |
|
227 // propagate error |
|
228 iTestConductor->SetTestError(aError); |
|
229 |
|
230 switch (iCurrentTest) |
|
231 { |
|
232 case ECreateLocalView: test.Printf(_L("Test failed at step CreateLocalView (%i) with error %i"), iCurrentTest, aError); break; |
|
233 case ECreateGroupOne: test.Printf(_L("Test failed at step CreateGroupOne (%i) with error %i"), iCurrentTest, aError); break; |
|
234 case ECreateGroupOneView: test.Printf(_L("Test failed at step CreateGroupOneView (%i) with error %i"), iCurrentTest, aError); break; |
|
235 case EAddContact: test.Printf(_L("Test failed at step AddContact (%i) with error %i"), iCurrentTest, aError); break; |
|
236 case EAddContactToGroupOne: test.Printf(_L("Test failed at step AddContactToGroupOne (%i) with error %i"), iCurrentTest, aError); break; |
|
237 case EModifyContactInGroupOne: test.Printf(_L("Test failed at step ModifyContactInGroupOne (%i) with error %i"), iCurrentTest, aError); break; |
|
238 |
|
239 case ENumTests: test.Printf(_L("Test failed at step NumTests (%i) with error %i"), iCurrentTest, aError); break; |
|
240 |
|
241 default: test.Printf(_L("Test failed at step %i with error %i"), iCurrentTest, aError); break; |
|
242 } |
|
243 |
|
244 CActiveScheduler::Stop(); |
|
245 return KErrNone; |
|
246 } |
|
247 |
|
248 void CGroupViewTester::HandleContactViewEvent(const CContactViewBase& aView,const TContactViewEvent& aEvent) |
|
249 { |
|
250 switch (iCurrentTest) |
|
251 { |
|
252 case ECreateLocalView: |
|
253 iLog.LogLine(_L("==== Handling the local view creation \n")); |
|
254 test(iLocalView==&aView); |
|
255 test(aEvent.iEventType==TContactViewEvent::EReady); |
|
256 break; |
|
257 |
|
258 case ECreateGroupOne: |
|
259 iLog.LogLine(_L("==== Handling the group creation \n")); |
|
260 break; |
|
261 |
|
262 case ECreateGroupOneView: |
|
263 iLog.LogLine(_L("==== Handling the group view creation \n")); |
|
264 test(iGroupViewOne==&aView); |
|
265 test(aEvent.iEventType==TContactViewEvent::EReady); |
|
266 break; |
|
267 |
|
268 case EAddContactToGroupOne: |
|
269 iLog.LogLine(_L("==== Handling the addition of a contact to the group \n")); |
|
270 break; |
|
271 |
|
272 case EAddContact: |
|
273 iLog.LogLine(_L("==== Handling the addition of a contact \n")); |
|
274 break; |
|
275 |
|
276 case EModifyContactInGroupOne: |
|
277 iLog.LogLine(_L("==== Handling Contact being modified. \n")); |
|
278 |
|
279 switch (aEvent.iEventType) |
|
280 { |
|
281 case TContactViewEvent::EItemRemoved: |
|
282 iLog.LogLine(_L("==== Contact Is removed for modify \n")); |
|
283 break; |
|
284 |
|
285 case TContactViewEvent::EItemAdded: |
|
286 iLog.LogLine(_L("==== Contact Is added for modify \n")); |
|
287 { |
|
288 TInt numberOfEntries = 0; |
|
289 TRAPD(err, numberOfEntries = aView.CountL() ); |
|
290 test(err == KErrNone && numberOfEntries != 0); |
|
291 } |
|
292 break; |
|
293 default: |
|
294 break; |
|
295 } |
|
296 break; |
|
297 |
|
298 case ENumTests: |
|
299 default: |
|
300 test(EFalse); |
|
301 break; |
|
302 } |
|
303 if (--iNumNotificationExpected<=0) |
|
304 { |
|
305 NextTest(); |
|
306 iNumNotificationExpected=0; |
|
307 } |
|
308 } |
|
309 |
|
310 void CGroupViewTester::NextTest() |
|
311 { |
|
312 ++iCurrentTest; |
|
313 TRequestStatus *pS=&iStatus; |
|
314 User::RequestComplete(pS,KErrNone); |
|
315 SetActive(); |
|
316 } |
|
317 |
|
318 |
|
319 |
|
320 |
|
321 |
|
322 |
|
323 void CGroupViewTester::DoCancel() |
|
324 { |
|
325 } |
|
326 |
|
327 // |
|
328 // Main. |
|
329 // |
|
330 |
|
331 /** |
|
332 |
|
333 @SYMTestCaseID PIM-T-GROUPVIEWMODIFIEDCONTACT-0001 |
|
334 |
|
335 */ |
|
336 |
|
337 GLDEF_C TInt E32Main() |
|
338 { |
|
339 __UHEAP_MARK; |
|
340 CActiveScheduler* scheduler=new CActiveScheduler; |
|
341 if (scheduler) |
|
342 { |
|
343 CActiveScheduler::Install(scheduler); |
|
344 CTrapCleanup* cleanup=CTrapCleanup::New(); |
|
345 if (cleanup) |
|
346 { |
|
347 CTestConductor* testConductor=NULL; |
|
348 test.Start(KTestName); |
|
349 |
|
350 TRAPD(err,testConductor=CTestConductor::NewL()); |
|
351 test(err == KErrNone); |
|
352 test.End(); |
|
353 test.Close(); |
|
354 delete testConductor; |
|
355 delete cleanup; |
|
356 } |
|
357 delete scheduler; |
|
358 } |
|
359 __UHEAP_MARKEND; |
|
360 return KErrNone; |
|
361 } |