4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief Exception unit tests */
26 //#include "Exception.test.hh"
27 //#include "Exception.test.ih"
30 #include "Exception.hh"
31 #include <boost/format.hpp>
34 #include <senf/Utils/auto_unit_test.hh>
35 #include <boost/test/test_tools.hpp>
38 ///////////////////////////////cc.p////////////////////////////////////////
40 SENF_AUTO_UNIT_TEST(wrapException)
42 bool bad_cast (false);
49 throw std::bad_cast();
51 SENF_WRAP_EXC(std::bad_cast)
53 SENF_WRAP_EXC(std::bad_cast)
55 catch (senf::ExceptionMixin & ex) {
56 ex << "\nspecial exception";
60 catch (std::exception const & ex) {
62 BOOST_CHECK( std::string(ex.what()).find("-- \n") != std::string::npos );
64 BOOST_CHECK( std::string(ex.what()).find("special exception") != std::string::npos );
68 catch (std::bad_cast &) {
71 BOOST_CHECK( bad_cast );
74 SENF_AUTO_UNIT_TEST(errnoException)
78 throw senf::SystemException("::open()", ENOENT) << "\nmore";
80 catch(senf::Exception & e) {
81 e << "\nx=" << 1 << boost::format("\ny=%d") % 2;
85 catch (senf::SystemException & e) {
86 BOOST_CHECK_EQUAL( e.errorNumber(), ENOENT );
87 BOOST_CHECK_EQUAL( e.errorString(), "No such file or directory" );
88 std::string what (e.what());
89 std::string::size_type pos (what.find("-- \n"));
90 if (pos != std::string::npos)
91 what = std::string(what, pos+4);
92 BOOST_CHECK_EQUAL( what, "[No such file or directory] ::open()\nmore\nx=1\ny=2" );
96 ///////////////////////////////cc.e////////////////////////////////////////
103 // comment-column: 40
104 // c-file-style: "senf"
105 // indent-tabs-mode: nil
106 // ispell-local-dictionary: "american"
107 // compile-command: "scons -u test"