aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-04-10 20:16:19 +0000
committerMike Buland <eichlan@xagasoft.com>2007-04-10 20:16:19 +0000
commit070374dde0f53bff26078550997f7682e84412e5 (patch)
treed9088b02e9b5f08f25d7f07f3a26035eea00e8e9 /src
parente7ab7cb1604c04763bbdcece5885e6ce5aa100b4 (diff)
downloadlibbu++-070374dde0f53bff26078550997f7682e84412e5.tar.gz
libbu++-070374dde0f53bff26078550997f7682e84412e5.tar.bz2
libbu++-070374dde0f53bff26078550997f7682e84412e5.tar.xz
libbu++-070374dde0f53bff26078550997f7682e84412e5.zip
I did it, the streams don't start with an S now.
Diffstat (limited to 'src')
-rw-r--r--src/file.cpp (renamed from src/sfile.cpp)28
-rw-r--r--src/file.h (renamed from src/sfile.h)10
-rw-r--r--src/socket.cpp10
-rw-r--r--src/socket.h (renamed from src/ssocket.h)10
-rw-r--r--src/ssocket.cpp9
-rw-r--r--src/tests/archive.cpp4
-rw-r--r--src/unit/file.cpp (renamed from src/unit/sfile.cpp)12
-rw-r--r--src/unitsuite.h35
8 files changed, 77 insertions, 41 deletions
diff --git a/src/sfile.cpp b/src/file.cpp
index 529d8cd..5de5f6c 100644
--- a/src/sfile.cpp
+++ b/src/file.cpp
@@ -1,8 +1,8 @@
1#include "sfile.h" 1#include "file.h"
2#include "exceptions.h" 2#include "exceptions.h"
3#include <errno.h> 3#include <errno.h>
4 4
5Bu::SFile::SFile( const char *sName, const char *sFlags ) 5Bu::File::File( const char *sName, const char *sFlags )
6{ 6{
7 fh = fopen( sName, sFlags ); 7 fh = fopen( sName, sFlags );
8 if( fh == NULL ) 8 if( fh == NULL )
@@ -11,12 +11,12 @@ Bu::SFile::SFile( const char *sName, const char *sFlags )
11 } 11 }
12} 12}
13 13
14Bu::SFile::~SFile() 14Bu::File::~File()
15{ 15{
16 close(); 16 close();
17} 17}
18 18
19void Bu::SFile::close() 19void Bu::File::close()
20{ 20{
21 if( fh ) 21 if( fh )
22 { 22 {
@@ -25,7 +25,7 @@ void Bu::SFile::close()
25 } 25 }
26} 26}
27 27
28size_t Bu::SFile::read( void *pBuf, size_t nBytes ) 28size_t Bu::File::read( void *pBuf, size_t nBytes )
29{ 29{
30 if( !fh ) 30 if( !fh )
31 throw FileException("File not open."); 31 throw FileException("File not open.");
@@ -38,7 +38,7 @@ size_t Bu::SFile::read( void *pBuf, size_t nBytes )
38 return nAmnt; 38 return nAmnt;
39} 39}
40 40
41size_t Bu::SFile::write( const void *pBuf, size_t nBytes ) 41size_t Bu::File::write( const void *pBuf, size_t nBytes )
42{ 42{
43 if( !fh ) 43 if( !fh )
44 throw FileException("File not open."); 44 throw FileException("File not open.");
@@ -46,7 +46,7 @@ size_t Bu::SFile::write( const void *pBuf, size_t nBytes )
46 return fwrite( pBuf, 1, nBytes, fh ); 46 return fwrite( pBuf, 1, nBytes, fh );
47} 47}
48 48
49long Bu::SFile::tell() 49long Bu::File::tell()
50{ 50{
51 if( !fh ) 51 if( !fh )
52 throw FileException("File not open."); 52 throw FileException("File not open.");
@@ -54,7 +54,7 @@ long Bu::SFile::tell()
54 return ftell( fh ); 54 return ftell( fh );
55} 55}
56 56
57void Bu::SFile::seek( long offset ) 57void Bu::File::seek( long offset )
58{ 58{
59 if( !fh ) 59 if( !fh )
60 throw FileException("File not open."); 60 throw FileException("File not open.");
@@ -62,7 +62,7 @@ void Bu::SFile::seek( long offset )
62 fseek( fh, offset, SEEK_CUR ); 62 fseek( fh, offset, SEEK_CUR );
63} 63}
64 64
65void Bu::SFile::setPos( long pos ) 65void Bu::File::setPos( long pos )
66{ 66{
67 if( !fh ) 67 if( !fh )
68 throw FileException("File not open."); 68 throw FileException("File not open.");
@@ -70,7 +70,7 @@ void Bu::SFile::setPos( long pos )
70 fseek( fh, pos, SEEK_SET ); 70 fseek( fh, pos, SEEK_SET );
71} 71}
72 72
73void Bu::SFile::setPosEnd( long pos ) 73void Bu::File::setPosEnd( long pos )
74{ 74{
75 if( !fh ) 75 if( !fh )
76 throw FileException("File not open."); 76 throw FileException("File not open.");
@@ -78,22 +78,22 @@ void Bu::SFile::setPosEnd( long pos )
78 fseek( fh, pos, SEEK_END ); 78 fseek( fh, pos, SEEK_END );
79} 79}
80 80
81bool Bu::SFile::isEOS() 81bool Bu::File::isEOS()
82{ 82{
83 return feof( fh ); 83 return feof( fh );
84} 84}
85 85
86bool Bu::SFile::canRead() 86bool Bu::File::canRead()
87{ 87{
88 return true; 88 return true;
89} 89}
90 90
91bool Bu::SFile::canWrite() 91bool Bu::File::canWrite()
92{ 92{
93 return true; 93 return true;
94} 94}
95 95
96bool Bu::SFile::canSeek() 96bool Bu::File::canSeek()
97{ 97{
98 return true; 98 return true;
99} 99}
diff --git a/src/sfile.h b/src/file.h
index f63b812..bbc620c 100644
--- a/src/sfile.h
+++ b/src/file.h
@@ -1,5 +1,5 @@
1#ifndef SFILE_H 1#ifndef FILE_H
2#define SFILE_H 2#define FILE_H
3 3
4#include <stdint.h> 4#include <stdint.h>
5 5
@@ -7,11 +7,11 @@
7 7
8namespace Bu 8namespace Bu
9{ 9{
10 class SFile : public Bu::Stream 10 class File : public Bu::Stream
11 { 11 {
12 public: 12 public:
13 SFile( const char *sName, const char *sFlags ); 13 File( const char *sName, const char *sFlags );
14 virtual ~SFile(); 14 virtual ~File();
15 15
16 virtual void close(); 16 virtual void close();
17 virtual size_t read( void *pBuf, size_t nBytes ); 17 virtual size_t read( void *pBuf, size_t nBytes );
diff --git a/src/socket.cpp b/src/socket.cpp
new file mode 100644
index 0000000..c5c592b
--- /dev/null
+++ b/src/socket.cpp
@@ -0,0 +1,10 @@
1#include "socket.h"
2
3Bu::Socket::Socket()
4{
5}
6
7Bu::Socket::~Socket()
8{
9}
10
diff --git a/src/ssocket.h b/src/socket.h
index ce02091..8ccde71 100644
--- a/src/ssocket.h
+++ b/src/socket.h
@@ -1,5 +1,5 @@
1#ifndef S_SOCKET_H 1#ifndef SOCKET_H
2#define S_SOCKET_H 2#define SOCKET_H
3 3
4#include <stdint.h> 4#include <stdint.h>
5 5
@@ -10,11 +10,11 @@ namespace Bu
10 /** 10 /**
11 * 11 *
12 */ 12 */
13 class SSocket : public Stream 13 class Socket : public Stream
14 { 14 {
15 public: 15 public:
16 SSocket(); 16 Socket();
17 virtual ~SSocket(); 17 virtual ~Socket();
18 18
19 private: 19 private:
20 20
diff --git a/src/ssocket.cpp b/src/ssocket.cpp
deleted file mode 100644
index 85a2da0..0000000
--- a/src/ssocket.cpp
+++ /dev/null
@@ -1,9 +0,0 @@
1#include "ssocket.h"
2
3Bu::SSocket::SSocket()
4{
5}
6
7Bu::SSocket::~SSocket()
8{
9}
diff --git a/src/tests/archive.cpp b/src/tests/archive.cpp
index 5b7e285..2035aa6 100644
--- a/src/tests/archive.cpp
+++ b/src/tests/archive.cpp
@@ -1,11 +1,11 @@
1#include "archive.h" 1#include "archive.h"
2#include "sfile.h" 2#include "file.h"
3 3
4using namespace Bu; 4using namespace Bu;
5 5
6int main() 6int main()
7{ 7{
8 SFile f("test.dat", "wb"); 8 File f("test.dat", "wb");
9 Archive ar( f, Archive::save ); 9 Archive ar( f, Archive::save );
10 10
11 std::string s("Hello there"); 11 std::string s("Hello there");
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 {