C++ Utilities  4.17.0
Useful C++ classes and routines such as argument parser, IO and conversion utilities
Public Member Functions | Static Public Member Functions | List of all members
TestUtilities::TestApplication Class Reference

The TestApplication class simplifies writing test applications that require opening test files. More...

#include <testutils.h>

Public Member Functions

 TestApplication (int argc, char **argv)
 Constructs a TestApplication instance. More...
 
 ~TestApplication ()
 Destroys the TestApplication. More...
 
 operator bool () const
 Returns whether the TestApplication instance is valid. More...
 
std::string testFilePath (const std::string &relativeTestFilePath) const
 Returns the full path of the test file with the specified relativeTestFilePath. More...
 
std::string workingCopyPathMode (const std::string &relativeTestFilePath, WorkingCopyMode mode) const
 Returns the full path to a working copy of the test file with the specified relativeTestFilePath. More...
 
std::string workingCopyPath (const std::string &relativeTestFilePath) const
 Returns the full path to a working copy of the test file with the specified relativeTestFilePath. More...
 
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. More...
 
bool unitsSpecified () const
 Returns whether particular units have been specified. More...
 
const std::vector< const char * > & units () const
 Returns the specified test units. More...
 

Static Public Member Functions

static const TestApplicationinstance ()
 Returns the current TestApplication instance. More...
 
static const char * appPath ()
 Returns the application path or an empty string if no application path has been set. More...
 

Detailed Description

The TestApplication class simplifies writing test applications that require opening test files.

Remarks
Only one instance is allowed at a time (singletone class).

Definition at line 23 of file testutils.h.

Constructor & Destructor Documentation

◆ TestApplication()

TestUtilities::TestApplication::TestApplication ( int  argc,
char **  argv 
)

Constructs a TestApplication instance.

Exceptions
Throwsstd::runtime_error if an instance has already been created.

Definition at line 112 of file testutils.cpp.

◆ ~TestApplication()

TestUtilities::TestApplication::~TestApplication ( )

Destroys the TestApplication.

Definition at line 218 of file testutils.cpp.

Member Function Documentation

◆ appPath()

const char * TestUtilities::TestApplication::appPath ( )
inlinestatic

Returns the application path or an empty string if no application path has been set.

Definition at line 81 of file testutils.h.

◆ instance()

const TestApplication * TestUtilities::TestApplication::instance ( )
inlinestatic

Returns the current TestApplication instance.

Definition at line 73 of file testutils.h.

◆ operator bool()

TestUtilities::TestApplication::operator bool ( ) const
inline

Returns whether the TestApplication instance is valid.

An instance is considered invalid if an error occured when parsing the command line arguments.

Definition at line 65 of file testutils.h.

◆ testFilePath()

string TestUtilities::TestApplication::testFilePath ( const std::string &  relativeTestFilePath) const

Returns the full path of the test file with the specified relativeTestFilePath.

The specified relativeTestFilePath is considered to be a path to a test file which is relative to at least one of the considered test file search directories.

The following directories are searched for test files in the given order:

  1. The directory specified as CLI argument.
  2. The fallback directory, which can be set by setting the environment variable TEST_FILE_PATH.
  3. The source directory, if it could be determined via "srcref"-file unless both, the CLI argument and environment variable are present.

Definition at line 236 of file testutils.cpp.

◆ units()

const std::vector< const char * > & TestUtilities::TestApplication::units ( ) const
inline

Returns the specified test units.

Remarks
The units argument must be present.

Definition at line 98 of file testutils.h.

◆ unitsSpecified()

bool TestUtilities::TestApplication::unitsSpecified ( ) const
inline

Returns whether particular units have been specified.

Definition at line 89 of file testutils.h.

◆ workingCopyPath()

string TestUtilities::TestApplication::workingCopyPath ( const std::string &  relativeTestFilePath) const

Returns the full path to a working copy of the test file with the specified relativeTestFilePath.

Remarks
The test file is located using testFilePath().

Definition at line 277 of file testutils.cpp.

◆ workingCopyPathAs()

string TestUtilities::TestApplication::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 specified mode controls whether a working copy is actually created or whether just the path is returned. If only the path is returned, the relativeTestFilePath is ignored.

In contrast to workingCopyPath(), this method allows to adjust the relative path of the working copy within the working copy directory via relativeWorkingCopyPath.

Remarks
  • The test file specified via relativeTestFilePath is located using testFilePath().
  • The name of the working copy file specified via relativeWorkingCopyPath will be adjusted if it already exists in the file system and can not be truncated.

Definition at line 296 of file testutils.cpp.

◆ workingCopyPathMode()

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

Returns the full path to a working copy of the test file with the specified relativeTestFilePath.

The specified mode controls whether a working copy is actually created or whether just the path is returned.

Remarks
The test file is located using testFilePath().

Definition at line 268 of file testutils.cpp.


The documentation for this class was generated from the following files: