source: tests/check.c @ 15c4cd4

Last change on this file since 15c4cd4 was 9516bb6, checked in by dequis <dx@…>, at 2015-10-30T10:44:37Z

tests: Define a stub sighandler_shutdown_setup() to allow linking

I'm sure that some day the tests will be useful, not just an annoyance.

Some day.

  • Property mode set to 100644
File size: 2.9 KB
RevLine 
[c2fa827]1#include <stdlib.h>
2#include <glib.h>
3#include <gmodule.h>
4#include <check.h>
[b40e60d]5#include <locale.h>
[3e16fb8]6#include <sys/time.h>
[1fc2958]7#include "bitlbee.h"
[6a90967]8#include "testsuite.h"
[1fc2958]9
[5ebff60]10global_t global;        /* Against global namespace pollution */
[1fc2958]11
[6a90967]12gboolean g_io_channel_pair(GIOChannel **ch1, GIOChannel **ch2)
13{
14        int sock[2];
[5ebff60]15
[6a90967]16        if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNIX, sock) < 0) {
17                perror("socketpair");
18                return FALSE;
19        }
20
21        *ch1 = g_io_channel_unix_new(sock[0]);
22        *ch2 = g_io_channel_unix_new(sock[1]);
23        return TRUE;
24}
25
[ed5df81]26irc_t *torture_irc(void)
27{
28        irc_t *irc;
29        GIOChannel *ch1, *ch2;
[5ebff60]30
31        if (!g_io_channel_pair(&ch1, &ch2)) {
[ed5df81]32                return NULL;
[5ebff60]33        }
[ed5df81]34        irc = irc_new(g_io_channel_unix_get_fd(ch1));
35        return irc;
36}
37
[1fc2958]38double gettime()
39{
40        struct timeval time[1];
41
[5ebff60]42        gettimeofday(time, 0);
43        return((double) time->tv_sec + (double) time->tv_usec / 1000000);
[1fc2958]44}
[c2fa827]45
[9516bb6]46void sighandler_shutdown_setup()
47{
48        /* no-op. originally defined in unix.c, needed by bitlbee.c */
49}
50
[c2fa827]51/* From check_util.c */
52Suite *util_suite(void);
53
[1fc2958]54/* From check_nick.c */
55Suite *nick_suite(void);
56
[6a90967]57/* From check_md5.c */
58Suite *md5_suite(void);
59
[2305488]60/* From check_arc.c */
61Suite *arc_suite(void);
62
[7bcdde3]63/* From check_irc.c */
64Suite *irc_suite(void);
65
[c227706]66/* From check_help.c */
67Suite *help_suite(void);
68
[ed5df81]69/* From check_user.c */
70Suite *user_suite(void);
71
[7738014]72/* From check_set.c */
73Suite *set_suite(void);
74
[af97b23]75/* From check_jabber_sasl.c */
76Suite *jabber_sasl_suite(void);
77
[3e6764a]78/* From check_jabber_sasl.c */
79Suite *jabber_util_suite(void);
80
[5ebff60]81int main(int argc, char **argv)
[c2fa827]82{
83        int nf;
[3b4cc8f]84        SRunner *sr;
85        GOptionContext *pc;
86        gboolean no_fork = FALSE;
87        gboolean verbose = FALSE;
88        GOptionEntry options[] = {
[5ebff60]89                { "no-fork", 'n', 0, G_OPTION_ARG_NONE, &no_fork, "Don't fork" },
90                { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Be verbose", NULL },
[3b4cc8f]91                { NULL }
92        };
93
94        pc = g_option_context_new("");
95        g_option_context_add_main_entries(pc, options, NULL);
96
[5ebff60]97        if (!g_option_context_parse(pc, &argc, &argv, NULL)) {
[3b4cc8f]98                return 1;
[5ebff60]99        }
[3b4cc8f]100
101        g_option_context_free(pc);
102
[7bcdde3]103        log_init();
[1521a85]104        b_main_init();
[b40e60d]105        setlocale(LC_CTYPE, "");
[7bcdde3]106
107        if (verbose) {
[5ebff60]108                log_link(LOGLVL_ERROR, LOGOUTPUT_CONSOLE);
[9225e08]109#ifdef DEBUG
[5ebff60]110                log_link(LOGLVL_DEBUG, LOGOUTPUT_CONSOLE);
[9225e08]111#endif
[5ebff60]112                log_link(LOGLVL_INFO, LOGOUTPUT_CONSOLE);
113                log_link(LOGLVL_WARNING, LOGOUTPUT_CONSOLE);
[7bcdde3]114        }
115
[5ebff60]116        global.conf = conf_load(0, NULL);
[7bcdde3]117        global.conf->runmode = RUNMODE_DAEMON;
[3b4cc8f]118
119        sr = srunner_create(util_suite());
[1fc2958]120        srunner_add_suite(sr, nick_suite());
[6a90967]121        srunner_add_suite(sr, md5_suite());
[2305488]122        srunner_add_suite(sr, arc_suite());
[7bcdde3]123        srunner_add_suite(sr, irc_suite());
[c227706]124        srunner_add_suite(sr, help_suite());
[ed5df81]125        srunner_add_suite(sr, user_suite());
[7738014]126        srunner_add_suite(sr, set_suite());
[af97b23]127        srunner_add_suite(sr, jabber_sasl_suite());
[3e6764a]128        srunner_add_suite(sr, jabber_util_suite());
[5ebff60]129        if (no_fork) {
[3b4cc8f]130                srunner_set_fork_status(sr, CK_NOFORK);
[5ebff60]131        }
132        srunner_run_all(sr, verbose ? CK_VERBOSE : CK_NORMAL);
[c2fa827]133        nf = srunner_ntests_failed(sr);
134        srunner_free(sr);
135        return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
136}
Note: See TracBrowser for help on using the repository browser.