diff options
author | Sven Gothel <[email protected]> | 2020-05-03 08:08:18 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-05-03 08:08:18 +0200 |
commit | efa490bc3f55b1af072b5159d075afece018991f (patch) | |
tree | 1280ef49f24ce3e2e2b26672bb39ed9919200cb2 /test | |
parent | 124b212524d0a2556b88fc7ee8731dd6ba27afb1 (diff) |
FunctionDef: Add StdInvocationFunc supporting std::function for capturing lambdas
StdInvocationFunc wraps std::function, while using a given unique uint64_t identifier
used for equality operations, as std::function doesn't support the very same.
std::function support allows using capturing lambdas in C++11,
which we require for on the fly callbacks.
Since we haven't figured out yet how to properly wrap capturing lambdas
otherwise via PlainInvocationFunc, StdInvocationFunc must do it until.
Diffstat (limited to 'test')
-rw-r--r-- | test/direct_bt/test_basictypes01.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/test/direct_bt/test_basictypes01.cpp b/test/direct_bt/test_basictypes01.cpp index a540f53e..e40370c4 100644 --- a/test/direct_bt/test_basictypes01.cpp +++ b/test/direct_bt/test_basictypes01.cpp @@ -73,6 +73,15 @@ class Cppunit_tests : public Cppunit { CHECKTM(msg, f1 != f2); } } + void test_FunctionPointer01(std::string msg, bool expEqual, MyClassFunction & f1, MyClassFunction &f2) { + // test std::function identity + PRINTM(msg+": FunctionPointer00 Fun f1p == f2p : " + std::to_string( f1 == f2 ) + ", f1p: " + f1.toString() + ", f2 "+f2.toString() ); + if( expEqual ) { + CHECKTM(msg, f1 == f2); + } else { + CHECKTM(msg, f1 != f2); + } + } public: void single_test() override { @@ -108,6 +117,39 @@ class Cppunit_tests : public Cppunit { test_FunctionPointer00("FuncPtr3ab_static_22", false, 1, 0, f3a_2, f3b_2); } { + // FunctionDef(Func1Type func) <int, int> + std::function<int(int i)> func4a_stdlambda = [](int i)->int { + int res = i+100; + return res;; + }; + std::function<int(int i)> func4b_stdlambda = [](int i)->int { + int res = i+1000; + return res;; + }; + MyClassFunction f3a_1 = bindStdFunc<int, int>(100, func4a_stdlambda); + MyClassFunction f3a_2 = bindStdFunc(100, func4a_stdlambda); + test_FunctionPointer00("FuncPtr4a_stdlambda_11", true, 1, 101, f3a_1, f3a_1); + test_FunctionPointer00("FuncPtr4a_stdlambda_12", true, 1, 101, f3a_1, f3a_2); + + MyClassFunction f3b_1 = bindStdFunc(200, func4b_stdlambda); + MyClassFunction f3b_2 = bindStdFunc(200, func4b_stdlambda); + test_FunctionPointer00("FuncPtr4b_stdlambda_11", true, 1, 1001, f3b_1, f3b_1); + test_FunctionPointer00("FuncPtr4b_stdlambda_12", true, 1, 1001, f3b_1, f3b_2); + + test_FunctionPointer00("FuncPtr4ab_stdlambda_11", false, 1, 0, f3a_1, f3b_1); + test_FunctionPointer00("FuncPtr4ab_stdlambda_22", false, 1, 0, f3a_2, f3b_2); + + MyClassFunction f3a_0 = bindStdFunc<int, int>(100); + MyClassFunction f3b_0 = bindStdFunc<int, int>(200); + test_FunctionPointer01("FuncPtr4a_stdlambda_01", true, f3a_0, f3a_1); + test_FunctionPointer01("FuncPtr4a_stdlambda_02", true, f3a_0, f3a_2); + test_FunctionPointer01("FuncPtr4b_stdlambda_01", true, f3b_0, f3b_1); + test_FunctionPointer01("FuncPtr4b_stdlambda_02", true, f3b_0, f3b_2); + test_FunctionPointer01("FuncPtr4ab_stdlambda_00", false, f3a_0, f3b_0); + test_FunctionPointer01("FuncPtr4ab_stdlambda_01", false, f3a_0, f3b_1); + test_FunctionPointer01("FuncPtr4ab_stdlambda_10", false, f3a_1, f3b_0); + } + { test_int32_t("INT32_MIN", INT32_MIN, 14, "-2,147,483,648"); test_int32_t("int32_t -thousand", -1000, 6, "-1,000"); test_int32_t("int32_t one", 1, 1, "1"); |