diff options
-rw-r--r-- | src/plugins/debugger/debuggerplugin.cpp | 204 | ||||
-rw-r--r-- | src/plugins/debugger/debuggerplugin.h | 1 | ||||
-rw-r--r-- | src/plugins/debugger/debuggerstartparameters.h | 10 | ||||
-rw-r--r-- | src/plugins/debugger/gdb/gdbengine.cpp | 2 |
4 files changed, 160 insertions, 57 deletions
diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp index f95f953bbd..e1e034666d 100644 --- a/src/plugins/debugger/debuggerplugin.cpp +++ b/src/plugins/debugger/debuggerplugin.cpp @@ -87,6 +87,7 @@ #include <cplusplus/ModelManagerInterface.h> #include <extensionsystem/pluginmanager.h> +#include <extensionsystem/invoker.h> #include <projectexplorer/abi.h> #include <projectexplorer/applicationrunconfiguration.h> @@ -429,10 +430,23 @@ struct BreakpointMenuContextData : public ContextData Mode mode; }; +struct TestCallBack +{ + TestCallBack() : receiver(0), slot(0) {} + TestCallBack(QObject *ob, const char *s) : receiver(ob), slot(s) {} + + QObject *receiver; + const char *slot; + QVariant cookie; +}; + + } // namespace Internal } // namespace Debugger Q_DECLARE_METATYPE(Debugger::Internal::BreakpointMenuContextData) +Q_DECLARE_METATYPE(Debugger::Internal::TestCallBack) + namespace Debugger { namespace Internal { @@ -834,9 +848,26 @@ public slots: #ifdef WITH_TESTS public slots: - void testStuff(int testCase); + void testLoadProject(const QString &proFile, const TestCallBack &cb); void testProjectLoaded(ProjectExplorer::Project *project); + void testUnloadProject(); + void testFinished(); + + void testRunProject(const DebuggerStartParameters &sp, const TestCallBack &cb); void testRunControlFinished(); + + void testPythonDumpers1(); + void testPythonDumpers2(); + void testPythonDumpers3(); + + void testStateMachine1(); + void testStateMachine2(); + void testStateMachine3(); + +public: + bool m_testSuccess; + QList<TestCallBack> m_testCallbacks; + #endif @@ -3646,44 +3677,21 @@ QAction *DebuggerPlugin::visibleDebugAction() #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) +void DebuggerPluginPrivate::testLoadProject(const QString &proFile, const TestCallBack &cb) { 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"; + m_testCallbacks.append(cb); 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); + if (pe->openProject(proFile, &error)) + return; // Will end up in callback. - //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); + // Eat the unused callback. + qWarning("Cannot open %s: %s", qPrintable(proFile), qPrintable(error)); + QVERIFY(false); + m_testCallbacks.pop_back(); } void DebuggerPluginPrivate::testProjectLoaded(Project *project) @@ -3692,55 +3700,141 @@ void DebuggerPluginPrivate::testProjectLoaded(Project *project) qWarning("Changed to null project."); return; } + ProjectExplorerPlugin *pe = ProjectExplorerPlugin::instance(); + disconnect(pe, SIGNAL(currentProjectChanged(ProjectExplorer::Project*)), + this, SLOT(testProjectLoaded(ProjectExplorer::Project*))); + 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())); + QVERIFY(!m_testCallbacks.isEmpty()); + TestCallBack cb = m_testCallbacks.takeLast(); + invoke<void>(cb.receiver, cb.slot); +} - BuildConfiguration *bc = target->activeBuildConfiguration(); - QVERIFY(bc); +void DebuggerPluginPrivate::testUnloadProject() +{ + ProjectExplorerPlugin *pe = ProjectExplorerPlugin::instance(); + invoke<void>(pe, "unloadProject"); +} - RunConfiguration *rc = target->activeRunConfiguration(); - QVERIFY(rc); +static Project *currentProject() +{ + return ProjectExplorerPlugin::instance()->currentProject(); +} - LocalApplicationRunConfiguration *lrc = - qobject_cast<LocalApplicationRunConfiguration *>(rc); - QVERIFY(lrc); +static Target *activeTarget() +{ + Project *project = currentProject(); + return project->activeTarget(); +} - ToolChain *tc = bc->toolChain(); - QVERIFY(tc); +static BuildConfiguration *activeBuildConfiguration() +{ + return activeTarget()->activeBuildConfiguration(); +} - DebuggerStartParameters sp; - sp.toolChainAbi = tc->targetAbi(); - sp.executable = lrc->executable(); +static RunConfiguration *activeRunConfiguration() +{ + return activeTarget()->activeRunConfiguration(); +} + +static ToolChain *currentToolChain() +{ + return activeBuildConfiguration()->toolChain(); +} +static LocalApplicationRunConfiguration *activeLocalRunConfiguration() +{ + return qobject_cast<LocalApplicationRunConfiguration *>(activeRunConfiguration()); +} + +void DebuggerPluginPrivate::testRunProject(const DebuggerStartParameters &sp, const TestCallBack &cb) +{ + m_testCallbacks.append(cb); 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; + QVERIFY(!m_testCallbacks.isEmpty()); + TestCallBack cb = m_testCallbacks.takeLast(); + ExtensionSystem::invoke<void>(cb.receiver, cb.slot); +} - disconnect(pe, SIGNAL(currentProjectChanged(ProjectExplorer::Project*)), - this, SLOT(testProjectLoaded(ProjectExplorer::Project*))); +void DebuggerPluginPrivate::testFinished() +{ QTestEventLoop::instance().exitLoop(); + QVERIFY(m_testSuccess); } +/////////////////////////////////////////////////////////////////////////// + void DebuggerPlugin::testPythonDumpers() { - //theDebuggerCore->testStuff(TestDumpers); - theDebuggerCore->testStuff(TestPythonDumpers); + theDebuggerCore->testPythonDumpers1(); +} + +void DebuggerPluginPrivate::testPythonDumpers1() +{ + m_testSuccess = true; + QString proFile = ICore::resourcePath() + + "/../../tests/manual/debugger/simple/simple.pro"; + testLoadProject(proFile, TestCallBack(this, "testPythonDumpers2")); + QVERIFY(m_testSuccess); + QTestEventLoop::instance().enterLoop(20); } +void DebuggerPluginPrivate::testPythonDumpers2() +{ + DebuggerStartParameters sp; + sp.toolChainAbi = currentToolChain()->targetAbi(); + sp.executable = activeLocalRunConfiguration()->executable(); + testRunProject(sp, TestCallBack(this, "testPythonDumpers3")); +} + +void DebuggerPluginPrivate::testPythonDumpers3() +{ + testUnloadProject(); + testFinished(); +} + + +/////////////////////////////////////////////////////////////////////////// + +void DebuggerPlugin::testStateMachine() +{ + theDebuggerCore->testStateMachine1(); +} + +void DebuggerPluginPrivate::testStateMachine1() +{ + m_testSuccess = true; + QString proFile = ICore::resourcePath() + + "/../../tests/manual/debugger/simple/simple.pro"; + testLoadProject(proFile, TestCallBack(this, "testStateMachine2")); + QVERIFY(m_testSuccess); + QTestEventLoop::instance().enterLoop(20); +} + +void DebuggerPluginPrivate::testStateMachine2() +{ + DebuggerStartParameters sp; + sp.toolChainAbi = currentToolChain()->targetAbi(); + sp.executable = activeLocalRunConfiguration()->executable(); + sp.testCase = TestNoBoundsOfCurrentFunction; + testRunProject(sp, TestCallBack(this, "testStateMachine3")); +} + +void DebuggerPluginPrivate::testStateMachine3() +{ + testUnloadProject(); + testFinished(); +} #endif } // namespace Debugger diff --git a/src/plugins/debugger/debuggerplugin.h b/src/plugins/debugger/debuggerplugin.h index 02f700be7f..0f960f4f0e 100644 --- a/src/plugins/debugger/debuggerplugin.h +++ b/src/plugins/debugger/debuggerplugin.h @@ -78,6 +78,7 @@ private: #ifdef WITH_TESTS private slots: void testPythonDumpers(); + void testStateMachine(); #endif }; diff --git a/src/plugins/debugger/debuggerstartparameters.h b/src/plugins/debugger/debuggerstartparameters.h index 3e983e2cfc..e155ffb3a2 100644 --- a/src/plugins/debugger/debuggerstartparameters.h +++ b/src/plugins/debugger/debuggerstartparameters.h @@ -69,7 +69,10 @@ public: startMode(NoStartMode), executableUid(0), communicationChannel(CommunicationChannelTcpIp), - serverPort(0) + serverPort(0), + testReceiver(0), + testCallback(0), + testCase(0) {} QString executable; @@ -125,6 +128,11 @@ public: CommunicationChannel communicationChannel; QString serverAddress; quint16 serverPort; + + // For Debugger testing. + QObject *testReceiver; + const char *testCallback; + int testCase; }; } // namespace Debugger diff --git a/src/plugins/debugger/gdb/gdbengine.cpp b/src/plugins/debugger/gdb/gdbengine.cpp index b249004b1c..3ad67f73c2 100644 --- a/src/plugins/debugger/gdb/gdbengine.cpp +++ b/src/plugins/debugger/gdb/gdbengine.cpp @@ -5086,7 +5086,7 @@ bool GdbEngine::isHiddenBreakpoint(const BreakpointResponseId &id) const void GdbEngine::scheduleTestResponse(int testCase, const QByteArray &response) { - if (!m_testCases.contains(testCase)) + if (!m_testCases.contains(testCase) && startParameters().testCase != testCase) return; int token = currentToken() + 1; |