[c2fa827] | 1 | #include <stdlib.h> |
---|
| 2 | #include <glib.h> |
---|
| 3 | #include <gmodule.h> |
---|
| 4 | #include <check.h> |
---|
[1fc2958] | 5 | #include "bitlbee.h" |
---|
[6a90967] | 6 | #include "testsuite.h" |
---|
[1fc2958] | 7 | |
---|
| 8 | global_t global; /* Against global namespace pollution */ |
---|
| 9 | |
---|
[6a90967] | 10 | gboolean g_io_channel_pair(GIOChannel **ch1, GIOChannel **ch2) |
---|
| 11 | { |
---|
| 12 | int sock[2]; |
---|
| 13 | if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNIX, sock) < 0) { |
---|
| 14 | perror("socketpair"); |
---|
| 15 | return FALSE; |
---|
| 16 | } |
---|
| 17 | |
---|
| 18 | *ch1 = g_io_channel_unix_new(sock[0]); |
---|
| 19 | *ch2 = g_io_channel_unix_new(sock[1]); |
---|
| 20 | return TRUE; |
---|
| 21 | } |
---|
| 22 | |
---|
[1fc2958] | 23 | double gettime() |
---|
| 24 | { |
---|
| 25 | struct timeval time[1]; |
---|
| 26 | |
---|
| 27 | gettimeofday( time, 0 ); |
---|
| 28 | return( (double) time->tv_sec + (double) time->tv_usec / 1000000 ); |
---|
| 29 | } |
---|
[c2fa827] | 30 | |
---|
| 31 | /* From check_util.c */ |
---|
| 32 | Suite *util_suite(void); |
---|
| 33 | |
---|
[1fc2958] | 34 | /* From check_nick.c */ |
---|
| 35 | Suite *nick_suite(void); |
---|
| 36 | |
---|
[6a90967] | 37 | /* From check_md5.c */ |
---|
| 38 | Suite *md5_suite(void); |
---|
| 39 | |
---|
[7bcdde3] | 40 | /* From check_irc.c */ |
---|
| 41 | Suite *irc_suite(void); |
---|
| 42 | |
---|
[3b4cc8f] | 43 | int main (int argc, char **argv) |
---|
[c2fa827] | 44 | { |
---|
| 45 | int nf; |
---|
[3b4cc8f] | 46 | SRunner *sr; |
---|
| 47 | GOptionContext *pc; |
---|
| 48 | gboolean no_fork = FALSE; |
---|
| 49 | gboolean verbose = FALSE; |
---|
| 50 | GOptionEntry options[] = { |
---|
| 51 | {"no-fork", 'n', 0, G_OPTION_ARG_NONE, &no_fork, "Don't fork" }, |
---|
| 52 | {"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Be verbose", NULL }, |
---|
| 53 | { NULL } |
---|
| 54 | }; |
---|
| 55 | int i; |
---|
| 56 | |
---|
| 57 | pc = g_option_context_new(""); |
---|
| 58 | g_option_context_add_main_entries(pc, options, NULL); |
---|
| 59 | |
---|
| 60 | if(!g_option_context_parse(pc, &argc, &argv, NULL)) |
---|
| 61 | return 1; |
---|
| 62 | |
---|
| 63 | g_option_context_free(pc); |
---|
| 64 | |
---|
[7bcdde3] | 65 | log_init(); |
---|
| 66 | |
---|
| 67 | if (verbose) { |
---|
| 68 | log_link( LOGLVL_ERROR, LOGOUTPUT_CONSOLE ); |
---|
| 69 | log_link( LOGLVL_DEBUG, LOGOUTPUT_CONSOLE ); |
---|
| 70 | log_link( LOGLVL_INFO, LOGOUTPUT_CONSOLE ); |
---|
| 71 | log_link( LOGLVL_WARNING, LOGOUTPUT_CONSOLE ); |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | global.conf = conf_load( 0, NULL); |
---|
| 75 | global.conf->runmode = RUNMODE_DAEMON; |
---|
[3b4cc8f] | 76 | |
---|
| 77 | sr = srunner_create(util_suite()); |
---|
[1fc2958] | 78 | srunner_add_suite(sr, nick_suite()); |
---|
[6a90967] | 79 | srunner_add_suite(sr, md5_suite()); |
---|
[7bcdde3] | 80 | srunner_add_suite(sr, irc_suite()); |
---|
[3b4cc8f] | 81 | if (no_fork) |
---|
| 82 | srunner_set_fork_status(sr, CK_NOFORK); |
---|
| 83 | srunner_run_all (sr, verbose?CK_VERBOSE:CK_NORMAL); |
---|
[c2fa827] | 84 | nf = srunner_ntests_failed(sr); |
---|
| 85 | srunner_free(sr); |
---|
| 86 | return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE; |
---|
| 87 | } |
---|