File indexing completed on 2024-06-09 05:21:30
0001 /* Copyright (C) 2006 - 2014 Jan Kundrát <jkt@flaska.net> 0002 0003 This file is part of the Trojita Qt IMAP e-mail client, 0004 http://trojita.flaska.net/ 0005 0006 This program is free software; you can redistribute it and/or 0007 modify it under the terms of the GNU General Public License as 0008 published by the Free Software Foundation; either version 2 of 0009 the License or (at your option) version 3 or any later version 0010 accepted by the membership of KDE e.V. (or its successor approved 0011 by the membership of KDE e.V.), which shall act as a proxy 0012 defined in Section 14 of version 3 of the license. 0013 0014 This program is distributed in the hope that it will be useful, 0015 but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0017 GNU General Public License for more details. 0018 0019 You should have received a copy of the GNU General Public License 0020 along with this program. If not, see <http://www.gnu.org/licenses/>. 0021 */ 0022 0023 #ifndef STREAMS_FAKE_SOCKET_H 0024 #define STREAMS_FAKE_SOCKET_H 0025 0026 #include <QAbstractSocket> 0027 #include <QProcess> 0028 #include "Socket.h" 0029 0030 class QTimer; 0031 0032 namespace Streams { 0033 0034 /** @short A fake socket implementation, useful for automated unit tests 0035 0036 See the unit tests in tests/ for how to use this class. 0037 */ 0038 class FakeSocket: public Socket 0039 { 0040 Q_OBJECT 0041 public: 0042 explicit FakeSocket(const Imap::ConnectionState initialState); 0043 ~FakeSocket(); 0044 bool canReadLine() override; 0045 QByteArray read(qint64 maxSize) override; 0046 QByteArray readLine(qint64 maxSize = 0) override; 0047 qint64 write(const QByteArray &byteArray) override; 0048 void startTls() override; 0049 void startDeflate() override; 0050 bool isDead() override; 0051 void close() override; 0052 0053 /** @short Return data written since the last call to this function */ 0054 QByteArray writtenStuff(); 0055 0056 private slots: 0057 /** @short Delayed informing about being connected */ 0058 void slotEmitConnected(); 0059 /** @short Delayed informing about being encrypted */ 0060 void slotEmitEncrypted(); 0061 0062 public slots: 0063 /** @short Simulate arrival of some data 0064 0065 The provided @arg what data are appended to the internal buffer and relevant signals 0066 are emitted. This function currently does not free the occupied memory, which might 0067 eventually lead to certain troubles. 0068 */ 0069 void fakeReading(const QByteArray &what); 0070 0071 void fakeDisconnect(const QString &message); 0072 0073 private: 0074 QIODevice *readChannel; 0075 QIODevice *writeChannel; 0076 0077 QByteArray r, w; 0078 0079 Imap::ConnectionState m_initialState; 0080 0081 FakeSocket(const FakeSocket &); // don't implement 0082 FakeSocket &operator=(const FakeSocket &); // don't implement 0083 }; 0084 0085 }; 0086 0087 #endif