|
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 // |
|
15 |
|
16 #include <e32test.h> |
|
17 #include <e32panic.h> |
|
18 #include <cntfldst.h> |
|
19 #include <cntdb.h> |
|
20 #include <cntitem.h> |
|
21 #include <cntdef.h> |
|
22 |
|
23 #include <cntviewbase.h> |
|
24 #include <cntview.h> |
|
25 |
|
26 |
|
27 static RTest test(_L("T_DBFill")) ; |
|
28 |
|
29 |
|
30 _LIT(KTestName,"@SYMTESTCaseID:PIM-T-DBFILL-0001 T_DBFill"); |
|
31 _LIT(KDBFilled,"Database Filled"); |
|
32 _LIT(KViewUpdated,"View Updated"); |
|
33 _LIT(KTestFailed,"RTEST: FAILED : T_DBFill test completed Failed!"); |
|
34 |
|
35 |
|
36 class CTestConductor : public CActive, public MContactViewObserver |
|
37 { |
|
38 |
|
39 public: |
|
40 CTestConductor(); |
|
41 void ConstructL(); |
|
42 void RunTestsL(); |
|
43 static CTestConductor* NewL() ; |
|
44 ~CTestConductor() ; |
|
45 void HandleContactViewEvent(const CContactViewBase &aView, |
|
46 const TContactViewEvent &aEvent) ; |
|
47 protected: |
|
48 void RunL(); |
|
49 void DoCancel(); |
|
50 void RunError(); |
|
51 |
|
52 private: |
|
53 CContactDatabase* iContactsDatabase; |
|
54 TContactItemId iGroupID ; |
|
55 CContactNamedRemoteView *irview ; |
|
56 CContactGroupView *igview ; |
|
57 CContactIdArray* imemberArray ; |
|
58 RTimer iTimer; |
|
59 TBool iFailed; |
|
60 }; |
|
61 |
|
62 |
|
63 void CTestConductor::HandleContactViewEvent(const CContactViewBase &aView, const TContactViewEvent &aEvent) |
|
64 { |
|
65 if ((aEvent.iEventType == TContactViewEvent::EItemRemoved) |
|
66 && (aEvent.iContactId == iGroupID) && (&aView == igview)) |
|
67 { |
|
68 // Check whether items from imemberArray are in the view |
|
69 // checking one item is good enough for this test |
|
70 TContactItemId id = (*imemberArray)[0]; |
|
71 TRAPD(err, igview->FindL(id)) |
|
72 if (err == KErrNone) |
|
73 { |
|
74 // the view has been updated |
|
75 test.Printf(KViewUpdated); |
|
76 CActiveScheduler::Stop(); |
|
77 } |
|
78 } |
|
79 |
|
80 } |
|
81 |
|
82 CTestConductor* CTestConductor::NewL() |
|
83 { |
|
84 CTestConductor* self=new(ELeave) CTestConductor(); |
|
85 CleanupStack::PushL(self); |
|
86 self->ConstructL(); |
|
87 self->RunTestsL(); |
|
88 CleanupStack::Pop(); |
|
89 return self; |
|
90 } |
|
91 |
|
92 CTestConductor::~CTestConductor() |
|
93 { |
|
94 |
|
95 Cancel(); |
|
96 iTimer.Close(); |
|
97 |
|
98 delete iContactsDatabase; |
|
99 |
|
100 |
|
101 } |
|
102 |
|
103 CTestConductor::CTestConductor() : CActive(0), iFailed(EFalse) |
|
104 { |
|
105 |
|
106 CActiveScheduler::Add(this); |
|
107 iTimer.CreateLocal(); |
|
108 |
|
109 } |
|
110 |
|
111 void CTestConductor::ConstructL() |
|
112 { |
|
113 |
|
114 iContactsDatabase=CContactDatabase::ReplaceL(); |
|
115 |
|
116 } |
|
117 |
|
118 void CTestConductor::RunL() |
|
119 { |
|
120 |
|
121 iFailed = ETrue; |
|
122 CActiveScheduler::Stop() ; //timeout expired - stop executing |
|
123 |
|
124 } |
|
125 |
|
126 void CTestConductor::RunError() |
|
127 { |
|
128 |
|
129 } |
|
130 |
|
131 void CTestConductor::DoCancel() |
|
132 { |
|
133 iTimer.Cancel(); |
|
134 } |
|
135 |
|
136 void CTestConductor::RunTestsL() |
|
137 { |
|
138 |
|
139 //DBFill |
|
140 _LIT(KText, "Group1") ; |
|
141 TBufC<30> g1(KText) ; |
|
142 CContactGroup *group1 = static_cast<CContactGroup*> (iContactsDatabase->CreateContactGroupL(g1)) ; |
|
143 CleanupStack::PushL(group1); |
|
144 |
|
145 TContactItemId id1 = group1->Id(); |
|
146 |
|
147 CContactCard* contact1 = CContactCard::NewL(); |
|
148 CleanupStack::PushL(contact1); |
|
149 |
|
150 TContactItemId cid1 = iContactsDatabase->AddNewContactL(*contact1); |
|
151 iContactsDatabase->AddContactToGroupL(cid1, id1) ; |
|
152 |
|
153 CleanupStack::PopAndDestroy(contact1); |
|
154 CleanupStack::PopAndDestroy(group1); |
|
155 |
|
156 iContactsDatabase->CloseContactL(id1); |
|
157 iContactsDatabase->CloseTables(); |
|
158 |
|
159 test.Printf(KDBFilled);//Database is filled |
|
160 |
|
161 delete iContactsDatabase; |
|
162 iContactsDatabase = 0; |
|
163 |
|
164 //ViewUpdate |
|
165 iContactsDatabase=CContactDatabase::OpenL(); |
|
166 |
|
167 RContactViewSortOrder sortOrder ; |
|
168 sortOrder.AppendL(KUidContactFieldGivenName); |
|
169 |
|
170 _LIT(KText1, "Remote View") ; |
|
171 TBufC<30> name(KText1) ; |
|
172 |
|
173 irview = CContactNamedRemoteView::NewL(*this, name, *iContactsDatabase, |
|
174 sortOrder, EContactAndGroups) ; |
|
175 |
|
176 CleanupStack::PushL(irview) ; |
|
177 |
|
178 igview = CContactGroupView::NewL(*iContactsDatabase, |
|
179 *irview, *this, id1, CContactGroupView::EShowContactsNotInAnyGroup) ; |
|
180 |
|
181 CleanupStack::PushL(igview) ; |
|
182 |
|
183 |
|
184 CContactIdArray *arrayOfContacts = iContactsDatabase->FindLC(_L("Group1"), NULL) ; |
|
185 |
|
186 TInt count = arrayOfContacts->Count(); |
|
187 |
|
188 TContactItemId id = 0; |
|
189 TInt i ; |
|
190 for(i = 0; i < count; i++) |
|
191 { |
|
192 id = (*arrayOfContacts)[i] ; |
|
193 CContactItem *item = iContactsDatabase->ReadContactL(id) ; |
|
194 CleanupStack::PushL(item) ; |
|
195 |
|
196 if (item->Type() == KUidContactGroup) |
|
197 { |
|
198 CleanupStack::PopAndDestroy(item) ; |
|
199 iGroupID = id ; |
|
200 break ; // This group should be deleted |
|
201 } |
|
202 CleanupStack::PopAndDestroy(item) ; |
|
203 } |
|
204 |
|
205 CleanupStack::PopAndDestroy(arrayOfContacts) ; |
|
206 |
|
207 if (i == count) |
|
208 { |
|
209 sortOrder.Close() ; |
|
210 User::Leave(KErrNotFound) ; |
|
211 } |
|
212 |
|
213 |
|
214 CContactGroup* group = (static_cast<CContactGroup*> (iContactsDatabase->ReadContactL(iGroupID))); |
|
215 CleanupStack::PushL(group) ; |
|
216 |
|
217 imemberArray = (const_cast<CContactIdArray*> (group->ItemsContained())); |
|
218 |
|
219 iContactsDatabase->DeleteContactL(id) ; |
|
220 |
|
221 iTimer.After(iStatus,3000000);//timeout after 3 seconds |
|
222 SetActive(); |
|
223 |
|
224 CActiveScheduler::Start() ; |
|
225 |
|
226 CleanupStack::PopAndDestroy(group) ; |
|
227 |
|
228 CleanupStack::PopAndDestroy(igview) ; |
|
229 CleanupStack::PopAndDestroy(irview) ; |
|
230 |
|
231 sortOrder.Close() ; |
|
232 |
|
233 if (!iFailed) |
|
234 { |
|
235 |
|
236 test.End(); |
|
237 |
|
238 } |
|
239 else |
|
240 { |
|
241 |
|
242 test.Printf(KTestFailed); |
|
243 |
|
244 } |
|
245 |
|
246 } |
|
247 |
|
248 |
|
249 LOCAL_C void doMainL() |
|
250 { |
|
251 __UHEAP_MARK; |
|
252 CTestConductor* testConductor = NULL; |
|
253 testConductor = CTestConductor::NewL(); |
|
254 |
|
255 CleanupStack::PushL( testConductor ); |
|
256 CleanupStack::PopAndDestroy( testConductor ); |
|
257 __UHEAP_MARKEND; |
|
258 } |
|
259 |
|
260 /** |
|
261 |
|
262 @SYMTestCaseID PIM-T-DBFILL-0001 |
|
263 |
|
264 */ |
|
265 |
|
266 GLDEF_C TInt E32Main() |
|
267 { |
|
268 __UHEAP_MARK; |
|
269 test.Start(KTestName); |
|
270 |
|
271 test.Title(); |
|
272 CActiveScheduler* scheduler=new CActiveScheduler; |
|
273 if (scheduler) |
|
274 { |
|
275 CActiveScheduler::Install(scheduler); |
|
276 CTrapCleanup* cleanup=CTrapCleanup::New(); |
|
277 if (cleanup) |
|
278 { |
|
279 TRAPD(err,doMainL()); |
|
280 test(err == KErrNone); |
|
281 delete cleanup; |
|
282 } |
|
283 delete scheduler; |
|
284 } |
|
285 |
|
286 test.Close(); |
|
287 __UHEAP_MARKEND; |
|
288 return KErrNone; |
|
289 } |
|
290 |