diff --git a/tests/GenerateSipBindings/CMakeLists.txt b/tests/GenerateSipBindings/CMakeLists.txt index c223bce..151db9f 100644 --- a/tests/GenerateSipBindings/CMakeLists.txt +++ b/tests/GenerateSipBindings/CMakeLists.txt @@ -1,47 +1,52 @@ cmake_minimum_required(VERSION 3.2) project(GenerateSipBindings) find_package(Qt5Core REQUIRED) set(CMAKE_AUTOMOC ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON) set(CMAKE_CXX_STANDARD 14) add_library(ExternalLib SHARED external_lib.cpp) target_link_libraries(ExternalLib PUBLIC Qt5::Core) target_compile_features(ExternalLib PUBLIC cxx_nullptr) -add_library(CppLib SHARED cpplib.cpp) +add_library(CppLib SHARED + cpplib.cpp + subdir/subdirfile.cpp +) target_link_libraries(CppLib PUBLIC Qt5::Core PRIVATE ExternalLib ) target_compile_features(CppLib PUBLIC cxx_nullptr) +target_include_directories(CppLib PUBLIC subdir) list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../find-modules) find_package(PythonModuleGeneration REQUIRED) ecm_generate_python_binding( TARGET ExternalLib PYTHONNAMESPACE PyTest MODULENAME ExternalLib SIP_DEPENDS QtCore/QtCoremod.sip HEADERS external_lib.h ) ecm_generate_python_binding( TARGET CppLib PYTHONNAMESPACE PyTest MODULENAME CppLib RULES_FILE "${CMAKE_CURRENT_SOURCE_DIR}/rules_SipTest.py" SIP_DEPENDS QtCore/QtCoremod.sip HEADERS cpplib.h + subdir/subdirfile.h ) diff --git a/tests/GenerateSipBindings/subdir/subdirfile.cpp b/tests/GenerateSipBindings/subdir/subdirfile.cpp new file mode 100644 index 0000000..d874243 --- /dev/null +++ b/tests/GenerateSipBindings/subdir/subdirfile.cpp @@ -0,0 +1,7 @@ + +#include "subdirfile.h" + +int SubdirObject::mul(int a, int b) +{ + return a * b; +} diff --git a/tests/GenerateSipBindings/subdir/subdirfile.h b/tests/GenerateSipBindings/subdir/subdirfile.h new file mode 100644 index 0000000..5fd18db --- /dev/null +++ b/tests/GenerateSipBindings/subdir/subdirfile.h @@ -0,0 +1,8 @@ + +#pragma once + +class SubdirObject +{ +public: + int mul(int a, int b); +}; diff --git a/tests/GenerateSipBindings/testscript.py b/tests/GenerateSipBindings/testscript.py index 9e12bd1..e79706b 100644 --- a/tests/GenerateSipBindings/testscript.py +++ b/tests/GenerateSipBindings/testscript.py @@ -1,120 +1,123 @@ import sys from PyQt5 import QtCore sys.path.append(sys.argv[1]) import PyTest.CppLib mo = PyTest.CppLib.MyObject() assert(mo.addThree(39) == 42) assert(mo.addThree([38, 39, 40]) == [41, 42, 43]) assert(mo.addThree("SomeString") == "DefaultSomeStringThree") assert(mo.findNeedle(["One", "Two", "Three"], "Two") == 1) assert(mo.findNeedle(["One", "Two", "Three"], "Four") == -1) assert(mo.findNeedle(["One", "Two", "Three"], "Th") == 2) assert(mo.findNeedle(["One", "Two", "Three"], "Th", QtCore.Qt.MatchExactly) == -1) assert(mo.const_parameters(30) == 15) assert(mo.const_parameters(30, mo) == 10) assert(mo.qtEnumTest(QtCore.Qt.MatchContains | QtCore.Qt.MatchStartsWith) == 3) assert(mo.localEnumTest(PyTest.CppLib.MyObject.Val2) == 2) lfd = PyTest.CppLib.LocalFwdDecl(18) assert(mo.localFwdDecl(lfd) == 18) import PyTest.ExternalLib efd = PyTest.ExternalLib.ExternalFwdDecl(18) assert(mo.externalFwdDecl(efd) == 18) assert(mo.localListDecl([1, 5, 7]) == 13) lfdl = [PyTest.CppLib.LocalFwdDecl(3), PyTest.CppLib.LocalFwdDecl(6)] assert(mo.localDeclListDecl(lfdl) == 9) # # Verify that an enum with attributes can be read. # assert(PyTest.CppLib.Foo == 0) assert(PyTest.CppLib.Bar == 2) class Reactor(QtCore.QObject): def __init__(self, obj): QtCore.QObject.__init__(self) self.gotPrivateSlotCalledSignal = False self.gotProtectedSlotCalledSignal = False self.gotPublicSlotCalledSignal = False obj.privateSlotCalled.connect(self.react_to_privateSlotCalled) obj.protectedSlotCalled.connect(self.react_to_protectedSlotCalled) obj.publicSlotCalled.connect(self.react_to_publicSlotCalled) def react_to_privateSlotCalled(self): self.gotPrivateSlotCalledSignal = True def react_to_protectedSlotCalled(self): self.gotProtectedSlotCalledSignal = True def react_to_publicSlotCalled(self): self.gotPublicSlotCalledSignal = True class Emitter(QtCore.QObject): privateTrigger = QtCore.pyqtSignal() protectedTrigger = QtCore.pyqtSignal() publicTrigger = QtCore.pyqtSignal() def __init__(self, obj): QtCore.QObject.__init__(self) self.privateTrigger.connect(obj.privateSlot1) self.protectedTrigger.connect(obj.protectedSlot1) self.publicTrigger.connect(obj.publicSlot1) def emitSignalForPublic(self): self.publicTrigger.emit() def emitSignalForPrivate(self): self.privateTrigger.emit() def emitSignalForProtected(self): self.protectedTrigger.emit() e = Emitter(mo) r = Reactor(mo) assert(not r.gotPrivateSlotCalledSignal) assert(not r.gotProtectedSlotCalledSignal) assert(not r.gotPublicSlotCalledSignal) e.emitSignalForPrivate() assert(r.gotPrivateSlotCalledSignal) e.emitSignalForProtected() assert(r.gotProtectedSlotCalledSignal) e.emitSignalForPublic() assert(r.gotPublicSlotCalledSignal) assert(PyTest.CppLib.SomeNS.EnumValueOne == 1) 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) + +sdo = PyTest.CppLib.SubdirObject() +assert(sdo.mul(5, 6) == 30)