aboutsummaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2010-08-22 05:34:12 +0000
committerMike Buland <eichlan@xagasoft.com>2010-08-22 05:34:12 +0000
commit611f1c821f9d882f935ac62b0c566d4988f26d1c (patch)
tree91e69a124cbff0862a8b2f4899d253455a40eaa3 /src/tests
parent7f17eeb7fccd52b7049f9f598121130dfd1b55ae (diff)
downloadlibbu++-611f1c821f9d882f935ac62b0c566d4988f26d1c.tar.gz
libbu++-611f1c821f9d882f935ac62b0c566d4988f26d1c.tar.bz2
libbu++-611f1c821f9d882f935ac62b0c566d4988f26d1c.tar.xz
libbu++-611f1c821f9d882f935ac62b0c566d4988f26d1c.zip
Bu::StreamStack works, it's tested, reasonably, it will be used first in the
gats project in Gats::ProtocolGats.
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/streamstack.cpp93
1 files changed, 93 insertions, 0 deletions
diff --git a/src/tests/streamstack.cpp b/src/tests/streamstack.cpp
new file mode 100644
index 0000000..56a7076
--- /dev/null
+++ b/src/tests/streamstack.cpp
@@ -0,0 +1,93 @@
1#include "bu/streamstack.h"
2
3#include "bu/file.h"
4#include "bu/base64.h"
5#include "bu/bzip2.h"
6
7#include "bu/sio.h"
8
9#include <time.h>
10
11using namespace Bu;
12
13class DoStuff
14{
15public:
16 DoStuff( Bu::Stream &rStream ) :
17 rStream( rStream )
18 {
19 }
20
21 virtual ~DoStuff()
22 {
23 }
24
25 void write()
26 {
27 Bu::FString s;
28 time_t tNow = time( NULL );
29 s = ctime( &tNow );
30 long lSize = s.getSize()-1;
31 rStream.write( &lSize, sizeof(long) );
32 rStream.write( s.getStr(), lSize );
33 }
34
35 void read()
36 {
37 Bu::FString s;
38 long lSize;
39 rStream.read( &lSize, sizeof(long) );
40 s.setSize( lSize );
41 rStream.read( s.getStr(), lSize );
42 sio << "Read str(" << lSize << ") = '" << s << "'" << sio.nl;
43 }
44
45private:
46 Bu::Stream &rStream;
47};
48
49int main()
50{
51 Bu::StreamStack ss;
52
53 DoStuff ds( ss );
54
55 try
56 {
57 ds.write();
58 sio << "This shouldn't have worked." << sio.nl;
59 }
60 catch( Bu::ExceptionBase &e )
61 {
62 sio << "Got exception, this is good: " << e.what() << sio.nl;
63 }
64
65 ss.setStream( new Bu::File("Hello.test", Bu::File::WriteNew ) );
66
67 ds.write();
68
69 ss.pushFilter<Bu::Base64>();
70
71 ds.write();
72
73 ss.pushFilter<Bu::BZip2>();
74
75 ds.write();
76
77 ss.clearStack();
78
79 ss.setStream( new Bu::File("Hello.test", Bu::File::Read ) );
80
81 ds.read();
82
83 ss.pushFilter<Bu::Base64>();
84
85 ds.read();
86
87 ss.pushFilter<Bu::BZip2>();
88
89 ds.read();
90
91 return 0;
92}
93