// $Id$
//
-// Copyright (C) 2007
-// Fraunhofer Institute for Open Communication Systems (FOKUS)
-// Competence Center NETwork research (NET), St. Augustin, GERMANY
+// Copyright (C) 2007
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
// Stefan Bund <g0dil@berlios.de>
//
// This program is free software; you can redistribute it and/or modify
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
-BOOST_AUTO_UNIT_TEST(errnoException)
+BOOST_AUTO_UNIT_TEST(wrapException)
{
- BOOST_CHECK_THROW( senf::throwErrno(), senf::SystemException );
- BOOST_CHECK_THROW( senf::throwErrno(ENOENT), senf::SystemException );
- BOOST_CHECK_THROW( senf::throwErrno(""), senf::SystemException );
- BOOST_CHECK_THROW( senf::throwErrno("", ENOENT), senf::SystemException );
+ 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) {
+ BOOST_CHECK( std::string(ex.what()).find("-- \n") != std::string::npos );
+ 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 {
- senf::throwErrno("::open()", ENOENT);
+ throw senf::SystemException("::open()", ENOENT) << "\nmore";
}
- catch(senf::SystemException & e) {
- e << ": x=" << 1 << boost::format(", y=%d") % 2;
+ 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.what(), "::open(): (2) No such file or directory: x=1, y=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" );
}
}