00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifdef HAVE_CONFIG_H
00022 #include <config.h>
00023 #endif
00024
00025
00026 #include <cstdlib>
00027 #include <cassert>
00028
00029 #include "CommandHandler.h"
00030 #include "TcpClientStream.h"
00031 #include "TcpServer.h"
00032 #include "TelnetProtocol.h"
00033 #include "LineBufferProtocol.h"
00034 #include "CommandManager.h"
00035 #include "Tokeniser.h"
00036 #include "CommandProtocol.h"
00037 #include "Logger.h"
00038 #include "IoStream.h"
00039 #include "Exception.h"
00040
00041 using namespace mdw;
00042
00043 namespace
00044 {
00045
00046 static bool _success = false;
00047
00048 class CommandHandlerTest : public CommandHandler
00049 {
00050 public:
00051 virtual void execute (const std::vector<std::string> args, int startArgs, Stream &output)
00052 {
00053 if (args[startArgs] == "true")
00054 {
00055 _success = true;
00056 }
00057 }
00058 };
00059
00060 void testTelnetCommands()
00061 {
00062 TcpServer aServer(35555);
00063 TelnetProtocol aTelnet(aServer);
00064 LineBufferProtocol aLineBuff(aTelnet);
00065 Tokeniser aTokeniser(aLineBuff);
00066 CommandProtocol aCommand(aTokeniser);
00067 CommandManager &cm = CommandManager::getInstance();
00068 cm.createNode("set").createNode("test").createNode("result", new CommandHandlerTest());
00069 TcpClientStream aClient("localhost", 35555);
00070 aCommand.getPendingCommands(1, 0);
00071 aClient << "set " << "te" << "st result " << "true\n";
00072 aCommand.getPendingCommands(1, 0);
00073 assert(_success);
00074 }
00075
00076 }
00077
00078 int main (int argc, char *argv[])
00079 {
00080 Logger::initialise(mdw::cout);
00081 try
00082 {
00083 CommandManager::initialise();
00084 testTelnetCommands();
00085
00086 cout << "Success!" << endl;
00087 return 0;
00088 }
00089 catch (mdw::Exception &e)
00090 {
00091 e.log(cout);
00092 return -1;
00093 }
00094 catch (std::exception &e)
00095 {
00096 cout << "Error std::exception : " << e.what() << endl;
00097 return -1;
00098 }
00099 catch (...)
00100 {
00101 cout << "Unknown exception" << endl;
00102 return -1;
00103 }
00104 }