-
Notifications
You must be signed in to change notification settings - Fork 0
/
mock_test.cpp
56 lines (48 loc) · 1.45 KB
/
mock_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
48
49
50
51
52
53
54
55
56
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include "mock_test.h"
using ::testing::AtLeast;
using ::testing::_;
using ::testing::Return;
using ::testing::StrEq;
class MockPrimaryTest: public ::testing::Test {
public:
StuBase *sPtr;
MockPrimary * mpPtr;
public:
void SetUp() override {
mpPtr = new MockPrimary(10, "Yang", "Math, Music");
sPtr = mpPtr;
}
void TearDown() override {
delete mpPtr;
sPtr = NULL;
mpPtr = NULL;
}
};
TEST_F(MockPrimaryTest, baseTestwithoutThrow) {
ON_CALL(*mpPtr, lessonList(StrEq("Wang"),_))
.WillByDefault(Return(false));
EXPECT_CALL(*mpPtr, lessonList(_, _)).Times(2);
ASSERT_NO_THROW(sPtr->displayLessonsList(sPtr));
bool value = true;
std::string name = "Wang";
std::string ret;
ASSERT_NO_THROW(value = mpPtr->lessonList(name, ret));
EXPECT_FALSE(value);
}
TEST_F(MockPrimaryTest, withoutThrow) {
ON_CALL(*mpPtr, lessonList(StrEq("Yang"),_))
.WillByDefault(
[&](std::string& name, std::string& lessons){
std::cout << "== Return Yang's lessons ==\n";
return true;
}
);
EXPECT_CALL(*mpPtr, lessonList(_, _)).Times(1);
bool value = false;
std::string name = "Yang";
std::string ret;
ASSERT_NO_THROW(value = mpPtr->lessonList(name, ret));
EXPECT_TRUE(value);
}