aboutsummaryrefslogtreecommitdiff
path: root/src/unit/file.unit
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2010-05-15 07:44:10 +0000
committerMike Buland <eichlan@xagasoft.com>2010-05-15 07:44:10 +0000
commit306b80c1cf9ab490a83b36d3e7cf07e09f9e5d68 (patch)
tree32c35f8507edb4ea403f4ebc4b625c1096f6f384 /src/unit/file.unit
parent11413d228bae2919fe69c83b74c7ff49209dd65a (diff)
downloadlibbu++-306b80c1cf9ab490a83b36d3e7cf07e09f9e5d68.tar.gz
libbu++-306b80c1cf9ab490a83b36d3e7cf07e09f9e5d68.tar.bz2
libbu++-306b80c1cf9ab490a83b36d3e7cf07e09f9e5d68.tar.xz
libbu++-306b80c1cf9ab490a83b36d3e7cf07e09f9e5d68.zip
mkunit.sh was a little dumb, it didn't handle a number of things correctly.
I've written a new program that basically does the same thing, only it's much more clever, and does many more of the translations and conversions better, including the #line directives. Also, I dropped nids, we don't need it anymore. But now I'm ready to write some serious tests for myriad.
Diffstat (limited to '')
-rw-r--r--src/unit/file.unit123
1 files changed, 62 insertions, 61 deletions
diff --git a/src/unit/file.unit b/src/unit/file.unit
index 11c82fb..f8cf7c1 100644
--- a/src/unit/file.unit
+++ b/src/unit/file.unit
@@ -12,84 +12,85 @@
12#include <sys/stat.h> 12#include <sys/stat.h>
13#include <unistd.h> 13#include <unistd.h>
14 14
15{=Init} 15suite File
16
17{%writeFull}
18{ 16{
19 Bu::File sf("testfile1", Bu::File::WriteNew ); 17 test writeFull
20 for( int c = 0; c < 256; c++ )
21 { 18 {
22 unsigned char ch = (unsigned char)c; 19 Bu::File sf("testfile1", Bu::File::WriteNew );
23 sf.write( &ch, 1 ); 20 for( int c = 0; c < 256; c++ )
24 unitTest( sf.tell() == c+1 ); 21 {
22 unsigned char ch = (unsigned char)c;
23 sf.write( &ch, 1 );
24 unitTest( sf.tell() == c+1 );
25 }
26 //unitTest( sf.canRead() == false );
27 //unitTest( sf.canWrite() == true );
28 //unitTest( sf.canSeek() == true );
29 sf.close();
30 struct stat sdat;
31 stat("testfile1", &sdat );
32 unitTest( sdat.st_size == 256 );
25 } 33 }
26 //unitTest( sf.canRead() == false );
27 //unitTest( sf.canWrite() == true );
28 //unitTest( sf.canSeek() == true );
29 sf.close();
30 struct stat sdat;
31 stat("testfile1", &sdat );
32 unitTest( sdat.st_size == 256 );
33}
34 34
35{%readBlocks} 35 test readBlocks
36{
37 Bu::File sf("testfile1", Bu::File::Read );
38 unsigned char buf[50];
39 size_t total = 0;
40 for(;;)
41 { 36 {
42 size_t s = sf.read( buf, 50 ); 37 Bu::File sf("testfile1", Bu::File::Read );
43 for( size_t c = 0; c < s; c++ ) 38 unsigned char buf[50];
39 size_t total = 0;
40 for(;;)
44 { 41 {
45 unitTest( buf[c] == (unsigned char)(c+total) ); 42 size_t s = sf.read( buf, 50 );
46 } 43 for( size_t c = 0; c < s; c++ )
47 total += s; 44 {
48 if( s < 50 ) 45 unitTest( buf[c] == (unsigned char)(c+total) );
49 { 46 }
50 unitTest( total == 256 ); 47 total += s;
51 unitTest( sf.isEos() == true ); 48 if( s < 50 )
52 break; 49 {
50 unitTest( total == 256 );
51 unitTest( sf.isEos() == true );
52 break;
53 }
53 } 54 }
55 sf.close();
54 } 56 }
55 sf.close();
56}
57 57
58{%readError1} 58 test readError1
59{
60 try
61 { 59 {
62 Bu::File sf("doesn'texist", Bu::File::Read ); 60 try
63 unitFailed("No exception thrown"); 61 {
64 } 62 Bu::File sf("doesn'texist", Bu::File::Read );
65 catch( Bu::FileException &e ) 63 unitFailed("No exception thrown");
66 { 64 }
67 return; 65 catch( Bu::FileException &e )
66 {
67 return;
68 }
68 } 69 }
69}
70 70
71{%readError2} 71 test readError2
72{
73 Bu::File sf("testfile1", Bu::File::Read );
74 char buf[256];
75 int r = sf.read( buf, 256 );
76 unitTest( r == 256 );
77 // You have to read past the end to set the EOS flag.
78 unitTest( sf.isEos() == false );
79 try
80 { 72 {
81 if( sf.read( buf, 5 ) > 0 ) 73 Bu::File sf("testfile1", Bu::File::Read );
74 char buf[256];
75 int r = sf.read( buf, 256 );
76 unitTest( r == 256 );
77 // You have to read past the end to set the EOS flag.
78 unitTest( sf.isEos() == false );
79 try
82 { 80 {
83 unitFailed("Non-zero read result"); 81 if( sf.read( buf, 5 ) > 0 )
82 {
83 unitFailed("Non-zero read result");
84 }
85 else
86 {
87 sf.close();
88 }
84 } 89 }
85 else 90 catch( Bu::FileException &e )
86 { 91 {
87 sf.close(); 92 sf.close();
93 return;
88 } 94 }
89 } 95 }
90 catch( Bu::FileException &e )
91 {
92 sf.close();
93 return;
94 }
95} 96}