3 * @author Adenilson Cavalcanti da Silva <adenilson.silva@indt.org.br>
4 * @date Fri Aug 1 17:36:44 2008
6 * @brief Utest trying to break the library.
8 * Tests with bad practices and forcing misuse of libgcal goes here.
11 #include "utest_screw.h"
12 #include "gcalendar.h"
14 /* XXX: API violation for forcing an error condition in 'mount_query_url' */
15 #include "internal_gcal.h"
17 START_TEST (test_usercalendarapi
)
20 struct gcal_event_array event_array
;
26 /* Wrong object construction */
27 gcal
= gcal_new(1345);
28 fail_if(gcal
!= NULL
, "Should return NULL!");
29 result
= gcal_get_authentication(gcal
, "nonexistant", "invalid");
30 fail_if(result
!= -1, "Should fail authentication!");
33 /* Querying without authentication/username */
34 gcal
= gcal_new(GCALENDAR
);
35 result
= gcal_get_updated_events(gcal
, &event_array
, NULL
);
36 fail_if(result
!= -1, "Should fail querying updated!");
37 result
= gcal_get_events(gcal
, &event_array
);
38 fail_if(result
!= -1, "Should fail querying!");
39 /* XXX: forcing test of internal 'mount_query_url' */
40 gcal
->auth
= "foobie";
41 result
= gcal_get_updated_events(gcal
, &event_array
, NULL
);
42 fail_if(result
!= -1, "Should fail querying updated!");
47 /* Failed authentication */
48 gcal
= gcal_new(GCALENDAR
);
49 result
= gcal_get_authentication(gcal
, "nonexistant", "invalid");
50 fail_if(result
!= -1, "Should fail authentication!");
51 result
= gcal_get_events(gcal
, NULL
);
52 fail_if(result
!= -1, "Should event extraction!");
53 result
= gcal_get_events(gcal
, &event_array
);
54 fail_if(result
!= -1, "Should event extraction!");
56 for (i
= 0; i
< event_array
.length
; ++i
) {
57 event
= gcal_event_element(&event_array
, i
);
58 fail_if(event
!= NULL
, "Should return NULL!");
59 ptr
= gcal_event_get_id(event
);
60 fail_if(ptr
!= NULL
, "Should return NULL!");
63 /* Forces access to elements */
64 event
= gcal_event_element(&event_array
, -1);
65 fail_if(event
!= NULL
, "Should return NULL!");
66 event
= gcal_event_element(&event_array
, 0);
67 fail_if(event
!= NULL
, "Should return NULL!");
68 ptr
= gcal_event_get_id(event
);
69 fail_if(ptr
!= NULL
, "Should return NULL!");
72 gcal_cleanup_events(&event_array
);
78 START_TEST (test_usermismatch
)
81 struct gcal_event_array event_array
;
82 struct gcal_contact_array contact_array
;
84 gcal_contact_t contact
;
87 gcal
= gcal_new(GCALENDAR
);
88 result
= gcal_get_authentication(gcal
, "gcal4tester", "66libgcal");
89 result
= gcal_get_events(gcal
, &contact_array
);
90 fail_if(result
!= -1, "Should fail writing contact out of a calendar!");
91 contact
= gcal_contact_element(&contact_array
, 0);
92 fail_if(contact
!= NULL
, "Contact should be NULL!");
94 gcal_set_service(gcal
, GCONTACT
);
95 result
= gcal_get_authentication(gcal
, "gcal4tester", "66libgcal");
96 result
= gcal_get_contacts(gcal
, &event_array
);
97 fail_if(result
!= -1, "Should fail writing events out of contacts!");
98 event
= gcal_event_element(&event_array
, 0);
99 fail_if(event
!= NULL
, "Event should be NULL!");
104 TCase
*gcal_screw(void)
107 int timeout_seconds
= 50;
108 tc
= tcase_create("gcalscrew");
109 tcase_set_timeout (tc
, timeout_seconds
);
111 tcase_add_test(tc
, test_usercalendarapi
);
112 tcase_add_test(tc
, test_usermismatch
);