Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_
00037 #define GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_
00038
00039 #include <algorithm>
00040
00041 #include "gmock/gmock-generated-actions.h"
00042
00043 namespace testing {
00044 namespace internal {
00045
00046
00047
00048
00049
00050
00051 template <typename FunctionImpl>
00052 class InvokeAction {
00053 public:
00054
00055
00056 explicit InvokeAction(FunctionImpl function_impl)
00057 : function_impl_(function_impl) {}
00058
00059 template <typename Result, typename ArgumentTuple>
00060 Result Perform(const ArgumentTuple& args) {
00061 return InvokeHelper<Result, ArgumentTuple>::Invoke(function_impl_, args);
00062 }
00063
00064 private:
00065 FunctionImpl function_impl_;
00066
00067 GTEST_DISALLOW_ASSIGN_(InvokeAction);
00068 };
00069
00070
00071 template <class Class, typename MethodPtr>
00072 class InvokeMethodAction {
00073 public:
00074 InvokeMethodAction(Class* obj_ptr, MethodPtr method_ptr)
00075 : obj_ptr_(obj_ptr), method_ptr_(method_ptr) {}
00076
00077 template <typename Result, typename ArgumentTuple>
00078 Result Perform(const ArgumentTuple& args) const {
00079 return InvokeHelper<Result, ArgumentTuple>::InvokeMethod(
00080 obj_ptr_, method_ptr_, args);
00081 }
00082
00083 private:
00084 Class* const obj_ptr_;
00085 const MethodPtr method_ptr_;
00086
00087 GTEST_DISALLOW_ASSIGN_(InvokeMethodAction);
00088 };
00089
00090 }
00091
00092
00093
00094
00095
00096 template <typename FunctionImpl>
00097 PolymorphicAction<internal::InvokeAction<FunctionImpl> > Invoke(
00098 FunctionImpl function_impl) {
00099 return MakePolymorphicAction(
00100 internal::InvokeAction<FunctionImpl>(function_impl));
00101 }
00102
00103
00104
00105 template <class Class, typename MethodPtr>
00106 PolymorphicAction<internal::InvokeMethodAction<Class, MethodPtr> > Invoke(
00107 Class* obj_ptr, MethodPtr method_ptr) {
00108 return MakePolymorphicAction(
00109 internal::InvokeMethodAction<Class, MethodPtr>(obj_ptr, method_ptr));
00110 }
00111
00112
00113
00114
00115
00116 template <typename InnerAction>
00117 inline internal::WithArgsAction<InnerAction>
00118 WithoutArgs(const InnerAction& action) {
00119 return internal::WithArgsAction<InnerAction>(action);
00120 }
00121
00122
00123
00124
00125
00126
00127 template <int k, typename InnerAction>
00128 inline internal::WithArgsAction<InnerAction, k>
00129 WithArg(const InnerAction& action) {
00130 return internal::WithArgsAction<InnerAction, k>(action);
00131 }
00132
00133
00134
00135
00136
00137
00138 #ifdef _MSC_VER
00139 # pragma warning(push)
00140 # pragma warning(disable:4100)
00141 #endif
00142
00143
00144 ACTION_TEMPLATE(ReturnArg,
00145 HAS_1_TEMPLATE_PARAMS(int, k),
00146 AND_0_VALUE_PARAMS()) {
00147 return std::tr1::get<k>(args);
00148 }
00149
00150
00151
00152 ACTION_TEMPLATE(SaveArg,
00153 HAS_1_TEMPLATE_PARAMS(int, k),
00154 AND_1_VALUE_PARAMS(pointer)) {
00155 *pointer = ::std::tr1::get<k>(args);
00156 }
00157
00158
00159
00160 ACTION_TEMPLATE(SaveArgPointee,
00161 HAS_1_TEMPLATE_PARAMS(int, k),
00162 AND_1_VALUE_PARAMS(pointer)) {
00163 *pointer = *::std::tr1::get<k>(args);
00164 }
00165
00166
00167
00168 ACTION_TEMPLATE(SetArgReferee,
00169 HAS_1_TEMPLATE_PARAMS(int, k),
00170 AND_1_VALUE_PARAMS(value)) {
00171 typedef typename ::std::tr1::tuple_element<k, args_type>::type argk_type;
00172
00173
00174
00175 GTEST_COMPILE_ASSERT_(internal::is_reference<argk_type>::value,
00176 SetArgReferee_must_be_used_with_a_reference_argument);
00177 ::std::tr1::get<k>(args) = value;
00178 }
00179
00180
00181
00182
00183
00184
00185 ACTION_TEMPLATE(SetArrayArgument,
00186 HAS_1_TEMPLATE_PARAMS(int, k),
00187 AND_2_VALUE_PARAMS(first, last)) {
00188
00189
00190 #ifdef _MSC_VER
00191 # pragma warning(push) // Saves the current warning state.
00192 # pragma warning(disable:4996) // Temporarily disables warning 4996.
00193 #endif
00194 ::std::copy(first, last, ::std::tr1::get<k>(args));
00195 #ifdef _MSC_VER
00196 # pragma warning(pop) // Restores the warning state.
00197 #endif
00198 }
00199
00200
00201
00202 ACTION_TEMPLATE(DeleteArg,
00203 HAS_1_TEMPLATE_PARAMS(int, k),
00204 AND_0_VALUE_PARAMS()) {
00205 delete ::std::tr1::get<k>(args);
00206 }
00207
00208
00209 ACTION_P(ReturnPointee, pointer) { return *pointer; }
00210
00211
00212
00213 #if GTEST_HAS_EXCEPTIONS
00214
00215
00216 # ifdef _MSC_VER
00217 # pragma warning(push) // Saves the current warning state.
00218 # pragma warning(disable:4702) // Temporarily disables warning 4702.
00219 # endif
00220 ACTION_P(Throw, exception) { throw exception; }
00221 # ifdef _MSC_VER
00222 # pragma warning(pop) // Restores the warning state.
00223 # endif
00224
00225 #endif // GTEST_HAS_EXCEPTIONS
00226
00227 #ifdef _MSC_VER
00228 # pragma warning(pop)
00229 #endif
00230
00231 }
00232
00233 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_