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
tests/sandbox: initial commit
- Loading branch information
Showing
5 changed files
with
120 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
SOURCES = sandboxhook.cpp | ||
|
||
TEMPLATE = lib | ||
TARGET = sandboxhook | ||
CONFIG -= app_bundle | ||
CONFIG += console qtestlib | ||
QT -= gui | ||
QT += network testlib | ||
|
||
!include( ../tests.pri ) { error("Unable to find tests include") } | ||
|
||
unix:target.path = $${PREFIX}/$$TESTS_PATH | ||
INSTALLS += target | ||
|
||
!include( ../../buildpath.pri ) { error("Unable to find build path specification") } |
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,90 @@ | ||
/** | ||
* @file sandboxfileenginehandler.h | ||
* @copyright 2013 Jolla Ltd. | ||
* @author Martin Kampas <martin.kampas@tieto.com> | ||
* @date 2013 | ||
*/ | ||
|
||
#ifndef _SANDBOXINGFILEENGINEHANDLER_H | ||
#define _SANDBOXINGFILEENGINEHANDLER_H | ||
|
||
#include <QtCore/QAbstractFileEngineHandler> | ||
#include <QtCore/QDir> | ||
#include <QtCore/QFSFileEngine> | ||
#include <QtCore/QFileInfo> | ||
#include <QtCore/QProcessEnvironment> | ||
#include <QtCore/QSet> | ||
|
||
#include <ssucoreconfig.h> | ||
#include "../../constants.h" | ||
|
||
/** | ||
* Redirects all file operations on system configuration files to files under | ||
* directory specified by SSU_TESTS_SANDBOX environment variable. | ||
*/ | ||
class SandboxFileEngineHandler : public QAbstractFileEngineHandler { | ||
public: | ||
QAbstractFileEngine *create(const QString &fileName) const{ | ||
static bool enabled = false; | ||
static bool firstCall = true; | ||
|
||
if (!enabled && !firstCall){ | ||
return 0; | ||
} | ||
|
||
static QString sandboxPath = | ||
QProcessEnvironment::systemEnvironment().value("SSU_TESTS_SANDBOX"); | ||
|
||
if (firstCall){ | ||
firstCall = false; | ||
|
||
if (sandboxPath.isEmpty()){ | ||
return 0; | ||
} | ||
|
||
if (!QFileInfo(sandboxPath).exists()){ | ||
qFatal("%s: Invalid SSU_TESTS_SANDBOX value: No such file or directory", | ||
qPrintable(sandboxPath)); | ||
} | ||
|
||
if (!QFileInfo(sandboxPath).isDir()){ | ||
qFatal("%s: Invalid SSU_TESTS_SANDBOX value: Not a directory", | ||
qPrintable(sandboxPath)); | ||
} | ||
|
||
enabled = true; | ||
} | ||
|
||
if (!fileName.startsWith('/')){ | ||
return 0; | ||
} | ||
|
||
static QSet<QString> ssuConfigFiles = QSet<QString>() | ||
<< SSU_CONFIGURATION | ||
<< SSU_REPO_CONFIGURATION | ||
<< SSU_DEFAULT_CONFIGURATION | ||
<< SSU_BOARD_MAPPING_CONFIGURATION; | ||
|
||
static QSet<QString> ssuConfigDirectories = QSet<QString>() | ||
<< SSU_BOARD_MAPPING_CONFIGURATION_DIR; | ||
|
||
if (!ssuConfigFiles.contains(fileName)){ | ||
bool match = false; | ||
foreach (const QString &ssuConfigDirectory, ssuConfigDirectories){ | ||
if (fileName.startsWith(ssuConfigDirectory + '/')){ | ||
match = true; | ||
break; | ||
} | ||
} | ||
if (!match){ | ||
return 0; | ||
} | ||
} | ||
|
||
const QString fileName_ = QDir(sandboxPath).absoluteFilePath(QString(fileName).remove(0, 1)); | ||
|
||
return new QFSFileEngine(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,12 @@ | ||
#include <dlfcn.h> | ||
|
||
#include "sandboxfileenginehandler.h" | ||
|
||
extern "C" void qt_startup_hook() | ||
{ | ||
SandboxFileEngineHandler *const handler = new SandboxFileEngineHandler(); | ||
Q_UNUSED(handler); | ||
|
||
static void(*next_qt_startup_hook)() = (void (*)()) dlsym(RTLD_NEXT, "qt_startup_hook"); | ||
next_qt_startup_hook(); | ||
} |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
DEPENDPATH *= $${PWD}/sandbox | ||
|
||
TESTS_PATH = /opt/tests/ssu | ||
DEFINES += TESTS_PATH="'\"$${TESTS_PATH}\"'" | ||
|
||
|
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