aboutsummaryrefslogtreecommitdiff
path: root/src/unit
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/unit/file.cpp (renamed from src/unit/sfile.cpp)12
-rw-r--r--src/unitsuite.h35
2 files changed, 41 insertions, 6 deletions
diff --git a/src/unit/sfile.cpp b/src/unit/file.cpp
index 2aff312..a45b8d7 100644
--- a/src/unit/sfile.cpp
+++ b/src/unit/file.cpp
@@ -1,5 +1,5 @@
1#include "unitsuite.h" 1#include "unitsuite.h"
2#include "sfile.h" 2#include "file.h"
3#include "exceptions.h" 3#include "exceptions.h"
4 4
5#include <sys/types.h> 5#include <sys/types.h>
@@ -11,7 +11,7 @@ class Unit : public Bu::UnitSuite
11public: 11public:
12 Unit() 12 Unit()
13 { 13 {
14 setName("SFile"); 14 setName("File");
15 addTest( Unit::writeFull ); 15 addTest( Unit::writeFull );
16 addTest( Unit::readBlocks ); 16 addTest( Unit::readBlocks );
17 addTest( Unit::readError1 ); 17 addTest( Unit::readError1 );
@@ -25,7 +25,7 @@ public:
25 // 25 //
26 void writeFull() 26 void writeFull()
27 { 27 {
28 Bu::SFile sf("testfile1", "wb"); 28 Bu::File sf("testfile1", "wb");
29 for( int c = 0; c < 256; c++ ) 29 for( int c = 0; c < 256; c++ )
30 { 30 {
31 unsigned char ch = (unsigned char)c; 31 unsigned char ch = (unsigned char)c;
@@ -43,7 +43,7 @@ public:
43 43
44 void readBlocks() 44 void readBlocks()
45 { 45 {
46 Bu::SFile sf("testfile1", "rb"); 46 Bu::File sf("testfile1", "rb");
47 unsigned char buf[50]; 47 unsigned char buf[50];
48 size_t total = 0; 48 size_t total = 0;
49 for(;;) 49 for(;;)
@@ -68,7 +68,7 @@ public:
68 { 68 {
69 try 69 try
70 { 70 {
71 Bu::SFile sf("doesn'texist", "rb"); 71 Bu::File sf("doesn'texist", "rb");
72 unitFailed("No exception thrown"); 72 unitFailed("No exception thrown");
73 } 73 }
74 catch( Bu::FileException &e ) 74 catch( Bu::FileException &e )
@@ -79,7 +79,7 @@ public:
79 79
80 void readError2() 80 void readError2()
81 { 81 {
82 Bu::SFile sf("testfile1", "rb"); 82 Bu::File sf("testfile1", "rb");
83 char buf[256]; 83 char buf[256];
84 int r = sf.read( buf, 256 ); 84 int r = sf.read( buf, 256 );
85 unitTest( r == 256 ); 85 unitTest( r == 256 );
diff --git a/src/unitsuite.h b/src/unitsuite.h
index db249b2..6e9270a 100644
--- a/src/unitsuite.h
+++ b/src/unitsuite.h
@@ -8,7 +8,42 @@
8namespace Bu 8namespace Bu
9{ 9{
10 /** 10 /**
11 * Provides a unit testing framework. This is pretty easy to use, probably
12 * the best way to get started is to use ch to generate a template, or use
13 * the code below with appropriate tweaks:
14 *@code
15 * #include "unitsuite.h"
16 *
17 * class Unit : public Bu::UnitSuite
18 * {
19 * public:
20 * Unit()
21 * {
22 * setName("Example");
23 * addTest( Unit::test );
24 * }
25 *
26 * virtual ~Unit() { }
27 *
28 * //
29 * // Tests go here
30 * //
31 * void test()
32 * {
33 * unitTest( 1 == 1 );
34 * }
35 * };
36 *
37 * int main( int argc, char *argv[] )
38 * {
39 * return Unit().run( argc, argv );
40 * }
11 * 41 *
42 @endcode
43 * The main function can contain other things, but using this one exactly
44 * makes all of the test suites work exactly the same. Using the optional
45 * setName at the top of the constructor replaces the class name with the
46 * chosen name when printing out stats and info.
12 */ 47 */
13 class UnitSuite 48 class UnitSuite
14 { 49 {