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

@ -9,6 +9,14 @@
#include <kde_terminal_interface.h> #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 namespace Konsole
{ {
class HistoryTest : public QObject class HistoryTest : public QObject
@ -16,6 +24,8 @@ class HistoryTest : public QObject
Q_OBJECT Q_OBJECT
private Q_SLOTS: private Q_SLOTS:
void initTestCase();
void cleanupTestCase();
void testHistoryNone(); void testHistoryNone();
void testHistoryFile(); void testHistoryFile();
void testCompactHistory(); void testCompactHistory();
@ -25,6 +35,12 @@ private Q_SLOTS:
void testHistoryTypeChange(); void testHistoryTypeChange();
private: 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