diff --git a/debugger/CMakeLists.txt b/debugger/CMakeLists.txt index ba8ab8cff8..ad91f8282e 100644 --- a/debugger/CMakeLists.txt +++ b/debugger/CMakeLists.txt @@ -1,64 +1,66 @@ add_definitions(-DTRANSLATION_DOMAIN=\"kdevplatform\") set(KDevPlatformDebugger_LIB_SRCS interfaces/idebugsession.cpp interfaces/iframestackmodel.cpp interfaces/ibreakpointcontroller.cpp interfaces/ivariablecontroller.cpp util/treeitem.cpp util/treemodel.cpp util/treeview.cpp util/pathmappings.cpp util/debug.cpp breakpoint/breakpoint.cpp breakpoint/breakpointmodel.cpp breakpoint/breakpointwidget.cpp breakpoint/breakpointdetails.cpp variable/variablewidget.cpp variable/variablecollection.cpp variable/variabletooltip.cpp variable/variablesortmodel.cpp framestack/framestackmodel.cpp framestack/framestackwidget.cpp ) kdevplatform_add_library(KDevPlatformDebugger SOURCES ${KDevPlatformDebugger_LIB_SRCS}) target_link_libraries(KDevPlatformDebugger LINK_PUBLIC KDev::Interfaces KDev::Util LINK_PRIVATE Qt5::Core KF5::Notifications KF5::TextEditor KDev::Sublime ) install(FILES interfaces/idebugsession.h interfaces/ibreakpointcontroller.h interfaces/ivariablecontroller.h interfaces/iframestackmodel.h DESTINATION ${KDE_INSTALL_INCLUDEDIR}/kdevplatform/debugger/interfaces COMPONENT Devel ) install(FILES util/treemodel.h util/treeitem.h util/treeview.h util/pathmappings.h DESTINATION ${KDE_INSTALL_INCLUDEDIR}/kdevplatform/debugger/util COMPONENT Devel ) install(FILES breakpoint/breakpointwidget.h breakpoint/breakpointdetails.h breakpoint/breakpoint.h breakpoint/breakpointmodel.h DESTINATION ${KDE_INSTALL_INCLUDEDIR}/kdevplatform/debugger/breakpoint COMPONENT Devel ) install(FILES variable/variablecollection.h DESTINATION ${KDE_INSTALL_INCLUDEDIR}/kdevplatform/debugger/variable COMPONENT Devel ) install(FILES framestack/framestackmodel.h DESTINATION ${KDE_INSTALL_INCLUDEDIR}/kdevplatform/debugger/framestack COMPONENT Devel ) + +add_subdirectory(tests) diff --git a/debugger/tests/CMakeLists.txt b/debugger/tests/CMakeLists.txt new file mode 100644 index 0000000000..f9d7503b70 --- /dev/null +++ b/debugger/tests/CMakeLists.txt @@ -0,0 +1,7 @@ +ecm_add_test(test_ivariablecontroller LINK_LIBRARIES + Qt5::Core + Qt5::Test + KDev::Tests + KDev::Debugger +) + diff --git a/debugger/tests/test_ivariablecontroller.cpp b/debugger/tests/test_ivariablecontroller.cpp new file mode 100644 index 0000000000..1f8fc050bb --- /dev/null +++ b/debugger/tests/test_ivariablecontroller.cpp @@ -0,0 +1,94 @@ +/* + * KDevelop Debugger Support + * + * 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 "test_ivariablecontroller.h" + +#include +#include +#include +#include +#include +#include + +#include + +QTEST_MAIN(KDevelop::TestIVariableController); + +using namespace KDevelop; + +TestIVariableController::TestIVariableController(QObject* parent) + : QObject(parent) + , m_debugSession(nullptr) +{ +} + +void TestIVariableController::initTestCase() +{ + AutoTestShell::init(); + TestCore::initialize(Core::NoUi); + m_debugSession = new TestDebugSession(); + // Simulate an already started and paused debug session + m_debugSession->runToCursor(); +} + +void KDevelop::TestIVariableController::updateRightAfterEnableAutoUpdate_data() +{ + QTest::addColumn("startAt"); + QTest::addColumn("switchTo"); + QTest::addColumn("jumpTo"); + + QTest::newRow("jump to somewhere else") << 1 << 0 << 2; + QTest::newRow("jump back") << 1 << 0 << 1; +} + +void TestIVariableController::updateRightAfterEnableAutoUpdate() +{ + QFETCH(int, startAt); + QFETCH(int, switchTo); + QFETCH(int, jumpTo); + + auto frameStackModel = m_debugSession->frameStackModel(); + auto variableController = qobject_cast(m_debugSession->variableController()); + if (!variableController) { + return; + } + + frameStackModel->setCurrentThread(0); + frameStackModel->setCurrentFrame(startAt); + + int oldCounter = variableController->updatedTimes(); + + variableController->setAutoUpdate(IVariableController::UpdateNone); + frameStackModel->setCurrentFrame(switchTo); // no update + variableController->setAutoUpdate(IVariableController::UpdateLocals); // trigger update + // switch back to frame we were at before disable auto update + frameStackModel->setCurrentFrame(jumpTo); // trigger another update + + int updatedTimes = variableController->updatedTimes() - oldCounter; + QCOMPARE(updatedTimes, 2); +} + +void TestIVariableController::cleanupTestCase() +{ + delete m_debugSession; + TestCore::shutdown(); +} diff --git a/debugger/tests/test_ivariablecontroller.h b/debugger/tests/test_ivariablecontroller.h new file mode 100644 index 0000000000..4f7d44f2f4 --- /dev/null +++ b/debugger/tests/test_ivariablecontroller.h @@ -0,0 +1,53 @@ +/* + * KDevelop Debugger Support + * + * 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 KDEVPLATFORM_TEST_IVARIABLECONTROLLER_H +#define KDEVPLATFORM_TEST_IVARIABLECONTROLLER_H + +#include + +namespace KDevelop +{ +class TestDebugSession; + +class TestIVariableController : public QObject +{ +Q_OBJECT +public: + explicit TestIVariableController(QObject* parent = nullptr); + +private Q_SLOTS: + void initTestCase(); + void cleanupTestCase(); + + /** + * Test for bug 333759. see https://bugs.kde.org/show_bug.cgi?id=333759 + */ + void updateRightAfterEnableAutoUpdate(); + void updateRightAfterEnableAutoUpdate_data(); + +private: + TestDebugSession *m_debugSession; +}; + +} +#endif // KDEVPLATFORM_TEST_IVARIABLECONTROLLER_H