aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-05-03 05:44:57 +0200
committerSven Gothel <[email protected]>2020-05-03 05:44:57 +0200
commit550abc2ed84637553d0aaeba77b04004953d8930 (patch)
treec8c6431430e2e839ecda4061a7eae0716c65854d /test
parent73ed5e758c801a1944fa575b0ffc280e8f62f20e (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.cpp37
1 files changed, 30 insertions, 7 deletions
diff --git a/test/direct_bt/test_basictypes01.cpp b/test/direct_bt/test_basictypes01.cpp
index fc94295..a540f53 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");