File indexing completed on 2024-04-28 05:50:35
0001 /* 0002 SPDX-FileCopyrightText: 2020 Lukasz Kotula <lukasz.kotula@gmx.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 // Own 0008 #include "ScreenTest.h" 0009 0010 // Qt 0011 #include <QString> 0012 0013 // KDE 0014 #include <QTest> 0015 0016 using namespace Konsole; 0017 0018 void ScreenTest::doLargeScreenCopyVerification(const QString &putToScreen, const QString &expectedSelection) 0019 { 0020 Screen screen(largeScreenLines, largeScreenColumns); 0021 0022 for (const auto &lineCharacter : putToScreen) { 0023 screen.displayCharacter(lineCharacter.toLatin1()); 0024 } 0025 0026 screen.setSelectionStart(0, 0, false); 0027 screen.setSelectionEnd(largeScreenColumns, 0, false); 0028 QCOMPARE(screen.selectedText(Screen::PlainText), expectedSelection); 0029 } 0030 0031 void ScreenTest::testLargeScreenCopyShortLine() 0032 { 0033 const QString putToScreen = QStringLiteral("0123456789abcde"); 0034 const QString expectedSelection = QStringLiteral("0123456789abcde\n"); 0035 doLargeScreenCopyVerification(putToScreen, expectedSelection); 0036 } 0037 0038 void ScreenTest::testBlockSelection() 0039 { 0040 Screen screen(largeScreenLines, largeScreenColumns); 0041 0042 const QString reallyBigTextForReflow = QStringLiteral("abcd efgh ijkl mnop qrst uvxz ABCD EFGH IJKL MNOP QRST UVXZ"); 0043 0044 for (const QChar &c : reallyBigTextForReflow) { 0045 screen.displayCharacter(c.toLatin1()); 0046 } 0047 0048 // this breaks the lines in `abcd efgh ` 0049 // reflowing everything to the lines below. 0050 screen.setReflowLines(true); 0051 0052 // reflow does not reflows cursor line, so let's move it a bit down. 0053 screen.cursorDown(1); 0054 screen.resizeImage(largeScreenLines, 10); 0055 0056 // True here means block selection. 0057 screen.setSelectionStart(0, 0, true); 0058 screen.setSelectionEnd(3, 1, false); 0059 0060 // after the resize, the string should be: 0061 // abcd efgh 0062 // ijkl mnop 0063 // ... 0064 // I'm selecting the first two lines of the first column of strings, 0065 // so, abcd ijkl. 0066 const QString selectedText = screen.selectedText(Screen::PlainText); 0067 QCOMPARE(screen.selectedText(Screen::PlainText), QStringLiteral("abcd ijkl")); 0068 } 0069 0070 void ScreenTest::testCJKBlockSelection() 0071 { 0072 Screen screen(largeScreenLines, largeScreenColumns); 0073 0074 const QString reallyBigTextForReflow = QStringLiteral( 0075 // Precomposed Hangul (NFC, each syllable block is a codepoint) 0076 "챠트 피면 술컵" 0077 "01234567890123" 0078 " 도 유효작 " 0079 "01234567890123" 0080 // Decomposed Hangul (NFD, syllables are made of several jamos) 0081 "챠트 피면 술컵" 0082 "01234567890123" 0083 " 도 유효작 " 0084 // Iroha (a pangrammic Japanese poem) 0085 "いろはにほへと" 0086 "01234567890123" 0087 " ちりぬるを " 0088 "01234567890123" 0089 "わかよたれそ " 0090 "01234567890123" 0091 " つねならむ " 0092 "01234567890123" 0093 "うゐのおくやま" 0094 "01234567890123" 0095 " けふこえて " 0096 "01234567890123" 0097 "あさきゆめみし" 0098 "01234567890123" 0099 "ゑひもせす"); 0100 0101 for (const QChar &c : reallyBigTextForReflow) { 0102 screen.displayCharacter(c.unicode()); 0103 } 0104 0105 // this breaks the text so it looks like above 0106 screen.setReflowLines(true); 0107 0108 // reflow does not reflows cursor line, so let's move it a bit down. 0109 screen.cursorDown(1); 0110 screen.resizeImage(32, 14); 0111 0112 // True here means block selection. 0113 screen.setSelectionStart(2, 0, true); 0114 screen.setSelectionEnd(6, 15, false); 0115 0116 // Do a block selection and compare the result to a known good result 0117 QCOMPARE(screen.selectedText(Screen::PlainText), 0118 QStringLiteral("\uD2B8 \uD53C 23456 \uC720\uD6A8 23456 \u1110\u1173 \u1111\u1175 23456 \u110B\u1172\u1112\u116D \u308D\u306F\u306B 23456 " 0119 "\u308A\u306C 23456 \u304B\u3088\u305F 23456 \u306D\u306A 23456 \u3090\u306E\u304A")); 0120 } 0121 0122 void ScreenTest::testLargeScreenCopyEmptyLine() 0123 { 0124 const QString putToScreen; 0125 const QString expectedSelection = QStringLiteral("\n"); 0126 0127 doLargeScreenCopyVerification(putToScreen, expectedSelection); 0128 } 0129 0130 void ScreenTest::testLargeScreenCopyLongLine() 0131 { 0132 QString putToScreen; 0133 0134 // Make the line longer than screen size (1300 characters) 0135 for (int i = 0; i < 130; ++i) { 0136 putToScreen.append(QStringLiteral("0123456789")); 0137 } 0138 const QString expectedSelection = putToScreen.left(1200); 0139 0140 doLargeScreenCopyVerification(putToScreen, expectedSelection); 0141 } 0142 0143 void ScreenTest::doComparePosition(Screen *screen, int y, int x) 0144 { 0145 QCOMPARE(screen->getCursorY(), y); 0146 QCOMPARE(screen->getCursorX(), x); 0147 } 0148 0149 // Test: setCursorYX, setCursorX, setCursorY, cursorDown, cursorUp, 0150 // cursorRight, cursorLeft, cursorNextLine and cursorPreviousLine 0151 void ScreenTest::testCursorPosition() 0152 { 0153 Screen *screen = new Screen(largeScreenLines, largeScreenColumns); 0154 0155 // setCursorYX will test setCursorX and setCursorY too 0156 screen->setCursorYX(6, 6); 0157 doComparePosition(screen, 5, 5); 0158 0159 screen->setCursorYX(2147483647, 2147483647); 0160 doComparePosition(screen, largeScreenLines - 1, largeScreenColumns - 1); 0161 0162 screen->setCursorYX(-1, -1); 0163 doComparePosition(screen, 0, 0); 0164 0165 screen->setCursorYX(0, 0); 0166 doComparePosition(screen, 0, 0); 0167 0168 screen->setCursorYX(1, 1); 0169 doComparePosition(screen, 0, 0); 0170 0171 screen->cursorDown(2147483647); 0172 doComparePosition(screen, largeScreenLines - 1, 0); 0173 0174 screen->cursorUp(2147483647); 0175 doComparePosition(screen, 0, 0); 0176 0177 screen->cursorDown(4); 0178 doComparePosition(screen, 4, 0); 0179 0180 screen->cursorDown(-1); 0181 doComparePosition(screen, 5, 0); 0182 0183 screen->cursorDown(0); 0184 doComparePosition(screen, 6, 0); 0185 0186 screen->cursorUp(0); 0187 doComparePosition(screen, 5, 0); 0188 0189 screen->cursorUp(-1); 0190 doComparePosition(screen, 4, 0); 0191 0192 screen->cursorUp(4); 0193 doComparePosition(screen, 0, 0); 0194 0195 screen->cursorRight(-1); 0196 doComparePosition(screen, 0, 1); 0197 0198 screen->cursorRight(3); 0199 doComparePosition(screen, 0, 4); 0200 0201 screen->cursorRight(0); 0202 doComparePosition(screen, 0, 5); 0203 0204 screen->cursorLeft(0); 0205 doComparePosition(screen, 0, 4); 0206 0207 screen->cursorLeft(2); 0208 doComparePosition(screen, 0, 2); 0209 0210 screen->cursorLeft(-1); 0211 doComparePosition(screen, 0, 1); 0212 0213 screen->cursorRight(2147483647); 0214 doComparePosition(screen, 0, largeScreenColumns - 1); 0215 0216 screen->cursorLeft(2147483647); 0217 doComparePosition(screen, 0, 0); 0218 0219 screen->cursorNextLine(4); 0220 doComparePosition(screen, 4, 0); 0221 0222 screen->cursorNextLine(-1); 0223 doComparePosition(screen, 5, 0); 0224 0225 screen->cursorNextLine(0); 0226 doComparePosition(screen, 6, 0); 0227 0228 screen->cursorPreviousLine(0); 0229 doComparePosition(screen, 5, 0); 0230 0231 screen->cursorPreviousLine(2); 0232 doComparePosition(screen, 3, 0); 0233 0234 screen->cursorPreviousLine(-1); 0235 doComparePosition(screen, 2, 0); 0236 0237 screen->cursorPreviousLine(2147483647); 0238 doComparePosition(screen, 0, 0); 0239 0240 screen->cursorNextLine(2147483647); 0241 doComparePosition(screen, largeScreenLines - 1, 0); 0242 0243 delete screen; 0244 } 0245 0246 QTEST_GUILESS_MAIN(ScreenTest) 0247 0248 #include "moc_ScreenTest.cpp"