Browse Source

Test updated to use ctor directly.

main
offa 7 years ago
parent
commit
71a7a4d83e
1 changed files with 10 additions and 10 deletions
  1. +10
    -10
      test/ScopeFailTest.cpp

+ 10
- 10
test/ScopeFailTest.cpp View File

TEST_CASE("exit function called on destruction", "[ScopeFail]") TEST_CASE("exit function called on destruction", "[ScopeFail]")
{ {
REQUIRE_CALL(m, deleter()).TIMES(0); REQUIRE_CALL(m, deleter()).TIMES(0);
auto guard = sr::make_scope_fail(deleter);
auto guard = sr::scope_fail{deleter};
static_cast<void>(guard); static_cast<void>(guard);
} }


{ {
CallMock cm; CallMock cm;
REQUIRE_CALL(cm, deleter()).TIMES(0); REQUIRE_CALL(cm, deleter()).TIMES(0);
auto guard = sr::make_scope_fail([&cm] { cm.deleter(); });
auto guard = sr::scope_fail{[&cm] { cm.deleter(); }};
static_cast<void>(guard); static_cast<void>(guard);
} }


const ThrowOnCopyMock noMove; const ThrowOnCopyMock noMove;
REQUIRE_CALL(noMove, deleter()); REQUIRE_CALL(noMove, deleter());


sr::scope_fail<decltype(noMove)> guard{noMove};
sr::scope_fail guard{noMove};
}()); }());
} }


TEST_CASE("exit function is not called if released", "[ScopeFail]") TEST_CASE("exit function is not called if released", "[ScopeFail]")
{ {
REQUIRE_CALL(m, deleter()).TIMES(0); REQUIRE_CALL(m, deleter()).TIMES(0);
auto guard = sr::make_scope_fail(deleter);
auto guard = sr::scope_fail{deleter};
guard.release(); guard.release();
} }


TEST_CASE("move releases moved-from object", "[ScopeFail]") TEST_CASE("move releases moved-from object", "[ScopeFail]")
{ {
REQUIRE_CALL(m, deleter()).TIMES(0); REQUIRE_CALL(m, deleter()).TIMES(0);
auto movedFrom = sr::make_scope_fail(deleter);
auto movedFrom = sr::scope_fail{deleter};
auto guard = std::move(movedFrom); auto guard = std::move(movedFrom);
static_cast<void>(guard); static_cast<void>(guard);
} }
CallMock mock; CallMock mock;
const NotNothrowMoveMock notNothrow{&mock}; const NotNothrowMoveMock notNothrow{&mock};
REQUIRE_CALL(mock, deleter()).TIMES(0); REQUIRE_CALL(mock, deleter()).TIMES(0);
sr::scope_fail<decltype(notNothrow)> movedFrom{notNothrow};
sr::scope_fail movedFrom{notNothrow};
auto guard = std::move(movedFrom); auto guard = std::move(movedFrom);
} }


TEST_CASE("move transfers state", "[ScopeFail]") TEST_CASE("move transfers state", "[ScopeFail]")
{ {
REQUIRE_CALL(m, deleter()).TIMES(0); REQUIRE_CALL(m, deleter()).TIMES(0);
auto movedFrom = sr::make_scope_fail(deleter);
auto movedFrom = sr::scope_fail{deleter};
auto guard = std::move(movedFrom); auto guard = std::move(movedFrom);
static_cast<void>(guard); static_cast<void>(guard);
} }
TEST_CASE("move transfers state if released", "[ScopeFail]") TEST_CASE("move transfers state if released", "[ScopeFail]")
{ {
REQUIRE_CALL(m, deleter()).TIMES(0); REQUIRE_CALL(m, deleter()).TIMES(0);
auto movedFrom = sr::make_scope_fail(deleter);
auto movedFrom = sr::scope_fail{deleter};
movedFrom.release(); movedFrom.release();
auto guard = std::move(movedFrom); auto guard = std::move(movedFrom);
static_cast<void>(guard); static_cast<void>(guard);
try try
{ {
REQUIRE_CALL(m, deleter()); REQUIRE_CALL(m, deleter());
auto guard = sr::make_scope_fail(deleter);
auto guard = sr::scope_fail{deleter};
static_cast<void>(guard); static_cast<void>(guard);
throw 3; throw 3;
} }
} }
catch( ... ) catch( ... )
{ {
auto guard = sr::make_scope_fail(deleter);
auto guard = sr::scope_fail{deleter};
static_cast<void>(guard); static_cast<void>(guard);
} }
} }

Loading…
Cancel
Save