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";
59 cout << "(6) irc::string -> std::string dynamic cast\n";
61 cout << endl << "(X) Exit test suite\n";
72 FOREACH_MOD(I_OnRunTestSuite, OnRunTestSuite());
75 cout << "Enter module filename to load: ";
77 cout << (Instance->Modules->Load(modname.c_str()) ? "\nSUCCESS!\n" : "\nFAILURE\n");
80 cout << "Enter module filename to unload: ";
82 cout << (Instance->Modules->Unload(modname.c_str()) ? "\nSUCCESS!\n" : "\nFAILURE\n");
85 cout << (DoThreadTests() ? "\nSUCCESS!\n" : "\nFAILURE\n");
88 cout << (DoWildTests() ? "\nSUCCESS!\n" : "\nFAILURE\n");
92 std::string* a = new std::string("test");
93 irc::string* b = (irc::string)a;
94 cout << "std::string value: '" << *a << "' irc::string value: '" << *b << "'" << endl;
102 cout << "Invalid option\n";
109 /* Test that x matches y with match() */
110 #define WCTEST(x, y) cout << "match(\"" << x << "\",\"" << y "\") " << ((passed = (match(x, y))) ? " SUCCESS!\n" : " FAILURE\n")
111 /* Test that x does not match y with match() */
112 #define WCTESTNOT(x, y) cout << "!match(\"" << x << "\",\"" << y "\") " << ((passed = ((!match(x, y)))) ? " SUCCESS!\n" : " FAILURE\n")
114 /* Test that x matches y with match() and cidr enabled */
115 #define CIDRTEST(x, y) cout << "match(\"" << x << "\",\"" << y "\", true) " << ((passed = (match(x, y, true))) ? " SUCCESS!\n" : " FAILURE\n")
116 /* Test that x does not match y with match() and cidr enabled */
117 #define CIDRTESTNOT(x, y) cout << "!match(\"" << x << "\",\"" << y "\", true) " << ((passed = ((!match(x, y, true)))) ? " SUCCESS!\n" : " FAILURE\n")
119 bool TestSuite::DoWildTests()
121 cout << "\n\nWildcard and CIDR tests\n\n";
124 WCTEST("foobar", "*");
125 WCTEST("foobar", "foo*");
126 WCTEST("foobar", "*bar");
127 WCTEST("foobar", "foo??r");
129 WCTESTNOT("foobar", "bazqux");
130 WCTESTNOT("foobar", "*qux");
131 WCTESTNOT("foobar", "foo*x");
132 WCTESTNOT("foobar", "baz*");
133 WCTESTNOT("foobar", "foo???r");
134 WCTESTNOT("foobar", "");
136 CIDRTEST("brain@1.2.3.4", "*@1.2.0.0/16");
137 CIDRTEST("brain@1.2.3.4", "*@1.2.3.0/24");
139 CIDRTEST("192.168.3.97", "192.168.3.0/24");
141 CIDRTESTNOT("brain@1.2.3.4", "x*@1.2.0.0/16");
142 CIDRTESTNOT("brain@1.2.3.4", "*@1.3.4.0/24");
144 CIDRTESTNOT("1.2.3.4", "1.2.4.0/24");
146 CIDRTESTNOT("brain@1.2.3.4", "*@/24");
147 CIDRTESTNOT("brain@1.2.3.4", "@1.2.3.4/9");
148 CIDRTESTNOT("brain@1.2.3.4", "@");
149 CIDRTESTNOT("brain@1.2.3.4", "");
154 bool TestSuite::DoThreadTests()
156 std::string anything;
157 ThreadEngine* te = NULL;
159 cout << "Creating new ThreadEngine class...\n";
162 ThreadEngineFactory* tef = new ThreadEngineFactory();
163 te = tef->Create(ServerInstance);
168 cout << "Creation failed, test failure.\n";
171 cout << "Creation success, type " << te->GetName() << "\n";
173 cout << "Allocate: new TestSuiteThread...\n";
174 TestSuiteThread* tst = new TestSuiteThread();
176 cout << "ThreadEngine::Create on TestSuiteThread...\n";
183 catch (CoreException &ce)
185 cout << "Failure: " << ce.GetReason() << endl;
190 cout << "Failure, unhandled exception\n";
193 cout << "Type any line and press enter to end test.\n";
196 /* Thread engine auto frees thread on delete */
197 cout << "Waiting for thread to exit... " << flush;
201 cout << "Delete ThreadEngine... ";
208 TestSuite::~TestSuite()
210 cout << "\n\n*** END OF TEST SUITE ***\n";