Renamed TestTemporaryFileManager to TestFileManager
authorRoland Schulz <roland@utk.edu>
Tue, 5 Jun 2012 20:55:36 +0000 (16:55 -0400)
committerRoland Schulz <roland@utk.edu>
Wed, 6 Jun 2012 16:30:47 +0000 (12:30 -0400)
Made utility functions static members of class

Change-Id: I706a9c4b5d6e8fe4f121d1e50d229b03f492e49d

src/gromacs/commandline/tests/cmdlinehelpwriter.cpp
src/gromacs/onlinehelp/tests/helpmanager.cpp
src/gromacs/selection/tests/selectioncollection.cpp
src/gromacs/selection/tests/selectionoption.cpp
src/testutils/datapath.cpp
src/testutils/datapath.h
src/testutils/refdata.cpp
src/testutils/testoptions.cpp

index 36ab4a53206c3994eb564bab104829f3f630513e..3d25d3de17db6b9ac7fa7b1dee47ad973a223fae 100644 (file)
@@ -67,7 +67,7 @@ class CommandLineHelpWriterTest : public ::gmx::test::StringTestBase
     public:
         void checkHelp(gmx::CommandLineHelpWriter *writer);
 
-        gmx::test::TestTemporaryFileManager tempFiles_;
+        gmx::test::TestFileManager tempFiles_;
 };
 
 void CommandLineHelpWriterTest::checkHelp(gmx::CommandLineHelpWriter *writer)
index 71279664680d5e46e2bec2f4dbdc8e77495c5305..57750e9ec391a2cde01b3a608ef3fa86e2266d89 100644 (file)
@@ -60,7 +60,7 @@ class HelpTestBase : public gmx::test::StringTestBase
     public:
         HelpTestBase();
 
-        gmx::test::TestTemporaryFileManager tempFiles_;
+        gmx::test::TestFileManager tempFiles_;
         MockHelpTopic           rootTopic_;
         gmx::HelpManager        manager_;
 };
index 5e7edb04f69f2f133a4967c44fd17e29b6307792..3b7c896f1d754441d6473f4dd78ac066ba191a7c 100644 (file)
@@ -127,7 +127,7 @@ SelectionCollectionTest::loadTopology(const char *filename)
     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);
@@ -354,7 +354,7 @@ TEST_F(SelectionCollectionTest, HandlesNoSelections)
 
 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());
index 4d33f9bf8c0680db1fc26410e090c21ad55985df..3db168982e89975b74ab987e56f78c64f6867bfd 100644 (file)
@@ -353,7 +353,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::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());
@@ -378,7 +378,7 @@ TEST_F(SelectionFileOptionTest, HandlesTwoSeparateSelectionOptions)
     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());
@@ -415,7 +415,7 @@ TEST_F(SelectionFileOptionTest, HandlesTwoSelectionOptionsFromSingleFile)
     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());
@@ -451,7 +451,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::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());
@@ -488,7 +488,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::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());
@@ -514,7 +514,7 @@ TEST_F(SelectionFileOptionTest, HandlesTwoRequiredOptionsFromSingleFile)
     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));
@@ -564,7 +564,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::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());
@@ -585,7 +585,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::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());
index e3266870009fe05274fa5c583fbed7fbfe1ad4cb..ae0bab30ec0b1188f5c9008688b2438466f70e39 100644 (file)
@@ -55,34 +55,16 @@ namespace gmx
 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.
@@ -99,7 +81,7 @@ class TestTemporaryFileManager::Impl
         FileNameList            files_;
 };
 
-void TestTemporaryFileManager::Impl::removeFiles()
+void TestFileManager::Impl::removeFiles()
 {
     FileNameList::const_iterator i;
     for (i = files_.begin(); i != files_.end(); ++i)
@@ -110,20 +92,20 @@ void TestTemporaryFileManager::Impl::removeFiles()
 }
 
 /********************************************************************
- * 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);
@@ -131,7 +113,7 @@ std::string TestTemporaryFileManager::getTemporaryFilePath(const char *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();
@@ -146,5 +128,23 @@ std::string TestTemporaryFileManager::getTestSpecificFileName(const char *suffix
     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
index 2aa528840d36d9dc3a0a2f70e18e656e2a798dbc..3ac418b740acf4ca873098f987701d94bae87755 100644 (file)
  */
 /*! \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
@@ -113,22 +65,26 @@ void setTestDataPath(const char *path);
  * 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.
@@ -158,6 +114,33 @@ class TestTemporaryFileManager
          */
         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;
 
index 3edd671f2c47ef867b6d25ccf6c21cbeec537a8d..4b9885ae4eb23cd855366eec2841e2ff3be8441e 100644 (file)
@@ -90,7 +90,7 @@ void setReferenceDataMode(ReferenceDataMode mode)
 
 std::string getReferenceDataPath()
 {
-    return getTestFilePath("refdata");
+    return TestFileManager::getTestFilePath("refdata");
 }
 
 void initReferenceData(int *argc, char **argv)
@@ -157,7 +157,7 @@ TestReferenceData::Impl::Impl(ReferenceDataMode mode)
     : _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;
index 2ec782ce4475dd87a47cd99c2e55e9f5d1c89a9c..884f2168692d8aee7c166dd4d4010be94a71aeb2 100644 (file)
@@ -72,7 +72,7 @@ void initTestUtils(const char *dataPath, int *argc, char *argv[])
         ::testing::InitGoogleMock(argc, argv);
         if (dataPath != NULL)
         {
-            setTestDataPath(dataPath);
+            TestFileManager::setTestDataPath(dataPath);
         }
         initReferenceData(argc, argv);
         boost::scoped_ptr<std::vector<std::string> > commandLine(