Commit 4cee7e23 authored by Carlos Alves's avatar Carlos Alves Committed by Kurt Hindenburg
Browse files

Add Reflow test to HistoryTest

While testing I found a bug in CompactHistoryScroll add function, it
should append before check the vector size and not after, it was
returning a Size > Max Size, not equal.
Another Bug found in fixed size history scroll, it was not properly
reflowing the last line, a position problem when adding and removing
lines to keep a fixed size.
parent f4643a0d
......@@ -131,5 +131,66 @@ void HistoryTest::testHistoryScroll()
delete historyScroll;
}
void HistoryTest::testHistoryReflow()
{
HistoryScroll *historyScroll;
const char testString[] = "abcdefghijklmnopqrstuvwxyz1234567890";
const int testStringSize = sizeof(testString) / sizeof(char) - 1;
auto testImage = new Character[testStringSize];
Character testChar;
for (int i = 0; i < testStringSize; i++) {
testImage[i] = Character((uint)testString[i]);
}
// None
historyScroll = new HistoryScrollNone();
QCOMPARE(historyScroll->getMaxLines(), 0);
QCOMPARE(historyScroll->reflowLines(10), 0);
delete historyScroll;
// Compact
historyScroll = new CompactHistoryScroll(10);
QCOMPARE(historyScroll->getMaxLines(), 10);
historyScroll->addCells(testImage, testStringSize);
historyScroll->addLine(false);
QCOMPARE(historyScroll->getLines(), 1);
QCOMPARE(historyScroll->reflowLines(10), 0);
QCOMPARE(historyScroll->getLines(), 4);
QCOMPARE(historyScroll->reflowLines(1), 26);
QCOMPARE(historyScroll->getLines(), 10);
QCOMPARE(historyScroll->getLineLen(5), 1);
historyScroll->getCells(3, 0, 1, &testChar);
QCOMPARE(testChar.character, (uint)testString[testStringSize - 7]);
historyScroll->getCells(0, 0, 1, &testChar);
QCOMPARE(testChar.character, (uint)testString[testStringSize - 10]);
historyScroll->getCells(9, 0, 1, &testChar);
QCOMPARE(testChar.character, (uint)testString[testStringSize - 1]);
delete historyScroll;
// File
historyScroll = new HistoryScrollFile();
QCOMPARE(historyScroll->getMaxLines(), 0);
historyScroll->addCells(testImage, testStringSize);
historyScroll->addLine(false);
QCOMPARE(historyScroll->getLines(), 1);
QCOMPARE(historyScroll->getMaxLines(), 1);
QCOMPARE(historyScroll->reflowLines(10), 0);
QCOMPARE(historyScroll->getLines(), 4);
QCOMPARE(historyScroll->getMaxLines(), 4);
QCOMPARE(historyScroll->reflowLines(1), 0);
QCOMPARE(historyScroll->getLines(), testStringSize);
QCOMPARE(historyScroll->getLineLen(5), 1);
historyScroll->getCells(3, 0, 1, &testChar);
QCOMPARE(testChar.character, (uint)testString[3]);
historyScroll->getCells(0, 0, 1, &testChar);
QCOMPARE(testChar.character, (uint)testString[0]);
historyScroll->getCells(testStringSize - 1, 0, 1, &testChar);
QCOMPARE(testChar.character, (uint)testString[testStringSize - 1]);
delete historyScroll;
delete[] testImage;
}
QTEST_MAIN(HistoryTest)
......@@ -22,6 +22,7 @@ private Q_SLOTS:
void testCompactHistory();
void testEmulationHistory();
void testHistoryScroll();
void testHistoryReflow();
private:
};
......
......@@ -178,10 +178,9 @@ int HistoryScrollFile::reflowLines(int columns)
while (currentPos < totalLines) {
reflowFile->get(reinterpret_cast<char *>(&newLine), sizeof(reflowData), currentPos * sizeof(reflowData));
_index.add(reinterpret_cast<char *>(&newLine.index), sizeof(qint64));
unsigned char flags = newLine.lineFlag ? 0x01 : 0x00;
_lineflags.add(reinterpret_cast<char *>(&flags), sizeof(char));
_index.add(reinterpret_cast<char *>(&newLine.index), sizeof(qint64));
currentPos++;
}
......
......@@ -30,12 +30,13 @@ CompactHistoryScroll::~CompactHistoryScroll()
void CompactHistoryScroll::addCellsVector(const TextLine &cells)
{
CompactHistoryLine *line;
line = new(_blockList) CompactHistoryLine(cells, _blockList);
line = new (_blockList) CompactHistoryLine(cells, _blockList);
_lines.append(line);
if (_lines.size() > static_cast<int>(_maxLineCount)) {
delete _lines.takeAt(0);
}
_lines.append(line);
}
void CompactHistoryScroll::addCells(const Character a[], int count)
......@@ -98,7 +99,7 @@ void CompactHistoryScroll::setMaxNbLines(unsigned int lineCount)
void CompactHistoryScroll::insertCellsVector(int position, const TextLine &cells)
{
CompactHistoryLine *line = new(_blockList) CompactHistoryLine(cells, _blockList);
CompactHistoryLine *line = new (_blockList) CompactHistoryLine(cells, _blockList);
_lines.insert(position, line);
......@@ -128,7 +129,7 @@ void CompactHistoryScroll::setCellsAt(int position, const Character a[], int cou
void CompactHistoryScroll::setCellsVectorAt(int position, const TextLine &cells)
{
CompactHistoryLine *line = new(_blockList) CompactHistoryLine(cells, _blockList);
CompactHistoryLine *line = new (_blockList) CompactHistoryLine(cells, _blockList);
delete _lines.takeAt(position);
_lines.insert(position, line);
......@@ -199,6 +200,7 @@ int CompactHistoryScroll::reflowLines(int columns)
} else {
addCells(curr_line + columns, curr_linelen - columns);
addLine(curr_line_property);
currentPos--;
}
if (removeLine) {
removedLines += 1;
......
Markdown is supported
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