diff options
-rw-r--r-- | include/configreader.h | 5 | ||||
-rw-r--r-- | include/modules.h | 4 | ||||
-rw-r--r-- | include/testsuite.h | 4 | ||||
-rw-r--r-- | src/inspircd.cpp | 23 | ||||
-rw-r--r-- | src/modules.cpp | 5 | ||||
-rw-r--r-- | src/testsuite.cpp | 9 |
6 files changed, 37 insertions, 13 deletions
diff --git a/include/configreader.h b/include/configreader.h index 7bc6c1bcb..e10f361d7 100644 --- a/include/configreader.h +++ b/include/configreader.h @@ -151,11 +151,6 @@ struct CommandLineConf */ bool writelog; - /** True if we have been told to run the testsuite from the commandline, - * rather than entering the mainloop. - */ - bool TestSuite; - /** Saved argc from startup */ int argc; diff --git a/include/modules.h b/include/modules.h index f6a984bcd..2abed2935 100644 --- a/include/modules.h +++ b/include/modules.h @@ -264,7 +264,7 @@ enum Implementation I_OnChangeLocalUserGECOS, I_OnUserRegister, I_OnChannelPreDelete, I_OnChannelDelete, I_OnPostOper, I_OnSyncNetwork, I_OnSetAway, I_OnPostCommand, I_OnPostJoin, I_OnWhoisLine, I_OnBuildNeighborList, I_OnGarbageCollect, I_OnSetConnectClass, - I_OnText, I_OnPassCompare, I_OnRunTestSuite, I_OnNamesListItem, I_OnNumeric, + I_OnText, I_OnPassCompare, I_OnNamesListItem, I_OnNumeric, I_OnPreRehash, I_OnModuleRehash, I_OnSendWhoLine, I_OnChangeIdent, I_OnSetUserIP, I_END }; @@ -1034,10 +1034,12 @@ class CoreExport Module : public classbase, public usecountbase */ virtual ModResult OnSetConnectClass(LocalUser* user, ConnectClass* myclass); +#ifdef INSPIRCD_ENABLE_TESTSUITE /** Add test suite hooks here. These are used for testing functionality of a module * via the --testsuite debugging parameter. */ virtual void OnRunTestSuite(); +#endif /** Called for every item in a NAMES list, so that modules may reformat portions of it as they see fit. * For example NAMESX, channel mode +u and +I, and UHNAMES. If the nick is set to an empty string by any diff --git a/include/testsuite.h b/include/testsuite.h index 7f0b2236a..c760513f8 100644 --- a/include/testsuite.h +++ b/include/testsuite.h @@ -18,6 +18,8 @@ #pragma once +#ifdef INSPIRCD_ENABLE_TESTSUITE + class TestSuite { public: @@ -30,3 +32,5 @@ class TestSuite bool DoSpaceSepStreamTests(); bool DoGenerateUIDTests(); }; + +#endif diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 12962d92d..7cc66cd5f 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -89,6 +89,13 @@ const char* ExitCodes[] = "Received SIGTERM" // 10 }; +#ifdef INSPIRCD_ENABLE_TESTSUITE +/** True if we have been told to run the testsuite from the commandline, + * rather than entering the mainloop. + */ +static int do_testsuite = 0; +#endif + template<typename T> static void DeleteZero(T*&n) { T* t = n; @@ -250,8 +257,9 @@ InspIRCd::InspIRCd(int argc, char** argv) : Extensions.Register(&OperQuit); FailedPortList pl; + // Flag variables passed to getopt_long() later int do_version = 0, do_nofork = 0, do_debug = 0, - do_nolog = 0, do_root = 0, do_testsuite = 0; /* flag variables */ + do_nolog = 0, do_root = 0; // Initialize so that if we exit before proper initialization they're not deleted this->Logs = 0; @@ -330,7 +338,9 @@ InspIRCd::InspIRCd(int argc, char** argv) : { "nolog", no_argument, &do_nolog, 1 }, { "runasroot", no_argument, &do_root, 1 }, { "version", no_argument, &do_version, 1 }, +#ifdef INSPIRCD_ENABLE_TESTSUITE { "testsuite", no_argument, &do_testsuite, 1 }, +#endif { 0, 0, 0, 0 } }; @@ -353,14 +363,16 @@ InspIRCd::InspIRCd(int argc, char** argv) : /* Fall through to handle other weird values too */ std::cout << "Unknown parameter '" << argv[optind-1] << "'" << std::endl; std::cout << "Usage: " << argv[0] << " [--nofork] [--nolog] [--debug] [--config <config>]" << std::endl << - std::string(static_cast<int>(8+strlen(argv[0])), ' ') << "[--runasroot] [--version] [--testsuite]" << std::endl; + std::string(static_cast<int>(8+strlen(argv[0])), ' ') << "[--runasroot] [--version]" << std::endl; Exit(EXIT_STATUS_ARGV); break; } } +#ifdef INSPIRCD_ENABLE_TESTSUITE if (do_testsuite) do_nofork = do_debug = true; +#endif if (do_version) { @@ -378,7 +390,6 @@ InspIRCd::InspIRCd(int argc, char** argv) : Config->cmdline.nofork = (do_nofork != 0); Config->cmdline.forcedebug = (do_debug != 0); Config->cmdline.writelog = (!do_nolog != 0); - Config->cmdline.TestSuite = (do_testsuite != 0); if (do_debug) { @@ -515,7 +526,7 @@ InspIRCd::InspIRCd(int argc, char** argv) : * * -- nenolod */ - if ((!do_nofork) && (!do_testsuite) && (!Config->cmdline.forcedebug)) + if ((!do_nofork) && (!Config->cmdline.forcedebug)) { int fd = open("/dev/null", O_RDWR); @@ -636,13 +647,15 @@ void InspIRCd::UpdateTime() void InspIRCd::Run() { +#ifdef INSPIRCD_ENABLE_TESTSUITE /* See if we're supposed to be running the test suite rather than entering the mainloop */ - if (Config->cmdline.TestSuite) + if (do_testsuite) { TestSuite* ts = new TestSuite; delete ts; return; } +#endif UpdateTime(); time_t OLDTIME = TIME.tv_sec; diff --git a/src/modules.cpp b/src/modules.cpp index 245ad5345..2eefc957e 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -151,13 +151,16 @@ void Module::OnBuildNeighborList(User*, IncludeChanList&, std::map<User*,bool>& void Module::OnGarbageCollect() { DetachEvent(I_OnGarbageCollect); } ModResult Module::OnSetConnectClass(LocalUser* user, ConnectClass* myclass) { DetachEvent(I_OnSetConnectClass); return MOD_RES_PASSTHRU; } void Module::OnText(User*, void*, int, const std::string&, char, CUList&) { DetachEvent(I_OnText); } -void Module::OnRunTestSuite() { DetachEvent(I_OnRunTestSuite); } void Module::OnNamesListItem(User*, Membership*, std::string&, std::string&) { DetachEvent(I_OnNamesListItem); } ModResult Module::OnNumeric(User*, unsigned int, const std::string&) { DetachEvent(I_OnNumeric); return MOD_RES_PASSTHRU; } ModResult Module::OnAcceptConnection(int, ListenSocket*, irc::sockets::sockaddrs*, irc::sockets::sockaddrs*) { DetachEvent(I_OnAcceptConnection); return MOD_RES_PASSTHRU; } void Module::OnSendWhoLine(User*, const std::vector<std::string>&, User*, Channel*, std::string&) { DetachEvent(I_OnSendWhoLine); } void Module::OnSetUserIP(LocalUser*) { DetachEvent(I_OnSetUserIP); } +#ifdef INSPIRCD_ENABLE_TESTSUITE +void Module::OnRunTestSuite() { } +#endif + ServiceProvider::ServiceProvider(Module* Creator, const std::string& Name, ServiceType Type) : creator(Creator), name(Name), service(Type) { diff --git a/src/testsuite.cpp b/src/testsuite.cpp index b27f6e18c..b57a21ab8 100644 --- a/src/testsuite.cpp +++ b/src/testsuite.cpp @@ -19,6 +19,8 @@ */ +#ifdef INSPIRCD_ENABLE_TESTSUITE + #include "inspircd.h" #include "testsuite.h" #include "threadengine.h" @@ -74,8 +76,12 @@ TestSuite::TestSuite() switch (choice) { case '1': - FOREACH_MOD(OnRunTestSuite, ()); + { + const ModuleManager::ModuleMap& mods = ServerInstance->Modules->GetModules(); + for (ModuleManager::ModuleMap::const_iterator i = mods.begin(); i != mods.end(); ++i) + i->second->OnRunTestSuite(); break; + } case '2': std::cout << "Enter module filename to load: "; std::cin >> modname; @@ -394,3 +400,4 @@ TestSuite::~TestSuite() std::cout << "\n\n*** END OF TEST SUITE ***\n"; } +#endif |