From 45e065bc4fc93731ea9a0543462bc7cf9e6084d7 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 7 Jan 2009 15:59:57 +0000 Subject: 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. --- src/unit/file.unit | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 src/unit/file.unit (limited to 'src/unit/file.unit') diff --git a/src/unit/file.unit b/src/unit/file.unit new file mode 100644 index 0000000..e6320ad --- /dev/null +++ b/src/unit/file.unit @@ -0,0 +1,95 @@ +// vim: syntax=cpp +/* + * Copyright (C) 2007-2008 Xagasoft, All rights reserved. + * + * This file is part of the libbu++ library and is released under the + * terms of the license contained in the file LICENSE. + */ + +#include "bu/file.h" + +#include +#include +#include + +{=Init} + +{%writeFull} +{ + Bu::File sf("testfile1", Bu::File::Write ); + 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 ); +} + +{%readBlocks} +{ + Bu::File sf("testfile1", Bu::File::Read ); + unsigned char buf[50]; + size_t total = 0; + for(;;) + { + 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(); +} + +{%readError1} +{ + 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 + { + if( sf.read( buf, 5 ) > 0 ) + { + unitFailed("Non-zero read result"); + } + else + { + sf.close(); + } + } + catch( Bu::FileException &e ) + { + sf.close(); + return; + } +} -- cgit v1.2.3