From 87be79f0a4f9a4010a2281247199b2f9eb30f940 Mon Sep 17 00:00:00 2001 From: Kurt Pattyn Date: Sat, 31 Aug 2013 19:09:01 +0200 Subject: Moved registerMetaType calls to init() method --- tests/tst_dataprocessor.cpp | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/tests/tst_dataprocessor.cpp b/tests/tst_dataprocessor.cpp index ef9830e..8fe953f 100644 --- a/tests/tst_dataprocessor.cpp +++ b/tests/tst_dataprocessor.cpp @@ -173,7 +173,6 @@ tst_DataProcessor::tst_DataProcessor() void tst_DataProcessor::initTestCase() { - qRegisterMetaType("QWebSocketProtocol::CloseCode"); } void tst_DataProcessor::cleanupTestCase() @@ -182,6 +181,8 @@ void tst_DataProcessor::cleanupTestCase() void tst_DataProcessor::init() { + qRegisterMetaType("QWebSocketProtocol::OpCode"); + qRegisterMetaType("QWebSocketProtocol::CloseCode"); } void tst_DataProcessor::cleanup() @@ -218,16 +219,16 @@ void tst_DataProcessor::goodBinaryFrames_data() void tst_DataProcessor::goodControlFrames_data() { //TODO: still to test with no close code and no close reason (is valid) - QTest::addColumn("payload"); + QTest::addColumn("payload"); QTest::addColumn("closeCode"); //control frame data cannot exceed 125 bytes; smaller than 124, because we also need a 2 byte close code for (int i = 0; i < 124; ++i) { - QTest::newRow(QString("Close frame with %1 ASCII characters").arg(i).toStdString().data()) << QByteArray(i, 'a') << QWebSocketProtocol::CC_NORMAL; + QTest::newRow(QString("Close frame with %1 ASCII characters").arg(i).toStdString().data()) << QString(i, 'a') << QWebSocketProtocol::CC_NORMAL; } - for (int i = 0; i < 256; ++i) + for (int i = 0; i < 126; ++i) { - QTest::newRow(QString("Text frame with containing ASCII character '0x%1'").arg(QByteArray(1, char(i)).toHex().constData()).toStdString().data()) << QByteArray(1, char(i)) << QWebSocketProtocol::CC_NORMAL; + QTest::newRow(QString("Text frame with containing ASCII character '0x%1'").arg(QByteArray(1, char(i)).toHex().constData()).toStdString().data()) << QString(1, char(i)) << QWebSocketProtocol::CC_NORMAL; } } @@ -323,11 +324,10 @@ void tst_DataProcessor::goodTextFrames() void tst_DataProcessor::goodControlFrames() { - qRegisterMetaType("QWebSocketProtocol::OpCode"); QByteArray data; QBuffer buffer; DataProcessor dataProcessor; - QFETCH(QByteArray, payload); + QFETCH(QString, payload); QFETCH(QWebSocketProtocol::CloseCode, closeCode); quint16 swapped = qToBigEndian(closeCode); const char *wireRepresentation = static_cast(static_cast(&swapped)); @@ -336,14 +336,15 @@ void tst_DataProcessor::goodControlFrames() buffer.setData(data); buffer.open(QIODevice::ReadOnly); - QSignalSpy spyControlFrameReceived(&dataProcessor, SIGNAL(controlFrameReceived(QWebSocketProtocol::OpCode,QByteArray))); + QSignalSpy spyCloseFrameReceived(&dataProcessor, SIGNAL(closeReceived(QWebSocketProtocol::CloseCode,QString))); + dataProcessor.process(&buffer); - QCOMPARE(spyControlFrameReceived.count(), 1); - QList arguments = spyControlFrameReceived.takeFirst(); - //QCOMPARE(arguments.at(0).toInt(), int(QWebSocketProtocol::OC_CLOSE)); - QCOMPARE(arguments.at(1).toByteArray().length() - 2, payload.length()); + QCOMPARE(spyCloseFrameReceived.count(), 1); + QList arguments = spyCloseFrameReceived.takeFirst(); + QCOMPARE(arguments.at(0).value(), closeCode); + QCOMPARE(arguments.at(1).toString().length(), payload.length()); buffer.close(); - spyControlFrameReceived.clear(); + spyCloseFrameReceived.clear(); data.clear(); } -- cgit v1.2.1