X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Utils%2FException.test.cc;h=58a2f2bf2fc2e5e1e9a7fd9a683111863fbde92a;hb=412024ed31a4ab4eaea7a4165a434f8efebee325;hp=a65aa5fd3af4e687e9a452f58b339d6a8cecf506;hpb=a66bffcc77f006b22190e1c27cbe0cd75fc4501c;p=senf.git diff --git a/Utils/Exception.test.cc b/Utils/Exception.test.cc index a65aa5f..58a2f2b 100644 --- a/Utils/Exception.test.cc +++ b/Utils/Exception.test.cc @@ -37,11 +37,45 @@ #define prefix_ ///////////////////////////////cc.p//////////////////////////////////////// +BOOST_AUTO_UNIT_TEST(wrapException) +{ + bool bad_cast (false); + + try { + try { + try { + try { + try { + throw std::bad_cast(); + } + SENF_WRAP_EXC(std::bad_cast) + } + SENF_WRAP_EXC(std::bad_cast) + } + catch (senf::ExceptionMixin & ex) { + ex << "\nspecial exception"; + throw; + } + } + catch (std::exception const & ex) { +#ifdef SENF_DEBUG + BOOST_CHECK( std::string(ex.what()).find("-- \n") != std::string::npos ); +#endif + BOOST_CHECK( std::string(ex.what()).find("special exception") != std::string::npos ); + throw; + } + } + catch (std::bad_cast &) { + bad_cast = true; + } + BOOST_CHECK( bad_cast ); +} + BOOST_AUTO_UNIT_TEST(errnoException) { try { try { - throw senf::SystemException("::open()", ENOENT); + throw senf::SystemException("::open()", ENOENT) << "\nmore"; } catch(senf::Exception & e) { e << "\nx=" << 1 << boost::format("\ny=%d") % 2; @@ -50,8 +84,12 @@ BOOST_AUTO_UNIT_TEST(errnoException) } catch (senf::SystemException & e) { BOOST_CHECK_EQUAL( e.errorNumber(), ENOENT ); - //BOOST_CHECK_EQUAL( e.what(), "::open(): (2) No such file or directory\nx=1\ny=2" ); - BOOST_CHECK_EQUAL( e.what(), "[No such file or directory]; ::open()\nx=1\ny=2" ); + BOOST_CHECK_EQUAL( e.errorString(), "No such file or directory" ); + std::string what (e.what()); + std::string::size_type pos (what.find("-- \n")); + if (pos != std::string::npos) + what = std::string(what, pos+4); + BOOST_CHECK_EQUAL( what, "[No such file or directory] ::open()\nmore\nx=1\ny=2" ); } }