aboutsummaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/optparser.cpp25
-rw-r--r--src/tests/signals.cpp39
2 files changed, 60 insertions, 4 deletions
diff --git a/src/tests/optparser.cpp b/src/tests/optparser.cpp
index 9168af8..ee2ea58 100644
--- a/src/tests/optparser.cpp
+++ b/src/tests/optparser.cpp
@@ -8,13 +8,30 @@ public:
8 Opts() : 8 Opts() :
9 iBob( 542 ) 9 iBob( 542 )
10 { 10 {
11 callback( this, &Opts::cb ); 11 Option o;
12 o.sUsed = slot( this, &Opts::cb );
13 o.cOpt = 'x';
14 o.sOpt = "things";
15 o.bShortHasParams = true;
16 o.sHelp = "This is the first test parameter. It calls a function, and takes parameters.";
17 addOption( o );
18
19 Option o2;
20 o2.sUsed = slot( this, &Opts::cb );
21 o2.cOpt = 'y';
22 o2.sOpt = "stuff";
23 o2.bShortHasParams = false;
24 o2.sHelp = "This is the second test parameter. It does not take parameters. However, I do want to make this part much longer to see how it looks when you add way too much text to one of these things. It can't really be that bad, right?";
25 addOption( o2 );
26
27 addHelpOption('h', "help", "This help.");
12 } 28 }
13 29
14 int cb( int argc, char *argv[] ) 30 int cb( StrArray aParams )
15 { 31 {
16 sio << "Hey, cb was called, here's a class var: " << iBob << sio.nl; 32 sio << "Hey, cb was called, here's a class var: " << iBob << sio.nl;
17 return 5; 33 sio << "argv[] = " << aParams << sio.nl;
34 return 1;
18 } 35 }
19 36
20 int iBob; 37 int iBob;
@@ -23,5 +40,7 @@ public:
23int main( int argc, char *argv[] ) 40int main( int argc, char *argv[] )
24{ 41{
25 Opts o; 42 Opts o;
43
44 o.parse( argc, argv );
26} 45}
27 46
diff --git a/src/tests/signals.cpp b/src/tests/signals.cpp
index b4b1363..4af2b8e 100644
--- a/src/tests/signals.cpp
+++ b/src/tests/signals.cpp
@@ -51,7 +51,32 @@ private:
51 51
52void pfnc0() 52void pfnc0()
53{ 53{
54 sio << "This doesn't have state, it's pfnc0()!" << sio.nl; 54 sio << ": void pfnc0()" << sio.nl;
55}
56
57void pfnc1( int a )
58{
59 sio << ": void pfnc1( " << a << " )" << sio.nl;
60}
61
62void pfnc2( int a, Bu::FString b )
63{
64 sio << ": void pfnc2( " << a << ", \"" << b << "\" )" << sio.nl;
65}
66
67void pfnc3( int a, Bu::FString b, double c )
68{
69 sio << ": void pfnc3( " << a << ", \"" << b << "\", " << c << " )" << sio.nl;
70}
71
72void pfnc4( int a, Bu::FString b, double c, char d )
73{
74 sio << ": void pfnc4( " << a << ", \"" << b << "\", " << c << ", '" << d << "' )" << sio.nl;
75}
76
77void pfnc5( int a, Bu::FString b, double c, char d, long e )
78{
79 sio << ": void pfnc5( " << a << ", \"" << b << "\", " << c << ", '" << d << "', " << e << " )" << sio.nl;
55} 80}
56 81
57void callit( Signal0<void> sig ) 82void callit( Signal0<void> sig )
@@ -65,21 +90,33 @@ int main()
65 90
66 Signal0<void> cb0( slot( &t, &Thing::fnc0 ) ); 91 Signal0<void> cb0( slot( &t, &Thing::fnc0 ) );
67 cb0(); 92 cb0();
93 cb0 = slot( &pfnc0 );
94 cb0();
68 95
69 Signal1<void, int> cb1( slot( &t, &Thing::fnc1 ) ); 96 Signal1<void, int> cb1( slot( &t, &Thing::fnc1 ) );
70 cb1( 5 ); 97 cb1( 5 );
98 cb1 = slot( &pfnc1 );
99 cb1( 5 );
71 100
72 Signal2<void, int, Bu::FString> cb2( slot( &t, &Thing::fnc2 ) ); 101 Signal2<void, int, Bu::FString> cb2( slot( &t, &Thing::fnc2 ) );
73 cb2( 5, "Hi there" ); 102 cb2( 5, "Hi there" );
103 cb2 = slot( &pfnc2 );
104 cb2( 5, "Hi there" );
74 105
75 Signal3<void, int, Bu::FString, double> cb3( slot( &t, &Thing::fnc3 ) ); 106 Signal3<void, int, Bu::FString, double> cb3( slot( &t, &Thing::fnc3 ) );
76 cb3( 5, "Hi there", 12.85 ); 107 cb3( 5, "Hi there", 12.85 );
108 cb3 = slot( &pfnc3 );
109 cb3( 5, "Hi there", 12.85 );
77 110
78 Signal4<void, int, Bu::FString, double, char> cb4( slot( &t, &Thing::fnc4 ) ); 111 Signal4<void, int, Bu::FString, double, char> cb4( slot( &t, &Thing::fnc4 ) );
79 cb4( 5, "Hi there", 12.85, 'z' ); 112 cb4( 5, "Hi there", 12.85, 'z' );
113 cb4 = slot( &pfnc4 );
114 cb4( 5, "Hi there", 12.85, 'z' );
80 115
81 Signal5<void, int, Bu::FString, double, char, long> cb5( slot( &t, &Thing::fnc5 ) ); 116 Signal5<void, int, Bu::FString, double, char, long> cb5( slot( &t, &Thing::fnc5 ) );
82 cb5( 5, "Hi there", 12.85, 'z', 849 ); 117 cb5( 5, "Hi there", 12.85, 'z', 849 );
118 cb5 = slot( &pfnc5 );
119 cb5( 5, "Hi there", 12.85, 'z', 849 );
83 120
84// Signal1<int, int> cb1( slot( &t, &Thing::fnc1 ) ); 121// Signal1<int, int> cb1( slot( &t, &Thing::fnc1 ) );
85// sio << "Result: " << cb1( 5 ) << sio.nl; 122// sio << "Result: " << cb1( 5 ) << sio.nl;