#include "gromacs/selection/selectionoptionmanager.h"
#include "gromacs/utility/file.h"
-#include "testutils/datapath.h"
#include "testutils/stringtest.h"
+#include "testutils/testfilemanager.h"
namespace
{
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/file.h"
-#include "testutils/datapath.h"
#include "testutils/mock_helptopic.h"
#include "testutils/stringtest.h"
+#include "testutils/testfilemanager.h"
namespace
{
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/file.h"
-#include "testutils/datapath.h"
+#include "testutils/testfilemanager.h"
namespace
{
#include "gromacs/utility/flags.h"
#include "gromacs/utility/stringutil.h"
-#include "testutils/datapath.h"
#include "testutils/refdata.h"
+#include "testutils/testfilemanager.h"
#include "testutils/testoptions.h"
namespace
matrix box;
snew(top_, 1);
- read_tps_conf(gmx::test::TestFileManager::getTestFilePath(filename).c_str(),
+ read_tps_conf(gmx::test::TestFileManager::getInputFilePath(filename).c_str(),
title, top_, &ePBC, &xtop, NULL, box, FALSE);
snew(frame_, 1);
TEST_F(SelectionCollectionTest, ParsesSelectionsFromFile)
{
- ASSERT_NO_THROW(sel_ = sc_.parseFromFile(gmx::test::TestFileManager::getTestFilePath("selfile.dat")));
+ ASSERT_NO_THROW(sel_ = sc_.parseFromFile(
+ gmx::test::TestFileManager::getInputFilePath("selfile.dat")));
// These should match the contents of selfile.dat
ASSERT_EQ(2U, sel_.size());
EXPECT_STREQ("resname RA RB", sel_[0].selectionText());
#include "gromacs/selection/selectionoptionmanager.h"
#include "gromacs/utility/exceptions.h"
-#include "testutils/datapath.h"
+#include "testutils/testfilemanager.h"
+
+using gmx::test::TestFileManager;
namespace
{
ASSERT_NO_THROW(assigner.startOption("sel"));
EXPECT_NO_THROW(assigner.finishOption());
ASSERT_NO_THROW(assigner.startOption("sf"));
- EXPECT_NO_THROW(assigner.appendValue(gmx::test::TestFileManager::getTestFilePath("selfile.dat")));
+ EXPECT_NO_THROW(assigner.appendValue(TestFileManager::getInputFilePath("selfile.dat")));
EXPECT_NO_THROW(assigner.finishOption());
EXPECT_NO_THROW(assigner.finish());
EXPECT_NO_THROW(options_.finish());
setManager();
gmx::OptionsAssigner assigner(&options_);
- std::string value(gmx::test::TestFileManager::getTestFilePath("selfile.dat"));
+ std::string value(TestFileManager::getInputFilePath("selfile.dat"));
EXPECT_NO_THROW(assigner.start());
ASSERT_NO_THROW(assigner.startOption("sel1"));
EXPECT_NO_THROW(assigner.finishOption());
setManager();
gmx::OptionsAssigner assigner(&options_);
- std::string value(gmx::test::TestFileManager::getTestFilePath("selfile.dat"));
+ std::string value(TestFileManager::getInputFilePath("selfile.dat"));
EXPECT_NO_THROW(assigner.start());
ASSERT_NO_THROW(assigner.startOption("sel1"));
EXPECT_NO_THROW(assigner.finishOption());
gmx::OptionsAssigner assigner(&options_);
EXPECT_NO_THROW(assigner.start());
ASSERT_NO_THROW(assigner.startOption("sf"));
- EXPECT_NO_THROW(assigner.appendValue(gmx::test::TestFileManager::getTestFilePath("selfile.dat")));
+ EXPECT_NO_THROW(assigner.appendValue(TestFileManager::getInputFilePath("selfile.dat")));
EXPECT_NO_THROW(assigner.finishOption());
EXPECT_NO_THROW(assigner.startOption("optsel"));
EXPECT_NO_THROW(assigner.finishOption());
EXPECT_NO_THROW(assigner.appendValue("resname RC RD"));
EXPECT_NO_THROW(assigner.finishOption());
ASSERT_NO_THROW(assigner.startOption("sf"));
- EXPECT_NO_THROW(assigner.appendValue(gmx::test::TestFileManager::getTestFilePath("selfile.dat")));
+ EXPECT_NO_THROW(assigner.appendValue(TestFileManager::getInputFilePath("selfile.dat")));
EXPECT_NO_THROW(assigner.finishOption());
EXPECT_NO_THROW(assigner.finish());
EXPECT_NO_THROW(options_.finish());
setManager();
gmx::OptionsAssigner assigner(&options_);
- std::string value(gmx::test::TestFileManager::getTestFilePath("selfile.dat"));
+ std::string value(TestFileManager::getInputFilePath("selfile.dat"));
EXPECT_NO_THROW(assigner.start());
ASSERT_NO_THROW(assigner.startOption("sf"));
EXPECT_NO_THROW(assigner.appendValue(value));
ASSERT_NO_THROW(assigner.startOption("sf"));
// TODO: Should this be changed to an InvalidInputError?
EXPECT_THROW(assigner.appendValue("nonexistentfile"), gmx::FileIOError);
- EXPECT_THROW(assigner.appendValue(gmx::test::TestFileManager::getTestFilePath("selfile.dat")),
+ EXPECT_THROW(assigner.appendValue(TestFileManager::getInputFilePath("selfile.dat")),
gmx::InvalidInputError);
EXPECT_NO_THROW(assigner.finishOption());
EXPECT_NO_THROW(assigner.finish());
ASSERT_NO_THROW(assigner.startOption("sel"));
EXPECT_NO_THROW(assigner.finishOption());
ASSERT_NO_THROW(assigner.startOption("sf"));
- EXPECT_NO_THROW(assigner.appendValue(gmx::test::TestFileManager::getTestFilePath("selfile.dat")));
+ EXPECT_NO_THROW(assigner.appendValue(TestFileManager::getInputFilePath("selfile.dat")));
EXPECT_THROW(assigner.appendValue("nonexistentfile"), gmx::InvalidInputError);
EXPECT_NO_THROW(assigner.finishOption());
EXPECT_NO_THROW(assigner.finish());
#include "gromacs/utility/file.h"
#include "testutils/cmdlinetest.h"
-#include "testutils/datapath.h"
#include "testutils/datatest.h"
#include "testutils/refdata.h"
+#include "testutils/testfilemanager.h"
namespace gmx
{
AbstractTrajectoryAnalysisModuleTestFixture::setTopology(const char *filename)
{
impl_->cmdline_.append("-s");
- impl_->cmdline_.append(TestFileManager::getTestFilePath(filename));
+ impl_->cmdline_.append(TestFileManager::getInputFilePath(filename));
}
void
AbstractTrajectoryAnalysisModuleTestFixture::setTrajectory(const char *filename)
{
impl_->cmdline_.append("-f");
- impl_->cmdline_.append(TestFileManager::getTestFilePath(filename));
+ impl_->cmdline_.append(TestFileManager::getInputFilePath(filename));
}
void
#include "gromacs/utility/gmxassert.h"
#include "gromacs/utility/path.h"
#include "gromacs/utility/stringutil.h"
-#include "testutils/datapath.h"
#include "testutils/testexceptions.h"
+#include "testutils/testfilemanager.h"
namespace
{
std::string getReferenceDataPath()
{
- return TestFileManager::getTestFilePath("refdata");
+ return TestFileManager::getInputFilePath("refdata");
}
void initReferenceData(int *argc, char **argv)
*/
/*! \internal \file
* \brief
- * Implements functions and classes in datapath.h.
+ * Implements gmx::test::TestFileManager.
*
* \author Teemu Murtola <teemu.murtola@cbr.su.se>
* \ingroup module_testutils
*/
-#include "datapath.h"
+#include "testfilemanager.h"
#include <cstdio>
#include "gromacs/utility/gmxassert.h"
#include "gromacs/utility/path.h"
-namespace
-{
-
-//! Global test input data path set with gmx::test::TestFileManager::setTestDataPath().
-const char *g_testDataPath = NULL;
-
-} // namespace
-
namespace gmx
{
namespace test
class TestFileManager::Impl
{
public:
+ //! Global test input data path set with setDataInputDirectory().
+ static const char *s_inputDirectory;
+
//! Container type for names of temporary files.
typedef std::set<std::string> FileNameList;
FileNameList files_;
};
+const char *TestFileManager::Impl::s_inputDirectory = NULL;
+
void TestFileManager::Impl::removeFiles()
{
FileNameList::const_iterator i;
return filename;
}
-std::string TestFileManager::getTestFilePath(const char *filename)
+std::string TestFileManager::getInputFilePath(const char *filename)
{
- return Path::join(getTestDataPath(), filename);
+ return Path::join(getInputDataDirectory(), filename);
}
-const char *TestFileManager::getTestDataPath()
+const char *TestFileManager::getInputDataDirectory()
{
- GMX_RELEASE_ASSERT(g_testDataPath != NULL, "Test data path not set");
- return g_testDataPath;
+ GMX_RELEASE_ASSERT(Impl::s_inputDirectory != NULL, "Test data path not set");
+ return Impl::s_inputDirectory;
}
-void TestFileManager::setTestDataPath(const char *path)
+void TestFileManager::setInputDataDirectory(const char *path)
{
+ // There is no need to protect this by a mutex, as this is called in early
+ // initialization of the tests.
GMX_RELEASE_ASSERT(Directory::exists(path),
"Test data directory does not exist");
- g_testDataPath = path;
+ Impl::s_inputDirectory = path;
}
} // namespace test
*/
/*! \libinternal \file
* \brief
- * Declares gmx::test::TestFileManager
+ * Declares gmx::test::TestFileManager.
*
* \author Teemu Murtola <teemu.murtola@cbr.su.se>
* \inlibraryapi
*
* \ingroup group_utilitymodules
*/
-#ifndef GMX_TESTUTILS_DATAPATH_H
-#define GMX_TESTUTILS_DATAPATH_H
+#ifndef GMX_TESTUTILS_TESTFILEMANAGER_H
+#define GMX_TESTUTILS_TESTFILEMANAGER_H
#include <string>
namespace gmx
{
+/*! \libinternal \brief
+ * Testing utilities namespace.
+ *
+ * This namespace contains utilities for writing unit tests, mostly from the
+ * \ref module_testutils module.
+ */
namespace test
{
* getTemporaryFilePath()) at test teardown (i.e., when the
* TestFileManager is destructed).
*
- * Functions getTestFilePath() and getTestDataPath() provide means to access
- * data files that are located in the test source directory. This is typically
- * used to provide input files for the tests.
+ * Functions getInputFilePath() and getInputDataDirectory() provide means to
+ * access data files that are located in the test source directory.
+ * This is used to provide input files for the tests, and also to store test
+ * reference data persistently (see TestReferenceData).
*
* \inlibraryapi
* \ingroup module_testutils
std::string getTemporaryFilePath(const char *suffix);
/*! \brief
- * Creates a name for reference data or temporary file within a single unit test.
+ * Creates a file name for use within a single unit test.
*
* \param[in] suffix Suffix to add to the file name (should contain an
* extension if one is desired).
* This method should only be called from within a Google Test test.
* Two calls with the same \p suffix return the same string within the
* same test.
+ * Intended to produce distinct names for files that may be stored in
+ * the same directory for multiple tests.
*/
static std::string getTestSpecificFileName(const char *suffix);
* \param[in] filename Relative path/filename to a test input file.
* \returns Path to \p filename under the test input data directory.
*/
- static std::string getTestFilePath(const char *filename);
+ static std::string getInputFilePath(const char *filename);
/*! \brief
* Returns the path to the test input directory.
*
* \returns Path to input data directory for the test executable.
*/
- static const char *getTestDataPath();
+ static const char *getInputDataDirectory();
/*! \brief
* Sets the test input directory.
*
* \p path must name an existing directory.
*
- * This function is automatically called by test_main_gtest.cpp and
- * test_main_gmock.cpp.
+ * This function is automatically called by unittest_main.cpp through
+ * initTestUtils().
*/
- static void setTestDataPath(const char *path);
+ static void setInputDataDirectory(const char *path);
private:
class Impl;
#include "gromacs/utility/gmxassert.h"
#include "gromacs/utility/programinfo.h"
-#include "datapath.h"
#include "refdata.h"
#include "testexceptions.h"
+#include "testfilemanager.h"
namespace
{
::testing::InitGoogleMock(argc, argv);
if (dataPath != NULL)
{
- TestFileManager::setTestDataPath(dataPath);
+ TestFileManager::setInputDataDirectory(dataPath);
}
initReferenceData(argc, argv);
boost::scoped_ptr<std::vector<std::string> > commandLine(