1 | #include <stdlib.h> |
---|
2 | #include <glib.h> |
---|
3 | #include <gmodule.h> |
---|
4 | #include <check.h> |
---|
5 | #include "bitlbee.h" |
---|
6 | #include "testsuite.h" |
---|
7 | |
---|
8 | global_t global; /* Against global namespace pollution */ |
---|
9 | |
---|
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 | |
---|
23 | irc_t *torture_irc(void) |
---|
24 | { |
---|
25 | irc_t *irc; |
---|
26 | GIOChannel *ch1, *ch2; |
---|
27 | if (!g_io_channel_pair(&ch1, &ch2)) |
---|
28 | return NULL; |
---|
29 | irc = irc_new(g_io_channel_unix_get_fd(ch1)); |
---|
30 | return irc; |
---|
31 | } |
---|
32 | |
---|
33 | double gettime() |
---|
34 | { |
---|
35 | struct timeval time[1]; |
---|
36 | |
---|
37 | gettimeofday( time, 0 ); |
---|
38 | return( (double) time->tv_sec + (double) time->tv_usec / 1000000 ); |
---|
39 | } |
---|
40 | |
---|
41 | /* From check_util.c */ |
---|
42 | Suite *util_suite(void); |
---|
43 | |
---|
44 | /* From check_nick.c */ |
---|
45 | Suite *nick_suite(void); |
---|
46 | |
---|
47 | /* From check_md5.c */ |
---|
48 | Suite *md5_suite(void); |
---|
49 | |
---|
50 | /* From check_irc.c */ |
---|
51 | Suite *irc_suite(void); |
---|
52 | |
---|
53 | /* From check_help.c */ |
---|
54 | Suite *help_suite(void); |
---|
55 | |
---|
56 | /* From check_user.c */ |
---|
57 | Suite *user_suite(void); |
---|
58 | |
---|
59 | /* From check_crypting.c */ |
---|
60 | Suite *crypting_suite(void); |
---|
61 | |
---|
62 | /* From check_set.c */ |
---|
63 | Suite *set_suite(void); |
---|
64 | |
---|
65 | int main (int argc, char **argv) |
---|
66 | { |
---|
67 | int nf; |
---|
68 | SRunner *sr; |
---|
69 | GOptionContext *pc; |
---|
70 | gboolean no_fork = FALSE; |
---|
71 | gboolean verbose = FALSE; |
---|
72 | GOptionEntry options[] = { |
---|
73 | {"no-fork", 'n', 0, G_OPTION_ARG_NONE, &no_fork, "Don't fork" }, |
---|
74 | {"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Be verbose", NULL }, |
---|
75 | { NULL } |
---|
76 | }; |
---|
77 | int i; |
---|
78 | |
---|
79 | pc = g_option_context_new(""); |
---|
80 | g_option_context_add_main_entries(pc, options, NULL); |
---|
81 | |
---|
82 | if(!g_option_context_parse(pc, &argc, &argv, NULL)) |
---|
83 | return 1; |
---|
84 | |
---|
85 | g_option_context_free(pc); |
---|
86 | |
---|
87 | log_init(); |
---|
88 | |
---|
89 | if (verbose) { |
---|
90 | log_link( LOGLVL_ERROR, LOGOUTPUT_CONSOLE ); |
---|
91 | #ifdef DEBUG |
---|
92 | log_link( LOGLVL_DEBUG, LOGOUTPUT_CONSOLE ); |
---|
93 | #endif |
---|
94 | log_link( LOGLVL_INFO, LOGOUTPUT_CONSOLE ); |
---|
95 | log_link( LOGLVL_WARNING, LOGOUTPUT_CONSOLE ); |
---|
96 | } |
---|
97 | |
---|
98 | global.conf = conf_load( 0, NULL); |
---|
99 | global.conf->runmode = RUNMODE_DAEMON; |
---|
100 | |
---|
101 | sr = srunner_create(util_suite()); |
---|
102 | srunner_add_suite(sr, nick_suite()); |
---|
103 | srunner_add_suite(sr, md5_suite()); |
---|
104 | srunner_add_suite(sr, irc_suite()); |
---|
105 | srunner_add_suite(sr, help_suite()); |
---|
106 | srunner_add_suite(sr, user_suite()); |
---|
107 | srunner_add_suite(sr, crypting_suite()); |
---|
108 | srunner_add_suite(sr, set_suite()); |
---|
109 | if (no_fork) |
---|
110 | srunner_set_fork_status(sr, CK_NOFORK); |
---|
111 | srunner_run_all (sr, verbose?CK_VERBOSE:CK_NORMAL); |
---|
112 | nf = srunner_ntests_failed(sr); |
---|
113 | srunner_free(sr); |
---|
114 | return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE; |
---|
115 | } |
---|