C++ Utilities: CppUtilities::TestApplication Class Reference

C++ Utilities 5.32.1 Useful C++ classes and routines such as argument parser, IO and conversion utilities

Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
CppUtilities::TestApplication Class Reference

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

`#include <testutils.h>`

## Public Member Functions
| TestApplication ()
| Constructs a TestApplication instance without further arguments.
| TestApplication (int argc, const char *const *argv)
| Constructs a TestApplication instance for the specified arguments.
| ~TestApplication ()
| Destroys the TestApplication.
| operator bool () const
| Returns whether the TestApplication instance is valid.
std::string | testFilePath (const std::string &relativeTestFilePath) const
| Returns the full path of the test file with the specified relativeTestFilePath.
std::string | testDirPath (const std::string &relativeTestDirPath) const
| Returns the full path of the test directory with the specified relativeTestDirPath.
std::string | workingCopyPath (const std::string &relativeTestFilePath, WorkingCopyMode mode=WorkingCopyMode::CreateCopy) const
| Returns the full path to a working copy of the test file with the specified relativeTestFilePath.
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.
const std::vector< std::string > & | testFilePaths () const
| Returns the list of directories to look for test files.
const std::string & | workingDirectory () const
| Returns the directory which is supposed to used for storing files created by tests.
const char * | applicationPath ()
| Returns the application path or an empty string if no application path has been set.
bool | unitsSpecified () const
| Returns whether particular units have been specified.
const std::vector< const char * > & | units () const
| Returns the specified test units.
bool | onlyListUnits () const
| Returns whether the test application should only list available units and not actually run any tests.

## Static Public Member Functions
static const TestApplication * | instance ()
| Returns the current TestApplication instance.
static const char * | appPath ()
| Returns the application path or an empty string if no application path has been set.

## 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 34 of file testutils.h.

## Constructor & Destructor Documentation

## ◆ TestApplication() [1/2]

CppUtilities::TestApplication::TestApplication | ( |  | ) |
| explicit

Constructs a TestApplication instance without further arguments.

Remarks
  This constructor skips parsing CLI arguments. Other initialization like reading environment variables for test file paths and working directories is still done.

Exceptions

  Throws | std::runtime_error if an instance has already been created.

Definition at line 140 of file testutils.cpp.

## ◆ TestApplication() [2/2]

CppUtilities::TestApplication::TestApplication | ( | int | argc,
|  | const char *const * | argv )
| explicit

Constructs a TestApplication instance for the specified arguments.

Exceptions

  Throws | std::runtime_error if an instance has already been created.

Definition at line 149 of file testutils.cpp.

## ◆ ~TestApplication()

CppUtilities::TestApplication::~TestApplication | ( |  | ) |

Destroys the TestApplication.

Definition at line 245 of file testutils.cpp.

## Member Function Documentation

## ◆ applicationPath()

const char * CppUtilities::TestApplication::applicationPath | ( |  | ) |
| inline

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

Definition at line 127 of file testutils.h.

## ◆ appPath()

const char * CppUtilities::TestApplication::appPath | ( |  | ) |
| inlinestatic

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

Definition at line 103 of file testutils.h.

## ◆ instance()

const TestApplication * CppUtilities::TestApplication::instance | ( |  | ) |
| inlinestatic

Returns the current TestApplication instance.

Definition at line 95 of file testutils.h.

## ◆ onlyListUnits()

bool CppUtilities::TestApplication::onlyListUnits | ( |  | ) | const
| inline

Returns whether the test application should only list available units and not actually run any tests.

Definition at line 152 of file testutils.h.

## ◆ operator bool()

CppUtilities::TestApplication::operator bool | ( |  | ) | const
| inline

Returns whether the TestApplication instance is valid.

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

Definition at line 87 of file testutils.h.

## ◆ testDirPath()

std::string CppUtilities::TestApplication::testDirPath | ( | const std::string & | relativeTestDirPath | ) | const

Returns the full path of the test directory with the specified relativeTestDirPath.

This is the same as TestApplication::testFilePath() but for directories. Check out the documentation of TestApplication::testFilePath() for details about the lookup.

Definition at line 280 of file testutils.cpp.

## ◆ testFilePath()

std::string CppUtilities::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 directories specified as CLI argument.
2. The directory set via the environment variable TEST_FILE_PATH.
3. The subdirectory "testfiles" within the source directory, if it could be determined via "srcref"-file.
4. The subdirectory "testfiles" within present working directory.

Definition at line 262 of file testutils.cpp.

## ◆ testFilePaths()

const std::vector< std::string > & CppUtilities::TestApplication::testFilePaths | ( |  | ) | const
| inline

Returns the list of directories to look for test files.

Definition at line 111 of file testutils.h.

## ◆ units()

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

Returns the specified test units.

Remarks
  The units argument must be present.

Definition at line 144 of file testutils.h.

## ◆ unitsSpecified()

bool CppUtilities::TestApplication::unitsSpecified | ( |  | ) | const
| inline

Returns whether particular units have been specified.

Definition at line 135 of file testutils.h.

## ◆ workingCopyPath()

string CppUtilities::TestApplication::workingCopyPath | ( | const std::string & | relativeTestFilePath,
|  | 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.

Remarks
  The test file is located using testFilePath().

Definition at line 299 of file testutils.cpp.

## ◆ workingCopyPathAs()

string CppUtilities::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 318 of file testutils.cpp.

## ◆ workingDirectory()

const std::string & CppUtilities::TestApplication::workingDirectory | ( |  | ) | const
| inline

Returns the directory which is supposed to used for storing files created by tests.

Definition at line 119 of file testutils.h.

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

- tests/testutils.h
- tests/testutils.cpp