Sfoglia il codice sorgente

Test and assignment corrected (#99).

main
offa 7 anni fa
parent
commit
a614c62087
3 ha cambiato i file con 27 aggiunte e 4 eliminazioni
  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 Vedi 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 Vedi 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 Vedi 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…
Annulla
Salva