Commit eba26111 authored by Peifeng Yu's avatar Peifeng Yu
Browse files

Add unit test about environment variable for lldb plugin

parent c389b3d7
......@@ -5,6 +5,7 @@ add_debuggable_executable(lldb_debugeerecursion SRCS debugeerecursion.cpp)
add_debuggable_executable(lldb_debugeespace SRCS "debugee space.cpp")
add_debuggable_executable(lldb_debugeemultilocbreakpoint SRCS debugeemultilocbreakpoint.cpp)
add_debuggable_executable(lldb_debugeemultiplebreakpoint SRCS debugeemultiplebreakpoint.cpp)
add_debuggable_executable(lldb_debugeeechoenv SRCS debugeeechoenv.cpp)
add_debuggable_executable(lldb_debugeethreads SRCS debugeethreads.cpp)
target_link_libraries(lldb_debugeethreads Qt5::Core)
......
/*
* Copyright 2016 Aetf <aetf@unlimitedcodeworks.xyz>
*
* 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 <http://www.gnu.org/licenses/>.
*
*/
#include <iostream>
#include <cstdlib>
int main() {
char * value = std::getenv("VariableA");
if (value) {
std::cout << value << std::endl;
} else {
std::cout << "Not found!" << std::endl;
}
return 0;
}
......@@ -36,6 +36,7 @@
#include <interfaces/iplugincontroller.h>
#include <tests/autotestshell.h>
#include <tests/testcore.h>
#include <util/environmentgrouplist.h>
#include <KConfigGroup>
#include <KIO/Global>
......@@ -43,6 +44,7 @@
#include <QFileInfo>
#include <QSignalSpy>
#include <QStringList>
#include <QTest>
#include <QTemporaryFile>
#include <QUrl>
......@@ -78,6 +80,16 @@ using namespace KDevelop;
using namespace KDevMI::LLDB;
namespace {
class WritableEnvironmentGroupList : public EnvironmentGroupList
{
public:
explicit WritableEnvironmentGroupList(KConfig* config) : EnvironmentGroupList(config) {}
using EnvironmentGroupList::variables;
using EnvironmentGroupList::saveSettings;
using EnvironmentGroupList::removeGroup;
};
class TestLaunchConfiguration : public ILaunchConfiguration
{
public:
......@@ -90,6 +102,11 @@ public:
cfg.writeEntry("isExecutable", true);
cfg.writeEntry("Executable", executable);
cfg.writeEntry("Working Directory", workingDirectory);
WritableEnvironmentGroupList groupList(c);
groupList.removeGroup("LldbTestGroup");
groupList.variables("LldbTestGroup")["VariableA"] = "A good value";
groupList.saveSettings(c);
}
~TestLaunchConfiguration() override {
delete c;
......@@ -236,6 +253,23 @@ void LldbTest::testStdout()
QCOMPARE(arguments.first().toStringList(), QStringList() << "Hello");
}
void LldbTest::testEnvironmentSet()
{
TestDebugSession *session = new TestDebugSession;
TestLaunchConfiguration cfg(findExecutable("lldb_debugeeechoenv"));
cfg.config().writeEntry("EnvironmentGroup", "LldbTestGroup");
QSignalSpy outputSpy(session, &TestDebugSession::inferiorStdoutLines);
QVERIFY(session->startDebugging(&cfg, m_iface));
WAIT_FOR_STATE(session, KDevelop::IDebugSession::EndedState);
QCOMPARE(outputSpy.count(), 1);
QList<QVariant> arguments = outputSpy.takeFirst();
QCOMPARE(arguments.count(), 1);
QCOMPARE(arguments.first().toStringList(), QStringList() << "A good value");
}
void LldbTest::testBreakpoint()
{
TestDebugSession *session = new TestDebugSession;
......@@ -246,15 +280,15 @@ void LldbTest::testBreakpoint()
QCOMPARE(b->state(), KDevelop::Breakpoint::NotStartedState);
QVERIFY(session->startDebugging(&cfg, m_iface));
WAIT_FOR_STATE(session, DebugSession::PausedState);
WAIT_FOR_STATE_AND_IDLE(session, DebugSession::PausedState);
QCOMPARE(b->state(), KDevelop::Breakpoint::CleanState);
QCOMPARE(session->currentLine(), 29);
session->stepInto();
WAIT_FOR_STATE(session, DebugSession::PausedState);
WAIT_FOR_STATE_AND_IDLE(session, DebugSession::PausedState);
session->stepInto();
WAIT_FOR_STATE(session, DebugSession::PausedState);
WAIT_FOR_STATE_AND_IDLE(session, DebugSession::PausedState);
session->run();
WAIT_FOR_STATE(session, DebugSession::EndedState);
......
......@@ -47,6 +47,7 @@ private slots:
void cleanup();
void testStdout();
void testEnvironmentSet();
void testBreakpoint();
void testBreakOnStart();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment