2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013, by the GROMACS development team, led by
5 * David van der Spoel, Berk Hess, Erik Lindahl, and including many
6 * others, as listed in the AUTHORS file in the top-level source
7 * directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
37 * Declares test fixture for TrajectoryAnalysisModule subclasses.
39 * \author Teemu Murtola <teemu.murtola@gmail.com>
40 * \ingroup module_trajectoryanalysis
42 #ifndef GMX_TRAJECTORYANALYSIS_TESTS_MODULETEST_H
43 #define GMX_TRAJECTORYANALYSIS_TESTS_MODULETEST_H
45 #include <gtest/gtest.h>
47 #include "gromacs/trajectoryanalysis/analysismodule.h"
48 #include "gromacs/utility/common.h"
53 class TrajectoryAnalysisModule;
62 * Test fixture for trajectory analysis modules.
64 * This class implements common logic for all tests for trajectory analysis
65 * modules. The tests simply need to specify the type of the module to test,
66 * input files and any additional options, names of datasets to test (if not
67 * all), and possible output files to explicitly test by calling the different
68 * methods in this class. runTest() then runs the specified module with the
69 * given options and performs all the requested tests against reference data.
71 * The actual module to be tested is constructed in the pure virtual
72 * createModule() method, which should be implemented in a subclass.
73 * Typically, the TrajectoryAnalysisModuleTestFixture template can be used.
75 * Any method in this class may throw std::bad_alloc if out of memory.
77 * \ingroup module_trajectoryanalysis
79 class AbstractTrajectoryAnalysisModuleTestFixture : public ::testing::Test
82 AbstractTrajectoryAnalysisModuleTestFixture();
83 virtual ~AbstractTrajectoryAnalysisModuleTestFixture();
86 * Sets the topology file to use for the test.
88 * \param[in] filename Name of input topology file.
90 * \p filename is interpreted relative to the test input data
91 * directory, see getTestDataPath().
93 * Must be called at most once. Either this method or setTrajectory()
94 * must be called before runTest().
96 void setTopology(const char *filename);
98 * Sets the trajectory file to use for the test.
100 * \param[in] filename Name of input trajectory file.
102 * \p filename is interpreted relative to the test input data
103 * directory, see getTestDataPath().
105 * Must be called at most once. Either this method or setTopology()
106 * must be called before runTest().
108 void setTrajectory(const char *filename);
110 * Sets an output file to use for the test.
112 * \param[in] option Option to set.
113 * \param[in] filename Name of the output file.
116 * - Sets \p option in the tested module to a temporary file name
117 * constructed from \p filename.
118 * - Makes runTest() to check the contents of the file against
119 * reference data after running the module.
120 * - Marks the temporary file for removal at test teardown.
122 * \p filename is given to TestTemporaryFileManager to make a unique
123 * filename for the temporary file, but is not otherwise used.
125 * Currently, this method should not be called for an XVG file, because
126 * the comments in the beginning of the file contain timestamps and
127 * other variable information, causing the test to fail. Best used
128 * only for custom data formats. For numeric data, testing the
129 * underlying dataset is typically sufficient.
131 void setOutputFile(const char *option, const char *filename);
133 * Includes only specified dataset for the test.
135 * \param[in] name Name of dataset to include.
137 * If this method is not called, all datasets are tested by default.
138 * If called once, only the specified dataset is tested.
139 * If called more than once, also the additional datasets are tested.
141 * \p name should be one of the names registered for the tested module
142 * using TrajectoryAnalysisModule::registerBasicDataset() or
143 * TrajectoryAnalysisModule::registerAnalysisDataset().
145 void includeDataset(const char *name);
147 * Excludes specified dataset from the test.
149 * \param[in] name Name of dataset to exclude.
151 * If includeDataset() has been called, \p name must be one of the
154 * \p name should be one of the names registered for the tested module
155 * using TrajectoryAnalysisModule::registerBasicDataset() or
156 * TrajectoryAnalysisModule::registerAnalysisDataset().
158 void excludeDataset(const char *name);
161 * Runs the analysis module with the given additional options.
163 * \param[in] args Options to provide to the module.
165 * \p args should be formatted as command-line options, and contain the
166 * name of the module as the first argument (the latter requirement is
167 * for clarity only). They are passed to the module in addition to
168 * those specified using other methods in this class.
170 * All other methods should be called before calling this method.
172 * Exceptions thrown by the module are caught by this method.
174 void runTest(const CommandLine &args);
178 * Constructs the analysis module to be tested.
180 virtual TrajectoryAnalysisModulePointer createModule() = 0;
185 PrivateImplPointer<Impl> impl_;
189 * Test fixture for a trajectory analysis module.
191 * \tparam ModuleInfo Info object for the analysis module to test.
193 * \p ModuleInfo should provide a static
194 * `TrajectoryAnalysisModulePointer create()` method.
196 * \ingroup module_trajectoryanalysis
198 template <class ModuleInfo>
199 class TrajectoryAnalysisModuleTestFixture
200 : public AbstractTrajectoryAnalysisModuleTestFixture
203 virtual TrajectoryAnalysisModulePointer createModule()
205 return ModuleInfo::create();