2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2018,2019, 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.
43 #include "gromacs/tools/report_methods.h"
45 #include "gromacs/fileio/tpxio.h"
46 #include "gromacs/gmxpreprocess/grompp.h"
47 #include "gromacs/mdtypes/state.h"
48 #include "gromacs/utility/exceptions.h"
49 #include "gromacs/utility/stringstream.h"
50 #include "gromacs/utility/textwriter.h"
52 #include "testutils/cmdlinetest.h"
53 #include "testutils/refdata.h"
54 #include "testutils/testfilemanager.h"
55 #include "testutils/textblockmatchers.h"
56 #include "testutils/tprfilegenerator.h"
64 class ReportMethodsTest : public ::testing::Test
67 // TODO this is changed in newer googletest versions
68 //! Prepare shared resources.
69 static void SetUpTestCase() { s_tprFileHandle = new TprAndFileManager("lysozyme"); }
70 //! Clean up shared resources.
71 static void TearDownTestCase()
73 delete s_tprFileHandle;
74 s_tprFileHandle = nullptr;
76 //! Storage for opened file handles.
77 static TprAndFileManager* s_tprFileHandle;
80 TprAndFileManager* ReportMethodsTest::s_tprFileHandle = nullptr;
83 * Reads a tpr for the test.
85 * Reads a tpr to have access to the system information for print out.
87 * \param[in] tprHandle Handle to the tpr to red in.
88 * \param[in] mtop Pointer to topology datastructure to populate.
89 * \param[in] ir Pointer to inputrec to populate.
91 static void readTprInput(const TprAndFileManager* tprHandle, gmx_mtop_t* mtop, t_inputrec* ir)
93 // read tpr into variables needed for output
96 read_tpx_state(tprHandle->tprName().c_str(), ir, &state, mtop);
100 TEST_F(ReportMethodsTest, WritesCorrectHeadersFormated)
102 gmx::StringOutputStream stream;
103 gmx::TextWriter test(&stream);
104 writeHeader(&test, "Test", "Test", true);
106 std::string referenceString = "\\Test{Test}\n";
108 EXPECT_EQ(stream.toString(), referenceString);
110 TEST_F(ReportMethodsTest, WritesCorrectHeadersUnformatted)
112 gmx::StringOutputStream stream;
113 gmx::TextWriter test(&stream);
114 writeHeader(&test, "Test", "Test", false);
116 std::string referenceString = "Test: Test\n";
118 EXPECT_EQ(stream.toString(), referenceString);
121 TEST_F(ReportMethodsTest, WritesCorrectInformation)
125 EXPECT_NO_THROW(readTprInput(s_tprFileHandle, &top, &ir));
127 // Test both formatted and unformatted output in the same test
129 gmx::StringOutputStream stream;
130 gmx::TextWriter test(&stream);
132 writeSystemInformation(&test, top, true);
134 std::string referenceString =
135 "\\subsection{Simulation system}\n"
136 "A system of 1 molecules (156 atoms) was simulated.\n";
138 EXPECT_EQ(stream.toString(), referenceString);
142 gmx::StringOutputStream stream;
143 gmx::TextWriter test(&stream);
145 writeSystemInformation(&test, top, false);
147 std::string referenceString =
148 "subsection: Simulation system\n"
149 "A system of 1 molecules (156 atoms) was simulated.\n";
151 EXPECT_EQ(stream.toString(), referenceString);
154 // Test for correct parameter information as well
156 gmx::StringOutputStream stream;
157 gmx::TextWriter test(&stream);
159 writeParameterInformation(&test, ir, true);
161 std::string referenceString =
162 "\\subsection{Simulation settings}\n"
163 "A total of 0 ns were simulated with a time step of 1 fs.\n"
164 "Neighbor searching was performed every 10 steps.\n"
165 "The Cut-off algorithm was used for electrostatic interactions.\n"
166 "with a cut-off of 1 nm.\nA single cut-off of 1.1 nm was used "
167 "for Van der Waals interactions.\n";
169 EXPECT_EQ(stream.toString(), referenceString);
173 TEST_F(ReportMethodsTest, ToolEndToEndTest)
175 const char* const command[] = { "report-methods", "-s", s_tprFileHandle->tprName().c_str() };
176 CommandLine cmdline(command);
177 EXPECT_EQ(0, gmx::test::CommandLineTestHelper::runModuleFactory(&gmx::ReportMethodsInfo::create,