| 1 |
// SPDX-License-Identifier: GPL-3.0-or-later |
| 2 |
|
| 3 |
#pragma once |
| 4 |
|
| 5 |
|
| 6 |
#include "common/clipboardmode.h" |
| 7 |
|
| 8 |
#include <QByteArray> |
| 9 |
#include <QStringList> |
| 10 |
#include <QVariant> |
| 11 |
#include <QtContainerFwd> |
| 12 |
|
| 13 |
#include <memory> |
| 14 |
|
| 15 |
class QRegularExpression; |
| 16 |
class QProcess; |
| 17 |
|
| 18 |
/** |
| 19 |
* Interface for tests. |
| 20 |
*/ |
| 21 |
class TestInterface { |
| 22 |
public: |
| 23 |
enum ReadStderrFlag { |
| 24 |
// Read errors from stderr (lines with "Error:", "Warning:" and similar). |
| 25 |
ReadErrors = 0, |
| 26 |
// Read all stderr. |
| 27 |
ReadAllStderr = 1, |
| 28 |
}; |
| 29 |
|
| 30 |
TestInterface() = default; |
| 31 |
|
| 32 |
virtual ~TestInterface() = default; |
| 33 |
|
| 34 |
/// Start or restart GUI server and return true if successful. |
| 35 |
virtual QByteArray startServer() = 0; |
| 36 |
|
| 37 |
/// Stop GUI server and return true if server is was stopped or is not running. |
| 38 |
virtual QByteArray stopServer() = 0; |
| 39 |
|
| 40 |
/// Returns an error if server doesn't stop after some interval. |
| 41 |
virtual QByteArray waitForServerToStop() = 0; |
| 42 |
|
| 43 |
/// Return true if GUI server is not running. |
| 44 |
virtual bool isServerRunning() = 0; |
| 45 |
|
| 46 |
virtual QString executable() = 0; |
| 47 |
|
| 48 |
/// Run client with given @a arguments and input and read outputs and return exit code. |
| 49 |
virtual int run(const QStringList &arguments, QByteArray *stdoutData = nullptr, |
| 50 |
QByteArray *stderrData = nullptr, const QByteArray &in = QByteArray(), |
| 51 |
const QStringList &environment = QStringList()) = 0; |
| 52 |
|
| 53 |
/// Run client with given @a arguments and read all errors/warnings. |
| 54 |
virtual QByteArray runClient(const QStringList &arguments, const QByteArray &stdoutExpected, |
| 55 |
const QByteArray &input = QByteArray()) = 0; |
| 56 |
|
| 57 |
/// Run client with given @a arguments and expect errors/warnings on server and client side. |
| 58 |
virtual QByteArray runClientWithError(const QStringList &arguments, int expectedExitCode, |
| 59 |
const QByteArray &stderrContains = QByteArray()) = 0; |
| 60 |
|
| 61 |
/// Run client with given @a arguments and read output, check stderr and exit code. |
| 62 |
virtual QByteArray getClientOutput(const QStringList &arguments, QByteArray *stdoutActual) = 0; |
| 63 |
|
| 64 |
/// Waits on client output. |
| 65 |
virtual QByteArray waitOnOutput(const QStringList &arguments, const QByteArray &stdoutExpected) = 0; |
| 66 |
|
| 67 |
/// Set clipboard through monitor process. |
| 68 |
virtual QByteArray setClipboard(const QMap<QString, QVariant> &data, ClipboardMode mode = ClipboardMode::Clipboard) = 0; |
| 69 |
|
| 70 |
/// Set clipboard through monitor process. |
| 71 |
virtual QByteArray setClipboard( |
| 72 |
const QByteArray &bytes, |
| 73 |
const QString &mime = QLatin1String("text/plain"), |
| 74 |
ClipboardMode mode = ClipboardMode::Clipboard) = 0; |
| 75 |
|
| 76 |
/// Verify clipboard content. |
| 77 |
virtual QByteArray verifyClipboard(const QByteArray &data, const QString &mime, bool exact = true) = 0; |
| 78 |
|
| 79 |
/** |
| 80 |
* Return errors/warning from server (otherwise empty output). |
| 81 |
* If @a readAll is set, read all stderr. |
| 82 |
*/ |
| 83 |
virtual QByteArray readServerErrors(ReadStderrFlag flag = ReadErrors) = 0; |
| 84 |
|
| 85 |
/// Init test case. Return error string on error. |
| 86 |
virtual QByteArray initTestCase() = 0; |
| 87 |
|
| 88 |
/// Clean up test case. Return error string on error. |
| 89 |
virtual QByteArray cleanupTestCase() = 0; |
| 90 |
|
| 91 |
/// Init test. Return error string on error. |
| 92 |
virtual QByteArray init() = 0; |
| 93 |
|
| 94 |
/// Clean up tabs and items. Return error string on error. |
| 95 |
virtual QByteArray cleanup() = 0; |
| 96 |
|
| 97 |
/// Platform specific key to remove (usually Delete, Backspace on OS X). |
| 98 |
virtual QString shortcutToRemove() = 0; |
| 99 |
|
| 100 |
/// Set environment variable for test. |
| 101 |
virtual void setEnv(const QString &name, const QString &value) = 0; |
| 102 |
|
| 103 |
/// Ignore specific client and server errors. |
| 104 |
virtual void ignoreErrors(const QRegularExpression &re) = 0; |
| 105 |
|
| 106 |
virtual bool writeOutErrors(const QByteArray &errors) = 0; |
| 107 |
|
| 108 |
/// Start a client process with the given arguments without waiting for completion. |
| 109 |
virtual bool startClient(QProcess *p, const QStringList &arguments) = 0; |
| 110 |
|
| 111 |
TestInterface(const TestInterface &) = delete; |
| 112 |
TestInterface &operator=(const TestInterface &) = delete; |
| 113 |
}; |
| 114 |
|
| 115 |
using TestInterfacePtr = std::shared_ptr<TestInterface>; |