From 0a700ced28520be170c0965191f2450a2e4a82ac Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 25 Aug 2006 20:54:47 +0000 Subject: Added tests and exception codes, so you're program can tell just how bad things really are. --- src/test/clistress/main.cpp | 39 ++++++++++++++++++++ src/test/srvstress/main.cpp | 86 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 src/test/clistress/main.cpp create mode 100644 src/test/srvstress/main.cpp (limited to 'src/test') diff --git a/src/test/clistress/main.cpp b/src/test/clistress/main.cpp new file mode 100644 index 0000000..3f5038b --- /dev/null +++ b/src/test/clistress/main.cpp @@ -0,0 +1,39 @@ +#include "connection.h" + +void _waitForLength( Connection &con, int len) +{ + int rlen = con.getInputAmnt(); + + if (rlen >= len) + return; + + int time_left = 5; + int mic_left = 0; + + while (rlen < len) + { + if (time_left == 0 && mic_left == 0) + { + throw "Socket Timeout"; + } + con.readInput(time_left, mic_left, &time_left, &mic_left); + rlen = con.getInputAmnt(); + } +} + +int main() +{ + Connection c; + + c.open("localhost", 4001 ); + + c.appendOutput("d"); + c.writeOutput(); + + _waitForLength( c, 40 ); + + c.close(); + + return 0; +} + diff --git a/src/test/srvstress/main.cpp b/src/test/srvstress/main.cpp new file mode 100644 index 0000000..c7795e4 --- /dev/null +++ b/src/test/srvstress/main.cpp @@ -0,0 +1,86 @@ +#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; + }; + + 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; +} -- cgit v1.2.3