1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/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.test", "fo?bar.t*t");
120 WCTEST("foobar.tttt", "fo?bar.**t");
121 WCTEST("foobar", "foobar");
122 WCTEST("foobar", "foo***bar");
123 WCTEST("foobar", "*foo***bar");
124 WCTEST("foobar", "**foo***bar");
125 WCTEST("foobar", "**foobar*");
126 WCTEST("foobar", "**foobar**");
127 WCTEST("foobar", "**foobar");
128 WCTEST("foobar", "**f?*?ar");
129 WCTEST("foobar", "**f?*b?r");
130 WCTEST("foofar", "**f?*f*r");
131 WCTEST("foofar", "**f?*f*?");
134 WCTEST("test@foo.bar.test", "*@*.bar.test");
135 WCTEST("test@foo.bar.test", "*test*@*.bar.test");
136 WCTEST("test@foo.bar.test", "*@*test");
141 WCTEST("aaaa", "*a");
142 WCTEST("aaaaa", "*a");
143 WCTEST("aaaaaa", "*a");
144 WCTEST("aaaaaaa", "*a");
145 WCTEST("aaaaaaaa", "*a");
146 WCTEST("aaaaaaaaa", "*a");
147 WCTEST("aaaaaaaaaa", "*a");
148 WCTEST("aaaaaaaaaaa", "*a");
150 WCTESTNOT("foobar", "bazqux");
151 WCTESTNOT("foobar", "*qux");
152 WCTESTNOT("foobar", "foo*x");
153 WCTESTNOT("foobar", "baz*");
154 WCTESTNOT("foobar", "foo???r");
155 WCTESTNOT("foobar", "foobars");
156 WCTESTNOT("foobar", "**foobar**h");
157 WCTESTNOT("foobar", "**foobar**h*");
158 WCTESTNOT("foobar", "**f??*bar?");
159 WCTESTNOT("foobar", "");
160 WCTESTNOT("", "foobar");
161 WCTESTNOT("OperServ", "O");
162 WCTESTNOT("O", "OperServ");
163 WCTESTNOT("foobar.tst", "fo?bar.*g");
164 WCTESTNOT("foobar.test", "fo?bar.*tt");
166 CIDRTEST("brain@1.2.3.4", "*@1.2.0.0/16");
167 CIDRTEST("brain@1.2.3.4", "*@1.2.3.0/24");
168 CIDRTEST("192.168.3.97", "192.168.3.0/24");
170 CIDRTESTNOT("brain@1.2.3.4", "x*@1.2.0.0/16");
171 CIDRTESTNOT("brain@1.2.3.4", "*@1.3.4.0/24");
172 CIDRTESTNOT("1.2.3.4", "1.2.4.0/24");
173 CIDRTESTNOT("brain@1.2.3.4", "*@/24");
174 CIDRTESTNOT("brain@1.2.3.4", "@1.2.3.4/9");
175 CIDRTESTNOT("brain@1.2.3.4", "@");
176 CIDRTESTNOT("brain@1.2.3.4", "");
181 bool TestSuite::DoThreadTests()
183 std::string anything;
184 ThreadEngine* te = NULL;
186 cout << "Creating new ThreadEngine class...\n";
189 te = new ThreadEngine(ServerInstance);
193 cout << "Creation failed, test failure.\n";
196 cout << "Creation success, type " << te->GetName() << "\n";
198 cout << "Allocate: new TestSuiteThread...\n";
199 TestSuiteThread* tst = new TestSuiteThread();
201 cout << "ThreadEngine::Create on TestSuiteThread...\n";
208 catch (CoreException &ce)
210 cout << "Failure: " << ce.GetReason() << endl;
215 cout << "Failure, unhandled exception\n";
218 cout << "Type any line and press enter to end test.\n";
221 /* Thread engine auto frees thread on delete */
222 cout << "Waiting for thread to exit... " << flush;
226 cout << "Delete ThreadEngine... ";
233 TestSuite::~TestSuite()
235 cout << "\n\n*** END OF TEST SUITE ***\n";