2 * @file utest_contact.h
3 * @author Adenilson Cavalcanti da Silva <adenilson.silva@indt.org.br>
4 * @date Started on May 25 2008
6 * @brief Module for google contacts utests.
9 #include "utest_contact.h"
13 #include "gcal_parser.h"
18 static struct gcal_resource
*ptr_gcal
= NULL
;
20 static void setup(void)
22 /* here goes any common data allocation */
23 ptr_gcal
= gcal_construct(GCONTACT
);
26 static void teardown(void)
28 /* and here we clean up */
29 gcal_destroy(ptr_gcal
);
33 START_TEST (test_contact_dump
)
36 result
= gcal_get_authentication(ptr_gcal
, "gcal4tester", "66libgcal");
38 fail_if(1, "Authentication should work");
40 result
= gcal_dump(ptr_gcal
, "GData-Version: 3.0");
41 fail_if(result
!= 0, "Failed dumping contacts");
47 START_TEST (test_contact_authenticate
)
52 result
= gcal_get_authentication(ptr_gcal
, "gcal4tester", "66libgcal");
53 fail_if(result
!= 0, "Authentication should work");
55 result
= gcal_get_authentication(ptr_gcal
, "gcal4tester", "fail_fail");
56 fail_if(result
== 0, "Authentication must fail");
62 START_TEST (test_contact_entries
)
64 /* obs: this test is a copy of utest_gcal.c:test_gcal_event */
66 char *contacts_emails
[] = { "gcal4tester@gmail.com",
67 "gcalntester@gmail.com",
68 "cavalcantii@gmail.com" };
70 int contacts_count
= 3;
72 result
= gcal_get_authentication(ptr_gcal
, "gcal4tester", "66libgcal");
74 fail_if(1, "Authentication should work");
76 result
= gcal_dump(ptr_gcal
, "GData-Version: 3.0");
77 fail_if(result
!= 0, "Failed dumping contacts");
79 result
= gcal_entry_number(ptr_gcal
);
80 fail_if(result
!= 3, "Got wrong number of contacts");
82 for (i
= 0; i
< contacts_count
; ++i
)
83 if (!(ptr
= strstr(gcal_access_buffer(ptr_gcal
),
85 fail_if(1, "Can't find contact in atom stream. "
86 "Position = %i\n", i
);
93 START_TEST (test_contact_extract
)
97 struct gcal_contact
*contacts
;
98 char *contacts_email
[] = { "gcal4tester@gmail.com",
99 "gcalntester@gmail.com",
100 "cavalcantii@gmail.com" };
101 char *contacts_name
[] = { "", /* its valid not having a name */
103 "Adenilson Cavalcanti" };
104 char *temp
= (char *)malloc(255);
105 size_t contacts_count
= 3, found_count
= 0;
107 result
= gcal_get_authentication(ptr_gcal
, "gcal4tester", "66libgcal");
108 fail_if(result
== -1, "Authentication should work");
110 result
= gcal_dump(ptr_gcal
, "GData-Version: 3.0");
111 fail_if(result
!= 0, "Failed dumping contacts");
113 contacts
= gcal_get_all_contacts(ptr_gcal
, &count
);
114 fail_if(contacts
== NULL
, "Failed extracting the contacts vector!");
116 for (i
= 0; i
< contacts_count
; ++i
) {
117 for (j
= 0; j
< count
; ++j
) {
118 if(contacts
[i
].structured_name
)
119 temp
= gcal_contact_get_structured_entry(contacts
[i
].structured_name
,0,1,"fullName");
122 if ((!(strcmp(contacts
[i
].emails_field
[0],
123 contacts_email
[j
]))) &&
130 fail_if(found_count
!= contacts_count
, "Cannot find all 3 contacts!");
131 gcal_destroy_contacts(contacts
, count
);
136 START_TEST (test_contact_xml
)
138 int result
, length
, address_nr
, address_count
;
139 struct gcal_contact contact
;
140 char *xml
= NULL
, *ptr
;
142 contact
.common
.title
= NULL
;
144 contact
.structured_name
=(struct gcal_structured_subvalues
*)malloc(sizeof(struct gcal_structured_subvalues
));
145 contact
.structured_name
->field_typenr
= 0;
146 contact
.structured_name
->field_key
= malloc(sizeof(char*));
147 contact
.structured_name
->field_key
= NULL
;
148 contact
.structured_name
->field_value
= malloc(sizeof(char*));
149 contact
.structured_name
->field_value
= NULL
;
150 contact
.structured_name_nr
= 1;
151 gcal_contact_set_structured_entry(contact
.structured_name
,0,1,"givenName","John");
152 gcal_contact_set_structured_entry(contact
.structured_name
,0,1,"additionalName","W.");
153 gcal_contact_set_structured_entry(contact
.structured_name
,0,1,"familyName","Doe");
154 gcal_contact_set_structured_entry(contact
.structured_name
,0,1,"namePrefix","Dr.");
155 gcal_contact_set_structured_entry(contact
.structured_name
,0,1,"fullName","Dr. John W. Doe");
157 contact
.emails_field
= malloc(sizeof(char*));
158 contact
.emails_field
[0] = "john.doe@foo.bar.com";
159 contact
.emails_nr
= 1;
160 /* TODO: set etag as NULL in all utests here */
161 contact
.common
.id
= contact
.common
.updated
= contact
.common
.edit_uri
= contact
.common
.etag
= NULL
;
162 contact
.photo
= contact
.photo_data
= NULL
;
164 contact
.nickname
= "The Fox";
165 contact
.content
= "A very interesting person";
166 contact
.org_name
= "Foo software";
167 contact
.org_title
= "Software engineer";
168 contact
.occupation
= "Programmer";
169 contact
.phone_numbers_field
= malloc(sizeof(char*));
170 contact
.phone_numbers_field
[0] = "+9977554422119900";
171 contact
.emails_type
= malloc(sizeof(char*));
172 contact
.emails_type
[0] = "Home";
173 contact
.phone_numbers_nr
= 1;
174 contact
.phone_numbers_type
= malloc(sizeof(char*));
175 contact
.phone_numbers_type
[0] = "Home";
176 contact
.groupMembership
= malloc(sizeof(char*));
177 contact
.groupMembership
[0] = "http://www.google.com/m8/feeds/groups/gcal4tester%40gmail.com/base/6";
178 contact
.groupMembership_nr
= 1;
179 contact
.birthday
= "1980-10-10";
180 contact
.im_address
= malloc(sizeof(char*));
181 contact
.im_address
[0] = "john_skype";
182 contact
.im_protocol
= malloc(sizeof(char*));
183 contact
.im_protocol
[0] = "SKYPE";
184 contact
.im_type
= malloc(sizeof(char*));
185 contact
.im_type
[0] = "home";
187 contact
.homepage
= "www.homegage.com";
188 contact
.blog
= "myblog.homegage.com";
189 contact
.post_address
= NULL
;
190 contact
.structured_address
=(struct gcal_structured_subvalues
*)malloc(sizeof(struct gcal_structured_subvalues
));
191 contact
.structured_address
->field_typenr
= 0;
192 contact
.structured_address
->field_key
= malloc(sizeof(char*));
193 contact
.structured_address
->field_key
= NULL
;
194 contact
.structured_address
->field_value
= malloc(sizeof(char*));
195 contact
.structured_address
->field_value
= NULL
;
196 contact
.structured_address_nr
= 0;
197 contact
.structured_address_type
= (char**)malloc(sizeof(char*));
198 address_nr
= gcal_contact_set_structured_address_nr(&contact
,A_HOME
);
199 address_count
= contact
.structured_address_nr
;
200 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"street","Unknown Av St, n 69");
201 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"pobox","PO BOX 123 456");
202 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"city","Dirty Old Town");
203 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"region","Somewhere");
204 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"postcode","ABC 12345-D");
205 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"country","Madagascar");
206 address_nr
= gcal_contact_set_structured_address_nr(&contact
,A_WORK
);
207 address_count
= contact
.structured_address_nr
;
208 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"street","This One St, n 23");
209 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"pobox","PO BOX 333 444 5");
210 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"city","My Hometown");
211 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"region","Hereorthere");
212 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"postcode","XYZ 98765-C");
213 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"country","Island");
214 gcal_contact_set_pref_structured_address(&contact
,1);
216 result
= xmlcontact_create(&contact
, &xml
, &length
);
217 fail_if(result
== -1 || xml
== NULL
,
218 "Failed creating XML for a new contact!");
220 ptr
= strstr(xml
, "Dr. John W. Doe");
221 fail_if(ptr
== NULL
, "XML lacks a field: gd:name/gd:fullName\n");
222 ptr
= strstr(xml
, contact
.nickname
);
223 fail_if(ptr
== NULL
, "XML lacks a field: %s\n", contact
.nickname
);
224 ptr
= strstr(xml
, contact
.occupation
);
225 fail_if(ptr
== NULL
, "XML lacks a field: %s\n", contact
.occupation
);
226 ptr
= strstr(xml
, contact
.blog
);
227 fail_if(ptr
== NULL
, "XML lacks a field: %s\n", contact
.blog
);
228 ptr
= strstr(xml
, contact
.homepage
);
229 fail_if(ptr
== NULL
, "XML lacks a field: %s\n", contact
.homepage
);
230 ptr
= strstr(xml
, contact
.emails_field
[0]);
231 fail_if(ptr
== NULL
, "XML lacks a field: %s\n", contact
.emails_field
[0]);
232 ptr
= strstr(xml
, contact
.content
);
233 fail_if(ptr
== NULL
, "XML lacks a field: %s\n", contact
.content
);
234 ptr
= strstr(xml
, contact
.org_name
);
235 fail_if(ptr
== NULL
, "XML lacks a field: %s\n", contact
.org_name
);
236 ptr
= strstr(xml
, contact
.org_title
);
237 fail_if(ptr
== NULL
, "XML lacks a field: %s\n", contact
.org_title
);
238 ptr
= strstr(xml
, contact
.phone_numbers_field
[0]);
239 fail_if(ptr
== NULL
, "XML lacks a field: %s\n", contact
.phone_numbers_field
[0]);
240 ptr
= strstr(xml
, "This One St, n 23");
241 fail_if(ptr
== NULL
, "XML lacks a field: street\n");
242 ptr
= strstr(xml
, "PO BOX 333 444 5");
243 fail_if(ptr
== NULL
, "XML lacks a field: pobox\n");
244 ptr
= strstr(xml
, "My Hometown");
245 fail_if(ptr
== NULL
, "XML lacks a field: city\n");
246 ptr
= strstr(xml
, "Hereorthere");
247 fail_if(ptr
== NULL
, "XML lacks a field: region\n");
248 ptr
= strstr(xml
, "XYZ 98765-C");
249 fail_if(ptr
== NULL
, "XML lacks a field: postcode\n");
250 ptr
= strstr(xml
, "Island");
251 fail_if(ptr
== NULL
, "XML lacks a field: country\n");
252 ptr
= strstr(xml
, contact
.birthday
);
253 fail_if(ptr
== NULL
, "XML lacks a field: %s\n", contact
.birthday
);
254 ptr
= strstr(xml
, contact
.im_address
[0]);
255 fail_if(ptr
== NULL
, "XML lacks a field IM:%s\n",contact
.im_address
[0]);
262 START_TEST (test_contact_add
)
264 int result
, address_nr
, address_count
;
265 struct gcal_contact contact
;
267 contact
.common
.title
= NULL
;
269 contact
.structured_name
=(struct gcal_structured_subvalues
*)malloc(sizeof(struct gcal_structured_subvalues
));
270 contact
.structured_name
->field_typenr
= 0;
271 contact
.structured_name
->field_key
= malloc(sizeof(char*));
272 contact
.structured_name
->field_key
= NULL
;
273 contact
.structured_name
->field_value
= malloc(sizeof(char*));
274 contact
.structured_name
->field_value
= NULL
;
275 contact
.structured_name_nr
= 1;
276 gcal_contact_set_structured_entry(contact
.structured_name
,0,1,"givenName","John");
277 gcal_contact_set_structured_entry(contact
.structured_name
,0,1,"additionalName","W.");
278 gcal_contact_set_structured_entry(contact
.structured_name
,0,1,"familyName","Doe");
279 gcal_contact_set_structured_entry(contact
.structured_name
,0,1,"namePrefix","Dr.");
280 gcal_contact_set_structured_entry(contact
.structured_name
,0,1,"nameSuffix","IV.");
282 contact
.emails_field
= malloc(sizeof(char*));
283 contact
.emails_field
[0] = "john.doe@foo.bar.com";
284 contact
.emails_type
= malloc(sizeof(char*));
285 contact
.emails_type
[0] = "home";
286 contact
.emails_nr
= 1;
287 contact
.pref_email
= 0;
288 contact
.common
.id
= contact
.common
.updated
= contact
.common
.edit_uri
= contact
.common
.etag
= NULL
;
289 contact
.photo
= contact
.photo_data
= NULL
;
291 contact
.nickname
= "The Fox";
292 contact
.content
= "A very interesting person";
293 contact
.org_name
= "Foo software";
294 contact
.org_title
= "Software engineer";
295 contact
.occupation
= "Programmer";
296 contact
.birthday
= "1980-10-10";
297 contact
.im_address
= malloc(sizeof(char*));
298 contact
.im_address
[0] = "john";
299 contact
.im_protocol
= malloc(sizeof(char*));
300 contact
.im_protocol
[0] = "SKYPE";
301 contact
.im_type
= malloc(sizeof(char*));
302 contact
.im_type
[0] = "home";
304 contact
.phone_numbers_field
= malloc(sizeof(char*));
305 contact
.phone_numbers_field
[0] = "+9977554422119900";
306 contact
.phone_numbers_type
= malloc(sizeof(char*));
307 contact
.phone_numbers_type
[0] = "home";
308 contact
.phone_numbers_nr
= 1;
309 contact
.groupMembership
= malloc(sizeof(char*));
310 contact
.groupMembership
[0] = "http://www.google.com/m8/feeds/groups/gcalntester%40gmail.com/base/6";
311 contact
.groupMembership_nr
= 1;
312 contact
.birthday
= "1980-10-10";
313 contact
.homepage
= "www.homegage.com";
314 contact
.blog
= "myblog.homegage.com";
315 contact
.structured_address
=(struct gcal_structured_subvalues
*)malloc(sizeof(struct gcal_structured_subvalues
));
316 contact
.structured_address
->field_typenr
= 0;
317 contact
.structured_address
->field_key
= malloc(sizeof(char*));
318 contact
.structured_address
->field_key
= NULL
;
319 contact
.structured_address
->field_value
= malloc(sizeof(char*));
320 contact
.structured_address
->field_value
= NULL
;
321 contact
.structured_address_nr
= 0;
322 contact
.structured_address_type
= (char**)malloc(sizeof(char*));
323 address_nr
= gcal_contact_set_structured_address_nr(&contact
,A_HOME
);
324 address_count
= contact
.structured_address_nr
;
325 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"street","Unknown Av St, n 69");
326 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"pobox","PO BOX 123 456");
327 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"city","Dirty Old Town");
328 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"region","Somewhere");
329 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"postcode","ABC 12345-D");
330 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"country","Madagascar");
331 address_nr
= gcal_contact_set_structured_address_nr(&contact
,A_WORK
);
332 address_count
= contact
.structured_address_nr
;
333 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"street","This One St, n 23");
334 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"pobox","PO BOX 333 444 5");
335 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"city","My Hometown");
336 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"region","Hereorthere");
337 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"postcode","XYZ 98765-C");
338 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"country","Island");
339 gcal_contact_set_pref_structured_address(&contact
,1);
341 result
= gcal_get_authentication(ptr_gcal
, "gcalntester", "77libgcal");
342 fail_if(result
== -1, "Authentication should work.");
344 result
= gcal_create_contact(ptr_gcal
, &contact
, NULL
);
345 fail_if(result
== -1, "Failed creating a new contact!");
347 /* I commented this test because it prints too much error
348 * information to stderr. I must add a logging of some sort
351 /* Trying to insert another contact with same email
352 * should trigger HTTP 409 Conflict code.
354 /* result = gcal_create_contact(&contact, ptr_gcal); */
355 /* fail_if(result != -1, "Adding the same contact must conflict!"); */
361 START_TEST (test_contact_delete
)
363 /* This test assumes that 'test_contact_add' worked fine:
364 * I'm going to delete that contact.
366 char *test_title
= "Dr. John W. Doe IV.", *temp
= (char *)malloc(255);;
367 char *test_email
= "john.doe@foo.bar.com";
368 struct gcal_contact
*contacts
;
369 int i
, result
, entry_index
= -1;
372 result
= gcal_get_authentication(ptr_gcal
, "gcalntester", "77libgcal");
373 fail_if(result
== -1, "Authentication should work.");
375 result
= gcal_dump(ptr_gcal
, "GData-Version: 3.0");
376 fail_if(result
!= 0, "Failed dumping contacts");
378 contacts
= gcal_get_all_contacts(ptr_gcal
, &count
);
379 fail_if(contacts
== NULL
, "Failed extracting contacts vector!");
381 for (i
= 0; i
< (int)count
; ++i
) {
382 if (contacts
[i
].structured_name
)
383 temp
= gcal_contact_get_structured_entry(contacts
[i
].structured_name
,0,1,"fullName");
387 if (contacts
[i
].emails_field
&& temp
) {
388 if ((!(strcmp(contacts
[i
].emails_field
[0], test_email
))) &&
389 (!(strcmp(temp
, test_title
)))) {
396 temp
= (char *)malloc(255);
397 sprintf(temp
, "Cannot locate the newly added contact!\nindex = %d\tname = %s\n", entry_index
,
398 contacts
[entry_index
].common
.title
);
399 fail_if(entry_index
== -1, temp
);
402 // result = gcal_delete_contact(ptr_gcal, (contacts + entry_index));
403 // fail_if(result == -1, "Failed deleting contact!");
405 gcal_destroy_contacts(contacts
, count
);
409 START_TEST (test_contact_edit
)
411 int result
, address_nr
, address_count
;
412 struct gcal_contact contact
, contact_new
, updated
;
413 gcal_structured_subvalues_t structured_entry
;
415 contact
.common
.title
= NULL
;
417 contact
.structured_name
=(struct gcal_structured_subvalues
*)malloc(sizeof(struct gcal_structured_subvalues
));
418 contact
.structured_name
->field_typenr
= 0;
419 contact
.structured_name
->field_key
= malloc(sizeof(char*));
420 contact
.structured_name
->field_key
= NULL
;
421 contact
.structured_name
->field_value
= malloc(sizeof(char*));
422 contact
.structured_name
->field_value
= NULL
;
423 contact
.structured_name_nr
= 1;
424 gcal_contact_set_structured_entry(contact
.structured_name
,0,1,"givenName","John");
425 gcal_contact_set_structured_entry(contact
.structured_name
,0,1,"additionalName","W.");
426 gcal_contact_set_structured_entry(contact
.structured_name
,0,1,"familyName","Doe");
427 gcal_contact_set_structured_entry(contact
.structured_name
,0,1,"namePrefix","Dr.");
429 contact
.photo
= contact
.photo_data
= NULL
;
430 contact
.photo_length
= 0;
431 contact
.emails_field
= malloc(sizeof(char*));
432 contact
.emails_field
[0] = "johny.doe@foo.bar.com";
433 contact
.emails_nr
= 1;
434 contact
.pref_email
= 0;
435 contact
.emails_type
= malloc(sizeof(char*));
436 contact
.emails_type
[0] = "home";
437 contact
.common
.id
= contact
.common
.updated
= contact
.common
.edit_uri
= contact
.common
.etag
= NULL
;
439 contact
.nickname
= "The Fox";
440 contact
.content
= "A very interesting person";
441 contact
.org_name
= "Foo software";
442 contact
.org_title
= "Software engineer";
443 contact
.occupation
= "Programmer";
444 contact
.birthday
= "1980-10-10";
445 contact
.im_address
= malloc(sizeof(char*));
446 contact
.im_address
[0] = "johny";
447 contact
.im_protocol
= malloc(sizeof(char*));
448 contact
.im_protocol
[0] = "SKYPE";
449 contact
.im_type
= malloc(sizeof(char*));
450 contact
.im_type
[0] = "home";
452 contact
.phone_numbers_field
= malloc(sizeof(char*));
453 contact
.phone_numbers_field
[0] = "+9977554422119900";
454 contact
.phone_numbers_type
= malloc(sizeof(char*));
455 contact
.phone_numbers_type
[0] = "home";
456 contact
.phone_numbers_nr
= 1;
457 contact
.groupMembership
= malloc(sizeof(char*));
458 contact
.groupMembership
[0] = "http://www.google.com/m8/feeds/groups/gcalntester%40gmail.com/base/6";
459 contact
.groupMembership_nr
= 1;
460 contact
.birthday
= "1980-10-10";
461 contact
.homepage
= "www.homegage.com";
462 contact
.blog
= "myblog.homegage.com";
463 contact
.structured_address
=(struct gcal_structured_subvalues
*)malloc(sizeof(struct gcal_structured_subvalues
));
464 contact
.structured_address
->field_typenr
= 0;
465 contact
.structured_address
->field_key
= malloc(sizeof(char*));
466 contact
.structured_address
->field_key
= NULL
;
467 contact
.structured_address
->field_value
= malloc(sizeof(char*));
468 contact
.structured_address
->field_value
= NULL
;
469 contact
.structured_address_nr
= 0;
470 contact
.structured_address_type
= (char**)malloc(sizeof(char*));
471 address_nr
= gcal_contact_set_structured_address_nr(&contact
,A_HOME
);
472 address_count
= contact
.structured_address_nr
;
473 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"street","Unknown Av St, n 69");
474 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"pobox","PO BOX 123 456");
475 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"city","Dirty Old Town");
476 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"region","Somewhere");
477 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"postcode","ABC 12345-D");
478 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"country","Madagascar");
479 address_nr
= gcal_contact_set_structured_address_nr(&contact
,A_WORK
);
480 address_count
= contact
.structured_address_nr
;
481 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"street","This One St, n 23");
482 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"pobox","PO BOX 333 444 5");
483 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"city","My Hometown");
484 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"region","Hereorthere");
485 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"postcode","XYZ 98765-C");
486 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"country","Island");
487 gcal_contact_set_pref_structured_address(&contact
,1);
489 /* Authenticate and add a new contact */
490 result
= gcal_get_authentication(ptr_gcal
, "gcalntester", "77libgcal");
491 fail_if(result
== -1, "Authentication should work.");
492 result
= gcal_create_contact(ptr_gcal
, &contact
, &contact_new
);
495 contact_new
.structured_name
=(struct gcal_structured_subvalues
*)malloc(sizeof(struct gcal_structured_subvalues
));
496 contact_new
.structured_name
->field_typenr
= 0;
497 contact_new
.structured_name
->field_key
= malloc(sizeof(char*));
498 contact_new
.structured_name
->field_key
= NULL
;
499 contact_new
.structured_name
->field_value
= malloc(sizeof(char*));
500 contact_new
.structured_name
->field_value
= NULL
;
501 contact_new
.structured_name_nr
= 1;
502 gcal_contact_set_structured_entry(contact_new
.structured_name
,0,1,"givenName","Johny");
503 gcal_contact_set_structured_entry(contact_new
.structured_name
,0,1,"additionalName","'the mad'");
504 gcal_contact_set_structured_entry(contact_new
.structured_name
,0,1,"familyName","Doe");
506 contact_new
.structured_address
=(struct gcal_structured_subvalues
*)malloc(sizeof(struct gcal_structured_subvalues
));
507 contact_new
.structured_address
->field_typenr
= 0;
508 contact_new
.structured_address
->field_key
= malloc(sizeof(char*));
509 contact_new
.structured_address
->field_key
= NULL
;
510 contact_new
.structured_address
->field_value
= malloc(sizeof(char*));
511 contact_new
.structured_address
->field_value
= NULL
;
512 contact_new
.structured_address_nr
= 0;
513 contact_new
.structured_address_type
= (char**)malloc(sizeof(char*));
514 address_nr
= gcal_contact_set_structured_address_nr(&contact_new
,A_HOME
);
515 address_count
= contact_new
.structured_address_nr
;
516 gcal_contact_set_structured_entry(contact_new
.structured_address
,address_nr
,address_count
,"street","New Av St, n 61");
517 gcal_contact_set_structured_entry(contact_new
.structured_address
,address_nr
,address_count
,"pobox","PO BOX 987 654");
518 gcal_contact_set_structured_entry(contact_new
.structured_address
,address_nr
,address_count
,"city","My New Town");
519 gcal_contact_set_structured_entry(contact_new
.structured_address
,address_nr
,address_count
,"region","Hereorthere");
520 gcal_contact_set_structured_entry(contact_new
.structured_address
,address_nr
,address_count
,"postcode","XYZ 987654-V");
521 gcal_contact_set_structured_entry(contact_new
.structured_address
,address_nr
,address_count
,"country","Italy");
522 address_nr
= gcal_contact_set_structured_address_nr(&contact_new
,A_WORK
);
523 address_count
= contact_new
.structured_address_nr
;
524 gcal_contact_set_structured_entry(contact_new
.structured_address
,address_nr
,address_count
,"street","Longlong St, n 23");
525 gcal_contact_set_structured_entry(contact_new
.structured_address
,address_nr
,address_count
,"pobox","PO BOX 1");
526 gcal_contact_set_structured_entry(contact_new
.structured_address
,address_nr
,address_count
,"city","Smallville");
527 gcal_contact_set_structured_entry(contact_new
.structured_address
,address_nr
,address_count
,"region","Nowhere");
528 gcal_contact_set_structured_entry(contact_new
.structured_address
,address_nr
,address_count
,"postcode","QQQ 112233-WW");
529 gcal_contact_set_structured_entry(contact_new
.structured_address
,address_nr
,address_count
,"country","South Africa");
531 result
= gcal_edit_contact(ptr_gcal
, &contact_new
, &updated
);
532 fail_if(result
== -1, "Failed editing contact!");
534 structured_entry
= gcal_contact_get_structured_address(&contact
);
535 gcal_contact_delete_structured_entry(structured_entry
,gcal_contact_get_structured_address_count_obj(&contact
),gcal_contact_get_structured_address_type_obj(&contact
));
537 structured_entry
= gcal_contact_get_structured_name(&contact
);
538 gcal_contact_delete_structured_entry(structured_entry
,NULL
,NULL
);
540 /* Delete the contact: pay attention that each edit changes
541 * the "edit_url" field!
543 result
= gcal_delete_contact(ptr_gcal
, &updated
);
544 fail_if(result
== -1, "Failed deleting contact!");
546 /* Do memory clean up */
547 gcal_destroy_contact(&contact_new
);
548 gcal_destroy_contact(&updated
);
553 TCase
*gcontact_tcase_create(void)
556 int timeout_seconds
= 50;
557 tc
= tcase_create("gcontact");
558 tcase_add_checked_fixture(tc
, setup
, teardown
);
559 tcase_set_timeout (tc
, timeout_seconds
);
560 tcase_add_test(tc
, test_contact_authenticate
);
561 tcase_add_test(tc
, test_contact_dump
);
562 tcase_add_test(tc
, test_contact_entries
);
563 tcase_add_test(tc
, test_contact_extract
);
564 tcase_add_test(tc
, test_contact_xml
);
565 tcase_add_test(tc
, test_contact_add
);
566 tcase_add_test(tc
, test_contact_delete
);
567 tcase_add_test(tc
, test_contact_edit
);