#include "test.h" Test::Test(QObject *parent) : QObject(parent) { m_serv = new PTServer(this); connect(m_serv, SIGNAL(newConnection()), this, SLOT(m_newConnection())); connect(m_serv, SIGNAL(newClient(PTSocket*)), this, SLOT(m_newClient(PTSocket*))); } void Test::testIntConvert() { QList tests; tests << 0 << 1 << 255 << 256 << 65535 << 65536 << -1 << -65535 << -65536 << 123456789 << -123456789; for(int i = 0; i < tests.size(); ++i) Q_ASSERT(PTSocket::byteArrayToInt(PTSocket::intToByteArray(tests[i])) == tests[i]); qDebug()<<"Int convert OK"; } void Test::testListen(quint16 p) { Q_ASSERT(m_serv->listen(QHostAddress::Any, p)); } void Test::testNewConnection() { ASSERT_LISTEN; PTSocket* sock = new PTSocket(this); connect(sock, SIGNAL(stateChanged(PTSocket::State)), this, SLOT(m_clientStateChanged(PTSocket::State))); m_clients.append(sock); sock->connectToHost("127.0.0.1", m_serv->serverPort()); } void Test::m_newConnection() { qDebug()<<"New socket"; } void Test::m_newClient(PTSocket* s) { connect(s, SIGNAL(stateChanged(PTSocket::State)), this, SLOT(m_clientStateChanged(PTSocket::State))); qDebug()<<"New client:"<peerAddress()<peerPort(); } void Test::m_clientStateChanged(PTSocket::State s) { PTSocket* sock = qobject_cast(sender()); if(sock == 0) return; qDebug()<isServerSide()<errorString(); }