From 5ec9a131e12d021c42b46b601f5e79502485bebb Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 27 Jun 2007 15:42:50 +0000 Subject: The MemBuf works just fine, although it still can't over-write data in the buffer. --- src/unit/entities/unit | 30 ++++++++++++++++++++++++++++++ src/unit/file.cpp | 10 ++++++++-- src/unit/hash.cpp | 4 ++-- src/unit/membuf.cpp | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 src/unit/entities/unit create mode 100644 src/unit/membuf.cpp (limited to 'src/unit') diff --git a/src/unit/entities/unit b/src/unit/entities/unit new file mode 100644 index 0000000..28db45f --- /dev/null +++ b/src/unit/entities/unit @@ -0,0 +1,30 @@ + + + + #include "bu/unitsuite.h" + +class Unit : public Bu::UnitSuite +{ +public: + Unit() + { + setName("{=name}"); + addTest( Unit::test01 ); + } + + virtual ~Unit() + { + } + + void test01() + { + unitTest( 0 == 5 ); + } +}; + +int main( int argc, char *argv[] ){ return Unit().run( argc, argv ); } + + diff --git a/src/unit/file.cpp b/src/unit/file.cpp index a45b8d7..1eaaf36 100644 --- a/src/unit/file.cpp +++ b/src/unit/file.cpp @@ -87,8 +87,14 @@ public: unitTest( sf.isEOS() == false ); try { - sf.read( buf, 5 ); - unitFailed("No exception thrown"); + if( sf.read( buf, 5 ) > 0 ) + { + unitFailed("Non-zero read result"); + } + else + { + sf.close(); + } } catch( Bu::FileException &e ) { diff --git a/src/unit/hash.cpp b/src/unit/hash.cpp index 588e687..9ea933f 100644 --- a/src/unit/hash.cpp +++ b/src/unit/hash.cpp @@ -1,6 +1,6 @@ #include "bu/fstring.h" #include "bu/hash.h" -#include "unitsuite.h" +#include "bu/unitsuite.h" #include @@ -23,7 +23,7 @@ public: { StrIntHash h; char buf[20]; - for(int i=0;i<10000;i++) + for(int i=1;i<10000;i++) { sprintf(buf,"%d",i); Bu::FString sTmp(buf); diff --git a/src/unit/membuf.cpp b/src/unit/membuf.cpp new file mode 100644 index 0000000..65ba82a --- /dev/null +++ b/src/unit/membuf.cpp @@ -0,0 +1,37 @@ +#include "bu/unitsuite.h" +#include "bu/membuf.h" + +class Unit : public Bu::UnitSuite +{ +public: + Unit() + { + setName("MemBuf"); + addTest( Unit::testWriteRead01 ); + } + + virtual ~Unit() + { + } + + void testWriteRead01() + { + Bu::MemBuf mb; + unitTest( mb.write("ab", 2 ) == 2 ); + unitTest( mb.write("cde", 3 ) == 3 ); + unitTest( mb.write("FG", 2 ) == 2 ); + + mb.setPos( 0 ); + + char buf[8]; + buf[7] = '\0'; + unitTest( mb.read( buf, 7 ) == 7 ); + unitTest( !strncmp( buf, "abcdeFG", 7 ) ); + unitTest( mb.read( buf, 7 ) == 0 ); + mb.seek( -3 ); + unitTest( mb.read( buf, 7 ) == 3 ); + unitTest( !strncmp( buf, "eFG", 3 ) ); + } +}; + +int main( int argc, char *argv[] ){ return Unit().run( argc, argv ); } -- cgit v1.2.3