2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
35 /*! \libinternal \file
37 * Declares gmx::test::TestFileManager.
39 * \author Teemu Murtola <teemu.murtola@gmail.com>
41 * \ingroup module_testutils
43 /*! \libinternal \defgroup module_testutils Unit Testing Utilities (testutils)
45 * Common helper classes and functions for writing unit tests.
47 * To build unit tests using these utilities, libxml2 is required.
49 * \ingroup group_utilitymodules
51 #ifndef GMX_TESTUTILS_TESTFILEMANAGER_H
52 #define GMX_TESTUTILS_TESTFILEMANAGER_H
56 #include "gromacs/utility/common.h"
60 /*! \libinternal \brief
61 * Testing utilities namespace.
63 * This namespace contains utilities for writing unit tests, mostly from the
64 * \ref module_testutils module.
69 /*! \libinternal \brief
70 * Helper for tests that need output files.
72 * To be used as a member in a test fixture class, this class provides
73 * getTemporaryFilePath() method that returns a path for creating file names
74 * for temporary files. The returned path contains the name of the running
75 * test, making it unique across tests. Additionally, this class takes care of
76 * removing any temporary files (i.e., all paths returned by
77 * getTemporaryFilePath()) at test teardown (i.e., when the
78 * TestFileManager is destructed).
80 * Functions getInputFilePath() and getInputDataDirectory() provide means to
81 * access data files that are located in the test source directory.
82 * This is used to provide input files for the tests, and also to store test
83 * reference data persistently (see TestReferenceData).
86 * \ingroup module_testutils
93 * Frees internal storage and deletes any accessed file paths.
95 * Any errors (e.g., missing files) encountered while deleting the
101 * Creates a name for a temporary file within a single unit test.
103 * \param[in] suffix Suffix to add to the file name (should contain an
104 * extension if one is desired).
105 * \returns Temporary file name that includes the test name and
108 * This method should only be called from within a Google Test test.
109 * Two calls with the same \p suffix return the same string within the
112 std::string getTemporaryFilePath(const char *suffix);
115 * Creates a file name for use within a single unit test.
117 * \param[in] suffix Suffix to add to the file name (should contain an
118 * extension if one is desired).
119 * \returns File name that includes the test name and
122 * This method should only be called from within a Google Test test.
123 * Two calls with the same \p suffix return the same string within the
125 * Intended to produce distinct names for files that may be stored in
126 * the same directory for multiple tests.
128 static std::string getTestSpecificFileName(const char *suffix);
131 * Returns the path to a test input file.
133 * \param[in] filename Relative path/filename to a test input file.
134 * \returns Path to \p filename under the test input data directory.
136 static std::string getInputFilePath(const char *filename);
139 * Returns the path to the test input directory.
141 * \returns Path to input data directory for the test executable.
143 static const char *getInputDataDirectory();
146 * Sets the test input directory.
148 * \param[in] path Path from which test input data is looked up from.
150 * \p path must name an existing directory.
152 * This function is automatically called by unittest_main.cpp through
155 static void setInputDataDirectory(const char *path);
160 PrivateImplPointer<Impl> impl_;