/* * test.h: TODO * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team * Rights to this code are documented in doc/poddoc/license.pod * * $Id: test.h,v 1.8 2007/09/22 14:27:30 pippijn Exp $ */ // STL #include #include // Standard C #include // Atheme #include "atheme.h" #include #include "account.h" #include "uplink.h" #include "pmodule.h" #include "internal.h" #include "datastream.h" #include "authcookie.h" #include "account/kline.h" #include "account/myuser.h" #include "account/mynick.h" #include "account/mychan.h" #include "account/chanacs.h" #include "account/metadata.h" #include "common/balloc.h" #include "util/random.h" #include "util/exception.h" #include #include #include "protocol/inspircd.h" namespace impl { template void ensure (srcinf const &si, char const *msg, T const &expr) { if (!expr) std::cerr << "Test `" << msg << "´ failed at " << si.file () << ", line " << si.line () << "\n"; } void ensure_streq (srcinf const &si, const char * const msg, const char * const actual, const char * const expected) { if (strcmp (actual, expected)) std::cerr << "Test `" << msg << "´ expected " << expected << ", but got " << actual << " at " << si.file () << ", line " << si.line () << "\n"; } template void ensure_null (srcinf const &si, char const *msg, T const &expr) { if (!(expr == 0)) std::cerr << "Test `" << msg << " == 0´ failed at " << si.file () << ", line " << si.line () << "\n"; } template void ensure_equals (srcinf const &si, char const *msg, T const &actual, T const &expected) { if (actual != expected) std::cerr << "Test `" << msg << "´ expected " << expected << ", but got " << actual << " at " << si.file () << ", line " << si.line () << "\n"; } template void ensure_distance (srcinf const &si, char const *msg, T const &actual, T const &expected, T const &tolerance) { if (actual < expected - tolerance || expected + tolerance < actual) std::cerr << "Test `" << msg << "´ expected [" << expected - tolerance << ";" << expected + tolerance << "], but got " << actual << " at " << si.file () << ", line " << si.line () << "\n"; } } #define ensure(expr) impl::ensure (SRCINF, #expr, expr) #define ensure_streq(msg, expected) impl::ensure_streq (SRCINF, #msg, msg, expected) #define ensure_null(expr) impl::ensure_null (SRCINF, #expr, expr) #define ensure_equals(actual, expected) impl::ensure_equals (SRCINF, #actual, actual, expected) #define ensure_distance(actual, expected, tolerance) impl::ensure_distance (SRCINF, #actual, actual, expected, tolerance) template void exec_test () __attribute__ ((__noreturn__)); template void exec_test () { exit (EXIT_SUCCESS); } #define test template<> void exec_test void run_tests (void) __attribute__ ((__noreturn__)); /**************** * Ermyth stuff */ // We need this... protocol::ircd_t InspIRCd = { "InspIRCd 1.1.x", /* IRCd name */ "$", /* TLD Prefix, used by Global. */ false, /* Whether or not we use IRCNet/TS6 UID */ false, /* Whether or not we use RCOMMAND */ true, /* Whether or not we support channel owners. */ true, /* Whether or not we support channel protection. */ true, /* Whether or not we support halfops. */ false, /* Whether or not we use P10 */ true, /* Whether or not we use vHosts. */ CMODE_OPERONLY, /* Oper-only cmodes */ CMODE_OWNER, /* Integer flag for owner channel flag. */ CMODE_PROTECT, /* Integer flag for protect channel flag. */ CMODE_HALFOP, /* Integer flag for halfops. */ "+q", /* Mode we set for owner. */ "+a", /* Mode we set for protect. */ "+h", /* Mode we set for halfops. */ PROTOCOL_INSPIRCD, /* Protocol type */ 0, /* Permanent cmodes */ "beIg", /* Ban-like cmodes */ 'e', /* Except mchar */ 'I', /* Invex mchar */ IRCD_CIDR_BANS /* Flags */ }; /** * services main () style setup */ int main (int argc, char *argv[]) { ircd = &InspIRCd; curr_uplink = NULL; cold_start = true; runflags |= RF_STARTING; // set up shstr buckets std::vector *shstr_buckets = new std::vector [shstr::bucketcnt ()]; shstr::initbuckets (shstr_buckets); me.start = time_t (now ()); NOW = me.start; init_gen_rand (NOW); srand (gen_rand32 ()); me.execname = argv[0]; /* set signal handlers */ init_signal_handlers (); event_init (); init_dlink_nodes (); init_netio (); init_socket_queues (); init_nodes (); servtree_init (); init_ircpacket (); authcookie_init (); common_ctcp_init (); update_chanacs_flags (); /* we've done the critical startup steps now */ cold_start = false; /* no longer starting */ runflags &= ~RF_STARTING; /* we probably have a few open already... */ me.maxfd = 3; me.connected = false; /* run tests instead of main loop (no logging available, no uplink ready) */ run_tests (); /* free used memory */ shstr::cleanup (); modules::cleanup (); mychan_t::cleanup (); mynick_t::cleanup (); myuser_t::cleanup (); delete phandler; log_shutdown (); return 0; }