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

@@ -111,7 +111,7 @@ namespace sr
}
else
{
m_resource = std::as_const(r);
m_resource.reset(std::as_const(r));
}

m_execute_on_destruction = true;

+ 23
- 1
test/CallMocks.h View File

@@ -138,9 +138,31 @@ namespace mock
};


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
{
CopyMock() {}
CopyMock() { }
CopyMock(const CopyMock&) { }
};


+ 3
- 2
test/UniqueResourceTest.cpp View File

@@ -132,8 +132,9 @@ TEST_CASE("reset sets new lvalue and calls deleter on previous", "[UniqueResourc
{
REQUIRE_CALL(m, deleter(3));
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);
}


Loading…
Cancel
Save