-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_template_function_with_gmock.cpp
More file actions
55 lines (45 loc) · 1.6 KB
/
Copy pathtest_template_function_with_gmock.cpp
File metadata and controls
55 lines (45 loc) · 1.6 KB
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
#include "mock_non_virtual.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <iostream>
using namespace std;
template < typename T >
string getString() {
return "Non mocked.";
}
template < typename T >
struct Simple {
T t;
string getString() {
return "Non mocked.";
}
};
DECLARE_FUNCTION_MOCK0(template_getString, string);
DECLARE_MEMBER_FUNCTION_MOCK0(template_member_getString, string);
class TryGmockTemplateTest : public ::testing::Test {
protected:
virtual void SetUp() {
INIT_FUNCTION(getString<int>, template_getString);
INIT_MEMBER_FUNCTION(&Simple<int>::getString, template_member_getString);
}
virtual void TearDown() {
FINALIZE_FUNCTION(getString<int>, template_getString);
FINALIZE_FUNCTION(&Simple<int>::getString, template_member_getString);
}
};
TEST_F(TryGmockTemplateTest, TemplateMember) {
EXPECT_CALL(*USE_FUNCTION_OBJECT(template_member_getString), template_member_getString())
.Times(::testing::AtLeast(0))
.WillOnce(::testing::Return("B"));
EXPECT_STREQ("B", Simple<int>().getString().c_str());
RESTORE_FUNCTION(&Simple<int>::getString, template_member_getString);
EXPECT_STRNE("B", Simple<int>().getString().c_str());
}
TEST_F(TryGmockTemplateTest, TemplateGlobal) {
EXPECT_CALL(*USE_FUNCTION_OBJECT(template_getString), template_getString())
.Times(::testing::AtLeast(0))
.WillOnce(::testing::Return("B"));
EXPECT_STREQ("B", getString<int>().c_str());
RESTORE_FUNCTION(getString<int>, template_getString);
EXPECT_STRNE("B", getString<int>().c_str());
}