From 611f1c821f9d882f935ac62b0c566d4988f26d1c Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sun, 22 Aug 2010 05:34:12 +0000 Subject: Bu::StreamStack works, it's tested, reasonably, it will be used first in the gats project in Gats::ProtocolGats. --- src/tests/streamstack.cpp | 93 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 src/tests/streamstack.cpp (limited to 'src/tests') 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 @@ +#include "bu/streamstack.h" + +#include "bu/file.h" +#include "bu/base64.h" +#include "bu/bzip2.h" + +#include "bu/sio.h" + +#include + +using namespace Bu; + +class DoStuff +{ +public: + DoStuff( Bu::Stream &rStream ) : + rStream( rStream ) + { + } + + virtual ~DoStuff() + { + } + + void write() + { + Bu::FString s; + time_t tNow = time( NULL ); + s = ctime( &tNow ); + long lSize = s.getSize()-1; + rStream.write( &lSize, sizeof(long) ); + rStream.write( s.getStr(), lSize ); + } + + void read() + { + Bu::FString s; + long lSize; + rStream.read( &lSize, sizeof(long) ); + s.setSize( lSize ); + rStream.read( s.getStr(), lSize ); + sio << "Read str(" << lSize << ") = '" << s << "'" << sio.nl; + } + +private: + Bu::Stream &rStream; +}; + +int main() +{ + Bu::StreamStack ss; + + DoStuff ds( ss ); + + try + { + ds.write(); + sio << "This shouldn't have worked." << sio.nl; + } + catch( Bu::ExceptionBase &e ) + { + sio << "Got exception, this is good: " << e.what() << sio.nl; + } + + ss.setStream( new Bu::File("Hello.test", Bu::File::WriteNew ) ); + + ds.write(); + + ss.pushFilter(); + + ds.write(); + + ss.pushFilter(); + + ds.write(); + + ss.clearStack(); + + ss.setStream( new Bu::File("Hello.test", Bu::File::Read ) ); + + ds.read(); + + ss.pushFilter(); + + ds.read(); + + ss.pushFilter(); + + ds.read(); + + return 0; +} + -- cgit v1.2.3