sandbox_p.h 1.73 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
/**
 * @file sandbox_p.h
 * @copyright 2013 Jolla Ltd.
 * @author Martin Kampas <martin.kampas@tieto.com>
 * @date 2013
 */

#ifndef _SANDBOX_P_H
#define _SANDBOX_P_H

11
#include <QtCore/QDir>
12
#include <QtCore/QSet>
13 14
#include <QtCore/QString>

15 16 17 18 19 20
// use either environment variable SSU_TESTS_DATA_PATH or compile time
// TESTS_DATA_PATH to locate test data
#define LOCATE_DATA_PATH (getenv("SSU_TESTS_DATA_PATH") ? \
                          getenv("SSU_TESTS_DATA_PATH") : \
                          TESTS_DATA_PATH)

21 22 23
class Sandbox
{
public:
24
    enum Usage {
25 26
        UseDirectly,
        UseAsSkeleton,
27 28
    };

29
    enum Scope {
30 31
        ThisProcess    = 0x01,
        ChildProcesses = 0x02,
32 33 34
    };
    Q_DECLARE_FLAGS(Scopes, Scope)

35
public:
36
    Sandbox();
37
    Sandbox(const QString &sandboxPath, Usage usage, Scopes scopes);
38 39
    ~Sandbox();

40
    bool activate();
41
    void deactivate();
42 43
    bool isActive() const;

44 45
    static QDir effectiveRootDir();
    static QString map(const QString &fileName);
46
    static QString map(const QString &pathName, const QString &fileName);
47

48
    bool addWorldFiles(const QString &directory, QDir::Filters filters = QDir::NoFilter,
49
                       const QStringList &filterNames = QStringList(), bool recurse = true);
50
    bool addWorldFile(const QString &file);
51

52
private:
53
    bool prepare();
54
    static QString createTmpDir(const QString &nameTemplate);
55
    static bool copyDir(const QString &directory, const QString &newName);
56

57
private:
58 59 60 61 62 63
    static Sandbox *s_activeInstance;
    const bool m_defaultConstructed;
    const Usage m_usage;
    const Scopes m_scopes;
    const QString m_sandboxPath;
    bool m_prepared;
64
    QString m_tempDir;
65
    QDir m_workingSandboxDir;
66 67
};

68 69
Q_DECLARE_OPERATORS_FOR_FLAGS(Sandbox::Scopes)

70
#endif