Clarify TestFileManager naming and comments.
authorTeemu Murtola <teemu.murtola@gmail.com>
Sun, 5 Aug 2012 05:54:09 +0000 (08:54 +0300)
committerTeemu Murtola <teemu.murtola@gmail.com>
Sun, 5 Aug 2012 18:24:08 +0000 (21:24 +0300)
- Rename datapath.* to testfilemanger.*, since they now only declare
  that one class.
- Make functions that return input data paths have "Input" explicitly in
  their name to make it clear what data path they are returning.  Also
  remove redundant "Test" from the names and replace "Path" by
  "Directory" for the functions that deal with directories.
- Some Doxygen documentation updates.

Change-Id: If80b5d83d075f3ce29b7b40c0d17f319166332b8

src/gromacs/commandline/tests/cmdlinehelpwriter.cpp
src/gromacs/onlinehelp/tests/helpmanager.cpp
src/gromacs/options/tests/filenameoption.cpp
src/gromacs/selection/tests/selectioncollection.cpp
src/gromacs/selection/tests/selectionoption.cpp
src/gromacs/trajectoryanalysis/tests/moduletest.cpp
src/testutils/refdata.cpp
src/testutils/testfilemanager.cpp [moved from src/testutils/datapath.cpp with 82% similarity]
src/testutils/testfilemanager.h [moved from src/testutils/datapath.h with 81% similarity]
src/testutils/testoptions.cpp

index 58a7b1c6bb75b5726886585c231dd6b6473bc9ad..2c80aa9803fdacc13d6603924794ba3b53a96479 100644 (file)
@@ -57,8 +57,8 @@
 #include "gromacs/selection/selectionoptionmanager.h"
 #include "gromacs/utility/file.h"
 
-#include "testutils/datapath.h"
 #include "testutils/stringtest.h"
+#include "testutils/testfilemanager.h"
 
 namespace
 {
index 34a049cfd6ccb3c4a7e8f11816cee62243a01d9c..6bd66c677efec47d5519f15c156f62470a4d2d34 100644 (file)
@@ -47,9 +47,9 @@
 #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
 {
index c3a628e39b5ecb5f1114d87c75257b857b080564..84f781ed630803bfb82b36f5db834e85d1b112d7 100644 (file)
@@ -45,7 +45,7 @@
 #include "gromacs/utility/exceptions.h"
 #include "gromacs/utility/file.h"
 
-#include "testutils/datapath.h"
+#include "testutils/testfilemanager.h"
 
 namespace
 {
index 46e2d70a88d05994a37939e54b77553354664eb4..7cf179f7884403b57c577b56ef5008d3a34795a3 100644 (file)
@@ -50,8 +50,8 @@
 #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
@@ -127,7 +127,7 @@ SelectionCollectionTest::loadTopology(const char *filename)
     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);
@@ -354,7 +354,8 @@ TEST_F(SelectionCollectionTest, HandlesNoSelections)
 
 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());
index 2f228025f367f5b04c7021eb29fdb797757e31a9..e5fd8a5eb4f1acdfd708e6d0f92a6175e2ab75ff 100644 (file)
@@ -47,7 +47,9 @@
 #include "gromacs/selection/selectionoptionmanager.h"
 #include "gromacs/utility/exceptions.h"
 
-#include "testutils/datapath.h"
+#include "testutils/testfilemanager.h"
+
+using gmx::test::TestFileManager;
 
 namespace
 {
@@ -352,7 +354,7 @@ TEST_F(SelectionFileOptionTest, HandlesSingleSelectionOptionFromFile)
     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());
@@ -377,7 +379,7 @@ TEST_F(SelectionFileOptionTest, HandlesTwoSeparateSelectionOptions)
     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());
@@ -414,7 +416,7 @@ TEST_F(SelectionFileOptionTest, HandlesTwoSelectionOptionsFromSingleFile)
     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());
@@ -450,7 +452,7 @@ TEST_F(SelectionFileOptionTest, HandlesRequiredOptionFromFile)
     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());
