2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2019,2020, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source 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.
38 * Helpers and data for outputadapter module tests.
40 * \author Paul Bauer <paul.bauer.q@gmail.com>
42 * \ingroup module_coordinateio
45 #ifndef GMX_COORDINATEIO_TESTS_MODULE_H
46 #define GMX_COORDINATEIO_TESTS_MODULE_H
52 #include <gtest/gtest.h>
54 #include "gromacs/coordinateio/outputadapters/outputselector.h"
55 #include "gromacs/coordinateio/outputadapters/setatoms.h"
56 #include "gromacs/coordinateio/outputadapters/setbox.h"
57 #include "gromacs/coordinateio/outputadapters/setforces.h"
58 #include "gromacs/coordinateio/outputadapters/setprecision.h"
59 #include "gromacs/coordinateio/outputadapters/setstarttime.h"
60 #include "gromacs/coordinateio/outputadapters/settimestep.h"
61 #include "gromacs/coordinateio/outputadapters/setvelocities.h"
63 #include "gromacs/coordinateio/tests/coordinate_test.h"
71 /*!\libinternal \brief Helper to test supported file names. */
72 class SetAtomsSupportedFiles
: public ModuleTest
75 void prepareTest(const char* filename
)
78 //! Storage for requirements.
79 OutputRequirements requirements
;
81 requirements
.atoms
= ChangeAtomsType::AlwaysFromStructure
;
83 EXPECT_NO_THROW(runTest(filename
, requirements
));
87 /*!\libinternal \brief Helper to test supported file names. */
88 class SetAtomsUnSupportedFiles
: public ModuleTest
91 void prepareTest(const char* filename
)
93 //! Storage for requirements.
94 OutputRequirements requirements
;
96 requirements
.atoms
= ChangeAtomsType::AlwaysFromStructure
;
98 EXPECT_THROW(runTest(filename
, requirements
), InconsistentInputError
);
102 /*!\libinternal \brief Helper to test supported file names. */
103 class AnyOutputSupportedFiles
: public ModuleTest
, public ModuleSelection
106 void prepareTest(const char* filename
)
109 //! Storage for requirements.
110 OutputRequirements requirements
;
118 addOptionForSelection(&dummySelection_
, true);
119 setSelectionOptionValues(getOption(), &dummySelection_
, true);
121 copy_mat(requirements
.newBox
, box
);
122 requirements
.box
= ChangeFrameInfoType::Always
;
123 requirements
.frameTime
= ChangeFrameTimeType::Both
;
125 EXPECT_NO_THROW(runTest(filename
, requirements
));
129 /*!\libinternal \brief Helper to test support for disabling all output options. */
130 class NoOptionalOutput
: public ModuleTest
133 void prepareTest(const char* filename
)
136 //! Storage for requirements.
137 OutputRequirements requirements
;
139 requirements
.atoms
= ChangeAtomsType::Never
;
140 requirements
.velocity
= ChangeSettingType::Never
;
141 requirements
.force
= ChangeSettingType::Never
;
142 requirements
.precision
= ChangeFrameInfoType::Always
;
143 requirements
.prec
= 3;
145 EXPECT_NO_THROW(runTest(filename
, requirements
));
149 /*!\libinternal \brief Helper to test that invalid selection is rejected */
150 class OutputSelectorDeathTest
: public ModuleTest
, public ModuleSelection
155 //! Storage for frameadapters.
156 OutputAdapterContainer
adapters(CoordinateFileFlags::Base
);
160 addOptionForSelection(&sel
, false);
161 setSelectionOptionValues(getOption(), &sel
, false);
163 GMX_ASSERT_DEATH_IF_SUPPORTED(adapters
.addAdapter(std::make_unique
<OutputSelector
>(sel
),
164 CoordinateFileFlags::RequireCoordinateSelection
),
165 "Need a valid selection out of simple atom indices");
169 /*!\libinternal \brief Helper to test supported file names. */
170 class SetVelocitySupportedFiles
: public ModuleTest
173 void prepareTest(const char* filename
)
176 //! Storage for requirements.
177 OutputRequirements requirements
;
179 requirements
.velocity
= ChangeSettingType::Always
;
181 EXPECT_NO_THROW(runTest(filename
, requirements
));
185 /*!\libinternal \brief Helper to test supported file names. */
186 class SetVelocityUnSupportedFiles
: public ModuleTest
189 void prepareTest(const char* filename
)
191 //! Storage for requirements.
192 OutputRequirements requirements
;
194 requirements
.velocity
= ChangeSettingType::Always
;
196 EXPECT_THROW(runTest(filename
, requirements
), InconsistentInputError
);
200 /*!\libinternal \brief Helper to test supported file names. */
201 class SetForceSupportedFiles
: public ModuleTest
204 void prepareTest(const char* filename
)
207 //! Storage for requirements.
208 OutputRequirements requirements
;
210 requirements
.force
= ChangeSettingType::Always
;
212 EXPECT_NO_THROW(runTest(filename
, requirements
));
216 /*!\libinternal \brief Helper to test supported file names. */
217 class SetForceUnSupportedFiles
: public ModuleTest
220 void prepareTest(const char* filename
)
222 //! Storage for requirements.
223 OutputRequirements requirements
;
225 requirements
.force
= ChangeSettingType::Always
;
227 EXPECT_THROW(runTest(filename
, requirements
), InconsistentInputError
);
231 /*!\libinternal \brief Helper to test supported file names. */
232 class SetPrecisionSupportedFiles
: public ModuleTest
235 /*! \brief Set up the test case before running.
237 * \param[in] filename Name of the outputfile used to specify file type.
239 void prepareTest(const char* filename
)
242 OutputRequirements requirements
;
244 requirements
.precision
= ChangeFrameInfoType::Always
;
245 requirements
.prec
= 5;
247 EXPECT_NO_THROW(runTest(filename
, requirements
));
251 /*!\libinternal \brief Helper to test supported file names. */
252 class SetPrecisionUnSupportedFiles
: public ModuleTest
255 /*! \brief Set up the test case before running.
257 * \param[in] filename Name of the outputfile used to specify file type.
259 void prepareTest(const char* filename
)
261 OutputRequirements requirements
;
263 requirements
.precision
= ChangeFrameInfoType::Always
;
264 requirements
.prec
= 5;
266 EXPECT_THROW(runTest(filename
, requirements
), InconsistentInputError
);
270 //! Names here work for setAtoms module
271 const char* const setAtomsSupported
[] = {
279 //! Names here don't work for setAtoms module
280 const char* const setAtomsUnSupported
[] = { "spc2-traj.trr", "spc2-traj.xtc", "spc2-traj.g96" };
283 * Names here work for stuff that has no specific requirements.
285 * PDB and GRO format are not tested here because they also require atoms information
286 * that is incompatible with the other output formats.
288 const char* const anySupported
[] = { "spc2-traj.trr",
292 "spc2-traj.xtc", "spc2-traj.g96" };
294 //! Names here work for setVelocity module
295 const char* const setVelocitySupported
[] = {
303 //! Names here don't work for setVelocity module
304 const char* const setVelocityUnSupported
[] = { "spc2-traj.xtc", "spc2-traj.pdb", "spc2-traj.g96" };
306 //! Names here work for setForce module
307 const char* const setForceSupported
[] = {
314 //! Names here don't work for setForce module
315 const char* const setForceUnSupported
[] = { "spc2-traj.xtc", "spc2-traj.pdb", "spc2-traj.gro",
318 //! Names here work for setPrecision module
319 const char* const setPrecisionSupported
[] = {
326 //! Names here don't work for setPrecision module
327 const char* const setPrecisionUnSupported
[] = { "spc2-traj.trr", "spc2-traj.pdb", "spc2-traj.gro",