File indexing completed on 2024-05-12 04:37:37

0001 /*
0002     SPDX-FileCopyrightText: 2016 Aetf <aetf@unlimitedcodeworks.xyz>
0003 
0004     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 #include "test_ivariablecontroller.h"
0008 
0009 #include <debugger/interfaces/ivariablecontroller.h>
0010 #include <debugger/interfaces/iframestackmodel.h>
0011 #include <tests/autotestshell.h>
0012 #include <tests/testcore.h>
0013 #include <tests/testdebugsession.h>
0014 #include <tests/testvariablecontroller.h>
0015 
0016 #include <QTest>
0017 
0018 QTEST_MAIN(KDevelop::TestIVariableController)
0019 
0020 using namespace KDevelop;
0021 
0022 TestIVariableController::TestIVariableController(QObject* parent)
0023     : QObject(parent)
0024 {
0025 }
0026 
0027 void TestIVariableController::initTestCase()
0028 {
0029     AutoTestShell::init();
0030     TestCore::initialize(Core::NoUi);
0031     m_debugSession = new TestDebugSession();
0032     // Simulate an already started and paused debug session
0033     m_debugSession->runToCursor();
0034 }
0035 
0036 void KDevelop::TestIVariableController::updateRightAfterEnableAutoUpdate_data()
0037 {
0038     QTest::addColumn<int>("startAt");
0039     QTest::addColumn<int>("switchTo");
0040     QTest::addColumn<int>("jumpTo");
0041 
0042     QTest::newRow("jump to somewhere else") << 1 << 0 << 2;
0043     QTest::newRow("jump back") << 1 << 0 << 1;
0044 }
0045 
0046 void TestIVariableController::updateRightAfterEnableAutoUpdate()
0047 {
0048     QFETCH(int, startAt);
0049     QFETCH(int, switchTo);
0050     QFETCH(int, jumpTo);
0051 
0052     auto frameStackModel = m_debugSession->frameStackModel();
0053     auto variableController = qobject_cast<TestVariableController*>(m_debugSession->variableController());
0054     if (!variableController) {
0055         return;
0056     }
0057 
0058     frameStackModel->setCurrentThread(0);
0059     frameStackModel->setCurrentFrame(startAt);
0060 
0061     int oldCounter = variableController->updatedTimes();
0062 
0063     variableController->setAutoUpdate(IVariableController::UpdateNone);
0064     frameStackModel->setCurrentFrame(switchTo); // no update
0065     variableController->setAutoUpdate(IVariableController::UpdateLocals); // trigger update
0066     // switch back to frame we were at before disable auto update
0067     frameStackModel->setCurrentFrame(jumpTo); // trigger another update
0068 
0069     int updatedTimes = variableController->updatedTimes() - oldCounter;
0070     QCOMPARE(updatedTimes, 2);
0071 }
0072 
0073 void TestIVariableController::cleanupTestCase()
0074 {
0075     delete m_debugSession;
0076     TestCore::shutdown();
0077 }
0078 
0079 #include "moc_test_ivariablecontroller.cpp"