diff options
author | Mike Buland <eichlan@xagasoft.com> | 2007-06-27 15:42:50 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2007-06-27 15:42:50 +0000 |
commit | 5ec9a131e12d021c42b46b601f5e79502485bebb (patch) | |
tree | 31d63d293a6c5bc6ea1d677474380ea48976add4 /src/unit | |
parent | 01ecf54b07e75c17ca5f7039084daeefaea9a1c7 (diff) | |
download | libbu++-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')
-rw-r--r-- | src/unit/entities/unit | 30 | ||||
-rw-r--r-- | src/unit/file.cpp | 10 | ||||
-rw-r--r-- | src/unit/hash.cpp | 4 | ||||
-rw-r--r-- | src/unit/membuf.cpp | 37 |
4 files changed, 77 insertions, 4 deletions
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 @@ | |||
1 | <?xml version="1.1" ?> | ||
2 | <entity desc="Unit test framework"> | ||
3 | <param name="name" required="yes" desc="Name of the class"/> | ||
4 | <file | ||
5 | name="source" | ||
6 | filename="{=name:%tolower}.cpp" | ||
7 | >#include "bu/unitsuite.h" | ||
8 | |||
9 | class Unit : public Bu::UnitSuite | ||
10 | { | ||
11 | public: | ||
12 | Unit() | ||
13 | { | ||
14 | setName("{=name}"); | ||
15 | addTest( Unit::test01 ); | ||
16 | } | ||
17 | |||
18 | virtual ~Unit() | ||
19 | { | ||
20 | } | ||
21 | |||
22 | void test01() | ||
23 | { | ||
24 | unitTest( 0 == 5 ); | ||
25 | } | ||
26 | }; | ||
27 | |||
28 | int main( int argc, char *argv[] ){ return Unit().run( argc, argv ); } | ||
29 | </file> | ||
30 | </entity> | ||
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: | |||
87 | unitTest( sf.isEOS() == false ); | 87 | unitTest( sf.isEOS() == false ); |
88 | try | 88 | try |
89 | { | 89 | { |
90 | sf.read( buf, 5 ); | 90 | if( sf.read( buf, 5 ) > 0 ) |
91 | unitFailed("No exception thrown"); | 91 | { |
92 | unitFailed("Non-zero read result"); | ||
93 | } | ||
94 | else | ||
95 | { | ||
96 | sf.close(); | ||
97 | } | ||
92 | } | 98 | } |
93 | catch( Bu::FileException &e ) | 99 | catch( Bu::FileException &e ) |
94 | { | 100 | { |
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 @@ | |||
1 | #include "bu/fstring.h" | 1 | #include "bu/fstring.h" |
2 | #include "bu/hash.h" | 2 | #include "bu/hash.h" |
3 | #include "unitsuite.h" | 3 | #include "bu/unitsuite.h" |
4 | 4 | ||
5 | #include <stdio.h> | 5 | #include <stdio.h> |
6 | 6 | ||
@@ -23,7 +23,7 @@ public: | |||
23 | { | 23 | { |
24 | StrIntHash h; | 24 | StrIntHash h; |
25 | char buf[20]; | 25 | char buf[20]; |
26 | for(int i=0;i<10000;i++) | 26 | for(int i=1;i<10000;i++) |
27 | { | 27 | { |
28 | sprintf(buf,"%d",i); | 28 | sprintf(buf,"%d",i); |
29 | Bu::FString sTmp(buf); | 29 | 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 @@ | |||
1 | #include "bu/unitsuite.h" | ||
2 | #include "bu/membuf.h" | ||
3 | |||
4 | class Unit : public Bu::UnitSuite | ||
5 | { | ||
6 | public: | ||
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 | |||
37 | int main( int argc, char *argv[] ){ return Unit().run( argc, argv ); } | ||