Skip to content

Commit

Permalink
fixed #929
Browse files Browse the repository at this point in the history
Observer::unregisterWith(...) and QL_ENABLE_THREAD_SAFE_OBSERVER_PATTERN
  • Loading branch information
klausspanderen committed Nov 28, 2020
1 parent 60afa35 commit 831faf3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
3 changes: 1 addition & 2 deletions ql/patterns/observable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,8 +541,7 @@ namespace QuantLib {
Size Observer::unregisterWith(const ext::shared_ptr<Observable>& h) {
boost::lock_guard<boost::recursive_mutex> lock(mutex_);

if (h) {
QL_REQUIRE(proxy_, "unregister called without a proxy");
if (h && proxy_) {
h->unregisterObserver(proxy_);
}

Expand Down
19 changes: 18 additions & 1 deletion test-suite/observable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,23 @@ void ObservableTest::testDeepUpdate() {
BOOST_CHECK_CLOSE(v4, 0.21, 1E-10);
}

namespace {
class DummyObserver : public Observer {
public:
DummyObserver() {}
void update() {}
};
}

void ObservableTest::testEmptyObserverList() {
BOOST_TEST_MESSAGE("Testing unregisterWith call on empty observer...");

SavedSettings backup;

const ext::shared_ptr<DummyObserver> dummyObserver=ext::make_shared<DummyObserver>();
dummyObserver->unregisterWith(ext::make_shared<SimpleQuote>(10.0));
}

test_suite* ObservableTest::suite() {
test_suite* suite = BOOST_TEST_SUITE("Observer tests");

Expand All @@ -319,7 +336,7 @@ test_suite* ObservableTest::suite() {
#endif

suite->add(QUANTLIB_TEST_CASE(&ObservableTest::testDeepUpdate));

suite->add(QUANTLIB_TEST_CASE(&ObservableTest::testEmptyObserverList));
return suite;
}

1 change: 1 addition & 0 deletions test-suite/observable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class ObservableTest {
static void testAsyncGarbagCollector();
static void testMultiThreadingGlobalSettings();
static void testDeepUpdate();
static void testEmptyObserverList();

static boost::unit_test_framework::test_suite* suite();
};
Expand Down

0 comments on commit 831faf3

Please sign in to comment.