From 1ef6c2b1f005361ed857da929d1538a4e70d95de Mon Sep 17 00:00:00 2001
From: hjk <qtc-committer@nokia.com>
Date: Mon, 23 Jan 2012 16:45:00 +0100
Subject: [PATCH] debugger: work on autotest integration

Change-Id: Iafd07a55e20cd2a65c3bcd23208c24855aeb429f
Reviewed-by: hjk <qthjk@ovi.com>
---
 src/plugins/debugger/debuggercore.h     |   7 ++
 src/plugins/debugger/debuggerplugin.cpp | 116 ++++++++++++++++++++++++
 src/plugins/debugger/debuggerplugin.h   |   5 +
 src/plugins/debugger/gdb/gdbengine.cpp  |   2 +-
 src/plugins/debugger/gdb/gdbengine.h    |   6 --
 5 files changed, 129 insertions(+), 7 deletions(-)

diff --git a/src/plugins/debugger/debuggercore.h b/src/plugins/debugger/debuggercore.h
index 2cd82e8c3e0..519c314be05 100644
--- a/src/plugins/debugger/debuggercore.h
+++ b/src/plugins/debugger/debuggercore.h
@@ -66,6 +66,13 @@ class Symbol;
 class DebuggerToolTipManager;
 class GlobalDebuggerOptions;
 
+enum TestCases
+{
+    // Gdb
+    TestNoBoundsOfCurrentFunction = 1,
+    TestPythonDumpers
+};
+
 class DebuggerCore : public QObject
 {
     Q_OBJECT
diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp
index 77fdd435c05..e0ec8d4d777 100644
--- a/src/plugins/debugger/debuggerplugin.cpp
+++ b/src/plugins/debugger/debuggerplugin.cpp
@@ -89,6 +89,8 @@
 #include <extensionsystem/pluginmanager.h>
 
 #include <projectexplorer/abi.h>
+#include <projectexplorer/applicationrunconfiguration.h>
+#include <projectexplorer/buildconfiguration.h>
 #include <projectexplorer/projectexplorerconstants.h>
 #include <projectexplorer/projectexplorer.h>
 #include <projectexplorer/projectexplorersettings.h>
@@ -127,6 +129,12 @@
 #include <QtGui/QTreeWidget>
 #include <QtGui/QInputDialog>
 
+#ifdef WITH_TESTS
+#include <QtTest/QTest>
+#include <QtTest/QSignalSpy>
+#include <QtTest/QTestEventLoop>
+#endif
+
 #include <climits>
 
 #define DEBUG_STATE 1
@@ -824,6 +832,14 @@ public slots:
     void evaluateExpression(const QString &expression);
     void coreShutdown();
 
+#ifdef WITH_TESTS
+public slots:
+    void testStuff(int testCase);
+    void testProjectLoaded(ProjectExplorer::Project *project);
+    void testRunControlFinished();
+#endif
+
+
 public slots:
     void updateDebugActions();
 
@@ -3632,6 +3648,106 @@ QAction *DebuggerPlugin::visibleDebugAction()
     return theDebuggerCore->m_visibleStartAction;
 }
 
