From 925dbdbc537afd54e7140e8f83cf1f3ae6314577 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Mon, 29 Apr 2013 12:32:04 +0100 Subject: [PATCH] [block_t] verify any exception thrown by validator->check() gets passed up, and the lock is not consequently taken. --- unit-tests/block_t.cc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/unit-tests/block_t.cc b/unit-tests/block_t.cc index a1b6144..e659dc8 100644 --- a/unit-tests/block_t.cc +++ b/unit-tests/block_t.cc @@ -242,6 +242,13 @@ namespace { validator_mock::ptr vmock; validator_mock::ptr vmock2; }; + + class my_error : public runtime_error { + public: + my_error(string const &msg) + : runtime_error(msg) { + } + }; } //-------------------------------- @@ -401,4 +408,16 @@ TEST_F(ValidatorTests, validator_can_be_changed_by_superblock_zero) bm4096::write_ref wr = bm->superblock_zero(0, vmock2); } +//-------------------------------- + +TEST_F(ValidatorTests, validator_check_failure_gets_passed_up) +{ + validator_mock::ptr v(new validator_mock); + + EXPECT_CALL(*v, check(_, Eq(0ull))).Times(1).WillOnce(Throw(my_error("bang!"))); + + ASSERT_THROW(bm->read_lock(0, v), my_error); + ASSERT_FALSE(bm->is_locked(0)); +} + //----------------------------------------------------------------