diff options
Diffstat (limited to 'sources/pyside2/tests/pysidetest')
29 files changed, 2221 insertions, 0 deletions
diff --git a/sources/pyside2/tests/pysidetest/CMakeLists.txt b/sources/pyside2/tests/pysidetest/CMakeLists.txt new file mode 100644 index 000000000..05b0b86b4 --- /dev/null +++ b/sources/pyside2/tests/pysidetest/CMakeLists.txt @@ -0,0 +1,139 @@ +project(pysidetest) +project(testbinding) + +cmake_minimum_required(VERSION 2.6) + +set(QT_USE_QTCORE 1) +# no more supported: include(${QT_USE_FILE}) +add_definitions(${Qt5Core_DEFINITIONS}) +add_definitions(-DQT_SHARED) +add_definitions(-DRXX_ALLOCATOR_INIT_0) + +find_package(Qt5Widgets) + +set(pysidetest_SRC +testobject.cpp +testview.cpp +hiddenobject.cpp +) + +set(pysidetest_MOC_HEADERS +testobject.h +testview.h +hiddenobject.h +) + +qt5_wrap_cpp(pysidetest_MOC_SRC ${pysidetest_MOC_HEADERS}) + +set(testbinding_SRC +${CMAKE_CURRENT_BINARY_DIR}/testbinding/testobject_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/testbinding/intvalue_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/testbinding/pysidecpp_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/testbinding/pysidecpp_testobjectwithnamespace_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/testbinding/pysidecpp2_testobjectwithoutnamespace_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/testbinding/testview_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/testbinding/testbinding_module_wrapper.cpp +) + +# Get per module include dirs. +# There are usually 3 paths there: +# ./qt/include/; ./qt/include/QtCore ; ./qt/mkspecs/linux-g++ +# on framework build they are: +# ./qt/lib/QtCore.framework; ./qt/lib/QtCore.framework/Headers ; ./qt/mkspecs/macx-clang +# Thus we use the second direct path, which contains the actual header files. + +list(GET Qt5Core_INCLUDE_DIRS 1 Qt5Core_DIRECT_INCLUDE_DIR) +list(GET Qt5Gui_INCLUDE_DIRS 1 Qt5Gui_DIRECT_INCLUDE_DIR) +list(GET Qt5Widgets_INCLUDE_DIRS 1 Qt5Widgets_DIRECT_INCLUDE_DIR) + +# Adjust include headers paths for frameworks. +set(shiboken_framework_include_dirs_option "") +if(CMAKE_HOST_APPLE AND QtCore_is_framework) + set(shiboken_framework_include_dirs "${QT_FRAMEWORK_INCLUDE_DIR}") + set(shiboken_framework_include_dirs_option "--framework-include-paths=${shiboken_framework_include_dirs}") +endif() + +make_path(testbinding_include_dirs ${pyside2_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/../../PySide2 + ${CMAKE_CURRENT_SOURCE_DIR}/../../libpyside + ${QT_INCLUDE_DIR} + ${Qt5Core_DIRECT_INCLUDE_DIR} + ${Qt5Gui_DIRECT_INCLUDE_DIR} + ${Qt5Widgets_DIRECT_INCLUDE_DIR} + ) + +make_path(testbinding_typesystem_path ${CMAKE_CURRENT_SOURCE_DIR} + ${pyside2_SOURCE_DIR} + ${QtCore_SOURCE_DIR} ${QtGui_SOURCE_DIR} ${QtWidgets_SOURCE_DIR} + ${QtCore_BINARY_DIR} ${QtGui_BINARY_DIR} ${QtWidgets_BINARY_DIR} + ) + +add_custom_command(OUTPUT ${testbinding_SRC} +COMMAND ${SHIBOKEN_BINARY} ${GENERATOR_EXTRA_FLAGS} + ${CMAKE_CURRENT_SOURCE_DIR}/pysidetest_global.h + --include-paths=${testbinding_include_dirs} + ${shiboken_framework_include_dirs_option} + --typesystem-paths=${testbinding_typesystem_path} + --output-directory=${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/typesystem_pysidetest.xml + --api-version=${SUPPORTED_QT_VERSION} +WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +COMMENT "Running generator for test binding..." +) + +include_directories(${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_BINARY_DIR} + ${Qt5Core_INCLUDE_DIRS} + ${Qt5Gui_INCLUDE_DIRS} + ${Qt5Widgets_INCLUDE_DIRS} + ${SHIBOKEN_INCLUDE_DIR} + ${pyside2_SOURCE_DIR} + ${QtCore_GEN_DIR} + ${QtGui_GEN_DIR} + ${QtWidgets_GEN_DIR} + ${libpyside_SOURCE_DIR} + ${SHIBOKEN_PYTHON_INCLUDE_DIR}) + +add_library(pysidetest SHARED ${pysidetest_SRC} ${pysidetest_MOC_SRC}) +target_link_libraries(pysidetest + ${Qt5Core_LIBRARIES} + ${Qt5Gui_LIBRARIES} + ${Qt5Widgets_LIBRARIES} + ) + +add_library(testbinding MODULE ${testbinding_SRC}) +set_property(TARGET testbinding PROPERTY PREFIX "") +if(WIN32) + set_target_properties(testbinding PROPERTIES SUFFIX ".pyd") +endif() +target_link_libraries(testbinding + pysidetest + pyside2 + ${PYTHON_LIBRARIES} + ${SHIBOKEN_LIBRARY} + ${Qt5Core_LIBRARIES} + ${Qt5Gui_LIBRARIES} + ${Qt5Widgets_LIBRARIES} + ${SBK_PYTHON_LIBRARIES}) + +add_dependencies(testbinding pyside2 QtCore libpyside pysidetest) + +PYSIDE_TEST(decoratedslot_test.py) +PYSIDE_TEST(delegatecreateseditor_test.py) +PYSIDE_TEST(enum_test.py) +PYSIDE_TEST(homonymoussignalandmethod_test.py) +PYSIDE_TEST(list_signal_test.py) +PYSIDE_TEST(modelview_test.py) +PYSIDE_TEST(new_inherited_functions_test.py) +PYSIDE_TEST(notify_id.py) +PYSIDE_TEST(qvariant_test.py) +PYSIDE_TEST(signalandnamespace_test.py) +PYSIDE_TEST(signalwithdefaultvalue_test.py) +PYSIDE_TEST(signalemissionfrompython_test.py) +PYSIDE_TEST(version_test.py) +PYSIDE_TEST(typedef_signal_test.py) +PYSIDE_TEST(bug_1016.py) +PYSIDE_TEST(utils_test.py) +PYSIDE_TEST(mixin_signal_slots_test.py) +PYSIDE_TEST(signal_slot_warning.py) diff --git a/sources/pyside2/tests/pysidetest/bug_1016.py b/sources/pyside2/tests/pysidetest/bug_1016.py new file mode 100644 index 000000000..745012248 --- /dev/null +++ b/sources/pyside2/tests/pysidetest/bug_1016.py @@ -0,0 +1,40 @@ +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of PySide2. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +from testbinding import * +import unittest + +class TestBug1016 (unittest.TestCase): + + def testIt(self): + obj = getHiddenObject() + self.assertEqual(obj.callMe(), None) + self.assertTrue(obj.wasCalled()) + +if __name__ == "__main__": + unittest.main() diff --git a/sources/pyside2/tests/pysidetest/curr_errors.txt b/sources/pyside2/tests/pysidetest/curr_errors.txt new file mode 100644 index 000000000..83b6e6212 --- /dev/null +++ b/sources/pyside2/tests/pysidetest/curr_errors.txt @@ -0,0 +1,12 @@ +Generating class model... [OK] +Generating enum model... [OK] +Generating namespace model... [OK] +Resolving typedefs... [OK] +Fixing class inheritance... [OK] +Detecting inconsistencies in class model... [OK] +[OK] + type 'QPyTextObject' is specified in typesystem, but not defined. This could potentially lead to compilation errors. + + + +Done, 1 warnings (1051 known issues) diff --git a/sources/pyside2/tests/pysidetest/decoratedslot_test.py b/sources/pyside2/tests/pysidetest/decoratedslot_test.py new file mode 100644 index 000000000..6268f331c --- /dev/null +++ b/sources/pyside2/tests/pysidetest/decoratedslot_test.py @@ -0,0 +1,67 @@ +#!/usr/bin/python + +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of PySide2. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +import unittest +from PySide2.QtCore import QObject +from testbinding import TestObject + +class Receiver(QObject): + def __init__(self): + QObject.__init__(self) + self.called = False + + def ReceiverDecorator(func): + def decoratedFunction(self, *args, **kw): + func(self, *args, **kw) + return decoratedFunction + + # This method with the same name of the internal decorated function + # is here to test the binding capabilities. + def decoratedFunction(self): + pass + + @ReceiverDecorator + def slot(self): + self.called = True + + +class DecoratedSlotTest(unittest.TestCase): + + def testCallingOfDecoratedSlot(self): + obj = TestObject(0) + receiver = Receiver() + obj.staticMethodDouble.connect(receiver.slot) + obj.emitStaticMethodDoubleSignal() + self.assertTrue(receiver.called) + + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside2/tests/pysidetest/delegatecreateseditor_test.py b/sources/pyside2/tests/pysidetest/delegatecreateseditor_test.py new file mode 100644 index 000000000..ec557340a --- /dev/null +++ b/sources/pyside2/tests/pysidetest/delegatecreateseditor_test.py @@ -0,0 +1,83 @@ +#!/usr/bin/python + +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of PySide2. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +import unittest +from helper import UsesQApplication + +from testbinding import TestView +from PySide2.QtCore import Qt +from PySide2.QtWidgets import QAbstractItemDelegate, QComboBox + +id_text = 'This is me' + +class DelegateDoesntKeepReferenceToEditor(QAbstractItemDelegate): + def createEditor(self, parent, option, index): + comboBox = QComboBox(parent) + comboBox.addItem(id_text) + return comboBox + + +class DelegateKeepsReferenceToEditor(QAbstractItemDelegate): + def __init__(self, parent=None): + QAbstractItemDelegate.__init__(self, parent) + self.comboBox = QComboBox() + self.comboBox.addItem(id_text) + + def createEditor(self, parent, option, index): + self.comboBox.setParent(parent) + return self.comboBox + + +class EditorCreatedByDelegateTest(UsesQApplication): + + def testDelegateDoesntKeepReferenceToEditor(self): + view = TestView(None) + delegate = DelegateDoesntKeepReferenceToEditor() + view.setItemDelegate(delegate) + editor = view.getEditorWidgetFromItemDelegate() + self.assertEqual(type(editor), QComboBox) + self.assertEqual(editor.count(), 1) + self.assertEqual(editor.itemData(0, Qt.DisplayRole), id_text) + editor.metaObject() + + def testDelegateKeepsReferenceToEditor(self): + view = TestView(None) + delegate = DelegateKeepsReferenceToEditor() + view.setItemDelegate(delegate) + editor = view.getEditorWidgetFromItemDelegate() + self.assertEqual(type(editor), QComboBox) + self.assertEqual(editor.count(), 1) + self.assertEqual(editor.itemData(0, Qt.DisplayRole), id_text) + editor.metaObject() + + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside2/tests/pysidetest/enum_test.py b/sources/pyside2/tests/pysidetest/enum_test.py new file mode 100644 index 000000000..b3cb4e4d7 --- /dev/null +++ b/sources/pyside2/tests/pysidetest/enum_test.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- + +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of PySide2. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +import unittest +from testbinding import Enum1, TestObjectWithoutNamespace + +class ListConnectionTest(unittest.TestCase): + + def testEnumVisibility(self): + self.assertEqual(Enum1.Option1, 1) + self.assertEqual(Enum1.Option2, 2) + self.assertEqual(TestObjectWithoutNamespace.Enum2.Option3, 3) + self.assertEqual(TestObjectWithoutNamespace.Enum2.Option4, 4) + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside2/tests/pysidetest/hiddenobject.cpp b/sources/pyside2/tests/pysidetest/hiddenobject.cpp new file mode 100644 index 000000000..da6d0434b --- /dev/null +++ b/sources/pyside2/tests/pysidetest/hiddenobject.cpp @@ -0,0 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of PySide2. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "hiddenobject.h" + +void HiddenObject::callMe() +{ + m_called = true; +} + +bool HiddenObject::wasCalled() +{ + return m_called; +} + +QObject* getHiddenObject() +{ + return new HiddenObject(); +} diff --git a/sources/pyside2/tests/pysidetest/hiddenobject.h b/sources/pyside2/tests/pysidetest/hiddenobject.h new file mode 100644 index 000000000..ba96cec9c --- /dev/null +++ b/sources/pyside2/tests/pysidetest/hiddenobject.h @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of PySide2. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef HIDDENOBJECT_H +#define HIDDENOBJECT_H + +#ifdef pysidetest_EXPORTS +#define PYSIDE_EXPORTS 1 +#endif +#include "pysidemacros.h" +#include <QObject> + +// This class shouldn't be exported! +class HiddenObject : public QObject +{ + Q_OBJECT +public: + HiddenObject() : m_called(false) {} + Q_INVOKABLE void callMe(); +public slots: + bool wasCalled(); +private: + bool m_called; +}; + +// Return a instance of HiddenObject +PYSIDE_API QObject* getHiddenObject(); + + +#endif diff --git a/sources/pyside2/tests/pysidetest/homonymoussignalandmethod_test.py b/sources/pyside2/tests/pysidetest/homonymoussignalandmethod_test.py new file mode 100644 index 000000000..6be6245f9 --- /dev/null +++ b/sources/pyside2/tests/pysidetest/homonymoussignalandmethod_test.py @@ -0,0 +1,81 @@ +#!/usr/bin/python + +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of PySide2. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +import unittest +from testbinding import TestObject + +'''Tests the behaviour of homonymous signals and slots.''' + +class HomonymousSignalAndMethodTest(unittest.TestCase): + + def setUp(self): + self.value = 123 + self.called = False + self.obj = TestObject(self.value) + + def tearDown(self): + del self.value + del self.called + del self.obj + + def testIdValueSignalEmission(self): + def callback(idValue): + self.assertEqual(idValue, self.value) + self.obj.idValue.connect(callback) + self.obj.emitIdValueSignal() + + def testStaticMethodDoubleSignalEmission(self): + def callback(): + self.called = True + self.obj.staticMethodDouble.connect(callback) + self.obj.emitStaticMethodDoubleSignal() + self.assertTrue(self.called) + + def testSignalNotCallable(self): + self.assertRaises(TypeError, self.obj.justASignal) + + def testCallingInstanceMethodWithArguments(self): + self.assertRaises(TypeError, TestObject.idValue, 1) + + def testCallingInstanceMethodWithoutArguments(self): + self.assertRaises(TypeError, TestObject.idValue) + + def testHomonymousSignalAndMethod(self): + self.assertEqual(self.obj.idValue(), self.value) + + def testHomonymousSignalAndStaticMethod(self): + self.assertEqual(TestObject.staticMethodDouble(3), 6) + + def testHomonymousSignalAndStaticMethodFromInstance(self): + self.assertEqual(self.obj.staticMethodDouble(4), 8) + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside2/tests/pysidetest/list_signal_test.py b/sources/pyside2/tests/pysidetest/list_signal_test.py new file mode 100644 index 000000000..1a130070e --- /dev/null +++ b/sources/pyside2/tests/pysidetest/list_signal_test.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- + +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of PySide2. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +import unittest +from testbinding import TestObject +from PySide2.QtCore import QObject + +class ListConnectionTest(unittest.TestCase): + + def childrenChanged(self, children): + self._child = children[0] + + def testConnection(self): + o = TestObject(0) + c = QObject() + c.setObjectName("child") + self._child = None + o.childrenChanged.connect(self.childrenChanged) + o.addChild(c) + self.assertEqual(self._child.objectName(), "child") + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside2/tests/pysidetest/mixin_signal_slots_test.py b/sources/pyside2/tests/pysidetest/mixin_signal_slots_test.py new file mode 100644 index 000000000..cdd9ea19a --- /dev/null +++ b/sources/pyside2/tests/pysidetest/mixin_signal_slots_test.py @@ -0,0 +1,216 @@ +#!/usr/bin/python + +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of PySide2. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +''' PYSIDE-315: https://bugreports.qt.io/browse/PYSIDE-315 + Test that all signals and slots of a class (including any mixin classes) + are registered at type parsing time. Also test that the signal and slot + indices do not change after signal connection or emission. ''' + +import unittest +from PySide2 import QtCore + +class Mixin(object): + mixinSignal = QtCore.Signal() + def __init__(self, *args, **kwargs): + super(Mixin,self).__init__(*args, **kwargs) + +class MixinTwo(Mixin): + mixinTwoSignal = QtCore.Signal() + + def __init__(self, *args, **kwargs): + super(MixinTwo,self).__init__(*args, **kwargs) + self.mixinTwoSlotCalled = False + + @QtCore.Slot() + def mixinTwoSlot(self): + self.mixinTwoSlotCalled = True + +class MixinThree(object): + mixinThreeSignal = QtCore.Signal() + + def __init__(self, *args, **kwargs): + super(MixinThree,self).__init__(*args, **kwargs) + self.mixinThreeSlotCalled = False + + @QtCore.Slot() + def mixinThreeSlot(self): + self.mixinThreeSlotCalled = True + +class Derived(Mixin, QtCore.QObject): + derivedSignal = QtCore.Signal(str) + + def __init__(self): + super(Derived,self).__init__() + self.derivedSlotCalled = False + self.derivedSlotString = '' + + @QtCore.Slot(str) + def derivedSlot(self, theString): + self.derivedSlotCalled = True + self.derivedSlotString = theString + +class MultipleDerived(MixinTwo, MixinThree, Mixin, QtCore.QObject): + derivedSignal = QtCore.Signal(str) + + def __init__(self): + super(MultipleDerived,self).__init__() + self.derivedSlotCalled = False + self.derivedSlotString = '' + + @QtCore.Slot(str) + def derivedSlot(self, theString): + self.derivedSlotCalled = True + self.derivedSlotString = theString + + +class MixinTest(unittest.TestCase): + def testMixinSignalSlotRegistration(self): + obj = Derived() + m = obj.metaObject() + + # Should contain 2 signals and 1 slot immediately after type parsing + self.assertEqual(m.methodCount() - m.methodOffset(), 3) + + # Save method indices to check that they do not change + methodIndices = {} + for i in range(m.methodOffset(), m.methodCount()): + signature = m.method(i).methodSignature() + methodIndices[signature] = i + + # Check derivedSignal emission + obj.derivedSignal.connect(obj.derivedSlot) + obj.derivedSignal.emit('emit1') + self.assertTrue(obj.derivedSlotCalled) + obj.derivedSlotCalled = False + + # Check derivedSignal emission after mixingSignal connection + self.outsideSlotCalled = False + @QtCore.Slot() + def outsideSlot(): + self.outsideSlotCalled = True + + obj.mixinSignal.connect(outsideSlot) + obj.derivedSignal.emit('emit2') + self.assertTrue(obj.derivedSlotCalled) + self.assertFalse(self.outsideSlotCalled) + obj.derivedSlotCalled = False + + # Check mixinSignal emission + obj.mixinSignal.emit() + self.assertTrue(self.outsideSlotCalled) + self.assertFalse(obj.derivedSlotCalled) + self.outsideSlotCalled = False + + # Check that method indices haven't changed. + # Make sure to requery for the meta object, to check that a new one was not + # created as a child of the old one. + m = obj.metaObject() + self.assertEqual(m.methodCount() - m.methodOffset(), 3) + for i in range(m.methodOffset(), m.methodCount()): + signature = m.method(i).methodSignature() + self.assertEqual(methodIndices[signature], i) + + + def testMixinSignalSlotRegistrationWithMultipleInheritance(self): + obj = MultipleDerived() + m = obj.metaObject() + + # Should contain 4 signals and 3 slots immediately after type parsing + self.assertEqual(m.methodCount() - m.methodOffset(), 7) + + # Save method indices to check that they do not change + methodIndices = {} + for i in range(m.methodOffset(), m.methodCount()): + signature = m.method(i).methodSignature() + methodIndices[signature] = i + + # Check derivedSignal emission + obj.derivedSignal.connect(obj.derivedSlot) + obj.derivedSignal.emit('emit1') + self.assertTrue(obj.derivedSlotCalled) + self.assertFalse(obj.mixinTwoSlotCalled) + self.assertFalse(obj.mixinThreeSlotCalled) + obj.derivedSlotCalled = False + + # Check derivedSignal emission after mixinThreeSignal connection + self.outsideSlotCalled = False + @QtCore.Slot() + def outsideSlot(): + self.outsideSlotCalled = True + + obj.mixinThreeSignal.connect(obj.mixinThreeSlot) + obj.mixinThreeSignal.connect(outsideSlot) + obj.derivedSignal.emit('emit2') + self.assertTrue(obj.derivedSlotCalled) + self.assertFalse(obj.mixinTwoSlotCalled) + self.assertFalse(obj.mixinThreeSlotCalled) + self.assertFalse(self.outsideSlotCalled) + obj.derivedSlotCalled = False + + # Check mixinThreeSignal emission + obj.mixinThreeSignal.emit() + self.assertTrue(self.outsideSlotCalled) + self.assertTrue(obj.mixinThreeSlotCalled) + self.assertFalse(obj.derivedSlotCalled) + self.assertFalse(obj.mixinTwoSlotCalled) + self.outsideSlotCalled = False + obj.mixinThreeSlotCalled = False + + # Check mixinTwoSignal emission + obj.mixinTwoSignal.connect(obj.mixinTwoSlot) + obj.mixinTwoSignal.emit() + self.assertTrue(obj.mixinTwoSlotCalled) + self.assertFalse(obj.mixinThreeSlotCalled) + self.assertFalse(obj.derivedSlotCalled) + self.assertFalse(self.outsideSlotCalled) + obj.mixinTwoSlotCalled = False + + # Check mixinSignal emission + obj.mixinSignal.connect(outsideSlot) + obj.mixinSignal.emit() + self.assertTrue(self.outsideSlotCalled) + self.assertFalse(obj.mixinTwoSlotCalled) + self.assertFalse(obj.mixinThreeSlotCalled) + self.assertFalse(obj.derivedSlotCalled) + self.outsideSlotCalled = False + + # Check that method indices haven't changed. + # Make sure to requery for the meta object, to check that a new one was not + # created as a child of the old one. + m = obj.metaObject() + self.assertEqual(m.methodCount() - m.methodOffset(), 7) + for i in range(m.methodOffset(), m.methodCount()): + signature = m.method(i).methodSignature() + self.assertEqual(methodIndices[signature], i) + + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside2/tests/pysidetest/modelview_test.py b/sources/pyside2/tests/pysidetest/modelview_test.py new file mode 100644 index 000000000..3a02946dc --- /dev/null +++ b/sources/pyside2/tests/pysidetest/modelview_test.py @@ -0,0 +1,99 @@ +#!/usr/bin/python + +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of PySide2. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +import unittest +import py3kcompat as py3k +from testbinding import TestView +from PySide2.QtCore import QAbstractListModel, QObject, QModelIndex + +'''Tests model/view relationship.''' + +object_name = 'test object' + +class MyObject(QObject): + pass + +class ListModelKeepsReference(QAbstractListModel): + def __init__(self, parent=None): + QAbstractListModel.__init__(self, parent) + self.obj = MyObject() + self.obj.setObjectName(object_name) + + def rowCount(self, parent=QModelIndex()): + return 1 + + def data(self, index, role): + return self.obj + +class ListModelDoesntKeepsReference(QAbstractListModel): + def rowCount(self, parent=QModelIndex()): + return 1 + + def data(self, index, role): + obj = MyObject() + obj.setObjectName(object_name) + return obj + +class ListModelThatReturnsString(QAbstractListModel): + def rowCount(self, parent=QModelIndex()): + return 1 + + def data(self, index, role): + self.obj = 'string' + return self.obj + + +class ModelViewTest(unittest.TestCase): + + def testListModelDoesntKeepsReference(self): + model = ListModelDoesntKeepsReference() + view = TestView(model) + obj = view.getData() + self.assertEqual(type(obj), MyObject) + self.assertEqual(obj.objectName(), object_name) + obj.metaObject() + + def testListModelKeepsReference(self): + model = ListModelKeepsReference() + view = TestView(model) + obj = view.getData() + self.assertEqual(type(obj), MyObject) + self.assertEqual(obj.objectName(), object_name) + + def testListModelThatReturnsString(self): + model = ListModelThatReturnsString() + view = TestView(model) + obj = view.getData() + self.assertEqual(type(obj), py3k.unicode) + self.assertEqual(obj, 'string') + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside2/tests/pysidetest/new_inherited_functions_test.py b/sources/pyside2/tests/pysidetest/new_inherited_functions_test.py new file mode 100644 index 000000000..bd5db7661 --- /dev/null +++ b/sources/pyside2/tests/pysidetest/new_inherited_functions_test.py @@ -0,0 +1,215 @@ +############################################################################# +## +## Copyright (C) 2017 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of PySide2. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions(). For further +## information use the contact form at https://www.qt.io/contact-us(). +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3().0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +from __future__ import print_function + +import sys +import os +import unittest + +import PySide2.QtCore + +# This test tests the existence and callability of the newly existing functions, +# after the inheritance was made complete in the course of PYSIDE-331. + +def warn_essential(modname): + print(80 * "*") + print("*** Warning: '{}' is an essential module! Are you sure to skip it?" + .format(modname)) + print(80 * "*") + +new_functions = """ + PySide2.QtCore.QAbstractItemModel().parent() + PySide2.QtCore.QAbstractListModel().parent() + PySide2.QtCore.QAbstractTableModel().parent() + PySide2.QtCore.QFile().resize(qint64) + m = PySide2.QtCore.QMutex(); m.tryLock(); m.unlock() # prevent a message "QMutex: destroying locked mutex" + PySide2.QtCore.QSortFilterProxyModel().parent() + PySide2.QtCore.QTemporaryFile(tfarg).open(openMode) +""" +try: + modname = "PySide2.QtGui" + exec("import " + modname) + new_functions += """ + PySide2.QtGui.QBitmap().transformed(qMatrix,transformationMode) + PySide2.QtGui.QStandardItemModel().insertColumn(int,qModelIndex) + PySide2.QtGui.QStandardItemModel().parent() + # PySide2.QtGui.QTextList(qTextDocument).setFormat(qTextFormat) # Segmentation fault: 11 + # PySide2.QtGui.QTextTable(qTextDocument).setFormat(qTextFormat) # Segmentation fault: 11 + """ +except ImportError: + warn_essential(modname) +try: + modname = "PySide2.QtWidgets" + exec("import " + modname) + new_functions += """ + PySide2.QtWidgets.QAbstractItemView().update() + PySide2.QtWidgets.QApplication.palette() + PySide2.QtWidgets.QApplication.setFont(qFont) + PySide2.QtWidgets.QApplication.setPalette(qPalette) + PySide2.QtWidgets.QBoxLayout(direction).addWidget(qWidget) + PySide2.QtWidgets.QColorDialog().open() + PySide2.QtWidgets.QDirModel().index(int,int,qModelIndex) + PySide2.QtWidgets.QDirModel().parent() + PySide2.QtWidgets.QFileDialog().open() + PySide2.QtWidgets.QFileSystemModel().index(int,int,qModelIndex) + PySide2.QtWidgets.QFileSystemModel().parent() + PySide2.QtWidgets.QFontDialog().open() + PySide2.QtWidgets.QGestureEvent([]).accept() + PySide2.QtWidgets.QGestureEvent([]).ignore() + PySide2.QtWidgets.QGestureEvent([]).isAccepted() + PySide2.QtWidgets.QGestureEvent([]).setAccepted(bool) + # PySide2.QtWidgets.QGraphicsView().render(qPaintDevice,qPoint,qRegion,renderFlags) # QPaintDevice: NotImplementedError + PySide2.QtWidgets.QGridLayout().addWidget(qWidget) + PySide2.QtWidgets.QHeaderView(orientation).initStyleOption(qStyleOptionFrame) + PySide2.QtWidgets.QInputDialog().open() + PySide2.QtWidgets.QLineEdit().addAction(qAction) + PySide2.QtWidgets.QListWidget().closePersistentEditor(qModelIndex) + PySide2.QtWidgets.QListWidget().openPersistentEditor(qModelIndex) + PySide2.QtWidgets.QMessageBox().open() + PySide2.QtWidgets.QPlainTextEdit.find(quintptr) + PySide2.QtWidgets.QProgressDialog().open() + PySide2.QtWidgets.QStackedLayout().widget() + # PySide2.QtWidgets.QStylePainter().begin(qPaintDevice) # QPaintDevice: NotImplementedError + PySide2.QtWidgets.QTableWidget().closePersistentEditor(qModelIndex) + PySide2.QtWidgets.QTableWidget().openPersistentEditor(qModelIndex) + PySide2.QtWidgets.QTextEdit.find(quintptr) + PySide2.QtWidgets.QTreeWidget().closePersistentEditor(qModelIndex) + PySide2.QtWidgets.QTreeWidget().openPersistentEditor(qModelIndex) + """ +except ImportError: + warn_essential(modname) +try: + modname = "PySide2.QtPrintSupport" + exec("import " + modname) + new_functions += """ + # PySide2.QtPrintSupport.QPageSetupDialog().open() # Segmentation fault: 11 + # PySide2.QtPrintSupport.QPrintDialog().open() # opens the dialog, but works + PySide2.QtPrintSupport.QPrintDialog().printer() + PySide2.QtPrintSupport.QPrintPreviewDialog().open() # note: this prints something, but really shouldn't ;-) + """ +except ImportError: + warn_essential(modname) +try: + import PySide2.QtHelp + new_functions += """ + PySide2.QtHelp.QHelpContentModel().parent() + # PySide2.QtHelp.QHelpIndexModel().createIndex(int,int,quintptr) # returned NULL without setting an error + # PySide2.QtHelp.QHelpIndexModel().createIndex(int,int,object()) # returned NULL without setting an error + """ +except ImportError: + pass +try: + import PySide2.QtQuick + new_functions += """ + PySide2.QtQuick.QQuickPaintedItem().update() + """ +except ImportError: + pass + + +class MainTest(unittest.TestCase): + + def testNewInheriedFunctionsExist(self): + """ + Run all new method signarures + """ + for app in "QtWidgets.QApplication", "QtGui.QGuiApplication", "QtCore.QCoreApplication": + try: + exec("qApp = PySide2.{0}([]) or PySide2.{0}.instance()".format(app)) + break + except AttributeError: + continue + bool = True + int = 42 + qint64 = 42 + tfarg = os.path.join(PySide2.QtCore.QDir.tempPath(), "XXXXXX.tmp") + orientation = PySide2.QtCore.Qt.Orientation() + openMode = PySide2.QtCore.QIODevice.OpenMode(PySide2.QtCore.QIODevice.ReadOnly) + qModelIndex = PySide2.QtCore.QModelIndex() + transformationMode = PySide2.QtCore.Qt.TransformationMode() + qObject = PySide2.QtCore.QObject() + qPoint = PySide2.QtCore.QPoint() + try: + PySide2.QtGui + #qPaintDevice = PySide2.QtGui.QPaintDevice() # NotImplementedError + qMatrix = PySide2.QtGui.QMatrix() + qTextDocument = PySide2.QtGui.QTextDocument() + qTextFormat = PySide2.QtGui.QTextFormat() + quintptr = long(42) if sys.version_info[0] < 3 else 42 + qFont = PySide2.QtGui.QFont() + qPalette = PySide2.QtGui.QPalette() + except AttributeError: + pass + try: + PySide2.QtWidgets + direction = PySide2.QtWidgets.QBoxLayout.Direction() + qWidget = PySide2.QtWidgets.QWidget() + qStyleOptionFrame = PySide2.QtWidgets.QStyleOptionFrame() + qAction = PySide2.QtWidgets.QAction(qObject) + renderFlags = PySide2.QtWidgets.QWidget.RenderFlags + except AttributeError: + pass + + for func in new_functions.splitlines(): + func = func.strip() + if func.startswith("#"): + # this is a crashing or otherwise untestable function + print(func) + continue + try: + exec(func) + except NotImplementedError: + print(func, "# raises NotImplementedError") + else: + print(func) + + def testQAppSignatures(self): + """ + Verify that qApp.palette owns three signatures, especially + palette() without argument. + """ + try: + qApp = (PySide2.QtWidgets.QApplication.instance() or + PySide2.QtWidgets.QApplication([])) + except AttributeError: + unittest.TestCase().skipTest("this test makes only sense if QtWidgets is available.") + try: + PySide2.QtWidgets.QApplication.palette(42) # raises + except TypeError as e: + lines = e.args[0].splitlines() + heading_pos = lines.index("Supported signatures:") + lines = lines[heading_pos+1:] + self.assertEqual(len(lines), 3) + txt = '\n'.join(lines) + print("Signatures found:") + print(txt) + self.assertTrue("palette()" in txt) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside2/tests/pysidetest/notify_id.py b/sources/pyside2/tests/pysidetest/notify_id.py new file mode 100644 index 000000000..09226e6e2 --- /dev/null +++ b/sources/pyside2/tests/pysidetest/notify_id.py @@ -0,0 +1,76 @@ +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of PySide2. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +import unittest +from PySide2.QtCore import QObject, Signal, Property, Slot + +'''Tests that the signal notify id of a property is correct, aka corresponds to the initially set +notify method.''' + +class Foo(QObject): + def __init__(self): + QObject.__init__(self) + self._prop = "Empty" + + def getProp(self): + return self._prop + + def setProp(self, value): + if value != self._prop: + self._prop = value + self.propChanged.emit() + + # Inside the dynamic QMetaObject, the methods have to be sorted, so that this slot comes + # after any signals. That means the property notify id has to be updated, to have the correct + # relative method id. + @Slot() + def randomSlot(): + pass + + propChanged = Signal() + prop = Property(str, getProp, setProp, notify=propChanged) + +class NotifyIdSignal(unittest.TestCase): + def setUp(self): + self.obj = Foo() + + def tearDown(self): + del self.obj + + def testSignalEmission(self): + metaObject = self.obj.metaObject() + propertyIndex = metaObject.indexOfProperty("prop") + property = metaObject.property(propertyIndex) + + signalIndex = property.notifySignalIndex() + signal = metaObject.method(signalIndex) + signalName = signal.name() + self.assertEqual(signalName, "propChanged") + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside2/tests/pysidetest/pysidetest_global.h b/sources/pyside2/tests/pysidetest/pysidetest_global.h new file mode 100644 index 000000000..9fc1828e1 --- /dev/null +++ b/sources/pyside2/tests/pysidetest/pysidetest_global.h @@ -0,0 +1,34 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of PySide2. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// PySide global.h file +#include "pyside2_global.h" +#include "testobject.h" +#include "testview.h" +#define PYSIDE_API +#include "hiddenobject.h" diff --git a/sources/pyside2/tests/pysidetest/qvariant_test.py b/sources/pyside2/tests/pysidetest/qvariant_test.py new file mode 100644 index 000000000..46c9ddbda --- /dev/null +++ b/sources/pyside2/tests/pysidetest/qvariant_test.py @@ -0,0 +1,45 @@ +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of PySide2. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +import unittest + +from testbinding import TestObject +from PySide2.QtCore import Qt +from PySide2.QtGui import QKeySequence + +from helper import UsesQApplication + +class QVariantTest(UsesQApplication): + + def testQKeySequenceQVariantOperator(self): + # bug #775 + ks = QKeySequence(Qt.SHIFT, Qt.CTRL, Qt.Key_P, Qt.Key_R) + self.assertEqual(TestObject.checkType(ks), 75) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside2/tests/pysidetest/signal_slot_warning.py b/sources/pyside2/tests/pysidetest/signal_slot_warning.py new file mode 100644 index 000000000..fd3d41b52 --- /dev/null +++ b/sources/pyside2/tests/pysidetest/signal_slot_warning.py @@ -0,0 +1,70 @@ +#!/usr/bin/python + +############################################################################# +## +## Copyright (C) 2017 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of PySide2. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +''' PYSIDE-315: https://bugreports.qt.io/browse/PYSIDE-315 + Test that creating a signal in the wrong order triggers a warning. ''' + +from __future__ import print_function + +import unittest +import PySide2.QtCore as QtCore +import sys +import warnings + + +class Whatever(QtCore.QObject): + echoSignal = QtCore.Signal(str) + + def __init__(self): + super(Whatever, self).__init__() + self.echoSignal.connect(self.mySlot) + + def mySlot(self, v): + pass + +class WarningTest(unittest.TestCase): + def testSignalSlotWarning(self): + # we create an object. This gives no warning. + obj = Whatever() + # then we insert a signal after slots have been created. + setattr(Whatever, "foo", QtCore.Signal()) + with warnings.catch_warnings(record=True) as w: + # Cause all warnings to always be triggered. + warnings.simplefilter("always") + # Trigger a warning. + obj.foo.connect(obj.mySlot) + # Verify some things + assert issubclass(w[-1].category, RuntimeWarning) + assert "*** Sort Warning ***" in str(w[-1].message) + # note that this warning cannot be turned into an error (too hard) + + +if __name__ == "__main__": + unittest.main() diff --git a/sources/pyside2/tests/pysidetest/signalandnamespace_test.py b/sources/pyside2/tests/pysidetest/signalandnamespace_test.py new file mode 100644 index 000000000..846e5b2b9 --- /dev/null +++ b/sources/pyside2/tests/pysidetest/signalandnamespace_test.py @@ -0,0 +1,120 @@ +#!/usr/bin/python + +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of PySide2. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +import unittest +from testbinding import PySideCPP, TestObjectWithoutNamespace + +class ModelViewTest(unittest.TestCase): + + def callback(self, o): + self._called = o + + def testWithoutNamespace(self): + self._called = None + o = PySideCPP.TestObjectWithNamespace(None) + o.emitSignal.connect(self.callback) + o.emitSignal.emit(o) + self.assertTrue(o == self._called) + + self._called = None + o = PySideCPP.TestObjectWithNamespace(None) + o.emitSignal.connect(self.callback) + o.callSignal(o) + self.assertTrue(o == self._called) + + def testWithNamespace(self): + self._called = None + o = PySideCPP.TestObjectWithNamespace(None) + o.emitSignalWithNamespace.connect(self.callback) + o.emitSignalWithNamespace.emit(o) + self.assertTrue(o == self._called) + + self._called = None + o = PySideCPP.TestObjectWithNamespace(None) + o.emitSignalWithNamespace.connect(self.callback) + o.callSignalWithNamespace(o) + self.assertTrue(o == self._called) + + + def testWithoutNamespace1(self): + self._called = None + o = TestObjectWithoutNamespace(None) + o.emitSignal.connect(self.callback) + o.emitSignal.emit(o) + self.assertTrue(o == self._called) + + self._called = None + o = TestObjectWithoutNamespace(None) + o.emitSignal.connect(self.callback) + o.callSignal(o) + self.assertTrue(o == self._called) + + def testWithNamespace1(self): + self._called = None + o = TestObjectWithoutNamespace(None) + o.emitSignalWithNamespace.connect(self.callback) + o.emitSignalWithNamespace.emit(o) + self.assertTrue(o == self._called) + + self._called = None + o = TestObjectWithoutNamespace(None) + o.emitSignalWithNamespace.connect(self.callback) + o.callSignalWithNamespace(o) + self.assertTrue(o == self._called) + + def testTypedfWithouNamespace(self): + self._called = None + o = PySideCPP.TestObjectWithNamespace(None) + o.emitSignalWithTypedef.connect(self.callback) + o.emitSignalWithTypedef.emit(10) + self.assertEqual(10, self._called) + + self._called = None + o = PySideCPP.TestObjectWithNamespace(None) + o.emitSignalWithTypedef.connect(self.callback) + o.callSignalWithTypedef(10) + self.assertEqual(10, self._called) + + def testTypedefWithNamespace(self): + self._called = None + o = TestObjectWithoutNamespace(None) + o.emitSignalWithTypedef.connect(self.callback) + o.emitSignalWithTypedef.emit(10) + self.assertEqual(10, self._called) + + self._called = None + o = TestObjectWithoutNamespace(None) + o.emitSignalWithTypedef.connect(self.callback) + o.callSignalWithTypedef(10) + self.assertEqual(10, self._called) + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside2/tests/pysidetest/signalemissionfrompython_test.py b/sources/pyside2/tests/pysidetest/signalemissionfrompython_test.py new file mode 100644 index 000000000..1bd08c071 --- /dev/null +++ b/sources/pyside2/tests/pysidetest/signalemissionfrompython_test.py @@ -0,0 +1,107 @@ +#!/usr/bin/python + +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of PySide2. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +import unittest +from testbinding import TestObject +from PySide2.QtCore import QObject, SIGNAL + +'''Tests the behaviour of signals with default values when emitted from Python.''' + +class SignalEmissionFromPython(unittest.TestCase): + + def setUp(self): + self.obj1 = TestObject(0) + self.obj2 = TestObject(0) + self.one_called = 0 + self.two_called = 0 + + def tearDown(self): + del self.obj1 + del self.obj2 + del self.one_called + del self.two_called + + def testConnectNewStyleEmitVoidSignal(self): + def callbackOne(): + self.one_called += 1 + self.obj2.signalWithDefaultValue.emit() + def callbackTwo(): + self.two_called += 1 + self.obj1.signalWithDefaultValue.connect(callbackOne) + self.obj2.signalWithDefaultValue.connect(callbackTwo) + self.obj1.emitSignalWithDefaultValue_void() + self.obj2.emitSignalWithDefaultValue_void() + self.assertEqual(self.one_called, 1) + self.assertEqual(self.two_called, 2) + + def testConnectOldStyleEmitVoidSignal(self): + def callbackOne(): + self.one_called += 1 + self.obj2.signalWithDefaultValue.emit() + def callbackTwo(): + self.two_called += 1 + QObject.connect(self.obj1, SIGNAL('signalWithDefaultValue()'), callbackOne) + QObject.connect(self.obj2, SIGNAL('signalWithDefaultValue()'), callbackTwo) + self.obj1.emitSignalWithDefaultValue_void() + self.obj2.emitSignalWithDefaultValue_void() + self.assertEqual(self.one_called, 1) + self.assertEqual(self.two_called, 2) + + def testConnectNewStyleEmitBoolSignal(self): + def callbackOne(): + self.one_called += 1 + self.obj2.signalWithDefaultValue[bool].emit(True) + def callbackTwo(): + self.two_called += 1 + self.obj1.signalWithDefaultValue.connect(callbackOne) + self.obj2.signalWithDefaultValue.connect(callbackTwo) + self.obj1.emitSignalWithDefaultValue_void() + self.obj2.emitSignalWithDefaultValue_void() + self.assertEqual(self.one_called, 1) + self.assertEqual(self.two_called, 2) + + def testConnectOldStyleEmitBoolSignal(self): + def callbackOne(): + self.one_called += 1 + self.obj2.signalWithDefaultValue[bool].emit(True) + def callbackTwo(): + self.two_called += 1 + QObject.connect(self.obj1, SIGNAL('signalWithDefaultValue()'), callbackOne) + QObject.connect(self.obj2, SIGNAL('signalWithDefaultValue()'), callbackTwo) + self.obj1.emitSignalWithDefaultValue_void() + self.obj2.emitSignalWithDefaultValue_void() + self.assertEqual(self.one_called, 1) + self.assertEqual(self.two_called, 2) + + + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside2/tests/pysidetest/signalwithdefaultvalue_test.py b/sources/pyside2/tests/pysidetest/signalwithdefaultvalue_test.py new file mode 100644 index 000000000..8014d4879 --- /dev/null +++ b/sources/pyside2/tests/pysidetest/signalwithdefaultvalue_test.py @@ -0,0 +1,95 @@ +#!/usr/bin/python + +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of PySide2. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +import unittest +from testbinding import TestObject +from PySide2.QtCore import QObject, SIGNAL + +'''Tests the behaviour of signals with default values.''' + +class SignalWithDefaultValueTest(unittest.TestCase): + + def setUp(self): + self.obj = TestObject(0) + self.void_called = False + self.bool_called = False + + def tearDown(self): + del self.obj + del self.void_called + del self.bool_called + + def testConnectNewStyleEmitVoidSignal(self): + def callbackVoid(): + self.void_called = True + def callbackBool(value): + self.bool_called = True + self.obj.signalWithDefaultValue.connect(callbackVoid) + self.obj.signalWithDefaultValue[bool].connect(callbackBool) + self.obj.emitSignalWithDefaultValue_void() + self.assertTrue(self.void_called) + self.assertTrue(self.bool_called) + + def testConnectNewStyleEmitBoolSignal(self): + def callbackVoid(): + self.void_called = True + def callbackBool(value): + self.bool_called = True + self.obj.signalWithDefaultValue.connect(callbackVoid) + self.obj.signalWithDefaultValue[bool].connect(callbackBool) + self.obj.emitSignalWithDefaultValue_bool() + self.assertTrue(self.void_called) + self.assertTrue(self.bool_called) + + def testConnectOldStyleEmitVoidSignal(self): + def callbackVoid(): + self.void_called = True + def callbackBool(value): + self.bool_called = True + QObject.connect(self.obj, SIGNAL('signalWithDefaultValue()'), callbackVoid) + QObject.connect(self.obj, SIGNAL('signalWithDefaultValue(bool)'), callbackBool) + self.obj.emitSignalWithDefaultValue_void() + self.assertTrue(self.void_called) + self.assertTrue(self.bool_called) + + def testConnectOldStyleEmitBoolSignal(self): + def callbackVoid(): + self.void_called = True + def callbackBool(value): + self.bool_called = True + QObject.connect(self.obj, SIGNAL('signalWithDefaultValue()'), callbackVoid) + QObject.connect(self.obj, SIGNAL('signalWithDefaultValue(bool)'), callbackBool) + self.obj.emitSignalWithDefaultValue_bool() + self.assertTrue(self.void_called) + self.assertTrue(self.bool_called) + +if __name__ == '__main__': + unittest.main() + diff --git a/sources/pyside2/tests/pysidetest/symbols.filter b/sources/pyside2/tests/pysidetest/symbols.filter new file mode 100644 index 000000000..af6c744dd --- /dev/null +++ b/sources/pyside2/tests/pysidetest/symbols.filter @@ -0,0 +1,7 @@ +{ +local: +_ZSt*; +_ZNSt*; +_ZNSs*; +_ZNKSt*; +}; diff --git a/sources/pyside2/tests/pysidetest/testobject.cpp b/sources/pyside2/tests/pysidetest/testobject.cpp new file mode 100644 index 000000000..4fe98461c --- /dev/null +++ b/sources/pyside2/tests/pysidetest/testobject.cpp @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of PySide2. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "testobject.h" + +void TestObject::emitIdValueSignal() +{ + emit idValue(m_idValue); +} + +void TestObject::emitStaticMethodDoubleSignal() +{ + emit staticMethodDouble(); +} + +void TestObject::emitSignalWithDefaultValue_void() +{ + emit signalWithDefaultValue(); +} + +void TestObject::emitSignalWithDefaultValue_bool() +{ + emit signalWithDefaultValue(true); +} + +void TestObject::emitSignalWithTypedefValue(int value) +{ + emit signalWithTypedefValue(TypedefValue(value)); +} diff --git a/sources/pyside2/tests/pysidetest/testobject.h b/sources/pyside2/tests/pysidetest/testobject.h new file mode 100644 index 000000000..7e1f46250 --- /dev/null +++ b/sources/pyside2/tests/pysidetest/testobject.h @@ -0,0 +1,140 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of PySide2. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TESTOBJECT_H +#define TESTOBJECT_H + +#include <QObject> +#include <QApplication> +#include <QMetaType> +#include <QVariant> +#ifdef pysidetest_EXPORTS +#define PYSIDE_EXPORTS 1 +#endif +#include "pysidemacros.h" + +class IntValue +{ +public: + + IntValue(int val): value(val){}; + IntValue() : value(0) {}; + int value; +}; + +typedef IntValue TypedefValue; + +class PYSIDE_API TestObject : public QObject +{ + Q_OBJECT +public: + static void createApp() { int argc=0; new QApplication(argc, 0); }; + static int checkType(const QVariant& var) { return (int)var.type(); } + + TestObject(int idValue, QObject* parent = 0) : QObject(parent), m_idValue(idValue) {} + int idValue() const { return m_idValue; } + static int staticMethodDouble(int value) { return value * 2; } + void addChild(QObject* c) { m_children.append(c); emit childrenChanged(m_children); } + + void emitIdValueSignal(); + void emitStaticMethodDoubleSignal(); + + void emitSignalWithDefaultValue_void(); + void emitSignalWithDefaultValue_bool(); + + void emitSignalWithTypedefValue(int value); + +signals: + void idValue(int newValue); + void justASignal(); + void staticMethodDouble(); + void childrenChanged(const QList<QObject*>&); + void signalWithDefaultValue(bool value = false); + void signalWithTypedefValue(TypedefValue value); + +private: + int m_idValue; + QList<QObject*> m_children; +}; + + +typedef int PySideInt; + + +namespace PySideCPP { + +class PYSIDE_API TestObjectWithNamespace : public QObject +{ + Q_OBJECT +public: + TestObjectWithNamespace(QObject* parent) : QObject(parent) {} + QString name() { return "TestObjectWithNamespace"; } + + void callSignal(TestObjectWithNamespace* obj) { emitSignal(obj); } + void callSignalWithNamespace(TestObjectWithNamespace* obj) { emitSignalWithNamespace(obj); } + void callSignalWithTypedef(int val) { emitSignalWithTypedef(val); } + +signals: + void emitSignal(TestObjectWithNamespace* obj); + void emitSignalWithNamespace(PySideCPP::TestObjectWithNamespace* obj); + void emitSignalWithTypedef(PySideInt val); +}; + + +} // Namespace PySideCPP + +namespace PySideCPP2 { + +enum Enum1 { Option1 = 1, Option2 = 2 }; + + +typedef long PySideLong; + +class PYSIDE_API TestObjectWithoutNamespace : public QObject +{ + Q_OBJECT +public: + enum Enum2 { Option3 = 3, Option4 = 4}; + TestObjectWithoutNamespace(QObject* parent) : QObject(parent) {} + QString name() { return "TestObjectWithoutNamespace"; } + + void callSignal(TestObjectWithoutNamespace* obj) { emitSignal(obj); } + void callSignalWithNamespace(TestObjectWithoutNamespace* obj) { emitSignalWithNamespace(obj); } + void callSignalWithTypedef(long val) { emitSignalWithTypedef(val); } + +signals: + void emitSignal(TestObjectWithoutNamespace* obj); + void emitSignalWithNamespace(PySideCPP2::TestObjectWithoutNamespace* obj); + void emitSignalWithTypedef(PySideLong val); +}; + + +} // Namespace PySideCPP2 + +#endif // TESTOBJECT_H + diff --git a/sources/pyside2/tests/pysidetest/testview.cpp b/sources/pyside2/tests/pysidetest/testview.cpp new file mode 100644 index 000000000..b974f1fc7 --- /dev/null +++ b/sources/pyside2/tests/pysidetest/testview.cpp @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of PySide2. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "testview.h" + +#include <QDebug> +#include <QWidget> +#include <QAbstractListModel> +#include <QAbstractItemDelegate> + +QVariant +TestView::getData() +{ + QModelIndex index; + return m_model->data(index); +} + +QWidget* +TestView::getEditorWidgetFromItemDelegate() const +{ + if (!m_delegate) + return 0; + + QModelIndex index; + QStyleOptionViewItem options; + return m_delegate->createEditor(0, options, index); +} diff --git a/sources/pyside2/tests/pysidetest/testview.h b/sources/pyside2/tests/pysidetest/testview.h new file mode 100644 index 000000000..22caab59f --- /dev/null +++ b/sources/pyside2/tests/pysidetest/testview.h @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of PySide2. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TESTVIEW_H +#define TESTVIEW_H + +#include <QObject> +#ifdef pysidetest_EXPORTS +#define PYSIDE_EXPORTS 1 +#endif +#include "pysidemacros.h" + +QT_BEGIN_NAMESPACE +class QWidget; +class QAbstractListModel; +class QAbstractItemDelegate; +QT_END_NAMESPACE + +class PYSIDE_API TestView : public QObject +{ + Q_OBJECT +public: + TestView(QAbstractListModel* model, QObject* parent = 0) : QObject(parent), m_model(model) {} + QAbstractListModel* model() { return m_model; } + QVariant getData(); + + void setItemDelegate(QAbstractItemDelegate* delegate) { m_delegate = delegate; } + QWidget* getEditorWidgetFromItemDelegate() const; + +private: + QAbstractListModel* m_model; + QAbstractItemDelegate* m_delegate; +}; + +#endif // TESTVIEW_H + diff --git a/sources/pyside2/tests/pysidetest/typedef_signal_test.py b/sources/pyside2/tests/pysidetest/typedef_signal_test.py new file mode 100644 index 000000000..7f2f47344 --- /dev/null +++ b/sources/pyside2/tests/pysidetest/typedef_signal_test.py @@ -0,0 +1,54 @@ +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of PySide2. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +import unittest + +from PySide2.QtCore import QObject +from testbinding import TestObject + +class Receiver(QObject): + + def __init__(self): + QObject.__init__(self) + self.received = None + + def slot(self, value): + self.received = value + +class TypedefSignal(unittest.TestCase): + + def testTypedef(self): + obj = TestObject(0) + receiver = Receiver() + + obj.signalWithTypedefValue.connect(receiver.slot) + obj.emitSignalWithTypedefValue(2) + self.assertEqual(receiver.received.value, 2) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside2/tests/pysidetest/typesystem_pysidetest.xml b/sources/pyside2/tests/pysidetest/typesystem_pysidetest.xml new file mode 100644 index 000000000..4053b7b77 --- /dev/null +++ b/sources/pyside2/tests/pysidetest/typesystem_pysidetest.xml @@ -0,0 +1,64 @@ +<?xml version="1.0"?> +<typesystem package="testbinding"> + <load-typesystem name="typesystem_core.xml" generate="no" /> + <value-type name="IntValue"/> + <primitive-type name="TypedefValue"> + <!-- + A conversion rule is used here because ApiExtractor can't associate + a primitive typedef to a non-primitive type. That would be a good + improvement to ApiExtractor. + --> + <conversion-rule> + <native-to-target> + return %CONVERTTOPYTHON[IntValue](%in); + </native-to-target> + <target-to-native> + <add-conversion type="IntValue"> + IntValue value = %CONVERTTOCPP[IntValue](%in); + %out = %OUTTYPE(value); + </add-conversion> + </target-to-native> + </conversion-rule> + </primitive-type> + <object-type name="TestObject" /> + + <primitive-type name="PySideInt"/> + <primitive-type name="PySideCPP2::PySideLong"/> + <!--<primitive-type name="PySideLong"/>--> + + <function signature="getHiddenObject()" /> + + <inject-code position="end"> + Shiboken::Conversions::registerConverterName(Shiboken::Conversions::PrimitiveTypeConverter<long>(), "PySideLong"); + Shiboken::Conversions::registerConverterName(Shiboken::Conversions::PrimitiveTypeConverter<long>(), "PySideCPP2::PySideLong"); + qRegisterMetaType<PySideInt>("PySideInt"); + qRegisterMetaType<PySideCPP2::PySideLong>("PySideLong"); + </inject-code> + + <namespace-type name="PySideCPP"> + <object-type name="TestObjectWithNamespace"/> + </namespace-type> + + <namespace-type name="PySideCPP2" generate="no"> + <enum-type name="Enum1" /> + <object-type name="TestObjectWithoutNamespace"> + <enum-type name="Enum2" /> + </object-type> + </namespace-type> + + <object-type name="TestView" > + <modify-function signature="TestView(QAbstractListModel*,QObject*)"> + <modify-argument index="1"> + <reference-count action="set"/> + </modify-argument> + </modify-function> + </object-type> + <suppress-warning text="type 'QPyTextObject' is specified in typesystem, but not defined. This could potentially lead to compilation errors." /> + <!-- Qt5: I never really understood this warning. Probably it is because there + is no way to instantiate the class. Anyway, why must this class emit this warning? + I am not a C++ warrior, so I'd prefer if it would say "it is ok if you see this warning!". + Well, maybe somebody will enlighten me, and I'll change this comment. + I'd actually prefer an implementation that avoids generating this message, but I still failed + doing so :-( + --> +</typesystem> diff --git a/sources/pyside2/tests/pysidetest/utils_test.py b/sources/pyside2/tests/pysidetest/utils_test.py new file mode 100644 index 000000000..30f283312 --- /dev/null +++ b/sources/pyside2/tests/pysidetest/utils_test.py @@ -0,0 +1,51 @@ +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of PySide2. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +import unittest +import sys +import os + + +if sys.platform == 'win32': + from PySide2._utils import _get_win32_case_sensitive_name + + class Win32UtilsTest(unittest.TestCase): + def testWin32CaseSensitiveName(self): + from tempfile import mkdtemp + caseSensitiveName = 'CaseSensitiveName' + tmpdir = mkdtemp(caseSensitiveName) + try: + path = _get_win32_case_sensitive_name(tmpdir.lower()) + self.assertTrue(path.endswith(caseSensitiveName)) + finally: + if os.path.exists(tmpdir): + os.rmdir(tmpdir) + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside2/tests/pysidetest/version_test.py b/sources/pyside2/tests/pysidetest/version_test.py new file mode 100644 index 000000000..5901a56c1 --- /dev/null +++ b/sources/pyside2/tests/pysidetest/version_test.py @@ -0,0 +1,45 @@ +#!/usr/bin/python + +############################################################################# +## +## Copyright (C) 2016 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of PySide2. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +import unittest +from PySide2 import __version_info__, __version__, QtCore + +class CheckForVariablesTest(unittest.TestCase): + def testVesions(self): + self.assertTrue(__version_info__ >= (1, 0, 0)) + self.assertTrue(__version_info__ < (99, 99, 99)) + self.assertTrue(__version__) + + self.assertTrue(QtCore.__version_info__ >= (4, 5, 0)) + self.assertTrue(QtCore.__version__) + +if __name__ == '__main__': + unittest.main() + |