| { | { | ||||
| public: | public: | ||||
| unique_resource() | |||||
| : resource(R{}, scope_exit{[] { }}), | |||||
| deleter(D{}, scope_exit{[] { }}), | |||||
| execute_on_reset(false) | |||||
| { | |||||
| } | |||||
| template<class RR, class DD, | template<class RR, class DD, | ||||
| std::enable_if_t<(std::is_constructible_v<R ,RR> && std::is_constructible_v<D, DD> | std::enable_if_t<(std::is_constructible_v<R ,RR> && std::is_constructible_v<D, DD> | ||||
| && (std::is_nothrow_constructible_v<R, RR> || std::is_constructible_v<R, RR&>) | && (std::is_nothrow_constructible_v<R, RR> || std::is_constructible_v<R, RR&>) |
| }; | }; | ||||
| struct MoveableMock | |||||
| { | |||||
| static constexpr bool trompeloeil_movable_mock = true; | |||||
| MAKE_CONST_MOCK1(deleter, void(Handle)); | |||||
| void operator()(Handle h) const | |||||
| { | |||||
| this->deleter(h); | |||||
| } | |||||
| }; | |||||
| struct ThrowOnCopyMock | struct ThrowOnCopyMock | ||||
| { | { | ||||
| ThrowOnCopyMock() | ThrowOnCopyMock() |
| } | } | ||||
| } | } | ||||
| TEST_CASE("default construction", "[UniqueResource]") | |||||
| { | |||||
| sr::unique_resource<int, MoveableMock> guard{}; | |||||
| } | |||||
| TEST_CASE("construction with move", "[UniqueResource]") | TEST_CASE("construction with move", "[UniqueResource]") | ||||
| { | { | ||||
| REQUIRE_CALL(m, deleter(3)); | REQUIRE_CALL(m, deleter(3)); |