1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
// excepttest.cc
#include <string>
using namespace std;
#include "ExceptionTest.hh"
using namespace ExceptionTest;
#include "synch.hh"
#define MYPASS( AAA ) \
tracker.writeComment(AAA); \
tracker.endPart(part_no, synch::ResultType_PASS);
#define MYFAIL( AAA ) \
tracker.writeComment(AAA); \
tracker.endPart(part_no, synch::ResultType_FAIL);
int main() {
int part_no = 0;
synch::RegOut tracker = synch::RegOut::_create();
Fib fib = Fib::_create();
tracker.setExpectations(4);
try {
tracker.startPart(++part_no);
fib.getFib(10,25,200,0);
MYPASS( "no exception thrown (none expected)" );
} catch (...) {
MYFAIL("unexpected exception thrown");
}
try {
tracker.startPart(++part_no);
fib.getFib(-1,10,10,0);
MYFAIL( "no exception thrown (NegativeValueException expected)" );
} catch ( NegativeValueException ex ) {
MYPASS( "NegativeValueException thrown (as expected)" );
} catch ( ... ) {
MYFAIL( "unexpected exception thrown" );
}
try {
tracker.startPart(++part_no);
fib.getFib(10,1,1000,0);
MYFAIL( "no exception thrown (TooDeepException expected)" );
} catch ( TooDeepException ex ) {
MYFAIL( "TooDeepException thrown (and unexpectedly caught!)");
} catch ( FibException ex ) { // catch declared types
TooDeepException ex2 = ex; // downcast
if ( !ex2 ) {
MYFAIL( "FibException caught, but cannot cast to TooDeepException" );
} else {
MYPASS( "FibException caught, and correctly cast to TooDeepException" );
}
} catch( ... ) {
MYFAIL( "unexpected exception thrown" );
}
try {
tracker.startPart(++part_no);
fib.getFib(10,1000,1,0);
MYFAIL( "no exception thrown (TooBigException expected)" );
} catch ( TooBigException ex ) {
MYFAIL( "TooBigException thrown (and unexpectedly caught!)");
} catch ( FibException ex ) { // catch declared types
TooBigException ex2 = ex; // downcast
if ( !ex2 ) {
MYFAIL( "FibException caught, but cannot cast to TooBigException" );
} else {
MYPASS( "FibException caught, and correctly cast to TooBigException" );
}
} catch( ... ) {
MYFAIL( "unexpected exception thrown" );
}
tracker.close();
return 0;
}
|