Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
ut_sandbox: initial commit
  • Loading branch information
martyone committed Apr 8, 2013
1 parent c4d77ec commit 9dbf523
Show file tree
Hide file tree
Showing 12 changed files with 156 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/tests.pro
Expand Up @@ -5,6 +5,7 @@ SUBDIRS = \
testutils/sandboxhook.pro \
ut_coreconfig \
ut_rndssucli \
ut_sandbox \
ut_settings \
ut_ssuurlresolver \
ut_urlresolver \
Expand Down
5 changes: 5 additions & 0 deletions tests/tests.xml
Expand Up @@ -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>
Expand Down
19 changes: 19 additions & 0 deletions tests/ut_sandbox/main.cpp
@@ -0,0 +1,19 @@
/**
* @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;
}
79 changes: 79 additions & 0 deletions tests/ut_sandbox/sandboxtest.cpp
@@ -0,0 +1,79 @@
/**
* @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();
}
23 changes: 23 additions & 0 deletions tests/ut_sandbox/sandboxtest.h
@@ -0,0 +1,23 @@
/**
* @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
1 change: 1 addition & 0 deletions tests/ut_sandbox/testdata/sandbox/sandbox-only
@@ -0,0 +1 @@
sandbox/sandbox-only
1 change: 1 addition & 0 deletions tests/ut_sandbox/testdata/sandbox/world-and-sandbox
@@ -0,0 +1 @@
sandbox/world-and-sandbox
1 change: 1 addition & 0 deletions tests/ut_sandbox/testdata/world/world-and-sandbox
@@ -0,0 +1 @@
world/world-and-sandbox
1 change: 1 addition & 0 deletions tests/ut_sandbox/testdata/world/world-only
@@ -0,0 +1 @@
world/world-only
@@ -0,0 +1 @@
world/world-only-to-be-copied-into-sandbox
23 changes: 23 additions & 0 deletions tests/ut_sandbox/ut_sandbox.pro
@@ -0,0 +1,23 @@
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
1 change: 1 addition & 0 deletions tests/ut_sandbox/ut_sandbox_dependencies.pri
@@ -0,0 +1 @@
include(../../libssu/libssu.pri)

0 comments on commit 9dbf523

Please sign in to comment.