4 #include "../application/argumentparser.h" 5 #include "../conversion/stringbuilder.h" 6 #include "../conversion/types.h" 7 #include "../misc/traits.h" 28 operator bool()
const;
33 int execApp(
const char *
const *args, std::string &output, std::string &errors,
bool suppressLogging =
false,
int timeout = -1)
const;
35 bool unitsSpecified()
const;
36 const std::vector<const char *> &units()
const;
38 static const char *appPath();
41 static std::string readTestfilePathFromEnv();
42 static std::string readTestfilePathFromSrcRef();
50 std::string m_testFilesPath;
51 std::string m_fallbackTestFilesPath;
52 std::string m_workingDir;
63 inline TestApplication::operator bool()
const 73 return TestApplication::m_instance;
81 return m_instance && m_instance->m_applicationPathArg.
firstValue() ? m_instance->m_applicationPathArg.
firstValue() :
"";
98 return m_unitsArg.
values();
137 inline CPP_UTILITIES_EXPORT int execApp(
const char *
const *args, std::string &output, std::string &errors)
143 const char *appPath,
const char *
const *args, std::string &output, std::string &errors,
bool suppressLogging =
false,
int timeout = -1);
144 #endif // PLATFORM_UNIX 171 template <
typename T> std::ostream &operator<<(std::ostream &out, const AsHexNumber<T> &value)
173 return out <<
'0' <<
'x' << std::hex << std::setfill(
'0') << std::setw(2) << unsigned(value.value) << std::dec;
200 template <
typename T, Traits::DisableIf<std::is_
integral<T>> * =
nullptr>
const T &
integralsAsHexNumber(
const T &value)
213 #define TESTUTILS_ASSERT_EXEC(args) \ 215 const auto returnCode = execApp(args, stdout, stderr); \ 216 if (returnCode != 0) { \ 218 ::ConversionUtilities::argsToString("app failed with return code ", returnCode, "\nstdout: ", stdout, "\nstderr: ", stderr)); \ 226 #define TESTUTILS_ASSERT_LIKE(message, expectedRegex, actualString) \ 227 (CPPUNIT_NS::Asserter::failIf(!(std::regex_match(actualString, std::regex(expectedRegex))), \ 228 CPPUNIT_NS::Message(ConversionUtilities::argsToString('\"', actualString, "\"\n not like\n\"", expectedRegex, '\"'), \ 229 "Expression: " #actualString, message), \ 230 CPPUNIT_SOURCELINE())) 235 template <
typename Pair, Traits::EnableIf<Traits::IsSpecializationOf<Pair, std::pair>> * =
nullptr>
236 inline std::ostream &
operator<<(std::ostream &out,
const Pair &pair)
238 return out <<
"key: " << pair.first <<
"; value: " << pair.second <<
'\n';
244 template <
typename Iteratable, Traits::EnableIf<Traits::IsIteratable<Iteratable>, Traits::Not<Traits::IsString<Iteratable>>> * =
nullptr>
245 inline std::ostream &
operator<<(std::ostream &out,
const Iteratable &iteratable)
248 std::size_t index = 0;
249 for (
const auto &item : iteratable) {
264 constexpr std::size_t
operator"" _st(
unsigned long long size)
266 return static_cast<std::size_t
>(size);
273 constexpr
uint64 operator"" _uint64(
unsigned long long size)
275 return static_cast<uint64>(size);
282 constexpr
int64 operator"" _int64(
unsigned long long size)
284 return static_cast<int64>(size);
289 #endif // TESTUTILS_H std::int64_t int64
signed 64-bit integer
bool unitsSpecified() const
Returns whether particular units have been specified.
std::string workingCopyPathMode(const std::string &name, WorkingCopyMode mode) const
Returns the full path to a working copy of the test file with the specified name. ...
The TestApplication class simplifies writing test applications that require opening test files...
std::ostream & operator<<(std::ostream &out, const AsHexNumber< T > &value)
Provides the actual formatting of the output for AsHexNumber class.
AsHexNumber(const T &value)
Constructs a new instance; use asHexNumber() for convenience instead.
std::string testFilePath(const std::string &name) const
Returns the full path of the test file with the specified name.
const char * firstValue() const
Returns the first parameter value of the first occurrence of the argument.
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...
std::uint64_t uint64
unsigned 64-bit integer
std::string workingCopyPath(const std::string &name) const
Creates a working copy of the test file with the specified name and returns the full path of the crea...
static const char * appPath()
Returns the application path or an empty string if no application path has been set.
Contains classes and functions utilizing creating of test applications.
const std::vector< const char * > & values(std::size_t occurrence=0) const
Returns the parameter values for the specified occurrence of argument.
bool operator==(const AsHexNumber< T > &lhs, const AsHexNumber< T > &rhs)
Provides operator == required by CPPUNIT_ASSERT_EQUAL.
The Argument class is a wrapper for command line argument information.
CPP_UTILITIES_EXPORT std::string workingCopyPath(const std::string &name)
Convenience function which returns the full path to a working copy of the test file with the specifie...
const std::vector< const char * > & units() const
Returns the specified test units.
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...
WorkingCopyMode
The WorkingCopyMode enum specifies additional options to influence behavior of TestApplication::worki...
bool isPresent() const
Returns an indication whether the argument could be detected when parsing.
The HelpArgument class prints help information for an argument parser when present (–help...
static const TestApplication * instance()
Returns the current TestApplication instance.
#define CPP_UTILITIES_EXPORT
Marks the symbol to be exported by the c++utilities library.
The AsHexNumber class allows printing values asserted with cppunit (or similar test framework) using ...
CPP_UTILITIES_EXPORT std::string testFilePath(const std::string &name)
Convenience function which returns the full path of the test file with the specified name...
The ArgumentParser class provides a means for handling command line arguments.
CPP_UTILITIES_EXPORT std::string workingCopyPathMode(const std::string &name, WorkingCopyMode mode)
Convenience function which returns the full path to a working copy of the test file with the specifie...