1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
17 #include "testsuite.h"
18 #include "threadengine.h"
23 class TestSuiteThread : public Thread
26 TestSuiteThread() : Thread()
30 virtual ~TestSuiteThread()
36 while (GetExitFlag() == false)
38 cout << "Test suite thread run...\n";
44 TestSuite::TestSuite(InspIRCd* Instance) : ServerInstance(Instance)
46 cout << "\n\n*** STARTING TESTSUITE ***\n";
53 cout << "(1) Call all module OnRunTestSuite() methods\n";
54 cout << "(2) Load a module\n";
55 cout << "(3) Unload a module\n";
56 cout << "(4) Threading tests\n";
57 cout << "(5) Wildcard and CIDR tests\n";
59 cout << endl << "(X) Exit test suite\n";
61 cout << "\nChoices (Enter one or more options as a list then press enter, e.g. 15X): ";
70 FOREACH_MOD(I_OnRunTestSuite, OnRunTestSuite());
73 cout << "Enter module filename to load: ";
75 cout << (Instance->Modules->Load(modname.c_str()) ? "\nSUCCESS!\n" : "\nFAILURE\n");
78 cout << "Enter module filename to unload: ";
80 cout << (Instance->Modules->Unload(modname.c_str()) ? "\nSUCCESS!\n" : "\nFAILURE\n");
83 cout << (DoThreadTests() ? "\nSUCCESS!\n" : "\nFAILURE\n");
86 cout << (DoWildTests() ? "\nSUCCESS!\n" : "\nFAILURE\n");
92 cout << "Invalid option\n";
99 /* Test that x matches y with match() */
100 #define WCTEST(x, y) cout << "match(\"" << x << "\",\"" << y "\") " << ((passed = (InspIRCd::Match(x, y, NULL))) ? " SUCCESS!\n" : " FAILURE\n")
101 /* Test that x does not match y with match() */
102 #define WCTESTNOT(x, y) cout << "!match(\"" << x << "\",\"" << y "\") " << ((passed = ((!InspIRCd::Match(x, y, NULL)))) ? " SUCCESS!\n" : " FAILURE\n")
104 /* Test that x matches y with match() and cidr enabled */
105 #define CIDRTEST(x, y) cout << "match(\"" << x << "\",\"" << y "\", true) " << ((passed = (InspIRCd::MatchCIDR(x, y, NULL))) ? " SUCCESS!\n" : " FAILURE\n")
106 /* Test that x does not match y with match() and cidr enabled */
107 #define CIDRTESTNOT(x, y) cout << "!match(\"" << x << "\",\"" << y "\", true) " << ((passed = ((!InspIRCd::MatchCIDR(x, y, NULL)))) ? " SUCCESS!\n" : " FAILURE\n")
109 bool TestSuite::DoWildTests()
111 cout << "\n\nWildcard and CIDR tests\n\n";
114 WCTEST("foobar", "*");
115 WCTEST("foobar", "foo*");
116 WCTEST("foobar", "*bar");
117 WCTEST("foobar", "foo??r");
118 WCTEST("foobar.test", "fo?bar.*t");
119 WCTEST("foobar", "foobar");
120 WCTEST("foobar", "foo***bar");
122 WCTESTNOT("foobar", "bazqux");
123 WCTESTNOT("foobar", "*qux");
124 WCTESTNOT("foobar", "foo*x");
125 WCTESTNOT("foobar", "baz*");
126 WCTESTNOT("foobar", "foo???r");
127 WCTESTNOT("foobar", "");
128 WCTESTNOT("", "foobar");
129 WCTESTNOT("OperServ", "O");
130 WCTESTNOT("O", "OperServ");
131 WCTESTNOT("foobar.tst", "fo?bar.*g");
133 CIDRTEST("brain@1.2.3.4", "*@1.2.0.0/16");
134 CIDRTEST("brain@1.2.3.4", "*@1.2.3.0/24");
136 CIDRTEST("192.168.3.97", "192.168.3.0/24");
138 CIDRTESTNOT("brain@1.2.3.4", "x*@1.2.0.0/16");
139 CIDRTESTNOT("brain@1.2.3.4", "*@1.3.4.0/24");
141 CIDRTESTNOT("1.2.3.4", "1.2.4.0/24");
143 CIDRTESTNOT("brain@1.2.3.4", "*@/24");
144 CIDRTESTNOT("brain@1.2.3.4", "@1.2.3.4/9");
145 CIDRTESTNOT("brain@1.2.3.4", "@");
146 CIDRTESTNOT("brain@1.2.3.4", "");
151 bool TestSuite::DoThreadTests()
153 std::string anything;
154 ThreadEngine* te = NULL;
156 cout << "Creating new ThreadEngine class...\n";
159 ThreadEngineFactory* tef = new ThreadEngineFactory();
160 te = tef->Create(ServerInstance);
165 cout << "Creation failed, test failure.\n";
168 cout << "Creation success, type " << te->GetName() << "\n";
170 cout << "Allocate: new TestSuiteThread...\n";
171 TestSuiteThread* tst = new TestSuiteThread();
173 cout << "ThreadEngine::Create on TestSuiteThread...\n";
180 catch (CoreException &ce)
182 cout << "Failure: " << ce.GetReason() << endl;
187 cout << "Failure, unhandled exception\n";
190 cout << "Type any line and press enter to end test.\n";
193 /* Thread engine auto frees thread on delete */
194 cout << "Waiting for thread to exit... " << flush;
198 cout << "Delete ThreadEngine... ";
205 TestSuite::~TestSuite()
207 cout << "\n\n*** END OF TEST SUITE ***\n";