Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. Un-inline SandboxFileEngineHandler (originally it was all implemented in single header file to avoid the need for a real library to be linked) 2. Extract RndSsuCliTest::Process 3. Keep all the stuff inside tests/testutils
- Loading branch information
Showing
18 changed files
with
261 additions
and
163 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 was deleted.
Oops, something went wrong.
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
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,68 @@ | ||
/** | ||
* @file process.cpp | ||
* @copyright 2013 Jolla Ltd. | ||
* @author Martin Kampas <martin.kampas@tieto.com> | ||
* @date 2013 | ||
*/ | ||
|
||
#include "process.h" | ||
|
||
/** | ||
* @class Wraps QProcess for easier use within test code | ||
* | ||
* Example use: | ||
* | ||
* @code | ||
* Process ssu; | ||
* const QString output = ssu.execute("ssu", QStringList() << "mode"); | ||
* QVERIFY2(!ssu.hasError(), qPrintable(ssu.fmtErrorMessage())); | ||
* | ||
* QCOMPARE(output, "..."); | ||
* @endcode | ||
*/ | ||
|
||
Process::Process() : m_expectFail(false), m_timedOut(false) {} | ||
|
||
QString Process::execute(const QString &program, const QStringList &arguments, | ||
bool expectedResult){ | ||
Q_ASSERT(processStatus() == NotRunning); | ||
m_program = program; | ||
m_arguments = arguments; | ||
m_expectFail = expectedResult == ExpectFail; | ||
m_process.start(program, arguments); | ||
m_timedOut = !m_process.waitForFinished(); | ||
return m_process.readAllStandardOutput(); | ||
} | ||
|
||
bool Process::hasError(){ | ||
return m_timedOut | ||
|| m_process.error() != QProcess::UnknownError | ||
|| m_process.exitStatus() != QProcess::NormalExit | ||
|| (m_process.exitCode() != 0) != m_expectFail; | ||
} | ||
|
||
QString Process::fmtErrorMessage(){ | ||
Q_ASSERT(hasError()); | ||
|
||
QStringList reasons; | ||
if (m_timedOut){ | ||
reasons.append("Timed out"); | ||
}else if (m_process.exitStatus() != QProcess::NormalExit){ | ||
reasons.append("Process crashed"); | ||
}else if (m_expectFail && (m_process.exitCode() == 0)){ | ||
reasons.append("Did not fail while it was expected to"); | ||
}else{ | ||
if (m_process.error() != QProcess::UnknownError){ | ||
reasons.append(m_process.errorString()); | ||
} | ||
const QString errorOut = m_process.readAllStandardError(); | ||
if (!errorOut.isEmpty()){ | ||
reasons.append(errorOut); | ||
} | ||
} | ||
|
||
return QString("Failed to execute `%1 %2`: %3") | ||
.arg(m_program) | ||
.arg(QStringList(m_arguments).replaceInStrings(QRegExp("^|$"), "\"").join(" ")) | ||
.arg(reasons.join(": ")); | ||
} |
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,36 @@ | ||
/** | ||
* @file process.h | ||
* @copyright 2013 Jolla Ltd. | ||
* @author Martin Kampas <martin.kampas@tieto.com> | ||
* @date 2013 | ||
*/ | ||
|
||
#ifndef _PROCESS_H | ||
#define _PROCESS_H | ||
|
||
#include <QtCore/QProcess> | ||
|
||
class Process { | ||
public: | ||
enum ExpectedResult { | ||
ExpectSuccess, | ||
ExpectFail | ||
}; | ||
|
||
public: | ||
Process(); | ||
|
||
QString execute(const QString &program, const QStringList &arguments, | ||
bool expectedResult = ExpectSuccess); | ||
bool hasError(); | ||
QString fmtErrorMessage(); | ||
|
||
private: | ||
QProcess m_process; | ||
QString m_program; | ||
QStringList m_arguments; | ||
bool m_expectFail; | ||
bool m_timedOut; | ||
}; | ||
|
||
#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,4 @@ | ||
#!/bin/sh | ||
|
||
export LD_LIBRARY_PATH="`dirname "$0"`:${LD_LIBRARY_PATH}" | ||
exec "`dirname "$0"`/$1" |
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,88 @@ | ||
/** | ||
* @file sandboxfileenginehandler.cpp | ||
* @copyright 2013 Jolla Ltd. | ||
* @author Martin Kampas <martin.kampas@tieto.com> | ||
* @date 2013 | ||
*/ | ||
|
||
#include "sandboxfileenginehandler.h" | ||
|
||
#include <QtCore/QDir> | ||
#include <QtCore/QFSFileEngine> | ||
#include <QtCore/QFileInfo> | ||
#include <QtCore/QProcessEnvironment> | ||
#include <QtCore/QSet> | ||
|
||
#include <ssucoreconfig.h> | ||
#include "../../constants.h" | ||
|
||
/** | ||
* @class SandboxFileEngineHandler | ||
* | ||
* Redirects all file operations on system configuration files to files under | ||
* directory specified by SSU_TESTS_SANDBOX environment variable. | ||
*/ | ||
|
||
SandboxFileEngineHandler::SandboxFileEngineHandler() {} | ||
|
||
QAbstractFileEngine *SandboxFileEngineHandler::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_); | ||
} |
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 sandboxfileenginehandler.h | ||
* @copyright 2013 Jolla Ltd. | ||
* @author Martin Kampas <martin.kampas@tieto.com> | ||
* @date 2013 | ||
*/ | ||
|
||
#ifndef _SANDBOXINGFILEENGINEHANDLER_H | ||
#define _SANDBOXINGFILEENGINEHANDLER_H | ||
|
||
#include <QtCore/QAbstractFileEngineHandler> | ||
|
||
class SandboxFileEngineHandler : public QAbstractFileEngineHandler { | ||
public: | ||
SandboxFileEngineHandler(); | ||
QAbstractFileEngine *create(const QString &fileName) const; | ||
}; | ||
|
||
#endif |
File renamed without changes.
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
Oops, something went wrong.