diff options
author | Sven Gothel <[email protected]> | 2020-05-03 05:44:57 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-05-03 05:44:57 +0200 |
commit | 4125c66a021ee2a5f57bdbe9305d8e056516dd7d (patch) | |
tree | 8229f486b8a2b06c6037bcb6d7bbb831e3c20615 /test | |
parent | e9df1ba4b677766e6b56e611bbaa3efd394502a6 (diff) |
ClassFunction -> FunctionDef generalization, adding plain function (non-class-member) support
To support on-the-fly lambda non-member functions for callbacks,
we need to bind to same non-member plain functions.
Hence rename ClassFunction -> FunctionDef and add PlainInvocationFunc for this purpose.
Tested via C++ unit test test_basictypes01.cpp
Diffstat (limited to 'test')
-rw-r--r-- | test/direct_bt/test_basictypes01.cpp | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/test/direct_bt/test_basictypes01.cpp b/test/direct_bt/test_basictypes01.cpp index fc94295d..a540f53e 100644 --- a/test/direct_bt/test_basictypes01.cpp +++ b/test/direct_bt/test_basictypes01.cpp @@ -7,7 +7,7 @@ #include <direct_bt/BasicTypes.hpp> #include <direct_bt/BTAddress.hpp> -#include <direct_bt/ClassFunction.hpp> +#include <direct_bt/FunctionDef.hpp> using namespace direct_bt; @@ -47,9 +47,17 @@ class Cppunit_tests : public Cppunit { int res = i+1000; return res;; } + static int Func3a_static(int i) { + int res = i+100; + return res;; + } + static int Func3b_static(int i) { + int res = i+1000; + return res;; + } // template<typename R, typename... A> - typedef ClassFunction<int, int> MyClassFunction; + typedef FunctionDef<int, int> MyClassFunction; void test_FunctionPointer00(std::string msg, bool expEqual, int value, int expRes, MyClassFunction & f1, MyClassFunction &f2) { // test std::function identity @@ -70,14 +78,14 @@ class Cppunit_tests : public Cppunit { void single_test() override { { - // FunctionPointer(Cppunit_tests &base, Func1Type func) - MyClassFunction f2a_1 = bindClassFunction<int, Cppunit_tests, int>(this, &Cppunit_tests::func2a_member); - MyClassFunction f2a_2 = bindClassFunction(this, &Cppunit_tests::func2a_member); + // FunctionDef(Cppunit_tests &base, Func1Type func) + MyClassFunction f2a_1 = bindMemberFunc<int, Cppunit_tests, int>(this, &Cppunit_tests::func2a_member); + MyClassFunction f2a_2 = bindMemberFunc(this, &Cppunit_tests::func2a_member); test_FunctionPointer00("FuncPtr2a_member_11", true, 1, 101, f2a_1, f2a_1); test_FunctionPointer00("FuncPtr2a_member_12", true, 1, 101, f2a_1, f2a_2); - MyClassFunction f2b_1 = bindClassFunction(this, &Cppunit_tests::func2b_member); - MyClassFunction f2b_2 = bindClassFunction(this, &Cppunit_tests::func2b_member); + MyClassFunction f2b_1 = bindMemberFunc(this, &Cppunit_tests::func2b_member); + MyClassFunction f2b_2 = bindMemberFunc(this, &Cppunit_tests::func2b_member); test_FunctionPointer00("FuncPtr2b_member_11", true, 1, 1001, f2b_1, f2b_1); test_FunctionPointer00("FuncPtr2b_member_12", true, 1, 1001, f2b_1, f2b_2); @@ -85,6 +93,21 @@ class Cppunit_tests : public Cppunit { test_FunctionPointer00("FuncPtr2ab_member_22", false, 1, 0, f2a_2, f2b_2); } { + // FunctionDef(Func1Type func) + MyClassFunction f3a_1 = bindPlainFunc<int, int>(&Cppunit_tests::Func3a_static); + MyClassFunction f3a_2 = bindPlainFunc(&Cppunit_tests::Func3a_static); + test_FunctionPointer00("FuncPtr3a_static_11", true, 1, 101, f3a_1, f3a_1); + test_FunctionPointer00("FuncPtr3a_static_12", true, 1, 101, f3a_1, f3a_2); + + MyClassFunction f3b_1 = bindPlainFunc(&Cppunit_tests::Func3b_static); + MyClassFunction f3b_2 = bindPlainFunc(&Func3b_static); + test_FunctionPointer00("FuncPtr3b_static_11", true, 1, 1001, f3b_1, f3b_1); + test_FunctionPointer00("FuncPtr3b_static_12", true, 1, 1001, f3b_1, f3b_2); + + test_FunctionPointer00("FuncPtr3ab_static_11", false, 1, 0, f3a_1, f3b_1); + test_FunctionPointer00("FuncPtr3ab_static_22", false, 1, 0, f3a_2, f3b_2); + } + { 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"); |