Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <wibble/test.h>
00022 #include <wibble/exception.h>
00023 #include <errno.h>
00024
00025 using namespace std;
00026 namespace wex = wibble::exception;
00027
00028 struct TestException {
00029 Test generic()
00030 {
00031 try {
00032 throw wex::Generic("antani");
00033 } catch ( std::exception& e ) {
00034 assert(string(e.what()).find("antani") != string::npos);
00035 }
00036
00037 try {
00038 throw wex::Generic("antani");
00039 } catch ( wex::Generic& e ) {
00040 assert(e.fullInfo().find("antani") != string::npos);
00041 }
00042 }
00043
00044 Test system()
00045 {
00046 try {
00047 assert_eq(access("does-not-exist", F_OK), -1);
00048 throw wex::System("checking for existance of nonexisting file");
00049 } catch ( wibble::exception::System& e ) {
00050
00051 assert_eq(e.code(), ENOENT);
00052 }
00053
00054 try {
00055 assert_eq(access("does-not-exist", F_OK), -1);
00056 throw wex::File("does-not-exist", "checking for existance of nonexisting file");
00057 } catch ( wex::File& e ) {
00058
00059 assert_eq(e.code(), ENOENT);
00060 assert(e.fullInfo().find("does-not-exist") != string::npos);
00061 }
00062 }
00063
00064 Test badCast()
00065 {
00066 int check = -1;
00067 try {
00068 check = 0;
00069 throw wex::BadCastExt< int, const char * >( "test" );
00070 check = 1;
00071 } catch ( wex::BadCast& e ) {
00072 assert_eq( e.fullInfo(),
00073 "bad cast: from i to PKc. Context:\n test" );
00074 check = 2;
00075 }
00076 assert_eq( check, 2 );
00077 }
00078
00079 Test addContext() {
00080 wex::AddContext ctx( "toplevel context" );
00081 int check = -1;
00082 try {
00083 wex::AddContext ctx( "first context" );
00084 check = 0;
00085 {
00086 wex::AddContext ctx( "second context" );
00087 throw wex::Generic( "foobar" );
00088 }
00089 } catch( wex::Generic &e ) {
00090 assert_eq( e.formatContext(), "toplevel context, \n "
00091 "first context, \n "
00092 "second context, \n "
00093 "foobar" );
00094 check = 2;
00095 }
00096 assert_eq( check, 2 );
00097 }
00098 };
00099
00100