New git HEAD version
[libdai.git] / tests / unit / exceptions_test.cpp
1 /* This file is part of libDAI - http://www.libdai.org/
2 *
3 * Copyright (c) 2006-2011, The libDAI authors. All rights reserved.
4 *
5 * Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
6 */
7
8
9 #include <dai/exceptions.h>
10 #include <strstream>
11
12
13 using namespace dai;
14
15
16 #define BOOST_TEST_MODULE ExceptionsTest
17
18
19 #include <boost/test/unit_test.hpp>
20
21
22 BOOST_AUTO_TEST_CASE( ExceptionsTest ) {
23 BOOST_CHECK_THROW( DAI_THROW(NOT_IMPLEMENTED), Exception );
24 BOOST_CHECK_THROW( DAI_THROW(NOT_IMPLEMENTED), std::runtime_error );
25 BOOST_CHECK_THROW( DAI_THROWE(NOT_IMPLEMENTED,"Detailed error message"), Exception );
26 BOOST_CHECK_THROW( DAI_THROWE(NOT_IMPLEMENTED,"Detailed error messgae"), std::runtime_error );
27 BOOST_CHECK_THROW( DAI_ASSERT( 0 ), Exception );
28 BOOST_CHECK_THROW( DAI_ASSERT( 0 == 1 ), std::runtime_error );
29
30 try {
31 DAI_THROW(NOT_IMPLEMENTED);
32 } catch( Exception& e ) {
33 BOOST_CHECK_EQUAL( e.getCode(), Exception::NOT_IMPLEMENTED );
34 BOOST_CHECK_EQUAL( e.getMsg(), std::string("Feature not implemented") );
35 BOOST_CHECK_EQUAL( e.getDetailedMsg(), std::string("") );
36 BOOST_CHECK_EQUAL( e.getFilename(), std::string("tests/unit/exceptions_test.cpp") );
37 BOOST_CHECK_EQUAL( e.getFunction(), std::string("void ExceptionsTest::test_method()") );
38 BOOST_CHECK_EQUAL( e.getLine(), std::string("31") );
39 }
40
41 try {
42 DAI_THROWE(NOT_IMPLEMENTED,"Detailed error message");
43 } catch( Exception& e ) {
44 BOOST_CHECK_EQUAL( e.getCode(), Exception::NOT_IMPLEMENTED );
45 BOOST_CHECK_EQUAL( e.getMsg(), std::string("Feature not implemented") );
46 BOOST_CHECK_EQUAL( e.getDetailedMsg(), std::string("Detailed error message") );
47 BOOST_CHECK_EQUAL( e.getFilename(), std::string("tests/unit/exceptions_test.cpp") );
48 BOOST_CHECK_EQUAL( e.getFunction(), std::string("void ExceptionsTest::test_method()") );
49 BOOST_CHECK_EQUAL( e.getLine(), std::string("42") );
50 }
51
52 try {
53 DAI_THROW(NOT_IMPLEMENTED);
54 } catch( std::runtime_error& e ) {
55 BOOST_CHECK_EQUAL( e.what(), std::string("Feature not implemented [File tests/unit/exceptions_test.cpp, line 53, function: void ExceptionsTest::test_method()]") );
56 }
57
58 try {
59 DAI_THROWE(NOT_IMPLEMENTED,"Detailed error message");
60 } catch( std::runtime_error& e ) {
61 BOOST_CHECK_EQUAL( e.what(), std::string("Feature not implemented: Detailed error message [File tests/unit/exceptions_test.cpp, line 59, function: void ExceptionsTest::test_method()]") );
62 }
63 }