From e36432f90556ac07572981d64be7d8be5c06c26f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Wed, 15 Aug 2018 11:00:31 +0200 Subject: [PATCH] Restructure tests --- nymea-remoteproxy.pri | 3 - .../nymea-remoteproxy-tests-offline.cpp} | 231 +++--------------- .../offline/nymea-remoteproxy-tests-offline.h | 51 ++++ tests/offline/offline.pro | 14 ++ tests/online/online.pro | 2 + tests/testbase/basetest.cpp | 209 ++++++++++++++++ .../basetest.h} | 41 +--- tests/{ => testbase}/mockauthenticator.cpp | 0 tests/{ => testbase}/mockauthenticator.h | 0 tests/testbase/testbase.pri | 14 ++ tests/tests.pro | 20 +- 11 files changed, 339 insertions(+), 246 deletions(-) rename tests/{nymea-remoteproxy-tests.cpp => offline/nymea-remoteproxy-tests-offline.cpp} (65%) create mode 100644 tests/offline/nymea-remoteproxy-tests-offline.h create mode 100644 tests/offline/offline.pro create mode 100644 tests/online/online.pro create mode 100644 tests/testbase/basetest.cpp rename tests/{nymea-remoteproxy-tests.h => testbase/basetest.h} (77%) rename tests/{ => testbase}/mockauthenticator.cpp (100%) rename tests/{ => testbase}/mockauthenticator.h (100%) create mode 100644 tests/testbase/testbase.pri diff --git a/nymea-remoteproxy.pri b/nymea-remoteproxy.pri index d1914bd..2b077fc 100644 --- a/nymea-remoteproxy.pri +++ b/nymea-remoteproxy.pri @@ -16,9 +16,6 @@ CONFIG += c++11 console QMAKE_CXXFLAGS *= -Werror -std=c++11 -g QMAKE_LFLAGS *= -std=c++11 -INCLUDEPATH += /home/timon/guh/development/cloud/aws-sdk-cpp/build/install/include -LIBS += -L/home/timon/guh/development/cloud/aws-sdk-cpp/build/install/lib -laws-cpp-sdk-core -laws-cpp-sdk-lambda - top_srcdir=$$PWD top_builddir=$$shadowed($$PWD) diff --git a/tests/nymea-remoteproxy-tests.cpp b/tests/offline/nymea-remoteproxy-tests-offline.cpp similarity index 65% rename from tests/nymea-remoteproxy-tests.cpp rename to tests/offline/nymea-remoteproxy-tests-offline.cpp index 7e9f4f6..c10dd25 100644 --- a/tests/nymea-remoteproxy-tests.cpp +++ b/tests/offline/nymea-remoteproxy-tests-offline.cpp @@ -1,4 +1,4 @@ -#include "nymea-remoteproxy-tests.h" +#include "nymea-remoteproxy-tests-offline.h" #include "engine.h" #include "loggingcategories.h" @@ -11,200 +11,9 @@ #include RemoteProxyTests::RemoteProxyTests(QObject *parent) : - QObject(parent) + BaseTest(parent) { - m_configuration = new ProxyConfiguration(this); - QFile certificateFile(":/test-certificate.crt"); - if (!certificateFile.open(QIODevice::ReadOnly)) { - qWarning() << "Could not open resource file" << certificateFile.fileName(); - exit(1); - } - - QByteArray certificateData = certificateFile.readAll(); - //qDebug() << "Certificate:" << endl << qUtf8Printable(certificateData); - - QFile keyFile(":/test-certificate.key"); - if (!keyFile.open(QIODevice::ReadOnly)) { - qWarning() << "Could not open resource file" << keyFile.fileName(); - exit(1); - } - - QByteArray keyData = keyFile.readAll(); - //qDebug() << "Certificate key:" << endl << qUtf8Printable(keyData); - m_authenticator = new MockAuthenticator(this); - - m_sslConfiguration.setPrivateKey(QSslKey(keyData, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey)); - m_sslConfiguration.setLocalCertificate(QSslCertificate(certificateData, QSsl::Pem)); - m_sslConfiguration.setPeerVerifyMode(QSslSocket::VerifyNone); - m_sslConfiguration.setProtocol(QSsl::TlsV1_2OrLater); - - m_testToken = "eyJraWQiOiJXdnFFT3prVVh5VDlINzFyRUpoNWdxRnkxNFhnR2l3SFAzVEIzUFQ1V3ZrPSIsImFsZyI6IlJT" - "MjU2In0.eyJzdWIiOiJmZTJmZDNlNC1hMGJhLTQ1OTUtOWRiZS00ZDkxYjRiMjFlMzUiLCJhdWQiOiI4cmpoZ" - "mRsZjlqZjFzdW9rMmpjcmx0ZDZ2IiwiZW1haWxfdmVyaWZpZWQiOnRydWUsImV2ZW50X2lkIjoiN2Y5NTRiNm" - "ItOTYyZi0xMWU4LWI0ZjItMzU5NWRiZmRiODVmIiwidG9rZW5fdXNlIjoiaWQiLCJhdXRoX3RpbWUiOjE1MzM" - "xOTkxMzgsImlzcyI6Imh0dHBzOlwvXC9jb2duaXRvLWlkcC5ldS13ZXN0LTEuYW1hem9uYXdzLmNvbVwvZXUt" - "d2VzdC0xXzZlWDZZam1YciIsImNvZ25pdG86dXNlcm5hbWUiOiIyYzE3YzUwZC0xZDFlLTRhM2UtYmFjOS0zZ" - "DI0YjQ1MTFiYWEiLCJleHAiOjE1MzMyMDI3MzgsImlhdCI6MTUzMzE5OTEzOCwiZW1haWwiOiJqZW5raW5zQG" - "d1aC5pbyJ9.hMMSvZMx7pMvV70PaUmTZOZgdez5WGX5yagRFPZojBm8jNWZND1lUmi0RFkybeD4HonDiKHxTF" - "_psyJoBVndgHbxYBBl3Np4gn0MxECWjvLxYzGxVBBkN24SqNUyAGkr0uFcZKkBecdtJlqNQnZN8Uk49twmODf" - "raRaRmGmKmRBAK1qDITpUgP6AWqH9xoJWaoDzt0kwJ3EtPxS7vL1PHqOaN8ggXA8Eq4iTCSfXU1HAXhIWJH9Y" - "pQbj58v1vktaAEATdmKmlzmcix-HJK9wWHRSuv3TsNa8DGxvcPOoeTu8Vql7krZ-y7Zu-s2WsgeP4VxyT80VE" - "T_xh6pMkOhE6g"; - -} - -void RemoteProxyTests::cleanUpEngine() -{ - if (Engine::exists()) { - Engine::instance()->stop(); - Engine::instance()->destroy(); - QVERIFY(!Engine::exists()); - } -} - -void RemoteProxyTests::restartEngine() -{ - cleanUpEngine(); - startEngine(); -} - -void RemoteProxyTests::startEngine() -{ - if (!Engine::exists()) { - QString serverName = "nymea-remoteproxy-testserver"; - Engine::instance()->setAuthenticator(m_authenticator); - Engine::instance()->setServerName(serverName); - Engine::instance()->setConfiguration(m_configuration); - Engine::instance()->setSslConfiguration(m_sslConfiguration); - Engine::instance()->setDeveloperModeEnabled(true); - - QVERIFY(Engine::exists()); - QVERIFY(Engine::instance()->serverName() == serverName); - } -} - -void RemoteProxyTests::startServer() -{ - startEngine(); - - if (!Engine::instance()->running()) { - QSignalSpy runningSpy(Engine::instance(), &Engine::runningChanged); - Engine::instance()->setConfiguration(m_configuration); - Engine::instance()->setDeveloperModeEnabled(true); - Engine::instance()->start(); - runningSpy.wait(); - QVERIFY(runningSpy.count() == 1); - } - - QVERIFY(Engine::instance()->running()); - QVERIFY(Engine::instance()->webSocketServer()->running()); -} - -void RemoteProxyTests::stopServer() -{ - if (!Engine::instance()->running()) - return; - - Engine::instance()->stop(); - QVERIFY(!Engine::instance()->running()); -} - -QVariant RemoteProxyTests::invokeApiCall(const QString &method, const QVariantMap params, bool remainsConnected) -{ - Q_UNUSED(remainsConnected) - - QVariantMap request; - request.insert("id", m_commandCounter); - request.insert("method", method); - request.insert("params", params); - QJsonDocument jsonDoc = QJsonDocument::fromVariant(request); - - QWebSocket *socket = new QWebSocket("proxy-testclient", QWebSocketProtocol::Version13); - connect(socket, &QWebSocket::sslErrors, this, &RemoteProxyTests::sslErrors); - QSignalSpy spyConnection(socket, SIGNAL(connected())); - socket->open(Engine::instance()->webSocketServer()->serverUrl()); - spyConnection.wait(); - if (spyConnection.count() == 0) { - return QVariant(); - } - - QSignalSpy dataSpy(socket, SIGNAL(textMessageReceived(QString))); - socket->sendTextMessage(QString(jsonDoc.toJson(QJsonDocument::Compact))); - dataSpy.wait(); - - socket->close(); - socket->deleteLater(); - - for (int i = 0; i < dataSpy.count(); i++) { - // Make sure the response it a valid JSON string - QJsonParseError error; - jsonDoc = QJsonDocument::fromJson(dataSpy.at(i).last().toByteArray(), &error); - if (error.error != QJsonParseError::NoError) { - qWarning() << "JSON parser error" << error.errorString(); - return QVariant(); - } - QVariantMap response = jsonDoc.toVariant().toMap(); - - // skip notifications - if (response.contains("notification")) - continue; - - if (response.value("id").toInt() == m_commandCounter) { - m_commandCounter++; - return jsonDoc.toVariant(); - } - } - m_commandCounter++; - return QVariant(); -} - -QVariant RemoteProxyTests::injectSocketData(const QByteArray &data) -{ - QWebSocket *socket = new QWebSocket("proxy-testclient", QWebSocketProtocol::Version13); - connect(socket, &QWebSocket::sslErrors, this, &RemoteProxyTests::sslErrors); - QSignalSpy spyConnection(socket, SIGNAL(connected())); - socket->open(Engine::instance()->webSocketServer()->serverUrl()); - spyConnection.wait(); - if (spyConnection.count() == 0) { - return QVariant(); - } - - QSignalSpy spy(socket, SIGNAL(textMessageReceived(QString))); - socket->sendTextMessage(QString(data)); - spy.wait(); - - socket->close(); - socket->deleteLater(); - - for (int i = 0; i < spy.count(); i++) { - // Make sure the response it a valid JSON string - QJsonParseError error; - QJsonDocument jsonDoc = QJsonDocument::fromJson(spy.at(i).last().toByteArray(), &error); - if (error.error != QJsonParseError::NoError) { - qWarning() << "JSON parser error" << error.errorString(); - return QVariant(); - } - return jsonDoc.toVariant(); - } - m_commandCounter++; - return QVariant(); -} - -void RemoteProxyTests::initTestCase() -{ - qRegisterMetaType(); - qRegisterMetaType(); - qRegisterMetaType(); - - qCDebug(dcApplication()) << "Init test case."; - restartEngine(); -} - -void RemoteProxyTests::cleanupTestCase() -{ - qCDebug(dcApplication()) << "Clean up test case."; - cleanUpEngine(); } void RemoteProxyTests::startStopServer() @@ -213,6 +22,42 @@ void RemoteProxyTests::startStopServer() stopServer(); } +void RemoteProxyTests::dummyAuthenticator() +{ + cleanUpEngine(); + DummyAuthenticator *dummyAuthenticator = new DummyAuthenticator(this); + + // Start proxy webserver + Engine::instance()->setConfiguration(m_configuration); + Engine::instance()->setAuthenticator(dummyAuthenticator); + Engine::instance()->setSslConfiguration(m_sslConfiguration); + + QSignalSpy runningSpy(Engine::instance(), &Engine::runningChanged); + Engine::instance()->start(); + runningSpy.wait(); + + QVERIFY(runningSpy.count() == 1); + + // Make sure the server is not running + QVERIFY(Engine::instance()->running()); + + // Make sure the websocket server is not running + QVERIFY(Engine::instance()->webSocketServer()->running()); + + // Create request + QVariantMap params; + params.insert("uuid", QUuid::createUuid().toString()); + params.insert("name", "test"); + params.insert("token", "foobar"); + + QVariant response = invokeApiCall("Authentication.Authenticate", params); + qDebug() << qUtf8Printable(QJsonDocument::fromVariant(response).toJson(QJsonDocument::Indented)); + verifyAuthenticationError(response); + + dummyAuthenticator->deleteLater(); + cleanUpEngine(); +} + void RemoteProxyTests::webserverConnectionBlocked() { // Create a dummy server which blocks the port diff --git a/tests/offline/nymea-remoteproxy-tests-offline.h b/tests/offline/nymea-remoteproxy-tests-offline.h new file mode 100644 index 0000000..3406ddc --- /dev/null +++ b/tests/offline/nymea-remoteproxy-tests-offline.h @@ -0,0 +1,51 @@ +#ifndef NYMEA_REMOTEPROXY_TESTS_H +#define NYMEA_REMOTEPROXY_TESTS_H + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "basetest.h" + +using namespace remoteproxy; +using namespace remoteproxyclient; + +class RemoteProxyTests : public BaseTest +{ + Q_OBJECT +public: + explicit RemoteProxyTests(QObject *parent = nullptr); + +private slots: + // Basic stuff + void startStopServer(); + void dummyAuthenticator(); + + // WebSocket connection + void webserverConnectionBlocked(); + void webserverConnection(); + + // Api + void getIntrospect(); + void getHello(); + + void apiBasicCalls_data(); + void apiBasicCalls(); + + void authenticate_data(); + void authenticate(); + + // Client lib + void clientConnection(); + void remoteConnection(); + void sslConfigurations(); + void timeout(); + +}; + +#endif // NYMEA_REMOTEPROXY_TESTS_H diff --git a/tests/offline/offline.pro b/tests/offline/offline.pro new file mode 100644 index 0000000..51e64f3 --- /dev/null +++ b/tests/offline/offline.pro @@ -0,0 +1,14 @@ +include(../../nymea-remoteproxy.pri) +include(../testbase/testbase.pri) + +CONFIG += testcase +QT += testlib + +TARGET = nymea-remoteproxy-tests-offline + +HEADERS += nymea-remoteproxy-tests-offline.h + +SOURCES += nymea-remoteproxy-tests-offline.cpp + +target.path = /usr/bin +INSTALLS += target diff --git a/tests/online/online.pro b/tests/online/online.pro new file mode 100644 index 0000000..597d48e --- /dev/null +++ b/tests/online/online.pro @@ -0,0 +1,2 @@ +include(../../nymea-remoteproxy.pri) + diff --git a/tests/testbase/basetest.cpp b/tests/testbase/basetest.cpp new file mode 100644 index 0000000..740c3b7 --- /dev/null +++ b/tests/testbase/basetest.cpp @@ -0,0 +1,209 @@ +#include "basetest.h" + +#include "engine.h" +#include "loggingcategories.h" +#include "remoteproxyconnection.h" + +#include +#include +#include +#include +#include + +BaseTest::BaseTest(QObject *parent) : + QObject(parent) +{ + m_configuration = new ProxyConfiguration(this); + + QFile certificateFile(":/test-certificate.crt"); + if (!certificateFile.open(QIODevice::ReadOnly)) { + qWarning() << "Could not open resource file" << certificateFile.fileName(); + exit(1); + } + + QByteArray certificateData = certificateFile.readAll(); + //qDebug() << "Certificate:" << endl << qUtf8Printable(certificateData); + + QFile keyFile(":/test-certificate.key"); + if (!keyFile.open(QIODevice::ReadOnly)) { + qWarning() << "Could not open resource file" << keyFile.fileName(); + exit(1); + } + + QByteArray keyData = keyFile.readAll(); + //qDebug() << "Certificate key:" << endl << qUtf8Printable(keyData); + m_authenticator = new MockAuthenticator(this); + + m_sslConfiguration.setPrivateKey(QSslKey(keyData, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey)); + m_sslConfiguration.setLocalCertificate(QSslCertificate(certificateData, QSsl::Pem)); + m_sslConfiguration.setPeerVerifyMode(QSslSocket::VerifyNone); + m_sslConfiguration.setProtocol(QSsl::TlsV1_2OrLater); + + m_testToken = "eyJraWQiOiJXdnFFT3prVVh5VDlINzFyRUpoNWdxRnkxNFhnR2l3SFAzVEIzUFQ1V3ZrPSIsImFsZyI6IlJT" + "MjU2In0.eyJzdWIiOiJmZTJmZDNlNC1hMGJhLTQ1OTUtOWRiZS00ZDkxYjRiMjFlMzUiLCJhdWQiOiI4cmpoZ" + "mRsZjlqZjFzdW9rMmpjcmx0ZDZ2IiwiZW1haWxfdmVyaWZpZWQiOnRydWUsImV2ZW50X2lkIjoiN2Y5NTRiNm" + "ItOTYyZi0xMWU4LWI0ZjItMzU5NWRiZmRiODVmIiwidG9rZW5fdXNlIjoiaWQiLCJhdXRoX3RpbWUiOjE1MzM" + "xOTkxMzgsImlzcyI6Imh0dHBzOlwvXC9jb2duaXRvLWlkcC5ldS13ZXN0LTEuYW1hem9uYXdzLmNvbVwvZXUt" + "d2VzdC0xXzZlWDZZam1YciIsImNvZ25pdG86dXNlcm5hbWUiOiIyYzE3YzUwZC0xZDFlLTRhM2UtYmFjOS0zZ" + "DI0YjQ1MTFiYWEiLCJleHAiOjE1MzMyMDI3MzgsImlhdCI6MTUzMzE5OTEzOCwiZW1haWwiOiJqZW5raW5zQG" + "d1aC5pbyJ9.hMMSvZMx7pMvV70PaUmTZOZgdez5WGX5yagRFPZojBm8jNWZND1lUmi0RFkybeD4HonDiKHxTF" + "_psyJoBVndgHbxYBBl3Np4gn0MxECWjvLxYzGxVBBkN24SqNUyAGkr0uFcZKkBecdtJlqNQnZN8Uk49twmODf" + "raRaRmGmKmRBAK1qDITpUgP6AWqH9xoJWaoDzt0kwJ3EtPxS7vL1PHqOaN8ggXA8Eq4iTCSfXU1HAXhIWJH9Y" + "pQbj58v1vktaAEATdmKmlzmcix-HJK9wWHRSuv3TsNa8DGxvcPOoeTu8Vql7krZ-y7Zu-s2WsgeP4VxyT80VE" + "T_xh6pMkOhE6g"; + +} + +void BaseTest::cleanUpEngine() +{ + if (Engine::exists()) { + Engine::instance()->stop(); + Engine::instance()->destroy(); + QVERIFY(!Engine::exists()); + } +} + +void BaseTest::restartEngine() +{ + cleanUpEngine(); + startEngine(); +} + +void BaseTest::startEngine() +{ + if (!Engine::exists()) { + QString serverName = "nymea-remoteproxy-testserver"; + Engine::instance()->setAuthenticator(m_authenticator); + Engine::instance()->setServerName(serverName); + Engine::instance()->setConfiguration(m_configuration); + Engine::instance()->setSslConfiguration(m_sslConfiguration); + Engine::instance()->setDeveloperModeEnabled(true); + + QVERIFY(Engine::exists()); + QVERIFY(Engine::instance()->serverName() == serverName); + } +} + +void BaseTest::startServer() +{ + startEngine(); + + if (!Engine::instance()->running()) { + QSignalSpy runningSpy(Engine::instance(), &Engine::runningChanged); + Engine::instance()->setConfiguration(m_configuration); + Engine::instance()->setDeveloperModeEnabled(true); + Engine::instance()->start(); + runningSpy.wait(); + QVERIFY(runningSpy.count() == 1); + } + + QVERIFY(Engine::instance()->running()); + QVERIFY(Engine::instance()->webSocketServer()->running()); +} + +void BaseTest::stopServer() +{ + if (!Engine::instance()->running()) + return; + + Engine::instance()->stop(); + QVERIFY(!Engine::instance()->running()); +} + +QVariant BaseTest::invokeApiCall(const QString &method, const QVariantMap params, bool remainsConnected) +{ + Q_UNUSED(remainsConnected) + + QVariantMap request; + request.insert("id", m_commandCounter); + request.insert("method", method); + request.insert("params", params); + QJsonDocument jsonDoc = QJsonDocument::fromVariant(request); + + QWebSocket *socket = new QWebSocket("proxy-testclient", QWebSocketProtocol::Version13); + connect(socket, &QWebSocket::sslErrors, this, &BaseTest::sslErrors); + QSignalSpy spyConnection(socket, SIGNAL(connected())); + socket->open(Engine::instance()->webSocketServer()->serverUrl()); + spyConnection.wait(); + if (spyConnection.count() == 0) { + return QVariant(); + } + + QSignalSpy dataSpy(socket, SIGNAL(textMessageReceived(QString))); + socket->sendTextMessage(QString(jsonDoc.toJson(QJsonDocument::Compact))); + dataSpy.wait(); + + socket->close(); + socket->deleteLater(); + + for (int i = 0; i < dataSpy.count(); i++) { + // Make sure the response it a valid JSON string + QJsonParseError error; + jsonDoc = QJsonDocument::fromJson(dataSpy.at(i).last().toByteArray(), &error); + if (error.error != QJsonParseError::NoError) { + qWarning() << "JSON parser error" << error.errorString(); + return QVariant(); + } + QVariantMap response = jsonDoc.toVariant().toMap(); + + // skip notifications + if (response.contains("notification")) + continue; + + if (response.value("id").toInt() == m_commandCounter) { + m_commandCounter++; + return jsonDoc.toVariant(); + } + } + m_commandCounter++; + return QVariant(); +} + +QVariant BaseTest::injectSocketData(const QByteArray &data) +{ + QWebSocket *socket = new QWebSocket("proxy-testclient", QWebSocketProtocol::Version13); + connect(socket, &QWebSocket::sslErrors, this, &BaseTest::sslErrors); + QSignalSpy spyConnection(socket, SIGNAL(connected())); + socket->open(Engine::instance()->webSocketServer()->serverUrl()); + spyConnection.wait(); + if (spyConnection.count() == 0) { + return QVariant(); + } + + QSignalSpy spy(socket, SIGNAL(textMessageReceived(QString))); + socket->sendTextMessage(QString(data)); + spy.wait(); + + socket->close(); + socket->deleteLater(); + + for (int i = 0; i < spy.count(); i++) { + // Make sure the response it a valid JSON string + QJsonParseError error; + QJsonDocument jsonDoc = QJsonDocument::fromJson(spy.at(i).last().toByteArray(), &error); + if (error.error != QJsonParseError::NoError) { + qWarning() << "JSON parser error" << error.errorString(); + return QVariant(); + } + return jsonDoc.toVariant(); + } + m_commandCounter++; + return QVariant(); +} + +void BaseTest::initTestCase() +{ + qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); + + qCDebug(dcApplication()) << "Init test case."; + restartEngine(); +} + +void BaseTest::cleanupTestCase() +{ + qCDebug(dcApplication()) << "Clean up test case."; + cleanUpEngine(); +} + diff --git a/tests/nymea-remoteproxy-tests.h b/tests/testbase/basetest.h similarity index 77% rename from tests/nymea-remoteproxy-tests.h rename to tests/testbase/basetest.h index ceebea9..999bb4b 100644 --- a/tests/nymea-remoteproxy-tests.h +++ b/tests/testbase/basetest.h @@ -1,7 +1,7 @@ -#ifndef NYMEA_REMOTEPROXY_TESTS_H -#define NYMEA_REMOTEPROXY_TESTS_H +#ifndef BASETEST_H +#define BASETEST_H -#include +#include #include #include #include @@ -14,17 +14,18 @@ #include "mockauthenticator.h" #include "proxyconfiguration.h" #include "remoteproxyconnection.h" +#include "authentication/dummyauthenticator.h" using namespace remoteproxy; using namespace remoteproxyclient; -class RemoteProxyTests : public QObject +class BaseTest : public QObject { Q_OBJECT public: - explicit RemoteProxyTests(QObject *parent = nullptr); + explicit BaseTest(QObject *parent = nullptr); -private: +protected: ProxyConfiguration *m_configuration = nullptr; quint16 m_port = 1212; @@ -49,31 +50,6 @@ protected slots: void initTestCase(); void cleanupTestCase(); -private slots: - // Basic stuff - void startStopServer(); - - // WebSocket connection - void webserverConnectionBlocked(); - void webserverConnection(); - - // Api - void getIntrospect(); - void getHello(); - - void apiBasicCalls_data(); - void apiBasicCalls(); - - void authenticate_data(); - void authenticate(); - - // Client lib - void clientConnection(); - void remoteConnection(); - void sslConfigurations(); - void timeout(); - - public slots: void sslErrors(const QList &) { @@ -103,6 +79,7 @@ public slots: } + }; -#endif // NYMEA_REMOTEPROXY_TESTS_H +#endif // BASETEST_H diff --git a/tests/mockauthenticator.cpp b/tests/testbase/mockauthenticator.cpp similarity index 100% rename from tests/mockauthenticator.cpp rename to tests/testbase/mockauthenticator.cpp diff --git a/tests/mockauthenticator.h b/tests/testbase/mockauthenticator.h similarity index 100% rename from tests/mockauthenticator.h rename to tests/testbase/mockauthenticator.h diff --git a/tests/testbase/testbase.pri b/tests/testbase/testbase.pri new file mode 100644 index 0000000..c7462c2 --- /dev/null +++ b/tests/testbase/testbase.pri @@ -0,0 +1,14 @@ +RESOURCES += ../certificate.qrc + +INCLUDEPATH += $${PWD} $$top_srcdir/libnymea-remoteproxy $$top_srcdir/libnymea-remoteproxyclient +LIBS += -L$$top_builddir/libnymea-remoteproxy/ -lnymea-remoteproxy \ + -L$$top_builddir/libnymea-remoteproxyclient/ -lnymea-remoteproxyclient \ + +HEADERS += \ + $${PWD}/basetest.h \ + $${PWD}/mockauthenticator.h \ + +SOURCES += \ + $${PWD}/basetest.cpp \ + $${PWD}/mockauthenticator.cpp \ + diff --git a/tests/tests.pro b/tests/tests.pro index 0ee4bf8..f46ccaf 100644 --- a/tests/tests.pro +++ b/tests/tests.pro @@ -1,20 +1,4 @@ -include(../nymea-remoteproxy.pri) +TEMPLATE=subdirs +SUBDIRS += offline -CONFIG += testcase -QT += testlib -TARGET = nymea-remoteproxy-tests - -INCLUDEPATH += ../libnymea-remoteproxy ../libnymea-remoteproxyclient -LIBS += -L$$top_builddir/libnymea-remoteproxy/ -lnymea-remoteproxy \ - -L$$top_builddir/libnymea-remoteproxyclient/ -lnymea-remoteproxyclient \ - -RESOURCES += certificate.qrc - -HEADERS += nymea-remoteproxy-tests.h \ - mockauthenticator.h -SOURCES += nymea-remoteproxy-tests.cpp \ - mockauthenticator.cpp - -target.path = /usr/bin -INSTALLS += target