Gromacs
2025.0-dev-20241014-f673b97
|
#include <gromacs/trajectoryanalysis/tests/moduletest.h>
Test fixture for trajectory analysis modules.
This class implements common logic for all tests for trajectory analysis modules. The tests simply need to specify the type of the module to test, input files and any additional options, names of datasets to test (if not all), and possible output files to explicitly test by calling the different methods in this class. runTest() then runs the specified module with the given options and performs all the requested tests against reference data.
Tests should prefer to test the underlying data sets instead of string comparison on the output files using setOutputFile().
The actual module to be tested is constructed in the pure virtual createModule() method, which should be implemented in a subclass. Typically, the TrajectoryAnalysisModuleTestFixture template can be used.
Any method in this class may throw std::bad_alloc if out of memory.
Public Member Functions | |
void | setTopology (const char *filename) |
Sets the topology file to use for the test. More... | |
void | setTrajectory (const char *filename) |
Sets the trajectory file to use for the test. More... | |
void | includeDataset (const char *name) |
Includes only specified dataset for the test. More... | |
void | excludeDataset (const char *name) |
Excludes specified dataset from the test. More... | |
void | setDatasetTolerance (const char *name, const FloatingPointTolerance &tolerance) |
Sets a custom tolerance for checking a dataset. More... | |
void | runTest (const CommandLine &args) |
Runs the analysis module with the given additional options. More... | |
void | runTestAnticipatingException (const CommandLine &args) |
Runs the analysis module with the given additional options. More... | |
Public Member Functions inherited from gmx::test::CommandLineTestBase | |
void | setInputFile (const char *option, const char *filename) |
Sets an input file. More... | |
void | setInputFile (const char *option, const std::string &filename) |
Sets an input file. More... | |
void | setModifiableInputFile (const char *option, const char *filename) |
Sets an input file that may be modified. The file is copied to a temporary file, which is used as the test input. More... | |
void | setModifiableInputFile (const char *option, const std::string &filename) |
Sets an input file that may be modified. The file is copied to a temporary file, which is used as the test input. More... | |
void | setInputFileContents (const char *option, const char *extension, const std::string &contents) |
Generates and sets an input file. More... | |
void | setInputFileContents (const char *option, const char *extension, const ArrayRef< const char *const > &contents) |
Generates and sets an input file. More... | |
std::string | setOutputFile (const char *option, const char *filename, const ITextBlockMatcherSettings &matcher) |
Sets an output file whose name is passed via an option and adds it to the set of tested files. More... | |
std::string | setOutputFile (const char *option, const char *filename, const IFileMatcherSettings &matcher) |
std::string | setOutputFileWithGeneratedName (const char *filename, const ITextBlockMatcherSettings &matcher) |
Sets an output file whose name is generated by the tool and adds it to the set of tested files. More... | |
std::string | setOutputFileWithGeneratedName (std::string &&filename, const ITextBlockMatcherSettings &matcher) |
Sets an output file whose name is generated by the tool and adds it to the set of tested files. More... | |
std::string | setOutputFileWithGeneratedName (const char *filename, const IFileMatcherSettings &matcher) |
Sets an output file whose name is generated by the tool and adds it to the set of tested files. More... | |
std::string | setOutputFileWithGeneratedName (std::string &&filename, const IFileMatcherSettings &matcher) |
Sets an output file whose name is generated by the tool and adds it to the set of tested files. More... | |
std::string | setInputAndOutputFile (const char *option, const char *filename, const ITextBlockMatcherSettings &matcher) |
Sets a file parameter that is used for input and modified as output. The input file is copied to a temporary file that is used as input and can be modified. | |
std::string | setInputAndOutputFile (const char *option, const char *filename, const IFileMatcherSettings &matcher) |
Sets a file parameter that is used for input and modified as output. The input file is copied to a temporary file that is used as input and can be modified. More... | |
CommandLine & | commandLine () |
Returns the internal CommandLine object used to construct the command line for the test. More... | |
TestFileManager & | fileManager () |
Returns the internal TestFileManager object used to manage the files. More... | |
TestReferenceChecker | rootChecker () |
Returns the root reference data checker. More... | |
void | setDefaultTolerance (const FloatingPointTolerance &tolerance) |
Sets the tolerance for floating-point comparisons. More... | |
void | testWriteHelp (ICommandLineModule *module) |
Checks the output of writeHelp() against reference data. | |
void | checkOutputFiles () |
Checks output files added with setOutputFile() against reference data. More... | |
Protected Member Functions | |
virtual TrajectoryAnalysisModulePointer | createModule ()=0 |
Constructs the analysis module to be tested. | |
void gmx::test::AbstractTrajectoryAnalysisModuleTestFixture::excludeDataset | ( | const char * | name | ) |
Excludes specified dataset from the test.
[in] | name | Name of dataset to exclude. |
name
should be one of the names registered for the tested module using TrajectoryAnalysisModule::registerBasicDataset() or TrajectoryAnalysisModule::registerAnalysisDataset().
void gmx::test::AbstractTrajectoryAnalysisModuleTestFixture::includeDataset | ( | const char * | name | ) |
Includes only specified dataset for the test.
[in] | name | Name of dataset to include. |
If this method is not called, all datasets are tested by default. If called once, only the specified dataset is tested. If called more than once, also the additional datasets are tested.
name
should be one of the names registered for the tested module using TrajectoryAnalysisModule::registerBasicDataset() or TrajectoryAnalysisModule::registerAnalysisDataset().
void gmx::test::AbstractTrajectoryAnalysisModuleTestFixture::runTest | ( | const CommandLine & | args | ) |
Runs the analysis module with the given additional options.
[in] | args | Options to provide to the module. |
args
should be formatted as command-line options, and contain the name of the module as the first argument (the latter requirement is for clarity only). They are passed to the module in addition to those specified using other methods in this class.
All other methods should be called before calling this method.
Exceptions thrown by the module are caught by this method.
void gmx::test::AbstractTrajectoryAnalysisModuleTestFixture::runTestAnticipatingException | ( | const CommandLine & | args | ) |
Runs the analysis module with the given additional options.
[in] | args | Options to provide to the module. |
As for runTest(const CommandLine& args)
, but does not catch exceptions thrown by the module. This is useful when testing that certain inputs produce an exception exactly when they should.
void gmx::test::AbstractTrajectoryAnalysisModuleTestFixture::setDatasetTolerance | ( | const char * | name, |
const FloatingPointTolerance & | tolerance | ||
) |
Sets a custom tolerance for checking a dataset.
[in] | name | Name of dataset to set the tolerance for. |
[in] | tolerance | Tolerance used when verifying the data. |
name
should be one of the names registered for the tested module using TrajectoryAnalysisModule::registerBasicDataset() or TrajectoryAnalysisModule::registerAnalysisDataset().
void gmx::test::AbstractTrajectoryAnalysisModuleTestFixture::setTopology | ( | const char * | filename | ) |
Sets the topology file to use for the test.
[in] | filename | Name of input topology file. |
filename
is interpreted relative to the test input data directory, see getTestDataPath().
Must be called at most once. Either this method or setTrajectory() must be called before runTest().
void gmx::test::AbstractTrajectoryAnalysisModuleTestFixture::setTrajectory | ( | const char * | filename | ) |
Sets the trajectory file to use for the test.
[in] | filename | Name of input trajectory file. |
filename
is interpreted relative to the test input data directory, see getTestDataPath().
Must be called at most once. Either this method or setTopology() must be called before runTest().