public:
void checkHelp(gmx::CommandLineHelpWriter *writer);
- gmx::test::TestTemporaryFileManager tempFiles_;
+ gmx::test::TestFileManager tempFiles_;
};
void CommandLineHelpWriterTest::checkHelp(gmx::CommandLineHelpWriter *writer)
public:
HelpTestBase();
- gmx::test::TestTemporaryFileManager tempFiles_;
+ gmx::test::TestFileManager tempFiles_;
MockHelpTopic rootTopic_;
gmx::HelpManager manager_;
};
matrix box;
snew(_top, 1);
- read_tps_conf(gmx::test::getTestFilePath(filename).c_str(),
+ read_tps_conf(gmx::test::TestFileManager::getTestFilePath(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::getTestFilePath("selfile.dat")));
+ ASSERT_NO_THROW(_sel = _sc.parseFromFile(gmx::test::TestFileManager::getTestFilePath("selfile.dat")));
// These should match the contents of selfile.dat
ASSERT_EQ(2U, _sel.size());
EXPECT_STREQ("resname RA RB", _sel[0].selectionText());
ASSERT_NO_THROW(assigner.startOption("sel"));
EXPECT_NO_THROW(assigner.finishOption());
ASSERT_NO_THROW(assigner.startOption("sf"));
- EXPECT_NO_THROW(assigner.appendValue(gmx::test::getTestFilePath("selfile.dat")));
+ EXPECT_NO_THROW(assigner.appendValue(gmx::test::TestFileManager::getTestFilePath("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::getTestFilePath("selfile.dat"));
+ std::string value(gmx::test::TestFileManager::getTestFilePath("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::getTestFilePath("selfile.dat"));
+ std::string value(gmx::test::TestFileManager::getTestFilePath("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::getTestFilePath("selfile.dat")));
+ EXPECT_NO_THROW(assigner.appendValue(gmx::test::TestFileManager::getTestFilePath("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::getTestFilePath("selfile.dat")));
+ EXPECT_NO_THROW(assigner.appendValue(gmx::test::TestFileManager::getTestFilePath("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::getTestFilePath("selfile.dat"));
+ std::string value(gmx::test::TestFileManager::getTestFilePath("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::getTestFilePath("selfile.dat")),
+ EXPECT_THROW(assigner.appendValue(gmx::test::TestFileManager::getTestFilePath("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::getTestFilePath("selfile.dat")));
+ EXPECT_NO_THROW(assigner.appendValue(gmx::test::TestFileManager::getTestFilePath("selfile.dat")));
EXPECT_THROW(assigner.appendValue("nonexistentfile"), gmx::InvalidInputError);
EXPECT_NO_THROW(assigner.finishOption());
EXPECT_NO_THROW(assigner.finish());
namespace test
{
-std::string getTestFilePath(const char *filename)
-{
- return Path::join(getTestDataPath(), filename);
-}
-
-const char *getTestDataPath()
-{
- GMX_RELEASE_ASSERT(g_testDataPath != NULL, "Test data path not set");
- return g_testDataPath;
-}
-
-void setTestDataPath(const char *path)
-{
- GMX_RELEASE_ASSERT(Directory::exists(path),
- "Test data directory does not exist");
- g_testDataPath = path;
-}
-
/********************************************************************
- * TestTemporaryFileManager::Impl
+ * TestFileManager::Impl
*/
/*! \internal \brief
- * Private implementation class for TestTemporaryFileManager.
+ * Private implementation class for TestFileManager.
*
* \ingroup module_testutils
*/
-class TestTemporaryFileManager::Impl
+class TestFileManager::Impl
{
public:
//! Container type for names of temporary files.
FileNameList files_;
};
-void TestTemporaryFileManager::Impl::removeFiles()
+void TestFileManager::Impl::removeFiles()
{
FileNameList::const_iterator i;
for (i = files_.begin(); i != files_.end(); ++i)
}
/********************************************************************
- * TestTemporaryFileManager
+ * TestFileManager
*/
-TestTemporaryFileManager::TestTemporaryFileManager()
+TestFileManager::TestFileManager()
: impl_(new Impl)
{
}
-TestTemporaryFileManager::~TestTemporaryFileManager()
+TestFileManager::~TestFileManager()
{
impl_->removeFiles();
}
-std::string TestTemporaryFileManager::getTemporaryFilePath(const char *suffix)
+std::string TestFileManager::getTemporaryFilePath(const char *suffix)
{
// TODO: Add the path of the test binary
std::string filename = getTestSpecificFileName(suffix);
return filename;
}
-std::string TestTemporaryFileManager::getTestSpecificFileName(const char *suffix)
+std::string TestFileManager::getTestSpecificFileName(const char *suffix)
{
const ::testing::TestInfo *test_info =
::testing::UnitTest::GetInstance()->current_test_info();
return filename;
}
+std::string TestFileManager::getTestFilePath(const char *filename)
+{
+ return Path::join(getTestDataPath(), filename);
+}
+
+const char *TestFileManager::getTestDataPath()
+{
+ GMX_RELEASE_ASSERT(g_testDataPath != NULL, "Test data path not set");
+ return g_testDataPath;
+}
+
+void TestFileManager::setTestDataPath(const char *path)
+{
+ GMX_RELEASE_ASSERT(Directory::exists(path),
+ "Test data directory does not exist");
+ g_testDataPath = path;
+}
+
} // namespace test
} // namespace gmx
*/
/*! \libinternal \file
* \brief
- * Functions for constructing file names for test files.
- *
- * 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.
- *
- * For temporary files used within a single test (typically in testing code
- * that writes into files), gmx::test::TestTemporaryFileManager is provided.
+ * Declares gmx::test::TestFileManager
*
* \author Teemu Murtola <teemu.murtola@cbr.su.se>
* \inlibraryapi
namespace gmx
{
-/*! \libinternal \brief
- * Namespace for unit testing utilities.
- *
- * This namespace contains utilities that are shared between unit tests.
- * Most members are declared in the \ref module_testutils module, but some
- * are also declared within individual tests (these are typically candidates
- * for using in other tests as well).
- *
- * \ingroup module_testutils
- */
namespace test
{
/*! \libinternal \brief
- * Returns the path to a test input file.
- *
- * \param[in] filename Relative path/filename to a test input file.
- * \returns Path to \p filename under the test input data directory.
- *
- * \inlibraryapi
- */
-std::string getTestFilePath(const char *filename);
-/*! \libinternal \brief
- * Returns the path to the test input directory.
- *
- * \returns Path to input data directory for the test executable.
- *
- * \inlibraryapi
- */
-const char *getTestDataPath();
-/*! \libinternal \brief
- * Sets the test input directory.
- *
- * \param[in] path Path from which test input data is looked up from.
- *
- * \p path must name an existing directory.
- *
- * This function is automatically called by test_main_gtest.cpp and
- * test_main_gmock.cpp.
- *
- * \inlibraryapi
- */
-void setTestDataPath(const char *path);
-
-/*! \libinternal \brief
- * Helper for tests that need temporary output files.
+ * Helper for tests that need output files.
*
* To be used as a member in a test fixture class, this class provides
* getTemporaryFilePath() method that returns a path for creating file names
* test, making it unique across tests. Additionally, this class takes care of
* removing any temporary files (i.e., all paths returned by
* getTemporaryFilePath()) at test teardown (i.e., when the
- * TestTemporaryFileManager is desctructed).
+ * 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.
*
* \inlibraryapi
* \ingroup module_testutils
*/
-class TestTemporaryFileManager
+class TestFileManager
{
public:
- TestTemporaryFileManager();
+ TestFileManager();
/*! \brief
* Frees internal storage and deletes any accessed file paths.
*
* Any errors (e.g., missing files) encountered while deleting the
* files are ignored.
*/
- ~TestTemporaryFileManager();
+ ~TestFileManager();
/*! \brief
* Creates a name for a temporary file within a single unit test.
*/
static std::string getTestSpecificFileName(const char *suffix);
+ /*! \brief
+ * Returns the path to a test input file.
+ *
+ * \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);
+
+ /*! \brief
+ * Returns the path to the test input directory.
+ *
+ * \returns Path to input data directory for the test executable.
+ */
+ static const char *getTestDataPath();
+
+ /*! \brief
+ * Sets the test input directory.
+ *
+ * \param[in] path Path from which test input data is looked up from.
+ *
+ * \p path must name an existing directory.
+ *
+ * This function is automatically called by test_main_gtest.cpp and
+ * test_main_gmock.cpp.
+ */
+ static void setTestDataPath(const char *path);
+
private:
class Impl;
std::string getReferenceDataPath()
{
- return getTestFilePath("refdata");
+ return TestFileManager::getTestFilePath("refdata");
}
void initReferenceData(int *argc, char **argv)
: _refDoc(NULL), _bWrite(false), _bInUse(false)
{
std::string dirname = getReferenceDataPath();
- std::string filename = TestTemporaryFileManager::getTestSpecificFileName(".xml");
+ std::string filename = TestFileManager::getTestSpecificFileName(".xml");
_fullFilename = Path::join(dirname, filename);
_bWrite = true;
::testing::InitGoogleMock(argc, argv);
if (dataPath != NULL)
{
- setTestDataPath(dataPath);
+ TestFileManager::setTestDataPath(dataPath);
}
initReferenceData(argc, argv);
boost::scoped_ptr<std::vector<std::string> > commandLine(