X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Utils%2FException.test.cc;h=0f0db829c1022ef40ac81b52cbd2e8751a970cbe;hb=532240d72e09e19e57fac9bb55c2560b9c9e5b97;hp=7421921aa1e2c6199e227dca679e351412999146;hpb=96d3a2a43b4e6d7693a136a3adeb099440f19068;p=senf.git diff --git a/Utils/Exception.test.cc b/Utils/Exception.test.cc index 7421921..0f0db82 100644 --- a/Utils/Exception.test.cc +++ b/Utils/Exception.test.cc @@ -1,8 +1,8 @@ // $Id$ // -// Copyright (C) 2007 -// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) -// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// Copyright (C) 2007 +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY // Stefan Bund // // This program is free software; you can redistribute it and/or modify @@ -21,22 +21,77 @@ // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /** \file - \brief Exception.test unit tests */ + \brief Exception unit tests */ //#include "Exception.test.hh" //#include "Exception.test.ih" // Custom includes #include "Exception.hh" +#include +#include -#include +#include "../Utils/auto_unit_test.hh" #include #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) << "\nmore"; + } + catch(senf::Exception & e) { + e << "\nx=" << 1 << boost::format("\ny=%d") % 2; + throw; + } + } + catch (senf::SystemException & e) { + BOOST_CHECK_EQUAL( e.errorNumber(), ENOENT ); + 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" ); + } +} ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_