ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/test/unit/test.h
Revision: 1.8
Committed: Sat Sep 22 14:27:30 2007 UTC (19 years, 2 months ago) by pippijn
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.7: +4 -3 lines
Log Message:
split up ermyth into ermyth-modules, libermyth (currently just ermyth-util) and ermyth-core

File Contents

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