95 lines
3.0 KiB
C++
95 lines
3.0 KiB
C++
#include <QtTest>
|
|
|
|
#include "moonlight_session.h"
|
|
|
|
using namespace vdi;
|
|
|
|
class MoonlightSessionTest : public QObject {
|
|
Q_OBJECT
|
|
|
|
private slots:
|
|
void parsesSplitReadyMarkers();
|
|
void requiresBothReadyMarkers();
|
|
void rejectsSecondStart();
|
|
};
|
|
|
|
void MoonlightSessionTest::parsesSplitReadyMarkers() {
|
|
MoonlightOutputParser parser;
|
|
parser.append("Test decode succ");
|
|
QVERIFY(!parser.isReady());
|
|
parser.append("essful\nRenderer 'SDL' with 'DRM' backend ");
|
|
QVERIFY(parser.hasTestDecode());
|
|
QVERIFY(!parser.hasRenderer());
|
|
parser.append("chosen\n");
|
|
QVERIFY(parser.isReady());
|
|
}
|
|
|
|
void MoonlightSessionTest::requiresBothReadyMarkers() {
|
|
MoonlightOutputParser parser;
|
|
parser.append("Test decode successful\n");
|
|
QVERIFY(!parser.isReady());
|
|
|
|
parser.reset();
|
|
parser.append("Renderer 'SDL' chosen\n");
|
|
QVERIFY(!parser.isReady());
|
|
|
|
parser.append("Connection terminated: -1\n");
|
|
QVERIFY(parser.hasTerminalError());
|
|
QVERIFY(!parser.isReady());
|
|
}
|
|
|
|
void MoonlightSessionTest::rejectsSecondStart() {
|
|
QTemporaryDir tempDir;
|
|
QVERIFY(tempDir.isValid());
|
|
|
|
const QString executable = tempDir.filePath(QStringLiteral("moonlight-qt"));
|
|
QFile script(executable);
|
|
QVERIFY(script.open(QIODevice::WriteOnly | QIODevice::Text));
|
|
script.write("#!/bin/sh\n"
|
|
"printf 'Test decode successful\\n'\n"
|
|
"printf \"Renderer 'SDL' with 'DRM' backend chosen\\n\"\n"
|
|
"sleep 5\n");
|
|
script.close();
|
|
QVERIFY(script.setPermissions(QFileDevice::ReadOwner | QFileDevice::WriteOwner |
|
|
QFileDevice::ExeOwner | QFileDevice::ReadGroup |
|
|
QFileDevice::ExeGroup | QFileDevice::ReadOther |
|
|
QFileDevice::ExeOther));
|
|
|
|
const QByteArray oldPath = qgetenv("PATH");
|
|
qputenv("PATH", tempDir.path().toUtf8() + ':' + oldPath);
|
|
|
|
ConnectionTicket ticket;
|
|
ticket.endpoint = QStringLiteral("127.0.0.1");
|
|
ticket.app = QStringLiteral("Desktop");
|
|
|
|
MoonlightSession session;
|
|
int started = 0;
|
|
int ready = 0;
|
|
int terminal = 0;
|
|
const auto callback = [&](const MoonlightSession::Event& event) {
|
|
if (event.type == MoonlightSession::EventType::kStarted) {
|
|
++started;
|
|
} else if (event.type == MoonlightSession::EventType::kStreamReady) {
|
|
++ready;
|
|
} else if (event.type == MoonlightSession::EventType::kFailed ||
|
|
event.type == MoonlightSession::EventType::kFinished) {
|
|
++terminal;
|
|
}
|
|
};
|
|
|
|
QVERIFY(session.start(ticket, callback));
|
|
QTRY_COMPARE_WITH_TIMEOUT(started, 1, 2000);
|
|
QVERIFY(!session.start(ticket, callback));
|
|
QTRY_COMPARE_WITH_TIMEOUT(ready, 1, 3000);
|
|
|
|
session.stop();
|
|
QTRY_COMPARE_WITH_TIMEOUT(terminal, 1, 4000);
|
|
QCOMPARE(ready, 1);
|
|
QCOMPARE(terminal, 1);
|
|
|
|
qputenv("PATH", oldPath);
|
|
}
|
|
|
|
QTEST_GUILESS_MAIN(MoonlightSessionTest)
|
|
#include "test_moonlight_session.moc"
|