Refactor memory allocations

Use cleanupTestCase() to free up memory allocations.  This also fixes
an old coverity issue.
wilder
Kurt Hindenburg 4 years ago
parent fca0f4f9d7
commit a7d70cd5c3
  1. 57
      src/autotests/HistoryTest.cpp
  2. 16
      src/autotests/HistoryTest.h

@ -11,47 +11,44 @@
// Konsole
#include "../Emulation.h"
#include "../history/HistoryScrollFile.h"
#include "../history/HistoryScrollNone.h"
#include "../history/HistoryTypeFile.h"
#include "../history/HistoryTypeNone.h"
#include "../history/compact/CompactHistoryScroll.h"
#include "../history/compact/CompactHistoryType.h"
#include "../session/Session.h"
using namespace Konsole;
void HistoryTest::testHistoryNone()
void HistoryTest::initTestCase()
{
HistoryType *history;
}
history = new HistoryTypeNone();
QCOMPARE(history->isEnabled(), false);
QCOMPARE(history->isUnlimited(), false);
QCOMPARE(history->maximumLineCount(), 0);
delete history;
void HistoryTest::cleanupTestCase()
{
delete[] testImage;
delete historyTypeNone;
delete historyTypeFile;
delete historyTypeCompact;
}
void HistoryTest::testHistoryFile()
void HistoryTest::testHistoryNone()
{
HistoryType *history;
historyTypeNone = new HistoryTypeNone();
QCOMPARE(historyTypeNone->isEnabled(), false);
QCOMPARE(historyTypeNone->isUnlimited(), false);
QCOMPARE(historyTypeNone->maximumLineCount(), 0);
}
history = new HistoryTypeFile();
QCOMPARE(history->isEnabled(), true);
QCOMPARE(history->isUnlimited(), true);
QCOMPARE(history->maximumLineCount(), -1);
delete history;
void HistoryTest::testHistoryFile()
{
historyTypeFile = new HistoryTypeFile();
QCOMPARE(historyTypeFile->isEnabled(), true);
QCOMPARE(historyTypeFile->isUnlimited(), true);
QCOMPARE(historyTypeFile->maximumLineCount(), -1);
}
void HistoryTest::testCompactHistory()
{
HistoryType *history;
history = new CompactHistoryType(42);
QCOMPARE(history->isEnabled(), true);
QCOMPARE(history->isUnlimited(), false);
QCOMPARE(history->maximumLineCount(), 42);
delete history;
historyTypeCompact = new CompactHistoryType(42);
QCOMPARE(historyTypeCompact->isEnabled(), true);
QCOMPARE(historyTypeCompact->isUnlimited(), false);
QCOMPARE(historyTypeCompact->maximumLineCount(), 42);
}
void HistoryTest::testEmulationHistory()
@ -128,10 +125,7 @@ void HistoryTest::testHistoryScroll()
void HistoryTest::testHistoryReflow()
{
const char testString[] = "abcdefghijklmnopqrstuvwxyz1234567890";
const int testStringSize = sizeof(testString) / sizeof(char) - 1;
// testImage leaks on any failure
auto testImage = new Character[testStringSize];
testImage = new Character[testStringSize];
Character testChar;
for (int i = 0; i < testStringSize; i++) {
testImage[i] = Character((uint)testString[i]);
@ -182,7 +176,6 @@ void HistoryTest::testHistoryReflow()
historyScrollFile->getCells(testStringSize - 1, 0, 1, &testChar);
QCOMPARE(testChar, testImage[testStringSize - 1]);
delete[] testImage;
}
void HistoryTest::testHistoryTypeChange()

@ -9,6 +9,14 @@
#include <kde_terminal_interface.h>
#include "../characters/Character.h"
#include "../history/HistoryScrollFile.h"
#include "../history/HistoryScrollNone.h"
#include "../history/HistoryTypeFile.h"
#include "../history/HistoryTypeNone.h"
#include "../history/compact/CompactHistoryScroll.h"
#include "../history/compact/CompactHistoryType.h"
namespace Konsole
{
class HistoryTest : public QObject
@ -16,6 +24,8 @@ class HistoryTest : public QObject
Q_OBJECT
private Q_SLOTS:
void initTestCase();
void cleanupTestCase();
void testHistoryNone();
void testHistoryFile();
void testCompactHistory();
@ -25,6 +35,12 @@ private Q_SLOTS:
void testHistoryTypeChange();
private:
static constexpr const char testString[] = "abcdefghijklmnopqrstuvwxyz1234567890";
static constexpr const int testStringSize = sizeof(testString) / sizeof(char) - 1;
Character *testImage = nullptr;
HistoryType *historyTypeNone = nullptr;
HistoryType *historyTypeFile = nullptr;
HistoryType *historyTypeCompact = nullptr;
};
}

Loading…
Cancel
Save