From 745875139b5ee46e469927d410364bfeeedb2995 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 11 Oct 2006 15:47:45 +0000 Subject: Despite some svn oddness, I'm now moving to a new setup for the tests, that's very much like the original one, but now using build. You will need the latest build in order to build the tests. --- build.conf | 10 ++- src/test/clistress/main.cpp | 20 ------ src/test/connect/main.cpp | 38 ---------- src/test/exception/exception.cpp | 16 ----- src/test/hash/main.cpp | 10 --- src/test/hashtest/hashtest.cpp | 107 ---------------------------- src/test/httpsrv/httpconnectionmonitor.cpp | 80 --------------------- src/test/httpsrv/httpconnectionmonitor.h | 16 ----- src/test/httpsrv/main.cpp | 22 ------ src/test/log/log.cpp | 29 -------- src/test/md5test/md5test.cpp | 19 ----- src/test/param/param.cpp | 46 ------------ src/test/param/param.h | 21 ------ src/test/plugin/main.cpp | 14 ---- src/test/plugin/plugin.cpp | 10 --- src/test/plugin/plugin.h | 14 ---- src/test/serialize/serialize.cpp | 30 -------- src/test/serializetext/serializetext.cpp | 28 -------- src/test/srvstress/main.cpp | 90 ----------------------- src/test/strhash/main.cpp | 12 ---- src/test/teltest/main.cpp | 21 ------ src/test/teltest/telnetmonitor.cpp | 53 -------------- src/test/teltest/telnetmonitor.h | 26 ------- src/test/xmlreadtest/xmlreadtest.cpp | 29 -------- src/test/xmlrepltest/xmlrepltest.cpp | 31 -------- src/test/xmlwritetest/xmlwritetest.cpp | 48 ------------- src/tests/clistress/main.cpp | 20 ++++++ src/tests/connect/main.cpp | 38 ++++++++++ src/tests/exception/exception.cpp | 16 +++++ src/tests/hash/main.cpp | 10 +++ src/tests/hashtest/hashtest.cpp | 107 ++++++++++++++++++++++++++++ src/tests/httpsrv/httpconnectionmonitor.cpp | 80 +++++++++++++++++++++ src/tests/httpsrv/httpconnectionmonitor.h | 16 +++++ src/tests/httpsrv/main.cpp | 22 ++++++ src/tests/log/log.cpp | 29 ++++++++ src/tests/md5test/md5test.cpp | 19 +++++ src/tests/param/param.cpp | 46 ++++++++++++ src/tests/param/param.h | 21 ++++++ src/tests/plugin/main.cpp | 14 ++++ src/tests/plugin/plugin.cpp | 10 +++ src/tests/plugin/plugin.h | 14 ++++ src/tests/serialize/serialize.cpp | 30 ++++++++ src/tests/serializetext/serializetext.cpp | 28 ++++++++ src/tests/srvstress/main.cpp | 90 +++++++++++++++++++++++ src/tests/strhash/main.cpp | 12 ++++ src/tests/teltest/main.cpp | 21 ++++++ src/tests/teltest/telnetmonitor.cpp | 53 ++++++++++++++ src/tests/teltest/telnetmonitor.h | 26 +++++++ src/tests/xmlreadtest/xmlreadtest.cpp | 29 ++++++++ src/tests/xmlrepltest/xmlrepltest.cpp | 31 ++++++++ src/tests/xmlwritetest.cpp | 48 +++++++++++++ 51 files changed, 839 insertions(+), 831 deletions(-) delete mode 100644 src/test/clistress/main.cpp delete mode 100644 src/test/connect/main.cpp delete mode 100644 src/test/exception/exception.cpp delete mode 100644 src/test/hash/main.cpp delete mode 100644 src/test/hashtest/hashtest.cpp delete mode 100644 src/test/httpsrv/httpconnectionmonitor.cpp delete mode 100644 src/test/httpsrv/httpconnectionmonitor.h delete mode 100644 src/test/httpsrv/main.cpp delete mode 100644 src/test/log/log.cpp delete mode 100644 src/test/md5test/md5test.cpp delete mode 100644 src/test/param/param.cpp delete mode 100644 src/test/param/param.h delete mode 100644 src/test/plugin/main.cpp delete mode 100644 src/test/plugin/plugin.cpp delete mode 100644 src/test/plugin/plugin.h delete mode 100644 src/test/serialize/serialize.cpp delete mode 100644 src/test/serializetext/serializetext.cpp delete mode 100644 src/test/srvstress/main.cpp delete mode 100644 src/test/strhash/main.cpp delete mode 100644 src/test/teltest/main.cpp delete mode 100644 src/test/teltest/telnetmonitor.cpp delete mode 100644 src/test/teltest/telnetmonitor.h delete mode 100644 src/test/xmlreadtest/xmlreadtest.cpp delete mode 100644 src/test/xmlrepltest/xmlrepltest.cpp delete mode 100644 src/test/xmlwritetest/xmlwritetest.cpp create mode 100644 src/tests/clistress/main.cpp create mode 100644 src/tests/connect/main.cpp create mode 100644 src/tests/exception/exception.cpp create mode 100644 src/tests/hash/main.cpp create mode 100644 src/tests/hashtest/hashtest.cpp create mode 100644 src/tests/httpsrv/httpconnectionmonitor.cpp create mode 100644 src/tests/httpsrv/httpconnectionmonitor.h create mode 100644 src/tests/httpsrv/main.cpp create mode 100644 src/tests/log/log.cpp create mode 100644 src/tests/md5test/md5test.cpp create mode 100644 src/tests/param/param.cpp create mode 100644 src/tests/param/param.h create mode 100644 src/tests/plugin/main.cpp create mode 100644 src/tests/plugin/plugin.cpp create mode 100644 src/tests/plugin/plugin.h create mode 100644 src/tests/serialize/serialize.cpp create mode 100644 src/tests/serializetext/serializetext.cpp create mode 100644 src/tests/srvstress/main.cpp create mode 100644 src/tests/strhash/main.cpp create mode 100644 src/tests/teltest/main.cpp create mode 100644 src/tests/teltest/telnetmonitor.cpp create mode 100644 src/tests/teltest/telnetmonitor.h create mode 100644 src/tests/xmlreadtest/xmlreadtest.cpp create mode 100644 src/tests/xmlrepltest/xmlrepltest.cpp create mode 100644 src/tests/xmlwritetest.cpp diff --git a/build.conf b/build.conf index 09efc01..a8c76aa 100644 --- a/build.conf +++ b/build.conf @@ -13,7 +13,7 @@ set "CXXFLAGS" += "-ggdb" set "CXXFLAGS" += "-Isrc -fPIC", input filesIn("src") filter regexp("^.*\\.cpp$") -directoriesIn("src/test","tests/"): +directoriesIn("src/tests","tests/"): rule "exe", target file, requires "libbu++.a", @@ -21,6 +21,14 @@ directoriesIn("src/test","tests/"): set "LDFLAGS" += "-L. -lbu++", input filesIn("{fulldir}") filter regexp("^.*\\.cpp$") +filesIn("src/tests") filter regexp("^src/tests/(.*)\\.cpp$", "tests/{re:1}"): + rule "exe", + target file, + requires "libbu++.a", + set "CXXFLAGS" += "-Isrc", + set "LDFLAGS" += "-L. -lbu++", + input "src/{target}.cpp" + "tests/plugin": set "LDFLAGS" += "-ldl" rule "exe": diff --git a/src/test/clistress/main.cpp b/src/test/clistress/main.cpp deleted file mode 100644 index 6b0ac66..0000000 --- a/src/test/clistress/main.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "connection.h" - -int main() -{ - Connection c; - - c.open("localhost", 4001 ); - - c.appendOutput("w"); - c.writeOutput(); - - c.waitForInput( 6, 5, 0 ); - - printf("read: %s\n", c.getInput() ); - - c.close(); - - return 0; -} - diff --git a/src/test/connect/main.cpp b/src/test/connect/main.cpp deleted file mode 100644 index a9fca64..0000000 --- a/src/test/connect/main.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include -#include -#include -#include -#include "connection.h" - -int main() -{ - Connection c; - c.open("127.0.0.1", 12457 ); - - { - int newSocket = c.getSocket(); - int flags; - - flags = fcntl(newSocket, F_GETFL, 0); - flags |= O_NONBLOCK; - if (fcntl(newSocket, F_SETFL, flags) < 0) - { - return false; - } - } - - for( int i = 0; i < 50; i++ ) - { - usleep( 100000 ); - int nbytes = c.readInput(); - if( nbytes == 0 ) - printf("0 bytes, EOF?\n"); - else - printf("Got %d bytes, whacky...\n", nbytes ); - } - - c.close(); - - return 0; -} - diff --git a/src/test/exception/exception.cpp b/src/test/exception/exception.cpp deleted file mode 100644 index 6417692..0000000 --- a/src/test/exception/exception.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include -#include "exceptions.h" - -int main() -{ - try - { - throw ExceptionBase( 42, "There was an error on line: %d", __LINE__ ); - } - catch( ExceptionBase &e ) - { - std::cout << "Error "<< e.getErrorCode() << ": " << e.what() << "\n"; - } - - throw ExceptionBase( 112, "This exception wasn't caught!"); -} diff --git a/src/test/hash/main.cpp b/src/test/hash/main.cpp deleted file mode 100644 index d0f5fa6..0000000 --- a/src/test/hash/main.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "hash.h" -#include "staticstring.h" - -int main() -{ - //Hash sTest; - - //sTest.hasKey("hello"); -} - diff --git a/src/test/hashtest/hashtest.cpp b/src/test/hashtest/hashtest.cpp deleted file mode 100644 index f31a3f8..0000000 --- a/src/test/hashtest/hashtest.cpp +++ /dev/null @@ -1,107 +0,0 @@ -#include -#include -#include "hashtable.h" -#include "hashfunctioncasestring.h" - -int main() -{ - const char *names[]={ - "Homer the Great", - "And Maggie Makes Three", - "Bart's Comet", - "Homie The Clown", - "Bart Vs Australia", - "Homer vs Patty and Selma", - "A star is burns", - "Lisa's Wedding", - "Two Dozen and One Greyhounds", - "The PTA Disbands", - "Round Springfield", - "The Springfield connection", - "Lemon of Troy", - "Who Shot Mr. Burns (Pt. 1)", - "Who Shot Mr. Burns (pt. 2)", - "Radioactive Man", - "Home Sweet Homediddly-dum-doodly", - "Bart Sells His Soul", - "Lisa the Vegetarian", - "Treehouse of horror VI", - "King Size Homer", - "Mother Simpson", - "Sideshow Bob's Last Gleaming", - "The Simpson's 138th Show Spectacular", - "Marge Be Not Proud", - "Team Homer", - "Two Bad Neighbors", - "Scenes From the Class Struggle in Springfield", - "Bart the Fink", - "Lisa the Iconoclast", - "Homer the Smithers", - "The Day the Violence Died", - "A Fish Called Selma", - "Bart on the road", - "22 Short Films about Springfield", - "The Curse of the Flying Hellfish", - "Much Apu about Nothing", - "Homerpalooza", - "The Summer of 4 Ft 2", - "Treehouse of Horror VII", - "You Only Move Twice", - "The Homer They Fall", - "Burns Baby Burns", - "Bart After Dark", - "A Millhouse Divided", - "Lisas Date With Destiny", - "Hurricane Neddy", - "The Mysterious Voyage of Our Homer", - "The Springfield Files", - "The Twisted World of Marge Simpson", - "Mountain of Madness", - NULL - }; - - HashTable h( new HashFunctionCaseString(), 5, false ); - - int j; - printf("Inserting...\n"); - for( j = 0; j < 10; j++ ) - { - h.insert( names[j], (void *)(j+1) ); - h.insert( names[j], (void *)(j+1) ); - printf("Capacity: %d, Size: %d, Load: %f\n", - h.getCapacity(), - h.getSize(), - h.getLoad() - ); - } - - for( j = 0; j < 10; j++ ) - { - printf("\"%s\" = %d\n", names[j], (int)h[names[j]] ); - } - - printf("\nDeleting some...\n"); - - for( int k = 0; k < 7; k++ ) - { - h.del( names[k] ); - //h.insert( names[j], (void *)(j+1) ); - printf("Capacity: %d, Size: %d, Load: %f\n", - h.getCapacity(), - h.getSize(), - h.getLoad() - ); - } - - printf("\nInserting more...\n"); - - for( ; names[j] != NULL; j++ ) - { - h.insert( names[j], (void *)(j+1) ); - printf("Capacity: %d, Size: %d, Load: %f\n", - h.getCapacity(), - h.getSize(), - h.getLoad() - ); - } -} diff --git a/src/test/httpsrv/httpconnectionmonitor.cpp b/src/test/httpsrv/httpconnectionmonitor.cpp deleted file mode 100644 index ee1eab3..0000000 --- a/src/test/httpsrv/httpconnectionmonitor.cpp +++ /dev/null @@ -1,80 +0,0 @@ -#include "httpconnectionmonitor.h" -#include "http.h" -#include - -HttpConnectionMonitor::HttpConnectionMonitor() -{ -} - -HttpConnectionMonitor::~HttpConnectionMonitor() -{ -} - -bool HttpConnectionMonitor::onNewConnection( Connection *pCon, int nPort ) -{ - printf("Got connection on port %d\n", nPort ); - Http hp( pCon ); - - pCon->readInput( 60, 0 ); - printf("#######################\n%s\n#######################\n", pCon->getInput() ); - - while( hp.parseRequest() == false ); - printf("Done parsing.\n\n"); - - if( hp.getRequestType() == Http::reqGet ) - { - printf("\"\"\"%s\"\"\"\n", hp.getRequestURI() ); - if( !strcmp( hp.getRequestURI(), "/" ) ) - { - std::string content("Server Test</test></head><body>This is a test of a new system where all the pages will be more or less dynamic...<br>If you want to try to login, you can do that here:<br><form method=\"post\" action=\"showvars\" enctype=\"multipart/form-data\">Name: <input type=\"text\" name=\"name\"><br>Password: <input type=\"password\" name=\"pass\"><br><input type=\"submit\" name=\"action\" value=\"login\"></form></body></html>"); - hp.buildResponse(); - hp.setResponseContent( - "text/html", - content.c_str(), - content.size() - ); - hp.sendResponse(); - } - else - { - std::string content("<html><head><title>URL Not Found</test></head><body>There is no content mapped to the URL you requested. Please try another one.</body></html>"); - hp.buildResponse( 404, "File not found."); - hp.setResponseContent( - "text/html", - content.c_str(), - content.size() - ); - hp.sendResponse(); - } - } - else - { - printf("Non get: %s\n", hp.getRequestTypeStr() ); - pCon->appendOutput("HTTP/1.1 100 Continue\r\n\r\n"); - } - pCon->writeOutput(); - //for( int j = 0; j < 50; j++ ) - { - pCon->readInput( 1, 0 ); - //printf("Size so far: %d\n", pCon->getInputAmnt() ); - } - - if( pCon->hasInput() ) - { - std::string s( pCon->getInput(), pCon->getInputAmnt() ); - - pCon->printInputDebug(); - //printf("Reamining data\n==============\n%s\n==============\n", - // s.c_str() ); - } - - pCon->disconnect(); - - return true; -} - -bool HttpConnectionMonitor::onClosedConnection( Connection *pCon ) -{ - return true; -} - diff --git a/src/test/httpsrv/httpconnectionmonitor.h b/src/test/httpsrv/httpconnectionmonitor.h deleted file mode 100644 index 30c0afd..0000000 --- a/src/test/httpsrv/httpconnectionmonitor.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef HTTPCONNECTIONMONITOR_H -#define HTTPCONNECTIONMONITOR_H - -#include "connectionmonitor.h" - -class HttpConnectionMonitor : public ConnectionMonitor -{ -public: - HttpConnectionMonitor(); - ~HttpConnectionMonitor(); - - bool onNewConnection( Connection *pCon, int nPort ); - bool onClosedConnection( Connection *pCon ); -}; - -#endif diff --git a/src/test/httpsrv/main.cpp b/src/test/httpsrv/main.cpp deleted file mode 100644 index 2f1563c..0000000 --- a/src/test/httpsrv/main.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "connectionmanager.h" -#include "httpconnectionmonitor.h" - -int main() -{ - printf("Starting server...\n"); - - ConnectionManager srv; - HttpConnectionMonitor http; - - srv.setConnectionMonitor( &http ); - - printf("Listening on port 7331\n"); - srv.startServer( 7331 ); - - for(;;) - { - srv.scanConnections( 5000, false ); - } - - return 0; -} diff --git a/src/test/log/log.cpp b/src/test/log/log.cpp deleted file mode 100644 index d7cfa0b..0000000 --- a/src/test/log/log.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <iostream> -#include "multilog.h" -#include "multilogtext.h" - -class Test -{ -public: - Test() - { - MultiLineLog( 4, "Test init'd\n"); - } -}; - -int main() -{ - MultiLog &xLog = MultiLog::getInstance(); - - xLog.LineLog( 2, "Hello again"); - - MultiLog::getInstance().addChannel( - new MultiLogText( STDOUT_FILENO, "%02y-%02m-%02d %02h:%02M:%02s: %t" ) - ); - - MultiLineLog( MultiLog::LError, "Hi there!"); - Test t; -} - diff --git a/src/test/md5test/md5test.cpp b/src/test/md5test/md5test.cpp deleted file mode 100644 index 6f832df..0000000 --- a/src/test/md5test/md5test.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include <stdio.h> -#include <string.h> -#include "md5.h" - -int main() -{ - md5 mproc; - md5sum sum; - char hexstr[33]; - - memset( hexstr, 0, 33 ); - - mproc.sumString( &sum, "qwertyuiopasdfgh" ); - mproc.sumToHex( &sum, hexstr ); - printf("sum: %s\n", hexstr ); - printf("chk: 1ebfc043d8880b758b13ddc8aa1638ef\n"); - - return 0; -} diff --git a/src/test/param/param.cpp b/src/test/param/param.cpp deleted file mode 100644 index a4d2824..0000000 --- a/src/test/param/param.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include "param.h" -#include <stdio.h> - -Param::Param() -{ - addHelpBanner("param - A test of the libbu++ parameter systems\n" - "Enjoy with care and caution\n\nTest stuff:\n"); - addParam( "name", 's', mkproc( Param::printStuff ), &str, "Test a param param" ); - //addParam( "name", &str ); - addParam( "job", 'U', mkproc( Param::printStuff ), "Test a paramless param" ); - - addHelpBanner("\nInformational:\n"); - addParam( "help", mkproc( ParamProc::help ), "Help!" ); - - addHelpBanner("\nThanks for trying my test!\n\n"); -} - -Param::~Param() -{ -} - -int Param::printStuff( int argc, char *argv[] ) -{ - printf("------------%02d-------------\n", argc ); - for( int j = 0; j < argc; j++ ) - { - printf("%d: %s\n", j, argv[j] ); - } - printf("---------------------------\n" ); - printf("SETVAR===\"%s\"\n", str.c_str() ); - - return 1; -} - -int main( int argc, char *argv[] ) -{ - if( argc == 1 ) - { - printf("You have to enter some parameter, try '--help'\n\n"); - return 0; - } - - Param p; - p.process( argc, argv ); -} - diff --git a/src/test/param/param.h b/src/test/param/param.h deleted file mode 100644 index 2756b69..0000000 --- a/src/test/param/param.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef PARAM_H -#define PARAM_H - -#include <stdint.h> - -#include "paramproc.h" - -class Param : public ParamProc -{ -public: - Param(); - virtual ~Param(); - -private: - int printStuff( int argc, char *argv[] ); - - std::string str; - uint32_t uint32; -}; - -#endif diff --git a/src/test/plugin/main.cpp b/src/test/plugin/main.cpp deleted file mode 100644 index 51c8390..0000000 --- a/src/test/plugin/main.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "plugger.h" -#include "plugin.h" - -int main() -{ - Plugger<Plugin> p; - - p.registerExternalPlugin( "./guy.so", "Guy" ); - - Plugin *t = p.instantiate( "Guy" ); - - p.destroy( t ); -} - diff --git a/src/test/plugin/plugin.cpp b/src/test/plugin/plugin.cpp deleted file mode 100644 index ea558fd..0000000 --- a/src/test/plugin/plugin.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "plugin.h" - -Plugin::Plugin() -{ -} - -Plugin::~Plugin() -{ -} - diff --git a/src/test/plugin/plugin.h b/src/test/plugin/plugin.h deleted file mode 100644 index f726867..0000000 --- a/src/test/plugin/plugin.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef PLUGIN_H -#define PLUGIN_H - -class Plugin -{ -public: - Plugin(); - virtual ~Plugin(); - -private: - -}; - -#endif diff --git a/src/test/serialize/serialize.cpp b/src/test/serialize/serialize.cpp deleted file mode 100644 index e233704..0000000 --- a/src/test/serialize/serialize.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include "serializerbinary.h" -#include "staticstring.h" -#include <stdio.h> -#include <string> - -int main() -{ - int32_t one; - double two; - bool three; - StaticString s("Test string!"); - std::string ss("Another test string"); - SerializerBinary ar("hello.dat", false); - ar << (int)85; - ar << (double)2.63434; - ar << false; - ar << ss; - ar.close(); - - one = 0; two = 0; three = true; s = "die"; - - SerializerBinary ar2("hello.dat", true); - ar2 >> one; - ar2 >> two; - ar2 >> three; - ar2 >> s; - - printf("we got %d - %f - %s - \"%s\"\n", one, two, (three ? "true":"false"), s.getString() ); - return 0; -} diff --git a/src/test/serializetext/serializetext.cpp b/src/test/serializetext/serializetext.cpp deleted file mode 100644 index f6be7d3..0000000 --- a/src/test/serializetext/serializetext.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "serializertext.h" -#include "staticstring.h" -#include <iostream> - -int main() -{ - StaticString s("You're a dog!!"); - SerializerText ar("hello.dat", false); - - ar << 4 << 3.993 << true << s; - - ar.close(); - - int one=0;float two=0.0;bool three=false; s = ""; - - SerializerText ar2("hello.dat", true); - - ar2 >> one; - ar2 >> two; - ar2 >> three; - ar2 >> s; - - //printf("out: %d, %f, %s, \"%s\"\n", one, two, (three ? "true" : "false"), s.getString()); - std::cout << one << ", " << two << ", " << three << ", " << s.getString() << "\n"; - - return 0; -} - diff --git a/src/test/srvstress/main.cpp b/src/test/srvstress/main.cpp deleted file mode 100644 index 7fe7657..0000000 --- a/src/test/srvstress/main.cpp +++ /dev/null @@ -1,90 +0,0 @@ -#include "connectionmanager.h" -#include "programlink.h" -#include "linkedlist.h" -#include "protocol.h" - -class StressProtocol : public Protocol -{ -public: - bool onNewData() - { - switch( getConnection()->getInput()[0] ) - { - case 'd': - throw "Hello"; - break; - - case 'w': - getConnection()->appendOutput("Hello"); - break; - }; - - return true; - } - - bool onNewConnection() - { - return true; - } -}; - -class StressMonitor : public ConnectionMonitor, public ProgramLink -{ -public: - bool init() - { - return true; - } - - bool deInit() - { - return true; - } - - bool timeSlice() - { - } - - bool onNewConnection( Connection *pCon, int nPort ) - { - StressProtocol *sp = new StressProtocol(); - pCon->setProtocol( sp ); - - printf(" sys: New connection: socket(%d), port(%d)\n", - pCon->getSocket(), nPort ); - - return true; - } - - bool onClosedConnection( Connection *pCon ) - { - printf(" sys: Closed connection: socket(%d)\n", - pCon->getSocket() ); - - return true; - } - - LinkMessage *processIRM( LinkMessage *pMsg ) - { - return NULL; - } -}; - -int main() -{ - printf("Starting server...\n"); - - ConnectionManager srv; - StressMonitor telnet; - - srv.setConnectionMonitor( &telnet ); - - srv.startServer( 4001 ); - - for(;;) - { - srv.scanConnections( 5000, false ); - } - - return 0; -} diff --git a/src/test/strhash/main.cpp b/src/test/strhash/main.cpp deleted file mode 100644 index 790c5b6..0000000 --- a/src/test/strhash/main.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include <stdio.h> -#include "hashfunctionstring.h" - -int main( int argc, char *argv[] ) -{ - HashFunctionString h; - - printf("\"%s\": %d\n", argv[1], h.hash( argv[1] ) ); - - return 0; -} - diff --git a/src/test/teltest/main.cpp b/src/test/teltest/main.cpp deleted file mode 100644 index 5d3ec26..0000000 --- a/src/test/teltest/main.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "connectionmanager.h" -#include "telnetmonitor.h" - -int main() -{ - printf("Starting server...\n"); - - ConnectionManager srv; - TelnetMonitor telnet; - - srv.setConnectionMonitor( &telnet ); - - srv.startServer( 4001 ); - - for(;;) - { - srv.scanConnections( 5000, false ); - } - - return 0; -} diff --git a/src/test/teltest/telnetmonitor.cpp b/src/test/teltest/telnetmonitor.cpp deleted file mode 100644 index 32c2924..0000000 --- a/src/test/teltest/telnetmonitor.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include "telnetmonitor.h" -#include "protocoltelnet.h" -#include <sys/stat.h> - -TelnetMonitor::TelnetMonitor() -{ -} - -TelnetMonitor::~TelnetMonitor() -{ -} - -bool TelnetMonitor::init() -{ - return true; -} - -bool TelnetMonitor::deInit() -{ - return true; -} - -bool TelnetMonitor::timeSlice() -{ - for( int j = 0; j < lCon.getSize(); j++ ) - { - if( ((Connection *)lCon[j])->hasInput() ) - { - printf("%s\n", ((Connection *)lCon[j])->getInput() ); - } - } - return true; -} - -LinkMessage* TelnetMonitor::processIRM( LinkMessage *pMsg ) -{ -} - -bool TelnetMonitor::onNewConnection( Connection *pCon, int nPort ) -{ - ProtocolTelnet *pt = new ProtocolTelnet(); - pCon->setProtocol( pt ); - - lCon.append( pt ); - - return true; -} - -bool TelnetMonitor::onClosedConnection( Connection *pCon ) -{ - return true; -} - diff --git a/src/test/teltest/telnetmonitor.h b/src/test/teltest/telnetmonitor.h deleted file mode 100644 index ba5761e..0000000 --- a/src/test/teltest/telnetmonitor.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef HTTPCONNECTIONMONITOR_H -#define HTTPCONNECTIONMONITOR_H - -#include "connectionmonitor.h" -#include "programlink.h" -#include "linkedlist.h" - -class TelnetMonitor : public ConnectionMonitor, public ProgramLink -{ -public: - TelnetMonitor(); - ~TelnetMonitor(); - - bool init(); - bool deInit(); - bool timeSlice(); - LinkMessage* processIRM( LinkMessage *pMsgIn ); - - bool onNewConnection( Connection *pCon, int nPort ); - bool onClosedConnection( Connection *pCon ); - -private: - LinkedList lCon; -}; - -#endif diff --git a/src/test/xmlreadtest/xmlreadtest.cpp b/src/test/xmlreadtest/xmlreadtest.cpp deleted file mode 100644 index 98d8a9e..0000000 --- a/src/test/xmlreadtest/xmlreadtest.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include "xmlfilereader.h" -#include "xmlstringreader.h" -#include "xmlfilewriter.h" - -int main( int argc, char *argv[] ) -{ - if( argc < 4 ) - { - printf("Usage: %s f <file in> <file out>\n", argv[0] ); - printf(" %s s <xml string> <file out>\n\n", argv[0] ); - return 0; - } - - if( argv[1][0] == 'f' ) - { - XmlFileReader r( argv[2], true ); -// XmlFileWriter w( argv[3], "\t", r.detatchRoot() ); -// w.write(); - } - else if( argv[1][0] == 's' ) - { - XmlStringReader r( argv[2], true ); -// XmlWriter w( argv[3], "\t", r.detatchRoot() ); -// w.write(); - } - - return 0; -} - diff --git a/src/test/xmlrepltest/xmlrepltest.cpp b/src/test/xmlrepltest/xmlrepltest.cpp deleted file mode 100644 index 1fe9ec2..0000000 --- a/src/test/xmlrepltest/xmlrepltest.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "xmlwriter.h" - -int main() -{ - printf("Testing Xml Replacement...\n"); - XmlDocument w; - - w.addNode("text"); - w.setContent("this text is before the node. "); - w.addNode("keepme", "This one we keep...", true ); - w.setContent("this text is after."); - w.addNode("deleteme", "This one we don't...", true ); - w.setContent("this is last..." ); - w.closeNode(); - - //XmlWriter::writeNode( stdout, w.getRoot(), 0, NULL ); - - printf("\n\n"); - - XmlNode *xNode = w.getRoot()->detatchNode( 1 ); - - //XmlWriter::writeNode( stdout, w.getRoot(), 0, NULL ); - - printf("\n\n"); - - //XmlWriter::writeNode( stdout, xNode, 0, NULL ); - - printf("\n\n"); - - return 0; -} diff --git a/src/test/xmlwritetest/xmlwritetest.cpp b/src/test/xmlwritetest/xmlwritetest.cpp deleted file mode 100644 index 54c7a80..0000000 --- a/src/test/xmlwritetest/xmlwritetest.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include "xmlfilewriter.h" -#include "xmlstringwriter.h" -#include "xmlstringreader.h" - -void fillItIn( XmlWriter &w ) -{ - w.addNode("thinglist"); - - w.addNode("thing"); - w.addProperty("type", "Weapon"); - - w.addNode("id", "Klophin Staff", true ); - w.addNode("name", "Klophin Staff", true ); - w.addNode("durability", "0.01", true ); - w.addNode("size", "0.1", true ); - - w.addNode("config"); - w.addNode("damage", "3d6+4", true ); - w.addNode("class", "melee", true ); - w.addNode("type", "bludgeon", true ); - w.addNode("damagedesc", "club/clubs", true ); - w.closeNode(); - - w.closeNode(); - - w.closeNode(); -} - -int main() -{ - printf("Testing XmlWriter...\n"); - - //XmlStringReader *xsr = new XmlStringReader("<stuff/>"); - - //printf("%08X\n%08X\n%08X\n", xsr, (XmlReader *)xsr, (XmlDocument *)xsr ); - - //delete (XmlDocument *)xsr; - XmlFileWriter wf("test.xml", "\t"); - - fillItIn( wf ); - - XmlStringWriter ws("\t"); - fillItIn( ws ); - - printf("Now the string version:\n\n%s\n", ws.getString().c_str() ); - - return 0; -} diff --git a/src/tests/clistress/main.cpp b/src/tests/clistress/main.cpp new file mode 100644 index 0000000..6b0ac66 --- /dev/null +++ b/src/tests/clistress/main.cpp @@ -0,0 +1,20 @@ +#include "connection.h" + +int main() +{ + Connection c; + + c.open("localhost", 4001 ); + + c.appendOutput("w"); + c.writeOutput(); + + c.waitForInput( 6, 5, 0 ); + + printf("read: %s\n", c.getInput() ); + + c.close(); + + return 0; +} + diff --git a/src/tests/connect/main.cpp b/src/tests/connect/main.cpp new file mode 100644 index 0000000..a9fca64 --- /dev/null +++ b/src/tests/connect/main.cpp @@ -0,0 +1,38 @@ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <fcntl.h> +#include "connection.h" + +int main() +{ + Connection c; + c.open("127.0.0.1", 12457 ); + + { + int newSocket = c.getSocket(); + int flags; + + flags = fcntl(newSocket, F_GETFL, 0); + flags |= O_NONBLOCK; + if (fcntl(newSocket, F_SETFL, flags) < 0) + { + return false; + } + } + + for( int i = 0; i < 50; i++ ) + { + usleep( 100000 ); + int nbytes = c.readInput(); + if( nbytes == 0 ) + printf("0 bytes, EOF?\n"); + else + printf("Got %d bytes, whacky...\n", nbytes ); + } + + c.close(); + + return 0; +} + diff --git a/src/tests/exception/exception.cpp b/src/tests/exception/exception.cpp new file mode 100644 index 0000000..6417692 --- /dev/null +++ b/src/tests/exception/exception.cpp @@ -0,0 +1,16 @@ +#include <iostream> +#include "exceptions.h" + +int main() +{ + try + { + throw ExceptionBase( 42, "There was an error on line: %d", __LINE__ ); + } + catch( ExceptionBase &e ) + { + std::cout << "Error "<< e.getErrorCode() << ": " << e.what() << "\n"; + } + + throw ExceptionBase( 112, "This exception wasn't caught!"); +} diff --git a/src/tests/hash/main.cpp b/src/tests/hash/main.cpp new file mode 100644 index 0000000..d0f5fa6 --- /dev/null +++ b/src/tests/hash/main.cpp @@ -0,0 +1,10 @@ +#include "hash.h" +#include "staticstring.h" + +int main() +{ + //Hash<class StaticString, int> sTest; + + //sTest.hasKey("hello"); +} + diff --git a/src/tests/hashtest/hashtest.cpp b/src/tests/hashtest/hashtest.cpp new file mode 100644 index 0000000..f31a3f8 --- /dev/null +++ b/src/tests/hashtest/hashtest.cpp @@ -0,0 +1,107 @@ +#include <stdio.h> +#include <iostream> +#include "hashtable.h" +#include "hashfunctioncasestring.h" + +int main() +{ + const char *names[]={ + "Homer the Great", + "And Maggie Makes Three", + "Bart's Comet", + "Homie The Clown", + "Bart Vs Australia", + "Homer vs Patty and Selma", + "A star is burns", + "Lisa's Wedding", + "Two Dozen and One Greyhounds", + "The PTA Disbands", + "Round Springfield", + "The Springfield connection", + "Lemon of Troy", + "Who Shot Mr. Burns (Pt. 1)", + "Who Shot Mr. Burns (pt. 2)", + "Radioactive Man", + "Home Sweet Homediddly-dum-doodly", + "Bart Sells His Soul", + "Lisa the Vegetarian", + "Treehouse of horror VI", + "King Size Homer", + "Mother Simpson", + "Sideshow Bob's Last Gleaming", + "The Simpson's 138th Show Spectacular", + "Marge Be Not Proud", + "Team Homer", + "Two Bad Neighbors", + "Scenes From the Class Struggle in Springfield", + "Bart the Fink", + "Lisa the Iconoclast", + "Homer the Smithers", + "The Day the Violence Died", + "A Fish Called Selma", + "Bart on the road", + "22 Short Films about Springfield", + "The Curse of the Flying Hellfish", + "Much Apu about Nothing", + "Homerpalooza", + "The Summer of 4 Ft 2", + "Treehouse of Horror VII", + "You Only Move Twice", + "The Homer They Fall", + "Burns Baby Burns", + "Bart After Dark", + "A Millhouse Divided", + "Lisas Date With Destiny", + "Hurricane Neddy", + "The Mysterious Voyage of Our Homer", + "The Springfield Files", + "The Twisted World of Marge Simpson", + "Mountain of Madness", + NULL + }; + + HashTable h( new HashFunctionCaseString(), 5, false ); + + int j; + printf("Inserting...\n"); + for( j = 0; j < 10; j++ ) + { + h.insert( names[j], (void *)(j+1) ); + h.insert( names[j], (void *)(j+1) ); + printf("Capacity: %d, Size: %d, Load: %f\n", + h.getCapacity(), + h.getSize(), + h.getLoad() + ); + } + + for( j = 0; j < 10; j++ ) + { + printf("\"%s\" = %d\n", names[j], (int)h[names[j]] ); + } + + printf("\nDeleting some...\n"); + + for( int k = 0; k < 7; k++ ) + { + h.del( names[k] ); + //h.insert( names[j], (void *)(j+1) ); + printf("Capacity: %d, Size: %d, Load: %f\n", + h.getCapacity(), + h.getSize(), + h.getLoad() + ); + } + + printf("\nInserting more...\n"); + + for( ; names[j] != NULL; j++ ) + { + h.insert( names[j], (void *)(j+1) ); + printf("Capacity: %d, Size: %d, Load: %f\n", + h.getCapacity(), + h.getSize(), + h.getLoad() + ); + } +} diff --git a/src/tests/httpsrv/httpconnectionmonitor.cpp b/src/tests/httpsrv/httpconnectionmonitor.cpp new file mode 100644 index 0000000..ee1eab3 --- /dev/null +++ b/src/tests/httpsrv/httpconnectionmonitor.cpp @@ -0,0 +1,80 @@ +#include "httpconnectionmonitor.h" +#include "http.h" +#include <sys/stat.h> + +HttpConnectionMonitor::HttpConnectionMonitor() +{ +} + +HttpConnectionMonitor::~HttpConnectionMonitor() +{ +} + +bool HttpConnectionMonitor::onNewConnection( Connection *pCon, int nPort ) +{ + printf("Got connection on port %d\n", nPort ); + Http hp( pCon ); + + pCon->readInput( 60, 0 ); + printf("#######################\n%s\n#######################\n", pCon->getInput() ); + + while( hp.parseRequest() == false ); + printf("Done parsing.\n\n"); + + if( hp.getRequestType() == Http::reqGet ) + { + printf("\"\"\"%s\"\"\"\n", hp.getRequestURI() ); + if( !strcmp( hp.getRequestURI(), "/" ) ) + { + std::string content("<html><head><title>Server Test</test></head><body>This is a test of a new system where all the pages will be more or less dynamic...<br>If you want to try to login, you can do that here:<br><form method=\"post\" action=\"showvars\" enctype=\"multipart/form-data\">Name: <input type=\"text\" name=\"name\"><br>Password: <input type=\"password\" name=\"pass\"><br><input type=\"submit\" name=\"action\" value=\"login\"></form></body></html>"); + hp.buildResponse(); + hp.setResponseContent( + "text/html", + content.c_str(), + content.size() + ); + hp.sendResponse(); + } + else + { + std::string content("<html><head><title>URL Not Found</test></head><body>There is no content mapped to the URL you requested. Please try another one.</body></html>"); + hp.buildResponse( 404, "File not found."); + hp.setResponseContent( + "text/html", + content.c_str(), + content.size() + ); + hp.sendResponse(); + } + } + else + { + printf("Non get: %s\n", hp.getRequestTypeStr() ); + pCon->appendOutput("HTTP/1.1 100 Continue\r\n\r\n"); + } + pCon->writeOutput(); + //for( int j = 0; j < 50; j++ ) + { + pCon->readInput( 1, 0 ); + //printf("Size so far: %d\n", pCon->getInputAmnt() ); + } + + if( pCon->hasInput() ) + { + std::string s( pCon->getInput(), pCon->getInputAmnt() ); + + pCon->printInputDebug(); + //printf("Reamining data\n==============\n%s\n==============\n", + // s.c_str() ); + } + + pCon->disconnect(); + + return true; +} + +bool HttpConnectionMonitor::onClosedConnection( Connection *pCon ) +{ + return true; +} + diff --git a/src/tests/httpsrv/httpconnectionmonitor.h b/src/tests/httpsrv/httpconnectionmonitor.h new file mode 100644 index 0000000..30c0afd --- /dev/null +++ b/src/tests/httpsrv/httpconnectionmonitor.h @@ -0,0 +1,16 @@ +#ifndef HTTPCONNECTIONMONITOR_H +#define HTTPCONNECTIONMONITOR_H + +#include "connectionmonitor.h" + +class HttpConnectionMonitor : public ConnectionMonitor +{ +public: + HttpConnectionMonitor(); + ~HttpConnectionMonitor(); + + bool onNewConnection( Connection *pCon, int nPort ); + bool onClosedConnection( Connection *pCon ); +}; + +#endif diff --git a/src/tests/httpsrv/main.cpp b/src/tests/httpsrv/main.cpp new file mode 100644 index 0000000..2f1563c --- /dev/null +++ b/src/tests/httpsrv/main.cpp @@ -0,0 +1,22 @@ +#include "connectionmanager.h" +#include "httpconnectionmonitor.h" + +int main() +{ + printf("Starting server...\n"); + + ConnectionManager srv; + HttpConnectionMonitor http; + + srv.setConnectionMonitor( &http ); + + printf("Listening on port 7331\n"); + srv.startServer( 7331 ); + + for(;;) + { + srv.scanConnections( 5000, false ); + } + + return 0; +} diff --git a/src/tests/log/log.cpp b/src/tests/log/log.cpp new file mode 100644 index 0000000..d7cfa0b --- /dev/null +++ b/src/tests/log/log.cpp @@ -0,0 +1,29 @@ +#include <stdio.h> +#include <stdlib.h> +#include <iostream> +#include "multilog.h" +#include "multilogtext.h" + +class Test +{ +public: + Test() + { + MultiLineLog( 4, "Test init'd\n"); + } +}; + +int main() +{ + MultiLog &xLog = MultiLog::getInstance(); + + xLog.LineLog( 2, "Hello again"); + + MultiLog::getInstance().addChannel( + new MultiLogText( STDOUT_FILENO, "%02y-%02m-%02d %02h:%02M:%02s: %t" ) + ); + + MultiLineLog( MultiLog::LError, "Hi there!"); + Test t; +} + diff --git a/src/tests/md5test/md5test.cpp b/src/tests/md5test/md5test.cpp new file mode 100644 index 0000000..6f832df --- /dev/null +++ b/src/tests/md5test/md5test.cpp @@ -0,0 +1,19 @@ +#include <stdio.h> +#include <string.h> +#include "md5.h" + +int main() +{ + md5 mproc; + md5sum sum; + char hexstr[33]; + + memset( hexstr, 0, 33 ); + + mproc.sumString( &sum, "qwertyuiopasdfgh" ); + mproc.sumToHex( &sum, hexstr ); + printf("sum: %s\n", hexstr ); + printf("chk: 1ebfc043d8880b758b13ddc8aa1638ef\n"); + + return 0; +} diff --git a/src/tests/param/param.cpp b/src/tests/param/param.cpp new file mode 100644 index 0000000..a4d2824 --- /dev/null +++ b/src/tests/param/param.cpp @@ -0,0 +1,46 @@ +#include "param.h" +#include <stdio.h> + +Param::Param() +{ + addHelpBanner("param - A test of the libbu++ parameter systems\n" + "Enjoy with care and caution\n\nTest stuff:\n"); + addParam( "name", 's', mkproc( Param::printStuff ), &str, "Test a param param" ); + //addParam( "name", &str ); + addParam( "job", 'U', mkproc( Param::printStuff ), "Test a paramless param" ); + + addHelpBanner("\nInformational:\n"); + addParam( "help", mkproc( ParamProc::help ), "Help!" ); + + addHelpBanner("\nThanks for trying my test!\n\n"); +} + +Param::~Param() +{ +} + +int Param::printStuff( int argc, char *argv[] ) +{ + printf("------------%02d-------------\n", argc ); + for( int j = 0; j < argc; j++ ) + { + printf("%d: %s\n", j, argv[j] ); + } + printf("---------------------------\n" ); + printf("SETVAR===\"%s\"\n", str.c_str() ); + + return 1; +} + +int main( int argc, char *argv[] ) +{ + if( argc == 1 ) + { + printf("You have to enter some parameter, try '--help'\n\n"); + return 0; + } + + Param p; + p.process( argc, argv ); +} + diff --git a/src/tests/param/param.h b/src/tests/param/param.h new file mode 100644 index 0000000..2756b69 --- /dev/null +++ b/src/tests/param/param.h @@ -0,0 +1,21 @@ +#ifndef PARAM_H +#define PARAM_H + +#include <stdint.h> + +#include "paramproc.h" + +class Param : public ParamProc +{ +public: + Param(); + virtual ~Param(); + +private: + int printStuff( int argc, char *argv[] ); + + std::string str; + uint32_t uint32; +}; + +#endif diff --git a/src/tests/plugin/main.cpp b/src/tests/plugin/main.cpp new file mode 100644 index 0000000..51c8390 --- /dev/null +++ b/src/tests/plugin/main.cpp @@ -0,0 +1,14 @@ +#include "plugger.h" +#include "plugin.h" + +int main() +{ + Plugger<Plugin> p; + + p.registerExternalPlugin( "./guy.so", "Guy" ); + + Plugin *t = p.instantiate( "Guy" ); + + p.destroy( t ); +} + diff --git a/src/tests/plugin/plugin.cpp b/src/tests/plugin/plugin.cpp new file mode 100644 index 0000000..ea558fd --- /dev/null +++ b/src/tests/plugin/plugin.cpp @@ -0,0 +1,10 @@ +#include "plugin.h" + +Plugin::Plugin() +{ +} + +Plugin::~Plugin() +{ +} + diff --git a/src/tests/plugin/plugin.h b/src/tests/plugin/plugin.h new file mode 100644 index 0000000..f726867 --- /dev/null +++ b/src/tests/plugin/plugin.h @@ -0,0 +1,14 @@ +#ifndef PLUGIN_H +#define PLUGIN_H + +class Plugin +{ +public: + Plugin(); + virtual ~Plugin(); + +private: + +}; + +#endif diff --git a/src/tests/serialize/serialize.cpp b/src/tests/serialize/serialize.cpp new file mode 100644 index 0000000..e233704 --- /dev/null +++ b/src/tests/serialize/serialize.cpp @@ -0,0 +1,30 @@ +#include "serializerbinary.h" +#include "staticstring.h" +#include <stdio.h> +#include <string> + +int main() +{ + int32_t one; + double two; + bool three; + StaticString s("Test string!"); + std::string ss("Another test string"); + SerializerBinary ar("hello.dat", false); + ar << (int)85; + ar << (double)2.63434; + ar << false; + ar << ss; + ar.close(); + + one = 0; two = 0; three = true; s = "die"; + + SerializerBinary ar2("hello.dat", true); + ar2 >> one; + ar2 >> two; + ar2 >> three; + ar2 >> s; + + printf("we got %d - %f - %s - \"%s\"\n", one, two, (three ? "true":"false"), s.getString() ); + return 0; +} diff --git a/src/tests/serializetext/serializetext.cpp b/src/tests/serializetext/serializetext.cpp new file mode 100644 index 0000000..f6be7d3 --- /dev/null +++ b/src/tests/serializetext/serializetext.cpp @@ -0,0 +1,28 @@ +#include "serializertext.h" +#include "staticstring.h" +#include <iostream> + +int main() +{ + StaticString s("You're a dog!!"); + SerializerText ar("hello.dat", false); + + ar << 4 << 3.993 << true << s; + + ar.close(); + + int one=0;float two=0.0;bool three=false; s = ""; + + SerializerText ar2("hello.dat", true); + + ar2 >> one; + ar2 >> two; + ar2 >> three; + ar2 >> s; + + //printf("out: %d, %f, %s, \"%s\"\n", one, two, (three ? "true" : "false"), s.getString()); + std::cout << one << ", " << two << ", " << three << ", " << s.getString() << "\n"; + + return 0; +} + diff --git a/src/tests/srvstress/main.cpp b/src/tests/srvstress/main.cpp new file mode 100644 index 0000000..7fe7657 --- /dev/null +++ b/src/tests/srvstress/main.cpp @@ -0,0 +1,90 @@ +#include "connectionmanager.h" +#include "programlink.h" +#include "linkedlist.h" +#include "protocol.h" + +class StressProtocol : public Protocol +{ +public: + bool onNewData() + { + switch( getConnection()->getInput()[0] ) + { + case 'd': + throw "Hello"; + break; + + case 'w': + getConnection()->appendOutput("Hello"); + break; + }; + + return true; + } + + bool onNewConnection() + { + return true; + } +}; + +class StressMonitor : public ConnectionMonitor, public ProgramLink +{ +public: + bool init() + { + return true; + } + + bool deInit() + { + return true; + } + + bool timeSlice() + { + } + + bool onNewConnection( Connection *pCon, int nPort ) + { + StressProtocol *sp = new StressProtocol(); + pCon->setProtocol( sp ); + + printf(" sys: New connection: socket(%d), port(%d)\n", + pCon->getSocket(), nPort ); + + return true; + } + + bool onClosedConnection( Connection *pCon ) + { + printf(" sys: Closed connection: socket(%d)\n", + pCon->getSocket() ); + + return true; + } + + LinkMessage *processIRM( LinkMessage *pMsg ) + { + return NULL; + } +}; + +int main() +{ + printf("Starting server...\n"); + + ConnectionManager srv; + StressMonitor telnet; + + srv.setConnectionMonitor( &telnet ); + + srv.startServer( 4001 ); + + for(;;) + { + srv.scanConnections( 5000, false ); + } + + return 0; +} diff --git a/src/tests/strhash/main.cpp b/src/tests/strhash/main.cpp new file mode 100644 index 0000000..790c5b6 --- /dev/null +++ b/src/tests/strhash/main.cpp @@ -0,0 +1,12 @@ +#include <stdio.h> +#include "hashfunctionstring.h" + +int main( int argc, char *argv[] ) +{ + HashFunctionString h; + + printf("\"%s\": %d\n", argv[1], h.hash( argv[1] ) ); + + return 0; +} + diff --git a/src/tests/teltest/main.cpp b/src/tests/teltest/main.cpp new file mode 100644 index 0000000..5d3ec26 --- /dev/null +++ b/src/tests/teltest/main.cpp @@ -0,0 +1,21 @@ +#include "connectionmanager.h" +#include "telnetmonitor.h" + +int main() +{ + printf("Starting server...\n"); + + ConnectionManager srv; + TelnetMonitor telnet; + + srv.setConnectionMonitor( &telnet ); + + srv.startServer( 4001 ); + + for(;;) + { + srv.scanConnections( 5000, false ); + } + + return 0; +} diff --git a/src/tests/teltest/telnetmonitor.cpp b/src/tests/teltest/telnetmonitor.cpp new file mode 100644 index 0000000..32c2924 --- /dev/null +++ b/src/tests/teltest/telnetmonitor.cpp @@ -0,0 +1,53 @@ +#include "telnetmonitor.h" +#include "protocoltelnet.h" +#include <sys/stat.h> + +TelnetMonitor::TelnetMonitor() +{ +} + +TelnetMonitor::~TelnetMonitor() +{ +} + +bool TelnetMonitor::init() +{ + return true; +} + +bool TelnetMonitor::deInit() +{ + return true; +} + +bool TelnetMonitor::timeSlice() +{ + for( int j = 0; j < lCon.getSize(); j++ ) + { + if( ((Connection *)lCon[j])->hasInput() ) + { + printf("%s\n", ((Connection *)lCon[j])->getInput() ); + } + } + return true; +} + +LinkMessage* TelnetMonitor::processIRM( LinkMessage *pMsg ) +{ +} + +bool TelnetMonitor::onNewConnection( Connection *pCon, int nPort ) +{ + ProtocolTelnet *pt = new ProtocolTelnet(); + pCon->setProtocol( pt ); + + lCon.append( pt ); + + return true; +} + +bool TelnetMonitor::onClosedConnection( Connection *pCon ) +{ + return true; +} + diff --git a/src/tests/teltest/telnetmonitor.h b/src/tests/teltest/telnetmonitor.h new file mode 100644 index 0000000..ba5761e --- /dev/null +++ b/src/tests/teltest/telnetmonitor.h @@ -0,0 +1,26 @@ +#ifndef HTTPCONNECTIONMONITOR_H +#define HTTPCONNECTIONMONITOR_H + +#include "connectionmonitor.h" +#include "programlink.h" +#include "linkedlist.h" + +class TelnetMonitor : public ConnectionMonitor, public ProgramLink +{ +public: + TelnetMonitor(); + ~TelnetMonitor(); + + bool init(); + bool deInit(); + bool timeSlice(); + LinkMessage* processIRM( LinkMessage *pMsgIn ); + + bool onNewConnection( Connection *pCon, int nPort ); + bool onClosedConnection( Connection *pCon ); + +private: + LinkedList lCon; +}; + +#endif diff --git a/src/tests/xmlreadtest/xmlreadtest.cpp b/src/tests/xmlreadtest/xmlreadtest.cpp new file mode 100644 index 0000000..98d8a9e --- /dev/null +++ b/src/tests/xmlreadtest/xmlreadtest.cpp @@ -0,0 +1,29 @@ +#include "xmlfilereader.h" +#include "xmlstringreader.h" +#include "xmlfilewriter.h" + +int main( int argc, char *argv[] ) +{ + if( argc < 4 ) + { + printf("Usage: %s f <file in> <file out>\n", argv[0] ); + printf(" %s s <xml string> <file out>\n\n", argv[0] ); + return 0; + } + + if( argv[1][0] == 'f' ) + { + XmlFileReader r( argv[2], true ); +// XmlFileWriter w( argv[3], "\t", r.detatchRoot() ); +// w.write(); + } + else if( argv[1][0] == 's' ) + { + XmlStringReader r( argv[2], true ); +// XmlWriter w( argv[3], "\t", r.detatchRoot() ); +// w.write(); + } + + return 0; +} + diff --git a/src/tests/xmlrepltest/xmlrepltest.cpp b/src/tests/xmlrepltest/xmlrepltest.cpp new file mode 100644 index 0000000..1fe9ec2 --- /dev/null +++ b/src/tests/xmlrepltest/xmlrepltest.cpp @@ -0,0 +1,31 @@ +#include "xmlwriter.h" + +int main() +{ + printf("Testing Xml Replacement...\n"); + XmlDocument w; + + w.addNode("text"); + w.setContent("this text is before the node. "); + w.addNode("keepme", "This one we keep...", true ); + w.setContent("this text is after."); + w.addNode("deleteme", "This one we don't...", true ); + w.setContent("this is last..." ); + w.closeNode(); + + //XmlWriter::writeNode( stdout, w.getRoot(), 0, NULL ); + + printf("\n\n"); + + XmlNode *xNode = w.getRoot()->detatchNode( 1 ); + + //XmlWriter::writeNode( stdout, w.getRoot(), 0, NULL ); + + printf("\n\n"); + + //XmlWriter::writeNode( stdout, xNode, 0, NULL ); + + printf("\n\n"); + + return 0; +} diff --git a/src/tests/xmlwritetest.cpp b/src/tests/xmlwritetest.cpp new file mode 100644 index 0000000..54c7a80 --- /dev/null +++ b/src/tests/xmlwritetest.cpp @@ -0,0 +1,48 @@ +#include "xmlfilewriter.h" +#include "xmlstringwriter.h" +#include "xmlstringreader.h" + +void fillItIn( XmlWriter &w ) +{ + w.addNode("thinglist"); + + w.addNode("thing"); + w.addProperty("type", "Weapon"); + + w.addNode("id", "Klophin Staff", true ); + w.addNode("name", "Klophin Staff", true ); + w.addNode("durability", "0.01", true ); + w.addNode("size", "0.1", true ); + + w.addNode("config"); + w.addNode("damage", "3d6+4", true ); + w.addNode("class", "melee", true ); + w.addNode("type", "bludgeon", true ); + w.addNode("damagedesc", "club/clubs", true ); + w.closeNode(); + + w.closeNode(); + + w.closeNode(); +} + +int main() +{ + printf("Testing XmlWriter...\n"); + + //XmlStringReader *xsr = new XmlStringReader("<stuff/>"); + + //printf("%08X\n%08X\n%08X\n", xsr, (XmlReader *)xsr, (XmlDocument *)xsr ); + + //delete (XmlDocument *)xsr; + XmlFileWriter wf("test.xml", "\t"); + + fillItIn( wf ); + + XmlStringWriter ws("\t"); + fillItIn( ws ); + + printf("Now the string version:\n\n%s\n", ws.getString().c_str() ); + + return 0; +} -- cgit v1.2.3