diff options
Diffstat (limited to 'src/tests')
25 files changed, 830 insertions, 0 deletions
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 @@ | |||
| 1 | #include "connection.h" | ||
| 2 | |||
| 3 | int main() | ||
| 4 | { | ||
| 5 | Connection c; | ||
| 6 | |||
| 7 | c.open("localhost", 4001 ); | ||
| 8 | |||
| 9 | c.appendOutput("w"); | ||
| 10 | c.writeOutput(); | ||
| 11 | |||
| 12 | c.waitForInput( 6, 5, 0 ); | ||
| 13 | |||
| 14 | printf("read: %s\n", c.getInput() ); | ||
| 15 | |||
| 16 | c.close(); | ||
| 17 | |||
| 18 | return 0; | ||
| 19 | } | ||
| 20 | |||
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 @@ | |||
| 1 | #include <stdio.h> | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <unistd.h> | ||
| 4 | #include <fcntl.h> | ||
| 5 | #include "connection.h" | ||
| 6 | |||
| 7 | int main() | ||
| 8 | { | ||
| 9 | Connection c; | ||
| 10 | c.open("127.0.0.1", 12457 ); | ||
| 11 | |||
| 12 | { | ||
| 13 | int newSocket = c.getSocket(); | ||
| 14 | int flags; | ||
| 15 | |||
| 16 | flags = fcntl(newSocket, F_GETFL, 0); | ||
| 17 | flags |= O_NONBLOCK; | ||
| 18 | if (fcntl(newSocket, F_SETFL, flags) < 0) | ||
| 19 | { | ||
| 20 | return false; | ||
| 21 | } | ||
| 22 | } | ||
| 23 | |||
| 24 | for( int i = 0; i < 50; i++ ) | ||
| 25 | { | ||
| 26 | usleep( 100000 ); | ||
| 27 | int nbytes = c.readInput(); | ||
| 28 | if( nbytes == 0 ) | ||
| 29 | printf("0 bytes, EOF?\n"); | ||
| 30 | else | ||
| 31 | printf("Got %d bytes, whacky...\n", nbytes ); | ||
| 32 | } | ||
| 33 | |||
| 34 | c.close(); | ||
| 35 | |||
| 36 | return 0; | ||
| 37 | } | ||
| 38 | |||
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 @@ | |||
| 1 | #include <iostream> | ||
| 2 | #include "exceptions.h" | ||
| 3 | |||
| 4 | int main() | ||
| 5 | { | ||
| 6 | try | ||
| 7 | { | ||
| 8 | throw ExceptionBase( 42, "There was an error on line: %d", __LINE__ ); | ||
| 9 | } | ||
| 10 | catch( ExceptionBase &e ) | ||
| 11 | { | ||
| 12 | std::cout << "Error "<< e.getErrorCode() << ": " << e.what() << "\n"; | ||
| 13 | } | ||
| 14 | |||
| 15 | throw ExceptionBase( 112, "This exception wasn't caught!"); | ||
| 16 | } | ||
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 @@ | |||
| 1 | #include "hash.h" | ||
| 2 | #include "staticstring.h" | ||
| 3 | |||
| 4 | int main() | ||
| 5 | { | ||
| 6 | //Hash<class StaticString, int> sTest; | ||
| 7 | |||
| 8 | //sTest.hasKey("hello"); | ||
| 9 | } | ||
| 10 | |||
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 @@ | |||
| 1 | #include <stdio.h> | ||
| 2 | #include <iostream> | ||
| 3 | #include "hashtable.h" | ||
| 4 | #include "hashfunctioncasestring.h" | ||
| 5 | |||
| 6 | int main() | ||
| 7 | { | ||
| 8 | const char *names[]={ | ||
| 9 | "Homer the Great", | ||
| 10 | "And Maggie Makes Three", | ||
| 11 | "Bart's Comet", | ||
| 12 | "Homie The Clown", | ||
| 13 | "Bart Vs Australia", | ||
| 14 | "Homer vs Patty and Selma", | ||
| 15 | "A star is burns", | ||
| 16 | "Lisa's Wedding", | ||
| 17 | "Two Dozen and One Greyhounds", | ||
| 18 | "The PTA Disbands", | ||
| 19 | "Round Springfield", | ||
| 20 | "The Springfield connection", | ||
| 21 | "Lemon of Troy", | ||
| 22 | "Who Shot Mr. Burns (Pt. 1)", | ||
| 23 | "Who Shot Mr. Burns (pt. 2)", | ||
| 24 | "Radioactive Man", | ||
| 25 | "Home Sweet Homediddly-dum-doodly", | ||
| 26 | "Bart Sells His Soul", | ||
| 27 | "Lisa the Vegetarian", | ||
| 28 | "Treehouse of horror VI", | ||
| 29 | "King Size Homer", | ||
| 30 | "Mother Simpson", | ||
| 31 | "Sideshow Bob's Last Gleaming", | ||
| 32 | "The Simpson's 138th Show Spectacular", | ||
| 33 | "Marge Be Not Proud", | ||
| 34 | "Team Homer", | ||
| 35 | "Two Bad Neighbors", | ||
| 36 | "Scenes From the Class Struggle in Springfield", | ||
| 37 | "Bart the Fink", | ||
| 38 | "Lisa the Iconoclast", | ||
| 39 | "Homer the Smithers", | ||
| 40 | "The Day the Violence Died", | ||
| 41 | "A Fish Called Selma", | ||
| 42 | "Bart on the road", | ||
| 43 | "22 Short Films about Springfield", | ||
| 44 | "The Curse of the Flying Hellfish", | ||
| 45 | "Much Apu about Nothing", | ||
| 46 | "Homerpalooza", | ||
| 47 | "The Summer of 4 Ft 2", | ||
| 48 | "Treehouse of Horror VII", | ||
| 49 | "You Only Move Twice", | ||
| 50 | "The Homer They Fall", | ||
| 51 | "Burns Baby Burns", | ||
| 52 | "Bart After Dark", | ||
| 53 | "A Millhouse Divided", | ||
| 54 | "Lisas Date With Destiny", | ||
| 55 | "Hurricane Neddy", | ||
| 56 | "The Mysterious Voyage of Our Homer", | ||
| 57 | "The Springfield Files", | ||
| 58 | "The Twisted World of Marge Simpson", | ||
| 59 | "Mountain of Madness", | ||
| 60 | NULL | ||
| 61 | }; | ||
| 62 | |||
| 63 | HashTable h( new HashFunctionCaseString(), 5, false ); | ||
| 64 | |||
| 65 | int j; | ||
| 66 | printf("Inserting...\n"); | ||
| 67 | for( j = 0; j < 10; j++ ) | ||
| 68 | { | ||
| 69 | h.insert( names[j], (void *)(j+1) ); | ||
| 70 | h.insert( names[j], (void *)(j+1) ); | ||
| 71 | printf("Capacity: %d, Size: %d, Load: %f\n", | ||
| 72 | h.getCapacity(), | ||
| 73 | h.getSize(), | ||
| 74 | h.getLoad() | ||
| 75 | ); | ||
| 76 | } | ||
| 77 | |||
| 78 | for( j = 0; j < 10; j++ ) | ||
| 79 | { | ||
| 80 | printf("\"%s\" = %d\n", names[j], (int)h[names[j]] ); | ||
| 81 | } | ||
| 82 | |||
| 83 | printf("\nDeleting some...\n"); | ||
| 84 | |||
| 85 | for( int k = 0; k < 7; k++ ) | ||
| 86 | { | ||
| 87 | h.del( names[k] ); | ||
| 88 | //h.insert( names[j], (void *)(j+1) ); | ||
| 89 | printf("Capacity: %d, Size: %d, Load: %f\n", | ||
| 90 | h.getCapacity(), | ||
| 91 | h.getSize(), | ||
| 92 | h.getLoad() | ||
| 93 | ); | ||
| 94 | } | ||
| 95 | |||
| 96 | printf("\nInserting more...\n"); | ||
| 97 | |||
| 98 | for( ; names[j] != NULL; j++ ) | ||
| 99 | { | ||
| 100 | h.insert( names[j], (void *)(j+1) ); | ||
| 101 | printf("Capacity: %d, Size: %d, Load: %f\n", | ||
| 102 | h.getCapacity(), | ||
| 103 | h.getSize(), | ||
| 104 | h.getLoad() | ||
| 105 | ); | ||
| 106 | } | ||
| 107 | } | ||
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 @@ | |||
| 1 | #include "httpconnectionmonitor.h" | ||
| 2 | #include "http.h" | ||
| 3 | #include <sys/stat.h> | ||
| 4 | |||
| 5 | HttpConnectionMonitor::HttpConnectionMonitor() | ||
| 6 | { | ||
| 7 | } | ||
| 8 | |||
| 9 | HttpConnectionMonitor::~HttpConnectionMonitor() | ||
| 10 | { | ||
| 11 | } | ||
| 12 | |||
| 13 | bool HttpConnectionMonitor::onNewConnection( Connection *pCon, int nPort ) | ||
| 14 | { | ||
| 15 | printf("Got connection on port %d\n", nPort ); | ||
| 16 | Http hp( pCon ); | ||
| 17 | |||
| 18 | pCon->readInput( 60, 0 ); | ||
| 19 | printf("#######################\n%s\n#######################\n", pCon->getInput() ); | ||
| 20 | |||
| 21 | while( hp.parseRequest() == false ); | ||
| 22 | printf("Done parsing.\n\n"); | ||
| 23 | |||
| 24 | if( hp.getRequestType() == Http::reqGet ) | ||
| 25 | { | ||
| 26 | printf("\"\"\"%s\"\"\"\n", hp.getRequestURI() ); | ||
| 27 | if( !strcmp( hp.getRequestURI(), "/" ) ) | ||
| 28 | { | ||
| 29 | 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>"); | ||
| 30 | hp.buildResponse(); | ||
| 31 | hp.setResponseContent( | ||
| 32 | "text/html", | ||
| 33 | content.c_str(), | ||
| 34 | content.size() | ||
| 35 | ); | ||
| 36 | hp.sendResponse(); | ||
| 37 | } | ||
| 38 | else | ||
| 39 | { | ||
| 40 | 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>"); | ||
| 41 | hp.buildResponse( 404, "File not found."); | ||
| 42 | hp.setResponseContent( | ||
| 43 | "text/html", | ||
| 44 | content.c_str(), | ||
| 45 | content.size() | ||
| 46 | ); | ||
| 47 | hp.sendResponse(); | ||
| 48 | } | ||
| 49 | } | ||
| 50 | else | ||
| 51 | { | ||
| 52 | printf("Non get: %s\n", hp.getRequestTypeStr() ); | ||
| 53 | pCon->appendOutput("HTTP/1.1 100 Continue\r\n\r\n"); | ||
| 54 | } | ||
| 55 | pCon->writeOutput(); | ||
| 56 | //for( int j = 0; j < 50; j++ ) | ||
| 57 | { | ||
| 58 | pCon->readInput( 1, 0 ); | ||
| 59 | //printf("Size so far: %d\n", pCon->getInputAmnt() ); | ||
| 60 | } | ||
| 61 | |||
| 62 | if( pCon->hasInput() ) | ||
| 63 | { | ||
| 64 | std::string s( pCon->getInput(), pCon->getInputAmnt() ); | ||
| 65 | |||
| 66 | pCon->printInputDebug(); | ||
| 67 | //printf("Reamining data\n==============\n%s\n==============\n", | ||
| 68 | // s.c_str() ); | ||
| 69 | } | ||
| 70 | |||
| 71 | pCon->disconnect(); | ||
| 72 | |||
| 73 | return true; | ||
| 74 | } | ||
| 75 | |||
| 76 | bool HttpConnectionMonitor::onClosedConnection( Connection *pCon ) | ||
| 77 | { | ||
| 78 | return true; | ||
| 79 | } | ||
| 80 | |||
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 @@ | |||
| 1 | #ifndef HTTPCONNECTIONMONITOR_H | ||
| 2 | #define HTTPCONNECTIONMONITOR_H | ||
| 3 | |||
| 4 | #include "connectionmonitor.h" | ||
| 5 | |||
| 6 | class HttpConnectionMonitor : public ConnectionMonitor | ||
| 7 | { | ||
| 8 | public: | ||
| 9 | HttpConnectionMonitor(); | ||
| 10 | ~HttpConnectionMonitor(); | ||
| 11 | |||
| 12 | bool onNewConnection( Connection *pCon, int nPort ); | ||
| 13 | bool onClosedConnection( Connection *pCon ); | ||
| 14 | }; | ||
| 15 | |||
| 16 | #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 @@ | |||
| 1 | #include "connectionmanager.h" | ||
| 2 | #include "httpconnectionmonitor.h" | ||
| 3 | |||
| 4 | int main() | ||
| 5 | { | ||
| 6 | printf("Starting server...\n"); | ||
| 7 | |||
| 8 | ConnectionManager srv; | ||
| 9 | HttpConnectionMonitor http; | ||
| 10 | |||
| 11 | srv.setConnectionMonitor( &http ); | ||
| 12 | |||
| 13 | printf("Listening on port 7331\n"); | ||
| 14 | srv.startServer( 7331 ); | ||
| 15 | |||
| 16 | for(;;) | ||
| 17 | { | ||
| 18 | srv.scanConnections( 5000, false ); | ||
| 19 | } | ||
| 20 | |||
| 21 | return 0; | ||
| 22 | } | ||
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 @@ | |||
| 1 | #include <stdio.h> | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <iostream> | ||
| 4 | #include "multilog.h" | ||
| 5 | #include "multilogtext.h" | ||
| 6 | |||
| 7 | class Test | ||
| 8 | { | ||
| 9 | public: | ||
| 10 | Test() | ||
| 11 | { | ||
| 12 | MultiLineLog( 4, "Test init'd\n"); | ||
| 13 | } | ||
| 14 | }; | ||
| 15 | |||
| 16 | int main() | ||
| 17 | { | ||
| 18 | MultiLog &xLog = MultiLog::getInstance(); | ||
| 19 | |||
| 20 | xLog.LineLog( 2, "Hello again"); | ||
| 21 | |||
| 22 | MultiLog::getInstance().addChannel( | ||
| 23 | new MultiLogText( STDOUT_FILENO, "%02y-%02m-%02d %02h:%02M:%02s: %t" ) | ||
| 24 | ); | ||
| 25 | |||
| 26 | MultiLineLog( MultiLog::LError, "Hi there!"); | ||
| 27 | Test t; | ||
| 28 | } | ||
| 29 | |||
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 @@ | |||
| 1 | #include <stdio.h> | ||
| 2 | #include <string.h> | ||
| 3 | #include "md5.h" | ||
| 4 | |||
| 5 | int main() | ||
| 6 | { | ||
| 7 | md5 mproc; | ||
| 8 | md5sum sum; | ||
| 9 | char hexstr[33]; | ||
| 10 | |||
| 11 | memset( hexstr, 0, 33 ); | ||
| 12 | |||
| 13 | mproc.sumString( &sum, "qwertyuiopasdfgh" ); | ||
| 14 | mproc.sumToHex( &sum, hexstr ); | ||
| 15 | printf("sum: %s\n", hexstr ); | ||
| 16 | printf("chk: 1ebfc043d8880b758b13ddc8aa1638ef\n"); | ||
| 17 | |||
| 18 | return 0; | ||
| 19 | } | ||
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 @@ | |||
| 1 | #include "param.h" | ||
| 2 | #include <stdio.h> | ||
| 3 | |||
| 4 | Param::Param() | ||
| 5 | { | ||
| 6 | addHelpBanner("param - A test of the libbu++ parameter systems\n" | ||
| 7 | "Enjoy with care and caution\n\nTest stuff:\n"); | ||
| 8 | addParam( "name", 's', mkproc( Param::printStuff ), &str, "Test a param param" ); | ||
| 9 | //addParam( "name", &str ); | ||
| 10 | addParam( "job", 'U', mkproc( Param::printStuff ), "Test a paramless param" ); | ||
| 11 | |||
| 12 | addHelpBanner("\nInformational:\n"); | ||
| 13 | addParam( "help", mkproc( ParamProc::help ), "Help!" ); | ||
| 14 | |||
| 15 | addHelpBanner("\nThanks for trying my test!\n\n"); | ||
| 16 | } | ||
| 17 | |||
| 18 | Param::~Param() | ||
| 19 | { | ||
| 20 | } | ||
| 21 | |||
| 22 | int Param::printStuff( int argc, char *argv[] ) | ||
| 23 | { | ||
| 24 | printf("------------%02d-------------\n", argc ); | ||
| 25 | for( int j = 0; j < argc; j++ ) | ||
| 26 | { | ||
| 27 | printf("%d: %s\n", j, argv[j] ); | ||
| 28 | } | ||
| 29 | printf("---------------------------\n" ); | ||
| 30 | printf("SETVAR===\"%s\"\n", str.c_str() ); | ||
| 31 | |||
| 32 | return 1; | ||
| 33 | } | ||
| 34 | |||
| 35 | int main( int argc, char *argv[] ) | ||
| 36 | { | ||
| 37 | if( argc == 1 ) | ||
| 38 | { | ||
| 39 | printf("You have to enter some parameter, try '--help'\n\n"); | ||
| 40 | return 0; | ||
| 41 | } | ||
| 42 | |||
| 43 | Param p; | ||
| 44 | p.process( argc, argv ); | ||
| 45 | } | ||
| 46 | |||
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 @@ | |||
| 1 | #ifndef PARAM_H | ||
| 2 | #define PARAM_H | ||
| 3 | |||
| 4 | #include <stdint.h> | ||
| 5 | |||
| 6 | #include "paramproc.h" | ||
| 7 | |||
| 8 | class Param : public ParamProc | ||
| 9 | { | ||
| 10 | public: | ||
| 11 | Param(); | ||
| 12 | virtual ~Param(); | ||
| 13 | |||
| 14 | private: | ||
| 15 | int printStuff( int argc, char *argv[] ); | ||
| 16 | |||
| 17 | std::string str; | ||
| 18 | uint32_t uint32; | ||
| 19 | }; | ||
| 20 | |||
| 21 | #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 @@ | |||
| 1 | #include "plugger.h" | ||
| 2 | #include "plugin.h" | ||
| 3 | |||
| 4 | int main() | ||
| 5 | { | ||
| 6 | Plugger<Plugin> p; | ||
| 7 | |||
| 8 | p.registerExternalPlugin( "./guy.so", "Guy" ); | ||
| 9 | |||
| 10 | Plugin *t = p.instantiate( "Guy" ); | ||
| 11 | |||
| 12 | p.destroy( t ); | ||
| 13 | } | ||
| 14 | |||
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 @@ | |||
| 1 | #include "plugin.h" | ||
| 2 | |||
| 3 | Plugin::Plugin() | ||
| 4 | { | ||
| 5 | } | ||
| 6 | |||
| 7 | Plugin::~Plugin() | ||
| 8 | { | ||
| 9 | } | ||
| 10 | |||
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 @@ | |||
| 1 | #ifndef PLUGIN_H | ||
| 2 | #define PLUGIN_H | ||
| 3 | |||
| 4 | class Plugin | ||
| 5 | { | ||
| 6 | public: | ||
| 7 | Plugin(); | ||
| 8 | virtual ~Plugin(); | ||
| 9 | |||
| 10 | private: | ||
| 11 | |||
| 12 | }; | ||
| 13 | |||
| 14 | #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 @@ | |||
| 1 | #include "serializerbinary.h" | ||
| 2 | #include "staticstring.h" | ||
| 3 | #include <stdio.h> | ||
| 4 | #include <string> | ||
| 5 | |||
| 6 | int main() | ||
| 7 | { | ||
| 8 | int32_t one; | ||
| 9 | double two; | ||
| 10 | bool three; | ||
| 11 | StaticString s("Test string!"); | ||
| 12 | std::string ss("Another test string"); | ||
| 13 | SerializerBinary ar("hello.dat", false); | ||
| 14 | ar << (int)85; | ||
| 15 | ar << (double)2.63434; | ||
| 16 | ar << false; | ||
| 17 | ar << ss; | ||
| 18 | ar.close(); | ||
| 19 | |||
| 20 | one = 0; two = 0; three = true; s = "die"; | ||
| 21 | |||
| 22 | SerializerBinary ar2("hello.dat", true); | ||
| 23 | ar2 >> one; | ||
| 24 | ar2 >> two; | ||
| 25 | ar2 >> three; | ||
| 26 | ar2 >> s; | ||
| 27 | |||
| 28 | printf("we got %d - %f - %s - \"%s\"\n", one, two, (three ? "true":"false"), s.getString() ); | ||
| 29 | return 0; | ||
| 30 | } | ||
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 @@ | |||
| 1 | #include "serializertext.h" | ||
| 2 | #include "staticstring.h" | ||
| 3 | #include <iostream> | ||
| 4 | |||
| 5 | int main() | ||
| 6 | { | ||
| 7 | StaticString s("You're a dog!!"); | ||
| 8 | SerializerText ar("hello.dat", false); | ||
| 9 | |||
| 10 | ar << 4 << 3.993 << true << s; | ||
| 11 | |||
| 12 | ar.close(); | ||
| 13 | |||
| 14 | int one=0;float two=0.0;bool three=false; s = ""; | ||
| 15 | |||
| 16 | SerializerText ar2("hello.dat", true); | ||
| 17 | |||
| 18 | ar2 >> one; | ||
| 19 | ar2 >> two; | ||
| 20 | ar2 >> three; | ||
| 21 | ar2 >> s; | ||
| 22 | |||
| 23 | //printf("out: %d, %f, %s, \"%s\"\n", one, two, (three ? "true" : "false"), s.getString()); | ||
| 24 | std::cout << one << ", " << two << ", " << three << ", " << s.getString() << "\n"; | ||
| 25 | |||
| 26 | return 0; | ||
| 27 | } | ||
| 28 | |||
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 @@ | |||
| 1 | #include "connectionmanager.h" | ||
| 2 | #include "programlink.h" | ||
| 3 | #include "linkedlist.h" | ||
| 4 | #include "protocol.h" | ||
| 5 | |||
| 6 | class StressProtocol : public Protocol | ||
| 7 | { | ||
| 8 | public: | ||
| 9 | bool onNewData() | ||
| 10 | { | ||
| 11 | switch( getConnection()->getInput()[0] ) | ||
| 12 | { | ||
| 13 | case 'd': | ||
| 14 | throw "Hello"; | ||
| 15 | break; | ||
| 16 | |||
| 17 | case 'w': | ||
| 18 | getConnection()->appendOutput("Hello"); | ||
| 19 | break; | ||
| 20 | }; | ||
| 21 | |||
| 22 | return true; | ||
| 23 | } | ||
| 24 | |||
| 25 | bool onNewConnection() | ||
| 26 | { | ||
| 27 | return true; | ||
| 28 | } | ||
| 29 | }; | ||
| 30 | |||
| 31 | class StressMonitor : public ConnectionMonitor, public ProgramLink | ||
| 32 | { | ||
| 33 | public: | ||
| 34 | bool init() | ||
| 35 | { | ||
| 36 | return true; | ||
| 37 | } | ||
| 38 | |||
| 39 | bool deInit() | ||
| 40 | { | ||
| 41 | return true; | ||
| 42 | } | ||
| 43 | |||
| 44 | bool timeSlice() | ||
| 45 | { | ||
| 46 | } | ||
| 47 | |||
| 48 | bool onNewConnection( Connection *pCon, int nPort ) | ||
| 49 | { | ||
| 50 | StressProtocol *sp = new StressProtocol(); | ||
| 51 | pCon->setProtocol( sp ); | ||
| 52 | |||
| 53 | printf(" sys: New connection: socket(%d), port(%d)\n", | ||
| 54 | pCon->getSocket(), nPort ); | ||
| 55 | |||
| 56 | return true; | ||
| 57 | } | ||
| 58 | |||
| 59 | bool onClosedConnection( Connection *pCon ) | ||
| 60 | { | ||
| 61 | printf(" sys: Closed connection: socket(%d)\n", | ||
| 62 | pCon->getSocket() ); | ||
| 63 | |||
| 64 | return true; | ||
| 65 | } | ||
| 66 | |||
| 67 | LinkMessage *processIRM( LinkMessage *pMsg ) | ||
| 68 | { | ||
| 69 | return NULL; | ||
| 70 | } | ||
| 71 | }; | ||
| 72 | |||
| 73 | int main() | ||
| 74 | { | ||
| 75 | printf("Starting server...\n"); | ||
| 76 | |||
| 77 | ConnectionManager srv; | ||
| 78 | StressMonitor telnet; | ||
| 79 | |||
| 80 | srv.setConnectionMonitor( &telnet ); | ||
| 81 | |||
| 82 | srv.startServer( 4001 ); | ||
| 83 | |||
| 84 | for(;;) | ||
| 85 | { | ||
| 86 | srv.scanConnections( 5000, false ); | ||
| 87 | } | ||
| 88 | |||
| 89 | return 0; | ||
| 90 | } | ||
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 @@ | |||
| 1 | #include <stdio.h> | ||
| 2 | #include "hashfunctionstring.h" | ||
| 3 | |||
| 4 | int main( int argc, char *argv[] ) | ||
| 5 | { | ||
| 6 | HashFunctionString h; | ||
| 7 | |||
| 8 | printf("\"%s\": %d\n", argv[1], h.hash( argv[1] ) ); | ||
| 9 | |||
| 10 | return 0; | ||
| 11 | } | ||
| 12 | |||
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 @@ | |||
| 1 | #include "connectionmanager.h" | ||
| 2 | #include "telnetmonitor.h" | ||
| 3 | |||
| 4 | int main() | ||
| 5 | { | ||
| 6 | printf("Starting server...\n"); | ||
| 7 | |||
| 8 | ConnectionManager srv; | ||
| 9 | TelnetMonitor telnet; | ||
| 10 | |||
| 11 | srv.setConnectionMonitor( &telnet ); | ||
| 12 | |||
| 13 | srv.startServer( 4001 ); | ||
| 14 | |||
| 15 | for(;;) | ||
| 16 | { | ||
| 17 | srv.scanConnections( 5000, false ); | ||
| 18 | } | ||
| 19 | |||
| 20 | return 0; | ||
| 21 | } | ||
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 @@ | |||
| 1 | #include "telnetmonitor.h" | ||
| 2 | #include "protocoltelnet.h" | ||
| 3 | #include <sys/stat.h> | ||
| 4 | |||
| 5 | TelnetMonitor::TelnetMonitor() | ||
| 6 | { | ||
| 7 | } | ||
| 8 | |||
| 9 | TelnetMonitor::~TelnetMonitor() | ||
| 10 | { | ||
| 11 | } | ||
| 12 | |||
| 13 | bool TelnetMonitor::init() | ||
| 14 | { | ||
| 15 | return true; | ||
| 16 | } | ||
| 17 | |||
| 18 | bool TelnetMonitor::deInit() | ||
| 19 | { | ||
| 20 | return true; | ||
| 21 | } | ||
| 22 | |||
| 23 | bool TelnetMonitor::timeSlice() | ||
| 24 | { | ||
| 25 | for( int j = 0; j < lCon.getSize(); j++ ) | ||
| 26 | { | ||
| 27 | if( ((Connection *)lCon[j])->hasInput() ) | ||
| 28 | { | ||
| 29 | printf("%s\n", ((Connection *)lCon[j])->getInput() ); | ||
| 30 | } | ||
| 31 | } | ||
| 32 | return true; | ||
| 33 | } | ||
| 34 | |||
| 35 | LinkMessage* TelnetMonitor::processIRM( LinkMessage *pMsg ) | ||
| 36 | { | ||
| 37 | } | ||
| 38 | |||
| 39 | bool TelnetMonitor::onNewConnection( Connection *pCon, int nPort ) | ||
| 40 | { | ||
| 41 | ProtocolTelnet *pt = new ProtocolTelnet(); | ||
| 42 | pCon->setProtocol( pt ); | ||
| 43 | |||
| 44 | lCon.append( pt ); | ||
| 45 | |||
| 46 | return true; | ||
| 47 | } | ||
| 48 | |||
| 49 | bool TelnetMonitor::onClosedConnection( Connection *pCon ) | ||
| 50 | { | ||
| 51 | return true; | ||
| 52 | } | ||
| 53 | |||
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 @@ | |||
| 1 | #ifndef HTTPCONNECTIONMONITOR_H | ||
| 2 | #define HTTPCONNECTIONMONITOR_H | ||
| 3 | |||
| 4 | #include "connectionmonitor.h" | ||
| 5 | #include "programlink.h" | ||
| 6 | #include "linkedlist.h" | ||
| 7 | |||
| 8 | class TelnetMonitor : public ConnectionMonitor, public ProgramLink | ||
| 9 | { | ||
| 10 | public: | ||
| 11 | TelnetMonitor(); | ||
| 12 | ~TelnetMonitor(); | ||
| 13 | |||
| 14 | bool init(); | ||
| 15 | bool deInit(); | ||
| 16 | bool timeSlice(); | ||
| 17 | LinkMessage* processIRM( LinkMessage *pMsgIn ); | ||
| 18 | |||
| 19 | bool onNewConnection( Connection *pCon, int nPort ); | ||
| 20 | bool onClosedConnection( Connection *pCon ); | ||
| 21 | |||
| 22 | private: | ||
| 23 | LinkedList lCon; | ||
| 24 | }; | ||
| 25 | |||
| 26 | #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 @@ | |||
| 1 | #include "xmlfilereader.h" | ||
| 2 | #include "xmlstringreader.h" | ||
| 3 | #include "xmlfilewriter.h" | ||
| 4 | |||
| 5 | int main( int argc, char *argv[] ) | ||
| 6 | { | ||
| 7 | if( argc < 4 ) | ||
| 8 | { | ||
| 9 | printf("Usage: %s f <file in> <file out>\n", argv[0] ); | ||
| 10 | printf(" %s s <xml string> <file out>\n\n", argv[0] ); | ||
| 11 | return 0; | ||
| 12 | } | ||
| 13 | |||
| 14 | if( argv[1][0] == 'f' ) | ||
| 15 | { | ||
| 16 | XmlFileReader r( argv[2], true ); | ||
| 17 | // XmlFileWriter w( argv[3], "\t", r.detatchRoot() ); | ||
| 18 | // w.write(); | ||
| 19 | } | ||
| 20 | else if( argv[1][0] == 's' ) | ||
| 21 | { | ||
| 22 | XmlStringReader r( argv[2], true ); | ||
| 23 | // XmlWriter w( argv[3], "\t", r.detatchRoot() ); | ||
| 24 | // w.write(); | ||
| 25 | } | ||
| 26 | |||
| 27 | return 0; | ||
| 28 | } | ||
| 29 | |||
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 @@ | |||
| 1 | #include "xmlwriter.h" | ||
| 2 | |||
| 3 | int main() | ||
| 4 | { | ||
| 5 | printf("Testing Xml Replacement...\n"); | ||
| 6 | XmlDocument w; | ||
| 7 | |||
| 8 | w.addNode("text"); | ||
| 9 | w.setContent("this text is before the node. "); | ||
| 10 | w.addNode("keepme", "This one we keep...", true ); | ||
| 11 | w.setContent("this text is after."); | ||
| 12 | w.addNode("deleteme", "This one we don't...", true ); | ||
| 13 | w.setContent("this is last..." ); | ||
| 14 | w.closeNode(); | ||
| 15 | |||
| 16 | //XmlWriter::writeNode( stdout, w.getRoot(), 0, NULL ); | ||
| 17 | |||
| 18 | printf("\n\n"); | ||
| 19 | |||
| 20 | XmlNode *xNode = w.getRoot()->detatchNode( 1 ); | ||
| 21 | |||
| 22 | //XmlWriter::writeNode( stdout, w.getRoot(), 0, NULL ); | ||
| 23 | |||
| 24 | printf("\n\n"); | ||
| 25 | |||
| 26 | //XmlWriter::writeNode( stdout, xNode, 0, NULL ); | ||
| 27 | |||
| 28 | printf("\n\n"); | ||
| 29 | |||
| 30 | return 0; | ||
| 31 | } | ||
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 @@ | |||
| 1 | #include "xmlfilewriter.h" | ||
| 2 | #include "xmlstringwriter.h" | ||
| 3 | #include "xmlstringreader.h" | ||
| 4 | |||
| 5 | void fillItIn( XmlWriter &w ) | ||
| 6 | { | ||
| 7 | w.addNode("thinglist"); | ||
| 8 | |||
| 9 | w.addNode("thing"); | ||
| 10 | w.addProperty("type", "Weapon"); | ||
| 11 | |||
| 12 | w.addNode("id", "Klophin Staff", true ); | ||
| 13 | w.addNode("name", "Klophin Staff", true ); | ||
| 14 | w.addNode("durability", "0.01", true ); | ||
| 15 | w.addNode("size", "0.1", true ); | ||
| 16 | |||
| 17 | w.addNode("config"); | ||
| 18 | w.addNode("damage", "3d6+4", true ); | ||
| 19 | w.addNode("class", "melee", true ); | ||
| 20 | w.addNode("type", "bludgeon", true ); | ||
| 21 | w.addNode("damagedesc", "club/clubs", true ); | ||
| 22 | w.closeNode(); | ||
| 23 | |||
| 24 | w.closeNode(); | ||
| 25 | |||
| 26 | w.closeNode(); | ||
| 27 | } | ||
| 28 | |||
| 29 | int main() | ||
| 30 | { | ||
| 31 | printf("Testing XmlWriter...\n"); | ||
| 32 | |||
| 33 | //XmlStringReader *xsr = new XmlStringReader("<stuff/>"); | ||
| 34 | |||
| 35 | //printf("%08X\n%08X\n%08X\n", xsr, (XmlReader *)xsr, (XmlDocument *)xsr ); | ||
| 36 | |||
| 37 | //delete (XmlDocument *)xsr; | ||
| 38 | XmlFileWriter wf("test.xml", "\t"); | ||
| 39 | |||
| 40 | fillItIn( wf ); | ||
| 41 | |||
| 42 | XmlStringWriter ws("\t"); | ||
| 43 | fillItIn( ws ); | ||
| 44 | |||
| 45 | printf("Now the string version:\n\n%s\n", ws.getString().c_str() ); | ||
| 46 | |||
| 47 | return 0; | ||
| 48 | } | ||
