2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2018,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.
37 * Tests for functionality of the "report" tool to write system information.
39 * \author Paul Bauer <paul.bauer.q@gmail.com>
43 #include "gromacs/tools/report_methods.h"
45 #include "gromacs/fileio/tpxio.h"
46 #include "gromacs/gmxpreprocess/grompp.h"
47 #include "gromacs/mdtypes/inputrec.h"
48 #include "gromacs/mdtypes/state.h"
49 #include "gromacs/topology/topology.h"
50 #include "gromacs/utility/exceptions.h"
51 #include "gromacs/utility/stringstream.h"
52 #include "gromacs/utility/textwriter.h"
54 #include "testutils/cmdlinetest.h"
55 #include "testutils/refdata.h"
56 #include "testutils/testfilemanager.h"
57 #include "testutils/textblockmatchers.h"
58 #include "testutils/tprfilegenerator.h"
66 class ReportMethodsTest
: public ::testing::Test
69 // TODO this is changed in newer googletest versions
70 //! Prepare shared resources.
71 static void SetUpTestCase() { s_tprFileHandle
= new TprAndFileManager("lysozyme"); }
72 //! Clean up shared resources.
73 static void TearDownTestCase()
75 delete s_tprFileHandle
;
76 s_tprFileHandle
= nullptr;
78 //! Storage for opened file handles.
79 static TprAndFileManager
* s_tprFileHandle
;
82 TprAndFileManager
* ReportMethodsTest::s_tprFileHandle
= nullptr;
85 * Reads a tpr for the test.
87 * Reads a tpr to have access to the system information for print out.
89 * \param[in] tprHandle Handle to the tpr to red in.
90 * \param[in] mtop Pointer to topology datastructure to populate.
91 * \param[in] ir Pointer to inputrec to populate.
93 static void readTprInput(const TprAndFileManager
* tprHandle
, gmx_mtop_t
* mtop
, t_inputrec
* ir
)
95 // read tpr into variables needed for output
98 read_tpx_state(tprHandle
->tprName().c_str(), ir
, &state
, mtop
);
102 TEST_F(ReportMethodsTest
, WritesCorrectHeadersFormated
)
104 gmx::StringOutputStream stream
;
105 gmx::TextWriter
test(&stream
);
106 writeHeader(&test
, "Test", "Test", true);
108 std::string referenceString
= "\\Test{Test}\n";
110 EXPECT_EQ(stream
.toString(), referenceString
);
112 TEST_F(ReportMethodsTest
, WritesCorrectHeadersUnformatted
)
114 gmx::StringOutputStream stream
;
115 gmx::TextWriter
test(&stream
);
116 writeHeader(&test
, "Test", "Test", false);
118 std::string referenceString
= "Test: Test\n";
120 EXPECT_EQ(stream
.toString(), referenceString
);
123 TEST_F(ReportMethodsTest
, WritesCorrectInformation
)
127 EXPECT_NO_THROW(readTprInput(s_tprFileHandle
, &top
, &ir
));
129 // Test both formatted and unformatted output in the same test
131 gmx::StringOutputStream stream
;
132 gmx::TextWriter
test(&stream
);
134 writeSystemInformation(&test
, top
, true);
136 std::string referenceString
=
137 "\\subsection{Simulation system}\n"
138 "A system of 1 molecules (156 atoms) was simulated.\n";
140 EXPECT_EQ(stream
.toString(), referenceString
);
144 gmx::StringOutputStream stream
;
145 gmx::TextWriter
test(&stream
);
147 writeSystemInformation(&test
, top
, false);
149 std::string referenceString
=
150 "subsection: Simulation system\n"
151 "A system of 1 molecules (156 atoms) was simulated.\n";
153 EXPECT_EQ(stream
.toString(), referenceString
);
156 // Test for correct parameter information as well
158 gmx::StringOutputStream stream
;
159 gmx::TextWriter
test(&stream
);
161 writeParameterInformation(&test
, ir
, true);
163 std::string referenceString
=
164 "\\subsection{Simulation settings}\n"
165 "A total of 0 ns were simulated with a time step of 1 fs.\n"
166 "Neighbor searching was performed every 10 steps.\n"
167 "The Cut-off algorithm was used for electrostatic interactions.\n"
168 "with a cut-off of 1 nm.\nA single cut-off of 1.1 nm was used "
169 "for Van der Waals interactions.\n";
171 EXPECT_EQ(stream
.toString(), referenceString
);
175 TEST_F(ReportMethodsTest
, ToolEndToEndTest
)
177 const char* const command
[] = { "report-methods", "-s", s_tprFileHandle
->tprName().c_str() };
178 CommandLine
cmdline(command
);
179 EXPECT_EQ(0, gmx::test::CommandLineTestHelper::runModuleFactory(&gmx::ReportMethodsInfo::create
,