source: tests/check.c @ ed5df81

Last change on this file since ed5df81 was ed5df81, checked in by Jelmer Vernooij <jelmer@…>, at 2007-01-21T21:17:11Z

Add unit testing for user code

  • Property mode set to 100644
File size: 2.3 KB
RevLine 
[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
8global_t global;        /* Against global namespace pollution */
9
[6a90967]10gboolean 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
[ed5df81]23irc_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
[1fc2958]33double gettime()
34{
35        struct timeval time[1];
36
37        gettimeofday( time, 0 );
38        return( (double) time->tv_sec + (double) time->tv_usec / 1000000 );
39}
[c2fa827]40
41/* From check_util.c */
42Suite *util_suite(void);
43
[1fc2958]44/* From check_nick.c */
45Suite *nick_suite(void);
46
[6a90967]47/* From check_md5.c */
48Suite *md5_suite(void);
49
[7bcdde3]50/* From check_irc.c */
51Suite *irc_suite(void);
52
[c227706]53/* From check_help.c */
54Suite *help_suite(void);
55
[ed5df81]56/* From check_user.c */
57Suite *user_suite(void);
58
[3b4cc8f]59int main (int argc, char **argv)
[c2fa827]60{
61        int nf;
[3b4cc8f]62        SRunner *sr;
63        GOptionContext *pc;
64        gboolean no_fork = FALSE;
65        gboolean verbose = FALSE;
66        GOptionEntry options[] = {
67                {"no-fork", 'n', 0, G_OPTION_ARG_NONE, &no_fork, "Don't fork" },
68                {"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Be verbose", NULL },
69                { NULL }
70        };
71        int i;
72
73        pc = g_option_context_new("");
74        g_option_context_add_main_entries(pc, options, NULL);
75
76        if(!g_option_context_parse(pc, &argc, &argv, NULL))
77                return 1;
78
79        g_option_context_free(pc);
80
[7bcdde3]81        log_init();
82
83        if (verbose) {
84                log_link( LOGLVL_ERROR, LOGOUTPUT_CONSOLE );
[9225e08]85#ifdef DEBUG
[7bcdde3]86                log_link( LOGLVL_DEBUG, LOGOUTPUT_CONSOLE );
[9225e08]87#endif
[7bcdde3]88                log_link( LOGLVL_INFO, LOGOUTPUT_CONSOLE );
89                log_link( LOGLVL_WARNING, LOGOUTPUT_CONSOLE );
90        }
91
92        global.conf = conf_load( 0, NULL);
93        global.conf->runmode = RUNMODE_DAEMON;
[3b4cc8f]94
95        sr = srunner_create(util_suite());
[1fc2958]96        srunner_add_suite(sr, nick_suite());
[6a90967]97        srunner_add_suite(sr, md5_suite());
[7bcdde3]98        srunner_add_suite(sr, irc_suite());
[c227706]99        srunner_add_suite(sr, help_suite());
[ed5df81]100        srunner_add_suite(sr, user_suite());
[3b4cc8f]101        if (no_fork)
102                srunner_set_fork_status(sr, CK_NOFORK);
103        srunner_run_all (sr, verbose?CK_VERBOSE:CK_NORMAL);
[c2fa827]104        nf = srunner_ntests_failed(sr);
105        srunner_free(sr);
106        return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
107}
Note: See TracBrowser for help on using the repository browser.