summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2009-12-16 20:10:58 +0000
committerMike Buland <eichlan@xagasoft.com>2009-12-16 20:10:58 +0000
commitf72c6e4b97afeb69d9ea4d743c0c302d647ea424 (patch)
tree48d9d94db520455324e902759e887c0d98de976a /src/tests
parent5eba456f0147b12a6247cd7aa41e55d121962358 (diff)
downloadlibbu++-f72c6e4b97afeb69d9ea4d743c0c302d647ea424.tar.gz
libbu++-f72c6e4b97afeb69d9ea4d743c0c302d647ea424.tar.bz2
libbu++-f72c6e4b97afeb69d9ea4d743c0c302d647ea424.tar.xz
libbu++-f72c6e4b97afeb69d9ea4d743c0c302d647ea424.zip
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.
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/optparser.cpp27
-rw-r--r--src/tests/signals.cpp87
-rw-r--r--src/tests/socket.cpp66
3 files changed, 180 insertions, 0 deletions
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 @@
1#include <bu/optparser.h>
2#include <bu/sio.h>
3using namespace Bu;
4
5class Opts : public Bu::OptParser
6{
7public:
8 Opts() :
9 iBob( 542 )
10 {
11 callback( this, &Opts::cb );
12 }
13
14 int cb( int argc, char *argv[] )
15 {
16 sio << "Hey, cb was called, here's a class var: " << iBob << sio.nl;
17 return 5;
18 }
19
20 int iBob;
21};
22
23int main( int argc, char *argv[] )
24{
25 Opts o;
26}
27
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 @@
1#include <bu/signals.h>
2#include <bu/sio.h>
3
4using namespace Bu;
5
6class Thing
7{
8public:
9 Thing() :
10 iState( 82731 )
11 {
12 }
13
14 virtual ~Thing()
15 {
16 }
17
18 void fnc0()
19 {
20 sio << iState << ": void fnc0()" << sio.nl;
21 }
22
23 void fnc1( int a )
24 {
25 sio << iState << ": void fnc1( " << a << " )" << sio.nl;
26 }
27
28 void fnc2( int a, Bu::FString b )
29 {
30 sio << iState << ": void fnc2( " << a << ", \"" << b << "\" )" << sio.nl;
31 }
32
33 void fnc3( int a, Bu::FString b, double c )
34 {
35 sio << iState << ": void fnc3( " << a << ", \"" << b << "\", " << c << " )" << sio.nl;
36 }
37
38 void fnc4( int a, Bu::FString b, double c, char d )
39 {
40 sio << iState << ": void fnc4( " << a << ", \"" << b << "\", " << c << ", '" << d << "' )" << sio.nl;
41 }
42
43 void fnc5( int a, Bu::FString b, double c, char d, long e )
44 {
45 sio << iState << ": void fnc5( " << a << ", \"" << b << "\", " << c << ", '" << d << "', " << e << " )" << sio.nl;
46 }
47
48private:
49 int iState;
50};
51
52void pfnc0()
53{
54 sio << "This doesn't have state, it's pfnc0()!" << sio.nl;
55}
56
57void callit( Signal0<void> sig )
58{
59 sig();
60}
61
62int main()
63{
64 Thing t;
65
66 Signal0<void> cb0( slot( &t, &Thing::fnc0 ) );
67 cb0();
68
69 Signal1<void, int> cb1( slot( &t, &Thing::fnc1 ) );
70 cb1( 5 );
71
72 Signal2<void, int, Bu::FString> cb2( slot( &t, &Thing::fnc2 ) );
73 cb2( 5, "Hi there" );
74
75 Signal3<void, int, Bu::FString, double> cb3( slot( &t, &Thing::fnc3 ) );
76 cb3( 5, "Hi there", 12.85 );
77
78 Signal4<void, int, Bu::FString, double, char> cb4( slot( &t, &Thing::fnc4 ) );
79 cb4( 5, "Hi there", 12.85, 'z' );
80
81 Signal5<void, int, Bu::FString, double, char, long> cb5( slot( &t, &Thing::fnc5 ) );
82 cb5( 5, "Hi there", 12.85, 'z', 849 );
83
84// Signal1<int, int> cb1( slot( &t, &Thing::fnc1 ) );
85// sio << "Result: " << cb1( 5 ) << sio.nl;
86}
87
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 @@
1#include <bu/socket.h>
2#include <bu/sio.h>
3
4#include <sys/time.h>
5#include <time.h>
6
7using namespace Bu;
8
9bool isUp()
10{
11 try
12 {
13 Socket s("xagasoft.com", 9898, 1 );
14
15 char buf[5];
16 buf[s.read(buf, 2, 1, 0)] = '\0';
17
18 if( !strcmp( buf, "hi" ) )
19 return true;
20 else
21 return false;
22 }
23 catch(...)
24 {
25 return false;
26 }
27}
28
29int main()
30{
31 uint32_t uUp = 0;
32 uint32_t uDown = 0;
33 uint32_t uTotal = 0;
34 struct timeval tv;
35
36 for(;;)
37 {
38 gettimeofday( &tv, NULL );
39 time_t goal = ((tv.tv_sec/5)+1)*5;
40 tv.tv_sec = goal-tv.tv_sec;
41 tv.tv_usec = 0-tv.tv_usec;
42 if( tv.tv_usec < 0 )
43 {
44 tv.tv_sec--;
45 tv.tv_usec = 1000000+tv.tv_usec;
46 }
47 select( 0, NULL, NULL, NULL, &tv );
48 gettimeofday( &tv, NULL );
49 if( isUp() )
50 {
51 uUp++;
52 sio << "status: up ";
53 }
54 else
55 {
56 uDown++;
57 sio << "status: down ";
58 }
59 uTotal++;
60
61 sio << "(up=" << (uUp*5) << "s, down=" << (uDown*5) << ") up for "
62 << uUp*100/uTotal << "% of " << uTotal*5 << "s" << sio.nl
63 << sio.flush;
64 }
65}
66