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/rot13.cpp | |
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/rot13.cpp')
-rw-r--r-- | src/tests/rot13.cpp | 91 |
1 files changed, 0 insertions, 91 deletions
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 | |||