Commit 200d7452 authored by Kurt Hindenburg's avatar Kurt Hindenburg
Browse files

Change method to not return dynamically allocated memory

Also, free memory before comparing in case of failure. This fixes a
really old coverity issue.
parent 8663b4be
Pipeline #180188 passed with stage
in 3 minutes and 39 seconds
......@@ -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();
......
Supports Markdown
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