C++ Utilities  4.17.0
Useful C++ classes and routines such as argument parser, IO and conversion utilities
Classes | Namespaces | Macros | Enumerations | Functions
testutils.h File Reference
#include "../application/argumentparser.h"
#include "../conversion/stringbuilder.h"
#include "../conversion/types.h"
#include "../misc/traits.h"
#include <iomanip>
#include <ostream>
#include <string>
Include dependency graph for testutils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  TestUtilities::TestApplication
 The TestApplication class simplifies writing test applications that require opening test files. More...
 
class  TestUtilities::AsHexNumber< T >
 The AsHexNumber class allows printing values asserted with cppunit (or similar test framework) using the hex system in the error case. More...
 

Namespaces

 TestUtilities
 Contains classes and functions utilizing creating of test applications.
 
 TestUtilities::Literals
 Contains literals to ease asserting with CPPUNIT_ASSERT_EQUAL.
 

Macros

#define TESTUTILS_ASSERT_EXEC(args)
 Asserts successful execution of the application with the specified CLI args. More...
 
#define TESTUTILS_ASSERT_LIKE(message, expectedRegex, actualString)
 Asserts whether the specified string matches the specified regex. More...
 

Enumerations

enum  TestUtilities::WorkingCopyMode { TestUtilities::WorkingCopyMode::CreateCopy, TestUtilities::WorkingCopyMode::NoCopy }
 The WorkingCopyMode enum specifies additional options to influence behavior of TestApplication::workingCopyPathMode(). More...
 

Functions

CPP_UTILITIES_EXPORT std::string TestUtilities::testFilePath (const std::string &relativeTestFilePath)
 Convenience function to invoke TestApplication::testFilePath(). More...
 
CPP_UTILITIES_EXPORT std::string TestUtilities::workingCopyPath (const std::string &relativeTestFilePath)
 Convenience function to invoke TestApplication::workingCopyPath(). More...
 
CPP_UTILITIES_EXPORT std::string TestUtilities::workingCopyPathMode (const std::string &relativeTestFilePath, WorkingCopyMode mode)
 Convenience function to invoke TestApplication::workingCopyPathMode(). More...
 
CPP_UTILITIES_EXPORT std::string TestUtilities::workingCopyPathAs (const std::string &relativeTestFilePath, const std::string &relativeWorkingCopyPath, WorkingCopyMode mode=WorkingCopyMode::CreateCopy)
 Convenience function to invoke TestApplication::workingCopyPathAs(). More...
 
template<typename T >
bool TestUtilities::operator== (const AsHexNumber< T > &lhs, const AsHexNumber< T > &rhs)
 Provides operator == required by CPPUNIT_ASSERT_EQUAL. More...
 
template<typename T >
std::ostream & TestUtilities::operator<< (std::ostream &out, const AsHexNumber< T > &value)
 Provides the actual formatting of the output for AsHexNumber class. More...
 
template<typename T >
AsHexNumber< T > TestUtilities::asHexNumber (const T &value)
 Wraps a value to be printed using the hex system in the error case when asserted with cppunit (or similar test framework). More...
 
template<typename T , Traits::EnableIf< std::is_integral< T >> * = nullptr>
AsHexNumber< T > TestUtilities::integralsAsHexNumber (const T &value)
 Wraps a value to be printed using the hex system in the error case when asserted with cppunit (or similar test framework). More...
 
template<typename T , Traits::DisableIf< std::is_integral< T >> * = nullptr>
const T & TestUtilities::integralsAsHexNumber (const T &value)
 Wraps a value to be printed using the hex system in the error case when asserted with cppunit (or similar test framework). More...
 
template<typename Pair , Traits::EnableIf< Traits::IsSpecializationOf< Pair, std::pair >> * = nullptr>
std::ostream & TestUtilities::operator<< (std::ostream &out, const Pair &pair)
 Allows printing pairs so key/values of maps/hashes can be asserted using CPPUNIT_ASSERT_EQUAL. More...
 
template<typename Iteratable , Traits::EnableIf< Traits::IsIteratable< Iteratable >, Traits::Not< Traits::IsString< Iteratable >>> * = nullptr>
std::ostream & TestUtilities::operator<< (std::ostream &out, const Iteratable &iteratable)
 Allows printing iteratable objects so those can be asserted using CPPUNIT_ASSERT_EQUAL. More...
 
constexpr std::size_t TestUtilities::Literals::operator""_st (unsigned long long size)
 Literal for std::size_t to ease asserting std::size_t with CPPUNIT_ASSERT_EQUAL. More...
 
constexpr uint64 TestUtilities::Literals::operator""_uint64 (unsigned long long size)
 Literal for uint64 to ease asserting uint64 with CPPUNIT_ASSERT_EQUAL. More...
 
constexpr int64 TestUtilities::Literals::operator""_int64 (unsigned long long size)
 Literal for int64 to ease asserting int64 with CPPUNIT_ASSERT_EQUAL. More...
 

Macro Definition Documentation

◆ TESTUTILS_ASSERT_EXEC

#define TESTUTILS_ASSERT_EXEC (   args)
Value:
{ \
const auto returnCode = execApp(args, stdout, stderr); \
if (returnCode != 0) { \
CPPUNIT_FAIL( \
::ConversionUtilities::argsToString("app failed with return code ", returnCode, "\nstdout: ", stdout, "\nstderr: ", stderr)); \
} \
}
constexpr StringType argsToString(Args &&... args)

Asserts successful execution of the application with the specified CLI args.

The application is executed via TestApplication::execApp(). Output is stored in the std::string variables stdout and stderr.

Remarks
Requires cppunit.

Definition at line 222 of file testutils.h.

◆ TESTUTILS_ASSERT_LIKE

#define TESTUTILS_ASSERT_LIKE (   message,
  expectedRegex,
  actualString 
)
Value:
(CPPUNIT_NS::Asserter::failIf(!(std::regex_match(actualString, std::regex(expectedRegex))), \
CPPUNIT_NS::Message(ConversionUtilities::argsToString('\"', actualString, "\"\n not like\n\"", expectedRegex, '\"'), \
"Expression: " #actualString, message), \
CPPUNIT_SOURCELINE()))
constexpr StringType argsToString(Args &&... args)

Asserts whether the specified string matches the specified regex.

Remarks
Requires cppunit.

Definition at line 235 of file testutils.h.