Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame] | 1 | #include "helpers.hpp" |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 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: |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 11 | utils::Ensure<std::function<void()>> sut; |
Szymon Dompke | bcf045a | 2022-09-16 15:23:30 +0200 | [diff] [blame] | 12 | |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 13 | size_t executed = 0u; |
| 14 | }; |
| 15 | |
| 16 | TEST_F(TestEnsure, executesCallbackOnceWhenDestroyed) |
| 17 | { |
Szymon Dompke | bcf045a | 2022-09-16 15:23:30 +0200 | [diff] [blame] | 18 | sut = [this] { ++executed; }; |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 19 | sut = nullptr; |
| 20 | |
| 21 | EXPECT_THAT(executed, Eq(1u)); |
| 22 | } |
| 23 | |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 24 | TEST_F(TestEnsure, executesCallbackTwiceWhenNewCallbackAssigned) |
| 25 | { |
Szymon Dompke | bcf045a | 2022-09-16 15:23:30 +0200 | [diff] [blame] | 26 | sut = [this] { ++executed; }; |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 27 | sut = [this] { executed += 10; }; |
| 28 | sut = nullptr; |
| 29 | |
| 30 | EXPECT_THAT(executed, Eq(11u)); |
| 31 | } |