29 #define CATCH_CONFIG_MAIN
30 #include <catch2/catch_amalgamated.hpp>
40 int func2a_member(
int i) {
44 int func2b_member(
int i) {
48 static int Func3a_static(
int i) {
52 static int Func3b_static(
int i) {
62 IntOffset(
int v) : value(v) {}
64 IntOffset(
const IntOffset &o)
67 INFO(
"IntOffset::copy_ctor");
69 IntOffset(IntOffset &&o)
70 : value(std::move(o.value))
72 INFO(
"IntOffset::move_ctor");
74 IntOffset& operator=(
const IntOffset &o) {
75 INFO(
"IntOffset::copy_assign");
82 IntOffset& operator=(IntOffset &&o) {
83 INFO(
"IntOffset::move_assign");
84 value = std::move(o.value);
93 return value == rhs.value;
97 {
return !( *
this == rhs ); }
104 int f1r = f1.
invoke(value);
105 int f2r = f2.
invoke(value);
108 REQUIRE(f1r == expRes);
109 REQUIRE(f2r == expRes);
127 INFO(
"FuncPtr2_member: bindMemberFunc<int, TestFunctionDef01, int>: START");
129 MyClassFunction f2a_1 = bindMemberFunc<int, TestFunctionDef01, int>(
this, &TestFunctionDef01::func2a_member);
131 test_FunctionPointer00(
"FuncPtr2a_member_11",
true, 1, 101, f2a_1, f2a_1);
132 test_FunctionPointer00(
"FuncPtr2a_member_12",
true, 1, 101, f2a_1, f2a_2);
136 test_FunctionPointer00(
"FuncPtr2b_member_11",
true, 1, 1001, f2b_1, f2b_1);
137 test_FunctionPointer00(
"FuncPtr2b_member_12",
true, 1, 1001, f2b_1, f2b_2);
139 test_FunctionPointer00(
"FuncPtr2ab_member_11",
false, 1, 0, f2a_1, f2b_1);
140 test_FunctionPointer00(
"FuncPtr2ab_member_22",
false, 1, 0, f2a_2, f2b_2);
141 INFO(
"FuncPtr2_member: bindMemberFunc<int, TestFunctionDef01, int>: END");
145 INFO(
"FuncPtr3_plain: bindPlainFunc<int, int>: START");
147 MyClassFunction f3a_1 = bindPlainFunc<int, int>(&TestFunctionDef01::Func3a_static);
149 test_FunctionPointer00(
"FuncPtr3a_plain_11",
true, 1, 101, f3a_1, f3a_1);
150 test_FunctionPointer00(
"FuncPtr3a_plain_12",
true, 1, 101, f3a_1, f3a_2);
154 test_FunctionPointer00(
"FuncPtr3b_plain_11",
true, 1, 1001, f3b_1, f3b_1);
155 test_FunctionPointer00(
"FuncPtr3b_plain_12",
true, 1, 1001, f3b_1, f3b_2);
157 test_FunctionPointer00(
"FuncPtr3ab_plain_11",
false, 1, 0, f3a_1, f3b_1);
158 test_FunctionPointer00(
"FuncPtr3ab_plain_22",
false, 1, 0, f3a_2, f3b_2);
159 INFO(
"FuncPtr3_plain: bindPlainFunc<int, int>: END");
163 INFO(
"FuncPtr4_stdlambda: bindStdFunc<int, int>: START");
165 std::function<int(
int i)> func4a_stdlambda = [](
int i)->
int {
169 std::function<int(
int i)> func4b_stdlambda = [](
int i)->
int {
175 test_FunctionPointer00(
"FuncPtr4a_stdlambda_11",
true, 1, 101, f4a_1, f4a_1);
176 test_FunctionPointer00(
"FuncPtr4a_stdlambda_12",
true, 1, 101, f4a_1, f4a_2);
180 test_FunctionPointer00(
"FuncPtr4b_stdlambda_11",
true, 1, 1001, f4b_1, f4b_1);
181 test_FunctionPointer00(
"FuncPtr4b_stdlambda_12",
true, 1, 1001, f4b_1, f4b_2);
183 test_FunctionPointer00(
"FuncPtr4ab_stdlambda_11",
false, 1, 0, f4a_1, f4b_1);
184 test_FunctionPointer00(
"FuncPtr4ab_stdlambda_22",
false, 1, 0, f4a_2, f4b_2);
188 test_FunctionPointer01(
"FuncPtr4a_stdlambda_01",
true, f4a_0, f4a_1);
189 test_FunctionPointer01(
"FuncPtr4a_stdlambda_02",
true, f4a_0, f4a_2);
190 test_FunctionPointer01(
"FuncPtr4b_stdlambda_01",
true, f4b_0, f4b_1);
191 test_FunctionPointer01(
"FuncPtr4b_stdlambda_02",
true, f4b_0, f4b_2);
192 test_FunctionPointer01(
"FuncPtr4ab_stdlambda_00",
false, f4a_0, f4b_0);
193 test_FunctionPointer01(
"FuncPtr4ab_stdlambda_01",
false, f4a_0, f4b_1);
194 test_FunctionPointer01(
"FuncPtr4ab_stdlambda_10",
false, f4a_1, f4b_0);
195 INFO(
"FuncPtr4_stdlambda: bindStdFunc<int, int>: END");
199 INFO(
"FuncPtr5_capture: bindCaptureFunc<int, int, int>: START");
203 int offset1000 = 1000;
205 int(*func5a_capture)(
int&, int) = [](
int& offset,
int i)->int {
206 int res = i+10000+offset;
209 int(*func5b_capture)(
int&, int) = [](
int& offset,
int i)->int {
210 int res = i+100000+offset;
216 [](
int& offset,
int i)->
int {
217 int res = i+10000+offset;
220 test_FunctionPointer01(
"FuncPtr5a_o100_capture_00",
true, f5a_o100_0, f5a_o100_0);
222 MyClassFunction f5a_o100_1 = bindCaptureFunc<int, int, int>(offset100, func5a_capture);
224 test_FunctionPointer01(
"FuncPtr5a_o100_capture_12",
true, f5a_o100_1, f5a_o100_2);
225 test_FunctionPointer00(
"FuncPtr5a_o100_capture_11",
true, 1, 10101, f5a_o100_1, f5a_o100_1);
226 test_FunctionPointer00(
"FuncPtr5a_o100_capture_12",
true, 1, 10101, f5a_o100_1, f5a_o100_2);
230 test_FunctionPointer01(
"FuncPtr5a_o1000_capture_12",
true, f5a_o1000_1, f5a_o1000_2);
231 test_FunctionPointer01(
"FuncPtr5a_o100_o1000_capture_11",
false, f5a_o100_1, f5a_o1000_1);
235 test_FunctionPointer00(
"FuncPtr5b_o100_capture_11",
true, 1, 100101, f5b_o100_1, f5b_o100_1);
236 test_FunctionPointer00(
"FuncPtr5b_o100_capture_12",
true, 1, 100101, f5b_o100_1, f5b_o100_2);
238 test_FunctionPointer00(
"FuncPtr5ab_o100_capture_11",
false, 1, 0, f5a_o100_1, f5b_o100_1);
239 test_FunctionPointer00(
"FuncPtr5ab_o100_capture_22",
false, 1, 0, f5a_o100_2, f5b_o100_2);
240 INFO(
"FuncPtr5_capture: bindCaptureFunc<int, int, int>: END");
244 INFO(
"FuncPtr6_capture: bindCaptureFunc<int, std::shared_ptr<IntOffset>, int>: START");
247 std::shared_ptr<IntOffset> offset100(
new IntOffset(100));
248 std::shared_ptr<IntOffset> offset1000(
new IntOffset(1000));
250 int(*func6a_capture)(std::shared_ptr<IntOffset>&, int) = [](std::shared_ptr<IntOffset>& sharedOffset,
int i)->int {
251 int res = i+10000+sharedOffset->value;
254 int(*func6b_capture)(std::shared_ptr<IntOffset>&, int) = [](std::shared_ptr<IntOffset>& sharedOffset,
int i)->int {
255 int res = i+100000+sharedOffset->value;
260 MyClassFunction f6a_o100_0 = bindCaptureFunc<int, std::shared_ptr<IntOffset>,
int>(offset100,
261 [](std::shared_ptr<IntOffset>& sharedOffset,
int i)->
int {
262 int res = i+10000+sharedOffset->value;
265 test_FunctionPointer01(
"FuncPtr6a_o100_capture_00",
true, f6a_o100_0, f6a_o100_0);
267 MyClassFunction f6a_o100_1 = bindCaptureFunc<int, std::shared_ptr<IntOffset>,
int>(offset100, func6a_capture);
269 test_FunctionPointer01(
"FuncPtr6a_o100_capture_12",
true, f6a_o100_1, f6a_o100_2);
270 test_FunctionPointer00(
"FuncPtr6a_o100_capture_11",
true, 1, 10101, f6a_o100_1, f6a_o100_1);
271 test_FunctionPointer00(
"FuncPtr6a_o100_capture_12",
true, 1, 10101, f6a_o100_1, f6a_o100_2);
275 test_FunctionPointer01(
"FuncPtr6a_o1000_capture_12",
true, f6a_o1000_1, f6a_o1000_2);
276 test_FunctionPointer01(
"FuncPtr6a_o100_o1000_capture_11",
false, f6a_o100_1, f6a_o1000_1);
280 test_FunctionPointer00(
"FuncPtr6b_o100_capture_11",
true, 1, 100101, f6b_o100_1, f6b_o100_1);
281 test_FunctionPointer00(
"FuncPtr6b_o100_capture_12",
true, 1, 100101, f6b_o100_1, f6b_o100_2);
283 test_FunctionPointer00(
"FuncPtr6ab_o100_capture_11",
false, 1, 0, f6a_o100_1, f6b_o100_1);
284 test_FunctionPointer00(
"FuncPtr6ab_o100_capture_22",
false, 1, 0, f6a_o100_2, f6b_o100_2);
285 INFO(
"FuncPtr6_capture: bindCaptureFunc<int, std::shared_ptr<IntOffset>, int>: END");
289 INFO(
"FuncPtr7_capture: bindCaptureFunc<int, IntOffset, int>: START");
292 IntOffset offset100(100);
293 IntOffset offset1000(1000);
295 int(*func7a_capture)(IntOffset&, int) = [](IntOffset& sharedOffset,
int i)->int {
296 int res = i+10000+sharedOffset.value;
299 int(*func7b_capture)(IntOffset&, int) = [](IntOffset& sharedOffset,
int i)->int {
300 int res = i+100000+sharedOffset.value;
305 MyClassFunction f7a_o100_0 = bindCaptureFunc<int, IntOffset, int>(offset100,
306 [](IntOffset& sharedOffset,
int i)->
int {
307 int res = i+10000+sharedOffset.value;
310 test_FunctionPointer01(
"FuncPtr7a_o100_capture_00",
true, f7a_o100_0, f7a_o100_0);
312 INFO(
"f7a_o100_1 copy_ctor");
313 MyClassFunction f7a_o100_1 = bindCaptureFunc<int, IntOffset, int>(offset100, func7a_capture);
314 INFO(
"f7a_o100_1 copy_ctor done");
315 INFO(
"f7a_o100_2 move_ctor");
317 INFO(
"f7a_o100_2 move_ctor done");
318 test_FunctionPointer01(
"FuncPtr7a_o100_capture_12",
true, f7a_o100_1, f7a_o100_2);
319 test_FunctionPointer00(
"FuncPtr7a_o100_capture_11",
true, 1, 10101, f7a_o100_1, f7a_o100_1);
320 test_FunctionPointer00(
"FuncPtr7a_o100_capture_12",
true, 1, 10101, f7a_o100_1, f7a_o100_2);
324 test_FunctionPointer01(
"FuncPtr7a_o1000_capture_12",
true, f7a_o1000_1, f7a_o1000_2);
325 test_FunctionPointer01(
"FuncPtr7a_o100_o1000_capture_11",
false, f7a_o100_1, f7a_o1000_1);
329 test_FunctionPointer00(
"FuncPtr7b_o100_capture_11",
true, 1, 100101, f7b_o100_1, f7b_o100_1);
330 test_FunctionPointer00(
"FuncPtr7b_o100_capture_12",
true, 1, 100101, f7b_o100_1, f7b_o100_2);
332 test_FunctionPointer00(
"FuncPtr7ab_o100_capture_11",
false, 1, 0, f7a_o100_1, f7b_o100_1);
333 test_FunctionPointer00(
"FuncPtr7ab_o100_capture_22",
false, 1, 0, f7a_o100_2, f7b_o100_2);
334 INFO(
"FuncPtr7_capture: bindCaptureFunc<int, IntOffset, int>: END");