Gazebo Common

API Reference

5.7.0
testing Namespace Reference

Classes

class  BazelTestPaths
 Implementation of TestPaths interface for Bazel. More...
 
class  CMakeTestPaths
 Implementation of TestPaths interface for CMake. More...
 
class  RedirectConsoleStream
 
class  TestPaths
 Helper interface to generate path information to support test access to source/data files. More...
 

Enumerations

enum class  StreamSource { STDOUT , STDERR }
 

Functions

bool GZ_COMMON_TESTING_VISIBLE createNewEmptyFile (const std::string &_filename)
 Create an empty file with no content. More...
 
std::shared_ptr< TempDirectory > MakeTestTempDirectory (const std::string &_prefix="test", const std::string &_subDir="gz", bool _cleanup=true)
 Create a temporary directory for test output in an OS and build appropriate location. More...
 
std::shared_ptr< TempDirectory > GZ_COMMON_TESTING_VISIBLE MakeTestTempDirectoryImpl (const std::string &_projectSourcePath, const std::string &_prefix="test", const std::string &_subDir="gz", bool _cleanup=true)
 Implementation of MakeTestTempDirectory. More...
 
RedirectConsoleStream RedirectStderr ()
 Redirect standard error to a test-specific temporary path. More...
 
RedirectConsoleStream RedirectStdout ()
 Redirect standard out to a test-specific temporary path. More...
 
template<typename... Args>
std::string SourceFile (Args const &... args)
 Get the path to a file in the project source tree. More...
 
template<typename... Args>
std::string TempPath (Args const &... args)
 Get the path to a file in a temporary directory. More...
 
BuildType GZ_COMMON_TESTING_VISIBLE TestBuildType (const std::string &_projectSourcePath=kTestingProjectSourceDir)
 Return the current build type. More...
 
template<typename... Args>
std::string TestFile (Args const &... args)
 Get the path to a file in the project test directory tree. More...
 
std::unique_ptr< TestPaths > GZ_COMMON_TESTING_VISIBLE TestPathFactory (const std::string &_projectSourcePath=kTestingProjectSourceDir)
 Get a TestPaths object for the current build type. More...
 

Variables

constexpr char kTestingProjectSourceDir [] = ""
 Constant referring to the project source dir of the current project. More...
 

Enumeration Type Documentation

◆ StreamSource

enum StreamSource
strong
Enumerator
STDOUT 
STDERR 

Function Documentation

◆ createNewEmptyFile()

bool GZ_COMMON_TESTING_VISIBLE testing::createNewEmptyFile ( const std::string _filename)

Create an empty file with no content.

Parameters
[in]_filenameFilename of the file to be created
Returns
true if file successfully created, false otherwise

◆ MakeTestTempDirectory()

std::shared_ptr<TempDirectory> testing::MakeTestTempDirectory ( const std::string _prefix = "test",
const std::string _subDir = "gz",
bool  _cleanup = true 
)
inline

Create a temporary directory for test output in an OS and build appropriate location.

The TempDirectory will have the form $TMPDIR/_subdir/_prefixXXXXX/

Parameters
[in]_prefixPrefix of the temporary directory
[in]_subDirAdditional subdirectory for temporary directory
[in]_cleanupTrue to indicate that the filesystem should be cleaned as part of the destructor
Returns
Shared pointer to TempDirectory

References kTestingProjectSourceDir, and MakeTestTempDirectoryImpl().

◆ MakeTestTempDirectoryImpl()

std::shared_ptr<TempDirectory> GZ_COMMON_TESTING_VISIBLE testing::MakeTestTempDirectoryImpl ( const std::string _projectSourcePath,
const std::string _prefix = "test",
const std::string _subDir = "gz",
bool  _cleanup = true 
)

Implementation of MakeTestTempDirectory.

The TempDirectory will have the form $TMPDIR/_subdir/_prefixXXXXX/

Parameters
[in]_projectSourcePathRoot of project source or empty
[in]_prefixPrefix of the temporary directory
[in]_subDirAdditional subdirectory for temporary directory
[in]_cleanupTrue to indicate that the filesystem should be cleaned as part of the destructor
Returns
Shared pointer to TempDirectory

Referenced by MakeTestTempDirectory().

◆ RedirectStderr()

RedirectConsoleStream testing::RedirectStderr ( )
inline

Redirect standard error to a test-specific temporary path.

References STDERR, and TempPath().

◆ RedirectStdout()

RedirectConsoleStream testing::RedirectStdout ( )
inline

Redirect standard out to a test-specific temporary path.

References STDOUT, and TempPath().

◆ SourceFile()

std::string testing::SourceFile ( Args const &...  args)

Get the path to a file in the project source tree.

Example: to get gz-common/test/data/box.dae SourceFile("test", "data", "box.dae");

Parameters
[in]argsRelative path to the source file
Returns
Full path to the source file

References gz::common::joinPaths(), kTestingProjectSourceDir, and TestPathFactory().

Referenced by TestFile().

◆ TempPath()

std::string testing::TempPath ( Args const &...  args)

Get the path to a file in a temporary directory.

Example: to get ${TMP}/.gz/foo.log TempPath(".gz", "foo.log");

Parameters
[in]argsPath to the file, relative to the temporary directory
Returns
Full path to the temporary directory

References gz::common::joinPaths(), kTestingProjectSourceDir, and TestPathFactory().

Referenced by RedirectStderr(), and RedirectStdout().

◆ TestBuildType()

BuildType GZ_COMMON_TESTING_VISIBLE testing::TestBuildType ( const std::string _projectSourcePath = kTestingProjectSourceDir)

Return the current build type.

Parameters
[in]_projectSourcePathRoot of project source or empty
Returns
The current build type

◆ TestFile()

std::string testing::TestFile ( Args const &...  args)

Get the path to a file in the project test directory tree.

Example: to get gz-common/test/data/box.dae TestFile("data", "box.dae");

Parameters
[in]argsPath to the file, relative to the test directory
Returns
Full path to the source file

References SourceFile().

◆ TestPathFactory()

std::unique_ptr<TestPaths> GZ_COMMON_TESTING_VISIBLE testing::TestPathFactory ( const std::string _projectSourcePath = kTestingProjectSourceDir)

Get a TestPaths object for the current build type.

Parameters
[in]_projectSourcePathRoot of project source or empty
Returns
TestPaths implementation for the current build type

Referenced by SourceFile(), and TempPath().

Variable Documentation

◆ kTestingProjectSourceDir

constexpr char kTestingProjectSourceDir[] = ""
constexpr

Constant referring to the project source dir of the current project.

For CMake builds, it is expected that this is injected via a buildsystem define of TESTING_PROJECT_SOURCE_DIR. This is done automatically for tests using gz-cmake's gz_build_tests

For Bazel builds, it is expected to be empty

Referenced by MakeTestTempDirectory(), SourceFile(), and TempPath().