blob: 0e300adb3174e936486212dc3d0d108a65f723f0 [file] [log] [blame]
Szymon Dompke1cdd7e42022-06-08 14:43:13 +02001#include "helpers.hpp"
Krzysztof Grobelnyf7ea2992022-01-27 11:04:58 +01002#include "utils/ensure.hpp"
3
4#include <gmock/gmock.h>
5
6using namespace testing;
7
8class TestEnsure : public Test
9{
10 public:
Krzysztof Grobelnyf7ea2992022-01-27 11:04:58 +010011 utils::Ensure<std::function<void()>> sut;
Szymon Dompkebcf045a2022-09-16 15:23:30 +020012
Krzysztof Grobelnyf7ea2992022-01-27 11:04:58 +010013 size_t executed = 0u;
14};
15
16TEST_F(TestEnsure, executesCallbackOnceWhenDestroyed)
17{
Szymon Dompkebcf045a2022-09-16 15:23:30 +020018 sut = [this] { ++executed; };
Krzysztof Grobelnyf7ea2992022-01-27 11:04:58 +010019 sut = nullptr;
20
21 EXPECT_THAT(executed, Eq(1u));
22}
23
Krzysztof Grobelnyf7ea2992022-01-27 11:04:58 +010024TEST_F(TestEnsure, executesCallbackTwiceWhenNewCallbackAssigned)
25{
Szymon Dompkebcf045a2022-09-16 15:23:30 +020026 sut = [this] { ++executed; };
Krzysztof Grobelnyf7ea2992022-01-27 11:04:58 +010027 sut = [this] { executed += 10; };
28 sut = nullptr;
29
30 EXPECT_THAT(executed, Eq(11u));
31}