source: tests/check.c @ 7bee5af

Last change on this file since 7bee5af was c227706, checked in by Jelmer Vernooij <jelmer@…>, at 2006-12-24T19:35:13Z

Refactor the help code to take a filename rather than using the global struct.

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