tests: Add test for exception propagation from make_lw_shared()

This commit is contained in:
Tomasz Grabiec
2015-07-17 14:48:51 +02:00
committed by Avi Kivity
parent 0bfcf27b15
commit db331efaa1

View File

@@ -26,6 +26,8 @@
#include <boost/test/included/unit_test.hpp>
#include "core/shared_ptr.hh"
struct expected_exception : public std::exception {};
struct A {
static bool destroyed;
A() {
@@ -93,3 +95,23 @@ BOOST_AUTO_TEST_CASE(test_shared_from_this_called_on_const_object) {
auto ptr = make_lw_shared<F>();
ptr->const_method();
}
BOOST_AUTO_TEST_CASE(test_exception_thrown_from_constructor_is_propagated) {
struct X {
X() {
throw expected_exception();
}
};
try {
auto ptr = make_lw_shared<X>();
BOOST_FAIL("Constructor should have thrown");
} catch (const expected_exception& e) {
BOOST_MESSAGE("Expected exception caught");
}
try {
auto ptr = ::make_shared<X>();
BOOST_FAIL("Constructor should have thrown");
} catch (const expected_exception& e) {
BOOST_MESSAGE("Expected exception caught");
}
}