From f4c20290509d7ed3a8fd5304577e7a4cc0b9d974 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 3 Apr 2007 03:49:53 +0000 Subject: Ok, no code is left in src, it's all in src/old. We'll gradually move code back into src as it's fixed and re-org'd. This includes tests, which, I may write a unit test system into libbu++ just to make my life easier. --- src/old/tests/clistress.cpp | 20 +++ src/old/tests/confpair.cpp | 19 ++ src/old/tests/connect.cpp | 38 ++++ src/old/tests/exception.cpp | 16 ++ src/old/tests/formula.cpp | 13 ++ src/old/tests/fstring.cpp | 48 +++++ src/old/tests/hash.cpp | 116 ++++++++++++ src/old/tests/hashtest.cpp | 107 +++++++++++ src/old/tests/hashtest2.cpp | 15 ++ src/old/tests/httpsrv/httpconnectionmonitor.cpp | 88 +++++++++ src/old/tests/httpsrv/httpconnectionmonitor.h | 16 ++ src/old/tests/httpsrv/main.cpp | 22 +++ src/old/tests/log.cpp | 29 +++ src/old/tests/md5test.cpp | 19 ++ src/old/tests/ordhash.cpp | 48 +++++ src/old/tests/param.cpp | 46 +++++ src/old/tests/param.h | 21 +++ src/old/tests/plugin/main.cpp | 14 ++ src/old/tests/plugin/plugin.cpp | 10 ++ src/old/tests/plugin/plugin.h | 14 ++ src/old/tests/qsort.cpp | 228 ++++++++++++++++++++++++ src/old/tests/sbuffer.cpp | 27 +++ src/old/tests/serialize.cpp | 30 ++++ src/old/tests/serializetext.cpp | 28 +++ src/old/tests/sha1.cpp | 44 +++++ src/old/tests/sptr.cpp | 55 ++++++ src/old/tests/srvstress.cpp | 91 ++++++++++ src/old/tests/strhash.cpp | 12 ++ src/old/tests/teltest/main.cpp | 21 +++ src/old/tests/teltest/telnetmonitor.cpp | 54 ++++++ src/old/tests/teltest/telnetmonitor.h | 26 +++ src/old/tests/xmlreadtest.cpp | 29 +++ src/old/tests/xmlrepltest.cpp | 31 ++++ src/old/tests/xmlwritetest.cpp | 48 +++++ 34 files changed, 1443 insertions(+) create mode 100644 src/old/tests/clistress.cpp create mode 100644 src/old/tests/confpair.cpp create mode 100644 src/old/tests/connect.cpp create mode 100644 src/old/tests/exception.cpp create mode 100644 src/old/tests/formula.cpp create mode 100644 src/old/tests/fstring.cpp create mode 100644 src/old/tests/hash.cpp create mode 100644 src/old/tests/hashtest.cpp create mode 100644 src/old/tests/hashtest2.cpp create mode 100644 src/old/tests/httpsrv/httpconnectionmonitor.cpp create mode 100644 src/old/tests/httpsrv/httpconnectionmonitor.h create mode 100644 src/old/tests/httpsrv/main.cpp create mode 100644 src/old/tests/log.cpp create mode 100644 src/old/tests/md5test.cpp create mode 100644 src/old/tests/ordhash.cpp create mode 100644 src/old/tests/param.cpp create mode 100644 src/old/tests/param.h create mode 100644 src/old/tests/plugin/main.cpp create mode 100644 src/old/tests/plugin/plugin.cpp create mode 100644 src/old/tests/plugin/plugin.h create mode 100644 src/old/tests/qsort.cpp create mode 100644 src/old/tests/sbuffer.cpp create mode 100644 src/old/tests/serialize.cpp create mode 100644 src/old/tests/serializetext.cpp create mode 100644 src/old/tests/sha1.cpp create mode 100644 src/old/tests/sptr.cpp create mode 100644 src/old/tests/srvstress.cpp create mode 100644 src/old/tests/strhash.cpp create mode 100644 src/old/tests/teltest/main.cpp create mode 100644 src/old/tests/teltest/telnetmonitor.cpp create mode 100644 src/old/tests/teltest/telnetmonitor.h create mode 100644 src/old/tests/xmlreadtest.cpp create mode 100644 src/old/tests/xmlrepltest.cpp create mode 100644 src/old/tests/xmlwritetest.cpp (limited to 'src/old/tests') diff --git a/src/old/tests/clistress.cpp b/src/old/tests/clistress.cpp new file mode 100644 index 0000000..6b0ac66 --- /dev/null +++ b/src/old/tests/clistress.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/old/tests/confpair.cpp b/src/old/tests/confpair.cpp new file mode 100644 index 0000000..fb1b0d3 --- /dev/null +++ b/src/old/tests/confpair.cpp @@ -0,0 +1,19 @@ +#include "confpair.h" +#include + +using namespace std; + +int main() +{ + ConfPair p1("DebugMode"); + p1.value() = 12; + cout << p1.value() << "\n"; + p1.value() = 55; + cout << p1.value() << "\n"; + + ConfPairBase &p = p1; + + p = "33.12"; + cout << p.getAsString(); +} + diff --git a/src/old/tests/connect.cpp b/src/old/tests/connect.cpp new file mode 100644 index 0000000..a9fca64 --- /dev/null +++ b/src/old/tests/connect.cpp @@ -0,0 +1,38 @@ +#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/old/tests/exception.cpp b/src/old/tests/exception.cpp new file mode 100644 index 0000000..6417692 --- /dev/null +++ b/src/old/tests/exception.cpp @@ -0,0 +1,16 @@ +#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/old/tests/formula.cpp b/src/old/tests/formula.cpp new file mode 100644 index 0000000..976b039 --- /dev/null +++ b/src/old/tests/formula.cpp @@ -0,0 +1,13 @@ +#include "formula.h" + +int main( int argc, char *argv[] ) +{ + if( argc < 2 ) return 0; + + Formula f; + double dOut = f.run( argv[1] ); + printf("%s = %f\n", argv[1], dOut ); + + return 0; +} + diff --git a/src/old/tests/fstring.cpp b/src/old/tests/fstring.cpp new file mode 100644 index 0000000..271738c --- /dev/null +++ b/src/old/tests/fstring.cpp @@ -0,0 +1,48 @@ +#include "hash.h" +#include "fstring.h" + +FString genThing() +{ + FString bob; + bob.append("ab "); + bob += "cd "; + bob += "efg"; + + printf("---bob------\n%08X: %s\n", (unsigned int)bob.c_str(), bob.c_str() ); + return bob; +} + +void thing( FString str ) +{ + printf("Hey: %s\n", str.c_str() ); +} + +#define pem printf("---------\n%08X: %s\n%08X: %s\n", (unsigned int)str.c_str(), str.c_str(), (unsigned int)str2.c_str(), str2.c_str() ); +int main( int argc, char *argv ) +{ + FString str("th"); + + str.prepend("Hello "); + str.append("ere."); + + FString str2( str ); + pem; + str += " What's up?"; + pem; + str2 += " How are you?"; + pem; + str = str2; + pem; + + str2 = genThing(); + pem; + + str = str2; + pem; + + thing( str2 ); + thing("test."); + + printf("%d == %d\n", __calcHashCode( str ), __calcHashCode( str.c_str() ) ); +} + diff --git a/src/old/tests/hash.cpp b/src/old/tests/hash.cpp new file mode 100644 index 0000000..2fc6968 --- /dev/null +++ b/src/old/tests/hash.cpp @@ -0,0 +1,116 @@ +#include "hash.h" +#include "staticstring.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 + }; + + Hash sTest; + + printf("Inserting\n-------------------\n\n"); + for( int j = 0; j < 33; j++ ) + { + sTest[names[j]] = j; + } + + printf("Test1: %d, Test2: %d\n", sTest.has("Lemon of Troy"), sTest.has(std::string("Lemon of Troy").c_str() ) ); + + sTest.has(std::string("Lemon of Troy").c_str() ); + + printf("Getting\n-------------------\n\n"); + + sTest.erase("Homer the Great"); + sTest["Bart's Comet"].erase(); + + for( Hash::iterator i = sTest.begin(); + i != sTest.end(); i++ ) + { + Hash::iterator j = i; + printf("%d: %s\n", (*j).second, (*j).first ); + } + + printf("Testing\n-------------------\n\n"); + for( int j = 0; j < 33; j++ ) + { + if( sTest.has(names[j]) ) + { + if( sTest[names[j]] != j ) + { + printf("'%s' should be %d, is %d\n", + names[j], j, + sTest[names[j]].value() + ); + } + } + else + { + printf("Missing element %d, '%s'\n", j, names[j] ); + } + } + + printf("Clearing\n-------------------\n\n"); + + sTest.clear(); + + for( Hash::iterator i = sTest.begin(); + i != sTest.end(); i++ ) + { + Hash::iterator j = i; + printf("%d: %s\n", (*j).second, (*j).first ); + } + +} + diff --git a/src/old/tests/hashtest.cpp b/src/old/tests/hashtest.cpp new file mode 100644 index 0000000..eaa84a0 --- /dev/null +++ b/src/old/tests/hashtest.cpp @@ -0,0 +1,107 @@ +#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: %lu, Size: %lu, 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: %lu, Size: %lu, 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: %lu, Size: %lu, Load: %f\n", + h.getCapacity(), + h.getSize(), + h.getLoad() + ); + } +} diff --git a/src/old/tests/hashtest2.cpp b/src/old/tests/hashtest2.cpp new file mode 100644 index 0000000..74700fd --- /dev/null +++ b/src/old/tests/hashtest2.cpp @@ -0,0 +1,15 @@ +#include "hash.h" +#include + +int main() +{ + char *a, *b; + a = new char[10]; + b = new char[10]; + strcpy( a, "Hey there"); + strcpy( b, "Hey there"); + printf("Same: %s\n", __cmpHashKeys( a, b )?"yes":"no"); + + return 0; +} + diff --git a/src/old/tests/httpsrv/httpconnectionmonitor.cpp b/src/old/tests/httpsrv/httpconnectionmonitor.cpp new file mode 100644 index 0000000..51d82f3 --- /dev/null +++ b/src/old/tests/httpsrv/httpconnectionmonitor.cpp @@ -0,0 +1,88 @@ +#include "httpconnectionmonitor.h" +#include "http.h" +#include "exceptions.h" +#include + +HttpConnectionMonitor::HttpConnectionMonitor() +{ +} + +HttpConnectionMonitor::~HttpConnectionMonitor() +{ +} + +bool HttpConnectionMonitor::onNewConnection( Connection *pCon, int nPort ) +{ + printf("Got connection on port %d\n", nPort ); + + try + { + pCon->readInput( 60, 0 ); + printf("#######################\n%s\n#######################\n", pCon->getInput() ); + + Http hp( pCon ); + 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(); + } + catch( ConnectionException &e ) + { + printf("Connection: %s\n", e.what() ); + } + + return true; +} + +bool HttpConnectionMonitor::onClosedConnection( Connection *pCon ) +{ + return true; +} + diff --git a/src/old/tests/httpsrv/httpconnectionmonitor.h b/src/old/tests/httpsrv/httpconnectionmonitor.h new file mode 100644 index 0000000..30c0afd --- /dev/null +++ b/src/old/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/old/tests/httpsrv/main.cpp b/src/old/tests/httpsrv/main.cpp new file mode 100644 index 0000000..2f1563c --- /dev/null +++ b/src/old/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/old/tests/log.cpp b/src/old/tests/log.cpp new file mode 100644 index 0000000..d7cfa0b --- /dev/null +++ b/src/old/tests/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/old/tests/md5test.cpp b/src/old/tests/md5test.cpp new file mode 100644 index 0000000..6f832df --- /dev/null +++ b/src/old/tests/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/old/tests/ordhash.cpp b/src/old/tests/ordhash.cpp new file mode 100644 index 0000000..f1d96ec --- /dev/null +++ b/src/old/tests/ordhash.cpp @@ -0,0 +1,48 @@ +#include "ordhash.h" +#include <string> + +typedef struct eldef +{ + eldef( int a, int b, const std::string &c ) : + id( a ), nSequence( b ), sName( c ) {} + int id; + int nSequence; + std::string sName; +} eldef; + +struct seqcmp +{ + bool operator()( eldef **a, eldef **b ) + { + return (*a)->nSequence < (*b)->nSequence; + } +}; + +struct namcmp +{ + bool operator()( eldef **a, eldef **b ) + { + return (*a)->sName < (*b)->sName; + } +}; + +typedef OrdHash<int, eldef, seqcmp> AHash; +//typedef OrdHash<int, eldef, namcmp> AHash; + +int main() +{ + AHash hsh; + hsh[1] = eldef( 0, 43, "Bob"); + hsh[4] = eldef( 1, 443, "Abby"); + hsh[2] = eldef( 2, 1, "Name"); + hsh[5] = eldef( 3, 0, "Catagory"); + hsh[32] = eldef( 4, 12, "Epilogue"); + + for( AHash::iterator i = hsh.begin(); i != hsh.end(); i++ ) + { + eldef e = (*i).second; + printf("%d, %d, %s\n", e.id, e.nSequence, e.sName.c_str() ); + } + +} + diff --git a/src/old/tests/param.cpp b/src/old/tests/param.cpp new file mode 100644 index 0000000..a4d2824 --- /dev/null +++ b/src/old/tests/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/old/tests/param.h b/src/old/tests/param.h new file mode 100644 index 0000000..2756b69 --- /dev/null +++ b/src/old/tests/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/old/tests/plugin/main.cpp b/src/old/tests/plugin/main.cpp new file mode 100644 index 0000000..51c8390 --- /dev/null +++ b/src/old/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/old/tests/plugin/plugin.cpp b/src/old/tests/plugin/plugin.cpp new file mode 100644 index 0000000..ea558fd --- /dev/null +++ b/src/old/tests/plugin/plugin.cpp @@ -0,0 +1,10 @@ +#include "plugin.h" + +Plugin::Plugin() +{ +} + +Plugin::~Plugin() +{ +} + diff --git a/src/old/tests/plugin/plugin.h b/src/old/tests/plugin/plugin.h new file mode 100644 index 0000000..f726867 --- /dev/null +++ b/src/old/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/old/tests/qsort.cpp b/src/old/tests/qsort.cpp new file mode 100644 index 0000000..28c6f03 --- /dev/null +++ b/src/old/tests/qsort.cpp @@ -0,0 +1,228 @@ +#define _QSORT_SWAP(a, b, t) ((void)((t = *a), (*a = *b), (*b = t))) + +/* Discontinue quicksort algorithm when partition gets below this size. + This particular magic number was chosen to work best on a Sun 4/260. */ +#define _QSORT_MAX_THRESH 4 + +/* Stack node declarations used to store unfulfilled partition obligations + * (inlined in QSORT). +typedef struct { + QSORT_TYPE *_lo, *_hi; +} qsort_stack_node; + */ + +/* The next 4 #defines implement a very fast in-line stack abstraction. */ +/* The stack needs log (total_elements) entries (we could even subtract + log(MAX_THRESH)). Since total_elements has type unsigned, we get as + upper bound for log (total_elements): + bits per byte (CHAR_BIT) * sizeof(unsigned). */ +#define _QSORT_STACK_SIZE (8 * sizeof(unsigned)) +#define _QSORT_PUSH(top, low, high) \ + (((top->_lo = (low)), (top->_hi = (high)), ++top)) +#define _QSORT_POP(low, high, top) \ + ((--top, (low = top->_lo), (high = top->_hi))) +#define _QSORT_STACK_NOT_EMPTY (_stack < _top) + + +/* Order size using quicksort. This implementation incorporates + four optimizations discussed in Sedgewick: + + 1. Non-recursive, using an explicit stack of pointer that store the + next array partition to sort. To save time, this maximum amount + of space required to store an array of SIZE_MAX is allocated on the + stack. Assuming a 32-bit (64 bit) integer for size_t, this needs + only 32 * sizeof(stack_node) == 256 bytes (for 64 bit: 1024 bytes). + Pretty cheap, actually. + + 2. Chose the pivot element using a median-of-three decision tree. + This reduces the probability of selecting a bad pivot value and + eliminates certain extraneous comparisons. + + 3. Only quicksorts TOTAL_ELEMS / MAX_THRESH partitions, leaving + insertion sort to order the MAX_THRESH items within each partition. + This is a big win, since insertion sort is faster for small, mostly + sorted array segments. + + 4. The larger of the two sub-partitions is always pushed onto the + stack first, with the algorithm then concentrating on the + smaller partition. This *guarantees* no more than log (total_elems) + stack size is needed (actually O(1) in this case)! */ + +/* The main code starts here... */ + +template<typename QSORT_TYPE, typename QSORT_LTT> +void qsrt( QSORT_TYPE *QSORT_BASE, int QSORT_NELT ) +{ + QSORT_LTT QSORT_LT; + QSORT_TYPE *const _base = (QSORT_BASE); + const unsigned _elems = (QSORT_NELT); + QSORT_TYPE _hold; + + /* Don't declare two variables of type QSORT_TYPE in a single + * statement: eg `TYPE a, b;', in case if TYPE is a pointer, + * expands to `type* a, b;' wich isn't what we want. + */ + + if (_elems > _QSORT_MAX_THRESH) { + QSORT_TYPE *_lo = _base; + QSORT_TYPE *_hi = _lo + _elems - 1; + struct { + QSORT_TYPE *_hi; QSORT_TYPE *_lo; + } _stack[_QSORT_STACK_SIZE], *_top = _stack + 1; + + while (_QSORT_STACK_NOT_EMPTY) { + QSORT_TYPE *_left_ptr; QSORT_TYPE *_right_ptr; + + /* Select median value from among LO, MID, and HI. Rearrange + LO and HI so the three values are sorted. This lowers the + probability of picking a pathological pivot value and + skips a comparison for both the LEFT_PTR and RIGHT_PTR in + the while loops. */ + + QSORT_TYPE *_mid = _lo + ((_hi - _lo) >> 1); + + if (QSORT_LT (_mid, _lo)) + _QSORT_SWAP (_mid, _lo, _hold); + if (QSORT_LT (_hi, _mid)) + _QSORT_SWAP (_mid, _hi, _hold); + else + goto _jump_over; + if (QSORT_LT (_mid, _lo)) + _QSORT_SWAP (_mid, _lo, _hold); + _jump_over:; + + _left_ptr = _lo + 1; + _right_ptr = _hi - 1; + + /* Here's the famous ``collapse the walls'' section of quicksort. + Gotta like those tight inner loops! They are the main reason + that this algorithm runs much faster than others. */ + do { + while (QSORT_LT (_left_ptr, _mid)) + ++_left_ptr; + + while (QSORT_LT (_mid, _right_ptr)) + --_right_ptr; + + if (_left_ptr < _right_ptr) { + _QSORT_SWAP (_left_ptr, _right_ptr, _hold); + if (_mid == _left_ptr) + _mid = _right_ptr; + else if (_mid == _right_ptr) + _mid = _left_ptr; + ++_left_ptr; + --_right_ptr; + } + else if (_left_ptr == _right_ptr) { + ++_left_ptr; + --_right_ptr; + break; + } + } while (_left_ptr <= _right_ptr); + + /* Set up pointers for next iteration. First determine whether + left and right partitions are below the threshold size. If so, + ignore one or both. Otherwise, push the larger partition's + bounds on the stack and continue sorting the smaller one. */ + + if (_right_ptr - _lo <= _QSORT_MAX_THRESH) { + if (_hi - _left_ptr <= _QSORT_MAX_THRESH) + /* Ignore both small partitions. */ + _QSORT_POP (_lo, _hi, _top); + else + /* Ignore small left partition. */ + _lo = _left_ptr; + } + else if (_hi - _left_ptr <= _QSORT_MAX_THRESH) + /* Ignore small right partition. */ + _hi = _right_ptr; + else if (_right_ptr - _lo > _hi - _left_ptr) { + /* Push larger left partition indices. */ + _QSORT_PUSH (_top, _lo, _right_ptr); + _lo = _left_ptr; + } + else { + /* Push larger right partition indices. */ + _QSORT_PUSH (_top, _left_ptr, _hi); + _hi = _right_ptr; + } + } + } + + /* Once the BASE array is partially sorted by quicksort the rest + is completely sorted using insertion sort, since this is efficient + for partitions below MAX_THRESH size. BASE points to the + beginning of the array to sort, and END_PTR points at the very + last element in the array (*not* one beyond it!). */ + + { + QSORT_TYPE *const _end_ptr = _base + _elems - 1; + QSORT_TYPE *_tmp_ptr = _base; + register QSORT_TYPE *_run_ptr; + QSORT_TYPE *_thresh; + + _thresh = _base + _QSORT_MAX_THRESH; + if (_thresh > _end_ptr) + _thresh = _end_ptr; + + /* Find smallest element in first threshold and place it at the + array's beginning. This is the smallest array element, + and the operation speeds up insertion sort's inner loop. */ + + for (_run_ptr = _tmp_ptr + 1; _run_ptr <= _thresh; ++_run_ptr) + if (QSORT_LT (_run_ptr, _tmp_ptr)) + _tmp_ptr = _run_ptr; + + if (_tmp_ptr != _base) + _QSORT_SWAP (_tmp_ptr, _base, _hold); + + /* Insertion sort, running from left-hand-side + * up to right-hand-side. */ + + _run_ptr = _base + 1; + while (++_run_ptr <= _end_ptr) { + _tmp_ptr = _run_ptr - 1; + while (QSORT_LT (_run_ptr, _tmp_ptr)) + --_tmp_ptr; + + ++_tmp_ptr; + if (_tmp_ptr != _run_ptr) { + QSORT_TYPE *_trav = _run_ptr + 1; + while (--_trav >= _run_ptr) { + QSORT_TYPE *_hi; QSORT_TYPE *_lo; + _hold = *_trav; + + for (_hi = _lo = _trav; --_lo >= _tmp_ptr; _hi = _lo) + *_hi = *_lo; + *_hi = _hold; + } + } + } + } + +} + + +struct cc +{ + bool operator()( int *a, int *b ) + { + return *a < *b; + } +}; + +#include <stdio.h> + +int main() +{ + int lst[] = { 43, 1, 342, 12, 491, 32, 12321, 32, 3, -3 }; + + for( int j = 0; j < 10; j++ ) + printf("%s%d", (j>0)?", ":"", lst[j] ); + printf("\n"); + qsrt<int, cc>( lst, 10 ); + for( int j = 0; j < 10; j++ ) + printf("%s%d", (j>0)?", ":"", lst[j] ); + printf("\n"); +} + diff --git a/src/old/tests/sbuffer.cpp b/src/old/tests/sbuffer.cpp new file mode 100644 index 0000000..02798cb --- /dev/null +++ b/src/old/tests/sbuffer.cpp @@ -0,0 +1,27 @@ +#include "sbuffer.h" + +int main() +{ + SBuffer buf; + + buf.write("abcdefg", 7 ); + + printf("tell: %ld\n", buf.tell() ); + + char abuf[6]; + int nRead; + nRead = buf.read( abuf, 5 ); + abuf[nRead] = '\0'; + printf("Read %d bytes \"%s\"\n", nRead, abuf ); + + buf.setPos( 0 ); + nRead = buf.read( abuf, 5 ); + abuf[nRead] = '\0'; + printf("Read %d bytes \"%s\"\n", nRead, abuf ); + + nRead = buf.read( abuf, 5 ); + abuf[nRead] = '\0'; + printf("Read %d bytes \"%s\"\n", nRead, abuf ); + +} + diff --git a/src/old/tests/serialize.cpp b/src/old/tests/serialize.cpp new file mode 100644 index 0000000..e233704 --- /dev/null +++ b/src/old/tests/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/old/tests/serializetext.cpp b/src/old/tests/serializetext.cpp new file mode 100644 index 0000000..f6be7d3 --- /dev/null +++ b/src/old/tests/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/old/tests/sha1.cpp b/src/old/tests/sha1.cpp new file mode 100644 index 0000000..df3113c --- /dev/null +++ b/src/old/tests/sha1.cpp @@ -0,0 +1,44 @@ +#include "sha1.h" +#include "sfile.h" + +#define BS 1024 + +int main( int argc, char *argv[] ) +{ + argc--; argv++; + + if( argc == 0 ) + { + printf("Provide a filename.\n"); + return 0; + } + + char buf[BS]; + + Sha1 s; + SFile fin( *argv, "rb" ); + for(;;) + { + int nRead = fin.read( buf, BS ); + if( nRead == 0 ) + break; + + s.update( buf, nRead ); + if( nRead < BS ) + break; + } + + unsigned char *dig = s.getDigest(); + + char val[]={"0123456789ABCDEF"}; + + for( int j = 0; j < 20; j++ ) + { + putchar( val[dig[j]>>4] ); + putchar( val[dig[j]&0x0F] ); + } + putchar('\n'); + + delete[] dig; +} + diff --git a/src/old/tests/sptr.cpp b/src/old/tests/sptr.cpp new file mode 100644 index 0000000..38d3675 --- /dev/null +++ b/src/old/tests/sptr.cpp @@ -0,0 +1,55 @@ +#include <stdio.h> +#include "sptr.h" + +class Annoy +{ +public: + Annoy() : nCnt( 0 ) + { + printf("Created.\n"); + } + + ~Annoy() + { + printf("Destroyed.\n"); + } + + void go() + { + printf("%d: I'm annoying.\n", ++nCnt); + } + + int nCnt; +}; + +void beAnnoying( SPtr<Annoy> bob ) +{ + printf("bob-Count: %d\n", bob.count() ); + bob->go(); +} + +int main() +{ + SPtr<Annoy> pt( new Annoy ); + printf("Count: %d\n", pt.count() ); + pt->go(); + + { + SPtr<Annoy> pt2 = pt; + printf("Count: %d\n", pt2.count() ); + + pt2->go(); + + { + SPtr<Annoy> pt3( pt2 ); + printf("Count: %d\n", pt3.count() ); + + pt3->go(); + + beAnnoying( pt3 ); + } + printf("Count: %d\n", pt.count() ); + } + printf("Count: %d\n", pt.count() ); +} + diff --git a/src/old/tests/srvstress.cpp b/src/old/tests/srvstress.cpp new file mode 100644 index 0000000..d9a9a1c --- /dev/null +++ b/src/old/tests/srvstress.cpp @@ -0,0 +1,91 @@ +#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() + { + return true; + } + + 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/old/tests/strhash.cpp b/src/old/tests/strhash.cpp new file mode 100644 index 0000000..f6528ca --- /dev/null +++ b/src/old/tests/strhash.cpp @@ -0,0 +1,12 @@ +#include <stdio.h> +#include "hashfunctionstring.h" + +int main( int argc, char *argv[] ) +{ + HashFunctionString h; + + printf("\"%s\": %lu\n", argv[1], h.hash( argv[1] ) ); + + return 0; +} + diff --git a/src/old/tests/teltest/main.cpp b/src/old/tests/teltest/main.cpp new file mode 100644 index 0000000..5d3ec26 --- /dev/null +++ b/src/old/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/old/tests/teltest/telnetmonitor.cpp b/src/old/tests/teltest/telnetmonitor.cpp new file mode 100644 index 0000000..65954eb --- /dev/null +++ b/src/old/tests/teltest/telnetmonitor.cpp @@ -0,0 +1,54 @@ +#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 ) +{ + return NULL; +} + +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/old/tests/teltest/telnetmonitor.h b/src/old/tests/teltest/telnetmonitor.h new file mode 100644 index 0000000..ba5761e --- /dev/null +++ b/src/old/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/old/tests/xmlreadtest.cpp b/src/old/tests/xmlreadtest.cpp new file mode 100644 index 0000000..d061810 --- /dev/null +++ b/src/old/tests/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 ); + XmlFileWriter w(stdout, "\t", r.detatchRoot() ); + w.write(); + } + + return 0; +} + diff --git a/src/old/tests/xmlrepltest.cpp b/src/old/tests/xmlrepltest.cpp new file mode 100644 index 0000000..9667705 --- /dev/null +++ b/src/old/tests/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/old/tests/xmlwritetest.cpp b/src/old/tests/xmlwritetest.cpp new file mode 100644 index 0000000..a22d19d --- /dev/null +++ b/src/old/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", " ±î´<M-F6><M-F6>³¸®°êòì¯"); + + 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