diff options
author | Stephen Kelly <steveire@gmail.com> | 2017-01-13 18:06:28 +0000 |
---|---|---|
committer | Stephen Kelly <steveire@gmail.com> | 2017-01-13 18:06:28 +0000 |
commit | af9f502f9629766130e171632d2072d563661959 (patch) | |
tree | ab77d12271937a6e579538991e8aa5704673665c /tests | |
parent | 39454cd893309c1a00eb7a9254045d52a8ced169 (diff) | |
download | extra-cmake-modules-af9f502f9629766130e171632d2072d563661959.tar.gz extra-cmake-modules-af9f502f9629766130e171632d2072d563661959.tar.bz2 |
Bindings: Implement ModuleCode and MethodCode databases
Diffstat (limited to 'tests')
-rw-r--r-- | tests/GenerateSipBindings/cpplib.cpp | 15 | ||||
-rw-r--r-- | tests/GenerateSipBindings/cpplib.h | 4 | ||||
-rw-r--r-- | tests/GenerateSipBindings/rules_SipTest.py | 37 | ||||
-rw-r--r-- | tests/GenerateSipBindings/testscript.py | 4 |
4 files changed, 60 insertions, 0 deletions
diff --git a/tests/GenerateSipBindings/cpplib.cpp b/tests/GenerateSipBindings/cpplib.cpp index 76b97b0e..7eb15939 100644 --- a/tests/GenerateSipBindings/cpplib.cpp +++ b/tests/GenerateSipBindings/cpplib.cpp @@ -146,3 +146,18 @@ qreal SomeNS::useEnum(MyFlags flags) { return flags; } + +int customMethod(QList<int> const& nums) +{ + return nums.size(); +} + +int SomeNS::customMethod(QList<int> const& nums) +{ + return 0; +} + +int anotherCustomMethod(QList<int> const& nums) +{ + return 0; +} diff --git a/tests/GenerateSipBindings/cpplib.h b/tests/GenerateSipBindings/cpplib.h index 81ad2038..b69480ee 100644 --- a/tests/GenerateSipBindings/cpplib.h +++ b/tests/GenerateSipBindings/cpplib.h @@ -126,8 +126,12 @@ Q_DECLARE_FLAGS(MyFlags, MyFlagType) qreal useEnum(MyFlags flags = EnumValueOne); +int customMethod(QList<int> const& nums); + } +int anotherCustomMethod(QList<int> const& nums); + enum __attribute__((visibility("default"))) EnumWithAttributes { Foo, Bar = 2 diff --git a/tests/GenerateSipBindings/rules_SipTest.py b/tests/GenerateSipBindings/rules_SipTest.py index e0cd2b9e..1331da41 100644 --- a/tests/GenerateSipBindings/rules_SipTest.py +++ b/tests/GenerateSipBindings/rules_SipTest.py @@ -11,7 +11,44 @@ def local_function_rules(): ["MyObject", "fwdDeclRef", ".*", ".*", ".*", rules_engine.function_discard], ] +def methodGenerator(function, sip, entry): + sip["code"] = """ + %MethodCode + sipRes = {} + myAcumulate(a0); + %End + """.format(entry["param"]) + + class RuleSet(Qt5Ruleset.RuleSet): def __init__(self): Qt5Ruleset.RuleSet.__init__(self) self._fn_db = rules_engine.FunctionRuleDb(lambda: local_function_rules() + Qt5Ruleset.function_rules()) + self._modulecode = rules_engine.ModuleCodeDb({ + "cpplib.h": { + "code": """ +%ModuleCode +int myAcumulate(const QList<int> *list) { + return std::accumulate(list->begin(), list->end(), 0); +} +%End\n + """ + } + }) + + self._methodcode = rules_engine.MethodCodeDb({ + "SomeNS": { + "customMethod": { + "code": """ + %MethodCode + sipRes = myAcumulate(a0); + %End + """ + } + }, + "cpplib.h": { + "anotherCustomMethod": { + "code": methodGenerator, + "param": 42 + } + } + }) diff --git a/tests/GenerateSipBindings/testscript.py b/tests/GenerateSipBindings/testscript.py index deefb960..9faea837 100644 --- a/tests/GenerateSipBindings/testscript.py +++ b/tests/GenerateSipBindings/testscript.py @@ -98,3 +98,7 @@ assert(PyTest.CppLib.SomeNS.EnumValueTwo == 2) assert(PyTest.CppLib.SomeNS.useEnum() == 1.0) assert(PyTest.CppLib.SomeNS.useEnum(PyTest.CppLib.SomeNS.EnumValueOne) == 1.0) assert(PyTest.CppLib.SomeNS.useEnum(PyTest.CppLib.SomeNS.EnumValueTwo) == 2.0) + +assert(PyTest.CppLib.SomeNS.customMethod([2, 3, 5]) == 10) + +assert(PyTest.CppLib.anotherCustomMethod([2, 3, 5]) == 52) |