C++ Utilities
5.4.0
Useful C++ classes and routines such as argument parser, IO and conversion utilities
|
Go to the documentation of this file.
4 #include "../application/argumentparser.h"
5 #include "../misc/traits.h"
27 operator bool()
const;
30 std::string
testFilePath(
const std::string &relativeTestFilePath)
const;
32 std::string
workingCopyPathAs(
const std::string &relativeTestFilePath,
const std::string &relativeWorkingCopyPath,
35 int execApp(
const char *
const *args, std::string &output, std::string &errors,
bool suppressLogging =
false,
int timeout = -1)
const;
39 const std::vector<std::string> &testFilePaths()
const;
40 const std::string &workingDirectory()
const;
41 const char *applicationPath();
42 bool unitsSpecified()
const;
43 const std::vector<const char *> &units()
const;
44 bool onlyListUnits()
const;
48 static const char *appPath();
51 static std::string readTestfilePathFromEnv();
52 static std::string readTestfilePathFromSrcRef();
61 std::vector<std::string> m_testFilesPaths;
62 std::string m_workingDir;
73 inline TestApplication::operator bool()
const
83 return TestApplication::s_instance;
99 return m_testFilesPaths;
132 return m_unitsArg.
values();
177 inline CPP_UTILITIES_EXPORT int execApp(
const char *
const *args, std::string &output, std::string &errors)
183 const char *appPath,
const char *
const *args, std::string &output, std::string &errors,
bool suppressLogging =
false,
int timeout = -1);
184 #endif // PLATFORM_UNIX
213 return out <<
'0' <<
'x' << std::hex << std::setfill(
'0') << std::setw(2) << unsigned(value.
value) << std::dec;
240 template <
typename T, Traits::DisableIf<std::is_
integral<T>> * =
nullptr>
const T &
integralsAsHexNumber(
const T &value)
253 #define TESTUTILS_ASSERT_EXEC(args) \
255 const auto returnCode = execApp(args, stdout, stderr); \
256 if (returnCode != 0) { \
257 CPPUNIT_FAIL(::CppUtilities::argsToString("app failed with return code ", returnCode, "\nstdout: ", stdout, "\nstderr: ", stderr)); \
265 #define TESTUTILS_ASSERT_LIKE_FLAGS(message, expectedRegex, regexFlags, actualString) \
266 (CPPUNIT_NS::Asserter::failIf(!(std::regex_match(actualString, std::regex(expectedRegex, regexFlags))), \
267 CPPUNIT_NS::Message( \
268 CppUtilities::argsToString('\"', actualString, "\"\n not like\n\"", expectedRegex, '\"'), "Expression: " #actualString, message), \
269 CPPUNIT_SOURCELINE()))
275 #define TESTUTILS_ASSERT_LIKE(message, expectedRegex, actualString) \
276 TESTUTILS_ASSERT_LIKE_FLAGS(message, expectedRegex, std::regex::ECMAScript, actualString)
281 template <
typename Pair, CppUtilities::Traits::EnableIf<CppUtilities::Traits::IsSpecializationOf<Pair, std::pair>> * =
nullptr>
282 inline std::ostream &
operator<<(std::ostream &out,
const Pair &pair)
284 return out <<
"key: " << pair.first <<
"; value: " << pair.second <<
'\n';
290 template <
typename Iteratable, Traits::EnableIf<Traits::IsIteratable<Iteratable>, Traits::Not<Traits::IsString<Iteratable>>> * =
nullptr>
291 inline std::ostream &
operator<<(std::ostream &out,
const Iteratable &iteratable)
294 std::size_t index = 0;
295 for (
const auto &item : iteratable) {
310 constexpr std::size_t
operator"" _st(
unsigned long long size)
312 return static_cast<std::size_t
>(size);
319 constexpr std::uint64_t
operator"" _uint64(
unsigned long long size)
321 return static_cast<std::uint64_t
>(size);
328 constexpr std::int64_t
operator"" _int64(
unsigned long long size)
330 return static_cast<std::int64_t
>(size);
335 #endif // TESTUTILS_H
const char * applicationPath()
Returns the application path or an empty string if no application path has been set.
bool unitsSpecified() const
Returns whether particular units have been specified.
CPP_UTILITIES_EXPORT std::string testFilePath(const std::string &relativeTestFilePath)
Convenience function to invoke TestApplication::testFilePath().
AsHexNumber< T > integralsAsHexNumber(const T &value)
Wraps a value to be printed using the hex system in the error case when asserted with cppunit (or sim...
The OperationArgument class is an Argument where denotesOperation() is true by default.
CPP_UTILITIES_EXPORT std::string workingCopyPathAs(const std::string &relativeTestFilePath, const std::string &relativeWorkingCopyPath, WorkingCopyMode mode=WorkingCopyMode::CreateCopy)
Convenience function to invoke TestApplication::workingCopyPathAs().
const std::vector< const char * > & units() const
Returns the specified test units.
const std::string & workingDirectory() const
Returns the directory which is supposed to used for storing files created by tests.
const std::vector< const char * > & values(std::size_t occurrence=0) const
Returns the parameter values for the specified occurrence of argument.
The TestApplication class simplifies writing test applications that require opening test files.
AsHexNumber(const T &value)
Constructs a new instance; use asHexNumber() for convenience instead.
The ConfigValueArgument class is an Argument where setCombinable() is true by default.
const std::vector< std::string > & testFilePaths() const
Returns the list of directories to look for test files.
CPP_UTILITIES_EXPORT std::ostream & operator<<(std::ostream &out, Indentation indentation)
const char * firstValue() const
Returns the first parameter value of the first occurrence of the argument.
std::string workingCopyPathAs(const std::string &relativeTestFilePath, const std::string &relativeWorkingCopyPath, WorkingCopyMode mode=WorkingCopyMode::CreateCopy) const
Returns the full path to a working copy of the test file with the specified relativeTestFilePath.
std::string testFilePath(const std::string &relativeTestFilePath) const
Returns the full path of the test file with the specified relativeTestFilePath.
Contains all utilities provides by the c++utilities library.
bool isPresent() const
Returns an indication whether the argument could be detected when parsing.
WorkingCopyMode
The WorkingCopyMode enum specifies additional options to influence behavior of TestApplication::worki...
bool onlyListUnits() const
Returns whether the test application should only list available units and not actually run any tests.
The AsHexNumber class allows printing values asserted with cppunit (or similar test framework) using ...
AsHexNumber< T > asHexNumber(const T &value)
Wraps a value to be printed using the hex system in the error case when asserted with cppunit (or sim...
static const char * appPath()
Returns the application path or an empty string if no application path has been set.
static const TestApplication * instance()
Returns the current TestApplication instance.
#define CPP_UTILITIES_EXPORT
Marks the symbol to be exported by the c++utilities library.
bool operator==(const AsHexNumber< T > &lhs, const AsHexNumber< T > &rhs)
Provides operator == required by CPPUNIT_ASSERT_EQUAL.
CPP_UTILITIES_EXPORT std::string workingCopyPath(const std::string &relativeTestFilePath, WorkingCopyMode mode=WorkingCopyMode::CreateCopy)
Convenience function to invoke TestApplication::workingCopyPath().
The ArgumentParser class provides a means for handling command line arguments.