ssu
sandbox_p.h
Go to the documentation of this file.
1 
8 #ifndef _SANDBOX_P_H
9 #define _SANDBOX_P_H
10 
11 #include <QtCore/QDir>
12 #include <QtCore/QSet>
13 #include <QtCore/QString>
14 
15 // use either environment variable SSU_TESTS_DATA_PATH or compile time
16 // TESTS_DATA_PATH to locate test data
17 #define LOCATE_DATA_PATH (getenv("SSU_TESTS_DATA_PATH") ? \
18  getenv("SSU_TESTS_DATA_PATH") : \
19  TESTS_DATA_PATH)
20 
21 class Sandbox
22 {
23 public:
24  enum Usage {
25  UseDirectly,
26  UseAsSkeleton,
27  };
28 
29  enum Scope {
30  ThisProcess = 0x01,
31  ChildProcesses = 0x02,
32  };
33  Q_DECLARE_FLAGS(Scopes, Scope)
34 
35 public:
36  Sandbox();
37  Sandbox(const QString &sandboxPath, Usage usage, Scopes scopes);
38  ~Sandbox();
39 
40  bool activate();
41  void deactivate();
42  bool isActive() const;
43 
44  static QDir effectiveRootDir();
45  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  static Sandbox *s_activeInstance;
59  const bool m_defaultConstructed;
60  const Usage m_usage;
61  const Scopes m_scopes;
62  const QString m_sandboxPath;
63  bool m_prepared;
64  QString m_tempDir;
65  QDir m_workingSandboxDir;
66 };
67 
68 Q_DECLARE_OPERATORS_FOR_FLAGS(Sandbox::Scopes)
69 
70 #endif
Sandbox
Helps to redirect file operations into sandbox directory.
Definition: sandbox_p.h:21
Sandbox::addWorldFiles
bool addWorldFiles(const QString &directory, QDir::Filters filters=QDir::NoFilter, const QStringList &filterNames=QStringList(), bool recurse=true)
Definition: sandbox.cpp:146