[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [konsole/frameworks] src/tests: Separate PartTest into an automated test and a manual test
From:       Kurt Hindenburg <kurt.hindenburg () gmail ! com>
Date:       2013-08-31 21:59:22
Message-ID: E1VFtCU-0008BN-3h () scm ! kde ! org
[Download RAW message or body]

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 <QWidget>
@@ -41,6 +41,7 @@
 #include <KPtyProcess>
 #include <KPtyDevice>
 #include <KDialog>
+#include <KDebug>
 #include <KMainWindow>
 #include <qtest_kde.h>
 
@@ -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 = 0; i < pingList.size(); ++i) {
-        info.setFile(pingList.at(i));
-        if (info.exists() && info.isExecutable())
-            pingExe = 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 = ptyProcess.pty()->masterFd();
-
-    // create a Konsole part and attempt to connect to it
-    KParts::Part* terminalPart = createPart();
-    bool result = QMetaObject::invokeMethod(terminalPart, "openTeletype",
-                                            Qt::DirectConnection, Q_ARG(int, 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 everything
-    // as soon as it becomes available and the terminal will not display any output
-    ptyProcess.pty()->setSuspended(true);
-
-    QWeakPointer<KDialog> dialog = new KDialog();
-    dialog.data()->setButtons(0);
-    QVBoxLayout* layout = 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 manually \
                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 == true);
     if (event->modifiers() == Qt::ControlModifier && event->key() == Qt::Key_S) {
@@ -170,12 +120,12 @@ void PartTest::overrideShortcut(QKeyEvent* event, bool& \
override)  _shortcutEventLoop->exit();
     }
 }
-void PartTest::shortcutTriggered()
+void PartManualTest::shortcutTriggered()
 {
     _shortcutTriggered = true;
 }
 
-KParts::Part* PartTest::createPart()
+KParts::Part* PartManualTest::createPart()
 {
     KService::Ptr service = 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 <QtCore/QEventLoop>
 
@@ -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 <QWidget>
 #include <QLabel>
 #include <QVBoxLayout>
-#include <QtGui/QKeyEvent>
-#include <qtestkeyboard.h>
-
-// System
-#include <termios.h>
-#include <sys/types.h>
 
 // KDE
-#include <KMenu>
-#include <KMenuBar>
 #include <KPluginLoader>
 #include <KPluginFactory>
 #include <KService>
@@ -41,13 +32,12 @@
 #include <KPtyProcess>
 #include <KPtyDevice>
 #include <KDialog>
+#include <KDebug>
 #include <KMainWindow>
 #include <qtest_kde.h>
 
 // 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 manually \
                because
-    // the result is different than when sending the key press via QTest::keyClick()
-    //
-    // When the key presses are sent manually, Konsole::TerminalDisplay::event() is \
                called
-    // and the overrideShortcut() signal is emitted by the part.
-    // When the key presses are sent automatically, the shortcut is triggered but
-    // Konsole::TerminalDisplay::event() is not called and the overrideShortcut() \
                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 terminal
-    KMainWindow* mainWindow = new KMainWindow();
-    QMenu* fileMenu = mainWindow->menuBar()->addMenu("File");
-    QAction* testAction = 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 = createPart();
-    QVERIFY(terminalPart);
-    mainWindow->setCentralWidget(terminalPart->widget());
-    TerminalInterface* terminal = qobject_cast<TerminalInterface*>(terminalPart);
-    QVERIFY(terminal);
-    terminal->sendInput("Press Ctrl+S twice.\n");
-    mainWindow->show();
-
-    // Test shortcut with override disabled, so the shortcut will be triggered
-    _shortcutTriggered = false;
-    _override = false;
-    _overrideCalled = false;
-    QVERIFY(connect(terminalPart, SIGNAL(overrideShortcut(QKeyEvent*,bool&)),
-                    this, SLOT(overrideShortcut(QKeyEvent*,bool&))));
-
-    //QTest::keyClick(terminalPart->widget(),Qt::Key_S,Qt::ControlModifier);
-    _shortcutEventLoop = new QEventLoop();
-    _shortcutEventLoop->exec();
-
-    QVERIFY(_overrideCalled);
-    QVERIFY(_shortcutTriggered);
-    QVERIFY(!_override);
-
-    // Test shortcut with override enabled, so the shortcut will not be triggered
-    _override = true;
-    _overrideCalled = false;
-    _shortcutTriggered = 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 == true);
-    if (event->modifiers() == Qt::ControlModifier && event->key() == Qt::Key_S) {
-        _overrideCalled = true;
-        override = _override;
-        _shortcutEventLoop->exit();
-    }
-}
-void PartTest::shortcutTriggered()
-{
-    _shortcutTriggered = 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;
 };
 
 }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic