diff options
author | Mike Buland <eichlan@xagasoft.com> | 2010-05-25 17:45:03 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2010-05-25 17:45:03 +0000 |
commit | 24ab24777d7cd72b7ff35a9d02cb43e26f006b0d (patch) | |
tree | 09b1e2e72e05ff6e7502f02edb6d3fc6100cc741 /src | |
parent | b4e1fa15d0c809439139db3a60a3969d848dcf77 (diff) | |
download | libbu++-24ab24777d7cd72b7ff35a9d02cb43e26f006b0d.tar.gz libbu++-24ab24777d7cd72b7ff35a9d02cb43e26f006b0d.tar.bz2 libbu++-24ab24777d7cd72b7ff35a9d02cb43e26f006b0d.tar.xz libbu++-24ab24777d7cd72b7ff35a9d02cb43e26f006b0d.zip |
More myriad testing, fixes, arrangement, etc. UnitSuite add-ons, it has some
command line parameters now, I would like to also add an automatic paramter that
would switch it to a computer-readable output mode for use in a larger testing
framework.
Diffstat (limited to 'src')
-rw-r--r-- | src/cachestoremyriad.h | 3 | ||||
-rw-r--r-- | src/exceptionbase.h | 2 | ||||
-rw-r--r-- | src/myriad.cpp | 51 | ||||
-rw-r--r-- | src/myriad.h | 31 | ||||
-rw-r--r-- | src/optparser.cpp | 2 | ||||
-rw-r--r-- | src/optparser.h | 2 | ||||
-rw-r--r-- | src/tools/myriad.cpp | 6 | ||||
-rw-r--r-- | src/unitsuite.cpp | 47 | ||||
-rw-r--r-- | src/unitsuite.h | 8 |
9 files changed, 123 insertions, 29 deletions
diff --git a/src/cachestoremyriad.h b/src/cachestoremyriad.h index 3ae3ec8..bffa0bb 100644 --- a/src/cachestoremyriad.h +++ b/src/cachestoremyriad.h | |||
@@ -64,7 +64,8 @@ namespace Bu | |||
64 | mStore.initialize( iBlockSize, iPreAllocate ); | 64 | mStore.initialize( iBlockSize, iPreAllocate ); |
65 | int iStream = mStore.createStream(); | 65 | int iStream = mStore.createStream(); |
66 | if( iStream != 1 ) | 66 | if( iStream != 1 ) |
67 | throw Bu::ExceptionBase("That's...horrible...id = %d.\n\n", iStream ); | 67 | throw Bu::ExceptionBase("That's...horrible...id = %d.\n\n", |
68 | iStream ); | ||
68 | MyriadStream ns = mStore.openStream( 1 ); | 69 | MyriadStream ns = mStore.openStream( 1 ); |
69 | Bu::Archive ar( ns, Bu::Archive::save ); | 70 | Bu::Archive ar( ns, Bu::Archive::save ); |
70 | ar << hId; | 71 | ar << hId; |
diff --git a/src/exceptionbase.h b/src/exceptionbase.h index 178fc86..c92962f 100644 --- a/src/exceptionbase.h +++ b/src/exceptionbase.h | |||
@@ -114,7 +114,7 @@ class name : public parent \ | |||
114 | }; | 114 | }; |
115 | 115 | ||
116 | #define subExceptionDeclBegin( name ) \ | 116 | #define subExceptionDeclBegin( name ) \ |
117 | class name : public Bu::ExceptionBase \ | 117 | class name : public Bu::ExceptionBase \ |
118 | { \ | 118 | { \ |
119 | public: \ | 119 | public: \ |
120 | name( const char *sFormat, ... ) throw (); \ | 120 | name( const char *sFormat, ... ) throw (); \ |
diff --git a/src/myriad.cpp b/src/myriad.cpp index f5bc67b..2f5c14f 100644 --- a/src/myriad.cpp +++ b/src/myriad.cpp | |||
@@ -24,13 +24,28 @@ namespace Bu | |||
24 | } | 24 | } |
25 | } | 25 | } |
26 | 26 | ||
27 | Bu::Myriad::Myriad( Bu::Stream &sStore ) : | 27 | Bu::Myriad::Myriad( Bu::Stream &sStore, int iBlockSize, int iPreallocate ) : |
28 | sStore( sStore ), | 28 | sStore( sStore ), |
29 | iBlockSize( 0 ), | 29 | iBlockSize( iBlockSize ), |
30 | iBlocks( 0 ), | 30 | iBlocks( 0 ), |
31 | iUsed( 0 ), | 31 | iUsed( 0 ), |
32 | bHeaderChanged( false ) | 32 | bHeaderChanged( false ) |
33 | { | 33 | { |
34 | try | ||
35 | { | ||
36 | initialize(); | ||
37 | } | ||
38 | catch( Bu::MyriadException &e ) | ||
39 | { | ||
40 | if( e.getErrorCode() == MyriadException::emptyStream ) | ||
41 | { | ||
42 | initialize( iBlockSize, iPreallocate ); | ||
43 | } | ||
44 | else | ||
45 | { | ||
46 | throw; | ||
47 | } | ||
48 | } | ||
34 | } | 49 | } |
35 | 50 | ||
36 | Bu::Myriad::~Myriad() | 51 | Bu::Myriad::~Myriad() |
@@ -69,18 +84,19 @@ void Bu::Myriad::initialize() | |||
69 | 84 | ||
70 | unsigned char buf[4]; | 85 | unsigned char buf[4]; |
71 | if( sStore.read( buf, 4 ) < 4 ) | 86 | if( sStore.read( buf, 4 ) < 4 ) |
72 | throw MyriadException("Input stream appears to be empty."); | 87 | throw MyriadException( MyriadException::emptyStream, |
88 | "Input stream appears to be empty."); | ||
73 | if( memcmp( buf, Myriad_MAGIC_CODE, 4 ) ) | 89 | if( memcmp( buf, Myriad_MAGIC_CODE, 4 ) ) |
74 | { | 90 | { |
75 | throw MyriadException( | 91 | throw MyriadException( MyriadException::invalidFormat, |
76 | "Stream does not appear to be a valid Myriad format."); | 92 | "Stream does not appear to be a valid Myriad format."); |
77 | } | 93 | } |
78 | sStore.read( buf, 2 ); | 94 | sStore.read( buf, 2 ); |
79 | if( buf[0] != 1 ) | 95 | if( buf[0] != 1 ) |
80 | throw MyriadException( | 96 | throw MyriadException( MyriadException::badVersion, |
81 | "We can only handle version 1 for now."); | 97 | "We can only handle version 1 for now."); |
82 | if( buf[1] != 32 ) | 98 | if( buf[1] != 32 ) |
83 | throw MyriadException( | 99 | throw MyriadException( MyriadException::invalidWordSize, |
84 | "We can only handle 32-bit words at the moment."); | 100 | "We can only handle 32-bit words at the moment."); |
85 | sStore.read( &iBlockSize, 4 ); | 101 | sStore.read( &iBlockSize, 4 ); |
86 | int iStreams; | 102 | int iStreams; |
@@ -342,12 +358,16 @@ int Bu::Myriad::findEmptyBlock() | |||
342 | // sio << "Myriad: findEmptyBlock(): No empty blocks, adding new one." << sio.nl; | 358 | // sio << "Myriad: findEmptyBlock(): No empty blocks, adding new one." << sio.nl; |
343 | 359 | ||
344 | bsBlockUsed.setSize( bsBlockUsed.getSize()+1, false ); | 360 | bsBlockUsed.setSize( bsBlockUsed.getSize()+1, false ); |
361 | /* | ||
345 | sStore.setPos( iBlockSize*iBlocks ); | 362 | sStore.setPos( iBlockSize*iBlocks ); |
346 | 363 | ||
347 | char *pBlock = new char[iBlockSize]; | 364 | char *pBlock = new char[iBlockSize]; |
348 | memset( pBlock, 0, iBlockSize ); | 365 | memset( pBlock, 0, iBlockSize ); |
349 | sStore.write( pBlock, iBlockSize ); | 366 | sStore.write( pBlock, iBlockSize ); |
350 | delete[] pBlock; | 367 | delete[] pBlock; |
368 | */ | ||
369 | |||
370 | sStore.setSize( (iBlocks+1)*iBlockSize ); | ||
351 | 371 | ||
352 | return iBlocks++; | 372 | return iBlocks++; |
353 | } | 373 | } |
@@ -400,6 +420,9 @@ Bu::Myriad::Stream *Bu::Myriad::findStream( int iId ) | |||
400 | return *i; | 420 | return *i; |
401 | } | 421 | } |
402 | 422 | ||
423 | throw MyriadException( MyriadException::noSuchStream, | ||
424 | "The requested stream doesn't exist and cannot be opened." ); | ||
425 | |||
403 | return NULL; | 426 | return NULL; |
404 | } | 427 | } |
405 | 428 | ||
@@ -480,3 +503,19 @@ void Bu::Myriad::setStreamSize( Stream *pStream, long iSize ) | |||
480 | } | 503 | } |
481 | } | 504 | } |
482 | 505 | ||
506 | bool Bu::Myriad::isMyriad( Bu::Stream &sStore ) | ||
507 | { | ||
508 | sStore.setPos( 0 ); | ||
509 | |||
510 | unsigned char buf[4]; | ||
511 | if( sStore.read( buf, 4 ) < 4 ) | ||
512 | throw MyriadException( MyriadException::emptyStream, | ||
513 | "Input stream appears to be empty."); | ||
514 | sStore.setPos( 0 ); | ||
515 | if( memcmp( buf, Myriad_MAGIC_CODE, 4 ) ) | ||
516 | { | ||
517 | return false; | ||
518 | } | ||
519 | return true; | ||
520 | } | ||
521 | |||
diff --git a/src/myriad.h b/src/myriad.h index 900037b..b5cd18c 100644 --- a/src/myriad.h +++ b/src/myriad.h | |||
@@ -19,7 +19,16 @@ namespace Bu | |||
19 | class Stream; | 19 | class Stream; |
20 | class MyriadStream; | 20 | class MyriadStream; |
21 | 21 | ||
22 | subExceptionDecl( MyriadException ) | 22 | subExceptionDeclBegin( MyriadException ) |
23 | enum | ||
24 | { | ||
25 | emptyStream, | ||
26 | invalidFormat, | ||
27 | badVersion, | ||
28 | invalidWordSize, | ||
29 | noSuchStream | ||
30 | }; | ||
31 | subExceptionDeclEnd() | ||
23 | 32 | ||
24 | /** | 33 | /** |
25 | * Numerically Indexed Data Streams. This is a working name so I can | 34 | * Numerically Indexed Data Streams. This is a working name so I can |
@@ -69,18 +78,10 @@ namespace Bu | |||
69 | { | 78 | { |
70 | friend class MyriadStream; | 79 | friend class MyriadStream; |
71 | public: | 80 | public: |
72 | Myriad( Bu::Stream &sStore ); | 81 | Myriad( Bu::Stream &sStore, int iBlockSize=512, int iPreallocate=8 ); |
73 | virtual ~Myriad(); | 82 | virtual ~Myriad(); |
74 | 83 | ||
75 | /** | 84 | /** |
76 | * Initialize this object based on the data already in the assosiated | ||
77 | * stream. This will be called automatically for you if you forget, | ||
78 | * but if you want to pre-initialize for some reason, just call this | ||
79 | * once before you actually start doing anything with your Myriad. | ||
80 | */ | ||
81 | void initialize(); | ||
82 | |||
83 | /** | ||
84 | * Create a new Myriad system in the assosiated stream. This should be | 85 | * Create a new Myriad system in the assosiated stream. This should be |
85 | * used carefully, it will destroy all data already within the stream. | 86 | * used carefully, it will destroy all data already within the stream. |
86 | * More options will probably be added soon. | 87 | * More options will probably be added soon. |
@@ -114,7 +115,17 @@ namespace Bu | |||
114 | */ | 115 | */ |
115 | void sync(); | 116 | void sync(); |
116 | 117 | ||
118 | static bool isMyriad( Bu::Stream &sStore ); | ||
119 | |||
117 | private: | 120 | private: |
121 | /** | ||
122 | * Initialize this object based on the data already in the assosiated | ||
123 | * stream. This will be called automatically for you if you forget, | ||
124 | * but if you want to pre-initialize for some reason, just call this | ||
125 | * once before you actually start doing anything with your Myriad. | ||
126 | */ | ||
127 | void initialize(); | ||
128 | |||
118 | enum | 129 | enum |
119 | { | 130 | { |
120 | blockUnused = 0xFFFFFFFFUL | 131 | blockUnused = 0xFFFFFFFFUL |
diff --git a/src/optparser.cpp b/src/optparser.cpp index 53efe92..864d8ce 100644 --- a/src/optparser.cpp +++ b/src/optparser.cpp | |||
@@ -290,7 +290,7 @@ int Bu::OptParser::optHelp( StrArray /*aParams*/ ) | |||
290 | return 0; | 290 | return 0; |
291 | } | 291 | } |
292 | 292 | ||
293 | void Bu::OptParser::optionError( const Bu::FString sOption ) | 293 | void Bu::OptParser::optionError( const Bu::FString &sOption ) |
294 | { | 294 | { |
295 | sio << "Unregcognized option discovered: " << sOption << sio.nl << sio.nl; | 295 | sio << "Unregcognized option discovered: " << sOption << sio.nl << sio.nl; |
296 | exit( 1 ); | 296 | exit( 1 ); |
diff --git a/src/optparser.h b/src/optparser.h index aacafc3..2936a4b 100644 --- a/src/optparser.h +++ b/src/optparser.h | |||
@@ -182,7 +182,7 @@ namespace Bu | |||
182 | * been handled by an option, and isn't an option (starts with - or --). | 182 | * been handled by an option, and isn't an option (starts with - or --). |
183 | * To change this behaviour call | 183 | * To change this behaviour call |
184 | */ | 184 | */ |
185 | virtual void optionError( const Bu::FString sOption ); | 185 | virtual void optionError( const Bu::FString &sOption ); |
186 | 186 | ||
187 | void setNonOption( OptionSignal sSignal ); | 187 | void setNonOption( OptionSignal sSignal ); |
188 | 188 | ||
diff --git a/src/tools/myriad.cpp b/src/tools/myriad.cpp index 605aac9..535d7ac 100644 --- a/src/tools/myriad.cpp +++ b/src/tools/myriad.cpp | |||
@@ -121,7 +121,6 @@ int main( int argc, char *argv[] ) | |||
121 | { | 121 | { |
122 | File fIn( opts.sFile, File::Read ); | 122 | File fIn( opts.sFile, File::Read ); |
123 | Myriad m( fIn ); | 123 | Myriad m( fIn ); |
124 | m.initialize(); | ||
125 | } | 124 | } |
126 | break; | 125 | break; |
127 | 126 | ||
@@ -135,7 +134,6 @@ int main( int argc, char *argv[] ) | |||
135 | { | 134 | { |
136 | File fOut( opts.sFile, File::Write|File::Read ); | 135 | File fOut( opts.sFile, File::Write|File::Read ); |
137 | Myriad m( fOut ); | 136 | Myriad m( fOut ); |
138 | m.initialize(); | ||
139 | m.createStream( opts.iPreallocate ); | 137 | m.createStream( opts.iPreallocate ); |
140 | } | 138 | } |
141 | break; | 139 | break; |
@@ -143,14 +141,13 @@ int main( int argc, char *argv[] ) | |||
143 | case modeStreamDump: | 141 | case modeStreamDump: |
144 | if( !opts.sFile.isSet() ) | 142 | if( !opts.sFile.isSet() ) |
145 | { | 143 | { |
146 | sio << "Please specify a file manipulate." << sio.nl; | 144 | sio << "Please specify a file to manipulate." << sio.nl; |
147 | return 0; | 145 | return 0; |
148 | } | 146 | } |
149 | else | 147 | else |
150 | { | 148 | { |
151 | File fOut( opts.sFile, File::Read ); | 149 | File fOut( opts.sFile, File::Read ); |
152 | Myriad m( fOut ); | 150 | Myriad m( fOut ); |
153 | m.initialize(); | ||
154 | MyriadStream s = m.openStream( opts.iStream ); | 151 | MyriadStream s = m.openStream( opts.iStream ); |
155 | sio << "Stream " << opts.iStream << ":" << sio.nl; | 152 | sio << "Stream " << opts.iStream << ":" << sio.nl; |
156 | char buf[8]; | 153 | char buf[8]; |
@@ -198,7 +195,6 @@ int main( int argc, char *argv[] ) | |||
198 | { | 195 | { |
199 | File fOut( opts.sFile, File::Write|File::Read ); | 196 | File fOut( opts.sFile, File::Write|File::Read ); |
200 | Myriad m( fOut ); | 197 | Myriad m( fOut ); |
201 | m.initialize(); | ||
202 | MyriadStream sOut = m.openStream( | 198 | MyriadStream sOut = m.openStream( |
203 | m.createStream( opts.iPreallocate ) | 199 | m.createStream( opts.iPreallocate ) |
204 | ); | 200 | ); |
diff --git a/src/unitsuite.cpp b/src/unitsuite.cpp index 711b9b5..7d8cc2a 100644 --- a/src/unitsuite.cpp +++ b/src/unitsuite.cpp | |||
@@ -8,6 +8,8 @@ | |||
8 | #include "bu/unitsuite.h" | 8 | #include "bu/unitsuite.h" |
9 | #include "bu/file.h" | 9 | #include "bu/file.h" |
10 | #include "bu/sio.h" | 10 | #include "bu/sio.h" |
11 | #include "bu/optparser.h" | ||
12 | #include <stdlib.h> | ||
11 | 13 | ||
12 | using namespace Bu; | 14 | using namespace Bu; |
13 | 15 | ||
@@ -30,8 +32,17 @@ Bu::UnitSuite::~UnitSuite() | |||
30 | } | 32 | } |
31 | 33 | ||
32 | // Argument handling is coming soon, I promise. | 34 | // Argument handling is coming soon, I promise. |
33 | int Bu::UnitSuite::run( int /*argc*/, char * /*argv */ [] ) | 35 | int Bu::UnitSuite::run( int argc, char *argv[] ) |
34 | { | 36 | { |
37 | bool bCleanup = true; | ||
38 | OptParser p; | ||
39 | p.addOption( Bu::slot( this, &Bu::UnitSuite::onListCases ), 'l', "list", | ||
40 | "List available test cases." ); | ||
41 | p.addOption( bCleanup, "no-cleanup", "Don't erase temp files."); | ||
42 | p.setOverride( "no-cleanup", "false" ); | ||
43 | p.addHelpOption(); | ||
44 | p.parse( argc, argv ); | ||
45 | |||
35 | int iEPass = 0; | 46 | int iEPass = 0; |
36 | int iEFail = 0; | 47 | int iEFail = 0; |
37 | int iUPass = 0; | 48 | int iUPass = 0; |
@@ -133,9 +144,12 @@ int Bu::UnitSuite::run( int /*argc*/, char * /*argv */ [] ) | |||
133 | if( iUPass == 0 && iUFail == 0 ) | 144 | if( iUPass == 0 && iUFail == 0 ) |
134 | sio << "\tNothing unexpected." << sio.nl << sio.nl; | 145 | sio << "\tNothing unexpected." << sio.nl << sio.nl; |
135 | 146 | ||
136 | for( StrList::iterator i = lFileCleanup.begin(); i; i++ ) | 147 | if( bCleanup ) |
137 | { | 148 | { |
138 | unlink( (*i).getStr() ); | 149 | for( StrList::iterator i = lFileCleanup.begin(); i; i++ ) |
150 | { | ||
151 | unlink( (*i).getStr() ); | ||
152 | } | ||
139 | } | 153 | } |
140 | 154 | ||
141 | return 0; | 155 | return 0; |
@@ -171,3 +185,30 @@ void Bu::UnitSuite::setName( const FString &sName ) | |||
171 | sSuiteName = sName; | 185 | sSuiteName = sName; |
172 | } | 186 | } |
173 | 187 | ||
188 | int Bu::UnitSuite::onListCases( StrArray aParam ) | ||
189 | { | ||
190 | sio << "Test cases:" << sio.nl; | ||
191 | for( TestList::iterator i = lTests.begin(); i; i++ ) | ||
192 | { | ||
193 | sio << "\t- " << Fmt( iNameWidth, 10, Fmt::Left ) << (*i).sName << " " | ||
194 | << (*i).eExpect << sio.nl; | ||
195 | } | ||
196 | sio << sio.nl; | ||
197 | exit( 0 ); | ||
198 | return 0; | ||
199 | } | ||
200 | |||
201 | Bu::Formatter &Bu::operator<<( Bu::Formatter &f, const Bu::UnitSuite::Expect &e ) | ||
202 | { | ||
203 | switch( e ) | ||
204 | { | ||
205 | case Bu::UnitSuite::expectPass: | ||
206 | return f << "expect pass"; | ||
207 | |||
208 | case Bu::UnitSuite::expectFail: | ||
209 | return f << "expect fail"; | ||
210 | } | ||
211 | |||
212 | return f << "**error**"; | ||
213 | } | ||
214 | |||
diff --git a/src/unitsuite.h b/src/unitsuite.h index 74aac6f..ddd3835 100644 --- a/src/unitsuite.h +++ b/src/unitsuite.h | |||
@@ -10,8 +10,9 @@ | |||
10 | 10 | ||
11 | #include <stdint.h> | 11 | #include <stdint.h> |
12 | #include "bu/list.h" | 12 | #include "bu/list.h" |
13 | #include "fstring.h" | 13 | #include "bu/fstring.h" |
14 | #include "bu/file.h" | 14 | #include "bu/file.h" |
15 | #include "bu/array.h" | ||
15 | 16 | ||
16 | namespace Bu | 17 | namespace Bu |
17 | { | 18 | { |
@@ -96,6 +97,9 @@ namespace Bu | |||
96 | void setName( const FString &sName ); | 97 | void setName( const FString &sName ); |
97 | 98 | ||
98 | private: | 99 | private: |
100 | int onListCases( Bu::Array<Bu::FString> aParam ); | ||
101 | |||
102 | private: | ||
99 | typedef struct TestInfo | 103 | typedef struct TestInfo |
100 | { | 104 | { |
101 | FString sName; | 105 | FString sName; |
@@ -113,6 +117,8 @@ namespace Bu | |||
113 | StrList lFileCleanup; | 117 | StrList lFileCleanup; |
114 | int iNameWidth; | 118 | int iNameWidth; |
115 | }; | 119 | }; |
120 | |||
121 | Bu::Formatter &operator<<( Bu::Formatter &f, const Bu::UnitSuite::Expect &e ); | ||
116 | } | 122 | } |
117 | 123 | ||
118 | #define addTest( fn ) add( static_cast<Bu::UnitSuite::Test>(&fn), #fn ) | 124 | #define addTest( fn ) add( static_cast<Bu::UnitSuite::Test>(&fn), #fn ) |