From f72c6e4b97afeb69d9ea4d743c0c302d647ea424 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 16 Dec 2009 20:10:58 +0000 Subject: The new signal/slots system is in place, and works from 0-5 parameters right now, I'll probably add more later on... I've also started on the replacement for ParamProc, OptParser. It should do everything that ParamProc did, only with less code, and much better. --- src/tests/optparser.cpp | 27 +++++++++++++++ src/tests/signals.cpp | 87 +++++++++++++++++++++++++++++++++++++++++++++++++ src/tests/socket.cpp | 66 +++++++++++++++++++++++++++++++++++++ 3 files changed, 180 insertions(+) create mode 100644 src/tests/optparser.cpp create mode 100644 src/tests/signals.cpp create mode 100644 src/tests/socket.cpp (limited to 'src/tests') diff --git a/src/tests/optparser.cpp b/src/tests/optparser.cpp new file mode 100644 index 0000000..9168af8 --- /dev/null +++ b/src/tests/optparser.cpp @@ -0,0 +1,27 @@ +#include +#include +using namespace Bu; + +class Opts : public Bu::OptParser +{ +public: + Opts() : + iBob( 542 ) + { + callback( this, &Opts::cb ); + } + + int cb( int argc, char *argv[] ) + { + sio << "Hey, cb was called, here's a class var: " << iBob << sio.nl; + return 5; + } + + int iBob; +}; + +int main( int argc, char *argv[] ) +{ + Opts o; +} + diff --git a/src/tests/signals.cpp b/src/tests/signals.cpp new file mode 100644 index 0000000..b4b1363 --- /dev/null +++ b/src/tests/signals.cpp @@ -0,0 +1,87 @@ +#include +#include + +using namespace Bu; + +class Thing +{ +public: + Thing() : + iState( 82731 ) + { + } + + virtual ~Thing() + { + } + + void fnc0() + { + sio << iState << ": void fnc0()" << sio.nl; + } + + void fnc1( int a ) + { + sio << iState << ": void fnc1( " << a << " )" << sio.nl; + } + + void fnc2( int a, Bu::FString b ) + { + sio << iState << ": void fnc2( " << a << ", \"" << b << "\" )" << sio.nl; + } + + void fnc3( int a, Bu::FString b, double c ) + { + sio << iState << ": void fnc3( " << a << ", \"" << b << "\", " << c << " )" << sio.nl; + } + + void fnc4( int a, Bu::FString b, double c, char d ) + { + sio << iState << ": void fnc4( " << a << ", \"" << b << "\", " << c << ", '" << d << "' )" << sio.nl; + } + + void fnc5( int a, Bu::FString b, double c, char d, long e ) + { + sio << iState << ": void fnc5( " << a << ", \"" << b << "\", " << c << ", '" << d << "', " << e << " )" << sio.nl; + } + +private: + int iState; +}; + +void pfnc0() +{ + sio << "This doesn't have state, it's pfnc0()!" << sio.nl; +} + +void callit( Signal0 sig ) +{ + sig(); +} + +int main() +{ + Thing t; + + Signal0 cb0( slot( &t, &Thing::fnc0 ) ); + cb0(); + + Signal1 cb1( slot( &t, &Thing::fnc1 ) ); + cb1( 5 ); + + Signal2 cb2( slot( &t, &Thing::fnc2 ) ); + cb2( 5, "Hi there" ); + + Signal3 cb3( slot( &t, &Thing::fnc3 ) ); + cb3( 5, "Hi there", 12.85 ); + + Signal4 cb4( slot( &t, &Thing::fnc4 ) ); + cb4( 5, "Hi there", 12.85, 'z' ); + + Signal5 cb5( slot( &t, &Thing::fnc5 ) ); + cb5( 5, "Hi there", 12.85, 'z', 849 ); + +// Signal1 cb1( slot( &t, &Thing::fnc1 ) ); +// sio << "Result: " << cb1( 5 ) << sio.nl; +} + diff --git a/src/tests/socket.cpp b/src/tests/socket.cpp new file mode 100644 index 0000000..1cf63e4 --- /dev/null +++ b/src/tests/socket.cpp @@ -0,0 +1,66 @@ +#include +#include + +#include +#include + +using namespace Bu; + +bool isUp() +{ + try + { + Socket s("xagasoft.com", 9898, 1 ); + + char buf[5]; + buf[s.read(buf, 2, 1, 0)] = '\0'; + + if( !strcmp( buf, "hi" ) ) + return true; + else + return false; + } + catch(...) + { + return false; + } +} + +int main() +{ + uint32_t uUp = 0; + uint32_t uDown = 0; + uint32_t uTotal = 0; + struct timeval tv; + + for(;;) + { + gettimeofday( &tv, NULL ); + time_t goal = ((tv.tv_sec/5)+1)*5; + tv.tv_sec = goal-tv.tv_sec; + tv.tv_usec = 0-tv.tv_usec; + if( tv.tv_usec < 0 ) + { + tv.tv_sec--; + tv.tv_usec = 1000000+tv.tv_usec; + } + select( 0, NULL, NULL, NULL, &tv ); + gettimeofday( &tv, NULL ); + if( isUp() ) + { + uUp++; + sio << "status: up "; + } + else + { + uDown++; + sio << "status: down "; + } + uTotal++; + + sio << "(up=" << (uUp*5) << "s, down=" << (uDown*5) << ") up for " + << uUp*100/uTotal << "% of " << uTotal*5 << "s" << sio.nl + << sio.flush; + } +} + -- cgit v1.2.3