diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index bc6632b8e8..961d0cea96 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,53 +1,62 @@ set(kdevtests_LIB_SRCS autotestshell.cpp kdevsignalspy.cpp testcore.cpp testproject.cpp testfile.cpp testlanguagecontroller.cpp testhelpers.cpp testplugincontroller.cpp + testdebugsession.cpp + testvariablecontroller.cpp + testbreakpointcontroller.cpp + testframestackmodel.cpp modeltest.cpp json/delayedoutput.cpp json/declarationvalidator.cpp json/testsuite.cpp ) kdevplatform_add_library(KDevPlatformTests SOURCES ${kdevtests_LIB_SRCS}) target_link_libraries(KDevPlatformTests LINK_PUBLIC KDev::Shell KDev::Language KDev::Project + KDev::Debugger ) target_link_libraries(KDevPlatformTests LINK_PRIVATE Qt5::Core Qt5::Test ) install(FILES autotestshell.h kdevsignalspy.h modeltest.h testcore.h testproject.h testfile.h testlanguagecontroller.h testhelpers.h testplugincontroller.h + testdebugsession.h + testvariablecontroller.h + testbreakpointcontroller.h + testframestackmodel.h DESTINATION ${KDE_INSTALL_INCLUDEDIR}/kdevplatform/tests/ COMPONENT Devel ) install(FILES json/declarationvalidator.h json/delayedoutput.h json/jsontesthelpers.h json/testsuite.h json/testsuite.cpp json/jsondeclarationtests.h json/jsonducontexttests.h json/jsontypetests.h DESTINATION ${KDE_INSTALL_INCLUDEDIR}/kdevplatform/tests/json COMPONENT Devel ) diff --git a/tests/testbreakpointcontroller.cpp b/tests/testbreakpointcontroller.cpp new file mode 100644 index 0000000000..d9ccf65631 --- /dev/null +++ b/tests/testbreakpointcontroller.cpp @@ -0,0 +1,37 @@ +/* + * This file is part of KDevelop + * + * Copyright 2016 Aetf + * + * 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) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * 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, see . + * + */ + +#include "testbreakpointcontroller.h" + +using namespace KDevelop; + +TestBreakpointController::TestBreakpointController(IDebugSession *parent) + : IBreakpointController(parent) +{ + +} + +void TestBreakpointController::sendMaybe(Breakpoint *breakpoint) +{ + Q_UNUSED(breakpoint); +} diff --git a/tests/testbreakpointcontroller.h b/tests/testbreakpointcontroller.h new file mode 100644 index 0000000000..d9f2dade2f --- /dev/null +++ b/tests/testbreakpointcontroller.h @@ -0,0 +1,48 @@ +/* + * This file is part of KDevelop + * + * Copyright 2016 Aetf + * + * 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) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * 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, see . + * + */ + +#ifndef TESTBREAKPOINTCONTROLLER_H +#define TESTBREAKPOINTCONTROLLER_H + +#include "testsexport.h" + +#include + +namespace KDevelop { + +/** + * Dummy BreakpointController + */ +class KDEVPLATFORMTESTS_EXPORT TestBreakpointController : public IBreakpointController +{ + Q_OBJECT + +public: + explicit TestBreakpointController(IDebugSession *parent); + +protected: + void sendMaybe(Breakpoint *breakpoint) override; +}; + +} // end of namespace KDevelop +#endif // TESTBREAKPOINTCONTROLLER_H diff --git a/tests/testdebugsession.cpp b/tests/testdebugsession.cpp new file mode 100644 index 0000000000..6d58d57573 --- /dev/null +++ b/tests/testdebugsession.cpp @@ -0,0 +1,155 @@ +/* + * This file is part of KDevelop + * + * Copyright 2016 Aetf + * + * 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) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * 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, see . + * + */ + +#include "testdebugsession.h" + +#include "testbreakpointcontroller.h" +#include "testvariablecontroller.h" +#include "testframestackmodel.h" + +using namespace KDevelop; + +TestDebugSession::TestDebugSession() + : m_breakpointController(nullptr) + , m_variableController(nullptr) + , m_frameStackModel(nullptr) + , m_sessionState(NotStartedState) +{ + setBreakpointController(nullptr); + setVariableController(nullptr); + setFrameStackModel(nullptr); +} + +TestDebugSession::~TestDebugSession() +{ + delete m_breakpointController; + delete m_variableController; + delete m_frameStackModel; +} + +void TestDebugSession::setBreakpointController(IBreakpointController *breakpointController) +{ + delete m_breakpointController; + m_breakpointController = breakpointController; + if (!m_breakpointController) { + m_breakpointController = new TestBreakpointController(this); + } +} + +void TestDebugSession::setVariableController(IVariableController *variableController) +{ + delete m_variableController; + m_variableController = variableController; + if (!m_variableController) { + m_variableController = new TestVariableController(this); + } +} + +void TestDebugSession::setFrameStackModel(IFrameStackModel *frameStackModel) +{ + delete m_frameStackModel; + m_frameStackModel = frameStackModel; + if (!m_frameStackModel) { + m_frameStackModel = new TestFrameStackModel(this); + } +} + +IDebugSession::DebuggerState TestDebugSession::state() const +{ + return m_sessionState; +} + +bool TestDebugSession::restartAvaliable() const +{ + return true; +} + +IBreakpointController* TestDebugSession::breakpointController() const +{ + return m_breakpointController; +} + +IVariableController* TestDebugSession::variableController() const +{ + return m_variableController; +} + +IFrameStackModel* TestDebugSession::frameStackModel() const +{ + return m_frameStackModel; +} + +void TestDebugSession::restartDebugger() +{ + m_sessionState = ActiveState; +} + +void TestDebugSession::stopDebugger() +{ + m_sessionState = StoppedState; +} + +void TestDebugSession::interruptDebugger() +{ + m_sessionState = StoppedState; +} + +void TestDebugSession::run() +{ + m_sessionState = ActiveState; +} + +void TestDebugSession::runToCursor() +{ + m_sessionState = PausedState; +} + +void TestDebugSession::jumpToCursor() +{ + m_sessionState = PausedState; +} + +void TestDebugSession::stepOver() +{ + m_sessionState = PausedState; +} + +void TestDebugSession::stepIntoInstruction() +{ + m_sessionState = PausedState; +} + +void TestDebugSession::stepInto() +{ + m_sessionState = PausedState; +} + +void TestDebugSession::stepOverInstruction() +{ + m_sessionState = PausedState; +} + +void TestDebugSession::stepOut() +{ + m_sessionState = PausedState; +} diff --git a/tests/testdebugsession.h b/tests/testdebugsession.h new file mode 100644 index 0000000000..690ec6053c --- /dev/null +++ b/tests/testdebugsession.h @@ -0,0 +1,111 @@ +/* + * This file is part of KDevelop + * + * Copyright 2016 Aetf + * + * 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) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * 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, see . + * + */ + +#ifndef TESTDEBUGSESSION_H +#define TESTDEBUGSESSION_H + +#include "testsexport.h" + +#include + +#include + +using std::unique_ptr; + +namespace KDevelop { + +class IBreakpointController; +class IVariableController; +class IFrameStackModel; + +/** + * \class TestDebugSession testdebugsession.h + * + * This is an IDebugSession implementation that should be used only inside + * unit tests. + * + * The initial debug state is NotStartedState, one can use normal slots to + * change the state, for example calling runToCursor() changes to PausedState. + * See corresponding implementation for what state a specific slot changes to. + * + * This class also allows one to replace IBreakpointController, IVariableController, + * or IFrameStackModel implementation with custom implementation to make it possible + * to write tests more easily. + * + * The usage is as follows: + * \code + * AutoTestShell::init(); + * TestCore::initialize(Core::NoUi); + * TestDebugSession* session = new TestDebugSession(); + * //replace variable controller or similar + * session->setVariableController(new MyCustomVariableController(session)); + * ... //test code + * delete session; + * TestCore::shutdown(); + * \endcode + * + * @note It is important to set custom controllers right after the creation of the + * debug session, and not change them inside the test code, as required by + * IDebugSession that controllers do not change during the lifetime of a session + */ +class KDEVPLATFORMTESTS_EXPORT TestDebugSession : public IDebugSession +{ + Q_OBJECT + +public: + TestDebugSession(); + ~TestDebugSession() override; + + void setBreakpointController(IBreakpointController *breakpointController); + void setVariableController(IVariableController *variableController); + void setFrameStackModel(IFrameStackModel *frameStackModel); + + DebuggerState state() const override; + + bool restartAvaliable() const override; + IBreakpointController* breakpointController() const override; + IVariableController* variableController() const override; + IFrameStackModel* frameStackModel() const override; + +public Q_SLOTS: + void restartDebugger() override; + void stopDebugger() override; + void interruptDebugger() override; + void run() override; + void runToCursor() override; + void jumpToCursor() override; + void stepOver() override; + void stepIntoInstruction() override; + void stepInto() override; + void stepOverInstruction() override; + void stepOut() override; + +private: + IBreakpointController *m_breakpointController; + IVariableController *m_variableController; + IFrameStackModel *m_frameStackModel; + DebuggerState m_sessionState; +}; + +} // end of namespace KDevelop +#endif // TESTDEBUGSESSION_H diff --git a/tests/testframestackmodel.cpp b/tests/testframestackmodel.cpp new file mode 100644 index 0000000000..99f70245fc --- /dev/null +++ b/tests/testframestackmodel.cpp @@ -0,0 +1,43 @@ +/* + * This file is part of KDevelop + * + * Copyright 2016 Aetf + * + * 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) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * 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, see . + * + */ + +#include "testframestackmodel.h" + +using namespace KDevelop; + +TestFrameStackModel::TestFrameStackModel(IDebugSession *parent) + : FrameStackModel(parent) +{ +} + +void TestFrameStackModel::fetchThreads() +{ + +} + +void TestFrameStackModel::fetchFrames(int threadNumber, int from, int to) +{ + Q_UNUSED(threadNumber); + Q_UNUSED(from); + Q_UNUSED(to); +} diff --git a/tests/testframestackmodel.h b/tests/testframestackmodel.h new file mode 100644 index 0000000000..089dff6429 --- /dev/null +++ b/tests/testframestackmodel.h @@ -0,0 +1,51 @@ +/* + * This file is part of KDevelop + * + * Copyright 2016 Aetf + * + * 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) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * 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, see . + * + */ + +#ifndef TESTFRAMESTACKMODEL_H +#define TESTFRAMESTACKMODEL_H + +#include "testsexport.h" + +#include + +namespace KDevelop { + +/** + * Dummy frame stack model + */ +class KDEVPLATFORMTESTS_EXPORT TestFrameStackModel : public FrameStackModel +{ + Q_OBJECT + +public: + explicit TestFrameStackModel(IDebugSession *parent); + +protected: + void fetchThreads() override; + void fetchFrames(int threadNumber, int from, int to) override; + +private: +}; + +} // end of namespace KDevelop +#endif // TESTFRAMESTACKMODEL_H diff --git a/tests/testvariablecontroller.cpp b/tests/testvariablecontroller.cpp new file mode 100644 index 0000000000..659e27bb97 --- /dev/null +++ b/tests/testvariablecontroller.cpp @@ -0,0 +1,77 @@ +/* + * This file is part of KDevelop + * + * Copyright 2016 Aetf + * + * 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) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * 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, see . + * + */ + +#include "testvariablecontroller.h" + +using namespace KDevelop; +using KTextEditor::Range; +using KTextEditor::Document; +using KTextEditor::Cursor; + +TestVariableController::TestVariableController(IDebugSession* parent) + : IVariableController(parent) + , m_updatedTimes(0) +{ + +} + +Variable* TestVariableController::createVariable(TreeModel* model, TreeItem* parent, + const QString& expression, + const QString& display) +{ + Q_UNUSED(model); + Q_UNUSED(parent); + Q_UNUSED(expression); + Q_UNUSED(display); + + return nullptr; +} + +Range TestVariableController::expressionRangeUnderCursor(Document* doc, + const Cursor& cursor) +{ + Q_UNUSED(doc); + Q_UNUSED(cursor); + + return {}; +} + +void TestVariableController::addWatch(Variable* variable) +{ + Q_UNUSED(variable); +} + +void TestVariableController::addWatchpoint(Variable* variable) +{ + Q_UNUSED(variable); +} + +void TestVariableController::update() +{ + ++m_updatedTimes; +} + +int TestVariableController::updatedTimes() const +{ + return m_updatedTimes; +} diff --git a/tests/testvariablecontroller.h b/tests/testvariablecontroller.h new file mode 100644 index 0000000000..d22476bfa1 --- /dev/null +++ b/tests/testvariablecontroller.h @@ -0,0 +1,66 @@ +/* + * This file is part of KDevelop + * + * Copyright 2016 Aetf + * + * 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) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * 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, see . + * + */ + +#ifndef TESTVARIABLECONTROLLER_H +#define TESTVARIABLECONTROLLER_H + +#include "testsexport.h" + +#include + +namespace KDevelop { + +/** + * Dummy VariableController that does nothing. + */ +class KDEVPLATFORMTESTS_EXPORT TestVariableController : public IVariableController +{ + Q_OBJECT + +public: + explicit TestVariableController(IDebugSession* parent); + + Variable* createVariable(TreeModel* model, TreeItem* parent, + const QString& expression, + const QString& display = {}) override; + + KTextEditor::Range expressionRangeUnderCursor(KTextEditor::Document* doc, + const KTextEditor::Cursor& cursor) override; + + void addWatch(Variable* variable) override; + void addWatchpoint(Variable* variable) override; + + /** + * Number of times update() has been called since creation. + */ + int updatedTimes() const; + +protected: + void update() override; + +private: + int m_updatedTimes; +}; + +} // end of namespace KDevelop +#endif // TESTVARIABLECONTROLLER_H