Skip to content

Commit

Permalink
ut_rndssucli: run own (sandboxed) `ssud' instance
Browse files Browse the repository at this point in the history
Otherwise existing (not-sandboxed) `ssud' instance is talked to and
system configuration is destroyed during test execution.
  • Loading branch information
martyone committed Oct 14, 2013
1 parent 0812c21 commit 37c5df1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/ut_rndssucli/rndssuclitest.cpp
Expand Up @@ -26,9 +26,39 @@ void RndSsuCliTest::init(){
QFAIL("Failed to activate sandbox");
}
setenv("LD_PRELOAD", qPrintable(QString("%1/libsandboxhook.so").arg(TESTS_PATH)), 1);

m_bus = new QProcess(this);
m_bus->start("dbus-daemon",
Args() << "--session" << "--nofork" << "--nopidfile" << "--print-address");
if (!m_bus->waitForReadyRead()){
QFAIL("Failed to run sandboxed D-Bus instance");
}
const QByteArray busAddress = m_bus->readAllStandardOutput();
setenv("DBUS_SESSION_BUS_ADDRESS", busAddress.constData(), 1);
setenv("DBUS_SYSTEM_BUS_ADDRESS", busAddress.constData(), 1);

m_ssud = new QProcess(this);
m_ssud->start("ssud");
if (!m_ssud->waitForStarted()){
QFAIL("Failed to run sandboxed ssud instance");
}
}

void RndSsuCliTest::cleanup(){
if (m_ssud->state() != QProcess::Running){
QFAIL("Sandboxed ssud instance exited unexpectedly");
}
delete m_ssud;
m_ssud = 0;

if (m_bus->state() != QProcess::Running){
QFAIL("Sandboxed D-Bus instance exited unexpectedly");
}
unsetenv("DBUS_SESSION_BUS_ADDRESS");
unsetenv("DBUS_SYSTEM_BUS_ADDRESS");
delete m_bus;
m_bus = 0;

delete m_sandbox;
m_sandbox = 0;
}
Expand Down
4 changes: 4 additions & 0 deletions tests/ut_rndssucli/rndssuclitest.h
Expand Up @@ -10,6 +10,8 @@

#include <QObject>

class QProcess;

class Sandbox;

class RndSsuCliTest: public QObject {
Expand All @@ -28,6 +30,8 @@ class RndSsuCliTest: public QObject {

private:
Sandbox *m_sandbox;
QProcess *m_bus;
QProcess *m_ssud;
};

#endif

0 comments on commit 37c5df1

Please sign in to comment.