Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
ut_sandbox: initial commit
- Loading branch information
Showing
12 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sandbox/sandbox-only |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sandbox/world-and-sandbox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
world/world-and-sandbox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
world/world-only |
1 change: 1 addition & 0 deletions
1
tests/ut_sandbox/testdata/world/world-only-to-be-copied-into-sandbox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
world/world-only-to-be-copied-into-sandbox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include(../../libssu/libssu.pri) |