From a8f2a1cf05e16b03eaee22de24ad73109ccf4a27 Mon Sep 17 00:00:00 2001 From: Steven Ceuppens Date: Sun, 29 Sep 2013 18:30:25 +0200 Subject: [PATCH] reorganized unittests & added module pri Change-Id: Ib1aa45f7cc07ea4564b0e5f1315273a2526a4e74 Reviewed-by: Kurt Pattyn --- modules/qt_websockets.pri | 8 ++ sync.profile | 4 + tests/auto/auto.pro | 6 ++ tests/auto/dataprocessor/dataprocessor.pro | 14 ++++ .../{ => auto/dataprocessor}/tst_dataprocessor.cpp | 6 +- tests/autobahn/autobahn.pro | 8 ++ tests/autobahn/compliance/compliance.pro | 14 ++++ tests/{ => autobahn/compliance}/tst_compliance.cpp | 23 +++--- tests/{ => autobahn/scripts}/echoserver.py | 0 tests/{ => autobahn/scripts}/fuzzingclient.json | 0 tests/{ => autobahn/scripts}/fuzzingserver.json | 0 .../scripts}/start_basic_sockettests.sh | 0 tests/{ => autobahn/scripts}/start_echo_server.sh | 0 tests/{ => autobahn/scripts}/stop_echo_server.sh | 0 tests/{ => autobahn/websockets}/tst_websockets.cpp | 29 ++++---- tests/autobahn/websockets/websockets.pro | 14 ++++ tests/main.cpp | 3 - tests/tests.pro | 24 +----- tests/unittests.h | 86 ---------------------- 19 files changed, 98 insertions(+), 141 deletions(-) create mode 100644 modules/qt_websockets.pri create mode 100644 tests/auto/auto.pro create mode 100644 tests/auto/dataprocessor/dataprocessor.pro rename tests/{ => auto/dataprocessor}/tst_dataprocessor.cpp (99%) create mode 100644 tests/autobahn/autobahn.pro create mode 100644 tests/autobahn/compliance/compliance.pro rename tests/{ => autobahn/compliance}/tst_compliance.cpp (84%) rename tests/{ => autobahn/scripts}/echoserver.py (100%) rename tests/{ => autobahn/scripts}/fuzzingclient.json (100%) rename tests/{ => autobahn/scripts}/fuzzingserver.json (100%) rename tests/{ => autobahn/scripts}/start_basic_sockettests.sh (100%) rename tests/{ => autobahn/scripts}/start_echo_server.sh (100%) rename tests/{ => autobahn/scripts}/stop_echo_server.sh (100%) rename tests/{ => autobahn/websockets}/tst_websockets.cpp (87%) create mode 100644 tests/autobahn/websockets/websockets.pro delete mode 100644 tests/main.cpp delete mode 100644 tests/unittests.h diff --git a/modules/qt_websockets.pri b/modules/qt_websockets.pri new file mode 100644 index 0000000..dc0fb3e --- /dev/null +++ b/modules/qt_websockets.pri @@ -0,0 +1,8 @@ +QT.websockets.name = QtWebSockets +QT.websockets.bins = $$QT_MODULE_BIN_BASE +QT.websockets.includes = $$QT_MODULE_INCLUDE_BASE $$QT_MODULE_INCLUDE_BASE/QtWebSockets +QT.websockets.private_includes = $$QT_MODULE_INCLUDE_BASE/QtWebSockets/$$QT.websockets.VERSION/QtWebSockets/private +QT.websockets.sources = $$QT_MODULE_BASE/src/websockets +QT.websockets.libs = $$QT_MODULE_LIB_BASE +QT.websockets.plugins = $$QT_MODULE_PLUGIN_BASE + diff --git a/sync.profile b/sync.profile index b26d76c..ed0c60a 100644 --- a/sync.profile +++ b/sync.profile @@ -5,6 +5,10 @@ %moduleheaders = ( ); +%modulepris = ( + "QtWebSockets" => "$basedir/modules/qt_websockets.pri", +); + %classnames = ( "qtwebsockets.h" => "QtWebSockets", ); diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro new file mode 100644 index 0000000..71c54c7 --- /dev/null +++ b/tests/auto/auto.pro @@ -0,0 +1,6 @@ +TEMPLATE = subdirs + +SUBDIRS += \ + #dataprocessor + + diff --git a/tests/auto/dataprocessor/dataprocessor.pro b/tests/auto/dataprocessor/dataprocessor.pro new file mode 100644 index 0000000..1e55129 --- /dev/null +++ b/tests/auto/dataprocessor/dataprocessor.pro @@ -0,0 +1,14 @@ +CONFIG += console +CONFIG += c++11 +CONFIG += testcase +CONFIG -= app_bundle + +TEMPLATE = app + +TARGET = tst_dataprocessor + +QT = core testlib websockets websockets-private + +SOURCES += tst_dataprocessor.cpp + +DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/tst_dataprocessor.cpp b/tests/auto/dataprocessor/tst_dataprocessor.cpp similarity index 99% rename from tests/tst_dataprocessor.cpp rename to tests/auto/dataprocessor/tst_dataprocessor.cpp index b2d0d5b..a9ef66d 100644 --- a/tests/tst_dataprocessor.cpp +++ b/tests/auto/dataprocessor/tst_dataprocessor.cpp @@ -4,8 +4,8 @@ #include #include #include -#include "dataprocessor_p.h" -#include "unittests.h" + +#include "private/dataprocessor_p.h" Q_DECLARE_METATYPE(QWebSocketProtocol::CloseCode) Q_DECLARE_METATYPE(QWebSocketProtocol::OpCode) @@ -1451,7 +1451,7 @@ void tst_DataProcessor::frameTooBig_data() << QWebSocketProtocol::CC_TOO_MUCH_DATA; } -DECLARE_TEST(tst_DataProcessor) +QTEST_MAIN(tst_DataProcessor) #include "tst_dataprocessor.moc" diff --git a/tests/autobahn/autobahn.pro b/tests/autobahn/autobahn.pro new file mode 100644 index 0000000..28961c4 --- /dev/null +++ b/tests/autobahn/autobahn.pro @@ -0,0 +1,8 @@ +TEMPLATE = subdirs + +SUBDIRS += \ + compliance \ + websockets + + + diff --git a/tests/autobahn/compliance/compliance.pro b/tests/autobahn/compliance/compliance.pro new file mode 100644 index 0000000..0fd32bc --- /dev/null +++ b/tests/autobahn/compliance/compliance.pro @@ -0,0 +1,14 @@ +CONFIG += console +CONFIG += c++11 +CONFIG += testcase +CONFIG -= app_bundle + +TEMPLATE = app + +TARGET = tst_compliance + +QT = core network websockets testlib + +SOURCES += tst_compliance.cpp + +DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/tst_compliance.cpp b/tests/autobahn/compliance/tst_compliance.cpp similarity index 84% rename from tests/tst_compliance.cpp rename to tests/autobahn/compliance/tst_compliance.cpp index 71f9761..c1c9318 100644 --- a/tests/tst_compliance.cpp +++ b/tests/autobahn/compliance/tst_compliance.cpp @@ -4,14 +4,13 @@ #include #include #include "qwebsocket.h" -#include "unittests.h" -class ComplianceTest : public QObject +class tst_ComplianceTest : public QObject { Q_OBJECT public: - ComplianceTest(); + tst_ComplianceTest(); private Q_SLOTS: void initTestCase(); @@ -30,28 +29,28 @@ private: void runTestCase(int nbr, int total); }; -ComplianceTest::ComplianceTest() : +tst_ComplianceTest::tst_ComplianceTest() : m_url("ws://localhost:9001") { } -void ComplianceTest::initTestCase() +void tst_ComplianceTest::initTestCase() { } -void ComplianceTest::cleanupTestCase() +void tst_ComplianceTest::cleanupTestCase() { } -void ComplianceTest::init() +void tst_ComplianceTest::init() { } -void ComplianceTest::cleanup() +void tst_ComplianceTest::cleanup() { } -void ComplianceTest::runTestCase(int nbr, int total) +void tst_ComplianceTest::runTestCase(int nbr, int total) { if (nbr == total) { @@ -85,12 +84,12 @@ void ComplianceTest::runTestCase(int nbr, int total) runTestCase(nbr + 1, total); } -void ComplianceTest::runTestCases(int startNbr, int stopNbr) +void tst_ComplianceTest::runTestCases(int startNbr, int stopNbr) { runTestCase(startNbr, stopNbr); } -void ComplianceTest::autobahnTest() +void tst_ComplianceTest::autobahnTest() { //connect to autobahn server at url ws://ipaddress:port/getCaseCount QWebSocket *pWebSocket = new QWebSocket; @@ -120,7 +119,7 @@ void ComplianceTest::autobahnTest() pWebSocket = 0; } -//DECLARE_TEST(ComplianceTest) +QTEST_MAIN(tst_ComplianceTest) #include "tst_compliance.moc" diff --git a/tests/echoserver.py b/tests/autobahn/scripts/echoserver.py similarity index 100% rename from tests/echoserver.py rename to tests/autobahn/scripts/echoserver.py diff --git a/tests/fuzzingclient.json b/tests/autobahn/scripts/fuzzingclient.json similarity index 100% rename from tests/fuzzingclient.json rename to tests/autobahn/scripts/fuzzingclient.json diff --git a/tests/fuzzingserver.json b/tests/autobahn/scripts/fuzzingserver.json similarity index 100% rename from tests/fuzzingserver.json rename to tests/autobahn/scripts/fuzzingserver.json diff --git a/tests/start_basic_sockettests.sh b/tests/autobahn/scripts/start_basic_sockettests.sh similarity index 100% rename from tests/start_basic_sockettests.sh rename to tests/autobahn/scripts/start_basic_sockettests.sh diff --git a/tests/start_echo_server.sh b/tests/autobahn/scripts/start_echo_server.sh similarity index 100% rename from tests/start_echo_server.sh rename to tests/autobahn/scripts/start_echo_server.sh diff --git a/tests/stop_echo_server.sh b/tests/autobahn/scripts/stop_echo_server.sh similarity index 100% rename from tests/stop_echo_server.sh rename to tests/autobahn/scripts/stop_echo_server.sh diff --git a/tests/tst_websockets.cpp b/tests/autobahn/websockets/tst_websockets.cpp similarity index 87% rename from tests/tst_websockets.cpp rename to tests/autobahn/websockets/tst_websockets.cpp index f330a88..f70a745 100644 --- a/tests/tst_websockets.cpp +++ b/tests/autobahn/websockets/tst_websockets.cpp @@ -4,14 +4,13 @@ #include #include #include "qwebsocket.h" -#include "unittests.h" -class WebSocketsTest : public QObject +class tst_WebSocketsTest : public QObject { Q_OBJECT public: - WebSocketsTest(); + tst_WebSocketsTest(); private Q_SLOTS: void initTestCase(); @@ -56,13 +55,13 @@ private: QUrl m_url; }; -WebSocketsTest::WebSocketsTest() : +tst_WebSocketsTest::tst_WebSocketsTest() : m_pWebSocket(0), m_url("ws://localhost:9000") { } -void WebSocketsTest::initTestCase() +void tst_WebSocketsTest::initTestCase() { m_pWebSocket = new QWebSocket(); /*m_pWebSocket->open(m_url, true); @@ -70,7 +69,7 @@ void WebSocketsTest::initTestCase() QVERIFY(m_pWebSocket->isValid());*/ } -void WebSocketsTest::cleanupTestCase() +void tst_WebSocketsTest::cleanupTestCase() { if (m_pWebSocket) { @@ -81,15 +80,15 @@ void WebSocketsTest::cleanupTestCase() } } -void WebSocketsTest::init() +void tst_WebSocketsTest::init() { } -void WebSocketsTest::cleanup() +void tst_WebSocketsTest::cleanup() { } -void WebSocketsTest::testTextMessage() +void tst_WebSocketsTest::testTextMessage() { const char *message = "Hello world!"; @@ -111,7 +110,7 @@ void WebSocketsTest::testTextMessage() QCOMPARE(spy.takeFirst().at(0).toString(), qMessage); } -void WebSocketsTest::testBinaryMessage() +void tst_WebSocketsTest::testBinaryMessage() { QSignalSpy spy(m_pWebSocket, SIGNAL(binaryMessageReceived(QByteArray))); @@ -125,14 +124,14 @@ void WebSocketsTest::testBinaryMessage() QCOMPARE(spy.takeFirst().at(0).toByteArray(), data); } -void WebSocketsTest::testLocalAddress() +void tst_WebSocketsTest::testLocalAddress() { QCOMPARE(m_pWebSocket->localAddress().toString(), QString("127.0.0.1")); quint16 localPort = m_pWebSocket->localPort(); QVERIFY2(localPort > 0, "Local port is invalid."); } -void WebSocketsTest::testPeerAddress() +void tst_WebSocketsTest::testPeerAddress() { QHostInfo hostInfo = QHostInfo::fromName(m_url.host()); QList addresses = hostInfo.addresses(); @@ -156,7 +155,7 @@ void WebSocketsTest::testPeerAddress() QCOMPARE(m_pWebSocket->peerPort(), (quint16)m_url.port(80)); } -void WebSocketsTest::testProxy() +void tst_WebSocketsTest::testProxy() { QNetworkProxy oldProxy = m_pWebSocket->proxy(); QNetworkProxy proxy(QNetworkProxy::HttpProxy, QString("proxy.network.com"), 80); @@ -166,13 +165,13 @@ void WebSocketsTest::testProxy() QCOMPARE(oldProxy, m_pWebSocket->proxy()); } -void WebSocketsTest::testInvalidWithUnopenedSocket() +void tst_WebSocketsTest::testInvalidWithUnopenedSocket() { QWebSocket qws; QCOMPARE(qws.isValid(), false); } -//DECLARE_TEST(WebSocketsTest) +QTEST_MAIN(tst_WebSocketsTest) #include "tst_websockets.moc" diff --git a/tests/autobahn/websockets/websockets.pro b/tests/autobahn/websockets/websockets.pro new file mode 100644 index 0000000..a8b2edb --- /dev/null +++ b/tests/autobahn/websockets/websockets.pro @@ -0,0 +1,14 @@ +CONFIG += console +CONFIG += c++11 +CONFIG += testcase +CONFIG -= app_bundle + +TEMPLATE = app + +TARGET = tst_websockets + +QT = core network websockets testlib + +SOURCES += tst_websockets.cpp + +DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/main.cpp b/tests/main.cpp deleted file mode 100644 index 68e1242..0000000 --- a/tests/main.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include "unittests.h" - -TEST_MAIN diff --git a/tests/tests.pro b/tests/tests.pro index 9cd3320..1a9ad66 100644 --- a/tests/tests.pro +++ b/tests/tests.pro @@ -1,22 +1,2 @@ -cache() - -QT += core network websockets testlib - -TARGET = unittests -CONFIG += testcase -CONFIG += console -CONFIG += c++11 -CONFIG -= app_bundle - -TEMPLATE = app - -SOURCES += \ - main.cpp \ - tst_websockets.cpp \ - tst_compliance.cpp \ - tst_dataprocessor.cpp - -HEADERS += \ - unittests.h - -DEFINES += SRCDIR=\\\"$$PWD/\\\" +TEMPLATE = subdirs +SUBDIRS += auto autobahn diff --git a/tests/unittests.h b/tests/unittests.h deleted file mode 100644 index 923c218..0000000 --- a/tests/unittests.h +++ /dev/null @@ -1,86 +0,0 @@ -#ifndef UNITTESTT_H -#define UNITTESTT_H - -#include -#include -#include -#include -#include -#include - -namespace AutoTest -{ - -typedef QList TestList; - -inline TestList& testList() -{ - static TestList list; - return list; -} - -inline bool findObject(QObject* object) -{ - TestList& list = testList(); - if (list.contains(object)) - { - return true; - } - Q_FOREACH (QObject* test, list) - { - if (test->objectName() == object->objectName()) - { - return true; - } - } - return false; -} - -inline void addTest(QObject* object) -{ - TestList& list = testList(); - if (!findObject(object)) - { - list.append(object); - } -} - -inline int run(int argc, char *argv[]) -{ - int ret = 0; - - Q_FOREACH (QObject* test, testList()) - { - ret += QTest::qExec(test, argc, argv); - } - testList().clear(); - return ret; -} - -} // end namespace - -template -class Test -{ -public: - QSharedPointer child; - - Test(const QString& name) : child(new T) - { - child->setObjectName(name); - AutoTest::addTest(child.data()); - } -}; - -#define DECLARE_TEST(className) static Test t(#className); - -#define TEST_MAIN \ - int main(int argc, char *argv[]) \ -{ \ - QCoreApplication app(argc, argv); \ - int ret = AutoTest::run(argc, argv); \ - return ret; \ - } -//return app.exec(); - -#endif -- 2.7.4