aboutsummaryrefslogtreecommitdiff
path: root/src/unit/file.unit
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/unit/file.unit160
1 files changed, 80 insertions, 80 deletions
diff --git a/src/unit/file.unit b/src/unit/file.unit
index 7140d03..c0358ac 100644
--- a/src/unit/file.unit
+++ b/src/unit/file.unit
@@ -14,87 +14,87 @@
14 14
15suite File 15suite File
16{ 16{
17 test writeFull 17 test writeFull
18 { 18 {
19 Bu::File sf("testfile1", Bu::File::WriteNew ); 19 Bu::File sf("testfile1", Bu::File::WriteNew );
20 for( int c = 0; c < 256; c++ ) 20 for( int c = 0; c < 256; c++ )
21 { 21 {
22 unsigned char ch = (unsigned char)c; 22 unsigned char ch = (unsigned char)c;
23 sf.write( &ch, 1 ); 23 sf.write( &ch, 1 );
24 unitTest( sf.tell() == c+1 ); 24 unitTest( sf.tell() == c+1 );
25 } 25 }
26 //unitTest( sf.canRead() == false ); 26 //unitTest( sf.canRead() == false );
27 //unitTest( sf.canWrite() == true ); 27 //unitTest( sf.canWrite() == true );
28 //unitTest( sf.canSeek() == true ); 28 //unitTest( sf.canSeek() == true );
29 sf.close(); 29 sf.close();
30 struct stat sdat; 30 struct stat sdat;
31 stat("testfile1", &sdat ); 31 stat("testfile1", &sdat );
32 unitTest( sdat.st_size == 256 ); 32 unitTest( sdat.st_size == 256 );
33 } 33 }
34 34
35 test readBlocks 35 test readBlocks
36 { 36 {
37 Bu::File sf("testfile1", Bu::File::Read ); 37 Bu::File sf("testfile1", Bu::File::Read );
38 unsigned char buf[50]; 38 unsigned char buf[50];
39 size_t total = 0; 39 size_t total = 0;
40 for(;;) 40 for(;;)
41 { 41 {
42 size_t s = sf.read( buf, 50 ); 42 size_t s = sf.read( buf, 50 );
43 for( size_t c = 0; c < s; c++ ) 43 for( size_t c = 0; c < s; c++ )
44 { 44 {
45 unitTest( buf[c] == (unsigned char)(c+total) ); 45 unitTest( buf[c] == (unsigned char)(c+total) );
46 } 46 }
47 total += s; 47 total += s;
48 if( s < 50 ) 48 if( s < 50 )
49 { 49 {
50 unitTest( total == 256 ); 50 unitTest( total == 256 );
51 unitTest( sf.isEos() == false ); 51 unitTest( sf.isEos() == false );
52 unitTest( sf.read( buf, 1 ) == 0 ); 52 unitTest( sf.read( buf, 1 ) == 0 );
53 unitTest( sf.isEos() == true ); 53 unitTest( sf.isEos() == true );
54 // EOS is only set when an attempt to read past the end of 54 // EOS is only set when an attempt to read past the end of
55 // the stream is made, not when a short block is returned. 55 // the stream is made, not when a short block is returned.
56 break; 56 break;
57 } 57 }
58 } 58 }
59 sf.close(); 59 sf.close();
60 } 60 }
61 61
62 test readError1 62 test readError1
63 { 63 {
64 try 64 try
65 { 65 {
66 Bu::File sf("doesn'texist", Bu::File::Read ); 66 Bu::File sf("doesn'texist", Bu::File::Read );
67 unitFailed("No exception thrown"); 67 unitFailed("No exception thrown");
68 } 68 }
69 catch( Bu::FileException &e ) 69 catch( Bu::FileException &e )
70 { 70 {
71 return; 71 return;
72 } 72 }
73 } 73 }
74 74
75 test readError2 75 test readError2
76 { 76 {
77 Bu::File sf("testfile1", Bu::File::Read ); 77 Bu::File sf("testfile1", Bu::File::Read );
78 char buf[256]; 78 char buf[256];
79 int r = sf.read( buf, 256 ); 79 int r = sf.read( buf, 256 );
80 unitTest( r == 256 ); 80 unitTest( r == 256 );
81 // You have to read past the end to set the EOS flag. 81 // You have to read past the end to set the EOS flag.
82 unitTest( sf.isEos() == false ); 82 unitTest( sf.isEos() == false );
83 try 83 try
84 { 84 {
85 if( sf.read( buf, 5 ) > 0 ) 85 if( sf.read( buf, 5 ) > 0 )
86 { 86 {
87 unitFailed("Non-zero read result"); 87 unitFailed("Non-zero read result");
88 } 88 }
89 else 89 else
90 { 90 {
91 sf.close(); 91 sf.close();
92 } 92 }
93 } 93 }
94 catch( Bu::FileException &e ) 94 catch( Bu::FileException &e )
95 { 95 {
96 sf.close(); 96 sf.close();
97 return; 97 return;
98 } 98 }
99 } 99 }
100} 100}