File indexing completed on 2025-01-19 03:57:46
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2011-03-22 0007 * Description : a MediaWiki C++ interface 0008 * 0009 * SPDX-FileCopyrightText: 2011-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * SPDX-FileCopyrightText: 2011 by Alexandre Mendes <alex dot mendes1988 at gmail dot com> 0011 * SPDX-FileCopyrightText: 2011 by Hormiere Guillaume <hormiere dot guillaume at gmail dot com> 0012 * SPDX-FileCopyrightText: 2011 by Manuel Campomanes <campomanes dot manuel at gmail dot com> 0013 * 0014 * SPDX-License-Identifier: GPL-2.0-or-later 0015 * 0016 * ============================================================ */ 0017 0018 #ifndef DIGIKAM_MEDIAWIKI_FAKE_SERVER_H 0019 #define DIGIKAM_MEDIAWIKI_FAKE_SERVER_H 0020 0021 // Qt includes 0022 0023 #include <QList> 0024 #include <QMutex> 0025 #include <QObject> 0026 #include <QString> 0027 #include <QStringList> 0028 #include <QThread> 0029 #include <QTcpServer> 0030 #include <QTcpSocket> 0031 0032 class FakeServer : QThread 0033 { 0034 Q_OBJECT 0035 0036 public: 0037 0038 class Request 0039 { 0040 public: 0041 0042 Request() 0043 { 0044 } 0045 0046 Request(const QString& t, const QString& a, const QString& v) 0047 : type (t), 0048 agent(a), 0049 value(v) 0050 { 0051 } 0052 0053 bool operator==(const FakeServer::Request &other) const 0054 { 0055 return ( 0056 (this->type == other.type) && 0057 (this->agent == other.agent) && 0058 (this->value == other.value) 0059 ); 0060 } 0061 0062 public: 0063 0064 QString type; 0065 QString agent; 0066 QString value; 0067 }; 0068 0069 public: 0070 0071 explicit FakeServer(QObject* const parent = nullptr); 0072 ~FakeServer() override; 0073 0074 void startAndWait(); 0075 void run() override; 0076 0077 void setScenario(const QString& scenario, const QString& cookie = QStringLiteral("empty")); 0078 void addScenario(const QString& scenario, const QString& cookie = QStringLiteral("empty")); 0079 void addScenarioFromFile(const QString& fileName, const QString& cookie = QStringLiteral("empty")); 0080 0081 bool isScenarioDone(int scenarioNumber) const; 0082 bool isAllScenarioDone() const; 0083 0084 const QList<FakeServer::Request>& getRequest(); 0085 FakeServer::Request takeLastRequest(); 0086 FakeServer::Request takeFirstRequest(); 0087 void clearRequest(); 0088 0089 private Q_SLOTS: 0090 0091 void newConnection(); 0092 void dataAvailable(); 0093 void started(); 0094 0095 private: 0096 0097 QStringList m_scenarios; 0098 QStringList m_cookie; 0099 QList<FakeServer::Request> m_request; 0100 QTcpServer* m_tcpServer; 0101 mutable QMutex m_mutex; 0102 QTcpSocket* m_clientSocket; 0103 }; 0104 0105 #endif // DIGIKAM_MEDIAWIKI_FAKE_SERVER_H