forked from sinojelly/mockcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctor.h
More file actions
123 lines (100 loc) · 3.12 KB
/
Functor.h
File metadata and controls
123 lines (100 loc) · 3.12 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
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
/***
mockcpp is a C/C++ mock framework.
Copyright [2008] [Darwin Yuan <[email protected]>]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
***/
#ifndef __MOCKCPP_FUNCTOR_H
#define __MOCKCPP_FUNCTOR_H
#include <mockcpp/mockcpp.h>
#include <string>
#include <mockcpp/GlobalMockObject.h>
#include <mockcpp/ArgumentsMacroHelpers.h>
MOCKCPP_NS_START
/////////////////////////////////////////////
struct BaseFunctor
{
BaseFunctor(const std::string& fName, const char* cName)
: name(fName), nameOfCaller(cName) {}
std::string getName() const
{
return name;
}
std::string getNameOfCaller() const
{
return nameOfCaller;
}
private:
std::string name;
std::string nameOfCaller;
};
////////////////////////////////////////////
template <typename F>
struct Functor;
#define FUNCTOR_CONS() \
Functor(const std::string& name, const char* cName) \
: BaseFunctor(name, cName) \
{}
////////////////////////////////////////////
#define FUNCTOR_DEF(n) \
template <typename R DECL_TEMPLATE_ARGS(n)> \
struct Functor<R(DECL_ARGS(n))> : public BaseFunctor \
{ \
FUNCTOR_CONS() \
\
R operator()(DECL_PARAMS_LIST(n)) \
{ \
return GlobalMockObject::instance.invoke<R>(getName()) \
(getNameOfCaller() DECL_REST_PARAMS(n)); \
} \
}
FUNCTOR_DEF(0);
FUNCTOR_DEF(1);
FUNCTOR_DEF(2);
FUNCTOR_DEF(3);
FUNCTOR_DEF(4);
FUNCTOR_DEF(5);
FUNCTOR_DEF(6);
FUNCTOR_DEF(7);
FUNCTOR_DEF(8);
FUNCTOR_DEF(9);
FUNCTOR_DEF(10);
FUNCTOR_DEF(11);
FUNCTOR_DEF(12);
///////////////////////////////////////////////////////
#define VARDIC_FUNCTOR_DEF(n) \
template <typename R DECL_TEMPLATE_ARGS(n)> \
struct Functor<R(DECL_VARDIC_ARGS(n) ...)> : public BaseFunctor \
{ \
FUNCTOR_CONS() \
\
R operator()(const RefAny& p1 = RefAny(), const RefAny& p2 = RefAny(), \
const RefAny& p3 = RefAny(), const RefAny& p4 = RefAny(), \
const RefAny& p5 = RefAny(), const RefAny& p6 = RefAny(), \
const RefAny& p7 = RefAny(), const RefAny& p8 = RefAny(), \
const RefAny& p9 = RefAny(), const RefAny& p10 = RefAny(), \
const RefAny& p11 = RefAny(), const RefAny& p12 = RefAny()) \
{ \
return GlobalMockObject::instance.invoke<R>(getName()) \
(getNameOfCaller() DECL_REST_PARAMS(12)); \
} \
}
VARDIC_FUNCTOR_DEF(0);
VARDIC_FUNCTOR_DEF(1);
VARDIC_FUNCTOR_DEF(2);
VARDIC_FUNCTOR_DEF(3);
VARDIC_FUNCTOR_DEF(4);
VARDIC_FUNCTOR_DEF(5);
VARDIC_FUNCTOR_DEF(6);
VARDIC_FUNCTOR_DEF(7);
VARDIC_FUNCTOR_DEF(8);
/////////////////////////////////////////////////////////////////////////////
MOCKCPP_NS_END
#endif