| 1 |
/* ============================================================ |
| 2 |
* |
| 3 |
* This file is a part of digiKam project |
| 4 |
* https://www.digikam.org |
| 5 |
* |
| 6 |
* Date : 2011-03-22 |
| 7 |
* Description : a MediaWiki C++ interface |
| 8 |
* |
| 9 |
* SPDX-FileCopyrightText: 2011-2026 by Gilles Caulier <caulier dot gilles at gmail dot com> |
| 10 |
* SPDX-FileCopyrightText: 2011 by Alexandre Mendes <alex dot mendes1988 at gmail dot com> |
| 11 |
* SPDX-FileCopyrightText: 2011 by Hormiere Guillaume <hormiere dot guillaume at gmail dot com> |
| 12 |
* SPDX-FileCopyrightText: 2011 by Manuel Campomanes <campomanes dot manuel at gmail dot com> |
| 13 |
* |
| 14 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 15 |
* |
| 16 |
* ============================================================ */ |
| 17 |
|
| 18 |
#pragma once |
| 19 |
|
| 20 |
// Qt includes |
| 21 |
|
| 22 |
#include <QList> |
| 23 |
#include <QMutex> |
| 24 |
#include <QObject> |
| 25 |
#include <QString> |
| 26 |
#include <QStringList> |
| 27 |
#include <QThread> |
| 28 |
#include <QTcpServer> |
| 29 |
#include <QTcpSocket> |
| 30 |
|
| 31 |
class FakeServer : QThread |
| 32 |
{ |
| 33 |
Q_OBJECT |
| 34 |
|
| 35 |
public: |
| 36 |
|
| 37 |
class Request |
| 38 |
{ |
| 39 |
public: |
| 40 |
|
| 41 |
Request() |
| 42 |
{ |
| 43 |
} |
| 44 |
|
| 45 |
Request(const QString& t, const QString& a, const QString& v) |
| 46 |
: type (t), |
| 47 |
agent(a), |
| 48 |
value(v) |
| 49 |
{ |
| 50 |
} |
| 51 |
|
| 52 |
bool operator==(const FakeServer::Request &other) const |
| 53 |
{ |
| 54 |
return ( |
| 55 |
(this->type == other.type) && |
| 56 |
(this->agent == other.agent) && |
| 57 |
(this->value == other.value) |
| 58 |
); |
| 59 |
} |
| 60 |
|
| 61 |
public: |
| 62 |
|
| 63 |
QString type; |
| 64 |
QString agent; |
| 65 |
QString value; |
| 66 |
}; |
| 67 |
|
| 68 |
public: |
| 69 |
|
| 70 |
explicit FakeServer(QObject* const parent = nullptr); |
| 71 |
~FakeServer() override; |
| 72 |
|
| 73 |
void startAndWait(); |
| 74 |
void run() override; |
| 75 |
|
| 76 |
void setScenario(const QString& scenario, const QString& cookie = QStringLiteral("empty")); |
| 77 |
void addScenario(const QString& scenario, const QString& cookie = QStringLiteral("empty")); |
| 78 |
void addScenarioFromFile(const QString& fileName, const QString& cookie = QStringLiteral("empty")); |
| 79 |
|
| 80 |
bool isScenarioDone(int scenarioNumber) const; |
| 81 |
bool isAllScenarioDone() const; |
| 82 |
|
| 83 |
const QList<FakeServer::Request>& getRequest(); |
| 84 |
FakeServer::Request takeLastRequest(); |
| 85 |
FakeServer::Request takeFirstRequest(); |
| 86 |
void clearRequest(); |
| 87 |
|
| 88 |
private Q_SLOTS: |
| 89 |
|
| 90 |
void newConnection(); |
| 91 |
void dataAvailable(); |
| 92 |
void started(); |
| 93 |
|
| 94 |
private: |
| 95 |
|
| 96 |
QStringList m_scenarios; |
| 97 |
QStringList m_cookie; |
| 98 |
QList<FakeServer::Request> m_request; |
| 99 |
QTcpServer* m_tcpServer = nullptr; |
| 100 |
mutable QMutex m_mutex; |
| 101 |
QTcpSocket* m_clientSocket = nullptr; |
| 102 |
}; |