Gromacs  2016.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members | Public Member Functions | Static Public Member Functions
gmx::test::TestFileManager Class Reference

#include <testutils/testfilemanager.h>

Description

Helper for tests that need input and output files.

To be used as a member in a test fixture class, this class provides getTemporaryFilePath() method that returns a path for creating file names for temporary files. The returned path contains the name of the running test, making it unique across tests. Additionally, this class takes care of removing any temporary files (i.e., all paths returned by getTemporaryFilePath()) at test teardown (i.e., when the TestFileManager is destructed).

In addition, class-level static accessors provide means to access data files that are located in the test source directory. This is used to provide input files for the tests, and also to store test reference data persistently (see TestReferenceData).

Note that setInputDataDirectory() and setGlobalOutputTempDirectory() must be called in setup code, before creating any objects of this class that are used for accessing the paths for these respective directories. Code in tests should avoid calling setGlobalOutputTempDirectory(), and instead instantiate an object and use setOutputTempDirectory(), so that the global state is not changed.

Public Member Functions

 TestFileManager ()
 Constructor.
 
 ~TestFileManager ()
 Frees internal storage and deletes any accessed file paths. More...
 
std::string getTemporaryFilePath (const char *suffix)
 Creates a name for a temporary file within a single unit test. More...
 
std::string getTemporaryFilePath (const std::string &suffix)
 Creates a name for a temporary file within a single unit test. More...
 
const char * getOutputTempDirectory () const
 Returns the path to the output temporary directory for tests which use this TestFileManager object. More...
 
void setOutputTempDirectory (const std::string &path)
 Sets the output temporary directory for tests which use this TestFileManager object. More...
 

Static Public Member Functions

static std::string getTestSpecificFileNameRoot ()
 Creates a file name root for use within a single unit test. More...
 
static std::string getTestSpecificFileName (const char *suffix)
 Creates a file name for use within a single unit test. More...
 
static std::string getInputFilePath (const char *filename)
 Returns the path to a test input file. More...
 
static const char * getInputDataDirectory ()
 Returns the path to the test input directory. More...
 
static void setInputDataDirectory (const std::string &path)
 Sets the test input directory. More...
 
static const char * getGlobalOutputTempDirectory ()
 Returns the path to the global test output temporary directory for future TestFileManager objects. More...
 
static void setGlobalOutputTempDirectory (const char *path)
 Sets the default global test output temporary directory for future TestFileManager objects. More...
 

Constructor & Destructor Documentation

gmx::test::TestFileManager::~TestFileManager ( )

Frees internal storage and deletes any accessed file paths.

Any errors (e.g., missing files) encountered while deleting the files are ignored.

Member Function Documentation

const char * gmx::test::TestFileManager::getGlobalOutputTempDirectory ( )
static

Returns the path to the global test output temporary directory for future TestFileManager objects.

Returns
Path to default output temporary directory for the test executable.
const char * gmx::test::TestFileManager::getInputDataDirectory ( )
static

Returns the path to the test input directory.

Returns
Path to input data directory for the test executable.
std::string gmx::test::TestFileManager::getInputFilePath ( const char *  filename)
static

Returns the path to a test input file.

Parameters
[in]filenameRelative path/filename to a test input file.
Returns
Path to filename under the test input data directory.
const char * gmx::test::TestFileManager::getOutputTempDirectory ( ) const

Returns the path to the output temporary directory for tests which use this TestFileManager object.

Returns
Path to output temporary directory
std::string gmx::test::TestFileManager::getTemporaryFilePath ( const char *  suffix)

Creates a name for a temporary file within a single unit test.

Parameters
[in]suffixSuffix to add to the file name (should contain an extension if one is desired).
Returns
Temporary file name that includes the test name and suffix.

This method should only be called from within a Google Test test. Two calls with the same suffix return the same string within the same test.

std::string gmx::test::TestFileManager::getTemporaryFilePath ( const std::string &  suffix)

Creates a name for a temporary file within a single unit test.

Parameters
[in]suffixSuffix to add to the file name (should contain an extension if one is desired).
Returns
Temporary file name that includes the test name and suffix.

This method should only be called from within a Google Test test. Two calls with the same suffix return the same string within the same test.

std::string gmx::test::TestFileManager::getTestSpecificFileName ( const char *  suffix)
static

Creates a file name for use within a single unit test.

Parameters
[in]suffixSuffix to add to the file name (should contain an extension if one is desired).
Returns
File name that includes the test name and suffix.

This method should only be called from within a Google Test test. Two calls with the same suffix return the same string within the same test. Intended to produce distinct names for files that may be stored in the same directory for multiple tests.

std::string gmx::test::TestFileManager::getTestSpecificFileNameRoot ( )
static

Creates a file name root for use within a single unit test.

This method should only be called from within a Google Test test. Uses the Google Test test fixture and test case name to construct a string that is unique over all tests. Intended to produce distinct names for files that may be stored in the same directory for multiple tests.

void gmx::test::TestFileManager::setGlobalOutputTempDirectory ( const char *  path)
static

Sets the default global test output temporary directory for future TestFileManager objects.

Parameters
[in]pathPath at which tests should write temporary files

path must name an existing directory.

This function is automatically called by unittest_main.cpp through initTestUtils(). Test fixtures should call setOutputTempDirectory(), rather than change the global state.

void gmx::test::TestFileManager::setInputDataDirectory ( const std::string &  path)
static

Sets the test input directory.

Parameters
[in]pathPath from which test input data is looked up from.

path must name an existing directory.

This function is automatically called by unittest_main.cpp through initTestUtils().

void gmx::test::TestFileManager::setOutputTempDirectory ( const std::string &  path)

Sets the output temporary directory for tests which use this TestFileManager object.

Parameters
[in]pathPath at which test should write temporary files

path must name an existing directory. An internal copy of path is made. The caller is responsible for holding a valid mutex on the object before calling this member function.


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