C++ Utilities  4.17.0
Useful C++ classes and routines such as argument parser, IO and conversion utilities
Namespaces | Classes | Enumerations | Functions
TestUtilities Namespace Reference

Contains classes and functions utilizing creating of test applications. More...

Namespaces

 Literals
 Contains literals to ease asserting with CPPUNIT_ASSERT_EQUAL.
 

Classes

class  AsHexNumber
 The AsHexNumber class allows printing values asserted with cppunit (or similar test framework) using the hex system in the error case. More...
 
class  OutputCheck
 The StandardOutputCheck class asserts whether the (standard) output written in the enclosing code block matches the expected output. More...
 
class  TestApplication
 The TestApplication class simplifies writing test applications that require opening test files. More...
 

Enumerations

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

Functions

CPP_UTILITIES_EXPORT std::string testFilePath (const std::string &relativeTestFilePath)
 Convenience function to invoke TestApplication::testFilePath(). More...
 
CPP_UTILITIES_EXPORT std::string workingCopyPath (const std::string &relativeTestFilePath)
 Convenience function to invoke TestApplication::workingCopyPath(). More...
 
CPP_UTILITIES_EXPORT std::string workingCopyPathMode (const std::string &relativeTestFilePath, WorkingCopyMode mode)
 Convenience function to invoke TestApplication::workingCopyPathMode(). More...
 
CPP_UTILITIES_EXPORT std::string workingCopyPathAs (const std::string &relativeTestFilePath, const std::string &relativeWorkingCopyPath, WorkingCopyMode mode=WorkingCopyMode::CreateCopy)
 Convenience function to invoke TestApplication::workingCopyPathAs(). More...
 
template<typename T >
bool operator== (const AsHexNumber< T > &lhs, const AsHexNumber< T > &rhs)
 Provides operator == required by CPPUNIT_ASSERT_EQUAL. More...
 
template<typename T >
std::ostream & operator<< (std::ostream &out, const AsHexNumber< T > &value)
 Provides the actual formatting of the output for AsHexNumber class. More...
 
template<typename T >
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 similar test framework). More...
 
template<typename T , Traits::EnableIf< std::is_integral< T >> * = nullptr>
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 similar test framework). More...
 
template<typename T , Traits::DisableIf< std::is_integral< T >> * = nullptr>
const T & 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 & 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 & operator<< (std::ostream &out, const Iteratable &iteratable)
 Allows printing iteratable objects so those can be asserted using CPPUNIT_ASSERT_EQUAL. More...
 
bool fileSystemItemExists (const string &path)
 
bool fileExists (const string &path)
 
bool dirExists (const string &path)
 
bool makeDir (const string &path)
 

Detailed Description

Contains classes and functions utilizing creating of test applications.

Enumeration Type Documentation

◆ WorkingCopyMode

The WorkingCopyMode enum specifies additional options to influence behavior of TestApplication::workingCopyPathMode().

Enumerator
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

Definition at line 18 of file testutils.h.

Function Documentation

◆ asHexNumber()

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).

Definition at line 189 of file testutils.h.

◆ dirExists()

bool TestUtilities::dirExists ( const string &  path)

Definition at line 72 of file testutils.cpp.

◆ fileExists()

bool TestUtilities::fileExists ( const string &  path)

Definition at line 57 of file testutils.cpp.

◆ fileSystemItemExists()

bool TestUtilities::fileSystemItemExists ( const string &  path)

Definition at line 42 of file testutils.cpp.

◆ integralsAsHexNumber() [1/2]

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).

Remarks
Only affects integral types. Values of other types are printed as usual.

Definition at line 199 of file testutils.h.

◆ integralsAsHexNumber() [2/2]

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).

Remarks
Only affects integral types. Values of other types are printed as usual.

Definition at line 209 of file testutils.h.

◆ makeDir()

bool TestUtilities::makeDir ( const string &  path)

Definition at line 87 of file testutils.cpp.

◆ operator<<() [1/3]

template<typename T >
std::ostream& TestUtilities::operator<< ( std::ostream &  out,
const AsHexNumber< T > &  value 
)

Provides the actual formatting of the output for AsHexNumber class.

Definition at line 180 of file testutils.h.

◆ operator<<() [2/3]

template<typename Pair , Traits::EnableIf< Traits::IsSpecializationOf< Pair, std::pair >> * = nullptr>
std::ostream& TestUtilities::operator<< ( std::ostream &  out,
const Pair &  pair 
)
inline

Allows printing pairs so key/values of maps/hashes can be asserted using CPPUNIT_ASSERT_EQUAL.

Definition at line 245 of file testutils.h.

◆ operator<<() [3/3]

template<typename Iteratable , Traits::EnableIf< Traits::IsIteratable< Iteratable >, Traits::Not< Traits::IsString< Iteratable >>> * = nullptr>
std::ostream& TestUtilities::operator<< ( std::ostream &  out,
const Iteratable &  iteratable 
)
inline

Allows printing iteratable objects so those can be asserted using CPPUNIT_ASSERT_EQUAL.

Definition at line 254 of file testutils.h.

◆ operator==()

template<typename T >
bool TestUtilities::operator== ( const AsHexNumber< T > &  lhs,
const AsHexNumber< T > &  rhs 
)

Provides operator == required by CPPUNIT_ASSERT_EQUAL.

Definition at line 172 of file testutils.h.

◆ testFilePath()

CPP_UTILITIES_EXPORT std::string TestUtilities::testFilePath ( const std::string &  relativeTestFilePath)
inline

Convenience function to invoke TestApplication::testFilePath().

Remarks
A TestApplication must be present.

Definition at line 107 of file testutils.h.

◆ workingCopyPath()

CPP_UTILITIES_EXPORT std::string TestUtilities::workingCopyPath ( const std::string &  relativeTestFilePath)
inline

Convenience function to invoke TestApplication::workingCopyPath().

Remarks
A TestApplication must be present.

Definition at line 116 of file testutils.h.

◆ workingCopyPathAs()

CPP_UTILITIES_EXPORT std::string TestUtilities::workingCopyPathAs ( const std::string &  relativeTestFilePath,
const std::string &  relativeWorkingCopyPath,
WorkingCopyMode  mode = WorkingCopyMode::CreateCopy 
)
inline

Convenience function to invoke TestApplication::workingCopyPathAs().

Remarks
A TestApplication must be present.

Definition at line 134 of file testutils.h.

◆ workingCopyPathMode()

CPP_UTILITIES_EXPORT std::string TestUtilities::workingCopyPathMode ( const std::string &  relativeTestFilePath,
WorkingCopyMode  mode 
)
inline

Convenience function to invoke TestApplication::workingCopyPathMode().

Remarks
A TestApplication must be present.

Definition at line 125 of file testutils.h.