ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/test/unit/test.h
Revision: 1.2
Committed: Sat Jul 21 01:29:13 2007 UTC (19 years, 3 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.1: +1 -1 lines
Log Message:
- moved to new documentation system
- fixed small build error

File Contents

# User Rev Content
1 pippijn 1.1 // STL
2     #include <iostream>
3     #include <string>
4    
5     // Standard C
6     #include <cstddef>
7    
8     // Atheme
9     #include "atheme.h"
10     #include "account.h"
11     #include "uplink.h"
12     #include "pmodule.h"
13     #include "internal.h"
14     #include "datastream.h"
15     #include "authcookie.h"
16     #include "account/kline.h"
17     #include "account/myuser.h"
18     #include "account/mychan.h"
19     #include "account/chanacs.h"
20     #include "account/metadata.h"
21 pippijn 1.2 #include "common/exception.h"
22 pippijn 1.1 #include "protocol/inspircd.h"
23    
24     namespace impl
25     {
26     template<class T>
27     void ensure (srcinf const &si, char const *msg, T const &expr)
28     {
29     if (!expr)
30     std::cerr << "Test `" << msg << "´ failed at " << si.file () << ", line " << si.line () << "\n";
31     }
32    
33     void ensure_streq (srcinf const &si, const char * const msg, const char * const expected)
34     {
35     if (strcmp (msg, expected))
36     std::cerr << "Test `" << msg << "´ expected " << expected
37     << ", but got " << msg << " at " << si.file () << ", line " << si.line () << "\n";
38     }
39    
40     template<class T>
41     void ensure_null (srcinf const &si, char const *msg, T const &expr)
42     {
43     if (!(expr == 0))
44     std::cerr << "Test `" << msg << " == 0´ failed at " << si.file () << ", line " << si.line () << "\n";
45     }
46    
47     template<class T>
48     void ensure_equals (srcinf const &si, char const *msg, T const &actual, T const &expected)
49     {
50     if (actual != expected)
51     std::cerr << "Test `" << msg << "´ expected " << expected
52     << ", but got " << actual << " at " << si.file () << ", line " << si.line () << "\n";
53     }
54    
55     template<class T>
56     void ensure_distance (srcinf const &si, char const *msg, T const &actual, T const &expected, T const &tolerance)
57     {
58     if (expected - tolerance > actual || expected + tolerance < actual)
59     std::cerr << "Test `" << msg << "´ expected [" << expected - tolerance << ";"
60     << expected + tolerance << "], but got " << actual << " at "
61     << si.file () << ", line " << si.line () << "\n";
62     }
63     }
64    
65     #define ensure(expr) impl::ensure (SRCINF, #expr, expr)
66     #define ensure_streq(msg, expected) impl::ensure_streq (SRCINF, msg, expected)
67     #define ensure_null(expr) impl::ensure_null (SRCINF, #expr, expr)
68     #define ensure_equals(actual, expected) impl::ensure_equals (SRCINF, #actual, actual, expected)
69     #define ensure_distance(actual, expected, tolerance) impl::ensure_distance (SRCINF, #actual, actual, expected, tolerance)
70    
71    
72     template<int n>
73     void exec_test ()
74     {
75     exit (EXIT_SUCCESS);
76     }
77    
78     #define test template<> void exec_test
79    
80     void run_tests (void);
81    
82     /****************
83     * Ermyth stuff
84     */
85    
86     // We need this...
87     ircd_t InspIRCd = {
88     "InspIRCd 1.1.x", /* IRCd name */
89     "$", /* TLD Prefix, used by Global. */
90     false, /* Whether or not we use IRCNet/TS6 UID */
91     false, /* Whether or not we use RCOMMAND */
92     true, /* Whether or not we support channel owners. */
93     true, /* Whether or not we support channel protection. */
94     true, /* Whether or not we support halfops. */
95     false, /* Whether or not we use P10 */
96     true, /* Whether or not we use vHosts. */
97     CMODE_OPERONLY, /* Oper-only cmodes */
98     CMODE_OWNER, /* Integer flag for owner channel flag. */
99     CMODE_PROTECT, /* Integer flag for protect channel flag. */
100     CMODE_HALFOP, /* Integer flag for halfops. */
101     "+q", /* Mode we set for owner. */
102     "+a", /* Mode we set for protect. */
103     "+h", /* Mode we set for halfops. */
104     PROTOCOL_INSPIRCD, /* Protocol type */
105     0, /* Permanent cmodes */
106     "beIg", /* Ban-like cmodes */
107     'e', /* Except mchar */
108     'I', /* Invex mchar */
109     IRCD_CIDR_BANS /* Flags */
110     };
111    
112     /**
113     * services main () style setup
114     */
115     int
116     main (int argc, char *argv[])
117     {
118     ircd = &InspIRCd;
119     curr_uplink = NULL;
120    
121     cold_start = true;
122    
123     runflags |= RF_STARTING;
124    
125     me.start = time (NULL);
126     NOW = me.start;
127     srand (arc4random ());
128     me.execname = argv[0];
129    
130     /* set signal handlers */
131     init_signal_handlers ();
132    
133     event_init ();
134     initBlockHeap ();
135     init_dlink_nodes ();
136     hooks_init ();
137     init_netio ();
138     init_socket_queues ();
139    
140     init_nodes ();
141     servtree_init ();
142     init_ircpacket ();
143    
144     modules_init ();
145     pcommand_init ();
146    
147     authcookie_init ();
148     common_ctcp_init ();
149     update_chanacs_flags ();
150    
151     /* we've done the critical startup steps now */
152     cold_start = false;
153    
154     /* no longer starting */
155     runflags &= ~RF_STARTING;
156    
157     /* we probably have a few open already... */
158     me.maxfd = 3;
159    
160     me.connected = false;
161    
162     /* run tests instead of main loop (no logging available, no uplink ready) */
163     run_tests ();
164    
165     errno = 0;
166    
167     return 0;
168     }