97 lines
1.7 KiB
C++
97 lines
1.7 KiB
C++
/*!
|
|
* \copyright Copyright (c) 2015-2018 Governikus GmbH & Co. KG, Germany
|
|
*/
|
|
|
|
#include "MockNetworkManager.h"
|
|
|
|
#include <http_parser.h>
|
|
#include <QTest>
|
|
|
|
using namespace governikus;
|
|
|
|
|
|
MockNetworkManager::MockNetworkManager()
|
|
: mNextReply(nullptr)
|
|
, mLastReply(nullptr)
|
|
, mLastRequest(nullptr)
|
|
{
|
|
}
|
|
|
|
|
|
MockNetworkManager::~MockNetworkManager()
|
|
{
|
|
}
|
|
|
|
|
|
MockNetworkReply* MockNetworkManager::getReply(const QNetworkRequest& pRequest)
|
|
{
|
|
if (mNextReply)
|
|
{
|
|
mLastReply = mNextReply;
|
|
mNextReply = nullptr;
|
|
}
|
|
else
|
|
{
|
|
QByteArray content;
|
|
if (!mFilename.isNull())
|
|
{
|
|
QFile msgFile(mFilename);
|
|
if (msgFile.open(QIODevice::ReadOnly | QIODevice::Text))
|
|
{
|
|
content = msgFile.readAll();
|
|
msgFile.close();
|
|
}
|
|
|
|
mLastReply = new MockNetworkReply(content, HTTP_STATUS_OK);
|
|
}
|
|
else
|
|
{
|
|
mLastReply = new MockNetworkReply();
|
|
}
|
|
}
|
|
|
|
mLastReply->setRequest(pRequest);
|
|
Q_EMIT fireReply();
|
|
return mLastReply;
|
|
}
|
|
|
|
|
|
QNetworkReply* MockNetworkManager::get(QNetworkRequest& pRequest,
|
|
const QByteArray& pSslSession,
|
|
int pTimeoutInMilliSeconds)
|
|
{
|
|
Q_UNUSED(pRequest);
|
|
Q_UNUSED(pSslSession);
|
|
Q_UNUSED(pTimeoutInMilliSeconds);
|
|
|
|
mLastRequest = &pRequest;
|
|
|
|
return getReply(pRequest);
|
|
}
|
|
|
|
|
|
QNetworkReply* MockNetworkManager::paos(QNetworkRequest& pRequest,
|
|
const QByteArray& pNamespace,
|
|
const QByteArray& pData,
|
|
bool pUsePsk,
|
|
const QByteArray& pSslSession,
|
|
int pTimeoutInMilliSeconds)
|
|
{
|
|
Q_UNUSED(pRequest);
|
|
Q_UNUSED(pNamespace);
|
|
Q_UNUSED(pData);
|
|
Q_UNUSED(pUsePsk);
|
|
Q_UNUSED(pSslSession);
|
|
Q_UNUSED(pTimeoutInMilliSeconds);
|
|
|
|
return getReply(pRequest);
|
|
}
|
|
|
|
|
|
bool MockNetworkManager::checkUpdateServerCertificate(const QNetworkReply& pReply)
|
|
{
|
|
Q_UNUSED(pReply);
|
|
|
|
return true;
|
|
}
|