Commit 9dbf5230 authored by Martin Kampas's avatar Martin Kampas

ut_sandbox: initial commit

parent c4d77eca
......@@ -5,6 +5,7 @@ SUBDIRS = \
testutils/sandboxhook.pro \
ut_coreconfig \
ut_rndssucli \
ut_sandbox \
ut_settings \
ut_ssuurlresolver \
ut_urlresolver \
......
......@@ -13,6 +13,11 @@
<step expected_result="0">/opt/tests/ssu/runtest.sh ut_rndssucli</step>
</case>
</set>
<set name="sandbox" description="Test to determine if sandboxing works properly" feature="sandbox">
<case name="ut_sandbox" type="Functional" description="Sandboxing test" timeout="1000" subfeature="">
<step expected_result="0">/opt/tests/ssu/runtest.sh ut_sandbox</step>
</case>
</set>
<set name="settings" description="Test to determine if configuration files processing works properly" feature="settings">
<case name="ut_settings" type="Functional" description="Settings processing test" timeout="1000" subfeature="">
<step expected_result="0">/opt/tests/ssu/runtest.sh ut_settings</step>
......
/**
* @file main.cpp
* @copyright 2012 Jolla Ltd.
* @author Martin Kampas <martin.kampas@tieto.com>
* @date 2012
*/
#include <QtTest/QtTest>
#include "sandboxtest.h"
int main(int argc, char **argv){
SandboxTest sandboxTest;
if (QTest::qExec(&sandboxTest, argc, argv))
return 1;
return 0;
}
/**
* @file sandboxtest.cpp
* @copyright 2013 Jolla Ltd.
* @author Martin Kampas <martin.kampas@tieto.com>
* @date 2013
*/
#include "sandboxtest.h"
#include <QtTest/QtTest>
#include "libssu/sandbox_p.h"
void SandboxTest::test(){
const QDir::Filters noHidden = QDir::AllEntries | QDir::NoDotAndDotDot;
QCOMPARE(QDir(TESTS_DATA_PATH "/world").entryList(noHidden, QDir::Name),
QStringList()
<< "world-and-sandbox"
<< "world-only"
<< "world-only-to-be-copied-into-sandbox");
QVERIFY(!QFileInfo(TESTS_DATA_PATH "/world/world-only").isWritable());
QCOMPARE(readAll(TESTS_DATA_PATH "/world/world-only").trimmed(),
QString("world/world-only"));
QVERIFY(!QFileInfo(TESTS_DATA_PATH "/world/world-and-sandbox").isWritable());
QCOMPARE(readAll(TESTS_DATA_PATH "/world/world-and-sandbox").trimmed(),
QString("world/world-and-sandbox"));
QVERIFY(!QFileInfo(TESTS_DATA_PATH "/world/world-only-to-be-copied-into-sandbox").isWritable());
QCOMPARE(readAll(TESTS_DATA_PATH "/world/world-only-to-be-copied-into-sandbox").trimmed(),
QString("world/world-only-to-be-copied-into-sandbox"));
QVERIFY(!QFileInfo(TESTS_DATA_PATH "/world/sandbox-only").exists());
Sandbox sandbox(TESTS_DATA_PATH "/sandbox",
Sandbox::UseAsSkeleton, Sandbox::ThisProcess | Sandbox::ChildProcesses);
sandbox.addWorldFiles(TESTS_DATA_PATH "/world", QDir::AllEntries,
QStringList() << "*-to-be-copied-into-sandbox");
QVERIFY(sandbox.activate());
QCOMPARE(QDir(TESTS_DATA_PATH "/world").entryList(noHidden, QDir::Name),
QStringList()
<< "world-and-sandbox"
<< "world-only"
<< "world-only-to-be-copied-into-sandbox");
QVERIFY(!QFileInfo(TESTS_DATA_PATH "/world/world-only").isWritable());
QCOMPARE(readAll(TESTS_DATA_PATH "/world/world-only").trimmed(),
QString("world/world-only"));
QVERIFY(QFileInfo(TESTS_DATA_PATH "/world/world-and-sandbox").isWritable());
QCOMPARE(readAll(TESTS_DATA_PATH "/world/world-and-sandbox").trimmed(),
QString("sandbox/world-and-sandbox"));
QVERIFY(QFileInfo(TESTS_DATA_PATH "/world/world-only-to-be-copied-into-sandbox").isWritable());
QCOMPARE(readAll(TESTS_DATA_PATH "/world/world-only-to-be-copied-into-sandbox").trimmed(),
QString("world/world-only-to-be-copied-into-sandbox"));
QVERIFY(QFileInfo(TESTS_DATA_PATH "/world/sandbox-only").exists());
QVERIFY(QFileInfo(TESTS_DATA_PATH "/world/sandbox-only").isWritable());
QCOMPARE(readAll(TESTS_DATA_PATH "/world/sandbox-only").trimmed(),
QString("sandbox/sandbox-only"));
}
QString SandboxTest::readAll(const QString &fileName){
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly)){
qWarning("%s: Failed to open file for reading: '%s': %s", Q_FUNC_INFO, qPrintable(fileName),
qPrintable(file.errorString()));
return QString();
}
return file.readAll();
}
/**
* @file sandboxtest.h
* @copyright 2013 Jolla Ltd.
* @author Martin Kampas <martin.kampas@tieto.com>
* @date 2013
*/
#ifndef _SANDBOXTEST_H
#define _SANDBOXTEST_H
#include <QObject>
class SandboxTest: public QObject {
Q_OBJECT
private slots:
void test();
private:
static QString readAll(const QString &fileName);
};
#endif
TARGET = ut_sandbox
include(../testapplication.pri)
include(ut_sandbox_dependencies.pri)
HEADERS = \
sandboxtest.h \
SOURCES = \
main.cpp \
sandboxtest.cpp \
test_data_world.path = $${TESTS_DATA_PATH}/world
test_data_world.files = \
testdata/world/world-only \
testdata/world/world-and-sandbox \
testdata/world/world-only-to-be-copied-into-sandbox \
test_data_sandbox.path = $${TESTS_DATA_PATH}/sandbox/$${test_data_world.path}
test_data_sandbox.files = \
testdata/sandbox/world-and-sandbox \
testdata/sandbox/sandbox-only \
INSTALLS += test_data_world test_data_sandbox
include(../../libssu/libssu.pri)
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