blob: d252bc320df506fb5900b5beb8ebdd2d1b1a09cb [file] [log] [blame]
#include "helpers.hpp"
#include "utils/ensure.hpp"
#include <gmock/gmock.h>
using namespace testing;
class TestEnsure : public Test
{
public:
utils::Ensure<std::function<void()>> makeEnsure()
{
return [this] { ++executed; };
}
utils::Ensure<std::function<void()>> sut;
size_t executed = 0u;
};
TEST_F(TestEnsure, executesCallbackOnceWhenDestroyed)
{
sut = makeEnsure();
sut = nullptr;
EXPECT_THAT(executed, Eq(1u));
}
TEST_F(TestEnsure, executesCallbackOnceWhenMoved)
{
sut = makeEnsure();
auto copy = std::move(sut);
copy = nullptr;
EXPECT_THAT(executed, Eq(1u));
}
TEST_F(TestEnsure, executesCallbackTwiceWhenReplaced)
{
sut = makeEnsure();
sut = makeEnsure();
sut = nullptr;
EXPECT_THAT(executed, Eq(2u));
}
TEST_F(TestEnsure, executesCallbackTwiceWhenNewCallbackAssigned)
{
sut = makeEnsure();
sut = [this] { executed += 10; };
sut = nullptr;
EXPECT_THAT(executed, Eq(11u));
}