From 306b80c1cf9ab490a83b36d3e7cf07e09f9e5d68 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sat, 15 May 2010 07:44:10 +0000 Subject: 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. --- src/unit/file.unit | 123 +++++++++++++++++++++++++++-------------------------- 1 file changed, 62 insertions(+), 61 deletions(-) (limited to 'src/unit/file.unit') 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 @@ #include #include -{=Init} - -{%writeFull} +suite File { - Bu::File sf("testfile1", Bu::File::WriteNew ); - for( int c = 0; c < 256; c++ ) + test writeFull { - unsigned char ch = (unsigned char)c; - sf.write( &ch, 1 ); - unitTest( sf.tell() == c+1 ); + Bu::File sf("testfile1", Bu::File::WriteNew ); + for( int c = 0; c < 256; c++ ) + { + unsigned char ch = (unsigned char)c; + sf.write( &ch, 1 ); + unitTest( sf.tell() == c+1 ); + } + //unitTest( sf.canRead() == false ); + //unitTest( sf.canWrite() == true ); + //unitTest( sf.canSeek() == true ); + sf.close(); + struct stat sdat; + stat("testfile1", &sdat ); + unitTest( sdat.st_size == 256 ); } - //unitTest( sf.canRead() == false ); - //unitTest( sf.canWrite() == true ); - //unitTest( sf.canSeek() == true ); - sf.close(); - struct stat sdat; - stat("testfile1", &sdat ); - unitTest( sdat.st_size == 256 ); -} -{%readBlocks} -{ - Bu::File sf("testfile1", Bu::File::Read ); - unsigned char buf[50]; - size_t total = 0; - for(;;) + test readBlocks { - size_t s = sf.read( buf, 50 ); - for( size_t c = 0; c < s; c++ ) + Bu::File sf("testfile1", Bu::File::Read ); + unsigned char buf[50]; + size_t total = 0; + for(;;) { - unitTest( buf[c] == (unsigned char)(c+total) ); - } - total += s; - if( s < 50 ) - { - unitTest( total == 256 ); - unitTest( sf.isEos() == true ); - break; + size_t s = sf.read( buf, 50 ); + for( size_t c = 0; c < s; c++ ) + { + unitTest( buf[c] == (unsigned char)(c+total) ); + } + total += s; + if( s < 50 ) + { + unitTest( total == 256 ); + unitTest( sf.isEos() == true ); + break; + } } + sf.close(); } - sf.close(); -} -{%readError1} -{ - try + test readError1 { - Bu::File sf("doesn'texist", Bu::File::Read ); - unitFailed("No exception thrown"); - } - catch( Bu::FileException &e ) - { - return; + try + { + Bu::File sf("doesn'texist", Bu::File::Read ); + unitFailed("No exception thrown"); + } + catch( Bu::FileException &e ) + { + return; + } } -} -{%readError2} -{ - Bu::File sf("testfile1", Bu::File::Read ); - char buf[256]; - int r = sf.read( buf, 256 ); - unitTest( r == 256 ); - // You have to read past the end to set the EOS flag. - unitTest( sf.isEos() == false ); - try + test readError2 { - if( sf.read( buf, 5 ) > 0 ) + Bu::File sf("testfile1", Bu::File::Read ); + char buf[256]; + int r = sf.read( buf, 256 ); + unitTest( r == 256 ); + // You have to read past the end to set the EOS flag. + unitTest( sf.isEos() == false ); + try { - unitFailed("Non-zero read result"); + if( sf.read( buf, 5 ) > 0 ) + { + unitFailed("Non-zero read result"); + } + else + { + sf.close(); + } } - else + catch( Bu::FileException &e ) { sf.close(); + return; } } - catch( Bu::FileException &e ) - { - sf.close(); - return; - } } -- cgit v1.2.3