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()
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";
58 cout << "(6) Comma sepstream tests\n";
59 cout << "(7) Space sepstream tests\n";
61 cout << endl << "(X) Exit test suite\n";
63 cout << "\nChoices (Enter one or more options as a list then press enter, e.g. 15X): ";
72 FOREACH_MOD(I_OnRunTestSuite, OnRunTestSuite());
75 cout << "Enter module filename to load: ";
77 cout << (ServerInstance->Modules->Load(modname.c_str()) ? "\nSUCCESS!\n" : "\nFAILURE\n");
80 cout << "Enter module filename to unload: ";
82 cout << (ServerInstance->Modules->Unload(modname.c_str()) ? "\nSUCCESS!\n" : "\nFAILURE\n");
85 cout << (DoThreadTests() ? "\nSUCCESS!\n" : "\nFAILURE\n");
88 cout << (DoWildTests() ? "\nSUCCESS!\n" : "\nFAILURE\n");
91 cout << (DoCommaSepStreamTests() ? "\nSUCCESS!\n" : "\nFAILURE\n");
94 cout << (DoSpaceSepStreamTests() ? "\nSUCCESS!\n" : "\nFAILURE\n");
100 cout << "Invalid option\n";
107 /* Test that x matches y with match() */
108 #define WCTEST(x, y) cout << "match(\"" << x << "\",\"" << y "\") " << ((passed = (InspIRCd::Match(x, y, NULL))) ? " SUCCESS!\n" : " FAILURE\n")
109 /* Test that x does not match y with match() */
110 #define WCTESTNOT(x, y) cout << "!match(\"" << x << "\",\"" << y "\") " << ((passed = ((!InspIRCd::Match(x, y, NULL)))) ? " SUCCESS!\n" : " FAILURE\n")
112 /* Test that x matches y with match() and cidr enabled */
113 #define CIDRTEST(x, y) cout << "match(\"" << x << "\",\"" << y "\", true) " << ((passed = (InspIRCd::MatchCIDR(x, y, NULL))) ? " SUCCESS!\n" : " FAILURE\n")
114 /* Test that x does not match y with match() and cidr enabled */
115 #define CIDRTESTNOT(x, y) cout << "!match(\"" << x << "\",\"" << y "\", true) " << ((passed = ((!InspIRCd::MatchCIDR(x, y, NULL)))) ? " SUCCESS!\n" : " FAILURE\n")
117 bool TestSuite::DoWildTests()
119 cout << "\n\nWildcard and CIDR tests\n\n";
122 WCTEST("foobar", "*");
123 WCTEST("foobar", "foo*");
124 WCTEST("foobar", "*bar");
125 WCTEST("foobar", "foo??r");
126 WCTEST("foobar.test", "fo?bar.*t");
127 WCTEST("foobar.test", "fo?bar.t*t");
128 WCTEST("foobar.tttt", "fo?bar.**t");
129 WCTEST("foobar", "foobar");
130 WCTEST("foobar", "foo***bar");
131 WCTEST("foobar", "*foo***bar");
132 WCTEST("foobar", "**foo***bar");
133 WCTEST("foobar", "**foobar*");
134 WCTEST("foobar", "**foobar**");
135 WCTEST("foobar", "**foobar");
136 WCTEST("foobar", "**f?*?ar");
137 WCTEST("foobar", "**f?*b?r");
138 WCTEST("foofar", "**f?*f*r");
139 WCTEST("foofar", "**f?*f*?");
142 WCTEST("test@foo.bar.test", "*@*.bar.test");
143 WCTEST("test@foo.bar.test", "*test*@*.bar.test");
144 WCTEST("test@foo.bar.test", "*@*test");
149 WCTEST("aaaa", "*a");
150 WCTEST("aaaaa", "*a");
151 WCTEST("aaaaaa", "*a");
152 WCTEST("aaaaaaa", "*a");
153 WCTEST("aaaaaaaa", "*a");
154 WCTEST("aaaaaaaaa", "*a");
155 WCTEST("aaaaaaaaaa", "*a");
156 WCTEST("aaaaaaaaaaa", "*a");
158 WCTESTNOT("foobar", "bazqux");
159 WCTESTNOT("foobar", "*qux");
160 WCTESTNOT("foobar", "foo*x");
161 WCTESTNOT("foobar", "baz*");
162 WCTESTNOT("foobar", "foo???r");
163 WCTESTNOT("foobar", "foobars");
164 WCTESTNOT("foobar", "**foobar**h");
165 WCTESTNOT("foobar", "**foobar**h*");
166 WCTESTNOT("foobar", "**f??*bar?");
167 WCTESTNOT("foobar", "");
168 WCTESTNOT("", "foobar");
169 WCTESTNOT("OperServ", "O");
170 WCTESTNOT("O", "OperServ");
171 WCTESTNOT("foobar.tst", "fo?bar.*g");
172 WCTESTNOT("foobar.test", "fo?bar.*tt");
174 CIDRTEST("brain@1.2.3.4", "*@1.2.0.0/16");
175 CIDRTEST("brain@1.2.3.4", "*@1.2.3.0/24");
176 CIDRTEST("192.168.3.97", "192.168.3.0/24");
178 CIDRTESTNOT("brain@1.2.3.4", "x*@1.2.0.0/16");
179 CIDRTESTNOT("brain@1.2.3.4", "*@1.3.4.0/24");
180 CIDRTESTNOT("1.2.3.4", "1.2.4.0/24");
181 CIDRTESTNOT("brain@1.2.3.4", "*@/24");
182 CIDRTESTNOT("brain@1.2.3.4", "@1.2.3.4/9");
183 CIDRTESTNOT("brain@1.2.3.4", "@");
184 CIDRTESTNOT("brain@1.2.3.4", "");
190 #define STREQUALTEST(x, y) cout << "==(\"" << x << ",\"" << y "\") " << ((passed = (x == y)) ? "SUCCESS\n" : "FAILURE\n")
192 bool TestSuite::DoCommaSepStreamTests()
195 irc::commasepstream items("this,is,a,comma,stream");
199 while (items.GetToken(item))
206 STREQUALTEST(item, "this");
209 STREQUALTEST(item, "is");
212 STREQUALTEST(item, "a");
215 STREQUALTEST(item, "comma");
218 STREQUALTEST(item, "stream");
221 cout << "COMMASEPSTREAM: FAILURE: Got an index too many! " << idx << " items\n";
229 bool TestSuite::DoSpaceSepStreamTests()
233 irc::spacesepstream list("this is a space stream");
237 while (list.GetToken(item))
244 STREQUALTEST(item, "this");
247 STREQUALTEST(item, "is");
250 STREQUALTEST(item, "a");
253 STREQUALTEST(item, "space");
256 STREQUALTEST(item, "stream");
259 cout << "SPACESEPSTREAM: FAILURE: Got an index too many! " << idx << " items\n";
266 bool TestSuite::DoThreadTests()
268 std::string anything;
269 ThreadEngine* te = NULL;
271 cout << "Creating new ThreadEngine class...\n";
274 te = new ThreadEngine;
278 cout << "Creation failed, test failure.\n";
281 cout << "Creation success, type " << te->GetName() << "\n";
283 cout << "Allocate: new TestSuiteThread...\n";
284 TestSuiteThread* tst = new TestSuiteThread();
286 cout << "ThreadEngine::Create on TestSuiteThread...\n";
293 catch (CoreException &ce)
295 cout << "Failure: " << ce.GetReason() << endl;
300 cout << "Failure, unhandled exception\n";
303 cout << "Type any line and press enter to end test.\n";
306 /* Thread engine auto frees thread on delete */
307 cout << "Waiting for thread to exit... " << flush;
311 cout << "Delete ThreadEngine... ";
318 TestSuite::~TestSuite()
320 cout << "\n\n*** END OF TEST SUITE ***\n";