Browse Source

Test and assignment corrected (#99).

main
offa 7 years ago
parent
commit
a614c62087
3 changed files with 27 additions and 4 deletions
  1. +1
    -1
      include/unique_resource.h
  2. +23
    -1
      test/CallMocks.h
  3. +3
    -2
      test/UniqueResourceTest.cpp

+ 1
- 1
include/unique_resource.h View File

} }
else else
{ {
m_resource = std::as_const(r);
m_resource.reset(std::as_const(r));
} }


m_execute_on_destruction = true; m_execute_on_destruction = true;

+ 23
- 1
test/CallMocks.h View File

}; };




struct NotNothrowAssignable
{
explicit NotNothrowAssignable(int value) : m_value(value) { }
NotNothrowAssignable(const NotNothrowAssignable&) = default;

NotNothrowAssignable& operator=(const NotNothrowAssignable& other)
{
if( this != &other )
{
assignNotNoexcept(other.m_value);
}
return *this;
}

void assignNotNoexcept(int value) noexcept(false)
{
m_value = value;
}

int m_value;
};

struct CopyMock struct CopyMock
{ {
CopyMock() {}
CopyMock() { }
CopyMock(const CopyMock&) { } CopyMock(const CopyMock&) { }
}; };



+ 3
- 2
test/UniqueResourceTest.cpp View File

{ {
REQUIRE_CALL(m, deleter(3)); REQUIRE_CALL(m, deleter(3));
REQUIRE_CALL(m, deleter(7)); REQUIRE_CALL(m, deleter(7));
auto guard = sr::unique_resource{Handle{3}, deleter};
const Handle h{7};
auto d = [](const auto& v) { deleter(v.m_value); };
auto guard = sr::unique_resource{NotNothrowAssignable{3}, d};
const NotNothrowAssignable h{7};
guard.reset(h); guard.reset(h);
} }



Loading…
Cancel
Save