00001 #ifdef TEST
00002
00003 #include "headers.h"
00004
00005 const static string tpPacketCommandString = "tpPacket";
00006 const static string construct1CommandString = "construct1";
00007 const static string construct2CommandString = "construct2";
00008 const static string construct3CommandString = "construct3";
00009 const static string copyConstructCommandString = "copyconstruct";
00010 const static string decodeCommandString = "decode";
00011
00012 TpPacketCommand::TpPacketCommand() : Command() {
00013 m_tpPacket = NULL;
00014 }
00015
00016
00017 void
00018 TpPacketCommand::getHtmlInterface(std::ostream& s) {
00019 s << "<h2>Transport Protocol Packet</h2>";
00020 beginUl(s);
00021 generateHtmlSubcmd(s, construct1CommandString, "Construct a data TP packet");
00022 generateHtmlSubcmd(s, construct2CommandString, "Construct a ACK TP packet");
00023 generateHtmlSubcmd(s, construct3CommandString, "Construct an empty data packet");
00024 generateHtmlSubcmd(s, copyConstructCommandString, "Test copy constructor");
00025 generateHtmlSubcmd(s, decodeCommandString, "Decode the packet (must be constructed first)");
00026 endUl(s);
00027 }
00028
00029
00030 void
00031 TpPacketCommand::run(std::ostream& s) {
00032 if (m_args[1] == construct1CommandString) {
00033 m_tpPacket = new TpPacket((u_char*)"abcd" , 5 ,
00034 false , 85 );
00035 s << *m_tpPacket;
00036 m_tpPacket->dumpHeader(s);
00037 delete m_tpPacket;
00038 m_tpPacket = NULL;
00039 }
00040 else if (m_args[1] == construct2CommandString) {
00041 m_tpPacket = new TpPacket(3, 4, false);
00042 s << *m_tpPacket;
00043 m_tpPacket->dumpHeader(s);
00044 delete m_tpPacket;
00045 m_tpPacket = NULL;
00046 }
00047 else if (m_args[1] == construct3CommandString) {
00048 m_tpPacket = new TpPacket(NULL, 0, 0, 35);
00049 s << *m_tpPacket;
00050 m_tpPacket->dumpHeader(s);
00051 delete m_tpPacket;
00052 m_tpPacket = NULL;
00053 }
00054 else if (m_args[1] == copyConstructCommandString) {
00055 m_tpPacket = new TpPacket(3, 4, false);
00056 s << "Testing the copy of an ACK packet...\n";
00057 s << "Original packet:\n";
00058 s << *m_tpPacket;
00059 m_tpPacket->dumpHeader(s);
00060 TpPacket* copy = new TpPacket(*m_tpPacket);
00061 s << "\nCopied packet:\n";
00062 s << *copy;
00063 copy->dumpHeader(s);
00064 delete m_tpPacket;
00065 m_tpPacket = NULL;
00066 delete copy;
00067
00068 s << "Testing copy of a data packet...\n";
00069 s << "Original packet:\n";
00070 m_tpPacket = new TpPacket((u_char*)"abcd" , 5 , false , 85 );
00071 s << *m_tpPacket;
00072 m_tpPacket->dumpHeader(s);
00073 copy = new TpPacket(*m_tpPacket);
00074 s << "\nCopied packet:\n";
00075 s << *copy;
00076 copy->dumpHeader(s);
00077 delete m_tpPacket;
00078 m_tpPacket = NULL;
00079 delete copy;
00080 }
00081 else if (m_args[1] == decodeCommandString) {
00082 TpPacket* decode = new TpPacket(m_tpPacket->getTpData(), m_tpPacket->getTpLength());
00083 s << *decode;
00084 }
00085
00086 }
00087
00088
00089 string
00090 TpPacketCommand::getCommandString() {
00091 return tpPacketCommandString;
00092 }
00093
00094 #endif
00095