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";
58 cout << "(6) Comma sepstream tests\n";
60 cout << endl << "(X) Exit test suite\n";
62 cout << "\nChoices (Enter one or more options as a list then press enter, e.g. 15X): ";
71 FOREACH_MOD(I_OnRunTestSuite, OnRunTestSuite());
74 cout << "Enter module filename to load: ";
76 cout << (Instance->Modules->Load(modname.c_str()) ? "\nSUCCESS!\n" : "\nFAILURE\n");
79 cout << "Enter module filename to unload: ";
81 cout << (Instance->Modules->Unload(modname.c_str()) ? "\nSUCCESS!\n" : "\nFAILURE\n");
84 cout << (DoThreadTests() ? "\nSUCCESS!\n" : "\nFAILURE\n");
87 cout << (DoWildTests() ? "\nSUCCESS!\n" : "\nFAILURE\n");
90 cout << (DoCommaSepStreamTests() ? "\nSUCCESS!\n" : "\nFAILURE\n");
96 cout << "Invalid option\n";
103 /* Test that x matches y with match() */
104 #define WCTEST(x, y) cout << "match(\"" << x << "\",\"" << y "\") " << ((passed = (InspIRCd::Match(x, y, NULL))) ? " SUCCESS!\n" : " FAILURE\n")
105 /* Test that x does not match y with match() */
106 #define WCTESTNOT(x, y) cout << "!match(\"" << x << "\",\"" << y "\") " << ((passed = ((!InspIRCd::Match(x, y, NULL)))) ? " SUCCESS!\n" : " FAILURE\n")
108 /* Test that x matches y with match() and cidr enabled */
109 #define CIDRTEST(x, y) cout << "match(\"" << x << "\",\"" << y "\", true) " << ((passed = (InspIRCd::MatchCIDR(x, y, NULL))) ? " SUCCESS!\n" : " FAILURE\n")
110 /* Test that x does not match y with match() and cidr enabled */
111 #define CIDRTESTNOT(x, y) cout << "!match(\"" << x << "\",\"" << y "\", true) " << ((passed = ((!InspIRCd::MatchCIDR(x, y, NULL)))) ? " SUCCESS!\n" : " FAILURE\n")
113 bool TestSuite::DoWildTests()
115 cout << "\n\nWildcard and CIDR tests\n\n";
118 WCTEST("foobar", "*");
119 WCTEST("foobar", "foo*");
120 WCTEST("foobar", "*bar");
121 WCTEST("foobar", "foo??r");
122 WCTEST("foobar.test", "fo?bar.*t");
123 WCTEST("foobar.test", "fo?bar.t*t");
124 WCTEST("foobar.tttt", "fo?bar.**t");
125 WCTEST("foobar", "foobar");
126 WCTEST("foobar", "foo***bar");
127 WCTEST("foobar", "*foo***bar");
128 WCTEST("foobar", "**foo***bar");
129 WCTEST("foobar", "**foobar*");
130 WCTEST("foobar", "**foobar**");
131 WCTEST("foobar", "**foobar");
132 WCTEST("foobar", "**f?*?ar");
133 WCTEST("foobar", "**f?*b?r");
134 WCTEST("foofar", "**f?*f*r");
135 WCTEST("foofar", "**f?*f*?");
138 WCTEST("test@foo.bar.test", "*@*.bar.test");
139 WCTEST("test@foo.bar.test", "*test*@*.bar.test");
140 WCTEST("test@foo.bar.test", "*@*test");
145 WCTEST("aaaa", "*a");
146 WCTEST("aaaaa", "*a");
147 WCTEST("aaaaaa", "*a");
148 WCTEST("aaaaaaa", "*a");
149 WCTEST("aaaaaaaa", "*a");
150 WCTEST("aaaaaaaaa", "*a");
151 WCTEST("aaaaaaaaaa", "*a");
152 WCTEST("aaaaaaaaaaa", "*a");
154 WCTESTNOT("foobar", "bazqux");
155 WCTESTNOT("foobar", "*qux");
156 WCTESTNOT("foobar", "foo*x");
157 WCTESTNOT("foobar", "baz*");
158 WCTESTNOT("foobar", "foo???r");
159 WCTESTNOT("foobar", "foobars");
160 WCTESTNOT("foobar", "**foobar**h");
161 WCTESTNOT("foobar", "**foobar**h*");
162 WCTESTNOT("foobar", "**f??*bar?");
163 WCTESTNOT("foobar", "");
164 WCTESTNOT("", "foobar");
165 WCTESTNOT("OperServ", "O");
166 WCTESTNOT("O", "OperServ");
167 WCTESTNOT("foobar.tst", "fo?bar.*g");
168 WCTESTNOT("foobar.test", "fo?bar.*tt");
170 CIDRTEST("brain@1.2.3.4", "*@1.2.0.0/16");
171 CIDRTEST("brain@1.2.3.4", "*@1.2.3.0/24");
172 CIDRTEST("192.168.3.97", "192.168.3.0/24");
174 CIDRTESTNOT("brain@1.2.3.4", "x*@1.2.0.0/16");
175 CIDRTESTNOT("brain@1.2.3.4", "*@1.3.4.0/24");
176 CIDRTESTNOT("1.2.3.4", "1.2.4.0/24");
177 CIDRTESTNOT("brain@1.2.3.4", "*@/24");
178 CIDRTESTNOT("brain@1.2.3.4", "@1.2.3.4/9");
179 CIDRTESTNOT("brain@1.2.3.4", "@");
180 CIDRTESTNOT("brain@1.2.3.4", "");
186 #define STREQUALTEST(x, y) cout << "commasepstreamtoken(\"" << x << ",\"" << y "\") " << ((passed = (x == y)) ? "SUCCESS\n" : "FAILURE\n")
188 bool TestSuite::DoCommaSepStreamTests()
191 irc::commasepstream items("this,is,a,comma,stream");
195 while (items.GetToken(item))
202 STREQUALTEST(item, "this");
205 STREQUALTEST(item, "is");
208 STREQUALTEST(item, "a");
211 STREQUALTEST(item, "comma");
214 STREQUALTEST(item, "stream");
217 cout << "COMMASEPSTREAM: FAILURE: Got an index too many! " << idx << " items\n";
225 bool TestSuite::DoThreadTests()
227 std::string anything;
228 ThreadEngine* te = NULL;
230 cout << "Creating new ThreadEngine class...\n";
233 te = new ThreadEngine(ServerInstance);
237 cout << "Creation failed, test failure.\n";
240 cout << "Creation success, type " << te->GetName() << "\n";
242 cout << "Allocate: new TestSuiteThread...\n";
243 TestSuiteThread* tst = new TestSuiteThread();
245 cout << "ThreadEngine::Create on TestSuiteThread...\n";
252 catch (CoreException &ce)
254 cout << "Failure: " << ce.GetReason() << endl;
259 cout << "Failure, unhandled exception\n";
262 cout << "Type any line and press enter to end test.\n";
265 /* Thread engine auto frees thread on delete */
266 cout << "Waiting for thread to exit... " << flush;
270 cout << "Delete ThreadEngine... ";
277 TestSuite::~TestSuite()
279 cout << "\n\n*** END OF TEST SUITE ***\n";