aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/tests/QtNetwork
diff options
context:
space:
mode:
Diffstat (limited to 'sources/pyside6/tests/QtNetwork')
-rw-r--r--sources/pyside6/tests/QtNetwork/CMakeLists.txt13
-rw-r--r--sources/pyside6/tests/QtNetwork/QtNetwork.pyproject11
-rw-r--r--sources/pyside6/tests/QtNetwork/accessManager_test.py55
-rw-r--r--sources/pyside6/tests/QtNetwork/bug_1084.py28
-rw-r--r--sources/pyside6/tests/QtNetwork/bug_446.py58
-rw-r--r--sources/pyside6/tests/QtNetwork/dnslookup_test.py46
-rw-r--r--sources/pyside6/tests/QtNetwork/qhostinfo_test.py76
-rw-r--r--sources/pyside6/tests/QtNetwork/qipv6address_test.py34
-rw-r--r--sources/pyside6/tests/QtNetwork/qpassworddigestor_test.py28
-rw-r--r--sources/pyside6/tests/QtNetwork/tcpserver_test.py39
-rw-r--r--sources/pyside6/tests/QtNetwork/udpsocket_test.py65
11 files changed, 453 insertions, 0 deletions
diff --git a/sources/pyside6/tests/QtNetwork/CMakeLists.txt b/sources/pyside6/tests/QtNetwork/CMakeLists.txt
new file mode 100644
index 000000000..bff3580a8
--- /dev/null
+++ b/sources/pyside6/tests/QtNetwork/CMakeLists.txt
@@ -0,0 +1,13 @@
+# Copyright (C) 2023 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+PYSIDE_TEST(bug_446.py)
+PYSIDE_TEST(bug_1084.py)
+PYSIDE_TEST(accessManager_test.py)
+PYSIDE_TEST(dnslookup_test.py)
+# Qt${QT_MAJOR_VERSION}: QHttp is gone PYSIDE_TEST(http_test.py)
+PYSIDE_TEST(qhostinfo_test.py)
+PYSIDE_TEST(qpassworddigestor_test.py)
+PYSIDE_TEST(tcpserver_test.py)
+PYSIDE_TEST(udpsocket_test.py)
+PYSIDE_TEST(qipv6address_test.py)
diff --git a/sources/pyside6/tests/QtNetwork/QtNetwork.pyproject b/sources/pyside6/tests/QtNetwork/QtNetwork.pyproject
new file mode 100644
index 000000000..0ba3f5947
--- /dev/null
+++ b/sources/pyside6/tests/QtNetwork/QtNetwork.pyproject
@@ -0,0 +1,11 @@
+{
+ "files": ["accessManager_test.py",
+ "bug_1084.py",
+ "bug_446.py",
+ "dnslookup_test.py",
+ "qhostinfo_test.py",
+ "qipv6address_test.py",
+ "qpassworddigestor_test.py",
+ "tcpserver_test.py",
+ "udpsocket_test.py"]
+}
diff --git a/sources/pyside6/tests/QtNetwork/accessManager_test.py b/sources/pyside6/tests/QtNetwork/accessManager_test.py
new file mode 100644
index 000000000..87711b278
--- /dev/null
+++ b/sources/pyside6/tests/QtNetwork/accessManager_test.py
@@ -0,0 +1,55 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+
+'''Test cases for QHttp'''
+
+import os
+import sys
+import unittest
+
+from pathlib import Path
+sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
+from init_paths import init_test_paths
+init_test_paths(False)
+
+from PySide6.QtCore import QUrl
+from PySide6.QtNetwork import QNetworkAccessManager, QNetworkReply, QNetworkRequest
+from helper.usesqapplication import UsesQApplication
+from httpd import TestServer
+
+
+class AccessManagerCase(UsesQApplication):
+
+ def setUp(self):
+ super(AccessManagerCase, self).setUp()
+ self.httpd = TestServer()
+ self.httpd.start()
+ self.called = False
+
+ def tearDown(self):
+ super(AccessManagerCase, self).tearDown()
+ if self.httpd:
+ self.httpd.shutdown()
+ self.httpd = None
+
+ def goAway(self):
+ self.httpd.shutdown()
+ self.app.quit()
+ self.httpd = None
+
+ def slot_replyFinished(self, reply):
+ self.assertEqual(type(reply), QNetworkReply)
+ self.called = True
+ self.goAway()
+
+ def testNetworkRequest(self):
+ manager = QNetworkAccessManager()
+ manager.finished.connect(self.slot_replyFinished)
+ port = self.httpd.port()
+ manager.get(QNetworkRequest(QUrl(f"http://127.0.0.1:{port}")))
+ self.app.exec()
+ self.assertTrue(self.called)
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/sources/pyside6/tests/QtNetwork/bug_1084.py b/sources/pyside6/tests/QtNetwork/bug_1084.py
new file mode 100644
index 000000000..515220c80
--- /dev/null
+++ b/sources/pyside6/tests/QtNetwork/bug_1084.py
@@ -0,0 +1,28 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+
+''' unit test for BUG #1084 '''
+
+import os
+import sys
+import unittest
+
+from pathlib import Path
+sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
+from init_paths import init_test_paths
+init_test_paths(False)
+
+from PySide6.QtNetwork import QTcpSocket
+
+
+class QTcpSocketTestCase(unittest.TestCase):
+ def setUp(self):
+ self.sock = QTcpSocket()
+ self.sock.connectToHost('127.0.0.1', 25)
+
+ def testIt(self):
+ self.sock.write(bytes('quit', "UTF-8"))
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/sources/pyside6/tests/QtNetwork/bug_446.py b/sources/pyside6/tests/QtNetwork/bug_446.py
new file mode 100644
index 000000000..f28ddb369
--- /dev/null
+++ b/sources/pyside6/tests/QtNetwork/bug_446.py
@@ -0,0 +1,58 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+
+import os
+import sys
+import unittest
+
+from pathlib import Path
+sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
+from init_paths import init_test_paths
+init_test_paths(False)
+
+from PySide6.QtNetwork import QHostAddress, QTcpServer, QTcpSocket
+from helper.usesqapplication import UsesQApplication
+
+
+class HttpSignalsCase(UsesQApplication):
+ '''Test case for launching QHttp signals'''
+ DATA = bytes("PySide rocks", "UTF-8")
+
+ def onError(self):
+ self.assertTrue(False)
+
+ def onNewConnection(self):
+ self.serverConnection = self.server.nextPendingConnection()
+ self.serverConnection.errorOccurred.connect(self.onError)
+ self.serverConnection.write(HttpSignalsCase.DATA)
+ self.server.close()
+
+ def onReadReady(self):
+ data = self.client.read(100)
+ self.assertEqual(len(data), len(HttpSignalsCase.DATA))
+ self.assertEqual(data, HttpSignalsCase.DATA)
+ self.done()
+
+ def onClientConnect(self):
+ self.client.readyRead.connect(self.onReadReady)
+
+ def initServer(self):
+ self.server = QTcpServer()
+ self.server.newConnection.connect(self.onNewConnection)
+ self.assertTrue(self.server.listen())
+ self.client = QTcpSocket()
+ self.client.connected.connect(self.onClientConnect)
+ self.client.connectToHost(QHostAddress(QHostAddress.LocalHost), self.server.serverPort())
+
+ def done(self):
+ self.serverConnection.close()
+ self.client.close()
+ self.app.quit()
+
+ def testRun(self):
+ self.initServer()
+ self.app.exec()
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/sources/pyside6/tests/QtNetwork/dnslookup_test.py b/sources/pyside6/tests/QtNetwork/dnslookup_test.py
new file mode 100644
index 000000000..c50a6b5d4
--- /dev/null
+++ b/sources/pyside6/tests/QtNetwork/dnslookup_test.py
@@ -0,0 +1,46 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+
+'''Test cases for QDnsLookup'''
+
+import gc
+import os
+import sys
+import unittest
+
+from pathlib import Path
+sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
+from init_paths import init_test_paths
+init_test_paths(False)
+
+from PySide6.QtCore import QCoreApplication
+from PySide6.QtNetwork import QDnsLookup
+
+
+class DnsLookupTestCase(unittest.TestCase):
+ '''Test case for QDnsLookup'''
+
+ def setUp(self):
+ self._app = QCoreApplication([])
+ self._lookup = QDnsLookup(QDnsLookup.ANY, 'www.qt.io')
+ self._lookup.finished.connect(self._finished)
+
+ def tearDown(self):
+ del self._lookup
+ # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
+ gc.collect()
+
+ def _finished(self):
+ if self._lookup.error() == QDnsLookup.NoError:
+ nameRecords = self._lookup.canonicalNameRecords()
+ if nameRecords:
+ print(nameRecords[0].name())
+ self._app.quit()
+
+ def testLookup(self):
+ self._lookup.lookup()
+ self._app.exec()
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/sources/pyside6/tests/QtNetwork/qhostinfo_test.py b/sources/pyside6/tests/QtNetwork/qhostinfo_test.py
new file mode 100644
index 000000000..8d8d2cae4
--- /dev/null
+++ b/sources/pyside6/tests/QtNetwork/qhostinfo_test.py
@@ -0,0 +1,76 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+
+'''Test case for QHostInfo.'''
+
+import os
+import sys
+import unittest
+
+from pathlib import Path
+sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
+from init_paths import init_test_paths
+init_test_paths(False)
+
+from helper.usesqapplication import UsesQApplication
+from PySide6.QtCore import (QCoreApplication, QElapsedTimer, QObject, QThread,
+ Slot, SLOT)
+from PySide6.QtNetwork import QHostInfo
+
+
+HOST = 'www.qt.io'
+
+
+TIMEOUT = 30000
+
+
+class Receiver(QObject):
+ def __init__(self, parent=None):
+ super().__init__(parent)
+ self._slot_called = False
+
+ def slot_called(self):
+ return self._slot_called
+
+ @Slot(QHostInfo)
+ def info_received(self, host_info):
+ name = host_info.hostName()
+ if host_info.error() == QHostInfo.NoError:
+ addresses = [a.toString() for a in host_info.addresses()]
+ addresses_str = ', '.join(addresses)
+ print(f'"{name}" resolved to {addresses_str}')
+ else:
+ error = host_info.errorString()
+ print(f'Unable to resolve "{name}": {error}', file=sys.stderr)
+ self._slot_called = True
+
+
+class QHostInfoTest(UsesQApplication):
+ '''Test case for QHostInfo.'''
+ def setUp(self):
+ UsesQApplication.setUp(self)
+ self._timer = QElapsedTimer()
+
+ def testStringBasedLookup(self):
+ receiver = Receiver()
+ self._timer.restart()
+ QHostInfo.lookupHost(HOST, receiver, SLOT('info_received(QHostInfo)'))
+ while not receiver.slot_called() and self._timer.elapsed() < TIMEOUT:
+ QCoreApplication.processEvents()
+ QThread.msleep(10)
+ print(f'String-based: Elapsed {self._timer.elapsed()}ms')
+ self.assertTrue(receiver.slot_called())
+
+ def testCallableLookup(self):
+ receiver = Receiver()
+ self._timer.restart()
+ QHostInfo.lookupHost(HOST, receiver.info_received)
+ while not receiver.slot_called() and self._timer.elapsed() < TIMEOUT:
+ QCoreApplication.processEvents()
+ QThread.msleep(10)
+ print(f'Callable: Elapsed {self._timer.elapsed()}ms')
+ self.assertTrue(receiver.slot_called())
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/sources/pyside6/tests/QtNetwork/qipv6address_test.py b/sources/pyside6/tests/QtNetwork/qipv6address_test.py
new file mode 100644
index 000000000..67b103d3c
--- /dev/null
+++ b/sources/pyside6/tests/QtNetwork/qipv6address_test.py
@@ -0,0 +1,34 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+
+'''Test cases for QIPv6Address'''
+
+import os
+import sys
+import unittest
+
+from pathlib import Path
+sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
+from init_paths import init_test_paths
+init_test_paths(False)
+
+from PySide6.QtNetwork import QIPv6Address
+
+
+class QIPv6AddressGetItemTest(unittest.TestCase):
+ def testLength(self):
+ ip = QIPv6Address()
+ self.assertEqual(len(ip), 16)
+
+ def testSetItemNegativeIndex(self):
+ ip = QIPv6Address()
+ ip[-1] = 8
+ self.assertEqual(ip[-1], 8)
+
+ def testSetItemLargeIndex(self):
+ ip = QIPv6Address()
+ self.assertRaises(IndexError, ip.__setitem__, 32, 16)
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/sources/pyside6/tests/QtNetwork/qpassworddigestor_test.py b/sources/pyside6/tests/QtNetwork/qpassworddigestor_test.py
new file mode 100644
index 000000000..db7a90da9
--- /dev/null
+++ b/sources/pyside6/tests/QtNetwork/qpassworddigestor_test.py
@@ -0,0 +1,28 @@
+#!/usr/bin/python
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+
+'''Test cases for QPasswordDigestor'''
+
+import os
+import sys
+import unittest
+
+from pathlib import Path
+sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
+from init_paths import init_test_paths
+init_test_paths(False)
+
+from PySide6.QtCore import QByteArray, QCryptographicHash
+from PySide6.QtNetwork import QPasswordDigestor
+
+
+class TestPasswordDigestor(unittest.TestCase):
+ def test(self):
+ b = QPasswordDigestor.deriveKeyPbkdf1(QCryptographicHash.Sha1,
+ b'test', b'saltnpep', 10, 20)
+ self.assertEqual(b.size(), 20)
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/sources/pyside6/tests/QtNetwork/tcpserver_test.py b/sources/pyside6/tests/QtNetwork/tcpserver_test.py
new file mode 100644
index 000000000..845afdfae
--- /dev/null
+++ b/sources/pyside6/tests/QtNetwork/tcpserver_test.py
@@ -0,0 +1,39 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+
+'''Test cases for QTCPServer'''
+
+import gc
+import os
+import sys
+import unittest
+
+from pathlib import Path
+sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
+from init_paths import init_test_paths
+init_test_paths(False)
+
+from PySide6.QtNetwork import QTcpServer
+
+
+class ListenDefaultArgsCase(unittest.TestCase):
+ '''Test case for TcpServer.listen with default args'''
+
+ def setUp(self):
+ # Acquire resources
+ self.server = QTcpServer()
+
+ def tearDown(self):
+ # Release resources
+ del self.server
+ # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
+ gc.collect()
+
+ def testDefaultArgs(self):
+ # @bug 108
+ # Default arguments for QTcpServer.listen
+ self.server.listen()
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/sources/pyside6/tests/QtNetwork/udpsocket_test.py b/sources/pyside6/tests/QtNetwork/udpsocket_test.py
new file mode 100644
index 000000000..950849801
--- /dev/null
+++ b/sources/pyside6/tests/QtNetwork/udpsocket_test.py
@@ -0,0 +1,65 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+
+'''Test cases for QUdpSocket'''
+
+import gc
+import os
+import sys
+import unittest
+
+from pathlib import Path
+sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
+from init_paths import init_test_paths
+init_test_paths(False)
+
+from PySide6.QtCore import QUrl, QObject, SIGNAL, QCoreApplication, QTimer
+from PySide6.QtNetwork import QUdpSocket, QHostAddress
+
+
+class HttpSignalsCase(unittest.TestCase):
+ '''Test case for bug #124 - readDatagram signature
+
+ QUdpSocket.readDatagram must return a tuple with the datagram, host and
+ port, while receiving only the max payload size.'''
+
+ def setUp(self):
+ # Acquire resources
+ self.called = False
+ self.app = QCoreApplication([])
+
+ self.socket = QUdpSocket()
+
+ self.server = QUdpSocket()
+ self.server.bind(QHostAddress(QHostAddress.LocalHost), 45454)
+
+ def tearDown(self):
+ # Release resources
+ del self.socket
+ del self.server
+ del self.app
+ # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
+ gc.collect()
+
+ def sendPackage(self):
+ addr = QHostAddress(QHostAddress.LocalHost)
+ self.socket.writeDatagram(bytes('datagram', "UTF-8"), addr, 45454)
+
+ def callback(self):
+ while self.server.hasPendingDatagrams():
+ datagram, host, port = self.server.readDatagram(self.server.pendingDatagramSize())
+ self.called = True
+ self.app.quit()
+
+ def testDefaultArgs(self):
+ # QUdpSocket.readDatagram pythonic return
+ # @bug 124
+ self.server.readyRead.connect(self.callback)
+ self.sendPackage()
+ self.app.exec()
+
+ self.assertTrue(self.called)
+
+
+if __name__ == '__main__':
+ unittest.main()