Some improvements to jtree and regiongraph and started work on regiongraph unit tests
[libdai.git] / tests / unit / exceptions.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 #define BOOST_TEST_DYN_LINK
12
13
14 #include <dai/exceptions.h>
15 #include <strstream>
16
17
18 using namespace dai;
19
20
21 #define BOOST_TEST_MODULE ExceptionsTest
22
23
24 #include <boost/test/unit_test.hpp>
25
26
27 BOOST_AUTO_TEST_CASE( ExceptionsTest ) {
28 BOOST_CHECK_THROW( DAI_THROW(NOT_IMPLEMENTED), Exception );
29 BOOST_CHECK_THROW( DAI_THROW(NOT_IMPLEMENTED), std::runtime_error );
30 BOOST_CHECK_THROW( DAI_THROWE(NOT_IMPLEMENTED,"Detailed error message"), Exception );
31 BOOST_CHECK_THROW( DAI_THROWE(NOT_IMPLEMENTED,"Detailed error messgae"), std::runtime_error );
32 BOOST_CHECK_THROW( DAI_ASSERT( 0 ), Exception );
33 BOOST_CHECK_THROW( DAI_ASSERT( 0 == 1 ), std::runtime_error );
34
35 try {
36 DAI_THROW(NOT_IMPLEMENTED);
37 } catch( Exception& e ) {
38 BOOST_CHECK_EQUAL( e.code(), Exception::NOT_IMPLEMENTED );
39 BOOST_CHECK_EQUAL( e.message(e.code()), std::string("Feature not implemented") );
40 }
41
42 try {
43 DAI_THROWE(NOT_IMPLEMENTED,"Detailed error message");
44 } catch( Exception& e ) {
45 BOOST_CHECK_EQUAL( e.code(), Exception::NOT_IMPLEMENTED );
46 BOOST_CHECK_EQUAL( e.message(e.code()), std::string("Feature not implemented") );
47 }
48
49 try {
50 DAI_THROW(NOT_IMPLEMENTED);
51 } catch( std::runtime_error& e ) {
52 BOOST_CHECK_EQUAL( e.what(), std::string("Feature not implemented [tests/unit/exceptions.cpp, line 50]") );
53 }
54
55 try {
56 DAI_THROWE(NOT_IMPLEMENTED,"Detailed error message");
57 } catch( std::runtime_error& e ) {
58 BOOST_CHECK_EQUAL( e.what(), std::string("Feature not implemented [tests/unit/exceptions.cpp, line 56]") );
59 }
60 }