aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorStephen Kelly <steveire@gmail.com>2017-01-13 18:06:28 +0000
committerStephen Kelly <steveire@gmail.com>2017-01-13 18:06:28 +0000
commitaf9f502f9629766130e171632d2072d563661959 (patch)
treeab77d12271937a6e579538991e8aa5704673665c /tests
parent39454cd893309c1a00eb7a9254045d52a8ced169 (diff)
downloadextra-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.cpp15
-rw-r--r--tests/GenerateSipBindings/cpplib.h4
-rw-r--r--tests/GenerateSipBindings/rules_SipTest.py37
-rw-r--r--tests/GenerateSipBindings/testscript.py4
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)