forked from gzc9047/CppFreeMock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
130 lines (111 loc) · 4.04 KB
/
main.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#ifndef CPPFREEMOCK_MAIN_H
#define CPPFREEMOCK_MAIN_H
#include "cpp_free_mock.h"
#include <iostream>
#include <string>
#include <cstring>
char * func(int) {
std::string str = "Non mocked";
char* cstr = new char[str.length() + 1]; // +1 for the null terminator
std::strcpy(cstr, str.c_str());
return cstr;
}
struct TestMockStruct {
char * func0Parameter(int) {
std::string str = "Non mocked";
char* cstr = new char[str.length() + 1]; // +1 for the null terminator
std::strcpy(cstr, str.c_str());
return cstr;
}
char * func1Parameter(int) const {
std::string str = "Non mocked";
char* cstr = new char[str.length() + 1]; // +1 for the null terminator
std::strcpy(cstr, str.c_str());
return cstr;
}
static char * testReferenceStubP1P2(int) {
std::string str = "Non mocked";
char* cstr = new char[str.length() + 1]; // +1 for the null terminator
std::strcpy(cstr, str.c_str());
return cstr;
}
};
namespace TestNamespace {
char * func0Parameter(int) {
std::string str = "Non mocked";
char* cstr = new char[str.length() + 1]; // +1 for the null terminator
std::strcpy(cstr, str.c_str());
return cstr;
}
}
struct ClassA {
char * func0(int) {
std::string str = "Non mocked 0";
char* cstr = new char[str.length() + 1]; // +1 for the null terminator
std::strcpy(cstr, str.c_str());
return cstr;
}
int a;
};
struct ClassB : ClassA {
char * func0(int) {
std::string str = "Non mocked 1";
char* cstr = new char[str.length() + 1]; // +1 for the null terminator
std::strcpy(cstr, str.c_str());
return cstr;
}
int b;
};
struct ClassC : ClassB {
char * func0(int) {
std::string str = "Non mocked 2";
char* cstr = new char[str.length() + 1]; // +1 for the null terminator
std::strcpy(cstr, str.c_str());
return cstr;
}
int c;
};
struct ClassD {
char * func0(int) {
std::string str = "Non mocked 3";
char* cstr = new char[str.length() + 1]; // +1 for the null terminator
std::strcpy(cstr, str.c_str());
return cstr;
}
int d;
};
struct ClassE : ClassC, ClassD {
char * func0(int) {
std::string str = "Non mocked 4";
char* cstr = new char[str.length() + 1]; // +1 for the null terminator
std::strcpy(cstr, str.c_str());
return cstr;
}
int e;
};
int main() {
MOCKER(func);
std::cout << "global method - func return: " << func(1) << std::endl;
MOCKER(&TestMockStruct::func0Parameter);
std::cout << "class member method - TestMockStruct::func0Parameter return: " << TestMockStruct().func0Parameter(1) << std::endl;
MOCKER(&TestMockStruct::func1Parameter);
std::cout << "class method method const - TestMockStruct::func1Parameter return: " << TestMockStruct().func1Parameter(1) << std::endl;
MOCKER(TestNamespace::func0Parameter);
std::cout << "global method in namespace - TestNamespace::func0Parameter return: " << TestNamespace::func0Parameter(1) << std::endl;
MOCKER(TestMockStruct::testReferenceStubP1P2);
std::cout << "class static method - TestMockStruct::testReferenceStubP1P2 return: " << TestMockStruct::testReferenceStubP1P2(1) << std::endl;
MOCKER(strerror);
std::cout << "lib method - strerror return: " << strerror(1) << std::endl;
MOCKER(&ClassA::func0);
std::cout << "class method - ClassA::func0 return: " << ClassA().func0(1) << std::endl;
MOCKER(&ClassB::func0);
std::cout << "class method - ClassB::func0 return: " << ClassB().func0(1) << std::endl;
MOCKER(&ClassC::func0);
std::cout << "class method - ClassC::func0 return: " << ClassC().func0(1) << std::endl;
MOCKER(&ClassD::func0);
std::cout << "class method - ClassD::func0 return: " << ClassD().func0(1) << std::endl;
MOCKER(&ClassE::func0);
std::cout << "class method - ClassE::func0 return: " << ClassE().func0(1) << std::endl;
return 0;
}
#endif //CPPFREEMOCK_MAIN_H