4 #include "../application/argumentparser.h" 5 #include "../conversion/stringbuilder.h" 6 #include "../conversion/types.h" 7 #include "../misc/traits.h" 28 operator bool()
const;
29 std::string
testFilePath(
const std::string &relativeTestFilePath)
const;
31 std::string
workingCopyPath(
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;
37 bool unitsSpecified()
const;
38 const std::vector<const char *> &units()
const;
40 static const char *appPath();
43 static std::string readTestfilePathFromEnv();
44 static std::string readTestfilePathFromSrcRef();
52 std::string m_testFilesPath;
53 std::string m_fallbackTestFilesPath;
54 std::string m_workingDir;
65 inline TestApplication::operator bool()
const 75 return TestApplication::m_instance;
83 return m_instance && m_instance->m_applicationPathArg.
firstValue() ? m_instance->m_applicationPathArg.
firstValue() :
"";
100 return m_unitsArg.
values();
146 inline CPP_UTILITIES_EXPORT int execApp(
const char *
const *args, std::string &output, std::string &errors)
152 const char *appPath,
const char *
const *args, std::string &output, std::string &errors,
bool suppressLogging =
false,
int timeout = -1);
153 #endif // PLATFORM_UNIX 182 return out <<
'0' <<
'x' << std::hex << std::setfill(
'0') << std::setw(2) << unsigned(value.
value) << std::dec;
209 template <
typename T, Traits::DisableIf<std::is_
integral<T>> * =
nullptr>
const T &
integralsAsHexNumber(
const T &value)
222 #define TESTUTILS_ASSERT_EXEC(args) \ 224 const auto returnCode = execApp(args, stdout, stderr); \ 225 if (returnCode != 0) { \ 227 ::ConversionUtilities::argsToString("app failed with return code ", returnCode, "\nstdout: ", stdout, "\nstderr: ", stderr)); \ 235 #define TESTUTILS_ASSERT_LIKE(message, expectedRegex, actualString) \ 236 (CPPUNIT_NS::Asserter::failIf(!(std::regex_match(actualString, std::regex(expectedRegex))), \ 237 CPPUNIT_NS::Message(ConversionUtilities::argsToString('\"', actualString, "\"\n not like\n\"", expectedRegex, '\"'), \ 238 "Expression: " #actualString, message), \ 239 CPPUNIT_SOURCELINE())) 244 template <
typename Pair, Traits::EnableIf<Traits::IsSpecializationOf<Pair, std::pair>> * =
nullptr>
245 inline std::ostream &
operator<<(std::ostream &out,
const Pair &pair)
247 return out <<
"key: " << pair.first <<
"; value: " << pair.second <<
'\n';
253 template <
typename Iteratable, Traits::EnableIf<Traits::IsIteratable<Iteratable>, Traits::Not<Traits::IsString<Iteratable>>> * =
nullptr>
254 inline std::ostream &
operator<<(std::ostream &out,
const Iteratable &iteratable)
257 std::size_t index = 0;
258 for (
const auto &item : iteratable) {
273 constexpr std::size_t
operator"" _st(
unsigned long long size)
275 return static_cast<std::size_t>(size);
282 constexpr
uint64 operator"" _uint64(
unsigned long long size)
284 return static_cast<uint64>(size);
291 constexpr
int64 operator"" _int64(
unsigned long long size)
293 return static_cast<int64>(size);
298 #endif // TESTUTILS_H std::int64_t int64
signed 64-bit integer
bool unitsSpecified() const
Returns whether particular units have been specified.
#define CPP_UTILITIES_EXPORT
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.
CPP_UTILITIES_EXPORT std::string workingCopyPathMode(const std::string &relativeTestFilePath, WorkingCopyMode mode)
Convenience function to invoke TestApplication::workingCopyPathMode().
AsHexNumber(const T &value)
Constructs a new instance; use asHexNumber() for convenience instead.
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
CPP_UTILITIES_EXPORT std::string workingCopyPath(const std::string &relativeTestFilePath)
Convenience function to invoke TestApplication::workingCopyPath().
static const char * appPath()
Returns the application path or an empty string if no application path has been set.
std::string testFilePath(const std::string &relativeTestFilePath) const
Returns the full path of the test file with the specified relativeTestFilePath.
Contains classes and functions utilizing creating of test applications.
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 * > & 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.
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.
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.
The AsHexNumber class allows printing values asserted with cppunit (or similar test framework) using ...
The ArgumentParser class provides a means for handling command line arguments.
CPP_UTILITIES_EXPORT std::string testFilePath(const std::string &relativeTestFilePath)
Convenience function to invoke TestApplication::testFilePath().