3 * @author Adenilson Cavalcanti
4 * @date Fri Jun 13 14:53:21 2008
6 * @brief Module for libgcal debug functions.
13 #include <sys/types.h>
18 #include "utest_debug.h"
21 #include "gcal_status.h"
24 static struct gcal_resource
*ptr_gcal
= NULL
;
26 static void setup(void)
28 /* here goes any common data allocation */
29 ptr_gcal
= gcal_construct(GCONTACT
);
32 static void teardown(void)
34 /* and here we clean up */
35 gcal_destroy(ptr_gcal
);
38 START_TEST (test_debug_authenticate
)
43 result
= gcal_get_authentication(ptr_gcal
, "gcal4tester", "66libgcal");
44 fail_if(result
!= 0, "Authentication should work!");
46 code
= gcal_status_httpcode(ptr_gcal
);
47 fail_if(code
!= 200, "Reported HTTP code should be 200!");
48 fail_if(gcal_status_msg(ptr_gcal
) != NULL
, "There should be no msg!");
50 result
= gcal_get_authentication(ptr_gcal
, "gcal4tester", "failfail");
51 fail_if(result
== 0, "Authentication must fail!");
53 code
= gcal_status_httpcode(ptr_gcal
);
54 fail_if(code
!= 403, "Reported HTTP code should be 403!");
59 START_TEST (test_debug_logfile
)
63 char *file_path
= "/tmp/libgcal.log";
64 char *error_line
= "code: 403";
65 char *file_content
= NULL
;
68 result
= gcal_status_setlog(ptr_gcal
, file_path
);
69 fail_if(result
== -1, "Failed setting log file!");
71 result
= gcal_get_authentication(ptr_gcal
, "gcal4tester", "failfail");
72 fail_if(result
== 0, "Authentication must fail!");
74 /* This triggers the file closing */
75 gcal_destroy(ptr_gcal
);
78 /* Read file and check for error msg */
79 fd
= open(file_path
, O_RDONLY
);
80 fail_if(fd
== -1, "Cannot open log file!");
81 result
= read_file(fd
, &file_content
, &length
);
82 fail_if(result
, "Failed reading log file!");
84 fail_if((!(strstr(file_content
, error_line
))), "Cannot find HTTP error"
93 TCase
*gcaldebug_tcase_create(void)
96 int timeout_seconds
= 50;
98 tc
= tcase_create("gcaldebug");
99 tcase_add_checked_fixture(tc
, setup
, teardown
);
100 tcase_set_timeout (tc
, timeout_seconds
);
102 tcase_add_test(tc
, test_debug_authenticate
);
103 tcase_add_test(tc
, test_debug_logfile
);