diff options
author | Mike Buland <eichlan@xagasoft.com> | 2009-01-07 15:59:57 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2009-01-07 15:59:57 +0000 |
commit | 45e065bc4fc93731ea9a0543462bc7cf9e6084d7 (patch) | |
tree | a9e8279fe00b9b01dc2393f59dc7f41b5e416b2a /src/unit/file.cpp | |
parent | d96fe229e79f9b1947cbd24ff52d6bf7bb9bf80d (diff) | |
download | libbu++-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/file.cpp')
-rw-r--r-- | src/unit/file.cpp | 117 |
1 files changed, 0 insertions, 117 deletions
diff --git a/src/unit/file.cpp b/src/unit/file.cpp deleted file mode 100644 index cc19fac..0000000 --- a/src/unit/file.cpp +++ /dev/null | |||
@@ -1,117 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2008 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include "bu/unitsuite.h" | ||
9 | #include "bu/file.h" | ||
10 | |||
11 | #include <sys/types.h> | ||
12 | #include <sys/stat.h> | ||
13 | #include <unistd.h> | ||
14 | |||
15 | class Unit : public Bu::UnitSuite | ||
16 | { | ||
17 | public: | ||
18 | Unit() | ||
19 | { | ||
20 | setName("File"); | ||
21 | addTest( Unit::writeFull ); | ||
22 | addTest( Unit::readBlocks ); | ||
23 | addTest( Unit::readError1 ); | ||
24 | addTest( Unit::readError2 ); | ||
25 | } | ||
26 | |||
27 | virtual ~Unit() { } | ||
28 | |||
29 | // | ||
30 | // Tests go here | ||
31 | // | ||
32 | void writeFull() | ||
33 | { | ||
34 | Bu::File sf("testfile1", Bu::File::Write ); | ||
35 | for( int c = 0; c < 256; c++ ) | ||
36 | { | ||
37 | unsigned char ch = (unsigned char)c; | ||
38 | sf.write( &ch, 1 ); | ||
39 | unitTest( sf.tell() == c+1 ); | ||
40 | } | ||
41 | //unitTest( sf.canRead() == false ); | ||
42 | //unitTest( sf.canWrite() == true ); | ||
43 | //unitTest( sf.canSeek() == true ); | ||
44 | sf.close(); | ||
45 | struct stat sdat; | ||
46 | stat("testfile1", &sdat ); | ||
47 | unitTest( sdat.st_size == 256 ); | ||
48 | } | ||
49 | |||
50 | void readBlocks() | ||
51 | { | ||
52 | Bu::File sf("testfile1", Bu::File::Read ); | ||
53 | unsigned char buf[50]; | ||
54 | size_t total = 0; | ||
55 | for(;;) | ||
56 | { | ||
57 | size_t s = sf.read( buf, 50 ); | ||
58 | for( size_t c = 0; c < s; c++ ) | ||
59 | { | ||
60 | unitTest( buf[c] == (unsigned char)(c+total) ); | ||
61 | } | ||
62 | total += s; | ||
63 | if( s < 50 ) | ||
64 | { | ||
65 | unitTest( total == 256 ); | ||
66 | unitTest( sf.isEOS() == true ); | ||
67 | break; | ||
68 | } | ||
69 | } | ||
70 | sf.close(); | ||
71 | } | ||
72 | |||
73 | void readError1() | ||
74 | { | ||
75 | try | ||
76 | { | ||
77 | Bu::File sf("doesn'texist", Bu::File::Read ); | ||
78 | unitFailed("No exception thrown"); | ||
79 | } | ||
80 | catch( Bu::FileException &e ) | ||
81 | { | ||
82 | return; | ||
83 | } | ||
84 | } | ||
85 | |||
86 | void readError2() | ||
87 | { | ||
88 | Bu::File sf("testfile1", Bu::File::Read ); | ||
89 | char buf[256]; | ||
90 | int r = sf.read( buf, 256 ); | ||
91 | unitTest( r == 256 ); | ||
92 | // You have to read past the end to set the EOS flag. | ||
93 | unitTest( sf.isEOS() == false ); | ||
94 | try | ||
95 | { | ||
96 | if( sf.read( buf, 5 ) > 0 ) | ||
97 | { | ||
98 | unitFailed("Non-zero read result"); | ||
99 | } | ||
100 | else | ||
101 | { | ||
102 | sf.close(); | ||
103 | } | ||
104 | } | ||
105 | catch( Bu::FileException &e ) | ||
106 | { | ||
107 | sf.close(); | ||
108 | return; | ||
109 | } | ||
110 | } | ||
111 | }; | ||
112 | |||
113 | int main( int argc, char *argv[] ) | ||
114 | { | ||
115 | return Unit().run( argc, argv ); | ||
116 | } | ||
117 | |||