diff options
Diffstat (limited to 'sources/pyside2/tests')
-rw-r--r-- | sources/pyside2/tests/QtCharts/CMakeLists.txt | 1 | ||||
-rw-r--r-- | sources/pyside2/tests/QtCharts/qcharts_test.py | 63 | ||||
-rw-r--r-- | sources/pyside2/tests/QtCore/CMakeLists.txt | 1 | ||||
-rw-r--r-- | sources/pyside2/tests/QtCore/qurl_test.py | 132 | ||||
-rw-r--r-- | sources/pyside2/tests/QtCore/qurlquery_test.py | 59 | ||||
-rw-r--r-- | sources/pyside2/tests/QtGui/CMakeLists.txt | 1 | ||||
-rw-r--r-- | sources/pyside2/tests/QtGui/qopenglwindow_test.py | 104 | ||||
-rw-r--r-- | sources/pyside2/tests/QtTextToSpeech/CMakeLists.txt | 1 | ||||
-rw-r--r-- | sources/pyside2/tests/QtTextToSpeech/qtexttospeech_test.py | 63 | ||||
-rw-r--r-- | sources/pyside2/tests/pysidetest/CMakeLists.txt | 25 |
10 files changed, 400 insertions, 50 deletions
diff --git a/sources/pyside2/tests/QtCharts/CMakeLists.txt b/sources/pyside2/tests/QtCharts/CMakeLists.txt new file mode 100644 index 000000000..16e8b4bc9 --- /dev/null +++ b/sources/pyside2/tests/QtCharts/CMakeLists.txt @@ -0,0 +1 @@ +PYSIDE_TEST(qcharts_test.py) diff --git a/sources/pyside2/tests/QtCharts/qcharts_test.py b/sources/pyside2/tests/QtCharts/qcharts_test.py new file mode 100644 index 000000000..1503b2e54 --- /dev/null +++ b/sources/pyside2/tests/QtCharts/qcharts_test.py @@ -0,0 +1,63 @@ +#!/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$ +## +############################################################################# + +'''Test cases for QCharts''' + +from helper import UsesQApplication +import unittest + +from PySide2.QtCore import QRect, QSize, QTimer +from PySide2.QtGui import QGuiApplication, QScreen +from PySide2.QtCharts import QtCharts + +class QChartsTestCase(UsesQApplication): + '''Tests related to QCharts''' + + def testCharts(self): + self.series = QtCharts.QPieSeries() + self.series.append("Jane", 1); + self.series.append("Joe", 2); + self.series.append("Andy", 3); + self.series.append("Barbara", 4); + self.series.append("Axel", 5); + slice = self.series.slices()[1] + slice.setExploded(); + slice.setLabelVisible(); + self.chart = QtCharts.QChart() + self.chart.addSeries(self.series); + chartView = QtCharts.QChartView(self.chart) + screenSize = QGuiApplication.primaryScreen().geometry().size() + chartView.resize(screenSize / 2) + chartView.show() + QTimer.singleShot(500, self.app.quit) + self.app.exec_() + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside2/tests/QtCore/CMakeLists.txt b/sources/pyside2/tests/QtCore/CMakeLists.txt index 436af3dac..f7eb86d16 100644 --- a/sources/pyside2/tests/QtCore/CMakeLists.txt +++ b/sources/pyside2/tests/QtCore/CMakeLists.txt @@ -104,6 +104,7 @@ PYSIDE_TEST(qtimer_singleshot_test.py) PYSIDE_TEST(qtimer_timeout_test.py) PYSIDE_TEST(qtnamespace_test.py) PYSIDE_TEST(qurl_test.py) +PYSIDE_TEST(qurlquery_test.py) PYSIDE_TEST(repr_test.py) PYSIDE_TEST(setprop_on_ctor_test.py) PYSIDE_TEST(staticMetaObject_test.py) diff --git a/sources/pyside2/tests/QtCore/qurl_test.py b/sources/pyside2/tests/QtCore/qurl_test.py index 595e5931f..d5eb37d6e 100644 --- a/sources/pyside2/tests/QtCore/qurl_test.py +++ b/sources/pyside2/tests/QtCore/qurl_test.py @@ -33,6 +33,7 @@ import unittest from PySide2.QtCore import QUrl +from PySide2.QtCore import QUrlQuery class QUrlBasicConstructor(unittest.TestCase): '''Tests the basic constructors''' @@ -67,59 +68,96 @@ class QUrlBasicConstructor(unittest.TestCase): self.assertEqual(url.toString(), 'ftp://john:abc123@www.google.com:8080/mail/view') +class QueryItemsTest(unittest.TestCase): + '''Test query item management''' + + def testQueryItems(self): + url = QUrl('http://www.google.com/search?q=python&hl=en') + valid_data = [(('q'), ('python')), (('hl'), ('en'))] + + self.assertEqual(sorted(QUrlQuery(url.query()).queryItems()), sorted(valid_data)) + + def testEncodedQueryItems(self): + url = QUrl('http://www.google.com/search?q=python&hl=en') + valid_data = [(('q'), ('python')), (('hl'), ('en'))] + + self.assertEqual(sorted(QUrlQuery(url.query()).queryItems()), sorted(valid_data)) + + def testSetQueryItems(self): + urla = QUrl('http://www.google.com/search?q=python&hl=en') + urlb = QUrl('http://www.google.com/search') + + urlb.setQuery(urla.query()) + + self.assertEqual(urla, urlb) + + def testAddQueryItem(self): + url = QUrlQuery() + valid_data = [('hl', 'en'), ('user', 'konqui')] + + url.addQueryItem(*valid_data[0]) + self.assertEqual(url.queryItems()[0], valid_data[0]) + + url.addQueryItem(*valid_data[1]) + self.assertEqual(sorted(url.queryItems()), sorted(valid_data)) + + def testAllQueryItemsValues(self): + url = QUrlQuery() + key = 'key' + valid_data = ['data', 'valid', 'test'] + + for i, data in enumerate(valid_data): + url.addQueryItem(key, data) + self.assertEqual(url.allQueryItemValues(key), + list(valid_data[:i+1])) + def testPath(self): url = QUrl("http://qt-project.org/images/ban/pgs_front.jpg") self.assertEqual(url.path(), "/images/ban/pgs_front.jpg") # PYSIDE-345: No bindings for QUrlQuery -# class QueryItemsTest(unittest.TestCase): -# '''Test query item management''' -# -# def testQueryItems(self): -# #QUrl.queryItems -# url = QUrl('http://www.google.com/search?q=python&hl=en') -# valid_data = [(('q'), ('python')), (('hl'), ('en'))] -# -# self.assertEqual(sorted(url.queryItems()), sorted(valid_data)) -# -# def testEncodedQueryItems(self): -# #QUrl.encodedQueryItems -# url = QUrl('http://www.google.com/search?q=python&hl=en') -# valid_data = [(('q'), ('python')), (('hl'), ('en'))] -# -# self.assertEqual(sorted(url.encodedQueryItems()), sorted(valid_data)) -# -# def testSetQueryItems(self): -# #QUrl.setQueryItems -# urla = QUrl('http://www.google.com/search?q=python&hl=en') -# urlb = QUrl('http://www.google.com/search') -# -# urlb.setQueryItems(urla.queryItems()) -# -# self.assertEqual(urla, urlb) -# -# def testAddQueryItem(self): -# #QUrl.addQueryItem -# url = QUrl() -# valid_data = [('hl', 'en'), ('user', 'konqui')] -# -# url.addQueryItem(*valid_data[0]) -# self.assertEqual(url.queryItems()[0], valid_data[0]) -# -# url.addQueryItem(*valid_data[1]) -# self.assertEqual(sorted(url.queryItems()), sorted(valid_data)) -# -# def testAllEncodedQueryItemsValues(self): -# #QUrl.allEncodedQueryItemValues -# url = QUrl() -# key = 'key' -# valid_data = ['data', 'valid', 'test'] -# -# for i, data in enumerate(valid_data): -# url.addQueryItem(key, data) -# self.assertEqual(url.allEncodedQueryItemValues(key), -# list(valid_data[:i+1])) +class QueryItemsTest(unittest.TestCase): + '''Test query item management''' + + def testQueryItems(self): + url = QUrl('http://www.google.com/search?q=python&hl=en') + valid_data = [(('q'), ('python')), (('hl'), ('en'))] + + self.assertEqual(sorted(QUrlQuery(url.query()).queryItems()), sorted(valid_data)) + + def testEncodedQueryItems(self): + url = QUrl('http://www.google.com/search?q=python&hl=en') + valid_data = [(('q'), ('python')), (('hl'), ('en'))] + + self.assertEqual(sorted(QUrlQuery(url.query()).queryItems()), sorted(valid_data)) + + def testSetQueryItems(self): + urla = QUrl('http://www.google.com/search?q=python&hl=en') + urlb = QUrl('http://www.google.com/search') + + urlb.setQuery(urla.query()) + + self.assertEqual(urla, urlb) + + def testAddQueryItem(self): + url = QUrlQuery() + valid_data = [('hl', 'en'), ('user', 'konqui')] + + url.addQueryItem(*valid_data[0]) + self.assertEqual(url.queryItems()[0], valid_data[0]) + + url.addQueryItem(*valid_data[1]) + self.assertEqual(sorted(url.queryItems()), sorted(valid_data)) + + def testAllQueryItemsValues(self): + url = QUrlQuery() + key = 'key' + valid_data = ['data', 'valid', 'test'] + for i, data in enumerate(valid_data): + url.addQueryItem(key, data) + self.assertEqual(url.allQueryItemValues(key), + list(valid_data[:i+1])) if __name__ == '__main__': unittest.main() diff --git a/sources/pyside2/tests/QtCore/qurlquery_test.py b/sources/pyside2/tests/QtCore/qurlquery_test.py new file mode 100644 index 000000000..e42856e6d --- /dev/null +++ b/sources/pyside2/tests/QtCore/qurlquery_test.py @@ -0,0 +1,59 @@ +#!/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$ +## +############################################################################# + +'''Unit tests for QUrlQuery''' + +import unittest +import ctypes +import sys + +from PySide2.QtCore import QUrlQuery + +class QUrlQueryTest(unittest.TestCase): + def testConstructing(self): + empty = QUrlQuery() + self.assertTrue(empty.isEmpty()) + self.assertEqual(empty.queryPairDelimiter(), QUrlQuery.defaultQueryPairDelimiter()) + self.assertEqual(empty.queryValueDelimiter(), QUrlQuery.defaultQueryValueDelimiter()) + + empty.clear(); + self.assertTrue(empty.isEmpty()) + + def testAddRemove(self): + query = QUrlQuery() + + query.addQueryItem("a", "b"); + self.assertTrue(not query.isEmpty()) + self.assertTrue(query.hasQueryItem("a")) + self.assertEqual(query.queryItemValue("a"), "b") + self.assertEqual(query.allQueryItemValues("a"), ["b"]) + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside2/tests/QtGui/CMakeLists.txt b/sources/pyside2/tests/QtGui/CMakeLists.txt index 63cf3c35f..eeb7c7e36 100644 --- a/sources/pyside2/tests/QtGui/CMakeLists.txt +++ b/sources/pyside2/tests/QtGui/CMakeLists.txt @@ -37,6 +37,7 @@ PYSIDE_TEST(qpolygonf_test.py) PYSIDE_TEST(qkeysequence_test.py) PYSIDE_TEST(qradialgradient_test.py) PYSIDE_TEST(qrasterwindow_test.py) +PYSIDE_TEST(qopenglwindow_test.py) PYSIDE_TEST(qregion_test.py) PYSIDE_TEST(qstylehints_test.py) PYSIDE_TEST(qtextdocument_undoredo_test.py) diff --git a/sources/pyside2/tests/QtGui/qopenglwindow_test.py b/sources/pyside2/tests/QtGui/qopenglwindow_test.py new file mode 100644 index 000000000..2d11a0238 --- /dev/null +++ b/sources/pyside2/tests/QtGui/qopenglwindow_test.py @@ -0,0 +1,104 @@ +############################################################################# +## +## 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$ +## +############################################################################# + +'''Unit test for QOpenGLContext, QOpenGLTexture, QOpenGLWindow and related classes''' + +import sys +import unittest + +from helper import UsesQApplication + +from PySide2.QtCore import QSize, QTimer, Qt +from PySide2.QtGui import (QColor, QGuiApplication, QImage, QOpenGLContext, + QOpenGLTexture, QSurfaceFormat, QOpenGLWindow) + +try: + from OpenGL import GL +except ImportError: + print("Skipping test due to missing OpenGL module") + sys.exit(0) + +class OpenGLWindow(QOpenGLWindow): + def __init__(self): + super(OpenGLWindow, self).__init__() + + self.m_functions = None + self.m_texture = None + self.visibleChanged.connect(self.slotVisibleChanged) + + def slotVisibleChanged(self, visible): + if not visible and self.m_texture is not None and self.context().makeCurrent(self): + self.m_texture = None + self.context().doneCurrent() + + def initializeGL(self): + self.m_functions = self.context().functions() + self.m_functions.initializeOpenGLFunctions() + image = QImage(QSize(200, 200), QImage.Format_RGBA8888) + image.fill(QColor(Qt.red)) + self.m_texture = QOpenGLTexture(image) + + def paintGL(self): + GL.glMatrixMode(GL.GL_MODELVIEW); + GL.glLoadIdentity(); + + GL.glMatrixMode(GL.GL_PROJECTION); + GL.glLoadIdentity(); + GL.glOrtho(0, 1, 1, 0, -1, 1); + + self.m_functions.glClear(GL.GL_COLOR_BUFFER_BIT) + self.m_functions.glEnable(GL.GL_TEXTURE_2D); + self.m_texture.bind() + + d = 0.5 + GL.glBegin(GL.GL_QUADS) + GL.glTexCoord2f(0, 0) + GL.glVertex2f(0, 0) + GL.glTexCoord2f(d, 0) + GL.glVertex2f(d, 0) + GL.glTexCoord2f(d, d) + GL.glVertex2f(d, d) + GL.glTexCoord2f(0, d) + GL.glVertex2f(0, d) + GL.glEnd() + self.m_texture.release() + + def resizeGL(self, w, h): + self.m_functions.glViewport(0, 0, self.width(), self.height()) + +class QOpenGLWindowTest(UsesQApplication): + # On macOS, glClear(), glViewport() are rejected due to GLbitfield/GLint not being resolved properly + def test(self): + openGlWindow = OpenGLWindow() + openGlWindow.resize(640, 480) + openGlWindow.show() + QTimer.singleShot(100, openGlWindow.close) + self.app.exec_() + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside2/tests/QtTextToSpeech/CMakeLists.txt b/sources/pyside2/tests/QtTextToSpeech/CMakeLists.txt new file mode 100644 index 000000000..6f5851587 --- /dev/null +++ b/sources/pyside2/tests/QtTextToSpeech/CMakeLists.txt @@ -0,0 +1 @@ +PYSIDE_TEST(qtexttospeech_test.py) diff --git a/sources/pyside2/tests/QtTextToSpeech/qtexttospeech_test.py b/sources/pyside2/tests/QtTextToSpeech/qtexttospeech_test.py new file mode 100644 index 000000000..6f26f3691 --- /dev/null +++ b/sources/pyside2/tests/QtTextToSpeech/qtexttospeech_test.py @@ -0,0 +1,63 @@ +#!/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$ +## +############################################################################# + +'''Test cases for QTextToSpeech methods''' + +from helper import UsesQApplication +import sys +import unittest + +from PySide2.QtCore import QTimer + +try: + from PySide2.QtTextToSpeech import QTextToSpeech, QVoice +except ImportError: + print("Skipping test due to missing QtTextToSpeech module") + sys.exit(0) + +class QTextToSpeechTestCase(UsesQApplication): + '''Tests related to QTextToSpeech''' + def testSay(self): + engines = QTextToSpeech.availableEngines() + if not engines: + print('No QTextToSpeech engines available') + else: + speech = QTextToSpeech(engines[0]) + speech.stateChanged.connect(self._slotStateChanged) + speech.say("Hello, PySide2") + QTimer.singleShot(5000, self.app.quit) + self.app.exec_() + + def _slotStateChanged(self, state): + if (state == QTextToSpeech.State.Ready): + self.app.quit() + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside2/tests/pysidetest/CMakeLists.txt b/sources/pyside2/tests/pysidetest/CMakeLists.txt index b5fcb8d12..e356529a2 100644 --- a/sources/pyside2/tests/pysidetest/CMakeLists.txt +++ b/sources/pyside2/tests/pysidetest/CMakeLists.txt @@ -38,14 +38,32 @@ ${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} - ${QT_INCLUDE_DIR}/QtCore - ${QT_INCLUDE_DIR}/QtGui - ${QT_INCLUDE_DIR}/QtWidgets + ${Qt5Core_DIRECT_INCLUDE_DIR} + ${Qt5Gui_DIRECT_INCLUDE_DIR} + ${Qt5Widgets_DIRECT_INCLUDE_DIR} ) make_path(testbinding_typesystem_path ${CMAKE_CURRENT_SOURCE_DIR} @@ -58,6 +76,7 @@ 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 |