@@ -487,7 +489,7 @@ TEST_F(SelectionFileOptionTest, HandlesRequiredOptionFromFileWithOtherOptionSet)
     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());
@@ -513,7 +515,7 @@ TEST_F(SelectionFileOptionTest, HandlesTwoRequiredOptionsFromSingleFile)
     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));
@@ -563,7 +565,7 @@ TEST_F(SelectionFileOptionTest, GivesErrorWithNonExistentFile)
     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());
@@ -584,7 +586,7 @@ TEST_F(SelectionFileOptionTest, GivesErrorWithMultipleFiles)
     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());
index bdbce2653bf4186fa0250647abe87ecaec454936..6a7267a4b89f16918cbdd3dc4b41425b004fe744 100644 (file)
@@ -46,9 +46,9 @@
 #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
 {
@@ -137,14 +137,14 @@ void
 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
index 2ba66fe6df715717589ee85214b347ce06449249..9fba5fe5734cebedfc9bd834007588c028e6a882 100644 (file)
@@ -52,8 +52,8 @@
 #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
 {
@@ -93,7 +93,7 @@ void setReferenceDataMode(ReferenceDataMode mode)
 
 std::string getReferenceDataPath()
 {
-    return TestFileManager::getTestFilePath("refdata");
+    return TestFileManager::getInputFilePath("refdata");
 }
 
 void initReferenceData(int *argc, char **argv)
similarity index 82%
rename from src/testutils/datapath.cpp
rename to src/testutils/testfilemanager.cpp
index c45508ddd0c9cca534a07f7800245967ac6b7543..3356779f85e20671261cb8271a3b61ea70f61044 100644 (file)
  */
 /*! \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
@@ -73,6 +65,9 @@ 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;
 
@@ -87,6 +82,8 @@ class TestFileManager::Impl
         FileNameList            files_;
 };
 
+const char *TestFileManager::Impl::s_inputDirectory = NULL;
+
 void TestFileManager::Impl::removeFiles()
 {
     FileNameList::const_iterator i;
@@ -134,22 +131,24 @@ std::string TestFileManager::getTestSpecificFileName(const char *suffix)
     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
similarity index 81%
rename from src/testutils/datapath.h
rename to src/testutils/testfilemanager.h
index 3ac418b740acf4ca873098f987701d94bae87755..6119b889fba068a0812cae8b14e28fcdae2179e3 100644 (file)
@@ -30,7 +30,7 @@
  */
 /*! \libinternal \file
  * \brief
- * Declares gmx::test::TestFileManager
+ * Declares gmx::test::TestFileManager.
  *
  * \author Teemu Murtola <teemu.murtola@cbr.su.se>
  * \inlibraryapi
@@ -44,8 +44,8 @@
  *
  * \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
 {
 
@@ -67,9 +73,10 @@ 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
@@ -101,7 +108,7 @@ class TestFileManager
         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).
@@ -111,6 +118,8 @@ class TestFileManager
          * 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);
 
@@ -120,14 +129,14 @@ class TestFileManager
          * \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.
@@ -136,10 +145,10 @@ class TestFileManager
          *
          * \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;
index 9601dfe66ceee7a986947d6d5b0bd397e64e881d..6b2f7bda267847b04aa2ef370b6d1d77c2e0491e 100644 (file)
@@ -53,9 +53,9 @@
 #include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/programinfo.h"
 
-#include "datapath.h"
 #include "refdata.h"
 #include "testexceptions.h"
+#include "testfilemanager.h"
 
 namespace
 {
@@ -78,7 +78,7 @@ void initTestUtils(const char *dataPath, int *argc, char *argv[])
         ::testing::InitGoogleMock(argc, argv);
         if (dataPath != NULL)
         {
-            TestFileManager::setTestDataPath(dataPath);
+            TestFileManager::setInputDataDirectory(dataPath);
         }
         initReferenceData(argc, argv);
         boost::scoped_ptr<std::vector<std::string> > commandLine(