Commit 7a35124f authored by Martin Tobias Holmedahl Sandsmark's avatar Martin Tobias Holmedahl Sandsmark Committed by Tomaz Canabrava
Browse files

Implement actual testing of Vt102 emulator

parent bd7134a6
......@@ -234,6 +234,8 @@ void Emulation::sendKeyEvent(QKeyEvent *ev)
void Emulation::receiveData(const char *text, int length)
{
Q_ASSERT(_decoder);
bufferedUpdate();
//send characters to terminal emulator
......
......@@ -1237,6 +1237,7 @@ void Vt102Emulation::sendKeyEvent(QKeyEvent *event)
} else if (!entry.text().isEmpty()) {
textToSend += entry.text(true,modifiers);
} else {
Q_ASSERT(_codec);
textToSend += _codec->fromUnicode(event->text());
}
......
......@@ -75,6 +75,37 @@ constexpr int token_csi_pe(int a)
return token_construct(10, a, 0);
}
void Vt102EmulationTest::sendAndCompare(TestEmulation *em,
const char *input,
size_t inputLen,
const QString &expectedPrint,
const QByteArray &expectedSent
)
{
em->_currentScreen->clearEntireScreen();
em->receiveData(input, inputLen);
QString printed = em->_currentScreen->text(0, em->_currentScreen->getColumns(), Screen::PlainText);
printed.chop(2); // Remove trailing space and newline
QCOMPARE(printed, expectedPrint);
QCOMPARE(em->lastSent, expectedSent);
}
void Vt102EmulationTest::testParse()
{
TestEmulation em;
em.setCodec(TestEmulation::Utf8Codec);
Q_ASSERT(em._currentScreen != nullptr);
sendAndCompare(&em, "a", 1, QStringLiteral("a"), "");
const char tertiaryDeviceAttributes[] = {
0x1b, '[', '=', '0', 'c'
};
QEXPECT_FAIL("", "Fixed by https://invent.kde.org/utilities/konsole/-/merge_requests/416", Abort);
sendAndCompare(&em, tertiaryDeviceAttributes, sizeof tertiaryDeviceAttributes, QStringLiteral(""), "\033P!|00000000\033\\");
}
void Vt102EmulationTest::testTokenFunctions()
{
QCOMPARE(token_construct(0, 0, 0), TY_CONSTRUCT(0, 0, 0));
......
......@@ -9,9 +9,13 @@
#include <QObject>
#include "Vt102Emulation.h"
namespace Konsole
{
class TestEmulation;
class Vt102EmulationTest : public QObject
{
Q_OBJECT
......@@ -19,7 +23,28 @@ class Vt102EmulationTest : public QObject
private Q_SLOTS:
void testTokenFunctions();
void testParse();
private:
static void sendAndCompare(TestEmulation *em,
const char *input, size_t inputLen,
const QString &expectedPrint,
const QByteArray &expectedSent
);
};
struct TestEmulation : public Vt102Emulation
{
Q_OBJECT
// Give us access to protected functions
friend class Vt102EmulationTest;
QByteArray lastSent;
public:
void sendString(const QByteArray &string) override {
lastSent = string;
Vt102Emulation::sendString(string);
}
};
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment