diff --git a/src/Screen.h b/src/Screen.h index ecdad8d1..27686986 100644 --- a/src/Screen.h +++ b/src/Screen.h @@ -32,6 +32,7 @@ // Konsole #include "Character.h" +#include "konsoleprivate_export.h" #define MODE_Origin 0 #define MODE_Wrap 1 @@ -70,7 +71,7 @@ class HistoryScroll; using selectedText(). When getImage() is used to retrieve the visible image, characters which are part of the selection have their colors inverted. */ -class Screen +class KONSOLEPRIVATE_EXPORT Screen { public: /* PlainText: Return plain text (default) diff --git a/src/autotests/CMakeLists.txt b/src/autotests/CMakeLists.txt index 63cb5114..21092821 100644 --- a/src/autotests/CMakeLists.txt +++ b/src/autotests/CMakeLists.txt @@ -87,6 +87,12 @@ ecm_mark_nongui_executable(ShellCommandTest) add_test(ShellCommandTest ShellCommandTest) target_link_libraries(ShellCommandTest ${KONSOLE_TEST_LIBS}) +add_executable(ScreenTest ScreenTest.cpp) +ecm_mark_as_test(ScreenTest) +ecm_mark_nongui_executable(ScreenTest) +add_test(ScreenTest ScreenTest) +target_link_libraries(ScreenTest ${KONSOLE_TEST_LIBS}) + add_executable(TerminalCharacterDecoderTest TerminalCharacterDecoderTest.cpp) ecm_mark_as_test(TerminalCharacterDecoderTest) diff --git a/src/autotests/ScreenTest.cpp b/src/autotests/ScreenTest.cpp new file mode 100644 index 00000000..2213ca62 --- /dev/null +++ b/src/autotests/ScreenTest.cpp @@ -0,0 +1,72 @@ +/* + Copyright 2020 by Lukasz Kotula + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. +*/ + +// Own +#include "ScreenTest.h" + +// Qt +#include + +// KDE +#include + +using namespace Konsole; + +void ScreenTest::doLargeScreenCopyVerification(const QString &putToScreen, const QString &expectedSelection) +{ + Screen screen(largeScreenLines, largeScreenColumns); + + for(const auto lineCharacter : putToScreen) { + screen.displayCharacter(lineCharacter.toLatin1()); + } + + screen.setSelectionStart(0,0, false); + screen.setSelectionEnd(largeScreenColumns,0); + QCOMPARE(screen.selectedText(Screen::PlainText), expectedSelection); +} + +void ScreenTest::testLargeScreenCopyShortLine() +{ + const QString putToScreen = QStringLiteral("0123456789abcde"); + const QString expectedSelection = QStringLiteral("0123456789abcde\n"); + doLargeScreenCopyVerification(putToScreen, expectedSelection); +} + +void ScreenTest::testLargeScreenCopyEmptyLine() +{ + const QString putToScreen; + const QString expectedSelection = QStringLiteral("\n"); + + doLargeScreenCopyVerification(putToScreen, expectedSelection); +} + +void ScreenTest::testLargeScreenCopyLongLine() +{ + QString putToScreen; + + // Make the line longer than screen size (1300 characters) + for(int i = 0; i <130; ++i) { + putToScreen.append(QStringLiteral("0123456789")); + } + const QString expectedSelection = putToScreen.left(1200); + + doLargeScreenCopyVerification(putToScreen, expectedSelection); +} + +QTEST_GUILESS_MAIN(ScreenTest) diff --git a/src/autotests/ScreenTest.h b/src/autotests/ScreenTest.h new file mode 100644 index 00000000..0fc69185 --- /dev/null +++ b/src/autotests/ScreenTest.h @@ -0,0 +1,50 @@ +/* + Copyright 2020 by Lukasz Kotula + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. +*/ + + +#ifndef SHELLCOMMANDTEST_H +#define SHELLCOMMANDTEST_H + +#include + +#include "../Screen.h" + +namespace Konsole +{ + +class ScreenTest : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void testLargeScreenCopyShortLine(); + void testLargeScreenCopyEmptyLine(); + void testLargeScreenCopyLongLine(); + +private: + void doLargeScreenCopyVerification(const QString &putToScreen, const QString &expectedSelection); + + const int largeScreenLines = 10; + const int largeScreenColumns = 1200; +}; + +} + +#endif // SHELLCOMMANDTEST_H +