1 #include "helpers.hpp" 2 #include "utils/ensure.hpp" 3 4 #include <gmock/gmock.h> 5 6 using namespace testing; 7 8 class TestEnsure : public Test 9 { 10 public: 11 utils::Ensure<std::function<void()>> sut; 12 13 size_t executed = 0u; 14 }; 15 TEST_F(TestEnsure,executesCallbackOnceWhenDestroyed)16TEST_F(TestEnsure, executesCallbackOnceWhenDestroyed) 17 { 18 sut = [this] { ++executed; }; 19 sut = nullptr; 20 21 EXPECT_THAT(executed, Eq(1u)); 22 } 23 TEST_F(TestEnsure,executesCallbackTwiceWhenNewCallbackAssigned)24TEST_F(TestEnsure, executesCallbackTwiceWhenNewCallbackAssigned) 25 { 26 sut = [this] { ++executed; }; 27 sut = [this] { executed += 10; }; 28 sut = nullptr; 29 30 EXPECT_THAT(executed, Eq(11u)); 31 } 32