Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
ut_rndssucli: use Sandbox with UseAsSkeleton
  • Loading branch information
martyone committed Apr 4, 2013
1 parent 8b12419 commit 715aba3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 41 deletions.
45 changes: 7 additions & 38 deletions tests/ut_rndssucli/rndssuclitest.cpp
Expand Up @@ -12,53 +12,22 @@

#include <QtTest/QtTest>

#include "libssu/sandbox_p.h"
#include "testutils/process.h"

typedef QStringList Args; // improve readability

void RndSsuCliTest::initTestCase(){
Process mktemp;
tempDir =
mktemp.execute("mktemp", Args() << "-t" << "-d" << "ut_rndssucli.XXX").trimmed();
QVERIFY2(!mktemp.hasError(), qPrintable(mktemp.fmtErrorMessage()));

QVERIFY2(QFileInfo(tempDir).isDir(), qPrintable(
QString("Temporary directory disappeared: '%1'").arg(tempDir)));

setenv("LD_PRELOAD", qPrintable(QString("%1/libsandboxhook.so").arg(TESTS_PATH)), 1);
setenv("SSU_TESTS_SANDBOX", qPrintable(QString("%1/configroot").arg(tempDir)), 1);
}

void RndSsuCliTest::cleanupTestCase(){

if (tempDir.isEmpty()){
return;
}

Process rm;
rm.execute("rm", Args() << "-rf" << tempDir);
QVERIFY2(!rm.hasError(), qPrintable(rm.fmtErrorMessage()));
}

void RndSsuCliTest::init(){
Q_ASSERT(!tempDir.isEmpty());
Q_ASSERT(m_sandbox == 0);

QVERIFY2(QFileInfo(tempDir).isDir(), qPrintable(
QString("Temporary directory disappeared: '%1'").arg(tempDir)));
QVERIFY2(QDir(tempDir).entryList(QDir::NoDotAndDotDot).count() == 0, qPrintable(
QString("Garbage in temporary directory: '%1'").arg(tempDir)));

Process cp;
cp.execute("cp", Args() << "-r" << QString("%1/configroot").arg(TESTS_DATA_PATH) << tempDir);
QVERIFY2(!cp.hasError(), qPrintable(cp.fmtErrorMessage()));
m_sandbox = new Sandbox(QString("%1/configroot").arg(TESTS_DATA_PATH),
Sandbox::UseAsSkeleton, Sandbox::ChildProcesses);
setenv("LD_PRELOAD", qPrintable(QString("%1/libsandboxhook.so").arg(TESTS_PATH)), 1);
}

void RndSsuCliTest::cleanup(){
Q_ASSERT(!tempDir.isEmpty());

Process rm;
rm.execute("rm", Args() << "-rf" << QString("%1/configroot").arg(tempDir));
QVERIFY2(!rm.hasError(), qPrintable(rm.fmtErrorMessage()));
delete m_sandbox;
m_sandbox = 0;
}

void RndSsuCliTest::testSubcommandFlavour(){
Expand Down
6 changes: 3 additions & 3 deletions tests/ut_rndssucli/rndssuclitest.h
Expand Up @@ -10,12 +10,12 @@

#include <QObject>

class Sandbox;

class RndSsuCliTest: public QObject {
Q_OBJECT

private slots:
void initTestCase();
void cleanupTestCase();
void init();
void cleanup();

Expand All @@ -24,7 +24,7 @@ class RndSsuCliTest: public QObject {
void testSubcommandMode();

private:
QString tempDir;
Sandbox *m_sandbox;
};

#endif

0 comments on commit 715aba3

Please sign in to comment.