forked from Crascit/DownloadProject
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.cpp
54 lines (43 loc) · 1 KB
/
example.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
48
49
50
51
52
53
54
#include "gtest/gtest.h"
#include "gmock/gmock.h"
// Simple test, does not use gmock
TEST(Dummy, foobar)
{
EXPECT_EQ(1, 1);
}
// Real class we want to mock
class TeaBreak
{
public:
virtual ~TeaBreak() {}
// Return minutes taken to make the drinks
int morningTea()
{
return makeCoffee(true, 1) +
makeCoffee(false, 0.5) +
makeHerbalTea();
}
private:
virtual int makeCoffee(bool milk, double sugars) = 0;
virtual int makeHerbalTea() = 0;
};
// Mock class
class MockTeaBreak : public TeaBreak
{
public:
MOCK_METHOD2(makeCoffee, int(bool milk, double sugars));
MOCK_METHOD0(makeHerbalTea, int());
};
using ::testing::Return;
using ::testing::_;
// Mocked test
TEST(TeaBreakTest, MorningTea)
{
MockTeaBreak teaBreak;
EXPECT_CALL(teaBreak, makeCoffee(_,_))
.WillOnce(Return(2))
.WillOnce(Return(1));
EXPECT_CALL(teaBreak, makeHerbalTea())
.WillOnce(Return(3));
EXPECT_LE(teaBreak.morningTea(), 6);
}