diff --git a/src/autotests/TerminalCharacterDecoderTest.cpp b/src/autotests/TerminalCharacterDecoderTest.cpp index 46207439..564e74bf 100644 --- a/src/autotests/TerminalCharacterDecoderTest.cpp +++ b/src/autotests/TerminalCharacterDecoderTest.cpp @@ -1,6 +1,6 @@ /* Copyright 2008 by Robert Knight - Copyright 2013 by Kurt Hindenburg + Copyright 2013, 2018 by Kurt Hindenburg This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -33,47 +33,92 @@ using namespace Konsole; -void TerminalCharacterDecoderTest::init() +Character* TerminalCharacterDecoderTest::convertToCharacter(QString text, QVector renditions) { + auto charResult = new Character[text.size()]; + + // Force renditions size to match that of text; default will be DEFAULT_RENDITION. + if (renditions.size() < text.size()) { + renditions.resize(text.size()); + } + for (int i = 0; i < text.size(); ++i) { + charResult[i] = Character(text.at(i).unicode()); + charResult[i].rendition = renditions.at(i); + } + return charResult; } -void TerminalCharacterDecoderTest::cleanup() +void TerminalCharacterDecoderTest::testPlainTextDecoder_data() { + QTest::addColumn("text"); + QTest::addColumn>("renditions"); + QTest::addColumn("result"); + + /* Notes: + * - rendition has no effect on plain decoded text + * + * TODO: need to add foregroundColor, backgroundColor, and isRealCharacter + */ + QTest::newRow("simple text with default rendition") << "hello" << QVector(6).fill(DEFAULT_RENDITION) << "hello"; + QTest::newRow("simple text with bold rendition") << "hello" << QVector(6).fill(RE_BOLD) << "hello"; + QTest::newRow("simple text with underline and italic rendition") << "hello" << QVector(6).fill(RE_UNDERLINE|RE_ITALIC) << "hello"; + + QTest::newRow("simple text with default rendition (shorten)") << "hello" << QVector(4).fill(DEFAULT_RENDITION) << "hello"; + QTest::newRow("simple text with underline rendition (shorten)") << "hello" << QVector(4).fill(RE_UNDERLINE) << "hello"; } void TerminalCharacterDecoderTest::testPlainTextDecoder() { + QFETCH(QString, text); + QFETCH(QVector, renditions); + QFETCH(QString, result); + TerminalCharacterDecoder *decoder = new PlainTextDecoder(); - Character characters[6]; - characters[0] = Character('h'); - characters[1] = Character('e'); - characters[2] = Character('l'); - characters[3] = Character('l'); - characters[4] = Character('o'); - characters[5] = Character(' '); - characters[5].isRealCharacter = false; + auto testCharacters = convertToCharacter(text, renditions); QString outputString; QTextStream outputStream(&outputString); decoder->begin(&outputStream); - decoder->decodeLine(characters, 6, LINE_DEFAULT); + decoder->decodeLine(testCharacters, text.size(), /* ignored */ LINE_DEFAULT); decoder->end(); - QCOMPARE(outputString, QStringLiteral("hello")); + QCOMPARE(outputString, result); + delete testCharacters; delete decoder; } -void TerminalCharacterDecoderTest::testHTMLFileForValidity() +void TerminalCharacterDecoderTest::testHTMLDecoder_data() { - QString fileName = QStringLiteral("konsole.html"); - QFile fi(fileName); - - if (!fi.exists()) { - QSKIP("Test html file not found."); - } + QTest::addColumn("text"); + QTest::addColumn>("renditions"); + QTest::addColumn("result"); + + /* Notes: + * TODO: need to add foregroundColor, backgroundColor, and isRealCharacter + */ + QTest::newRow("simple text with default rendition") << "hello" << QVector(6).fill(DEFAULT_RENDITION) << "hello
"; + QTest::newRow("simple text with bold rendition") << "hello" << QVector(6).fill(RE_BOLD) << "hello
"; + // The below is wrong; only the first rendition is used (eg ignores the |) + QTest::newRow("simple text with underline and italic rendition") << "hello" << QVector(6).fill(RE_UNDERLINE|RE_ITALIC) << "hello
"; + + // The below should likely have & replaced by & + QTest::newRow("text with &") << "hello &there" << QVector(6).fill(DEFAULT_RENDITION) << "hello &there
"; +} - QXmlSimpleReader xmlReader; - QXmlInputSource source(&fi); +void TerminalCharacterDecoderTest::testHTMLDecoder() +{ + QFETCH(QString, text); + QFETCH(QVector, renditions); + QFETCH(QString, result); - QVERIFY(xmlReader.parse(&source)); + TerminalCharacterDecoder *decoder = new HTMLDecoder(); + auto testCharacters = convertToCharacter(text, renditions); + QString outputString; + QTextStream outputStream(&outputString); + decoder->begin(&outputStream); + decoder->decodeLine(testCharacters, text.size(), /* ignored */ LINE_DEFAULT); + decoder->end(); + QCOMPARE(outputString, result); + delete testCharacters; + delete decoder; } QTEST_GUILESS_MAIN(TerminalCharacterDecoderTest) diff --git a/src/autotests/TerminalCharacterDecoderTest.h b/src/autotests/TerminalCharacterDecoderTest.h index 56f01130..d2a498b8 100644 --- a/src/autotests/TerminalCharacterDecoderTest.h +++ b/src/autotests/TerminalCharacterDecoderTest.h @@ -1,5 +1,6 @@ /* Copyright 2008 by Robert Knight + Copyright 2018 by Kurt Hindenburg This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -32,11 +33,11 @@ class TerminalCharacterDecoderTest : public QObject Q_OBJECT private Q_SLOTS: - void init(); - void cleanup(); - + Character* convertToCharacter(QString text, QVector renditions); void testPlainTextDecoder(); - void testHTMLFileForValidity(); + void testPlainTextDecoder_data(); + void testHTMLDecoder(); + void testHTMLDecoder_data(); }; }