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 = "John Doe";
143 contact
.common
.title
= NULL
;
145 contact
.structured_name
=(struct gcal_structured_subvalues
*)malloc(sizeof(struct gcal_structured_subvalues
));
146 contact
.structured_name
->field_typenr
= 0;
147 contact
.structured_name
->field_key
= malloc(sizeof(char*));
148 contact
.structured_name
->field_key
= NULL
;
149 contact
.structured_name
->field_value
= malloc(sizeof(char*));
150 contact
.structured_name
->field_value
= NULL
;
151 contact
.structured_name_nr
= 1;
152 gcal_contact_set_structured_entry(contact
.structured_name
,0,1,"givenName","John");
153 gcal_contact_set_structured_entry(contact
.structured_name
,0,1,"additionalName","W.");
154 gcal_contact_set_structured_entry(contact
.structured_name
,0,1,"familyName","Doe");
155 gcal_contact_set_structured_entry(contact
.structured_name
,0,1,"namePrefix","Dr.");
156 gcal_contact_set_structured_entry(contact
.structured_name
,0,1,"fullName","Dr. John W. Doe");
158 contact
.emails_field
= malloc(sizeof(char*));
159 contact
.emails_field
[0] = "john.doe@foo.bar.com";
160 contact
.emails_nr
= 1;
161 /* TODO: set etag as NULL in all utests here */
162 contact
.common
.id
= contact
.common
.updated
= contact
.common
.edit_uri
= contact
.common
.etag
= NULL
;
163 contact
.photo
= contact
.photo_data
= NULL
;
165 contact
.nickname
= "The Fox";
166 contact
.content
= "A very interesting person";
167 contact
.org_name
= "Foo software";
168 contact
.org_title
= "Software engineer";
169 contact
.occupation
= "Programmer";
170 contact
.phone_numbers_field
= malloc(sizeof(char*));
171 contact
.phone_numbers_field
[0] = "+9977554422119900";
172 contact
.emails_type
= malloc(sizeof(char*));
173 contact
.emails_type
[0] = "Home";
174 contact
.phone_numbers_nr
= 1;
175 contact
.phone_numbers_type
= malloc(sizeof(char*));
176 contact
.phone_numbers_type
[0] = "Home";
177 contact
.groupMembership
= malloc(sizeof(char*));
178 contact
.groupMembership
[0] = "http://www.google.com/m8/feeds/groups/gcal4tester%40gmail.com/base/6";
179 contact
.groupMembership_nr
= 1;
180 contact
.birthday
= "1980-10-10";
181 contact
.im_address
= malloc(sizeof(char*));
182 contact
.im_address
[0] = "john_skype";
183 contact
.im_protocol
= malloc(sizeof(char*));
184 contact
.im_protocol
[0] = "SKYPE";
185 contact
.im_type
= malloc(sizeof(char*));
186 contact
.im_type
[0] = "home";
188 contact
.homepage
= "www.homegage.com";
189 contact
.blog
= "myblog.homegage.com";
190 contact
.post_address
= NULL
;
191 contact
.structured_address
=(struct gcal_structured_subvalues
*)malloc(sizeof(struct gcal_structured_subvalues
));
192 contact
.structured_address
->field_typenr
= 0;
193 contact
.structured_address
->field_key
= malloc(sizeof(char*));
194 contact
.structured_address
->field_key
= NULL
;
195 contact
.structured_address
->field_value
= malloc(sizeof(char*));
196 contact
.structured_address
->field_value
= NULL
;
197 contact
.structured_address_nr
= 0;
198 contact
.structured_address_type
= (char**)malloc(sizeof(char*));
199 address_nr
= gcal_contact_set_structured_address_nr(&contact
,A_HOME
);
200 address_count
= contact
.structured_address_nr
;
201 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"street","Unknown Av St, n 69");
202 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"pobox","PO BOX 123 456");
203 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"city","Dirty Old Town");
204 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"region","Somewhere");
205 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"postcode","ABC 12345-D");
206 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"country","Madagascar");
207 address_nr
= gcal_contact_set_structured_address_nr(&contact
,A_WORK
);
208 address_count
= contact
.structured_address_nr
;
209 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"street","This One St, n 23");
210 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"pobox","PO BOX 333 444 5");
211 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"city","My Hometown");
212 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"region","Hereorthere");
213 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"postcode","XYZ 98765-C");
214 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"country","Island");
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
.emails_field
[0]);
223 fail_if(ptr
== NULL
, "XML lacks a field: %s\n", contact
.emails_field
[0]);
224 ptr
= strstr(xml
, contact
.content
);
225 fail_if(ptr
== NULL
, "XML lacks a field: %s\n", contact
.content
);
226 ptr
= strstr(xml
, contact
.org_name
);
227 fail_if(ptr
== NULL
, "XML lacks a field: %s\n", contact
.org_name
);
228 ptr
= strstr(xml
, contact
.org_title
);
229 fail_if(ptr
== NULL
, "XML lacks a field: %s\n", contact
.org_title
);
230 ptr
= strstr(xml
, contact
.phone_numbers_field
[0]);
231 fail_if(ptr
== NULL
, "XML lacks a field: %s\n", contact
.phone_numbers_field
[0]);
232 ptr
= strstr(xml
, "This One St, n 23");
233 fail_if(ptr
== NULL
, "XML lacks a field: street\n");
234 ptr
= strstr(xml
, "PO BOX 333 444 5");
235 fail_if(ptr
== NULL
, "XML lacks a field: pobox\n");
236 ptr
= strstr(xml
, "My Hometown");
237 fail_if(ptr
== NULL
, "XML lacks a field: city\n");
238 ptr
= strstr(xml
, "Hereorthere");
239 fail_if(ptr
== NULL
, "XML lacks a field: region\n");
240 ptr
= strstr(xml
, "XYZ 98765-C");
241 fail_if(ptr
== NULL
, "XML lacks a field: postcode\n");
242 ptr
= strstr(xml
, "Island");
243 fail_if(ptr
== NULL
, "XML lacks a field: country\n");
244 ptr
= strstr(xml
, contact
.birthday
);
245 fail_if(ptr
== NULL
, "XML lacks a field: %s\n", contact
.birthday
);
246 /* TODO: im requires a new field for service type (i.e. AIM, yahoo,
249 // ptr = strstr(xml, contact.im);
250 // fail_if(ptr == NULL, "XML lacks a field: %s\n", contact.im);
257 START_TEST (test_contact_add
)
259 int result
, address_nr
, address_count
;
260 struct gcal_contact contact
;
262 // contact.common.title = "John Doe";
263 contact
.common
.title
= NULL
;
265 contact
.structured_name
=(struct gcal_structured_subvalues
*)malloc(sizeof(struct gcal_structured_subvalues
));
266 contact
.structured_name
->field_typenr
= 0;
267 contact
.structured_name
->field_key
= malloc(sizeof(char*));
268 contact
.structured_name
->field_key
= NULL
;
269 contact
.structured_name
->field_value
= malloc(sizeof(char*));
270 contact
.structured_name
->field_value
= NULL
;
271 contact
.structured_name_nr
= 1;
272 gcal_contact_set_structured_entry(contact
.structured_name
,0,1,"givenName","John");
273 gcal_contact_set_structured_entry(contact
.structured_name
,0,1,"additionalName","W.");
274 gcal_contact_set_structured_entry(contact
.structured_name
,0,1,"familyName","Doe");
275 gcal_contact_set_structured_entry(contact
.structured_name
,0,1,"namePrefix","Dr.");
276 gcal_contact_set_structured_entry(contact
.structured_name
,0,1,"nameSuffix","IV.");
278 contact
.emails_field
= malloc(sizeof(char*));
279 contact
.emails_field
[0] = "john.doe@foo.bar.com";
280 contact
.emails_type
= malloc(sizeof(char*));
281 contact
.emails_type
[0] = "home";
282 contact
.emails_nr
= 1;
283 contact
.pref_email
= 0;
284 contact
.common
.id
= contact
.common
.updated
= contact
.common
.edit_uri
= contact
.common
.etag
= NULL
;
285 contact
.photo
= contact
.photo_data
= NULL
;
287 contact
.nickname
= "The Fox";
288 contact
.content
= "A very interesting person";
289 contact
.org_name
= "Foo software";
290 contact
.org_title
= "Software engineer";
291 contact
.occupation
= "Programmer";
292 contact
.birthday
= "1980-10-10";
293 contact
.im_address
= malloc(sizeof(char*));
294 contact
.im_address
[0] = "john";
295 contact
.im_protocol
= malloc(sizeof(char*));
296 contact
.im_protocol
[0] = "SKYPE";
297 contact
.im_type
= malloc(sizeof(char*));
298 contact
.im_type
[0] = "home";
300 contact
.phone_numbers_field
= malloc(sizeof(char*));
301 contact
.phone_numbers_field
[0] = "+9977554422119900";
302 contact
.phone_numbers_type
= malloc(sizeof(char*));
303 contact
.phone_numbers_type
[0] = "home";
304 contact
.phone_numbers_nr
= 1;
305 contact
.groupMembership
= malloc(sizeof(char*));
306 contact
.groupMembership
[0] = "http://www.google.com/m8/feeds/groups/gcalntester%40gmail.com/base/6";
307 contact
.groupMembership_nr
= 1;
308 contact
.birthday
= "1980-10-10";
309 contact
.homepage
= "www.homegage.com";
310 contact
.blog
= "myblog.homegage.com";
311 contact
.structured_address
=(struct gcal_structured_subvalues
*)malloc(sizeof(struct gcal_structured_subvalues
));
312 contact
.structured_address
->field_typenr
= 0;
313 contact
.structured_address
->field_key
= malloc(sizeof(char*));
314 contact
.structured_address
->field_key
= NULL
;
315 contact
.structured_address
->field_value
= malloc(sizeof(char*));
316 contact
.structured_address
->field_value
= NULL
;
317 contact
.structured_address_nr
= 0;
318 contact
.structured_address_type
= (char**)malloc(sizeof(char*));
319 address_nr
= gcal_contact_set_structured_address_nr(&contact
,A_HOME
);
320 address_count
= contact
.structured_address_nr
;
321 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"street","Unknown Av St, n 69");
322 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"pobox","PO BOX 123 456");
323 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"city","Dirty Old Town");
324 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"region","Somewhere");
325 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"postcode","ABC 12345-D");
326 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"country","Madagascar");
327 address_nr
= gcal_contact_set_structured_address_nr(&contact
,A_WORK
);
328 address_count
= contact
.structured_address_nr
;
329 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"street","This One St, n 23");
330 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"pobox","PO BOX 333 444 5");
331 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"city","My Hometown");
332 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"region","Hereorthere");
333 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"postcode","XYZ 98765-C");
334 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"country","Island");
336 result
= gcal_get_authentication(ptr_gcal
, "gcalntester", "77libgcal");
337 fail_if(result
== -1, "Authentication should work.");
339 result
= gcal_create_contact(ptr_gcal
, &contact
, NULL
);
340 fail_if(result
== -1, "Failed creating a new contact!");
342 /* I commented this test because it prints too much error
343 * information to stderr. I must add a logging of some sort
346 /* Trying to insert another contact with same email
347 * should trigger HTTP 409 Conflict code.
349 /* result = gcal_create_contact(&contact, ptr_gcal); */
350 /* fail_if(result != -1, "Adding the same contact must conflict!"); */
356 START_TEST (test_contact_delete
)
358 /* This test assumes that 'test_contact_add' worked fine:
359 * I'm going to delete that contact.
361 char *test_title
= "Dr. John W. Doe IV.", *temp
= (char *)malloc(255);;
362 char *test_email
= "john.doe@foo.bar.com";
363 struct gcal_contact
*contacts
;
364 int i
, result
, entry_index
= -1;
367 result
= gcal_get_authentication(ptr_gcal
, "gcalntester", "77libgcal");
368 fail_if(result
== -1, "Authentication should work.");
370 result
= gcal_dump(ptr_gcal
, "GData-Version: 3.0");
371 fail_if(result
!= 0, "Failed dumping contacts");
373 contacts
= gcal_get_all_contacts(ptr_gcal
, &count
);
374 fail_if(contacts
== NULL
, "Failed extracting contacts vector!");
376 for (i
= 0; i
< (int)count
; ++i
) {
377 if (contacts
[i
].structured_name
)
378 temp
= gcal_contact_get_structured_entry(contacts
[i
].structured_name
,0,1,"fullName");
382 if (contacts
[i
].emails_field
&& temp
) {
383 if ((!(strcmp(contacts
[i
].emails_field
[0], test_email
))) &&
384 (!(strcmp(temp
, test_title
)))) {
391 temp
= (char *)malloc(255);
392 sprintf(temp
, "Cannot locate the newly added contact!\nindex = %d\tname = %s\n", entry_index
,
393 contacts
[entry_index
].common
.title
);
394 fail_if(entry_index
== -1, temp
);
397 result
= gcal_delete_contact(ptr_gcal
, (contacts
+ entry_index
));
398 fail_if(result
== -1, "Failed deleting contact!");
400 gcal_destroy_contacts(contacts
, count
);
404 START_TEST (test_contact_edit
)
406 int result
, address_nr
, address_count
;
407 struct gcal_contact contact
, contact_new
, updated
;
408 gcal_structured_subvalues_t structured_entry
;
410 // contact.common.title = "Johny Doe";
411 contact
.common
.title
= NULL
;
413 contact
.structured_name
=(struct gcal_structured_subvalues
*)malloc(sizeof(struct gcal_structured_subvalues
));
414 contact
.structured_name
->field_typenr
= 0;
415 contact
.structured_name
->field_key
= malloc(sizeof(char*));
416 contact
.structured_name
->field_key
= NULL
;
417 contact
.structured_name
->field_value
= malloc(sizeof(char*));
418 contact
.structured_name
->field_value
= NULL
;
419 contact
.structured_name_nr
= 1;
420 gcal_contact_set_structured_entry(contact
.structured_name
,0,1,"givenName","John");
421 gcal_contact_set_structured_entry(contact
.structured_name
,0,1,"additionalName","W.");
422 gcal_contact_set_structured_entry(contact
.structured_name
,0,1,"familyName","Doe");
423 gcal_contact_set_structured_entry(contact
.structured_name
,0,1,"namePrefix","Dr.");
425 contact
.photo
= contact
.photo_data
= NULL
;
426 contact
.photo_length
= 0;
427 contact
.emails_field
= malloc(sizeof(char*));
428 contact
.emails_field
[0] = "johny.doe@foo.bar.com";
429 contact
.emails_nr
= 1;
430 contact
.pref_email
= 0;
431 contact
.emails_type
= malloc(sizeof(char*));
432 contact
.emails_type
[0] = "home";
433 contact
.common
.id
= contact
.common
.updated
= contact
.common
.edit_uri
= contact
.common
.etag
= NULL
;
435 contact
.nickname
= "The Fox";
436 contact
.content
= "A very interesting person";
437 contact
.org_name
= "Foo software";
438 contact
.org_title
= "Software engineer";
439 contact
.occupation
= "Programmer";
440 contact
.birthday
= "1980-10-10";
441 contact
.im_address
= malloc(sizeof(char*));
442 contact
.im_address
[0] = "johny";
443 contact
.im_protocol
= malloc(sizeof(char*));
444 contact
.im_protocol
[0] = "SKYPE";
445 contact
.im_type
= malloc(sizeof(char*));
446 contact
.im_type
[0] = "home";
448 contact
.phone_numbers_field
= malloc(sizeof(char*));
449 contact
.phone_numbers_field
[0] = "+9977554422119900";
450 contact
.phone_numbers_type
= malloc(sizeof(char*));
451 contact
.phone_numbers_type
[0] = "home";
452 contact
.phone_numbers_nr
= 1;
453 contact
.groupMembership
= malloc(sizeof(char*));
454 contact
.groupMembership
[0] = "http://www.google.com/m8/feeds/groups/gcalntester%40gmail.com/base/6";
455 contact
.groupMembership_nr
= 1;
456 contact
.birthday
= "1980-10-10";
457 contact
.homepage
= "www.homegage.com";
458 contact
.blog
= "myblog.homegage.com";
459 contact
.structured_address
=(struct gcal_structured_subvalues
*)malloc(sizeof(struct gcal_structured_subvalues
));
460 contact
.structured_address
->field_typenr
= 0;
461 contact
.structured_address
->field_key
= malloc(sizeof(char*));
462 contact
.structured_address
->field_key
= NULL
;
463 contact
.structured_address
->field_value
= malloc(sizeof(char*));
464 contact
.structured_address
->field_value
= NULL
;
465 contact
.structured_address_nr
= 0;
466 contact
.structured_address_type
= (char**)malloc(sizeof(char*));
467 address_nr
= gcal_contact_set_structured_address_nr(&contact
,A_HOME
);
468 address_count
= contact
.structured_address_nr
;
469 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"street","Unknown Av St, n 69");
470 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"pobox","PO BOX 123 456");
471 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"city","Dirty Old Town");
472 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"region","Somewhere");
473 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"postcode","ABC 12345-D");
474 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"country","Madagascar");
475 address_nr
= gcal_contact_set_structured_address_nr(&contact
,A_WORK
);
476 address_count
= contact
.structured_address_nr
;
477 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"street","This One St, n 23");
478 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"pobox","PO BOX 333 444 5");
479 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"city","My Hometown");
480 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"region","Hereorthere");
481 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"postcode","XYZ 98765-C");
482 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"country","Island");
484 /* Authenticate and add a new contact */
485 result
= gcal_get_authentication(ptr_gcal
, "gcalntester", "77libgcal");
486 fail_if(result
== -1, "Authentication should work.");
487 result
= gcal_create_contact(ptr_gcal
, &contact
, &contact_new
);
490 // if(contact_new.common.title)
491 // free(contact_new.common.title);
492 // contact_new.common.title = strdup("Johny 'the mad' Doe");
493 contact_new
.structured_name
=(struct gcal_structured_subvalues
*)malloc(sizeof(struct gcal_structured_subvalues
));
494 contact_new
.structured_name
->field_typenr
= 0;
495 contact_new
.structured_name
->field_key
= malloc(sizeof(char*));
496 contact_new
.structured_name
->field_key
= NULL
;
497 contact_new
.structured_name
->field_value
= malloc(sizeof(char*));
498 contact_new
.structured_name
->field_value
= NULL
;
499 contact_new
.structured_name_nr
= 1;
500 gcal_contact_set_structured_entry(contact_new
.structured_name
,0,1,"givenName","Johny");
501 gcal_contact_set_structured_entry(contact_new
.structured_name
,0,1,"additionalName","'the mad'");
502 gcal_contact_set_structured_entry(contact_new
.structured_name
,0,1,"familyName","Doe");
504 result
= gcal_edit_contact(ptr_gcal
, &contact_new
, &updated
);
505 fail_if(result
== -1, "Failed editing contact!");
507 structured_entry
= gcal_contact_get_structured_address(&contact
);
508 gcal_contact_delete_structured_entry(structured_entry
,gcal_contact_get_structured_address_count_obj(&contact
),gcal_contact_get_structured_address_type_obj(&contact
));
510 contact
.structured_address
->field_typenr
= 0;
511 contact
.structured_address
->field_key
= malloc(sizeof(char*));
512 contact
.structured_address
->field_key
= NULL
;
513 contact
.structured_address
->field_value
= malloc(sizeof(char*));
514 contact
.structured_address
->field_value
= NULL
;
515 contact
.structured_address_nr
= 0;
516 contact
.structured_address_type
= (char**)malloc(sizeof(char*));
517 address_nr
= gcal_contact_set_structured_address_nr(&contact
,A_HOME
);
518 address_count
= contact
.structured_address_nr
;
519 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"street","Unknown Av St, n 69");
520 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"pobox","PO BOX 123 456");
521 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"city","Dirty Old Town");
522 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"region","Somewhere");
523 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"postcode","ABC 12345-D");
524 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"country","Madagascar");
525 address_nr
= gcal_contact_set_structured_address_nr(&contact
,A_WORK
);
526 address_count
= contact
.structured_address_nr
;
527 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"street","This One St, n 23");
528 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"pobox","PO BOX 333 444 5");
529 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"city","My Hometown");
530 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"region","Hereorthere");
531 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"postcode","XYZ 98765-C");
532 gcal_contact_set_structured_entry(contact
.structured_address
,address_nr
,address_count
,"country","Island");
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
);