Fixed two problems related to g++ 4.0.0 on Darwin 9.8.0
[libdai.git] / tests / unit / exceptions_test.cpp
1 /* This file is part of libDAI - http://www.libdai.org/
2 *
3 * libDAI is licensed under the terms of the GNU General Public License version
4 * 2, or (at your option) any later version. libDAI is distributed without any
5 * warranty. See the file COPYING for more details.
6 *
7 * Copyright (C) 2010 Joris Mooij [joris dot mooij at libdai dot org]
8 */
9
10
11 #include <dai/exceptions.h>
12 #include <strstream>
13
14
15 using namespace dai;
16
17
18 #define BOOST_TEST_MODULE ExceptionsTest
19
20
21 #include <boost/test/unit_test.hpp>
22
23
24 BOOST_AUTO_TEST_CASE( ExceptionsTest ) {
25 BOOST_CHECK_THROW( DAI_THROW(NOT_IMPLEMENTED), Exception );
26 BOOST_CHECK_THROW( DAI_THROW(NOT_IMPLEMENTED), std::runtime_error );
27 BOOST_CHECK_THROW( DAI_THROWE(NOT_IMPLEMENTED,"Detailed error message"), Exception );
28 BOOST_CHECK_THROW( DAI_THROWE(NOT_IMPLEMENTED,"Detailed error messgae"), std::runtime_error );
29 BOOST_CHECK_THROW( DAI_ASSERT( 0 ), Exception );
30 BOOST_CHECK_THROW( DAI_ASSERT( 0 == 1 ), std::runtime_error );
31
32 try {
33 DAI_THROW(NOT_IMPLEMENTED);
34 } catch( Exception& e ) {
35 BOOST_CHECK_EQUAL( e.code(), Exception::NOT_IMPLEMENTED );
36 BOOST_CHECK_EQUAL( e.message(e.code()), std::string("Feature not implemented") );
37 }
38
39 try {
40 DAI_THROWE(NOT_IMPLEMENTED,"Detailed error message");
41 } catch( Exception& e ) {
42 BOOST_CHECK_EQUAL( e.code(), Exception::NOT_IMPLEMENTED );
43 BOOST_CHECK_EQUAL( e.message(e.code()), std::string("Feature not implemented") );
44 }
45
46 try {
47 DAI_THROW(NOT_IMPLEMENTED);
48 } catch( std::runtime_error& e ) {
49 BOOST_CHECK_EQUAL( e.what(), std::string("Feature not implemented [tests/unit/exceptions_test.cpp, line 47]") );
50 }
51
52 try {
53 DAI_THROWE(NOT_IMPLEMENTED,"Detailed error message");
54 } catch( std::runtime_error& e ) {
55 BOOST_CHECK_EQUAL( e.what(), std::string("Feature not implemented [tests/unit/exceptions_test.cpp, line 53]") );
56 }
57 }