Git commit f2fa8b9dca597740bd4ba5a11a380a3aa97f186c by Kurt Hindenburg. Committed on 31/08/2013 at 12:47. Pushed by hindenburg into branch 'frameworks'. Separate PartTest into an automated test and a manual test Currently the shortcut override test requires human interaction and hence the test is not automated. Move this test to PartManualTest so that other parts of PartTest will run automatedly. (cherry picked from commit 5ad1e902bae30d8770112ddd7e3914223b5bf848) M +9 -1 src/tests/CMakeLists.txt C +8 -58 src/tests/PartManualTest.cpp [from: src/tests/PartTest.cpp -= 067% similarity] C +4 -5 src/tests/PartManualTest.h [from: src/tests/PartTest.h - 092= % similarity] M +1 -83 src/tests/PartTest.cpp M +0 -12 src/tests/PartTest.h http://commits.kde.org/konsole/f2fa8b9dca597740bd4ba5a11a380a3aa97f186c diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index e10f0a4..641d5f8 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -5,7 +5,15 @@ include_directories(${KDE4_KPTY_INCLUDES} = set(KONSOLE_TEST_LIBS ${QT_QTTEST_LIBRARY} konsoleprivate) = -kde4_add_executable(PartTest TEST PartTest.cpp) +## If it's interactive, it shouldn't use kde4_add_unit_test, +## since make test is supposed to be fully automated. + +kde4_add_executable(PartManualTest TEST PartManualTest.cpp) +target_link_libraries(PartManualTest ${KDE4_KPARTS_LIBS} + ${KDE4_KPTY_LIBS} + ${KONSOLE_TEST_LIBS}) + +kde4_add_unit_test(PartTest PartTest.cpp) target_link_libraries(PartTest ${KDE4_KPARTS_LIBS} ${KDE4_KPTY_LIBS} ${KONSOLE_TEST_LIBS}) diff --git a/src/tests/PartTest.cpp b/src/tests/PartManualTest.cpp similarity index 67% copy from src/tests/PartTest.cpp copy to src/tests/PartManualTest.cpp index 03c7a66..07489dd 100644 --- a/src/tests/PartTest.cpp +++ b/src/tests/PartManualTest.cpp @@ -18,7 +18,7 @@ */ = // Own -#include "PartTest.h" +#include "PartManualTest.h" = // Qt #include @@ -41,6 +41,7 @@ #include #include #include +#include #include #include = @@ -51,58 +52,7 @@ = using namespace Konsole; = -void PartTest::testFd() -{ - // find ping - QStringList pingList; - QFileInfo info; - QString pingExe; - pingList << "/bin/ping" << "/sbin/ping"; - for (int i =3D 0; i < pingList.size(); ++i) { - info.setFile(pingList.at(i)); - if (info.exists() && info.isExecutable()) - pingExe =3D pingList.at(i); - } - - if (pingExe.isEmpty()) { - QSKIP("ping command not found."); - return; - } - - // start a pty process - KPtyProcess ptyProcess; - ptyProcess.setProgram(pingExe, QStringList() << "localhost"); - ptyProcess.setPtyChannels(KPtyProcess::AllChannels); - ptyProcess.start(); - QVERIFY(ptyProcess.waitForStarted()); - - int fd =3D ptyProcess.pty()->masterFd(); - - // create a Konsole part and attempt to connect to it - KParts::Part* terminalPart =3D createPart(); - bool result =3D QMetaObject::invokeMethod(terminalPart, "openTeletype", - Qt::DirectConnection, Q_ARG(in= t, fd)); - QVERIFY(result); - - // suspend the KPtyDevice so that the embedded terminal gets a chance = to - // read from the pty. Otherwise the KPtyDevice will simply read every= thing - // as soon as it becomes available and the terminal will not display a= ny output - ptyProcess.pty()->setSuspended(true); - - QWeakPointer dialog =3D new KDialog(); - dialog.data()->setButtons(0); - QVBoxLayout* layout =3D new QVBoxLayout(dialog.data()->mainWidget()); - layout->addWidget(new QLabel("Output of 'ping localhost' should appear= in a terminal below for 5 seconds")); - layout->addWidget(terminalPart->widget()); - QTimer::singleShot(5000, dialog.data(), SLOT(close())); - dialog.data()->exec(); - - delete terminalPart; - delete dialog.data(); - ptyProcess.kill(); - ptyProcess.waitForFinished(1000); -} -void PartTest::testShortcutOverride() +void PartManualTest::testShortcutOverride() { // FIXME: This test asks the user to press shortcut key sequences manu= ally because // the result is different than when sending the key press via QTest::= keyClick() @@ -161,7 +111,7 @@ void PartTest::testShortcutOverride() delete terminalPart; delete mainWindow; } -void PartTest::overrideShortcut(QKeyEvent* event, bool& override) +void PartManualTest::overrideShortcut(QKeyEvent* event, bool& override) { QVERIFY(override =3D=3D true); if (event->modifiers() =3D=3D Qt::ControlModifier && event->key() =3D= =3D Qt::Key_S) { @@ -170,12 +120,12 @@ void PartTest::overrideShortcut(QKeyEvent* event, boo= l& override) _shortcutEventLoop->exit(); } } -void PartTest::shortcutTriggered() +void PartManualTest::shortcutTriggered() { _shortcutTriggered =3D true; } = -KParts::Part* PartTest::createPart() +KParts::Part* PartManualTest::createPart() { KService::Ptr service =3D KService::serviceByDesktopName("konsolepart"= ); Q_ASSERT(service); @@ -187,7 +137,7 @@ KParts::Part* PartTest::createPart() return terminalPart; } = -QTEST_KDEMAIN(PartTest , GUI) +QTEST_KDEMAIN(PartManualTest , GUI) = -#include "PartTest.moc" +#include "PartManualTest.moc" = diff --git a/src/tests/PartTest.h b/src/tests/PartManualTest.h similarity index 92% copy from src/tests/PartTest.h copy to src/tests/PartManualTest.h index bf8f834..af7974c 100644 --- a/src/tests/PartTest.h +++ b/src/tests/PartManualTest.h @@ -17,8 +17,8 @@ 02110-1301 USA. */ = -#ifndef PARTTEST_H -#define PARTTEST_H +#ifndef PARTMANUALTEST_H +#define PARTMANUALTEST_H = #include = @@ -31,13 +31,12 @@ class QEvent; namespace Konsole { = -class PartTest : public QObject +class PartManualTest : public QObject { Q_OBJECT = private slots: void testShortcutOverride(); - void testFd(); = // marked as protected so they are not treated as test cases protected slots: @@ -56,5 +55,5 @@ private: = } = -#endif // PARTTEST_H +#endif // PARTMANUALTEST_H = diff --git a/src/tests/PartTest.cpp b/src/tests/PartTest.cpp index 03c7a66..7df4b2e 100644 --- a/src/tests/PartTest.cpp +++ b/src/tests/PartTest.cpp @@ -21,19 +21,10 @@ #include "PartTest.h" = // Qt -#include #include #include -#include -#include - -// System -#include -#include = // KDE -#include -#include #include #include #include @@ -41,13 +32,12 @@ #include #include #include +#include #include #include = // Konsole #include "../Pty.h" -#include "../Session.h" -#include "../KeyboardTranslator.h" = using namespace Konsole; = @@ -102,78 +92,6 @@ void PartTest::testFd() ptyProcess.kill(); ptyProcess.waitForFinished(1000); } -void PartTest::testShortcutOverride() -{ - // FIXME: This test asks the user to press shortcut key sequences manu= ally because - // the result is different than when sending the key press via QTest::= keyClick() - // - // When the key presses are sent manually, Konsole::TerminalDisplay::e= vent() is called - // and the overrideShortcut() signal is emitted by the part. - // When the key presses are sent automatically, the shortcut is trigge= red but - // Konsole::TerminalDisplay::event() is not called and the overrideSho= rtcut() signal is - // not emitted by the part. - - // Create a main window with a menu and a test - // action with a shortcut set to Ctrl+S, which is also used by the ter= minal - KMainWindow* mainWindow =3D new KMainWindow(); - QMenu* fileMenu =3D mainWindow->menuBar()->addMenu("File"); - QAction* testAction =3D fileMenu->addAction("Test"); - testAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S)); - connect(testAction, SIGNAL(triggered()), this, SLOT(shortcutTriggered(= ))); - - // Create terminal part and embed in into the main window - KParts::Part* terminalPart =3D createPart(); - QVERIFY(terminalPart); - mainWindow->setCentralWidget(terminalPart->widget()); - TerminalInterface* terminal =3D qobject_cast(termi= nalPart); - QVERIFY(terminal); - terminal->sendInput("Press Ctrl+S twice.\n"); - mainWindow->show(); - - // Test shortcut with override disabled, so the shortcut will be trigg= ered - _shortcutTriggered =3D false; - _override =3D false; - _overrideCalled =3D false; - QVERIFY(connect(terminalPart, SIGNAL(overrideShortcut(QKeyEvent*,bool&= )), - this, SLOT(overrideShortcut(QKeyEvent*,bool&)))); - - //QTest::keyClick(terminalPart->widget(),Qt::Key_S,Qt::ControlModifier= ); - _shortcutEventLoop =3D new QEventLoop(); - _shortcutEventLoop->exec(); - - QVERIFY(_overrideCalled); - QVERIFY(_shortcutTriggered); - QVERIFY(!_override); - - // Test shortcut with override enabled, so the shortcut will not be tr= iggered - _override =3D true; - _overrideCalled =3D false; - _shortcutTriggered =3D false; - - //QTest::keyClick(terminalPart->widget(),Qt::Key_S,Qt::ControlModifier= ); - _shortcutEventLoop->exec(); - - QVERIFY(_overrideCalled); - QVERIFY(!_shortcutTriggered); - QVERIFY(_override); - - delete _shortcutEventLoop; - delete terminalPart; - delete mainWindow; -} -void PartTest::overrideShortcut(QKeyEvent* event, bool& override) -{ - QVERIFY(override =3D=3D true); - if (event->modifiers() =3D=3D Qt::ControlModifier && event->key() =3D= =3D Qt::Key_S) { - _overrideCalled =3D true; - override =3D _override; - _shortcutEventLoop->exit(); - } -} -void PartTest::shortcutTriggered() -{ - _shortcutTriggered =3D true; -} = KParts::Part* PartTest::createPart() { diff --git a/src/tests/PartTest.h b/src/tests/PartTest.h index bf8f834..e06a984 100644 --- a/src/tests/PartTest.h +++ b/src/tests/PartTest.h @@ -36,22 +36,10 @@ class PartTest : public QObject Q_OBJECT = private slots: - void testShortcutOverride(); void testFd(); = -// marked as protected so they are not treated as test cases -protected slots: - void overrideShortcut(QKeyEvent* event, bool& override); - void shortcutTriggered(); - private: KParts::Part* createPart(); - - // variables for testShortcutOverride() - bool _shortcutTriggered; - bool _overrideCalled; - bool _override; - QEventLoop* _shortcutEventLoop; }; = }