Change method to not return dynamically allocated memory

Also, free memory before comparing in case of failure. This fixes a
really old coverity issue.
wilder
Kurt Hindenburg 4 years ago
parent 8663b4be86
commit 200d745295
  1. 15
      src/autotests/TerminalCharacterDecoderTest.cpp
  2. 2
      src/autotests/TerminalCharacterDecoderTest.h

@ -20,10 +20,8 @@
using namespace Konsole;
Character *TerminalCharacterDecoderTest::convertToCharacter(const QString &text, QVector<RenditionFlags> renditions)
void TerminalCharacterDecoderTest::convertToCharacter(Character *charResult, const QString &text, QVector<RenditionFlags> 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());
@ -32,7 +30,6 @@ Character *TerminalCharacterDecoderTest::convertToCharacter(const QString &text,
charResult[i] = Character(text.at(i).unicode());
charResult[i].rendition = renditions.at(i);
}
return charResult;
}
void TerminalCharacterDecoderTest::testPlainTextDecoder_data()
@ -61,15 +58,16 @@ void TerminalCharacterDecoderTest::testPlainTextDecoder()
QFETCH(QString, result);
TerminalCharacterDecoder *decoder = new PlainTextDecoder();
auto testCharacters = convertToCharacter(text, renditions);
auto testCharacters = new Character[text.size()];
convertToCharacter(testCharacters, 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;
QCOMPARE(outputString, result);
}
void TerminalCharacterDecoderTest::testHTMLDecoder_data()
@ -104,15 +102,16 @@ void TerminalCharacterDecoderTest::testHTMLDecoder()
QFETCH(QString, result);
TerminalCharacterDecoder *decoder = new HTMLDecoder();
auto testCharacters = convertToCharacter(text, renditions);
auto testCharacters = new Character[text.size()];
convertToCharacter(testCharacters, 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;
QCOMPARE(outputString, result);
}
QTEST_GUILESS_MAIN(TerminalCharacterDecoderTest)

@ -19,7 +19,7 @@ class TerminalCharacterDecoderTest : public QObject
Q_OBJECT
private Q_SLOTS:
Character *convertToCharacter(const QString &text, QVector<RenditionFlags> renditions);
void convertToCharacter(Character *charResult, const QString &text, QVector<RenditionFlags> renditions);
void testPlainTextDecoder();
void testPlainTextDecoder_data();
void testHTMLDecoder();

Loading…
Cancel
Save