]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/testsuite.cpp
Threadengine stuff
[user/henk/code/inspircd.git] / src / testsuite.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *          the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 /* $Core: libIRCDtestsuite */
15
16 #include "inspircd.h"
17 #include "testsuite.h"
18 #include "threadengine.h"
19 #include <iostream>
20
21 using namespace std;
22
23 class TestSuiteThread : public Thread
24 {
25         TestSuiteThread() : Thread()
26         {
27         }
28
29         virtual ~TestSuiteThread()
30         {
31         }
32
33         virtual void Run()
34         {
35                 while (1)
36                 {
37                         cout << "Test suite thread run...\n";
38                         sleep(10);
39                 }
40         }
41 };
42
43 TestSuite::TestSuite(InspIRCd* Instance) : ServerInstance(Instance)
44 {
45         cout << "\n\n*** STARTING TESTSUITE ***\n";
46
47         std::string modname;
48         std::string choice;
49
50         ServerInstance->SE->Blocking(fileno(stdin));
51
52         while (1)
53         {
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
59                 cout << endl << "(X) Exit test suite\n";
60
61                 cout << "\nChoice: ";
62                 cin >> choice;
63
64                 switch (*choice.begin())
65                 {
66                         case '1':
67                                 FOREACH_MOD(I_OnRunTestSuite, OnRunTestSuite());
68                         break;
69                         case '2':
70                                 cout << "Enter module filename to load: ";
71                                 cin >> modname;
72                                 cout << (Instance->Modules->Load(modname.c_str()) ? "\nSUCCESS!\n" : "\nFAILURE\n");
73                         break;
74                         case '3':
75                                 cout << "Enter module filename to unload: ";
76                                 cin >> modname;
77                                 cout << (Instance->Modules->Unload(modname.c_str()) ? "\nSUCCESS!\n" : "\nFAILURE\n");
78                         break;
79                         case '4':
80                                 cout << (DoThreadTests() ? "\nSUCCESS!\n" : "\nFAILURE\n");
81                         break;
82                         case 'X':
83                                 return;
84                         break;
85                         default:
86                                 cout << "Invalid option\n";
87                         break;
88                 }
89                 cout << endl;
90         }
91 }
92
93 bool TestSuite::DoThreadTests()
94 {
95         std::string anything;
96         cout << "Creating new ThreadEngine class...\n";
97         try
98         {
99                 ThreadEngineFactory* tef = new ThreadEngineFactory();
100                 ThreadEngine* te = tef->Create(ServerInstance);
101                 delete tef;
102         }
103         catch (...)
104         {
105                 cout << "Creation failed, test failure.\n";
106                 return false;
107         }
108         cout << "Creation success!\n";
109
110         cout << "Creating new thread of type TestSuiteThread\n";
111
112         TestSuiteThread* tst = new TestSuiteThread();
113
114         te->Create(tst);
115
116         cout >> "Press enter to end test.";
117         cin >> anything;
118
119         /* Auto frees thread */
120         delete tst;
121
122         delete te;
123
124         return true;
125 }
126
127 TestSuite::~TestSuite()
128 {
129         cout << "\n\n*** END OF TEST SUITE ***\n";
130 }
131