aboutsummaryrefslogtreecommitdiff
path: root/src/unit/membuf.unit
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2009-01-07 15:59:57 +0000
committerMike Buland <eichlan@xagasoft.com>2009-01-07 15:59:57 +0000
commit45e065bc4fc93731ea9a0543462bc7cf9e6084d7 (patch)
treea9e8279fe00b9b01dc2393f59dc7f41b5e416b2a /src/unit/membuf.unit
parentd96fe229e79f9b1947cbd24ff52d6bf7bb9bf80d (diff)
downloadlibbu++-45e065bc4fc93731ea9a0543462bc7cf9e6084d7.tar.gz
libbu++-45e065bc4fc93731ea9a0543462bc7cf9e6084d7.tar.bz2
libbu++-45e065bc4fc93731ea9a0543462bc7cf9e6084d7.tar.xz
libbu++-45e065bc4fc93731ea9a0543462bc7cf9e6084d7.zip
Only two real changes. First, Bu::FString and Bu::FBasicString are in different
files. This won't affect any programs at all anywhere. This will just make it easier to maintain and extend later. You still want to include "bu/fstring.h" and use Bu::FString in code. The other is kinda fun. I created a special format for unit tests, they use the extension .unit now and use the mkunit.sh script to convert them to c++ code. There are some nice features here too, maintaining unit tests is much, much easier, and we can have more features without making the code any harder to use. Also, it will be easier to have the unit tests generate reports and be run from a master program and the like.
Diffstat (limited to 'src/unit/membuf.unit')
-rw-r--r--src/unit/membuf.unit45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/unit/membuf.unit b/src/unit/membuf.unit
new file mode 100644
index 0000000..aebf36c
--- /dev/null
+++ b/src/unit/membuf.unit
@@ -0,0 +1,45 @@
1// vim: syntax=cpp
2/*
3 * Copyright (C) 2007-2008 Xagasoft, All rights reserved.
4 *
5 * This file is part of the libbu++ library and is released under the
6 * terms of the license contained in the file LICENSE.
7 */
8
9#include "bu/membuf.h"
10
11{=Init}
12
13{%testWriteRead01}
14{
15 Bu::MemBuf mb;
16 unitTest( mb.write("ab", 2 ) == 2 );
17 unitTest( mb.write("cde", 3 ) == 3 );
18 unitTest( mb.write("FG", 2 ) == 2 );
19
20 mb.setPos( 0 );
21
22 char buf[8];
23 buf[7] = '\0';
24 unitTest( mb.read( buf, 7 ) == 7 );
25 unitTest( !strncmp( buf, "abcdeFG", 7 ) );
26 unitTest( mb.read( buf, 7 ) == 0 );
27 mb.seek( -3 );
28 unitTest( mb.read( buf, 7 ) == 3 );
29 unitTest( !strncmp( buf, "eFG", 3 ) );
30}
31
32{%testOverwrite1}
33{
34 Bu::MemBuf mb;
35 unitTest( mb.write("0123456789") == 10 );
36 mb.setPos( 4 );
37 unitTest( mb.write("-5-") == 3 );
38 mb.setPos( 9 );
39 mb.write("Hey!!!");
40 unitTest( mb.tell() == 15 );
41 char buf[50];
42 mb.setPos( 0 );
43 buf[mb.read( buf, 50 )] = '\0';
44 unitTest( !strcmp( buf, "0123-5-78Hey!!!" ) );
45}