-
Notifications
You must be signed in to change notification settings - Fork 3
/
doctest-example.test.cpp
47 lines (33 loc) · 978 Bytes
/
doctest-example.test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// https://github.com/matepek/catch2-with-gmock
// NOTE that next line includes gmock and doctest headers automatically.
#include "ThirdParty/DOCTestWithMainAndGMock.hpp"
#include "ThirdParty/MockScopeGuard.hpp"
using namespace std;
///
class Foo {
public:
virtual ~Foo() {}
virtual bool Bar() const = 0;
};
class MockFoo : public Foo {
public:
MOCK_METHOD(bool, Bar, (), (const, override));
};
///
TEST_CASE("example #1") {
::testing::StrictMock<MockFoo> mock1, mock2;
Foo& foo1 = mock1;
SUBCASE("success") {
auto mockGuard = MockScopeGuard(mock1, mock2);
EXPECT_CALL(mock1, Bar).WillOnce(::testing::Return(true));
REQUIRE(true == foo1.Bar());
}
SUBCASE("failure #1") {
auto mockGuard = MockScopeGuard(mock1, mock2);
EXPECT_CALL(mock1, Bar).WillOnce(::testing::Return(true));
}
SUBCASE("failure #2") {
auto mockGuard = MockScopeGuard(mock1, mock2);
EXPECT_CALL(mock2, Bar).WillOnce(::testing::Return(true));
}
}