diff options
author | Mike Buland <eichlan@xagasoft.com> | 2011-03-30 22:33:41 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2011-03-30 22:33:41 +0000 |
commit | 4b9289cfb260f4bcecaf23a810584ef6ef8e8501 (patch) | |
tree | 79136af08c7e42ba3322f0d73e9779e4354b318a /src/tests | |
parent | c7636dc954eddfe58f7959392602fbc9072d77e7 (diff) | |
download | libbu++-4b9289cfb260f4bcecaf23a810584ef6ef8e8501.tar.gz libbu++-4b9289cfb260f4bcecaf23a810584ef6ef8e8501.tar.bz2 libbu++-4b9289cfb260f4bcecaf23a810584ef6ef8e8501.tar.xz libbu++-4b9289cfb260f4bcecaf23a810584ef6ef8e8501.zip |
Ok, string stuff is working much, much better, a load of new unit tests have
been added, and I deleted a whole slew of stupid old tests that I don't need.
Diffstat (limited to 'src/tests')
52 files changed, 0 insertions, 3402 deletions
diff --git a/src/tests/archive.cpp b/src/tests/archive.cpp deleted file mode 100644 index c905007..0000000 --- a/src/tests/archive.cpp +++ /dev/null | |||
@@ -1,27 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include "bu/archive.h" | ||
9 | #include "bu/file.h" | ||
10 | #include "bu/string.h" | ||
11 | |||
12 | using namespace Bu; | ||
13 | |||
14 | int main() | ||
15 | { | ||
16 | File f("test.dat", File::WriteNew ); | ||
17 | Archive ar( f, Archive::save ); | ||
18 | |||
19 | Bu::String s("Hello there"); | ||
20 | ar << s; | ||
21 | |||
22 | ar.setProp("hi", 45 ); | ||
23 | printf("Hi: %d", ar.getProp<int>("hi") ); | ||
24 | |||
25 | return 0; | ||
26 | } | ||
27 | |||
diff --git a/src/tests/archive2.cpp b/src/tests/archive2.cpp deleted file mode 100644 index e8d3360..0000000 --- a/src/tests/archive2.cpp +++ /dev/null | |||
@@ -1,102 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include "bu/archive.h" | ||
9 | #include "bu/archival.h" | ||
10 | #include "bu/file.h" | ||
11 | |||
12 | int giId = 0; | ||
13 | |||
14 | class A : public Bu::Archival | ||
15 | { | ||
16 | public: | ||
17 | A() : | ||
18 | iId( giId++ ) | ||
19 | { | ||
20 | } | ||
21 | |||
22 | virtual ~A() | ||
23 | { | ||
24 | } | ||
25 | |||
26 | virtual void archive( Bu::ArchiveBase &ar ) | ||
27 | { | ||
28 | ar && iId; | ||
29 | } | ||
30 | |||
31 | int iId; | ||
32 | }; | ||
33 | |||
34 | class B : public Bu::Archival | ||
35 | { | ||
36 | public: | ||
37 | B() : | ||
38 | iId( giId++ ), | ||
39 | a1( new A ), | ||
40 | a2( new A ) | ||
41 | { | ||
42 | } | ||
43 | |||
44 | virtual ~B() | ||
45 | { | ||
46 | delete a1; | ||
47 | delete a2; | ||
48 | } | ||
49 | |||
50 | virtual void archive( Bu::ArchiveBase &ar ) | ||
51 | { | ||
52 | //ar && iId && a1 && a2; | ||
53 | ar << iId << a1 << a2; | ||
54 | } | ||
55 | |||
56 | int iId; | ||
57 | A *a1, *a2; | ||
58 | }; | ||
59 | |||
60 | class C : public Bu::Archival | ||
61 | { | ||
62 | public: | ||
63 | C() : | ||
64 | iId( giId++ ), | ||
65 | a( new A ), | ||
66 | b( new B ) | ||
67 | { | ||
68 | } | ||
69 | |||
70 | virtual ~C() | ||
71 | { | ||
72 | delete a; | ||
73 | delete b; | ||
74 | } | ||
75 | |||
76 | virtual void archive( Bu::ArchiveBase &ar ) | ||
77 | { | ||
78 | //ar && iId && a && b; | ||
79 | ar << iId; | ||
80 | ar << a << b; | ||
81 | } | ||
82 | |||
83 | int iId; | ||
84 | A *a; | ||
85 | B *b; | ||
86 | }; | ||
87 | |||
88 | void write() | ||
89 | { | ||
90 | C *c = new C; | ||
91 | |||
92 | Bu::File f( "test.archive", Bu::File::Write ); | ||
93 | Bu::Archive ar( f, Bu::Archive::save ); | ||
94 | ar << c; | ||
95 | } | ||
96 | |||
97 | int main() | ||
98 | { | ||
99 | write(); | ||
100 | |||
101 | } | ||
102 | |||
diff --git a/src/tests/atom.cpp b/src/tests/atom.cpp deleted file mode 100644 index 7808282..0000000 --- a/src/tests/atom.cpp +++ /dev/null | |||
@@ -1,32 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include "bu/atom.h" | ||
9 | #include <stdio.h> | ||
10 | #include <stdlib.h> | ||
11 | |||
12 | typedef struct bob | ||
13 | { | ||
14 | int a, b; | ||
15 | } bob; | ||
16 | int main() | ||
17 | { | ||
18 | Bu::Atom<int> aInt; | ||
19 | Bu::Atom<const char *> aStr; | ||
20 | Bu::Atom<bob> aBob; | ||
21 | |||
22 | aBob = bob(); | ||
23 | aBob->a = 5; | ||
24 | |||
25 | aStr.set("Hey there, dude"); | ||
26 | aInt.set( 55 ); | ||
27 | int me = aInt; | ||
28 | aInt = 12; | ||
29 | printf("%d, %d\n", aInt.get(), me ); | ||
30 | printf("%s\n", aStr.get() ); | ||
31 | } | ||
32 | |||
diff --git a/src/tests/buffer.cpp b/src/tests/buffer.cpp deleted file mode 100644 index f3f6f41..0000000 --- a/src/tests/buffer.cpp +++ /dev/null | |||
@@ -1,45 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include "bu/membuf.h" | ||
9 | #include "bu/buffer.h" | ||
10 | #include "bu/file.h" | ||
11 | |||
12 | using namespace Bu; | ||
13 | |||
14 | int main( int argc, char *argv[] ) | ||
15 | { | ||
16 | argc--,argv++; | ||
17 | if( argc == 0 ) | ||
18 | { | ||
19 | MemBuf mOut; | ||
20 | Buffer bOut( mOut, 10 ); | ||
21 | |||
22 | for( int j = 0; j < 4; j++ ) | ||
23 | bOut.write("hi ", 3 ); | ||
24 | |||
25 | printf("Preflush: \"%s\"\n", mOut.getString().getStr() ); | ||
26 | bOut.flush(); | ||
27 | |||
28 | printf("Final: \"%s\"\n", mOut.getString().getStr() ); | ||
29 | } | ||
30 | else | ||
31 | { | ||
32 | File fIn( *argv, File::Read ); | ||
33 | Buffer bIn( fIn, 10 ); | ||
34 | |||
35 | char buf[5]; | ||
36 | for( int j = 0; j < 5; j++ ) | ||
37 | { | ||
38 | buf[bIn.read( buf, 4 )] = '\0'; | ||
39 | printf("Four chars: \"%s\"\n", buf ); | ||
40 | } | ||
41 | } | ||
42 | |||
43 | return 0; | ||
44 | } | ||
45 | |||
diff --git a/src/tests/cache.cpp b/src/tests/cache.cpp deleted file mode 100644 index e9dbd86..0000000 --- a/src/tests/cache.cpp +++ /dev/null | |||
@@ -1,260 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include <stdio.h> | ||
9 | #include <stdlib.h> | ||
10 | #include <sys/stat.h> | ||
11 | #include <sys/types.h> | ||
12 | #include <errno.h> | ||
13 | #include <unistd.h> | ||
14 | |||
15 | #include "bu/cache.h" | ||
16 | #include "bu/file.h" | ||
17 | #include "bu/string.h" | ||
18 | #include "bu/cachecalc.h" | ||
19 | |||
20 | class Bob | ||
21 | { | ||
22 | public: | ||
23 | Bob() | ||
24 | { | ||
25 | TRACE(); | ||
26 | } | ||
27 | |||
28 | Bob( int i ) : | ||
29 | iInt( i ) | ||
30 | { | ||
31 | TRACE( i ); | ||
32 | } | ||
33 | |||
34 | virtual ~Bob() | ||
35 | { | ||
36 | TRACE(); | ||
37 | } | ||
38 | |||
39 | void setInt( int i ) | ||
40 | { | ||
41 | TRACE( i ); | ||
42 | iInt = i; | ||
43 | } | ||
44 | |||
45 | long getKey() const | ||
46 | { | ||
47 | TRACE( i ); | ||
48 | return iInt; | ||
49 | } | ||
50 | |||
51 | int getInt() | ||
52 | { | ||
53 | return iInt; | ||
54 | } | ||
55 | |||
56 | int iInt; | ||
57 | }; | ||
58 | |||
59 | namespace Bu { | ||
60 | template<> | ||
61 | void __tracer_format<Bob*>( Bob* const &c ) | ||
62 | { | ||
63 | printf("%08X=%d", (uint32_t)c, c->getInt() ); | ||
64 | } | ||
65 | } | ||
66 | |||
67 | class BobStore : public Bu::CacheStore<long, Bob> | ||
68 | { | ||
69 | public: | ||
70 | BobStore() : | ||
71 | cLastId( 0 ) | ||
72 | { | ||
73 | TRACE(); | ||
74 | if( access( "bobcache/last", R_OK|W_OK ) ) | ||
75 | { | ||
76 | mkdir("bobcache", 0755 ); | ||
77 | Bu::File f("bobcache/last", Bu::File::Write|Bu::File::Create ); | ||
78 | f.write("0", 1); | ||
79 | printf("Initializing cache: %s\n", strerror( errno ) ); | ||
80 | } | ||
81 | else | ||
82 | { | ||
83 | cLastId = readNum("bobcache/last"); | ||
84 | } | ||
85 | } | ||
86 | |||
87 | ~BobStore() | ||
88 | { | ||
89 | TRACE(); | ||
90 | writeNum("bobcache/last", cLastId ); | ||
91 | } | ||
92 | |||
93 | long readNum( const Bu::String &sFile ) | ||
94 | { | ||
95 | TRACE( sFile ); | ||
96 | Bu::File f( sFile, Bu::File::Read ); | ||
97 | char buf[80]; | ||
98 | buf[f.read( buf, 80 )] = '\0'; | ||
99 | return strtol( buf, NULL, 0 ); | ||
100 | } | ||
101 | |||
102 | void writeNum( const Bu::String &sFile, long num ) | ||
103 | { | ||
104 | TRACE( sFile, num ); | ||
105 | Bu::File f( sFile, | ||
106 | Bu::File::Write|Bu::File::Create|Bu::File::Truncate | ||
107 | ); | ||
108 | f.write( Bu::String("%1").arg( num ) ); | ||
109 | } | ||
110 | |||
111 | virtual void sync( Bob *, const long & ) | ||
112 | { | ||
113 | } | ||
114 | |||
115 | virtual void sync() | ||
116 | { | ||
117 | } | ||
118 | |||
119 | virtual bool has( const long & ) | ||
120 | { | ||
121 | return true; | ||
122 | } | ||
123 | |||
124 | virtual Bob *load( const long &key ) | ||
125 | { | ||
126 | TRACE( key ); | ||
127 | Bu::String sDest = Bu::String("bobcache/%1").arg( key ); | ||
128 | return new Bob( readNum( sDest ) ); | ||
129 | } | ||
130 | |||
131 | virtual void unload( Bob *pObj, const long &key ) | ||
132 | { | ||
133 | TRACE( pObj, key ); | ||
134 | Bu::String sDest = Bu::String("bobcache/%1").arg( key ); | ||
135 | writeNum( sDest, pObj->getInt() ); | ||
136 | delete pObj; | ||
137 | } | ||
138 | |||
139 | virtual long create( Bob *rSrc ) | ||
140 | { | ||
141 | TRACE( rSrc ); | ||
142 | long id = ++cLastId; | ||
143 | Bu::String sDest = Bu::String("bobcache/%1").arg( id ); | ||
144 | writeNum( sDest, rSrc->getInt() ); | ||
145 | return id; | ||
146 | } | ||
147 | |||
148 | virtual void destroy( Bob *pObj, const long &key ) | ||
149 | { | ||
150 | TRACE( pObj, key ); | ||
151 | Bu::String sDest = Bu::String("bobcache/%1").arg( key ); | ||
152 | if( !access( sDest.getStr(), F_OK ) ) | ||
153 | unlink( sDest.getStr() ); | ||
154 | delete pObj; | ||
155 | } | ||
156 | |||
157 | virtual void destroy( const long &key ) | ||
158 | { | ||
159 | TRACE( pObj, key ); | ||
160 | Bu::String sDest = Bu::String("bobcache/%1").arg( key ); | ||
161 | if( !access( sDest.getStr(), F_OK ) ) | ||
162 | unlink( sDest.getStr() ); | ||
163 | } | ||
164 | |||
165 | private: | ||
166 | long cLastId; | ||
167 | }; | ||
168 | |||
169 | class BobCalc : public Bu::CacheCalc<long, Bob> | ||
170 | { | ||
171 | public: | ||
172 | BobCalc() | ||
173 | { | ||
174 | } | ||
175 | |||
176 | virtual ~BobCalc() | ||
177 | { | ||
178 | } | ||
179 | |||
180 | virtual void onLoad( Bob *, const long & ) | ||
181 | { | ||
182 | } | ||
183 | |||
184 | virtual void onUnload( Bob *, const long & ) | ||
185 | { | ||
186 | } | ||
187 | |||
188 | virtual void onDestroy( Bob *, const long & ) | ||
189 | { | ||
190 | } | ||
191 | |||
192 | virtual void onDestroy( const long & ) | ||
193 | { | ||
194 | } | ||
195 | |||
196 | virtual bool shouldSync( Bob *, const long &, time_t ) | ||
197 | { | ||
198 | return false; | ||
199 | } | ||
200 | |||
201 | private: | ||
202 | |||
203 | }; | ||
204 | |||
205 | int main( int argc, char *argv[] ) | ||
206 | { | ||
207 | TRACE( argc, argv ); | ||
208 | typedef Bu::Cache<long, Bob> BobCache; | ||
209 | typedef BobCache::Ptr BobPtr; | ||
210 | |||
211 | if( argc < 3 ) | ||
212 | { | ||
213 | printf("Try: %s [crudl] [<id/value>]\n\n", argv[0] ); | ||
214 | return 0; | ||
215 | } | ||
216 | |||
217 | BobCache cBob( new BobCalc(), new BobStore() ); | ||
218 | switch( argv[1][0] ) | ||
219 | { | ||
220 | case 'c': | ||
221 | { | ||
222 | BobCache::Ptr pBob = cBob.insert( | ||
223 | new Bob( strtol( argv[2], NULL, 0 ) ) | ||
224 | ); | ||
225 | printf("Key = %ld\n", pBob.getKey() ); | ||
226 | } | ||
227 | return 0; | ||
228 | |||
229 | case 'r': | ||
230 | { | ||
231 | BobCache::Ptr pBob = cBob.get( strtol( argv[2], NULL, 0 ) ); | ||
232 | printf("Value = %d\n", pBob->getInt() ); | ||
233 | } | ||
234 | return 0; | ||
235 | |||
236 | case 'u': | ||
237 | { | ||
238 | BobCache::Ptr pBob = cBob.get( strtol( argv[2], NULL, 0 ) ); | ||
239 | pBob->setInt( strtol( argv[3], NULL, 0 ) ); | ||
240 | } | ||
241 | return 0; | ||
242 | |||
243 | case 'd': | ||
244 | { | ||
245 | cBob.erase( strtol( argv[2], NULL, 0 ) ); | ||
246 | } | ||
247 | return 0; | ||
248 | |||
249 | case 'l': | ||
250 | { | ||
251 | BobCache::Ptr pBob = cBob.getLazy( strtol( argv[2], NULL, 0 ) ); | ||
252 | printf("isBound: %s\n", pBob.isBound()?"yes":"no"); | ||
253 | printf("Value = %d\n", pBob->getInt() ); | ||
254 | printf("isBound: %s\n", pBob.isBound()?"yes":"no"); | ||
255 | } | ||
256 | return 0; | ||
257 | } | ||
258 | |||
259 | } | ||
260 | |||
diff --git a/src/tests/conduit.cpp b/src/tests/conduit.cpp deleted file mode 100644 index d8d9e03..0000000 --- a/src/tests/conduit.cpp +++ /dev/null | |||
@@ -1,56 +0,0 @@ | |||
1 | #include "bu/conduit.h" | ||
2 | #include "bu/sio.h" | ||
3 | #include "bu/ito.h" | ||
4 | |||
5 | using namespace Bu; | ||
6 | |||
7 | class Reader : public Bu::Ito | ||
8 | { | ||
9 | public: | ||
10 | Reader( Bu::Conduit &rCond ) : | ||
11 | rCond( rCond ) | ||
12 | { | ||
13 | } | ||
14 | |||
15 | virtual ~Reader() | ||
16 | { | ||
17 | } | ||
18 | |||
19 | protected: | ||
20 | virtual void run() | ||
21 | { | ||
22 | while( rCond.isOpen() ) | ||
23 | { | ||
24 | char buf[1025]; | ||
25 | |||
26 | sio << "Reading..." << sio.flush; | ||
27 | Bu::size iRead = rCond.read( buf, 1024 ); | ||
28 | buf[iRead] = '\0'; | ||
29 | sio << "got " << iRead << " >" << buf << "<" << sio.nl; | ||
30 | } | ||
31 | |||
32 | sio << "Conduit closed, exting thread." << sio.nl; | ||
33 | } | ||
34 | |||
35 | private: | ||
36 | Bu::Conduit &rCond; | ||
37 | }; | ||
38 | |||
39 | int main() | ||
40 | { | ||
41 | Conduit c; | ||
42 | Reader r( c ); | ||
43 | r.start(); | ||
44 | |||
45 | sleep( 3 ); | ||
46 | c.write("Hi there", 8 ); | ||
47 | sleep( 3 ); | ||
48 | c.write("Goodbye, soon.", 14 ); | ||
49 | sleep( 3 ); | ||
50 | c.write("...NOW!", 9 ); | ||
51 | c.close(); | ||
52 | sleep( 3 ); | ||
53 | |||
54 | return 0; | ||
55 | } | ||
56 | |||
diff --git a/src/tests/console.cpp b/src/tests/console.cpp deleted file mode 100644 index 670ff5b..0000000 --- a/src/tests/console.cpp +++ /dev/null | |||
@@ -1,43 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include <bu/sio.h> | ||
9 | using namespace Bu; | ||
10 | |||
11 | #include <iostream> | ||
12 | using namespace std; | ||
13 | |||
14 | typedef struct Counter | ||
15 | { | ||
16 | Counter() : i( 0 ) | ||
17 | { | ||
18 | } | ||
19 | |||
20 | int get() | ||
21 | { | ||
22 | i++; | ||
23 | return i-1; | ||
24 | } | ||
25 | |||
26 | int i; | ||
27 | } Counter; | ||
28 | |||
29 | template<typename a> | ||
30 | void runtest( a &out ) | ||
31 | { | ||
32 | Counter c; | ||
33 | out << c.get() << ", " << c.get() << ", " << c.get() << ", " << c.get() << ", " << c.get() << "\n"; | ||
34 | } | ||
35 | |||
36 | int main() | ||
37 | { | ||
38 | runtest( cout ); | ||
39 | runtest( sio ); | ||
40 | |||
41 | return 0; | ||
42 | } | ||
43 | |||
diff --git a/src/tests/cryptpass.cpp b/src/tests/cryptpass.cpp deleted file mode 100644 index d272344..0000000 --- a/src/tests/cryptpass.cpp +++ /dev/null | |||
@@ -1,25 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include "bu/crypt.h" | ||
9 | #include "bu/sio.h" | ||
10 | |||
11 | using namespace Bu; | ||
12 | |||
13 | int main( int argc, char *argv[] ) | ||
14 | { | ||
15 | if( argc == 1 ) | ||
16 | sio << "Syntax: " << argv[0] << " <password> [salt]" << sio.nl | ||
17 | << sio.nl; | ||
18 | else if( argc == 2 ) | ||
19 | sio << "Crypt1: >> " << cryptPass( argv[1] ) << " <<" << sio.nl; | ||
20 | else | ||
21 | sio << "Crypt2: >> " << cryptPass( argv[1], argv[2] ) << " <<" << sio.nl; | ||
22 | |||
23 | return 0; | ||
24 | } | ||
25 | |||
diff --git a/src/tests/csv.cpp b/src/tests/csv.cpp deleted file mode 100644 index 850fda8..0000000 --- a/src/tests/csv.cpp +++ /dev/null | |||
@@ -1,50 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include "bu/optparser.h" | ||
9 | #include "bu/file.h" | ||
10 | #include "bu/newline.h" | ||
11 | #include "bu/csvreader.h" | ||
12 | #include "bu/buffer.h" | ||
13 | #include "bu/sio.h" | ||
14 | |||
15 | using namespace Bu; | ||
16 | |||
17 | class Options : public OptParser | ||
18 | { | ||
19 | public: | ||
20 | Options( int argc, char *argv[] ) | ||
21 | { | ||
22 | addOption( slot( this, &Options::onRead ), 'r', "read", | ||
23 | "Read and display a csv file." ); | ||
24 | |||
25 | addHelpOption(); | ||
26 | |||
27 | parse( argc, argv ); | ||
28 | } | ||
29 | |||
30 | int onRead( StrArray aArgs ) | ||
31 | { | ||
32 | File fIn( aArgs[1], File::Read ); | ||
33 | NewLine nlIn( fIn ); | ||
34 | Buffer bIn( nlIn ); | ||
35 | CsvReader rCsv( bIn ); | ||
36 | while( !fIn.isEos() ) | ||
37 | { | ||
38 | sio << rCsv.readLine() << sio.nl; | ||
39 | } | ||
40 | sio << sio.nl; | ||
41 | return 1; | ||
42 | } | ||
43 | }; | ||
44 | |||
45 | int main( int argc, char *argv[] ) | ||
46 | { | ||
47 | Options opts( argc, argv ); | ||
48 | return 0; | ||
49 | } | ||
50 | |||
diff --git a/src/tests/daysinmonth.cpp b/src/tests/daysinmonth.cpp deleted file mode 100644 index 1e78eb3..0000000 --- a/src/tests/daysinmonth.cpp +++ /dev/null | |||
@@ -1,23 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include "bu/sio.h" | ||
9 | #include "bu/util.h" | ||
10 | |||
11 | using namespace Bu; | ||
12 | |||
13 | int main() | ||
14 | { | ||
15 | for( int j = 0; j < 12; j++ ) | ||
16 | { | ||
17 | sio << "2012-" << j << " = " | ||
18 | << getDaysInMonth( j, 2012 ) << sio.nl; | ||
19 | } | ||
20 | |||
21 | return 0; | ||
22 | } | ||
23 | |||
diff --git a/src/tests/fastcgi.cpp b/src/tests/fastcgi.cpp deleted file mode 100644 index 7447a6f..0000000 --- a/src/tests/fastcgi.cpp +++ /dev/null | |||
@@ -1,90 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include "bu/fastcgi.h" | ||
9 | |||
10 | #include <unistd.h> | ||
11 | |||
12 | class Cgi : public Bu::FastCgi | ||
13 | { | ||
14 | public: | ||
15 | Cgi() : | ||
16 | Bu::FastCgi::FastCgi() | ||
17 | { | ||
18 | } | ||
19 | |||
20 | Cgi( int iPort ) : | ||
21 | Bu::FastCgi::FastCgi( iPort ) | ||
22 | { | ||
23 | } | ||
24 | |||
25 | virtual ~Cgi() | ||
26 | { | ||
27 | } | ||
28 | |||
29 | virtual int onRequest( const StrHash &hParams, | ||
30 | const Bu::String &sStdIn, Bu::Stream &sStdOut, | ||
31 | Bu::Stream &/*sStdErr*/ ) | ||
32 | { | ||
33 | Bu::String sOut("Content-Type: text/html\r\n\r\n"); | ||
34 | sOut += "<html><body><h1>Environment:</h1><ul>"; | ||
35 | for( StrHash::const_iterator i = hParams.begin(); i; i++ ) | ||
36 | { | ||
37 | sOut += "<li>" + i.getKey() + " = " + | ||
38 | i.getValue() + "</li>"; | ||
39 | } | ||
40 | sOut += "</ul>"; | ||
41 | char buf[2048]; | ||
42 | sOut += "<h1>Cwd:</h1><ul><li>"; | ||
43 | sOut += getcwd( buf, 2048 ); | ||
44 | sOut += "</li></ul>"; | ||
45 | sOut += "<h1>Stdin:</h1>"; | ||
46 | sOut += Bu::String("%1 bytes<pre>").arg( sStdIn.getSize() ); | ||
47 | Bu::String sL, sR; | ||
48 | for( Bu::String::const_iterator i = sStdIn.begin(); | ||
49 | i; i++ ) | ||
50 | { | ||
51 | sL += Bu::String("%1").arg( | ||
52 | (unsigned int)((unsigned char)*i), Bu::Fmt::hex().width(2).fill('0') ); | ||
53 | if( *i < 27 ) | ||
54 | sR += ". "; | ||
55 | else | ||
56 | sR += Bu::String("&#%1; ").arg( | ||
57 | (unsigned int)((unsigned char)*i) ); | ||
58 | if( sL.getSize()/3 == 8 ) | ||
59 | { | ||
60 | sOut += sL + " | " + sR + "\n"; | ||
61 | sL = sR = ""; | ||
62 | } | ||
63 | } | ||
64 | if( sL != "" ) | ||
65 | { | ||
66 | while( sL.getSize()/3 < 8 ) | ||
67 | sL += " "; | ||
68 | sOut += sL + " | " + sR + "\n"; | ||
69 | } | ||
70 | sOut += "</pre><hr/><pre>"; | ||
71 | sOut += sStdIn; | ||
72 | sOut += "</pre>"; | ||
73 | sOut += "<form method=\"post\" enctype=\"multipart/form-data\"><textarea name=\"bob\"></textarea><br /><input type=\"file\" name=\"somefile\" /><br /><input type=\"submit\" name=\"yeah\" value=\"try it\" /></form>"; | ||
74 | sOut += "</body></html>"; | ||
75 | |||
76 | sStdOut.write( sOut ); | ||
77 | |||
78 | return 0; | ||
79 | } | ||
80 | }; | ||
81 | |||
82 | int main() | ||
83 | { | ||
84 | Cgi c( 8789 ); | ||
85 | |||
86 | c.run(); | ||
87 | |||
88 | return 0; | ||
89 | } | ||
90 | |||
diff --git a/src/tests/formula.cpp b/src/tests/formula.cpp deleted file mode 100644 index a90ddaf..0000000 --- a/src/tests/formula.cpp +++ /dev/null | |||
@@ -1,56 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include "bu/formula.h" | ||
9 | #include <math.h> | ||
10 | |||
11 | int main( int argc, char *argv[] ) | ||
12 | { | ||
13 | if( argc < 2 ) | ||
14 | { | ||
15 | printf("usage: %s <formula>\n", argv[0] ); | ||
16 | return -1; | ||
17 | } | ||
18 | Bu::Formula<uint32_t> uForm; | ||
19 | Bu::Formula<double> dForm; | ||
20 | |||
21 | class DblCeilFunc : public Bu::Formula<double>::Func | ||
22 | { | ||
23 | public: | ||
24 | virtual double operator()( double x ) | ||
25 | { | ||
26 | return ceil( x ); | ||
27 | } | ||
28 | }; | ||
29 | |||
30 | dForm.hFunc.insert( "ceil", new DblCeilFunc() ); | ||
31 | |||
32 | class IntCeilFunc : public Bu::Formula<uint32_t>::Func | ||
33 | { | ||
34 | public: | ||
35 | virtual uint32_t operator()( uint32_t x ) | ||
36 | { | ||
37 | return x; | ||
38 | } | ||
39 | }; | ||
40 | |||
41 | uForm.hFunc.insert( "ceil", new IntCeilFunc() ); | ||
42 | |||
43 | uForm.hVars.insert("x", 10 ); | ||
44 | dForm.hVars.insert("x", 10.00 ); | ||
45 | uForm.hVars.insert("y", 10 ); | ||
46 | dForm.hVars.insert("y", 10.00 ); | ||
47 | |||
48 | for( int j = 1; j < argc; j++ ) | ||
49 | { | ||
50 | printf("u: %s = %u\n", argv[j], uForm.run( argv[j] ) ); | ||
51 | printf("d: %s = %f\n", argv[j], dForm.run( argv[j] ) ); | ||
52 | } | ||
53 | |||
54 | return 0; | ||
55 | } | ||
56 | |||
diff --git a/src/tests/fstratsptr.cpp b/src/tests/fstratsptr.cpp deleted file mode 100644 index 5053dd1..0000000 --- a/src/tests/fstratsptr.cpp +++ /dev/null | |||
@@ -1,53 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include "bu/string.h" | ||
9 | #include "bu/atom.h" | ||
10 | #include "bu/sptr.h" | ||
11 | |||
12 | class Person | ||
13 | { | ||
14 | public: | ||
15 | Person(){}; | ||
16 | virtual ~Person(){}; | ||
17 | |||
18 | Bu::Atom<Bu::String> sFirstName; | ||
19 | Bu::Atom<Bu::String> sLastName; | ||
20 | }; | ||
21 | |||
22 | typedef Bu::SPtr<Person> PersonPtr; | ||
23 | |||
24 | void Swap(PersonPtr one, PersonPtr two) | ||
25 | { | ||
26 | PersonPtr three(new Person); | ||
27 | three->sFirstName = one->sFirstName; | ||
28 | three->sLastName = two->sLastName; | ||
29 | |||
30 | printf( | ||
31 | "%s %s\n", | ||
32 | three->sFirstName->getStr(), | ||
33 | three->sLastName->getStr() ); | ||
34 | } | ||
35 | |||
36 | int main() | ||
37 | { | ||
38 | /* PersonPtr one(new Person); | ||
39 | PersonPtr two(new Person); | ||
40 | one->sFirstName = "Bob"; | ||
41 | one->sLastName = "Smith"; | ||
42 | two->sFirstName = "Fred"; | ||
43 | two->sLastName = "Carpenter"; | ||
44 | |||
45 | Swap(one, two); | ||
46 | */ | ||
47 | |||
48 | Bu::Atom<Bu::String> sOne, sTwo; | ||
49 | sOne = "Hello"; | ||
50 | sTwo = sOne; | ||
51 | |||
52 | return 0; | ||
53 | } | ||
diff --git a/src/tests/fstrstd.cpp b/src/tests/fstrstd.cpp deleted file mode 100644 index b2fed8a..0000000 --- a/src/tests/fstrstd.cpp +++ /dev/null | |||
@@ -1,16 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include <iostream> | ||
9 | #include "bu/string.h" | ||
10 | |||
11 | int main() | ||
12 | { | ||
13 | Bu::String s("Hey there, dude.\n"); | ||
14 | |||
15 | // std::cout << s << 5; | ||
16 | } | ||
diff --git a/src/tests/hash.cpp b/src/tests/hash.cpp deleted file mode 100644 index 7cefb79..0000000 --- a/src/tests/hash.cpp +++ /dev/null | |||
@@ -1,31 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include "bu/hash.h" | ||
9 | #include "bu/sptr.h" | ||
10 | |||
11 | typedef struct Bob | ||
12 | { | ||
13 | int nID; | ||
14 | } Bob; | ||
15 | |||
16 | int main() | ||
17 | { | ||
18 | Bu::Hash<int, Bu::SPtr<const Bob> > lb; | ||
19 | for( int j = 0; j < 10; j++ ) | ||
20 | { | ||
21 | Bob *b = new Bob; | ||
22 | b->nID = j; | ||
23 | lb.insert( j, b ); | ||
24 | } | ||
25 | |||
26 | for( int j = 0; j < 10; j++ ) | ||
27 | { | ||
28 | printf("%d\n", lb[j].getValue()->nID ); | ||
29 | } | ||
30 | } | ||
31 | |||
diff --git a/src/tests/hash2.cpp b/src/tests/hash2.cpp deleted file mode 100644 index 55bb4c9..0000000 --- a/src/tests/hash2.cpp +++ /dev/null | |||
@@ -1,35 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include <bu/string.h> | ||
9 | #include <bu/hash.h> | ||
10 | |||
11 | int main() | ||
12 | { | ||
13 | Bu::Hash<Bu::String, int> hCmd; | ||
14 | |||
15 | hCmd.insert("help", 5 ); | ||
16 | hCmd.insert("exit", 5 ); | ||
17 | hCmd.insert("getkey", 5 ); | ||
18 | hCmd.insert("setcrypt", 5 ); | ||
19 | hCmd.insert("user", 5 ); | ||
20 | hCmd.insert("pass", 5 ); | ||
21 | hCmd.erase("getkey"); | ||
22 | hCmd.erase("setcrypt"); | ||
23 | hCmd.insert("user", 5 ); | ||
24 | hCmd.insert("pass", 5 ); | ||
25 | hCmd.erase("pass"); | ||
26 | hCmd.erase("user"); | ||
27 | hCmd.insert("acl", 5 ); | ||
28 | hCmd.insert("owner", 5 ); | ||
29 | hCmd.insert("operator", 5 ); | ||
30 | hCmd.insert("admin", 5 ); | ||
31 | hCmd.insert("monitor", 5 ); | ||
32 | hCmd.insert("shutdown", 5 ); | ||
33 | |||
34 | return 0; | ||
35 | } | ||
diff --git a/src/tests/heap.cpp b/src/tests/heap.cpp deleted file mode 100644 index 520a57f..0000000 --- a/src/tests/heap.cpp +++ /dev/null | |||
@@ -1,120 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include <stdlib.h> | ||
9 | #include <stdio.h> | ||
10 | |||
11 | #include "bu/formatter.h" | ||
12 | #include "bu/heap.h" | ||
13 | #include "bu/string.h" | ||
14 | #include "bu/file.h" | ||
15 | |||
16 | typedef struct num | ||
17 | { | ||
18 | num( int iNum, int iOrder ) : iNum( iNum ), iOrder( iOrder ) | ||
19 | { | ||
20 | } | ||
21 | |||
22 | num( const num &src ) : iNum( src.iNum ), iOrder( src.iOrder ) | ||
23 | { | ||
24 | } | ||
25 | |||
26 | int iNum; | ||
27 | int iOrder; | ||
28 | |||
29 | bool operator<( const num &oth ) const | ||
30 | { | ||
31 | if( iNum == oth.iNum ) | ||
32 | return iOrder < oth.iOrder; | ||
33 | return iNum < oth.iNum; | ||
34 | } | ||
35 | bool operator>( const num &oth ) const | ||
36 | { | ||
37 | return iNum > oth.iNum; | ||
38 | } | ||
39 | } num; | ||
40 | |||
41 | void printHeap( Bu::Heap<Bu::String> &h, int j ) | ||
42 | { | ||
43 | // return; | ||
44 | Bu::String sFName = Bu::String("graph-step-%1.dot").arg( j, Bu::Fmt().width(2).fill('0') ); | ||
45 | Bu::File fOut( sFName, Bu::File::WriteNew ); | ||
46 | Bu::Formatter f( fOut ); | ||
47 | f << "Graph step: " << j << ", total size: " << h.getSize() << f.nl; | ||
48 | for( Bu::Heap<Bu::String>::iterator i = h.begin(); i; i++ ) | ||
49 | { | ||
50 | f << *i << f.nl; | ||
51 | } | ||
52 | f << f.nl; | ||
53 | } | ||
54 | |||
55 | int main() | ||
56 | { | ||
57 | /* | ||
58 | Bu::Heap<num> hNum; | ||
59 | |||
60 | for( int j = 0; j < 30; j++ ) | ||
61 | { | ||
62 | int r = rand()%10; | ||
63 | printf("Pushing: %d, top: ", r ); | ||
64 | hNum.enqueue( num( r, j ) ); | ||
65 | printf("%d\n", hNum.peek().iNum ); | ||
66 | } | ||
67 | |||
68 | while( !hNum.isEmpty() ) | ||
69 | { | ||
70 | printf("(%d:%d) ", hNum.peek().iOrder, hNum.peek().iNum ); | ||
71 | hNum.dequeue(); | ||
72 | } | ||
73 | printf("\n"); | ||
74 | */ | ||
75 | Bu::Heap<Bu::String> hStr; | ||
76 | int j = 0; | ||
77 | |||
78 | hStr.enqueue("George"); | ||
79 | printHeap( hStr, j++ ); | ||
80 | hStr.enqueue("George"); | ||
81 | printHeap( hStr, j++ ); | ||
82 | hStr.enqueue("Sam"); | ||
83 | printHeap( hStr, j++ ); | ||
84 | hStr.enqueue("Abby"); | ||
85 | printHeap( hStr, j++ ); | ||
86 | hStr.enqueue("Zorro"); | ||
87 | printHeap( hStr, j++ ); | ||
88 | hStr.enqueue("Brianna"); | ||
89 | printHeap( hStr, j++ ); | ||
90 | hStr.enqueue("Kate"); | ||
91 | printHeap( hStr, j++ ); | ||
92 | hStr.enqueue("Soggy"); | ||
93 | printHeap( hStr, j++ ); | ||
94 | |||
95 | while( !hStr.isEmpty() ) | ||
96 | { | ||
97 | printf("\"%s\" ", hStr.dequeue().getStr() ); | ||
98 | printHeap( hStr, j++ ); | ||
99 | } | ||
100 | printf("\n"); | ||
101 | |||
102 | Bu::List<Bu::String> lStr; | ||
103 | |||
104 | lStr.insertSorted("George"); | ||
105 | lStr.insertSorted("George"); | ||
106 | lStr.insertSorted("Sam"); | ||
107 | lStr.insertSorted("Abby"); | ||
108 | lStr.insertSorted("Zorro"); | ||
109 | lStr.insertSorted("Brianna"); | ||
110 | lStr.insertSorted("Kate"); | ||
111 | lStr.insertSorted("Soggy"); | ||
112 | for( Bu::List<Bu::String>::iterator i = lStr.begin(); i; i++ ) | ||
113 | { | ||
114 | printf("\"%s\" ", (*i).getStr() ); | ||
115 | } | ||
116 | printf("\n"); | ||
117 | |||
118 | return 0; | ||
119 | } | ||
120 | |||
diff --git a/src/tests/itoheap.cpp b/src/tests/itoheap.cpp deleted file mode 100644 index ec06b90..0000000 --- a/src/tests/itoheap.cpp +++ /dev/null | |||
@@ -1,70 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include <stdio.h> | ||
9 | #include <stdlib.h> | ||
10 | #include <unistd.h> | ||
11 | |||
12 | #include "bu/itoheap.h" | ||
13 | #include "bu/ito.h" | ||
14 | |||
15 | class Consumer : public Bu::Ito | ||
16 | { | ||
17 | public: | ||
18 | Consumer() | ||
19 | { | ||
20 | } | ||
21 | |||
22 | virtual ~Consumer() | ||
23 | { | ||
24 | } | ||
25 | |||
26 | void run() | ||
27 | { | ||
28 | for( int j = 0; j < 10; j++ ) | ||
29 | { | ||
30 | printf("Trying to read [%d].\n", j ); | ||
31 | |||
32 | try | ||
33 | { | ||
34 | int iNum = hInt.dequeue( 0, 500000 ); | ||
35 | printf("Read %d\n", iNum ); | ||
36 | } | ||
37 | catch( Bu::HeapException &e ) | ||
38 | { | ||
39 | printf("Nothing yet...\n"); | ||
40 | } | ||
41 | } | ||
42 | } | ||
43 | |||
44 | Bu::ItoHeap<int> hInt; | ||
45 | }; | ||
46 | |||
47 | |||
48 | int main() | ||
49 | { | ||
50 | Consumer c; | ||
51 | |||
52 | for( int j = 0; j < 3; j++ ) | ||
53 | { | ||
54 | int iNum = rand()%10; | ||
55 | printf("Enqueuing %d.\n", iNum ); | ||
56 | c.hInt.enqueue( iNum ); | ||
57 | } | ||
58 | |||
59 | printf("Sarting consumer.\n"); | ||
60 | c.start(); | ||
61 | |||
62 | for( int j = 0; j < 5; j++ ) | ||
63 | { | ||
64 | sleep( 1 ); | ||
65 | int iNum = rand()%10; | ||
66 | printf("Enqueuing %d.\n", iNum ); | ||
67 | c.hInt.enqueue( iNum ); | ||
68 | } | ||
69 | } | ||
70 | |||
diff --git a/src/tests/itoqueue1.cpp b/src/tests/itoqueue1.cpp deleted file mode 100644 index 27cb93c..0000000 --- a/src/tests/itoqueue1.cpp +++ /dev/null | |||
@@ -1,115 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include <string> | ||
9 | #include "bu/ito.h" | ||
10 | #include "bu/itoqueue.h" | ||
11 | #include <stdlib.h> | ||
12 | #include <stdio.h> | ||
13 | |||
14 | class Reader : public Bu::Ito | ||
15 | { | ||
16 | public: | ||
17 | Reader( Bu::ItoQueue<std::string *> &q, int id ) : | ||
18 | q( q ), | ||
19 | id( id ) | ||
20 | { | ||
21 | } | ||
22 | |||
23 | void run() | ||
24 | { | ||
25 | for( int i = 0; i < 10; i++ ) | ||
26 | { | ||
27 | std::string *pStr = q.dequeue( true ); | ||
28 | if( pStr == NULL ) | ||
29 | { | ||
30 | printf("Null received...\n"); | ||
31 | } | ||
32 | else | ||
33 | { | ||
34 | printf("[%d] read: %s\n", id, pStr->c_str() ); | ||
35 | delete pStr; | ||
36 | } | ||
37 | usleep( (int)(((double)rand())/((double)RAND_MAX)*2000000.0) ); | ||
38 | } | ||
39 | } | ||
40 | |||
41 | private: | ||
42 | Bu::ItoQueue<std::string *> &q; | ||
43 | int id; | ||
44 | }; | ||
45 | |||
46 | class Writer : public Bu::Ito | ||
47 | { | ||
48 | public: | ||
49 | Writer( Bu::ItoQueue<std::string *> &q, int id, const char *strbase ) : | ||
50 | q( q ), | ||
51 | strbase( strbase ), | ||
52 | id( id ) | ||
53 | { | ||
54 | } | ||
55 | |||
56 | void run() | ||
57 | { | ||
58 | for( int i = 0; i < 11; i++ ) | ||
59 | { | ||
60 | usleep( (int)(((double)rand())/((double)RAND_MAX)*2000000.0) ); | ||
61 | q.enqueue( new std::string( strbase ) ); | ||
62 | printf("[%d] write: %s\n", id, strbase ); | ||
63 | } | ||
64 | } | ||
65 | |||
66 | private: | ||
67 | Bu::ItoQueue<std::string *> &q; | ||
68 | const char *strbase; | ||
69 | int id; | ||
70 | }; | ||
71 | |||
72 | int main() | ||
73 | { | ||
74 | Writer *wr[5]; | ||
75 | Reader *rd[5]; | ||
76 | const char bob[][7]={ | ||
77 | {"Test 1"}, | ||
78 | {"Test 2"}, | ||
79 | {"Test 3"}, | ||
80 | {"Test 4"}, | ||
81 | {"Test 5"} | ||
82 | }; | ||
83 | |||
84 | Bu::ItoQueue<std::string *> q; | ||
85 | |||
86 | for( int j = 0; j < 5; j++ ) | ||
87 | { | ||
88 | wr[j] = new Writer( q, j, bob[j] ); | ||
89 | rd[j] = new Reader( q, j ); | ||
90 | } | ||
91 | |||
92 | for( int j = 0; j < 5; j++ ) | ||
93 | { | ||
94 | rd[j]->start(); | ||
95 | } | ||
96 | |||
97 | for( int j = 0; j < 5; j++ ) | ||
98 | { | ||
99 | wr[j]->start(); | ||
100 | } | ||
101 | |||
102 | for( int j = 0; j < 5; j++ ) | ||
103 | { | ||
104 | rd[j]->join(); | ||
105 | } | ||
106 | |||
107 | for( int j = 0; j < 5; j++ ) | ||
108 | { | ||
109 | delete wr[j]; | ||
110 | delete rd[j]; | ||
111 | } | ||
112 | |||
113 | return 0; | ||
114 | } | ||
115 | |||
diff --git a/src/tests/itoqueue2.cpp b/src/tests/itoqueue2.cpp deleted file mode 100644 index 10bc566..0000000 --- a/src/tests/itoqueue2.cpp +++ /dev/null | |||
@@ -1,87 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include <string> | ||
9 | #include "bu/ito.h" | ||
10 | #include "bu/itoqueue.h" | ||
11 | #include <errno.h> | ||
12 | #include <stdio.h> | ||
13 | |||
14 | class Reader : public Bu::Ito | ||
15 | { | ||
16 | public: | ||
17 | Reader( Bu::ItoQueue<std::string *> &q, int id ) : | ||
18 | q( q ), | ||
19 | id( id ) | ||
20 | { | ||
21 | } | ||
22 | |||
23 | void run() | ||
24 | { | ||
25 | for( int i = 0; i < 10; i++ ) | ||
26 | { | ||
27 | std::string *pStr = q.dequeue( 0, 500000 ); | ||
28 | if( pStr == NULL ) | ||
29 | { | ||
30 | printf("Null received...\n"); | ||
31 | i--; | ||
32 | } | ||
33 | else | ||
34 | { | ||
35 | printf("[%d] read: %s\n", id, pStr->c_str() ); | ||
36 | delete pStr; | ||
37 | } | ||
38 | } | ||
39 | } | ||
40 | |||
41 | private: | ||
42 | Bu::ItoQueue<std::string *> &q; | ||
43 | int id; | ||
44 | }; | ||
45 | |||
46 | class Writer : public Bu::Ito | ||
47 | { | ||
48 | public: | ||
49 | Writer( Bu::ItoQueue<std::string *> &q, int id, const char *strbase ) : | ||
50 | q( q ), | ||
51 | strbase( strbase ), | ||
52 | id( id ) | ||
53 | { | ||
54 | } | ||
55 | |||
56 | void run() | ||
57 | { | ||
58 | for( int i = 0; i < 11; i++ ) | ||
59 | { | ||
60 | sleep( 2 ); | ||
61 | printf("[%d] write: %s\n", id, strbase ); | ||
62 | q.enqueue( new std::string( strbase ) ); | ||
63 | } | ||
64 | } | ||
65 | |||
66 | private: | ||
67 | Bu::ItoQueue<std::string *> &q; | ||
68 | const char *strbase; | ||
69 | int id; | ||
70 | }; | ||
71 | |||
72 | int main() | ||
73 | { | ||
74 | printf("ETIMEDOUT: %d\n", ETIMEDOUT ); | ||
75 | Bu::ItoQueue<std::string *> q; | ||
76 | Writer wr( q, 0, "writer" ); | ||
77 | Reader rd( q, 0 ); | ||
78 | |||
79 | rd.start(); | ||
80 | wr.start(); | ||
81 | |||
82 | rd.join(); | ||
83 | wr.join(); | ||
84 | |||
85 | return 0; | ||
86 | } | ||
87 | |||
diff --git a/src/tests/itoserver.cpp b/src/tests/itoserver.cpp deleted file mode 100644 index 48ef527..0000000 --- a/src/tests/itoserver.cpp +++ /dev/null | |||
@@ -1,80 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include "bu/itoserver.h" | ||
9 | #include "bu/protocol.h" | ||
10 | #include "bu/client.h" | ||
11 | |||
12 | #define BU_TRACE | ||
13 | #include "bu/trace.h" | ||
14 | |||
15 | class ProtocolEcho : public Bu::Protocol | ||
16 | { | ||
17 | public: | ||
18 | ProtocolEcho() | ||
19 | { | ||
20 | TRACE(); | ||
21 | } | ||
22 | virtual ~ProtocolEcho() | ||
23 | { | ||
24 | TRACE(); | ||
25 | } | ||
26 | |||
27 | virtual void onNewConnection( Bu::Client * ) | ||
28 | { | ||
29 | TRACE(); | ||
30 | // Huh... | ||
31 | } | ||
32 | |||
33 | virtual void onNewData( Bu::Client *pClient ) | ||
34 | { | ||
35 | TRACE(); | ||
36 | char buf[1024]; | ||
37 | while( pClient->hasInput() ) | ||
38 | { | ||
39 | int iAmnt = pClient->read( buf, 1024 ); | ||
40 | pClient->write( buf, iAmnt ); | ||
41 | } | ||
42 | } | ||
43 | }; | ||
44 | |||
45 | class TestServer : public Bu::ItoServer | ||
46 | { | ||
47 | public: | ||
48 | TestServer() | ||
49 | { | ||
50 | TRACE(); | ||
51 | } | ||
52 | virtual ~TestServer() | ||
53 | { | ||
54 | TRACE(); | ||
55 | } | ||
56 | |||
57 | virtual void onNewConnection( Bu::Client *pClient, int ) | ||
58 | { | ||
59 | TRACE(); | ||
60 | pClient->setProtocol( new ProtocolEcho() ); | ||
61 | } | ||
62 | |||
63 | virtual void onClosedConnection( Bu::Client *pClient ) | ||
64 | { | ||
65 | TRACE(); | ||
66 | delete pClient->getProtocol(); | ||
67 | } | ||
68 | }; | ||
69 | |||
70 | int main() | ||
71 | { | ||
72 | TRACE(); | ||
73 | |||
74 | TestServer ts; | ||
75 | |||
76 | ts.addPort( 5555 ); | ||
77 | ts.start(); | ||
78 | ts.join(); | ||
79 | } | ||
80 | |||
diff --git a/src/tests/list.cpp b/src/tests/list.cpp deleted file mode 100644 index aa3d32d..0000000 --- a/src/tests/list.cpp +++ /dev/null | |||
@@ -1,77 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include "bu/list.h" | ||
9 | #include <list> | ||
10 | |||
11 | typedef struct Bob | ||
12 | { | ||
13 | int nID; | ||
14 | } Bob; | ||
15 | |||
16 | int main() | ||
17 | { | ||
18 | Bu::List<int> l; | ||
19 | |||
20 | l.append( 0 ); | ||
21 | |||
22 | for( int j = 3; j <= 21; j += 3 ) | ||
23 | { | ||
24 | l.append( j ); | ||
25 | l.prepend( -j ); | ||
26 | } | ||
27 | |||
28 | { | ||
29 | Bu::List<int>::iterator i = l.begin(); | ||
30 | Bu::List<int>::iterator j = i; | ||
31 | int a, b; | ||
32 | a = *j; | ||
33 | printf("end: %s\n", (j != l.end())?"no":"yes"); | ||
34 | j--; | ||
35 | printf("end: %s\n", (j != l.end())?"no":"yes"); | ||
36 | j++; | ||
37 | printf("end: %s\n", (j != l.end())?"no":"yes"); | ||
38 | i = j; | ||
39 | b = *i; | ||
40 | printf("%d -> %d\n", a, b ); | ||
41 | } | ||
42 | |||
43 | for( Bu::List<int>::iterator i = l.begin(); i != l.end(); i++ ) | ||
44 | { | ||
45 | printf("%d ", *i ); | ||
46 | } | ||
47 | printf("\n"); | ||
48 | for( Bu::List<int>::iterator i = l.begin(); i != l.end(); i++ ) | ||
49 | { | ||
50 | Bu::List<int>::iterator j = i; j--; | ||
51 | l.erase( i ); | ||
52 | i = j; | ||
53 | if( i != l.end() ) | ||
54 | printf("!%d ", *i ); | ||
55 | } | ||
56 | |||
57 | printf("\n\n"); | ||
58 | |||
59 | Bu::List<Bob> lb; | ||
60 | for( int j = 0; j < 10; j++ ) | ||
61 | { | ||
62 | Bob b; | ||
63 | b.nID = j; | ||
64 | lb.append( b ); | ||
65 | } | ||
66 | |||
67 | const Bu::List<Bob> rb = lb; | ||
68 | |||
69 | for( Bu::List<Bob>::const_iterator i = rb.begin(); i != rb.end(); i++ ) | ||
70 | { | ||
71 | //i->nID += 2; | ||
72 | //(*i).nID = 4; | ||
73 | printf("%d ", i->nID ); | ||
74 | } | ||
75 | printf("\n\n"); | ||
76 | } | ||
77 | |||
diff --git a/src/tests/list2.cpp b/src/tests/list2.cpp deleted file mode 100644 index 567370e..0000000 --- a/src/tests/list2.cpp +++ /dev/null | |||
@@ -1,26 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include <bu/list.h> | ||
9 | #include <bu/sio.h> | ||
10 | |||
11 | using namespace Bu; | ||
12 | |||
13 | int main() | ||
14 | { | ||
15 | List<int64_t> lInt; | ||
16 | |||
17 | lInt.append( 512 ); | ||
18 | lInt.append( 1024 ); | ||
19 | lInt.append( 4096 ); | ||
20 | lInt.append( 12 ); | ||
21 | lInt.erase( 12 ); | ||
22 | lInt.append( 12 ); | ||
23 | lInt.erase( 12 ); | ||
24 | lInt.append( 12 ); | ||
25 | } | ||
26 | |||
diff --git a/src/tests/listsort.cpp b/src/tests/listsort.cpp deleted file mode 100644 index 4873a05..0000000 --- a/src/tests/listsort.cpp +++ /dev/null | |||
@@ -1,79 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include <bu/list.h> | ||
9 | #include <bu/sio.h> | ||
10 | #include <bu/string.h> | ||
11 | |||
12 | using namespace Bu; | ||
13 | |||
14 | int main() | ||
15 | { | ||
16 | /* | ||
17 | List<int> il; | ||
18 | il.append( 5 ); | ||
19 | il.append( 12 ); | ||
20 | il.append( 0 ); | ||
21 | il.append( 7 ); | ||
22 | il.append( 3 ); | ||
23 | il.append( 5 ); | ||
24 | Bu::__basicLTCmp<int> cmp; | ||
25 | il.sortI( cmp ); | ||
26 | */ | ||
27 | |||
28 | String a("Soggy"), b("Sam"); | ||
29 | |||
30 | if( a < b ) | ||
31 | { | ||
32 | sio << "Bad" << sio.nl; | ||
33 | } | ||
34 | else | ||
35 | { | ||
36 | sio << "Good" << sio.nl; | ||
37 | } | ||
38 | |||
39 | typedef List<String> StrList; | ||
40 | |||
41 | StrList lNames; | ||
42 | |||
43 | lNames.append("George"); | ||
44 | lNames.append("Sam"); | ||
45 | lNames.append("Abby"); | ||
46 | lNames.append("Zorro"); | ||
47 | lNames.append("Brianna"); | ||
48 | lNames.append("Kate"); | ||
49 | lNames.append("Soggy"); | ||
50 | |||
51 | sio << "Names: " << lNames << sio.nl; | ||
52 | lNames.sort(); | ||
53 | |||
54 | sio << "Names: " << lNames << sio.nl; | ||
55 | |||
56 | StrList lNames2; | ||
57 | |||
58 | lNames2.insertSorted("George"); | ||
59 | lNames2.insertSorted("Sam"); | ||
60 | lNames2.insertSorted("Abby"); | ||
61 | lNames2.insertSorted("Zorro"); | ||
62 | lNames2.insertSorted("Brianna"); | ||
63 | lNames2.insertSorted("Kate"); | ||
64 | lNames2.insertSorted("Soggy"); | ||
65 | |||
66 | sio << "Names: " << lNames2 << sio.nl; | ||
67 | |||
68 | if( lNames == lNames2 ) | ||
69 | { | ||
70 | sio << "They're the same." << sio.nl; | ||
71 | } | ||
72 | else | ||
73 | { | ||
74 | sio << "They're different." << sio.nl; | ||
75 | } | ||
76 | |||
77 | return 0; | ||
78 | } | ||
79 | |||
diff --git a/src/tests/logger.cpp b/src/tests/logger.cpp deleted file mode 100644 index e97193c..0000000 --- a/src/tests/logger.cpp +++ /dev/null | |||
@@ -1,37 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include "bu/logger.h" | ||
9 | #include <errno.h> | ||
10 | #include <stdlib.h> | ||
11 | |||
12 | class Thing | ||
13 | { | ||
14 | public: | ||
15 | Thing() | ||
16 | { | ||
17 | lineLog( 2, "Want a thing?"); | ||
18 | } | ||
19 | |||
20 | void go( int ) | ||
21 | { | ||
22 | lineLog( 1, "GO!!!!"); | ||
23 | } | ||
24 | }; | ||
25 | |||
26 | int main() | ||
27 | { | ||
28 | setLogLevel( 4 ); | ||
29 | setLogFormat("%L: %y-%02m-%02d %h:%02M:%02s %f:%l:%F: %t"); | ||
30 | lineLog( 5, "Hey, error: %s", strerror( errno ) ); | ||
31 | |||
32 | logHexDump( 5, "This is a test of the hex-dump facility", 16, "Random stuff"); | ||
33 | |||
34 | Thing gh; | ||
35 | gh.go( 6 ); | ||
36 | } | ||
37 | |||
diff --git a/src/tests/md5.cpp b/src/tests/md5.cpp deleted file mode 100644 index a32f669..0000000 --- a/src/tests/md5.cpp +++ /dev/null | |||
@@ -1,34 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include "bu/sio.h" | ||
9 | #include "bu/file.h" | ||
10 | #include "bu/md5.h" | ||
11 | |||
12 | using Bu::sio; | ||
13 | |||
14 | int main( int argc, char *argv[] ) | ||
15 | { | ||
16 | argv++, argc--; | ||
17 | for(; *argv; argv++ ) | ||
18 | { | ||
19 | Bu::File fIn( *argv, Bu::File::Read ); | ||
20 | Bu::Md5 m; | ||
21 | |||
22 | char buf[100000]; | ||
23 | for(;;) | ||
24 | { | ||
25 | int iRead = fIn.read( buf, 100000 ); | ||
26 | m.addData( buf, iRead ); | ||
27 | if( iRead < 100000 ) | ||
28 | break; | ||
29 | } | ||
30 | |||
31 | sio << m.getHexResult() << " *" << *argv << sio.nl; | ||
32 | } | ||
33 | } | ||
34 | |||
diff --git a/src/tests/minicron.cpp b/src/tests/minicron.cpp deleted file mode 100644 index aed63e2..0000000 --- a/src/tests/minicron.cpp +++ /dev/null | |||
@@ -1,63 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include "bu/minicron.h" | ||
9 | #include "bu/sio.h" | ||
10 | |||
11 | #include <unistd.h> | ||
12 | |||
13 | using namespace Bu; | ||
14 | |||
15 | Bu::MiniCron mCron; | ||
16 | |||
17 | void job0( Bu::MiniCron::Job &job ) | ||
18 | { | ||
19 | sio << time( NULL ) << ": job0( id = " << job.getId() << ", count = " | ||
20 | << job.getRunCount() << ")" << sio.nl; | ||
21 | } | ||
22 | |||
23 | void job1( Bu::MiniCron::Job &job ) | ||
24 | { | ||
25 | sio << time( NULL ) << ": job1( id = " << job.getId() << ", count = " | ||
26 | << job.getRunCount() << ")" << sio.nl; | ||
27 | mCron.removeJob( 4 ); | ||
28 | } | ||
29 | |||
30 | void job2( Bu::MiniCron::Job &job ) | ||
31 | { | ||
32 | sio << time( NULL ) << ": job2( id = " << job.getId() << ", count = " | ||
33 | << job.getRunCount() << ")" << sio.nl; | ||
34 | } | ||
35 | |||
36 | void job3( Bu::MiniCron::Job &job ) | ||
37 | { | ||
38 | sio << time( NULL ) << ": job3( id = " << job.getId() << ", count = " | ||
39 | << job.getRunCount() << ")" << sio.nl; | ||
40 | } | ||
41 | |||
42 | int main() | ||
43 | { | ||
44 | mCron.addJob( | ||
45 | "job0", slot( &job0 ), MiniCron::TimerInterval( time(NULL)+3, 5 ) ); | ||
46 | mCron.addJob( | ||
47 | "job1", slot( &job1 ), MiniCron::TimerInterval( time(NULL)+10, 8 ) ); | ||
48 | mCron.addJob( | ||
49 | "job2", slot( &job2 ), MiniCron::TimerBasic("weekly wed 17") ); | ||
50 | mCron.addJob( | ||
51 | "job3", slot( &job3 ), MiniCron::TimerInterval( time(NULL)+1, 2 ) ); | ||
52 | |||
53 | sio << time( NULL ) << ": Program started." << sio.nl; | ||
54 | |||
55 | for(;;) | ||
56 | { | ||
57 | usleep( 50000 ); | ||
58 | mCron.poll(); | ||
59 | } | ||
60 | |||
61 | return 0; | ||
62 | } | ||
63 | |||
diff --git a/src/tests/mmparse.cpp b/src/tests/mmparse.cpp deleted file mode 100644 index c1ce862..0000000 --- a/src/tests/mmparse.cpp +++ /dev/null | |||
@@ -1,22 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include "bu/minimacro.h" | ||
9 | #include "bu/string.h" | ||
10 | |||
11 | int main() | ||
12 | { | ||
13 | Bu::MiniMacro mm; | ||
14 | |||
15 | mm.addVar("name", "Mike"); | ||
16 | mm.addVar("age", "no"); | ||
17 | |||
18 | printf("%s\n", mm.parse("Hey there {=name:toupper():tolower()}, how are you?").getStr() ); | ||
19 | |||
20 | return 0; | ||
21 | } | ||
22 | |||
diff --git a/src/tests/multiserver.cpp b/src/tests/multiserver.cpp deleted file mode 100644 index 12f4681..0000000 --- a/src/tests/multiserver.cpp +++ /dev/null | |||
@@ -1,76 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include "bu/multiserver.h" | ||
9 | #include "bu/protocol.h" | ||
10 | #include "bu/client.h" | ||
11 | |||
12 | class ProtocolRaw : public Bu::Protocol | ||
13 | { | ||
14 | public: | ||
15 | virtual void onNewConnection( Bu::Client *pClient ) | ||
16 | { | ||
17 | pClient->write("Raw echo\n"); | ||
18 | } | ||
19 | |||
20 | virtual void onNewData( Bu::Client *pClient ) | ||
21 | { | ||
22 | char buf[1024]; | ||
23 | while( pClient->hasInput() ) | ||
24 | { | ||
25 | int iAmnt = pClient->read( buf, 1024 ); | ||
26 | pClient->write( buf, iAmnt ); | ||
27 | } | ||
28 | } | ||
29 | }; | ||
30 | |||
31 | class ProtocolRot13 : public Bu::Protocol | ||
32 | { | ||
33 | public: | ||
34 | virtual void onNewConnection( Bu::Client *pClient ) | ||
35 | { | ||
36 | pClient->write("Rot13 echo\n"); | ||
37 | } | ||
38 | |||
39 | virtual void onNewData( Bu::Client *pClient ) | ||
40 | { | ||
41 | while( pClient->hasInput() ) | ||
42 | { | ||
43 | char sTmp[1024]; | ||
44 | int iAmnt = pClient->read( sTmp, 1024 ); | ||
45 | for( int j = 0; j < iAmnt; j++ ) | ||
46 | { | ||
47 | if( sTmp[j] >= 'a' && sTmp[j] <= 'z' ) | ||
48 | { | ||
49 | sTmp[j] = ((sTmp[j]-'a'+13)%26) + 'a'; | ||
50 | } | ||
51 | else if( sTmp[j] >= 'A' && sTmp[j] <= 'Z' ) | ||
52 | { | ||
53 | sTmp[j] = ((sTmp[j]-'A'+13)%26) + 'A'; | ||
54 | } | ||
55 | } | ||
56 | pClient->write( sTmp, iAmnt ); | ||
57 | } | ||
58 | } | ||
59 | }; | ||
60 | |||
61 | int main() | ||
62 | { | ||
63 | Bu::MultiServer msMain; | ||
64 | |||
65 | msMain.addProtocol( Bu::genProtocol<ProtocolRaw>, 5550 ); | ||
66 | msMain.addProtocol( Bu::genProtocol<ProtocolRot13>, 5551 ); | ||
67 | msMain.setTimeout( 5, 0 ); | ||
68 | |||
69 | for(;;) | ||
70 | { | ||
71 | msMain.scan(); | ||
72 | } | ||
73 | |||
74 | return 0; | ||
75 | } | ||
76 | |||
diff --git a/src/tests/procs.cpp b/src/tests/procs.cpp deleted file mode 100644 index 94d2cc5..0000000 --- a/src/tests/procs.cpp +++ /dev/null | |||
@@ -1,37 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include "bu/process.h" | ||
9 | |||
10 | #include <stdio.h> | ||
11 | |||
12 | int main() | ||
13 | { | ||
14 | Bu::Process p( Bu::Process::Both, "/bin/bash", "/bin/bash", "-c", "echo Hello 1>&2; echo StdOut; sleep 1; echo Yup; echo Yup 1>&2", NULL ); | ||
15 | |||
16 | char buf[1000]; | ||
17 | while( !p.isEos() ) | ||
18 | { | ||
19 | bool out, err; | ||
20 | p.select( out, err ); | ||
21 | if( out ) | ||
22 | { | ||
23 | int iSize = p.read( buf, 1000 ); | ||
24 | printf("::read=%d::\n", iSize ); | ||
25 | fwrite( buf, iSize, 1, stdout ); | ||
26 | } | ||
27 | if( err ) | ||
28 | { | ||
29 | int iSize = p.readErr( buf, 1000 ); | ||
30 | printf("::readErr=%d::\n", iSize ); | ||
31 | fwrite( buf, iSize, 1, stdout ); | ||
32 | } | ||
33 | } | ||
34 | |||
35 | return 0; | ||
36 | } | ||
37 | |||
diff --git a/src/tests/queuebuf.cpp b/src/tests/queuebuf.cpp deleted file mode 100644 index f872738..0000000 --- a/src/tests/queuebuf.cpp +++ /dev/null | |||
@@ -1,66 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include <bu/queuebuf.h> | ||
9 | #include <bu/sio.h> | ||
10 | |||
11 | using namespace Bu; | ||
12 | |||
13 | int main() | ||
14 | { | ||
15 | static const char *src = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789%#"; | ||
16 | QueueBuf qb; | ||
17 | |||
18 | for( int j = 0; j < 8; j++ ) | ||
19 | { | ||
20 | qb.write( src, 60 ); | ||
21 | } | ||
22 | |||
23 | char buf[11], bufp[11]; | ||
24 | while( !qb.isEos() ) | ||
25 | { | ||
26 | int iAmntPeek = qb.peek( bufp, 9 ); | ||
27 | int iAmntRead = qb.read( buf, 9 ); | ||
28 | if( iAmntPeek != iAmntRead ) | ||
29 | sio << "Differ: " << iAmntPeek << " vs " << iAmntRead << sio.nl; | ||
30 | buf[iAmntRead] = '\0'; | ||
31 | bufp[iAmntPeek] = '\0'; | ||
32 | if( memcmp( buf, bufp, iAmntPeek ) ) | ||
33 | { | ||
34 | sio << "Buffers differ" << sio.nl | ||
35 | << " " << buf << sio.nl | ||
36 | << " " << bufp << sio.nl; | ||
37 | } | ||
38 | else | ||
39 | sio << "Read: >>" << buf << "<<" << sio.nl; | ||
40 | } | ||
41 | |||
42 | sio << sio.nl << sio.nl << sio.nl << "Seek test:" << sio.nl << sio.nl; | ||
43 | |||
44 | for( int j = 0; j < 5; j++ ) | ||
45 | { | ||
46 | qb.write( src, 25 ); | ||
47 | qb.write( src+10, 25 ); | ||
48 | } | ||
49 | |||
50 | char bufa[26]; | ||
51 | char bufb[26]; | ||
52 | ::memcpy( bufb, src+10, 15 ); | ||
53 | ::memcpy( bufb+15, src+10, 10 ); | ||
54 | bufb[25] = '\0'; | ||
55 | sio << "Comparing to '" << bufb << "'" << sio.nl; | ||
56 | qb.seek( 10 ); | ||
57 | while( !qb.isEos() ) | ||
58 | { | ||
59 | bufa[qb.read( bufa, 25 )] = '\0'; | ||
60 | qb.seek( 25 ); | ||
61 | if( memcmp( bufa, bufb, 25 ) ) | ||
62 | sio << "Differ?" << sio.nl; | ||
63 | sio << "=== '" << bufa << "' == '" << bufb << "'" << sio.nl; | ||
64 | } | ||
65 | } | ||
66 | |||
diff --git a/src/tests/regex.cpp b/src/tests/regex.cpp deleted file mode 100644 index 376fbb2..0000000 --- a/src/tests/regex.cpp +++ /dev/null | |||
@@ -1,38 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include <bu/regex.h> | ||
9 | #include <stdio.h> | ||
10 | |||
11 | int main( int argc, char *argv[] ) | ||
12 | { | ||
13 | if( argc < 3 ) | ||
14 | { | ||
15 | printf("No... %s <regex> <string>\n\n", argv[0] ); | ||
16 | return 0; | ||
17 | } | ||
18 | |||
19 | Bu::RegEx re( argv[1] ); | ||
20 | |||
21 | printf("Regex: %s\n", argv[1] ); | ||
22 | printf("Match: %s\n", argv[2] ); | ||
23 | |||
24 | if( re.execute( argv[2] ) ) | ||
25 | { | ||
26 | for( int j = 0; j < re.getNumSubStrings(); j++ ) | ||
27 | { | ||
28 | printf("SubStr %d: %s\n", j, re.getSubString( j ).getStr() ); | ||
29 | } | ||
30 | } | ||
31 | else | ||
32 | { | ||
33 | printf("Regex did not match.\n"); | ||
34 | } | ||
35 | |||
36 | return 0; | ||
37 | } | ||
38 | |||
diff --git a/src/tests/ringbuffer.cpp b/src/tests/ringbuffer.cpp deleted file mode 100644 index da5126c..0000000 --- a/src/tests/ringbuffer.cpp +++ /dev/null | |||
@@ -1,38 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include "bu/ringbuffer.h" | ||
9 | #include <stdlib.h> | ||
10 | #include <stdint.h> | ||
11 | #include <stdio.h> | ||
12 | |||
13 | int main() | ||
14 | { | ||
15 | Bu::RingBuffer<uint32_t> ibuf( 10 ); | ||
16 | |||
17 | for( int k = 0; k < 2; k++ ) | ||
18 | { | ||
19 | int j = 1; | ||
20 | for(; j < 7; j++ ) | ||
21 | { | ||
22 | ibuf.enqueue( j ); | ||
23 | } | ||
24 | |||
25 | for(; j < 20; j++ ) | ||
26 | { | ||
27 | ibuf.enqueue( j ); | ||
28 | printf("- %d\n", ibuf.dequeue() ); | ||
29 | } | ||
30 | |||
31 | for(;;) | ||
32 | { | ||
33 | if( ibuf.isEmpty() ) break; | ||
34 | printf(". %d\n", ibuf.dequeue() ); | ||
35 | } | ||
36 | } | ||
37 | } | ||
38 | |||
diff --git a/src/tests/rot13.cpp b/src/tests/rot13.cpp deleted file mode 100644 index 1530af3..0000000 --- a/src/tests/rot13.cpp +++ /dev/null | |||
@@ -1,91 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include "bu/protocol.h" | ||
9 | #include "bu/multiserver.h" | ||
10 | #include "bu/client.h" | ||
11 | #include "bu/filter.h" | ||
12 | |||
13 | using namespace Bu; | ||
14 | |||
15 | class Rot13Filter : public Filter | ||
16 | { | ||
17 | public: | ||
18 | Rot13Filter( Stream &next ) : | ||
19 | Filter( next ) | ||
20 | { | ||
21 | } | ||
22 | |||
23 | virtual ~Rot13Filter() | ||
24 | { | ||
25 | } | ||
26 | |||
27 | virtual void start() | ||
28 | { | ||
29 | } | ||
30 | |||
31 | virtual Bu::size stop() | ||
32 | { | ||
33 | return 0; | ||
34 | } | ||
35 | |||
36 | virtual Bu::size read( void *pBuf, Bu::size nBytes ) | ||
37 | { | ||
38 | return rNext.read( pBuf, nBytes ); | ||
39 | } | ||
40 | |||
41 | virtual Bu::size write( const void *pBuf, Bu::size nBytes ) | ||
42 | { | ||
43 | const char *cBuf = (const char *)pBuf; | ||
44 | char *buf = new char[nBytes]; | ||
45 | for( Bu::size j = 0; j < nBytes; j++ ) | ||
46 | { | ||
47 | if( cBuf[j] >= 'a' && cBuf[j] <= 'z' ) | ||
48 | buf[j] = (cBuf[j]-'a'+13)%26+'a'; | ||
49 | else if( cBuf[j] >= 'A' && cBuf[j] <= 'Z' ) | ||
50 | buf[j] = (cBuf[j]-'A'+13)%26+'A'; | ||
51 | else | ||
52 | buf[j] = cBuf[j]; | ||
53 | } | ||
54 | rNext.write( buf, nBytes ); | ||
55 | delete[] buf; | ||
56 | return nBytes; | ||
57 | } | ||
58 | }; | ||
59 | |||
60 | class Rot13Protocol : public Protocol | ||
61 | { | ||
62 | public: | ||
63 | void onNewConnection( Bu::Client *pClient ) | ||
64 | { | ||
65 | pClient->pushFilter<Rot13Filter>(); | ||
66 | } | ||
67 | |||
68 | void onNewData( Bu::Client *pClient ) | ||
69 | { | ||
70 | char buf[1024]; | ||
71 | while( pClient->hasInput() ) | ||
72 | { | ||
73 | int iAmnt = pClient->read( buf, 1024 ); | ||
74 | pClient->write( buf, iAmnt ); | ||
75 | } | ||
76 | } | ||
77 | }; | ||
78 | |||
79 | int main() | ||
80 | { | ||
81 | MultiServer xSrv; | ||
82 | |||
83 | xSrv.setTimeout( 5 ); | ||
84 | xSrv.addProtocol( genProtocol<Rot13Protocol>, 9999 ); | ||
85 | |||
86 | for(;;) | ||
87 | xSrv.scan(); | ||
88 | |||
89 | return 0; | ||
90 | } | ||
91 | |||
diff --git a/src/tests/serverticks.cpp b/src/tests/serverticks.cpp deleted file mode 100644 index 3872a16..0000000 --- a/src/tests/serverticks.cpp +++ /dev/null | |||
@@ -1,69 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include "bu/server.h" | ||
9 | #include "bu/client.h" | ||
10 | #include "bu/protocol.h" | ||
11 | #include <unistd.h> | ||
12 | |||
13 | class TickProtocol : public Bu::Protocol | ||
14 | { | ||
15 | public: | ||
16 | TickProtocol() | ||
17 | { | ||
18 | } | ||
19 | |||
20 | virtual ~TickProtocol() | ||
21 | { | ||
22 | } | ||
23 | |||
24 | virtual void onTick( Bu::Client *pClient ) | ||
25 | { | ||
26 | printf("tick!\n"); | ||
27 | pClient->write("tick!\n"); | ||
28 | } | ||
29 | }; | ||
30 | |||
31 | class TickServer : public Bu::Server | ||
32 | { | ||
33 | public: | ||
34 | TickServer() | ||
35 | { | ||
36 | } | ||
37 | |||
38 | virtual ~TickServer() | ||
39 | { | ||
40 | } | ||
41 | |||
42 | virtual void onNewConnection( Bu::Client *pClient, int ) | ||
43 | { | ||
44 | pClient->setProtocol( new TickProtocol() ); | ||
45 | } | ||
46 | |||
47 | virtual void onClosedConnection( Bu::Client *pClient ) | ||
48 | { | ||
49 | delete pClient->getProtocol(); | ||
50 | } | ||
51 | }; | ||
52 | |||
53 | int main( int , char *[] ) | ||
54 | { | ||
55 | TickServer ts; | ||
56 | |||
57 | ts.setTimeout( 1, 0 ); | ||
58 | ts.setAutoTick(); | ||
59 | ts.addPort( 5555 ); | ||
60 | |||
61 | for(;;) | ||
62 | { | ||
63 | ts.scan(); | ||
64 | sleep( 1 ); | ||
65 | } | ||
66 | |||
67 | return 0; | ||
68 | } | ||
69 | |||
diff --git a/src/tests/sha1.cpp b/src/tests/sha1.cpp deleted file mode 100644 index ac795e7..0000000 --- a/src/tests/sha1.cpp +++ /dev/null | |||
@@ -1,39 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include "bu/sio.h" | ||
9 | #include "bu/file.h" | ||
10 | #include "bu/sha1.h" | ||
11 | |||
12 | using namespace Bu; | ||
13 | |||
14 | int main( int argc, char *argv[] ) | ||
15 | { | ||
16 | argv++, argc--; | ||
17 | for(; *argv; argv++ ) | ||
18 | { | ||
19 | Bu::File fIn( *argv, Bu::File::Read ); | ||
20 | Bu::Sha1 m; | ||
21 | |||
22 | char buf[100000]; | ||
23 | for(;;) | ||
24 | { | ||
25 | int iRead = fIn.read( buf, 100000 ); | ||
26 | m.addData( buf, iRead ); | ||
27 | if( iRead < 100000 ) | ||
28 | break; | ||
29 | } | ||
30 | |||
31 | Bu::String sRes = m.getResult(); | ||
32 | for( Bu::String::iterator i = sRes.begin(); i; i++ ) | ||
33 | { | ||
34 | sio << Fmt::hex(2,false) << (int)(unsigned char)(*i); | ||
35 | } | ||
36 | sio << " *" << *argv << sio.nl; | ||
37 | } | ||
38 | } | ||
39 | |||
diff --git a/src/tests/sharedcore.cpp b/src/tests/sharedcore.cpp deleted file mode 100644 index c68f07b..0000000 --- a/src/tests/sharedcore.cpp +++ /dev/null | |||
@@ -1,98 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include "bu/sharedcore.h" | ||
9 | #include "bu/sio.h" | ||
10 | |||
11 | using namespace Bu; | ||
12 | |||
13 | struct ShintCore | ||
14 | { | ||
15 | int val; | ||
16 | }; | ||
17 | class Shint : public Bu::SharedCore<Shint, struct ShintCore> | ||
18 | { | ||
19 | public: | ||
20 | Shint() | ||
21 | { | ||
22 | core->val = 0; | ||
23 | } | ||
24 | |||
25 | Shint( int val ) | ||
26 | { | ||
27 | core->val = val; | ||
28 | } | ||
29 | |||
30 | int getVal() const | ||
31 | { | ||
32 | return core->val; | ||
33 | } | ||
34 | |||
35 | void setValBad( int val ) | ||
36 | { | ||
37 | core->val = val; | ||
38 | } | ||
39 | |||
40 | void setVal( int val ) | ||
41 | { | ||
42 | _hardCopy(); | ||
43 | core->val = val; | ||
44 | } | ||
45 | |||
46 | bool operator==( const Shint &rhs ) | ||
47 | { | ||
48 | if( core == rhs.core ) | ||
49 | { | ||
50 | sio << "Same pointer (" << Fmt::ptr() << core << ")" << sio.nl; | ||
51 | return true; | ||
52 | } | ||
53 | if( core->val == rhs.core->val ) | ||
54 | { | ||
55 | sio << "Same value " << core->val << " (" | ||
56 | << Fmt::ptr() << core << " vs " | ||
57 | << Fmt::ptr() << rhs.core << ")" | ||
58 | << sio.nl; | ||
59 | return true; | ||
60 | } | ||
61 | sio << "Different" << sio.nl; | ||
62 | return false; | ||
63 | } | ||
64 | }; | ||
65 | |||
66 | #define line( x ) sio << __FILE__ ": " << __LINE__ << ": " << #x << sio.nl; x | ||
67 | |||
68 | int main() | ||
69 | { | ||
70 | line( Shint a; ) | ||
71 | line( Shint b( 5 ); ) | ||
72 | |||
73 | line( a == b; ) | ||
74 | |||
75 | line( b = a; ) | ||
76 | line( a == b; ) | ||
77 | |||
78 | line( b.setValBad( 12 ); ) | ||
79 | sio << a.getVal() << " != " << b.getVal() << sio.nl; | ||
80 | line( a == b; ) | ||
81 | |||
82 | line( a.setVal( 3 ); ) | ||
83 | sio << a.getVal() << " != " << b.getVal() << sio.nl; | ||
84 | line( a == b; ) | ||
85 | |||
86 | line( a.setVal( b.getVal() ); ) | ||
87 | line( a == b; ) | ||
88 | |||
89 | { | ||
90 | Shint c( b ); | ||
91 | Shint d( c ); | ||
92 | sio << c.getVal(); | ||
93 | d.setVal( 43 ); | ||
94 | } | ||
95 | |||
96 | sio << b.getVal(); | ||
97 | } | ||
98 | |||
diff --git a/src/tests/signals.cpp b/src/tests/signals.cpp deleted file mode 100644 index 14bbc9c..0000000 --- a/src/tests/signals.cpp +++ /dev/null | |||
@@ -1,131 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include <bu/signals.h> | ||
9 | #include <bu/sio.h> | ||
10 | |||
11 | using namespace Bu; | ||
12 | |||
13 | class Thing | ||
14 | { | ||
15 | public: | ||
16 | Thing() : | ||
17 | iState( 82731 ) | ||
18 | { | ||
19 | } | ||
20 | |||
21 | virtual ~Thing() | ||
22 | { | ||
23 | } | ||
24 | |||
25 | void fnc0() | ||
26 | { | ||
27 | sio << iState << ": void fnc0()" << sio.nl; | ||
28 | } | ||
29 | |||
30 | void fnc1( int a ) | ||
31 | { | ||
32 | sio << iState << ": void fnc1( " << a << " )" << sio.nl; | ||
33 | } | ||
34 | |||
35 | void fnc2( int a, Bu::String b ) | ||
36 | { | ||
37 | sio << iState << ": void fnc2( " << a << ", \"" << b << "\" )" << sio.nl; | ||
38 | } | ||
39 | |||
40 | void fnc3( int a, Bu::String b, double c ) | ||
41 | { | ||
42 | sio << iState << ": void fnc3( " << a << ", \"" << b << "\", " << c << " )" << sio.nl; | ||
43 | } | ||
44 | |||
45 | void fnc4( int a, Bu::String b, double c, char d ) | ||
46 | { | ||
47 | sio << iState << ": void fnc4( " << a << ", \"" << b << "\", " << c << ", '" << d << "' )" << sio.nl; | ||
48 | } | ||
49 | |||
50 | void fnc5( int a, Bu::String b, double c, char d, long e ) | ||
51 | { | ||
52 | sio << iState << ": void fnc5( " << a << ", \"" << b << "\", " << c << ", '" << d << "', " << e << " )" << sio.nl; | ||
53 | } | ||
54 | |||
55 | private: | ||
56 | int iState; | ||
57 | }; | ||
58 | |||
59 | void pfnc0() | ||
60 | { | ||
61 | sio << ": void pfnc0()" << sio.nl; | ||
62 | } | ||
63 | |||
64 | void pfnc1( int a ) | ||
65 | { | ||
66 | sio << ": void pfnc1( " << a << " )" << sio.nl; | ||
67 | } | ||
68 | |||
69 | void pfnc2( int a, Bu::String b ) | ||
70 | { | ||
71 | sio << ": void pfnc2( " << a << ", \"" << b << "\" )" << sio.nl; | ||
72 | } | ||
73 | |||
74 | void pfnc3( int a, Bu::String b, double c ) | ||
75 | { | ||
76 | sio << ": void pfnc3( " << a << ", \"" << b << "\", " << c << " )" << sio.nl; | ||
77 | } | ||
78 | |||
79 | void pfnc4( int a, Bu::String b, double c, char d ) | ||
80 | { | ||
81 | sio << ": void pfnc4( " << a << ", \"" << b << "\", " << c << ", '" << d << "' )" << sio.nl; | ||
82 | } | ||
83 | |||
84 | void pfnc5( int a, Bu::String b, double c, char d, long e ) | ||
85 | { | ||
86 | sio << ": void pfnc5( " << a << ", \"" << b << "\", " << c << ", '" << d << "', " << e << " )" << sio.nl; | ||
87 | } | ||
88 | |||
89 | void callit( Signal0<void> sig ) | ||
90 | { | ||
91 | sig(); | ||
92 | } | ||
93 | |||
94 | int main() | ||
95 | { | ||
96 | Thing t; | ||
97 | |||
98 | Signal0<void> cb0( slot( &t, &Thing::fnc0 ) ); | ||
99 | cb0(); | ||
100 | cb0 = slot( &pfnc0 ); | ||
101 | cb0(); | ||
102 | |||
103 | Signal1<void, int> cb1( slot( &t, &Thing::fnc1 ) ); | ||
104 | cb1( 5 ); | ||
105 | cb1 = slot( &pfnc1 ); | ||
106 | cb1( 5 ); | ||
107 | |||
108 | Signal2<void, int, Bu::String> cb2( slot( &t, &Thing::fnc2 ) ); | ||
109 | cb2( 5, "Hi there" ); | ||
110 | cb2 = slot( &pfnc2 ); | ||
111 | cb2( 5, "Hi there" ); | ||
112 | |||
113 | Signal3<void, int, Bu::String, double> cb3( slot( &t, &Thing::fnc3 ) ); | ||
114 | cb3( 5, "Hi there", 12.85 ); | ||
115 | cb3 = slot( &pfnc3 ); | ||
116 | cb3( 5, "Hi there", 12.85 ); | ||
117 | |||
118 | Signal4<void, int, Bu::String, double, char> cb4( slot( &t, &Thing::fnc4 ) ); | ||
119 | cb4( 5, "Hi there", 12.85, 'z' ); | ||
120 | cb4 = slot( &pfnc4 ); | ||
121 | cb4( 5, "Hi there", 12.85, 'z' ); | ||
122 | |||
123 | Signal5<void, int, Bu::String, double, char, long> cb5( slot( &t, &Thing::fnc5 ) ); | ||
124 | cb5( 5, "Hi there", 12.85, 'z', 849 ); | ||
125 | cb5 = slot( &pfnc5 ); | ||
126 | cb5( 5, "Hi there", 12.85, 'z', 849 ); | ||
127 | |||
128 | // Signal1<int, int> cb1( slot( &t, &Thing::fnc1 ) ); | ||
129 | // sio << "Result: " << cb1( 5 ) << sio.nl; | ||
130 | } | ||
131 | |||
diff --git a/src/tests/size.cpp b/src/tests/size.cpp deleted file mode 100644 index dfad16f..0000000 --- a/src/tests/size.cpp +++ /dev/null | |||
@@ -1,20 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include "bu/hash.h" | ||
9 | #include "bu/string.h" | ||
10 | |||
11 | #define pSize( t ) printf("%15s: %db\n", #t, sizeof( t ) ); | ||
12 | |||
13 | int main() | ||
14 | { | ||
15 | typedef Bu::Hash<char, char> charcharHash; | ||
16 | typedef Bu::Hash<Bu::String, Bu::String> strstrHash; | ||
17 | pSize( Bu::String ); | ||
18 | pSize( charcharHash ); | ||
19 | pSize( strstrHash ); | ||
20 | } | ||
diff --git a/src/tests/socketblock.cpp b/src/tests/socketblock.cpp deleted file mode 100644 index e36bb33..0000000 --- a/src/tests/socketblock.cpp +++ /dev/null | |||
@@ -1,56 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include "bu/ito.h" | ||
9 | #include "bu/tcpsocket.h" | ||
10 | #include "bu/tcpserversocket.h" | ||
11 | #include <stdio.h> | ||
12 | #include <unistd.h> | ||
13 | |||
14 | class TstServer : public Bu::Ito | ||
15 | { | ||
16 | public: | ||
17 | TstServer() : | ||
18 | s( 55678 ) | ||
19 | { | ||
20 | } | ||
21 | |||
22 | virtual void run() | ||
23 | { | ||
24 | Bu::TcpSocket c = s.accept( 45, 0 ); | ||
25 | printf("TstServer: Accetped connection.\n"); fflush( stdout ); | ||
26 | |||
27 | sleep( 1 ); | ||
28 | printf("TstServer: Trying to read 10 bytes...\n"); fflush( stdout ); | ||
29 | |||
30 | char buf[10]; | ||
31 | size_t nRead = c.read( buf, 10 ); | ||
32 | printf("TstServer: Got %d bytes...\n", nRead ); fflush( stdout ); | ||
33 | |||
34 | printf("TstServer: Closing connection...\n"); fflush( stdout ); | ||
35 | c.close(); | ||
36 | } | ||
37 | |||
38 | Bu::TcpServerSocket s; | ||
39 | }; | ||
40 | |||
41 | int main() | ||
42 | { | ||
43 | TstServer ts; | ||
44 | |||
45 | ts.start(); | ||
46 | |||
47 | printf("main: Connecting to server.\n"); fflush( stdout ); | ||
48 | Bu::TcpSocket s( "localhost", 55678 ); | ||
49 | |||
50 | printf("main: Sending 4 bytes.\n"); fflush( stdout ); | ||
51 | s.write( "aoeu", 4 ); | ||
52 | |||
53 | printf("main: Sleeping 10 seconds for good measure.\n"); fflush( stdout ); | ||
54 | sleep( 10 ); | ||
55 | } | ||
56 | |||
diff --git a/src/tests/socketbreak.cpp b/src/tests/socketbreak.cpp deleted file mode 100644 index d58ebcf..0000000 --- a/src/tests/socketbreak.cpp +++ /dev/null | |||
@@ -1,35 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include "bu/tcpserversocket.h" | ||
9 | #include "bu/tcpsocket.h" | ||
10 | #include <unistd.h> | ||
11 | |||
12 | int main() | ||
13 | { | ||
14 | Bu::TcpServerSocket sSrv( 9987 ); | ||
15 | |||
16 | Bu::TcpSocket sSend("localhost", 9987 ); | ||
17 | |||
18 | Bu::TcpSocket sRecv( sSrv.accept() ); | ||
19 | |||
20 | printf("Connected sockets.\n"); | ||
21 | |||
22 | sleep( 1 ); | ||
23 | printf("Closing sRecv.\n"); | ||
24 | sRecv.close(); | ||
25 | sleep( 1 ); | ||
26 | |||
27 | char buf[3]; | ||
28 | printf("About to write.\n"); | ||
29 | printf("write: %lld\n", sSend.write("hi", 2 ) ); | ||
30 | printf("About to read.\n"); | ||
31 | printf("read: %lld\n", sSend.read( buf, 2 ) ); | ||
32 | |||
33 | return 0; | ||
34 | } | ||
35 | |||
diff --git a/src/tests/speed.cpp b/src/tests/speed.cpp deleted file mode 100644 index 2fa29aa..0000000 --- a/src/tests/speed.cpp +++ /dev/null | |||
@@ -1,58 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include "bu/string.h" | ||
9 | #include <sys/time.h> | ||
10 | |||
11 | template<typename a> | ||
12 | struct tstCopy | ||
13 | { | ||
14 | tstCopy( const a &src ) : | ||
15 | src( src ) | ||
16 | { | ||
17 | } | ||
18 | |||
19 | void operator()() | ||
20 | { | ||
21 | a tmp = src; | ||
22 | } | ||
23 | |||
24 | a src; | ||
25 | }; | ||
26 | |||
27 | template<typename f> | ||
28 | double runTest( f fnc ) | ||
29 | { | ||
30 | struct timeval tStart, tEnd; | ||
31 | int j = 0; | ||
32 | gettimeofday( &tStart, NULL ); | ||
33 | for(; j < 500000; j++ ) | ||
34 | fnc(); | ||
35 | gettimeofday( &tEnd, NULL ); | ||
36 | |||
37 | return (double)(tEnd.tv_sec-tStart.tv_sec)+ | ||
38 | (double)(tEnd.tv_usec-tStart.tv_usec)/1000000.0; | ||
39 | } | ||
40 | |||
41 | template<typename tst> | ||
42 | void fullTest( tst t ) | ||
43 | { | ||
44 | double dTotal; | ||
45 | int iCount = 10; | ||
46 | for( int j = 0; j < iCount; j++ ) | ||
47 | dTotal += runTest( t ); | ||
48 | printf("Average time: %f\n", dTotal/iCount ); | ||
49 | } | ||
50 | |||
51 | int main() | ||
52 | { | ||
53 | Bu::String str; | ||
54 | for( int j = 0; j < 500; j++ ) | ||
55 | str.append("Hey, this is a test string. It will be reapeated many, many times. How's that?"); | ||
56 | fullTest( tstCopy<Bu::String>( str ) ); | ||
57 | } | ||
58 | |||
diff --git a/src/tests/stdstream.cpp b/src/tests/stdstream.cpp deleted file mode 100644 index 95df42e..0000000 --- a/src/tests/stdstream.cpp +++ /dev/null | |||
@@ -1,39 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include "bu/sio.h" | ||
9 | |||
10 | using Bu::sio; | ||
11 | using Bu::Fmt; | ||
12 | |||
13 | int main() | ||
14 | { | ||
15 | sio << "Hello there" << sio.nl; | ||
16 | |||
17 | sio << "sizeof(Fmt) = " << sizeof(Fmt) << sio.nl; | ||
18 | |||
19 | sio << -123 << ", " << 0 << ", " << 123 << sio.nl; | ||
20 | |||
21 | sio << "+----------+" << sio.nl; | ||
22 | sio << "|" << Fmt( 10, 10, Fmt::Center ) << "Test" << "|" << sio.nl; | ||
23 | sio << "+----------+" << sio.nl; | ||
24 | sio << "|" << Fmt( 10, 10, Fmt::Left ) << 123 << "|" << sio.nl; | ||
25 | sio << "|" << Fmt( 10, 10, Fmt::Center ) << 123 << "|" << sio.nl; | ||
26 | sio << "|" << Fmt( 10, 10, Fmt::Right ) << 123 << "|" << sio.nl; | ||
27 | sio << "+----------+" << sio.nl; | ||
28 | |||
29 | sio << Fmt(10,Fmt::Left) << "Hexcode:" << Fmt::ptr() << (void*)(&sio) << sio.nl; | ||
30 | |||
31 | sio << 0.123 << sio.nl; | ||
32 | sio << true << " and then " << false << sio.nl; | ||
33 | |||
34 | for( int j = 2; j <= 36; j++ ) | ||
35 | sio << "radix(" << j << ") = " << Fmt().radix( j ).width( 8 ).align( Fmt::Right ) << 255 << sio.nl; | ||
36 | |||
37 | return 0; | ||
38 | } | ||
39 | |||
diff --git a/src/tests/streamstack.cpp b/src/tests/streamstack.cpp deleted file mode 100644 index 4a0e128..0000000 --- a/src/tests/streamstack.cpp +++ /dev/null | |||
@@ -1,100 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include "bu/streamstack.h" | ||
9 | |||
10 | #include "bu/file.h" | ||
11 | #include "bu/base64.h" | ||
12 | #include "bu/bzip2.h" | ||
13 | |||
14 | #include "bu/sio.h" | ||
15 | |||
16 | #include <time.h> | ||
17 | |||
18 | using namespace Bu; | ||
19 | |||
20 | class DoStuff | ||
21 | { | ||
22 | public: | ||
23 | DoStuff( Bu::Stream &rStream ) : | ||
24 | rStream( rStream ) | ||
25 | { | ||
26 | } | ||
27 | |||
28 | virtual ~DoStuff() | ||
29 | { | ||
30 | } | ||
31 | |||
32 | void write() | ||
33 | { | ||
34 | Bu::String s; | ||
35 | time_t tNow = time( NULL ); | ||
36 | s = ctime( &tNow ); | ||
37 | long lSize = s.getSize()-1; | ||
38 | rStream.write( &lSize, sizeof(long) ); | ||
39 | rStream.write( s.getStr(), lSize ); | ||
40 | } | ||
41 | |||
42 | void read() | ||
43 | { | ||
44 | Bu::String s; | ||
45 | long lSize; | ||
46 | rStream.read( &lSize, sizeof(long) ); | ||
47 | s.setSize( lSize ); | ||
48 | rStream.read( s.getStr(), lSize ); | ||
49 | sio << "Read str(" << lSize << ") = '" << s << "'" << sio.nl; | ||
50 | } | ||
51 | |||
52 | private: | ||
53 | Bu::Stream &rStream; | ||
54 | }; | ||
55 | |||
56 | int main() | ||
57 | { | ||
58 | Bu::StreamStack ss; | ||
59 | |||
60 | DoStuff ds( ss ); | ||
61 | |||
62 | try | ||
63 | { | ||
64 | ds.write(); | ||
65 | sio << "This shouldn't have worked." << sio.nl; | ||
66 | } | ||
67 | catch( Bu::ExceptionBase &e ) | ||
68 | { | ||
69 | sio << "Got exception, this is good: " << e.what() << sio.nl; | ||
70 | } | ||
71 | |||
72 | ss.setStream( new Bu::File("Hello.test", Bu::File::WriteNew ) ); | ||
73 | |||
74 | ds.write(); | ||
75 | |||
76 | ss.pushFilter<Bu::Base64>(); | ||
77 | |||
78 | ds.write(); | ||
79 | |||
80 | ss.pushFilter<Bu::BZip2>(); | ||
81 | |||
82 | ds.write(); | ||
83 | |||
84 | ss.clear(); | ||
85 | |||
86 | ss.setStream( new Bu::File("Hello.test", Bu::File::Read ) ); | ||
87 | |||
88 | ds.read(); | ||
89 | |||
90 | ss.pushFilter<Bu::Base64>(); | ||
91 | |||
92 | ds.read(); | ||
93 | |||
94 | ss.pushFilter<Bu::BZip2>(); | ||
95 | |||
96 | ds.read(); | ||
97 | |||
98 | return 0; | ||
99 | } | ||
100 | |||
diff --git a/src/tests/string.cpp b/src/tests/string.cpp deleted file mode 100644 index b37460e..0000000 --- a/src/tests/string.cpp +++ /dev/null | |||
@@ -1,154 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include "bu/hash.h" | ||
9 | #include "bu/string.h" | ||
10 | #include <sys/time.h> | ||
11 | #include <string> | ||
12 | |||
13 | #ifndef WIN32 | ||
14 | inline double getTime() | ||
15 | { | ||
16 | struct timeval tv; | ||
17 | gettimeofday( &tv, NULL ); | ||
18 | return ((double)tv.tv_sec) + ((double)tv.tv_usec/1000000.0); | ||
19 | } | ||
20 | #else | ||
21 | #include "windows.h" | ||
22 | #include "winbase.h" | ||
23 | inline double getTime() | ||
24 | { | ||
25 | uint32_t t = (uint32_t) GetTickCount(); | ||
26 | return (double) t / 1000.0; | ||
27 | } | ||
28 | #endif | ||
29 | |||
30 | Bu::String genThing() | ||
31 | { | ||
32 | Bu::String bob; | ||
33 | bob.append("ab "); | ||
34 | bob += "cd "; | ||
35 | bob += "efg"; | ||
36 | |||
37 | printf("---bob------\n%08tX: %s\n", (ptrdiff_t)bob.getStr(), | ||
38 | bob.getStr() ); | ||
39 | return bob; | ||
40 | } | ||
41 | |||
42 | void thing( Bu::String str ) | ||
43 | { | ||
44 | printf("Hey: %s\n", str.getStr() ); | ||
45 | } | ||
46 | |||
47 | void copyfunc( std::string temp ) | ||
48 | { | ||
49 | temp += "Hi"; | ||
50 | } | ||
51 | |||
52 | void copyfunc( Bu::String temp ) | ||
53 | { | ||
54 | temp += "Hi"; | ||
55 | } | ||
56 | |||
57 | void doTimings() | ||
58 | { | ||
59 | Bu::String fs1, fs2; | ||
60 | std::string ss1, ss2; | ||
61 | double dStart, dEnd, tfs1, tfs2, tfs3, tss1, tss2, tss3; | ||
62 | int nChars = 50000000, nChunks=50000, nCopies=500000000, nChunkSize=1024*4; | ||
63 | char *buf = new char[nChunkSize]; | ||
64 | memset( buf, '!', nChunkSize ); | ||
65 | |||
66 | printf("Timing Bu::String single chars...\n"); | ||
67 | dStart = getTime(); | ||
68 | for( int j = 0; j < nChars; j++ ) fs1 += (char)('a'+(j%26)); | ||
69 | fs1.getStr(); | ||
70 | dEnd = getTime(); | ||
71 | tfs1 = dEnd-dStart; | ||
72 | |||
73 | printf("Timing std::string single chars...\n"); | ||
74 | dStart = getTime(); | ||
75 | for( int j = 0; j < nChars; j++ ) ss1 += (char)('a'+(j%26)); | ||
76 | ss1.c_str(); | ||
77 | dEnd = getTime(); | ||
78 | tss1 = dEnd-dStart; | ||
79 | |||
80 | printf("Timing Bu::String %d char chunks...\n", nChunkSize); | ||
81 | dStart = getTime(); | ||
82 | for( int j = 0; j < nChunks; j++ ) fs2.append(buf, nChunkSize); | ||
83 | fs2.getStr(); | ||
84 | dEnd = getTime(); | ||
85 | tfs2 = dEnd-dStart; | ||
86 | |||
87 | printf("Timing std::string %d char chunks...\n", nChunkSize); | ||
88 | dStart = getTime(); | ||
89 | for( int j = 0; j < nChunks; j++ ) ss2.append(buf, nChunkSize); | ||
90 | ss2.c_str(); | ||
91 | dEnd = getTime(); | ||
92 | tss2 = dEnd-dStart; | ||
93 | |||
94 | fs2 = "Hello there."; | ||
95 | ss2 = "Hello there."; | ||
96 | printf("Timing Bu::String copies...\n"); | ||
97 | dStart = getTime(); | ||
98 | for( int j = 0; j < nCopies; j++ ) Bu::String stmp = fs2; | ||
99 | dEnd = getTime(); | ||
100 | tfs3 = dEnd-dStart; | ||
101 | |||
102 | printf("Timing std::string copies...\n"); | ||
103 | dStart = getTime(); | ||
104 | for( int j = 0; j < nCopies; j++ ) std::string stpm = ss2; | ||
105 | dEnd = getTime(); | ||
106 | tss3 = dEnd-dStart; | ||
107 | |||
108 | printf( | ||
109 | "Results: singles: chunks: copies:\n" | ||
110 | "Bu::String %15.2f/s %15.2f/s %15.2f/s\n" | ||
111 | "std::string %15.2f/s %15.2f/s %15.2f/s\n", | ||
112 | nChars/tfs1, nChunks/tfs2, nCopies/tfs3, | ||
113 | nChars/tss1, nChunks/tss2, nCopies/tss3 ); | ||
114 | |||
115 | delete[] buf; | ||
116 | } | ||
117 | |||
118 | #define pem printf("---------\n%08tX: %s\n%08tX: %s\n", (ptrdiff_t)str.getConstStr(), str.getConstStr(), (ptrdiff_t)str2.getConstStr(), str2.getConstStr() ); | ||
119 | int main( ) | ||
120 | { | ||
121 | // Bu::String fs1; | ||
122 | // for( int j = 0; j < 500000; j++ ) fs1 += (char)('a'+(j%26)); | ||
123 | // return 0; | ||
124 | |||
125 | Bu::String str("th"); | ||
126 | |||
127 | str.prepend("Hello "); | ||
128 | str.append("ere."); | ||
129 | |||
130 | Bu::String str2( str ); | ||
131 | pem; | ||
132 | str += " What's up?"; | ||
133 | pem; | ||
134 | str2 += " How are you?"; | ||
135 | pem; | ||
136 | str = str2; | ||
137 | pem; | ||
138 | |||
139 | str2 = genThing(); | ||
140 | pem; | ||
141 | |||
142 | str = str2; | ||
143 | pem; | ||
144 | |||
145 | thing( str2 ); | ||
146 | thing("test."); | ||
147 | |||
148 | printf("%d == %d\n", Bu::__calcHashCode( str ), Bu::__calcHashCode( str.getStr() ) ); | ||
149 | |||
150 | doTimings(); | ||
151 | |||
152 | return 0; | ||
153 | } | ||
154 | |||
diff --git a/src/tests/stringspeed.cpp b/src/tests/stringspeed.cpp deleted file mode 100644 index 5636de7..0000000 --- a/src/tests/stringspeed.cpp +++ /dev/null | |||
@@ -1,122 +0,0 @@ | |||
1 | #include <bu/string.h> | ||
2 | |||
3 | #include <sys/time.h> | ||
4 | #include <stdio.h> | ||
5 | |||
6 | void timeit( void (*func)(), const char *sName, int iIter ) | ||
7 | { | ||
8 | struct timeval ts, te; | ||
9 | |||
10 | gettimeofday( &ts, NULL ); | ||
11 | for( int j = 0; j < iIter; j++ ) | ||
12 | { | ||
13 | func(); | ||
14 | } | ||
15 | gettimeofday( &te, NULL ); | ||
16 | |||
17 | double dTotal = (double)(te.tv_sec-ts.tv_sec) + (double)(te.tv_usec-ts.tv_usec)/1000000.0; | ||
18 | printf("%10s: %f spi (%f total)\n", sName, dTotal/iIter, dTotal ); | ||
19 | } | ||
20 | |||
21 | void append1() | ||
22 | { | ||
23 | Bu::String sTmp; | ||
24 | for( int c = 0; c < 5000; c++ ) | ||
25 | { | ||
26 | sTmp += (char)(c%256); | ||
27 | } | ||
28 | } | ||
29 | |||
30 | void append2() | ||
31 | { | ||
32 | Bu::String sTmp; | ||
33 | for( int c = 0; c < 5000; c++ ) | ||
34 | { | ||
35 | sTmp.append( (char)(c%256) ); | ||
36 | } | ||
37 | } | ||
38 | |||
39 | void append3() | ||
40 | { | ||
41 | Bu::String sTmp; | ||
42 | for( int c = 0; c < 5000; c++ ) | ||
43 | { | ||
44 | sTmp += "Test"; | ||
45 | } | ||
46 | } | ||
47 | |||
48 | void append4() | ||
49 | { | ||
50 | Bu::String sTmp; | ||
51 | for( int c = 0; c < 5000; c++ ) | ||
52 | { | ||
53 | sTmp.append("Test"); | ||
54 | } | ||
55 | } | ||
56 | |||
57 | void append5() | ||
58 | { | ||
59 | Bu::String sTmp, sAdd("Test"); | ||
60 | for( int c = 0; c < 5000; c++ ) | ||
61 | { | ||
62 | sTmp += sAdd; | ||
63 | } | ||
64 | } | ||
65 | |||
66 | void append6() | ||
67 | { | ||
68 | Bu::String sTmp, sAdd("Test"); | ||
69 | for( int c = 0; c < 5000; c++ ) | ||
70 | { | ||
71 | sTmp.append( sAdd ); | ||
72 | } | ||
73 | } | ||
74 | |||
75 | void prepend1() | ||
76 | { | ||
77 | Bu::String sTmp; | ||
78 | for( int c = 0; c < 5000; c++ ) | ||
79 | { | ||
80 | sTmp.prepend('c'); | ||
81 | } | ||
82 | } | ||
83 | |||
84 | void copy1() | ||
85 | { | ||
86 | Bu::String sSrc; | ||
87 | for( int c = 0; c < 1000; c++ ) | ||
88 | { | ||
89 | sSrc += (char)(c%256); | ||
90 | Bu::String sTmp = sSrc; | ||
91 | sTmp.append( '-' ); | ||
92 | } | ||
93 | } | ||
94 | |||
95 | void copy2() | ||
96 | { | ||
97 | Bu::String sSrc; | ||
98 | for( int c = 0; c < 1000; c++ ) | ||
99 | { | ||
100 | sSrc += (char)(c%256); | ||
101 | Bu::String sTmp = sSrc; | ||
102 | } | ||
103 | } | ||
104 | |||
105 | void replace1() | ||
106 | { | ||
107 | Bu::String s("Hey, this is a replacement test, what do you thing of it?"); | ||
108 | s.replace("e", "X").replace("a", "X").replace("what","XXX"); | ||
109 | } | ||
110 | |||
111 | int main() | ||
112 | { | ||
113 | timeit( append1, "Append1", 5000 ); | ||
114 | timeit( append2, "Append2", 5000 ); | ||
115 | timeit( append3, "Append3", 2000 ); | ||
116 | timeit( append4, "Append4", 2000 ); | ||
117 | timeit( append4, "Prepend1", 2000 ); | ||
118 | timeit( copy1, "Copy1", 2000 ); | ||
119 | timeit( copy2, "Copy2", 2000 ); | ||
120 | timeit( replace1, "Replace1", 10000 ); | ||
121 | } | ||
122 | |||
diff --git a/src/tests/tcpsocket.cpp b/src/tests/tcpsocket.cpp deleted file mode 100644 index 89c015c..0000000 --- a/src/tests/tcpsocket.cpp +++ /dev/null | |||
@@ -1,73 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include <bu/tcpsocket.h> | ||
9 | #include <bu/sio.h> | ||
10 | |||
11 | #include <sys/time.h> | ||
12 | #include <time.h> | ||
13 | |||
14 | using namespace Bu; | ||
15 | |||
16 | bool isUp() | ||
17 | { | ||
18 | try | ||
19 | { | ||
20 | TcpSocket s("xagasoft.com", 9898, 1 ); | ||
21 | |||
22 | char buf[5]; | ||
23 | buf[s.read(buf, 2, 1, 0)] = '\0'; | ||
24 | |||
25 | if( !strcmp( buf, "hi" ) ) | ||
26 | return true; | ||
27 | else | ||
28 | return false; | ||
29 | } | ||
30 | catch(...) | ||
31 | { | ||
32 | return false; | ||
33 | } | ||
34 | } | ||
35 | |||
36 | int main() | ||
37 | { | ||
38 | uint32_t uUp = 0; | ||
39 | uint32_t uDown = 0; | ||
40 | uint32_t uTotal = 0; | ||
41 | struct timeval tv; | ||
42 | |||
43 | for(;;) | ||
44 | { | ||
45 | gettimeofday( &tv, NULL ); | ||
46 | time_t goal = ((tv.tv_sec/5)+1)*5; | ||
47 | tv.tv_sec = goal-tv.tv_sec; | ||
48 | tv.tv_usec = 0-tv.tv_usec; | ||
49 | if( tv.tv_usec < 0 ) | ||
50 | { | ||
51 | tv.tv_sec--; | ||
52 | tv.tv_usec = 1000000+tv.tv_usec; | ||
53 | } | ||
54 | select( 0, NULL, NULL, NULL, &tv ); | ||
55 | gettimeofday( &tv, NULL ); | ||
56 | if( isUp() ) | ||
57 | { | ||
58 | uUp++; | ||
59 | sio << "status: up "; | ||
60 | } | ||
61 | else | ||
62 | { | ||
63 | uDown++; | ||
64 | sio << "status: down "; | ||
65 | } | ||
66 | uTotal++; | ||
67 | |||
68 | sio << "(up=" << (uUp*5) << "s, down=" << (uDown*5) << ") up for " | ||
69 | << uUp*100/uTotal << "% of " << uTotal*5 << "s" << sio.nl | ||
70 | << sio.flush; | ||
71 | } | ||
72 | } | ||
73 | |||
diff --git a/src/tests/telnetsrv.cpp b/src/tests/telnetsrv.cpp deleted file mode 100644 index aac6b39..0000000 --- a/src/tests/telnetsrv.cpp +++ /dev/null | |||
@@ -1,92 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include "bu/server.h" | ||
9 | #include "bu/protocoltelnet.h" | ||
10 | #include "bu/client.h" | ||
11 | |||
12 | class MyTelnet : public Bu::ProtocolTelnet | ||
13 | { | ||
14 | public: | ||
15 | MyTelnet() | ||
16 | { | ||
17 | } | ||
18 | |||
19 | virtual ~MyTelnet() | ||
20 | { | ||
21 | } | ||
22 | |||
23 | virtual void onNewConnection( Bu::Client *pClient ) | ||
24 | { | ||
25 | Bu::ProtocolTelnet::onNewConnection( pClient ); | ||
26 | |||
27 | //oNAWS.remoteSet(); | ||
28 | oEcho.localSet(); | ||
29 | oSuppressGA.remoteSet( true ); | ||
30 | oSuppressGA.localSet( true ); | ||
31 | setCanonical(); | ||
32 | } | ||
33 | |||
34 | virtual void onSubNAWS( uint16_t iWidth, uint16_t iHeight ) | ||
35 | { | ||
36 | printf("New dim = (%dx%d)\n", iWidth, iHeight ); | ||
37 | } | ||
38 | |||
39 | virtual void gotLine( Bu::String &sLine ) | ||
40 | { | ||
41 | printf("Line: \"%s\"\n", sLine.getStr() ); | ||
42 | write("\n\r", 2 ); | ||
43 | } | ||
44 | |||
45 | private: | ||
46 | |||
47 | }; | ||
48 | |||
49 | class TelServer : public Bu::Server | ||
50 | { | ||
51 | public: | ||
52 | TelServer() | ||
53 | { | ||
54 | } | ||
55 | |||
56 | virtual ~TelServer() | ||
57 | { | ||
58 | } | ||
59 | |||
60 | virtual void onNewConnection( Bu::Client *pClient, int ) | ||
61 | { | ||
62 | printf("New connection.\n"); | ||
63 | |||
64 | pClient->setProtocol( new MyTelnet() ); | ||
65 | } | ||
66 | |||
67 | virtual void onClosedConnection( Bu::Client *pClient ) | ||
68 | { | ||
69 | printf("Lost connection.\n"); | ||
70 | |||
71 | delete pClient->getProtocol(); | ||
72 | } | ||
73 | |||
74 | private: | ||
75 | |||
76 | }; | ||
77 | |||
78 | int main() | ||
79 | { | ||
80 | TelServer ts; | ||
81 | |||
82 | ts.addPort( 4000 ); | ||
83 | ts.setTimeout( 0, 5000 ); | ||
84 | |||
85 | printf("Initializing server on port: 4000\n"); | ||
86 | |||
87 | for(;;) | ||
88 | { | ||
89 | ts.scan(); | ||
90 | } | ||
91 | } | ||
92 | |||
diff --git a/src/tests/tracer.cpp b/src/tests/tracer.cpp deleted file mode 100644 index 703fa1a..0000000 --- a/src/tests/tracer.cpp +++ /dev/null | |||
@@ -1,36 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | |||
9 | #define BU_TRACE | ||
10 | #include "bu/trace.h" | ||
11 | |||
12 | void doThing3( int x, const char *bob, void *p ) | ||
13 | { | ||
14 | TRACE( x, bob, p ); | ||
15 | } | ||
16 | |||
17 | void doThing2( int x, const char *bob ) | ||
18 | { | ||
19 | TRACE( x, bob ); | ||
20 | } | ||
21 | |||
22 | void doThing( int8_t x ) | ||
23 | { | ||
24 | TRACE( x ); | ||
25 | } | ||
26 | |||
27 | int main( int argc, char *argv[] ) | ||
28 | { | ||
29 | TRACE( argc, argv ); | ||
30 | doThing( 54 ); | ||
31 | doThing2( 128, "Hello" ); | ||
32 | doThing3( 266, "Goodbye", argv ); | ||
33 | |||
34 | return 0; | ||
35 | } | ||
36 | |||
diff --git a/src/tests/udpsocket.cpp b/src/tests/udpsocket.cpp deleted file mode 100644 index 2a74acf..0000000 --- a/src/tests/udpsocket.cpp +++ /dev/null | |||
@@ -1,86 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include "bu/udpsocket.h" | ||
9 | #include "bu/sio.h" | ||
10 | |||
11 | #include <errno.h> | ||
12 | #include <arpa/inet.h> | ||
13 | #include <sys/socket.h> | ||
14 | #include <netinet/in.h> | ||
15 | #include <sys/utsname.h> | ||
16 | |||
17 | using namespace Bu; | ||
18 | |||
19 | int main( int argc, char *argv[] ) | ||
20 | { | ||
21 | sio << Fmt::hex(8) << INADDR_ANY << sio.nl << Fmt::hex(8) << inet_addr("0.0.0.0") << sio.nl; | ||
22 | if( argc == 1 ) | ||
23 | { | ||
24 | sio << "Options are 'l' for listening and 'b' for broadcasting." | ||
25 | << sio.nl; | ||
26 | } | ||
27 | else if( argv[1][0] == 'l' ) | ||
28 | { | ||
29 | sio << "Listening..." << sio.nl; | ||
30 | Bu::UdpSocket udp( "0.0.0.0", 6688, UdpSocket::Read|UdpSocket::Broadcast ); | ||
31 | |||
32 | for(;;) | ||
33 | { | ||
34 | char buf[1501]; | ||
35 | int iRead = udp.read( buf, 1500 ); | ||
36 | if( iRead >= 0 ) | ||
37 | { | ||
38 | buf[iRead] = '\0'; | ||
39 | sio << "Read(" << iRead << "): '" << buf << "'" << sio.nl; | ||
40 | } | ||
41 | else | ||
42 | { | ||
43 | sio << "Got " << iRead << ": " << strerror( errno ) << sio.nl; | ||
44 | } | ||
45 | } | ||
46 | } | ||
47 | else if( argv[1][0] == 'L' ) | ||
48 | { | ||
49 | sio << "Listening..." << sio.nl; | ||
50 | Bu::UdpSocket udp( "0.0.0.0", 6688, UdpSocket::Read|UdpSocket::Broadcast ); | ||
51 | |||
52 | for(;;) | ||
53 | { | ||
54 | char buf[1501]; | ||
55 | Bu::UdpSocket::addr aHost; | ||
56 | int iPort; | ||
57 | int iRead = udp.read( buf, 1500, aHost, iPort ); | ||
58 | if( iRead >= 0 ) | ||
59 | { | ||
60 | buf[iRead] = '\0'; | ||
61 | sio << "Read(" << iRead << ") from " << Bu::UdpSocket::addrToStr( aHost ) << ":" << iPort << ": '" << buf << "'" << sio.nl; | ||
62 | } | ||
63 | } | ||
64 | } | ||
65 | else if( argv[1][0] == 'b' ) | ||
66 | { | ||
67 | sio << "Broadcasting..." << sio.nl; | ||
68 | Bu::UdpSocket udp("255.255.255.255", 6688, | ||
69 | UdpSocket::Write|UdpSocket::Broadcast ); | ||
70 | |||
71 | for(;;) | ||
72 | { | ||
73 | int iWrote = udp.write("hello", 5 ); | ||
74 | sio << "Wrote(" << iWrote << "): " << strerror( errno ) << sio.nl; | ||
75 | usleep( 250000 ); | ||
76 | } | ||
77 | } | ||
78 | else | ||
79 | { | ||
80 | sio << "Options are 'l' for listening and 'b' for broadcasting." | ||
81 | << sio.nl; | ||
82 | } | ||
83 | |||
84 | return 0; | ||
85 | } | ||
86 | |||
diff --git a/src/tests/url.cpp b/src/tests/url.cpp deleted file mode 100644 index a381cbe..0000000 --- a/src/tests/url.cpp +++ /dev/null | |||
@@ -1,42 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include "bu/url.h" | ||
9 | |||
10 | #include <stdio.h> | ||
11 | |||
12 | int main( int argc, char *argv[] ) | ||
13 | { | ||
14 | for( argc--, argv++; argc >= 0; argc--, argv++ ) | ||
15 | { | ||
16 | printf("encodede: %s\n", Bu::Url::encode( *argv ).getStr() ); | ||
17 | printf("decodede: %s\n", Bu::Url::decode( *argv ).getStr() ); | ||
18 | Bu::Url u( *argv ); | ||
19 | |||
20 | printf("Protocol: %s\n", u.getProtocol().getStr() ); | ||
21 | printf("User: %s\n", u.getUser().getStr() ); | ||
22 | printf("Pass: %s\n", u.getPass().getStr() ); | ||
23 | printf("Host: %s\n", u.getHost().getStr() ); | ||
24 | printf("Path: %s\n", u.getPath().getStr() ); | ||
25 | try | ||
26 | { | ||
27 | printf("Port: %d\n", u.getPort() ); | ||
28 | } catch( Bu::ExceptionBase &e ) | ||
29 | { | ||
30 | printf("Port: not set.\n"); | ||
31 | } | ||
32 | printf("Parameters:\n"); | ||
33 | for( Bu::Url::ParamList::const_iterator i = u.getParamBegin(); i; i++ ) | ||
34 | { | ||
35 | printf(" \"%s\" = \"%s\"\n", | ||
36 | (*i).sName.getStr(), (*i).sValue.getStr() | ||
37 | ); | ||
38 | } | ||
39 | } | ||
40 | |||
41 | return 0; | ||
42 | } | ||
diff --git a/src/tests/variant.cpp b/src/tests/variant.cpp deleted file mode 100644 index 68dec4f..0000000 --- a/src/tests/variant.cpp +++ /dev/null | |||
@@ -1,52 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include <bu/sio.h> | ||
9 | #include <bu/variant.h> | ||
10 | #include <bu/list.h> | ||
11 | |||
12 | using namespace Bu; | ||
13 | |||
14 | Variant getThing( int i ) | ||
15 | { | ||
16 | Variant v; | ||
17 | switch( i ) | ||
18 | { | ||
19 | case 0: | ||
20 | v = 45; | ||
21 | break; | ||
22 | |||
23 | case 1: | ||
24 | v = true; | ||
25 | break; | ||
26 | |||
27 | case 2: | ||
28 | v = List<int>(5).append(10).append(15); | ||
29 | break; | ||
30 | } | ||
31 | |||
32 | return v; | ||
33 | } | ||
34 | |||
35 | int main() | ||
36 | { | ||
37 | Variant a; | ||
38 | Variant b; | ||
39 | Variant c; | ||
40 | |||
41 | a = getThing( 0 ); | ||
42 | b = getThing( 1 ); | ||
43 | c = getThing( 2 ); | ||
44 | |||
45 | sio << "a = " << a << " or " << (int)a << sio.nl | ||
46 | << "b = " << b << " or " << b.toString() << sio.nl | ||
47 | << "c = " << c << " or " << c.toString() << sio.nl | ||
48 | << sio.nl; | ||
49 | |||
50 | return 0; | ||
51 | } | ||
52 | |||