source: tests/check.c @ 0b9daac

Last change on this file since 0b9daac was 5ebff60, checked in by dequis <dx@…>, at 2015-02-20T22:50:54Z

Reindent everything to K&R style with tabs

Used uncrustify, with the configuration file in ./doc/uncrustify.cfg

Commit author set to "Indent <please@…>" so that it's easier to
skip while doing git blame.

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