File indexing completed on 2024-04-28 05:50:34
0001 /* 0002 SPDX-FileCopyrightText: 2013 Kurt Hindenburg <kurt.hindenburg@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 // Own 0008 #include "HistoryTest.h" 0009 0010 #include <QTest> 0011 0012 // Konsole 0013 #include "../Emulation.h" 0014 #include "../session/Session.h" 0015 0016 using namespace Konsole; 0017 0018 void HistoryTest::initTestCase() 0019 { 0020 } 0021 0022 void HistoryTest::cleanupTestCase() 0023 { 0024 delete[] testImage; 0025 } 0026 0027 void HistoryTest::testHistoryNone() 0028 { 0029 std::unique_ptr<HistoryType> historyTypeNone = std::make_unique<HistoryTypeNone>(); 0030 QCOMPARE(historyTypeNone->isEnabled(), false); 0031 QCOMPARE(historyTypeNone->isUnlimited(), false); 0032 QCOMPARE(historyTypeNone->maximumLineCount(), 0); 0033 } 0034 0035 void HistoryTest::testHistoryFile() 0036 { 0037 std::unique_ptr<HistoryType> historyTypeFile = std::make_unique<HistoryTypeFile>(); 0038 QCOMPARE(historyTypeFile->isEnabled(), true); 0039 QCOMPARE(historyTypeFile->isUnlimited(), true); 0040 QCOMPARE(historyTypeFile->maximumLineCount(), -1); 0041 } 0042 0043 void HistoryTest::testCompactHistory() 0044 { 0045 std::unique_ptr<HistoryType> historyTypeCompact = std::make_unique<CompactHistoryType>(42); 0046 QCOMPARE(historyTypeCompact->isEnabled(), true); 0047 QCOMPARE(historyTypeCompact->isUnlimited(), false); 0048 QCOMPARE(historyTypeCompact->maximumLineCount(), 42); 0049 } 0050 0051 void HistoryTest::testEmulationHistory() 0052 { 0053 auto session = std::make_unique<Session>(); 0054 Emulation *emulation = session->emulation(); 0055 0056 const HistoryType &historyTypeDefault = emulation->history(); 0057 QCOMPARE(historyTypeDefault.isEnabled(), false); 0058 QCOMPARE(historyTypeDefault.isUnlimited(), false); 0059 QCOMPARE(historyTypeDefault.maximumLineCount(), 0); 0060 0061 emulation->setHistory(HistoryTypeNone()); 0062 const HistoryType &historyTypeNone = emulation->history(); 0063 QCOMPARE(historyTypeNone.isEnabled(), false); 0064 QCOMPARE(historyTypeNone.isUnlimited(), false); 0065 QCOMPARE(historyTypeNone.maximumLineCount(), 0); 0066 0067 emulation->setHistory(HistoryTypeFile()); 0068 const HistoryType &historyTypeFile = emulation->history(); 0069 QCOMPARE(historyTypeFile.isEnabled(), true); 0070 QCOMPARE(historyTypeFile.isUnlimited(), true); 0071 QCOMPARE(historyTypeFile.maximumLineCount(), -1); 0072 0073 emulation->setHistory(CompactHistoryType(42)); 0074 const HistoryType &compactHistoryType = emulation->history(); 0075 QCOMPARE(compactHistoryType.isEnabled(), true); 0076 QCOMPARE(compactHistoryType.isUnlimited(), false); 0077 QCOMPARE(compactHistoryType.maximumLineCount(), 42); 0078 } 0079 0080 void HistoryTest::testHistoryScroll() 0081 { 0082 HistoryScroll *historyScroll; 0083 0084 // None 0085 historyScroll = new HistoryScrollNone(); 0086 QVERIFY(!historyScroll->hasScroll()); 0087 QCOMPARE(historyScroll->getLines(), 0); 0088 0089 const HistoryType &historyTypeNone = historyScroll->getType(); 0090 QCOMPARE(historyTypeNone.isEnabled(), false); 0091 QCOMPARE(historyTypeNone.isUnlimited(), false); 0092 QCOMPARE(historyTypeNone.maximumLineCount(), 0); 0093 0094 delete historyScroll; 0095 0096 // File 0097 historyScroll = new HistoryScrollFile(); 0098 QVERIFY(historyScroll->hasScroll()); 0099 QCOMPARE(historyScroll->getLines(), 0); 0100 0101 const HistoryType &historyTypeFile = historyScroll->getType(); 0102 QCOMPARE(historyTypeFile.isEnabled(), true); 0103 QCOMPARE(historyTypeFile.isUnlimited(), true); 0104 QCOMPARE(historyTypeFile.maximumLineCount(), -1); 0105 0106 delete historyScroll; 0107 0108 // Compact 0109 historyScroll = new CompactHistoryScroll(42); 0110 QVERIFY(historyScroll->hasScroll()); 0111 QCOMPARE(historyScroll->getLines(), 0); 0112 0113 const HistoryType &compactHistoryType = historyScroll->getType(); 0114 QCOMPARE(compactHistoryType.isEnabled(), true); 0115 QCOMPARE(compactHistoryType.isUnlimited(), false); 0116 QCOMPARE(compactHistoryType.maximumLineCount(), 42); 0117 0118 delete historyScroll; 0119 } 0120 0121 void HistoryTest::testHistoryReflow() 0122 { 0123 testImage = new Character[testStringSize]; 0124 Character testChar; 0125 for (int i = 0; i < testStringSize; i++) { 0126 testImage[i] = Character((uint)testString[i]); 0127 } 0128 0129 // None 0130 auto historyScrollNone = std::unique_ptr<HistoryScrollNone>(new HistoryScrollNone()); 0131 QCOMPARE(historyScrollNone->getMaxLines(), 0); 0132 QCOMPARE(historyScrollNone->reflowLines(10), 0); 0133 0134 // Compact 0135 auto compactHistoryScroll = std::unique_ptr<CompactHistoryScroll>(new CompactHistoryScroll(10)); 0136 0137 QCOMPARE(compactHistoryScroll->getMaxLines(), 10); 0138 compactHistoryScroll->addCells(testImage, testStringSize); 0139 compactHistoryScroll->addLine(); 0140 QCOMPARE(compactHistoryScroll->getLines(), 1); 0141 QCOMPARE(compactHistoryScroll->reflowLines(10), 0); 0142 QCOMPARE(compactHistoryScroll->getLines(), 4); 0143 QCOMPARE(compactHistoryScroll->reflowLines(1), 26); 0144 QCOMPARE(compactHistoryScroll->getLines(), 10); 0145 QCOMPARE(compactHistoryScroll->getLineLen(5), 1); 0146 compactHistoryScroll->getCells(3, 0, 1, &testChar); 0147 QCOMPARE(testChar, testImage[testStringSize - 7]); 0148 compactHistoryScroll->getCells(0, 0, 1, &testChar); 0149 QCOMPARE(testChar, testImage[testStringSize - 10]); 0150 compactHistoryScroll->getCells(9, 0, 1, &testChar); 0151 QCOMPARE(testChar, testImage[testStringSize - 1]); 0152 0153 // File 0154 auto historyScrollFile = std::unique_ptr<HistoryScrollFile>(new HistoryScrollFile()); 0155 0156 QCOMPARE(historyScrollFile->getMaxLines(), 0); 0157 historyScrollFile->addCells(testImage, testStringSize); 0158 historyScrollFile->addLine(); 0159 QCOMPARE(historyScrollFile->getLines(), 1); 0160 QCOMPARE(historyScrollFile->getMaxLines(), 1); 0161 QCOMPARE(historyScrollFile->reflowLines(10), 0); 0162 QCOMPARE(historyScrollFile->getLines(), 4); 0163 QCOMPARE(historyScrollFile->getMaxLines(), 4); 0164 QCOMPARE(historyScrollFile->reflowLines(1), 0); 0165 QCOMPARE(historyScrollFile->getLines(), testStringSize); 0166 QCOMPARE(historyScrollFile->getLineLen(5), 1); 0167 historyScrollFile->getCells(3, 0, 1, &testChar); 0168 QCOMPARE(testChar, testImage[3]); 0169 historyScrollFile->getCells(0, 0, 1, &testChar); 0170 QCOMPARE(testChar, testImage[0]); 0171 historyScrollFile->getCells(testStringSize - 1, 0, 1, &testChar); 0172 QCOMPARE(testChar, testImage[testStringSize - 1]); 0173 } 0174 0175 void HistoryTest::testHistoryTypeChange() 0176 { 0177 std::unique_ptr<HistoryScroll> historyScroll(nullptr); 0178 0179 const char testString[] = "abcdefghijklmnopqrstuvwxyz1234567890"; 0180 const int testStringSize = sizeof(testString) / sizeof(char) - 1; 0181 auto testImage = std::make_unique<Character[]>(testStringSize); 0182 Character testChar; 0183 for (int i = 0; i < testStringSize; i++) { 0184 testImage[i] = Character((uint)testString[i]); 0185 } 0186 0187 // None 0188 auto historyTypeNone = std::make_unique<HistoryTypeNone>(); 0189 historyTypeNone->scroll(historyScroll); 0190 0191 // None to File 0192 auto historyTypeFile = std::make_unique<HistoryTypeFile>(); 0193 historyTypeFile->scroll(historyScroll); 0194 0195 historyScroll->addCells(testImage.get(), testStringSize); 0196 historyScroll->addLine(); 0197 QCOMPARE(historyScroll->reflowLines(1), 0); 0198 QCOMPARE(historyScroll->getLines(), testStringSize); 0199 historyScroll->getCells(0, 0, 1, &testChar); 0200 QCOMPARE(testChar, testImage[0]); 0201 0202 // File to Compact 0203 auto compactHistoryType = std::make_unique<CompactHistoryType>(10); 0204 compactHistoryType->scroll(historyScroll); 0205 0206 QCOMPARE(historyScroll->getLines(), 10); 0207 historyScroll->getCells(0, 0, 1, &testChar); 0208 QCOMPARE(testChar, testImage[testStringSize - 10]); 0209 0210 // Compact to File 0211 historyTypeFile->scroll(historyScroll); 0212 QCOMPARE(historyScroll->getLines(), 10); 0213 historyScroll->getCells(0, 0, 1, &testChar); 0214 QCOMPARE(testChar, testImage[testStringSize - 10]); 0215 0216 // File to None 0217 historyTypeNone->scroll(historyScroll); 0218 QCOMPARE(historyScroll->getLines(), 0); 0219 } 0220 0221 QTEST_MAIN(HistoryTest) 0222 0223 #include "moc_HistoryTest.cpp"