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 * ---------------------------------------------------
14 /* $Core: libIRCDtestsuite */
17 #include "testsuite.h"
18 #include "threadengine.h"
24 class TestSuiteThread : public Thread
27 TestSuiteThread() : Thread()
31 virtual ~TestSuiteThread()
37 while (GetExitFlag() == false)
39 cout << "Test suite thread run...\n";
45 TestSuite::TestSuite(InspIRCd* Instance) : ServerInstance(Instance)
47 cout << "\n\n*** STARTING TESTSUITE ***\n";
54 cout << "(1) Call all module OnRunTestSuite() methods\n";
55 cout << "(2) Load a module\n";
56 cout << "(3) Unload a module\n";
57 cout << "(4) Threading tests\n";
58 cout << "(5) Wildcard and CIDR tests\n";
60 cout << endl << "(X) Exit test suite\n";
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");
93 cout << "Invalid option\n";
100 /* Test that x matches y with match() */
101 #define WCTEST(x, y) cout << "match(\"" << x << "\",\"" << y "\") " << ((passed = (match(x, y) || passed)) ? " SUCCESS!\n" : " FAILURE\n")
102 /* Test that x does not match y with match() */
103 #define WCTESTNOT(x, y) cout << "!match(\"" << x << "\",\"" << y "\") " << ((passed = ((!match(x, y)) || passed)) ? " SUCCESS!\n" : " FAILURE\n")
105 /* Test that x matches y with match() and cidr enabled */
106 #define CIDRTEST(x, y) cout << "match(\"" << x << "\",\"" << y "\", true) " << ((passed = (match(x, y, true) || passed)) ? " SUCCESS!\n" : " FAILURE\n")
107 /* Test that x does not match y with match() and cidr enabled */
108 #define CIDRTESTNOT(x, y) cout << "!match(\"" << x << "\",\"" << y "\", true) " << ((passed = ((!match(x, y, true)) || passed)) ? " SUCCESS!\n" : " FAILURE\n")
110 bool TestSuite::DoWildTests()
112 cout << "\n\nWildcard and CIDR tests\n\n";
115 WCTEST("foobar", "*");
116 WCTEST("foobar", "foo*");
117 WCTEST("foobar", "*bar");
118 WCTEST("foobar", "foo??r");
120 WCTESTNOT("foobar", "bazqux");
121 WCTESTNOT("foobar", "*qux");
122 WCTESTNOT("foobar", "foo*x");
123 WCTESTNOT("foobar", "baz*");
124 WCTESTNOT("foobar", "foo???r");
125 WCTESTNOT("foobar", "");
127 CIDRTEST("brain@1.2.3.4", "*@1.2.0.0/16");
128 CIDRTEST("brain@1.2.3.4", "*@1.2.3.0/24");
130 CIDRTESTNOT("brain@1.2.3.4", "x*@1.2.0.0/16");
131 CIDRTESTNOT("brain@1.2.3.4", "*@1.3.4.0/24");
133 CIDRTESTNOT("brain@1.2.3.4", "*@/24");
134 CIDRTESTNOT("brain@1.2.3.4", "@1.2.3.4/9");
135 CIDRTESTNOT("brain@1.2.3.4", "@");
136 CIDRTESTNOT("brain@1.2.3.4", "");
141 bool TestSuite::DoThreadTests()
143 std::string anything;
144 ThreadEngine* te = NULL;
146 cout << "Creating new ThreadEngine class...\n";
149 ThreadEngineFactory* tef = new ThreadEngineFactory();
150 te = tef->Create(ServerInstance);
155 cout << "Creation failed, test failure.\n";
158 cout << "Creation success, type " << te->GetName() << "\n";
160 cout << "Allocate: new TestSuiteThread...\n";
161 TestSuiteThread* tst = new TestSuiteThread();
163 cout << "ThreadEngine::Create on TestSuiteThread...\n";
170 catch (CoreException &ce)
172 cout << "Failure: " << ce.GetReason() << endl;
177 cout << "Failure, unhandled exception\n";
180 cout << "Type any line and press enter to end test.\n";
183 /* Thread engine auto frees thread on delete */
184 cout << "Waiting for thread to exit... " << flush;
188 cout << "Delete ThreadEngine... ";
195 TestSuite::~TestSuite()
197 cout << "\n\n*** END OF TEST SUITE ***\n";