Ver código fonte

Tests added and some fixes.

main
offa 7 anos atrás
pai
commit
41f4a3b3da
1 arquivos alterados com 17 adições e 9 exclusões
  1. +17
    -9
      test/UniqueResourceTest.cpp

+ 17
- 9
test/UniqueResourceTest.cpp Ver arquivo

#include <catch.hpp> #include <catch.hpp>
#include <trompeloeil.hpp> #include <trompeloeil.hpp>


#include <type_traits>

using namespace trompeloeil; using namespace trompeloeil;


namespace namespace
MAKE_MOCK1(deleter, void(Handle)); MAKE_MOCK1(deleter, void(Handle));
}; };


CallMock m;

void deleter(Handle h)
{
m.deleter(h);
}



struct ThrowOnCopyMock struct ThrowOnCopyMock
{ {


}; };


CallMock m;

void deleter(Handle h)
{
m.deleter(h);
}


} }


TEST_CASE("construction with move", "[UniqueResource]") TEST_CASE("construction with move", "[UniqueResource]")
{ {
REQUIRE_CALL(m, deleter(3));
auto guard = sr::make_unique_resource(Handle{3}, deleter); auto guard = sr::make_unique_resource(Handle{3}, deleter);
static_cast<void>(guard); static_cast<void>(guard);
} }
// TODO: Missing constrion with copy successful


TEST_CASE("construction with copy calls deleter and rethrows on failed copy", "[UniqueResource]") TEST_CASE("construction with copy calls deleter and rethrows on failed copy", "[UniqueResource]")
{ {


TEST_CASE("move-construction with move", "[UniqueResource]") TEST_CASE("move-construction with move", "[UniqueResource]")
{ {
REQUIRE_CALL(m, deleter(3));
auto movedFrom = sr::make_unique_resource(Handle{3}, deleter); auto movedFrom = sr::make_unique_resource(Handle{3}, deleter);
auto guard = std::move(movedFrom); auto guard = std::move(movedFrom);
static_cast<void>(guard); static_cast<void>(guard);
TEST_CASE("move-construction with copy", "[UniqueResource]") TEST_CASE("move-construction with copy", "[UniqueResource]")
{ {
CallMock mock; CallMock mock;
REQUIRE_CALL(mock, deleter(3));
const NotNothrowMoveMock notNothrow{&mock}; const NotNothrowMoveMock notNothrow{&mock};
Handle h{3}; Handle h{3};
sr::unique_resource<Handle, decltype(notNothrow)> movedFrom{h, notNothrow}; sr::unique_resource<Handle, decltype(notNothrow)> movedFrom{h, notNothrow};
} }


// TODO: Implement move assignment // TODO: Implement move assignment

TEST_CASE("deleter called on destruction", "[UniqueResource]")
{
REQUIRE_CALL(m, deleter(3));
auto guard = sr::make_unique_resource(Handle{3}, deleter);
static_cast<void>(guard);
}

Carregando…
Cancelar
Salvar