ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/test/unit/test.h
Revision: 1.4
Committed: Tue Aug 28 22:18:31 2007 UTC (19 years, 1 month ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.3: +2 -2 lines
Log Message:
added type traits

File Contents

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