summaryrefslogtreecommitdiff
path: root/src/unit/membuf.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-06-27 15:42:50 +0000
committerMike Buland <eichlan@xagasoft.com>2007-06-27 15:42:50 +0000
commit5ec9a131e12d021c42b46b601f5e79502485bebb (patch)
tree31d63d293a6c5bc6ea1d677474380ea48976add4 /src/unit/membuf.cpp
parent01ecf54b07e75c17ca5f7039084daeefaea9a1c7 (diff)
downloadlibbu++-5ec9a131e12d021c42b46b601f5e79502485bebb.tar.gz
libbu++-5ec9a131e12d021c42b46b601f5e79502485bebb.tar.bz2
libbu++-5ec9a131e12d021c42b46b601f5e79502485bebb.tar.xz
libbu++-5ec9a131e12d021c42b46b601f5e79502485bebb.zip
The MemBuf works just fine, although it still can't over-write data in the
buffer.
Diffstat (limited to 'src/unit/membuf.cpp')
-rw-r--r--src/unit/membuf.cpp37
1 files changed, 37 insertions, 0 deletions
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 @@
1#include "bu/unitsuite.h"
2#include "bu/membuf.h"
3
4class Unit : public Bu::UnitSuite
5{
6public:
7 Unit()
8 {
9 setName("MemBuf");
10 addTest( Unit::testWriteRead01 );
11 }
12
13 virtual ~Unit()
14 {
15 }
16
17 void testWriteRead01()
18 {
19 Bu::MemBuf mb;
20 unitTest( mb.write("ab", 2 ) == 2 );
21 unitTest( mb.write("cde", 3 ) == 3 );
22 unitTest( mb.write("FG", 2 ) == 2 );
23
24 mb.setPos( 0 );
25
26 char buf[8];
27 buf[7] = '\0';
28 unitTest( mb.read( buf, 7 ) == 7 );
29 unitTest( !strncmp( buf, "abcdeFG", 7 ) );
30 unitTest( mb.read( buf, 7 ) == 0 );
31 mb.seek( -3 );
32 unitTest( mb.read( buf, 7 ) == 3 );
33 unitTest( !strncmp( buf, "eFG", 3 ) );
34 }
35};
36
37int main( int argc, char *argv[] ){ return Unit().run( argc, argv ); }