Pārlūkot izejas kodu

Default ctor for unique_resource implemented (#151).

main
offa pirms 5 gadiem
vecāks
revīzija
8e1bf537a4
3 mainītis faili ar 25 papildinājumiem un 0 dzēšanām
  1. +7
    -0
      include/unique_resource.h
  2. +13
    -0
      test/CallMocks.h
  3. +5
    -0
      test/UniqueResourceTest.cpp

+ 7
- 0
include/unique_resource.h Parādīt failu

@@ -46,6 +46,13 @@ namespace sr
{
public:

unique_resource()
: resource(R{}, scope_exit{[] { }}),
deleter(D{}, scope_exit{[] { }}),
execute_on_reset(false)
{
}

template<class RR, class 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&>)

+ 13
- 0
test/CallMocks.h Parādīt failu

@@ -37,6 +37,19 @@ namespace mock
};


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
{
ThrowOnCopyMock()

+ 5
- 0
test/UniqueResourceTest.cpp Parādīt failu

@@ -38,6 +38,11 @@ namespace
}
}

TEST_CASE("default construction", "[UniqueResource]")
{
sr::unique_resource<int, MoveableMock> guard{};
}

TEST_CASE("construction with move", "[UniqueResource]")
{
REQUIRE_CALL(m, deleter(3));

Notiek ielāde…
Atcelt
Saglabāt