clang-tidy: override
[alexxy/gromacs.git] / src / testutils / filematchers.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2017,2018, 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.
8  *
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.
13  *
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.
18  *
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.
23  *
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.
31  *
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.
34  */
35 /*! \libinternal \file
36  * \brief
37  * Declares utility classes for testing file contents.
38  *
39  * \author Teemu Murtola <teemu.murtola@gmail.com>
40  * \inlibraryapi
41  * \ingroup module_testutils
42  */
43 #ifndef GMX_TESTUTILS_FILEMATCHERS_H
44 #define GMX_TESTUTILS_FILEMATCHERS_H
45
46 #include <memory>
47 #include <string>
48
49 namespace gmx
50 {
51 namespace test
52 {
53
54 class ITextBlockMatcherSettings;
55 class TestReferenceChecker;
56
57 /*! \libinternal \brief
58  * Represents a file matcher, matching file contents against reference (or
59  * other) data.
60  *
61  * Typical pattern of declaring such matchers is to
62  *  - Create a factory that implements IFileMatcherSettings,
63  *  - Make that factory provide any necessary parameters that the matcher needs,
64  *    using a "named parameter" idiom (see XvgMatch for an example), and
65  *  - Make the factory create and return an instance of an internal
66  *    implementation class that implements IFileMatcher and provides
67  *    the actual matching logic.
68  *
69  * Any method that then wants to accept a matcher can accept a
70  * IFileMatcherSettings.
71  *
72  * \inlibraryapi
73  * \ingroup module_testutils
74  */
75 class IFileMatcher
76 {
77     public:
78         virtual ~IFileMatcher();
79
80         /*! \brief
81          * Matches contents of a file.
82          *
83          * \param  path     Path to the file to match.
84          * \param  checker  Checker to use for matching.
85          *
86          * The method can change the state of the provided checker (e.g., by
87          * changing the default tolerance).
88          * The caller is responsible of providing a checker where such state
89          * changes do not matter.
90          */
91         virtual void checkFile(const std::string    &path,
92                                TestReferenceChecker *checker) = 0;
93 };
94
95 //! Smart pointer for managing a IFileMatcher.
96 typedef std::unique_ptr<IFileMatcher> FileMatcherPointer;
97
98 /*! \libinternal \brief
99  * Represents a factory for creating a file matcher.
100  *
101  * See derived classes for available matchers.  Each derived class represents
102  * one type of matcher (see IFileMatcher), and provides any methods
103  * necessary to pass parameters to such a matcher.  Methods that accept a
104  * matcher can then take in this interface, and call createFileMatcher() to use
105  * the matcher that the caller of the method specifies.
106  *
107  * \inlibraryapi
108  * \ingroup module_testutils
109  */
110 class IFileMatcherSettings
111 {
112     public:
113         //! Factory method that constructs the matcher after parameters are set.
114         virtual FileMatcherPointer createFileMatcher() const = 0;
115
116     protected:
117         virtual ~IFileMatcherSettings();
118 };
119
120 /*! \libinternal \brief
121  * Use a ITextBlockMatcher for matching the contents.
122  *
123  * \inlibraryapi
124  * \ingroup module_testutils
125  */
126 class TextFileMatch : public IFileMatcherSettings
127 {
128     public:
129         //! Creates a matcher to match contents with given text matcher.
130         explicit TextFileMatch(const ITextBlockMatcherSettings &streamSettings)
131             : streamSettings_(streamSettings)
132         {
133         }
134
135         FileMatcherPointer createFileMatcher() const override;
136
137     private:
138         const ITextBlockMatcherSettings &streamSettings_;
139 };
140
141 /*! \libinternal \brief
142  * Do not check the contents of the file.
143  *
144  * \inlibraryapi
145  * \ingroup module_testutils
146  */
147 class NoContentsMatch : public IFileMatcherSettings
148 {
149     public:
150         FileMatcherPointer createFileMatcher() const override;
151 };
152
153 } // namespace test
154 } // namespace gmx
155
156 #endif