Created new unittest model.
Separete unittest for module.
Only run unittest for compiled modules.
Reviewer: Marcelo Lira <marcelo.lira@openbossa.org>,
Luciano Wolf <luciano.wolf@openbossa.org>
This commit is contained in:
parent
471486732b
commit
ab918abc1e
211 changed files with 241 additions and 79 deletions
4
tests/QtNetwork/CMakeLists.txt
Normal file
4
tests/QtNetwork/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
PYSIDE_TEST(accessManager_test.py)
|
||||
PYSIDE_TEST(http_test.py)
|
||||
PYSIDE_TEST(tcpserver_test.py)
|
||||
PYSIDE_TEST(udpsocket_test.py)
|
||||
23
tests/QtNetwork/accessManager_test.py
Normal file
23
tests/QtNetwork/accessManager_test.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
|
||||
'''Test cases for QHttp'''
|
||||
|
||||
import unittest
|
||||
|
||||
from PySide.QtCore import *
|
||||
from PySide.QtNetwork import *
|
||||
|
||||
from helper import UsesQApplication
|
||||
|
||||
class AccessManagerCase(UsesQApplication):
|
||||
def slot_replyFinished(self, reply):
|
||||
self.assertEqual(type(reply), QNetworkReply)
|
||||
self.app.quit()
|
||||
|
||||
def testNetworkRequest(self):
|
||||
manager = QNetworkAccessManager()
|
||||
manager.finished.connect(self.slot_replyFinished)
|
||||
manager.get(QNetworkRequest(QUrl("http://qt.nokia.com")))
|
||||
self.app.exec_()
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
67
tests/QtNetwork/http_test.py
Normal file
67
tests/QtNetwork/http_test.py
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
|
||||
'''Test cases for QHttp'''
|
||||
|
||||
import unittest
|
||||
|
||||
from PySide.QtCore import *
|
||||
from PySide.QtNetwork import *
|
||||
|
||||
from helper import UsesQApplication
|
||||
|
||||
"""
|
||||
class HttpSignalsCase(UsesQApplication):
|
||||
'''Test case for launching QHttp signals'''
|
||||
|
||||
def setUp(self):
|
||||
super(HttpSignalsCase, self).setUp()
|
||||
|
||||
self.http = QHttp()
|
||||
self.url = QUrl('http://www.google.com')
|
||||
self.timer = QTimer.singleShot(250, self.app.quit)
|
||||
|
||||
def tearDown(self):
|
||||
del self.http
|
||||
super(HttpSignalsCase, self).tearDown()
|
||||
|
||||
def callback(self, ident):
|
||||
self.called = True
|
||||
|
||||
def testDefaultArgs(self):
|
||||
#QHttp signal requestStarted signal
|
||||
# @bug 114
|
||||
QObject.connect(self.http, SIGNAL('requestStarted(int)'), self.callback)
|
||||
self.http.get(self.url.path())
|
||||
|
||||
self.app.exec_()
|
||||
self.assert_(self.called)
|
||||
|
||||
class testHttp(UsesQApplication):
|
||||
def testRead(self):
|
||||
header = QHttpRequestHeader("GET", QString(QUrl.toPercentEncoding("/index.html")))
|
||||
header.setValue("Host", "qtsoftware.com");
|
||||
http = QHttp()
|
||||
http.setHost("qtsoftware.com")
|
||||
http.request(header)
|
||||
data = http.read(100)
|
||||
"""
|
||||
|
||||
class testAuthenticationSignal(UsesQApplication):
|
||||
def onAuthRequest(self, hostname, port, auth):
|
||||
self.assert_(isinstance(auth, QAuthenticator))
|
||||
print auth.realm()
|
||||
self._resultOk = True
|
||||
self.app.exit()
|
||||
|
||||
def testwaitSignal(self):
|
||||
self._resultOk = False
|
||||
http = QHttp()
|
||||
http.setHost("projects.maemo.org", QHttp.ConnectionModeHttps, 0)
|
||||
http.connect(SIGNAL("authenticationRequired(const QString&, quint16, QAuthenticator*)"), self.onAuthRequest)
|
||||
path = QUrl.toPercentEncoding("/index.html", "!$&'()*+,;=:@/")
|
||||
print http.get(path)
|
||||
self.app.exec_()
|
||||
self.assert_(self._resultOk)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
25
tests/QtNetwork/tcpserver_test.py
Normal file
25
tests/QtNetwork/tcpserver_test.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
|
||||
'''Test cases for QTCPServer'''
|
||||
|
||||
import unittest
|
||||
|
||||
from PySide.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
|
||||
|
||||
def testDefaultArgs(self):
|
||||
# @bug 108
|
||||
#Default arguments for QTcpServer.listen
|
||||
self.server.listen()
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
54
tests/QtNetwork/udpsocket_test.py
Normal file
54
tests/QtNetwork/udpsocket_test.py
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
|
||||
'''Test cases for QUdpSocket'''
|
||||
|
||||
import unittest
|
||||
|
||||
from PySide.QtCore import QUrl, QObject, SIGNAL, QCoreApplication, QTimer
|
||||
from PySide.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.app = QCoreApplication([])
|
||||
self.socket = QUdpSocket()
|
||||
self.socket.bind(45454)
|
||||
self.server = QUdpSocket()
|
||||
self.timer = QTimer.singleShot(1000, self.app.quit)
|
||||
self.a = QTimer.singleShot(100, self.broadcast)
|
||||
#self.a = QTimer()
|
||||
#self.a.setInterval(100)
|
||||
#QObject.connect(self.a, SIGNAL('timeout()'), self.broadcast)
|
||||
#self.a.start()
|
||||
|
||||
def tearDown(self):
|
||||
#Release resources
|
||||
del self.socket
|
||||
del self.server
|
||||
del self.app
|
||||
|
||||
def broadcast(self):
|
||||
addr = QHostAddress(QHostAddress.Broadcast)
|
||||
self.server.writeDatagram('datagram', addr, 45454)
|
||||
|
||||
def callback(self):
|
||||
while self.socket.hasPendingDatagrams():
|
||||
datagram, host, port = self.socket.readDatagram(
|
||||
self.socket.pendingDatagramSize())
|
||||
self.called = True
|
||||
self.app.quit()
|
||||
|
||||
def testDefaultArgs(self):
|
||||
#QUdpSocket.readDatagram pythonic return
|
||||
# @bug 124
|
||||
QObject.connect(self.socket, SIGNAL('readyRead()'), self.callback)
|
||||
self.app.exec_()
|
||||
|
||||
self.assert_(self.called)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue