Add workingCopyPathMode() to be able to skip actual copy

This commit is contained in:
Martchus 2017-02-04 20:16:50 +01:00
parent cb3b50c28c
commit c13eee6fcc
2 changed files with 39 additions and 10 deletions

View File

@ -165,7 +165,7 @@ string TestApplication::testFilePath(const string &name) const
* \brief Returns the full path to a working copy of the test file with the specified \a name.
* \remarks Currently only available under UNIX.
*/
string TestApplication::workingCopyPath(const string &name) const
string TestApplication::workingCopyPathMode(const string &name, WorkingCopyMode mode) const
{
// create file streams
fstream origFile, workingCopy;
@ -200,19 +200,28 @@ string TestApplication::workingCopyPath(const string &name) const
}
// copy file
try {
origFile.open(testFilePath(name), ios_base::in | ios_base::binary);
const string path = m_workingDir + name;
workingCopy.open(path, ios_base::out | ios_base::binary | ios_base::trunc);
workingCopy << origFile.rdbuf();
return path;
} catch(...) {
catchIoFailure();
cerr << "Unable to create working copy for \"" << name << "\": an IO error occured." << endl;
if(mode != WorkingCopyMode::NoCopy) {
try {
origFile.open(testFilePath(name), ios_base::in | ios_base::binary);
const string path = m_workingDir + name;
workingCopy.open(path, ios_base::out | ios_base::binary | ios_base::trunc);
workingCopy << origFile.rdbuf();
return path;
} catch(...) {
catchIoFailure();
cerr << "Unable to create working copy for \"" << name << "\": an IO error occured." << endl;
}
} else {
return m_workingDir + name;
}
return string();
}
string TestApplication::workingCopyPath(const string &name) const
{
return workingCopyPathMode(name, WorkingCopyMode::CreateCopy);
}
/*!
* \brief Executes the application to be tested with the specified \a args and stores the standard output and
* errors in \a stdout and \a stderr.

View File

@ -8,6 +8,15 @@
namespace TestUtilities {
/*!
* \brief The WorkingCopyMode enum specifies additional options to influence behavior of TestApplication::workingCopyPathMode().
*/
enum class WorkingCopyMode
{
CreateCopy, /**< a working copy of the test file is created */
NoCopy /**< only the directory for the working copy is created but not the test file itself */
};
class CPP_UTILITIES_EXPORT TestApplication
{
public:
@ -17,6 +26,7 @@ public:
operator bool() const;
std::string testFilePath(const std::string &name) const;
#ifdef PLATFORM_UNIX
std::string workingCopyPathMode(const std::string &name, WorkingCopyMode mode) const;
std::string workingCopyPath(const std::string &name) const;
int execApp(const char *const *args, std::string &output, std::string &errors, bool suppressLogging = false, int timeout = -1) const;
#endif
@ -95,6 +105,16 @@ inline CPP_UTILITIES_EXPORT std::string workingCopyPath(const std::string &name)
return TestApplication::instance()->workingCopyPath(name);
}
/*!
* \brief Convenience function which returns the full path to a working copy of the test file with the specified \a name.
* \remarks A TestApplication must be present.
* \sa TestApplication::workingCopyPathEx()
*/
inline CPP_UTILITIES_EXPORT std::string workingCopyPathMode(const std::string &name, WorkingCopyMode mode)
{
return TestApplication::instance()->workingCopyPathMode(name, mode);
}
/*!
* \brief Convenience function which executes the application to be tested with the specified \a args.
* \remarks A TestApplication must be present.