#include "testutils/cmdlinetest.h"
#include "testutils/testfilemanager.h"
+#include "testutils/tprfilegenerator.h"
namespace gmx
{
namespace test
{
-namespace
+class DumpTest : public ::testing::Test
{
+ public:
+ //! Run test case.
+ void runTest(CommandLine *cmdline);
+ protected:
+ // TODO this is changed in newer googletest versions
+ //! Prepare shared resources.
+ static void SetUpTestCase()
+ {
+ s_tprFileHandle = new TprAndFileManager("lysozyme");
+ }
+ //! Clean up shared resources.
+ static void TearDownTestCase()
+ {
+ delete s_tprFileHandle;
+ s_tprFileHandle = nullptr;
+ }
+ //! Storage for opened file handles.
+ static TprAndFileManager *s_tprFileHandle;
+};
-/*! \brief
- * Generates a tpr for the test.
- *
- * Generates the tpr from a sample pdb file using grompp,and returns the path
- * to the file as std::string for reading it in later.
- *
- * \param[in] fileManager Filemanager to keep track of the input file.
- * \param[in] filename Basename of the input and output files.
- */
-std::string generateTprInput(TestFileManager *fileManager, const std::string &filename)
-{
-// generate temporary tpr file from test system
- const std::string mdpInputFileName = fileManager->getTemporaryFilePath(filename + ".mdp");
- TextWriter::writeFileFromString(mdpInputFileName, "");
- std::string tprName = fileManager->getTemporaryFilePath(filename + ".tpr");
- {
- CommandLine caller;
- caller.append("grompp");
- caller.addOption("-f", mdpInputFileName);
- caller.addOption("-p", TestFileManager::getInputFilePath(filename + ".top"));
- caller.addOption("-c", TestFileManager::getInputFilePath(filename + ".pdb"));
- caller.addOption("-o", tprName);
- EXPECT_EQ(0, gmx_grompp(caller.argc(), caller.argv()));
- }
- return tprName;
-}
+TprAndFileManager *DumpTest::s_tprFileHandle = nullptr;
-TEST(DumpTest, WorksWithTpr)
+void DumpTest::runTest(CommandLine *cmdline)
{
- TestFileManager fileManager;
- std::string tprName = generateTprInput(&fileManager, "lysozyme");
- const char *const command[] = {
- "dump", "-s", tprName.c_str()
- };
- CommandLine cmdline(command);
EXPECT_EQ(0, gmx::test::CommandLineTestHelper::runModuleFactory(
- &gmx::DumpInfo::create, &cmdline));
-
+ &gmx::DumpInfo::create, cmdline));
}
-TEST(DumpTest, WorksWithTprAndMdpWriting)
+TEST_F(DumpTest, WorksWithTpr)
{
- TestFileManager fileManager;
- std::string tprName = generateTprInput(&fileManager, "lysozyme");
- std::string mdpName = fileManager.getTemporaryFilePath("output.mdp");
- const char *const command[] = {
- "dump", "-s", tprName.c_str(), "-om", mdpName.c_str()
- };
+ const char *const command[] =
+ { "dump", "-s", s_tprFileHandle->tprName().c_str()};
CommandLine cmdline(command);
- EXPECT_EQ(0, gmx::test::CommandLineTestHelper::runModuleFactory(
- &gmx::DumpInfo::create, &cmdline));
-
+ runTest(&cmdline);
}
-
-} // namespace
+TEST_F(DumpTest, WorksWithTprAndMdpWriting)
+{
+ TestFileManager fileManager;
+ std::string mdpName = fileManager.getTemporaryFilePath("output.mdp");
+ const char *const command[] =
+ { "dump", "-s", s_tprFileHandle->tprName().c_str(), "-om", mdpName.c_str() };
+ CommandLine cmdline(command);
+ runTest(&cmdline);
+}
} // namespace test
#include "testutils/refdata.h"
#include "testutils/testfilemanager.h"
#include "testutils/textblockmatchers.h"
+#include "testutils/tprfilegenerator.h"
namespace gmx
{
namespace test
{
-namespace
+class ReportMethodsTest : public ::testing::Test
{
+ protected:
+ // TODO this is changed in newer googletest versions
+ //! Prepare shared resources.
+ static void SetUpTestCase()
+ {
+ s_tprFileHandle = new TprAndFileManager("lysozyme");
+ }
+ //! Clean up shared resources.
+ static void TearDownTestCase()
+ {
+ delete s_tprFileHandle;
+ s_tprFileHandle = nullptr;
+ }
+ //! Storage for opened file handles.
+ static TprAndFileManager *s_tprFileHandle;
+};
+
+TprAndFileManager *ReportMethodsTest::s_tprFileHandle = nullptr;
/*! \brief
- * Generates a tpr for the test.
+ * Reads a tpr for the test.
*
- * Generates the tpr from a sample pdb file using grompp,and returns the path
- * to the file as std::string for reading it in later.
+ * Reads a tpr to have access to the system information for print out.
*
- * \param[in] fileManager Filemanager to keep track of the input file.
- * \param[in] filename Basename of the input and output files.
- */
-std::string generateTprInput(TestFileManager *fileManager, const std::string &filename)
-{
-// generate temporary tpr file from test system
- const std::string mdpInputFileName = fileManager->getTemporaryFilePath(filename + ".mdp");
- TextWriter::writeFileFromString(mdpInputFileName, "");
- std::string tprName = fileManager->getTemporaryFilePath(filename + ".tpr");
- {
- CommandLine caller;
- caller.append("grompp");
- caller.addOption("-f", mdpInputFileName);
- caller.addOption("-p", TestFileManager::getInputFilePath(filename + ".top"));
- caller.addOption("-c", TestFileManager::getInputFilePath(filename + ".pdb"));
- caller.addOption("-o", tprName);
- EXPECT_EQ(0, gmx_grompp(caller.argc(), caller.argv()));
- }
- return tprName;
-}
-
-/*! \brief
- * Generates and reads a tpr for the test.
- *
- * Generates a tpr from a sample pdb file using grompp, and reads it in to
- * have access to the system information for print out.
- *
- * \param[in] filename Basename of the input and output files.
+ * \param[in] tprHandle Handle to the tpr to red in.
* \param[in] mtop Pointer to topology datastructure to populate.
* \param[in] ir Pointer to inputrec to populate.
*/
-void generateAndReadTprInput(const std::string &filename, gmx_mtop_t *mtop, t_inputrec *ir)
+static void readTprInput(const TprAndFileManager *tprHandle, gmx_mtop_t *mtop, t_inputrec *ir)
{
- TestFileManager fileManager;
- std::string tprName = generateTprInput(&fileManager, filename);
// read tpr into variables needed for output
{
t_state state;
- read_tpx_state(tprName.c_str(), ir, &state, mtop);
+ read_tpx_state(tprHandle->tprName().c_str(), ir, &state, mtop);
}
}
-TEST(ReportMethodsTest, WritesCorrectHeadersFormated)
+TEST_F(ReportMethodsTest, WritesCorrectHeadersFormated)
{
gmx::StringOutputStream stream;
gmx::TextWriter test(&stream);
EXPECT_EQ(stream.toString(), referenceString);
}
-TEST(ReportMethodsTest, WritesCorrectHeadersUnformatted)
+TEST_F(ReportMethodsTest, WritesCorrectHeadersUnformatted)
{
gmx::StringOutputStream stream;
gmx::TextWriter test(&stream);
EXPECT_EQ(stream.toString(), referenceString);
}
-TEST(ReportMethodsTest, WritesCorrectInformation)
+TEST_F(ReportMethodsTest, WritesCorrectInformation)
{
gmx_mtop_t top;
t_inputrec ir;
- EXPECT_NO_THROW(generateAndReadTprInput("lysozyme", &top, &ir));
+ EXPECT_NO_THROW(readTprInput(s_tprFileHandle, &top, &ir));
// Test both formatted and unformatted output in the same test
{
}
}
-// This test sometimes fails for reasons that are not understood, see
-// Redmine #3804.
-TEST(ReportMethodsTest, DISABLED_ToolEndToEndTest)
+TEST_F(ReportMethodsTest, ToolEndToEndTest)
{
- TestFileManager fileManager;
- std::string tprName = generateTprInput(&fileManager, "lysozyme");
- const char *const command[] = {
- "report-methods", "-s", tprName.c_str()
+ const char *const command[] = {
+ "report-methods", "-s", s_tprFileHandle->tprName().c_str()
};
- CommandLine cmdline(command);
+ CommandLine cmdline(command);
EXPECT_EQ(0, gmx::test::CommandLineTestHelper::runModuleFactory(
&gmx::ReportMethodsInfo::create, &cmdline));
}
-} // namespace
-
} // namespace test
} // namespace gmx
testmatchers.cpp
testoptions.cpp
textblockmatchers.cpp
+ tprfilegenerator.cpp
xvgtest.cpp
)
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2012,2013,2014,2015,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014,2015,2017,2018,2019, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
{
const ::testing::TestInfo *test_info =
::testing::UnitTest::GetInstance()->current_test_info();
- std::string filenameRoot = std::string(test_info->test_case_name())
- + "_" + test_info->name();
+ std::string filenameRoot;
+ if (test_info)
+ {
+ filenameRoot = std::string(test_info->test_case_name())
+ + "_" + test_info->name();
+ }
+ else
+ {
+ const ::testing::TestCase *test_case_info = ::testing::UnitTest::GetInstance()->current_test_case();
+ filenameRoot = std::string(test_case_info->name());
+ }
std::replace(filenameRoot.begin(), filenameRoot.end(), '/', '_');
return filenameRoot;
}
--- /dev/null
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 2019, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+/*! \internal \file
+ * \brief
+ * Implements helper for generating reusuable TPR files for tests within the same test binary.
+ *
+ * \author Paul Bauer <paul.bauer.q@gmail.com>
+ * \ingroup module_testutils
+ */
+
+#include "gmxpre.h"
+
+#include "tprfilegenerator.h"
+
+#include "gromacs/gmxpreprocess/grompp.h"
+#include "gromacs/utility/textwriter.h"
+
+#include "testutils/cmdlinetest.h"
+
+namespace gmx
+{
+namespace test
+{
+
+TprAndFileManager::TprAndFileManager(const std::string &name)
+{
+ const std::string mdpInputFileName = fileManager_.getTemporaryFilePath(name + ".mdp");
+ gmx::TextWriter::writeFileFromString(mdpInputFileName, "");
+ tprFileName_ = fileManager_.getTemporaryFilePath(name + ".tpr");
+ {
+ CommandLine caller;
+ caller.append("grompp");
+ caller.addOption("-f", mdpInputFileName);
+ caller.addOption("-p", TestFileManager::getInputFilePath(name + ".top"));
+ caller.addOption("-c", TestFileManager::getInputFilePath(name + ".pdb"));
+ caller.addOption("-o", tprFileName_);
+ EXPECT_EQ(0, gmx_grompp(caller.argc(), caller.argv()));
+ }
+}
+
+} // namespace test
+} // namespace gmx
--- /dev/null
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 2019, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+/*! \libinternal \file
+ * \brief
+ * Helper for generating reusuable TPR files for tests within the same test binary.
+ *
+ * \ingroup module_testutils
+ * \author Paul Bauer <paul.bauer.q@gmail.com>
+ */
+#ifndef GMX_TESTUTILS_TPRFILEGENERATOR_H
+#define GMX_TESTUTILS_TPRFILEGENERATOR_H
+
+#include <memory>
+#include <string>
+
+#include "testutils/testfilemanager.h"
+
+namespace gmx
+{
+namespace test
+{
+
+class TestFileManager;
+
+/*! \libinternal \brief
+ * Helper to bundle generated TPR and the file manager to clean it up.
+ */
+class TprAndFileManager
+{
+ public:
+ /*! \brief
+ * Generates the file when needed.
+ *
+ * \param[in] name The basename of the input files and the generated TPR.
+ */
+ TprAndFileManager(const std::string &name);
+ //! Access to the string.
+ const std::string &tprName() const { return tprFileName_; }
+ private:
+ //! Tpr file name.
+ std::string tprFileName_;
+ //! Filemanager, needed to clean up the file later.
+ TestFileManager fileManager_;
+};
+
+} // namespace test
+} // namespace gmx
+
+#endif