+
+#ifdef WITH_TESTS
+
+static bool g_success;
+
+class TestCase
+{
+public:
+    TestCases id;
+    DebuggerEngineType suitableEngine;
+    bool needsProject;
+};
+
+static TestCase theTests[] =
+{
+    { TestNoBoundsOfCurrentFunction, GdbEngineType, true },
+    { TestPythonDumpers, GdbEngineType, true },
+};
+
+void DebuggerPluginPrivate::testStuff(int testCase)
+{
+    ProjectExplorerPlugin *pe = ProjectExplorerPlugin::instance();
+    connect(pe, SIGNAL(currentProjectChanged(ProjectExplorer::Project*)),
+            this, SLOT(testProjectLoaded(ProjectExplorer::Project*)));
+
+    QString proFile = ICore::instance()->resourcePath() + "/../../tests/manual/debugger/simple/simple.pro";
+    QString error;
+    if (!pe->openProject(proFile,&error)) {
+        qWarning("Cannot open %s: %s", qPrintable(proFile), qPrintable(error));
+        QVERIFY(false);
+        return;
+    }
+
+    g_success == false;
+    QTestEventLoop::instance().enterLoop(20);
+
+    //QCOMPARE(spy.count(), 1); // make sure the signal was emitted exactly one time
+    //QList<QVariant> arguments = spy.takeFirst(); // take the first signal
+
+    //QVERIFY(arguments.at(0).toBool() == true); // verify the first argument
+    QVERIFY(g_success);
+}
+
+void DebuggerPluginPrivate::testProjectLoaded(Project *project)
+{
+    if (!project) {
+        qWarning("Changed to null project.");
+        return;
+    }
+    QString fileName = project->file()->fileName();
+    QVERIFY(!fileName.isEmpty());
+    qWarning("Project %s loaded", qPrintable(fileName));
+
+    Target *target = project->activeTarget();
+    QVERIFY(target);
+    qWarning("Target %s selected", qPrintable(target->displayName()));
+
+    BuildConfiguration *bc = target->activeBuildConfiguration();
+    QVERIFY(bc);
+
+    RunConfiguration *rc = target->activeRunConfiguration();
+    QVERIFY(rc);
+
+    LocalApplicationRunConfiguration *lrc =
+            qobject_cast<LocalApplicationRunConfiguration *>(rc);
+    QVERIFY(lrc);
+
+    ToolChain *tc = bc->toolChain();
+    QVERIFY(tc);
+
+    DebuggerStartParameters sp;
+    sp.toolChainAbi = tc->targetAbi();
+    sp.executable = lrc->executable();
+
+    RunControl *rctl = createDebugger(sp);
+    QVERIFY(rctl);
+
+    connect(rctl, SIGNAL(finished()), this, SLOT(testRunControlFinished()));
+    ProjectExplorerPlugin::instance()->startRunControl(rctl, DebugRunMode);
+}
+
+void DebuggerPluginPrivate::testRunControlFinished()
+{
+    ProjectExplorerPlugin *pe = ProjectExplorerPlugin::instance();
+    qWarning("Run control finished.");
+    g_success = true;
+
+    disconnect(pe, SIGNAL(currentProjectChanged(ProjectExplorer::Project*)),
+            this, SLOT(testProjectLoaded(ProjectExplorer::Project*)));
+    QTestEventLoop::instance().exitLoop();
+}
+
+void DebuggerPlugin::testPythonDumpers()
+{
+    //theDebuggerCore->testStuff(TestDumpers);
+    theDebuggerCore->testStuff(TestPythonDumpers);
+}
+
+#endif
+
 } // namespace Debugger
 
 #include "debuggerplugin.moc"
diff --git a/src/plugins/debugger/debuggerplugin.h b/src/plugins/debugger/debuggerplugin.h
index 98b98a2c735..02f700be7ff 100644
--- a/src/plugins/debugger/debuggerplugin.h
+++ b/src/plugins/debugger/debuggerplugin.h
@@ -74,6 +74,11 @@ private:
     void remoteCommand(const QStringList &options, const QStringList &arguments);
     ShutdownFlag aboutToShutdown();
     void extensionsInitialized();
+
+#ifdef WITH_TESTS
+private slots:
+    void testPythonDumpers();
+#endif
 };
 
 } // namespace Debugger
diff --git a/src/plugins/debugger/gdb/gdbengine.cpp b/src/plugins/debugger/gdb/gdbengine.cpp
index 76a8bb73c35..b05014caec4 100644
--- a/src/plugins/debugger/gdb/gdbengine.cpp
+++ b/src/plugins/debugger/gdb/gdbengine.cpp
@@ -2114,7 +2114,7 @@ void GdbEngine::executeNext()
     if (isReverseDebugging()) {
         postCommand("reverse-next", RunRequest, CB(handleExecuteNext));
     } else {
-        scheduleTestResponse(GdbTestNoBoundsOfCurrentFunction,
+        scheduleTestResponse(TestNoBoundsOfCurrentFunction,
             "@TOKEN@^error,msg=\"Warning:\\nCannot insert breakpoint -39.\\n"
             " Error accessing memory address 0x11673fc: Input/output error.\\n\"");
         postCommand("-exec-next", RunRequest, CB(handleExecuteNext));
diff --git a/src/plugins/debugger/gdb/gdbengine.h b/src/plugins/debugger/gdb/gdbengine.h
index 4bab3df399d..5ff1f804838 100644
--- a/src/plugins/debugger/gdb/gdbengine.h
+++ b/src/plugins/debugger/gdb/gdbengine.h
@@ -78,12 +78,6 @@ enum DebuggingHelperState
     DebuggingHelperUnavailable
 };
 
-
-enum GdbTestCase
-{
-    GdbTestNoBoundsOfCurrentFunction = 1
-};
-
 class UpdateParameters
 {
 public:
-- 
GitLab