|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: EUnit test file. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include <cntdb.h> |
|
21 #include <cntitem.h> |
|
22 #include <cntfldst.h> |
|
23 #include <cpbkcontactitem.h> |
|
24 #include <cpbkcontactengine.h> |
|
25 |
|
26 |
|
27 HBufC* CreateFieldStringL(char* contactdata[], TInt aIx) |
|
28 { |
|
29 char* str = contactdata[aIx]; |
|
30 TInt len = 0; |
|
31 |
|
32 while (str[len] != '\0') |
|
33 { |
|
34 len++; |
|
35 } |
|
36 |
|
37 if ( len == 0 ) |
|
38 { |
|
39 return NULL; |
|
40 } |
|
41 |
|
42 HBufC *field = HBufC::NewL( len ); |
|
43 TPtr des = field->Des(); |
|
44 des.SetLength( len ); |
|
45 |
|
46 for (TInt i = 0; i < len; i++) |
|
47 { |
|
48 des[i] = (TChar) str[i]; |
|
49 } |
|
50 |
|
51 return field; |
|
52 } |
|
53 |
|
54 |
|
55 void AddFieldStringL( char* contactdata[], CPbkContactItem* aContact, TInt aIx, TInt aFieldId ) |
|
56 { |
|
57 HBufC* fieldName = CreateFieldStringL( contactdata, aIx ); |
|
58 |
|
59 if ( fieldName ) |
|
60 { |
|
61 CleanupStack::PushL( fieldName ); |
|
62 aContact->FindField( aFieldId )->TextStorage()->SetTextL( *fieldName ); |
|
63 CleanupStack::PopAndDestroy(fieldName); |
|
64 } |
|
65 } |
|
66 |
|
67 |
|
68 void AddContactL( char* contactdata[], CPbkContactEngine* engine, TInt aIx) |
|
69 { |
|
70 CPbkContactItem* contact = engine->CreateEmptyContactL(); |
|
71 CleanupStack::PushL( contact ); |
|
72 |
|
73 AddFieldStringL( contactdata, contact, aIx * 6 + 0, EPbkFieldIdFirstName ); |
|
74 AddFieldStringL( contactdata, contact, aIx * 6 + 1, EPbkFieldIdLastName ); |
|
75 AddFieldStringL( contactdata, contact, aIx * 6 + 2, EPbkFieldIdPhoneNumberMobile ); |
|
76 AddFieldStringL( contactdata, contact, aIx * 6 + 3, EPbkFieldIdPhoneNumberGeneral ); |
|
77 AddFieldStringL( contactdata, contact, aIx * 6 + 4, EPbkFieldIdCompanyName ); |
|
78 AddFieldStringL( contactdata, contact, aIx * 6 + 5, EPbkFieldIdEmailAddress ); |
|
79 |
|
80 engine->AddNewContactL( *contact ); |
|
81 |
|
82 CleanupStack::PopAndDestroy( contact ); |
|
83 } |
|
84 |
|
85 |
|
86 |
|
87 // --------------------------------------------------------- |
|
88 // CreateTestContactDatabaseL |
|
89 // |
|
90 // Creates a test contact database if it hasn't been created yet. |
|
91 // The existence of test base is done through testing if there |
|
92 // is a contact matching with word "Dummy". Test data base has |
|
93 // a contact for Mr Dummy Contact. |
|
94 // This is the primary function of this file. |
|
95 // --------------------------------------------------------- |
|
96 // |
|
97 TInt CreateTestContactDatabaseL() |
|
98 { |
|
99 |
|
100 TInt nbr_of_contacts = 15; |
|
101 |
|
102 /* |
|
103 * Contact data contains contact data as text strings. |
|
104 * Each contact takes six lines: |
|
105 * - first name |
|
106 * - last name |
|
107 * - cell number |
|
108 * - home number |
|
109 * - company name |
|
110 * - e-mail address |
|
111 * Empty string means that field is not set. |
|
112 */ |
|
113 |
|
114 char* contactdata[] = |
|
115 { |
|
116 "Dummy", |
|
117 "Contact", |
|
118 "+1056439939", |
|
119 "035558756", |
|
120 "Ericsson", |
|
121 "dummy.contact@ericsson.sw", |
|
122 |
|
123 "Jaakko", |
|
124 "Helanti", |
|
125 "+358405557631", |
|
126 "034447611", |
|
127 "Nokia", |
|
128 "jaakko.helanti@helanti.com", |
|
129 |
|
130 "Stan", |
|
131 "Laurel", |
|
132 "+0104438839992", |
|
133 "+0104438839000", |
|
134 "MGM", |
|
135 "stan.laurel@heaven.com", |
|
136 |
|
137 "Oliver", |
|
138 "Hardy", |
|
139 "+01078398927", |
|
140 "+10364537882", |
|
141 "MGM", |
|
142 "oliver.hardy@heaven.com", |
|
143 |
|
144 "Harold", |
|
145 "Lloyd", |
|
146 "+102843947", |
|
147 "+10290503958", |
|
148 "Universal", |
|
149 "harold.lloyd@universal.com", |
|
150 |
|
151 "Tauno", |
|
152 "Palo", |
|
153 "+358405557631", |
|
154 "014445466", |
|
155 "Suomi Filmi", |
|
156 "tauno.palo@gmail.com", |
|
157 |
|
158 "Tea", |
|
159 "Ista", |
|
160 "+358475554590", |
|
161 "018723195", |
|
162 "Helsingin Kaupungin Teatteri", |
|
163 "tea.ista@cultureclub.com", |
|
164 |
|
165 "Ansa", |
|
166 "Ikonen", |
|
167 "+358471134099", |
|
168 "012388192", |
|
169 "Suomi Filmi", |
|
170 "ansa.ikonen@gmail.com", |
|
171 |
|
172 "Bertil", |
|
173 "Nystrom", |
|
174 "+35866377334", |
|
175 "074500998", |
|
176 "Rovaniemen Viuluveistämö", |
|
177 "bertil.nystrom@rvv.com", |
|
178 |
|
179 "", |
|
180 "Onlylastname", |
|
181 "+3585556743", |
|
182 "+35835552727", |
|
183 "", |
|
184 "", |
|
185 |
|
186 "Onlyfirstname", |
|
187 "", |
|
188 "+358405559874", |
|
189 "035553747", |
|
190 "", |
|
191 "", |
|
192 |
|
193 "", |
|
194 "Two-Part Lastname", |
|
195 "+358405557432", |
|
196 "", |
|
197 "", |
|
198 "", |
|
199 |
|
200 "", |
|
201 "", |
|
202 "+35866377334", |
|
203 "074500998", |
|
204 "Just Companyname", |
|
205 "john.doe@justcompanyname.com", |
|
206 |
|
207 "One", |
|
208 "Number", |
|
209 "", |
|
210 "075553266", |
|
211 "Idaho", |
|
212 "", |
|
213 |
|
214 "No", |
|
215 "Number", |
|
216 "", |
|
217 "", |
|
218 "Ericsson", |
|
219 "no.number@ericsson.com", |
|
220 }; |
|
221 |
|
222 |
|
223 CPbkContactEngine* engine = CPbkContactEngine::NewL(); |
|
224 CleanupStack::PushL( engine ); |
|
225 |
|
226 _LIT(KDummyContact, "Dummy"); |
|
227 |
|
228 CContactIdArray* findings = engine->FindLC( KDummyContact ); |
|
229 |
|
230 // If dummy contact is found, the test database has already been created. |
|
231 if (findings->Count() > 0) |
|
232 { |
|
233 CleanupStack::PopAndDestroy( findings ); |
|
234 CleanupStack::PopAndDestroy( engine ); |
|
235 return 0; |
|
236 } |
|
237 |
|
238 CleanupStack::PopAndDestroy( findings ); |
|
239 |
|
240 for (TInt i = 0; i < nbr_of_contacts; i++ ) |
|
241 { |
|
242 AddContactL( contactdata, engine, i ); |
|
243 } |
|
244 |
|
245 CleanupStack::PopAndDestroy(engine); |
|
246 |
|
247 return nbr_of_contacts; |
|
248 } |
|
249 |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 |