SYCL: Avoid using no_init read accessor in rocFFT
[alexxy/gromacs.git] / src / testutils / include / testutils / textblockmatchers.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2015,2018,2019,2020, 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 multi-line strings against reference data.
38  *
39  * \author Teemu Murtola <teemu.murtola@gmail.com>
40  * \inlibraryapi
41  * \ingroup module_testutils
42  */
43 #ifndef GMX_TESTUTILS_TEXTBLOCKMATCHERS_H
44 #define GMX_TESTUTILS_TEXTBLOCKMATCHERS_H
45
46 #include <memory>
47 #include <string>
48 #include <vector>
49
50 namespace gmx
51 {
52
53 class TextInputStream;
54
55 namespace test
56 {
57
58 class TestReferenceChecker;
59
60 /*! \libinternal \brief
61  * Represents a text matcher, matching text stream contents against reference
62  * data.
63  *
64  * Typical pattern of declaring such matchers is to
65  *  - Create a factory that implements ITextBlockMatcherSettings,
66  *  - Make that factory provide any necessary parameters that the matcher needs,
67  *    using a "named parameter" idiom (see XvgMatch for an example), and
68  *  - Make the factory create and return an instance of an internal
69  *    implementation class that implements ITextBlockMatcher and provides
70  *    the actual matching logic.
71  *
72  * Any method that then wants to accept a matcher can accept a
73  * ITextBlockMatcherSettings.
74  *
75  * \inlibraryapi
76  * \ingroup module_testutils
77  */
78 class ITextBlockMatcher
79 {
80 public:
81     virtual ~ITextBlockMatcher();
82
83     /*! \brief
84      * Matches contents of a stream against reference data.
85      *
86      * \param  stream   Stream to match.
87      * \param  checker  Checker to use for matching.
88      *
89      * The method can change the state of the provided checker (e.g., by
90      * changing the default tolerance).
91      * The caller is responsible of providing a checker where such state
92      * changes do not matter.
93      */
94     virtual void checkStream(TextInputStream* stream, TestReferenceChecker* checker) = 0;
95 };
96
97 //! Smart pointer for managing a ITextBlockMatcher.
98 typedef std::unique_ptr<ITextBlockMatcher> TextBlockMatcherPointer;
99
100 /*! \libinternal \brief
101  * Represents a factory for creating a text matcher.
102  *
103  * See derived classes for available matchers.  Each derived class represents
104  * one type of matcher (see ITextBlockMatcher), and provides any methods
105  * necessary to pass parameters to such a matcher.  Methods that accept a
106  * matcher can then take in this interface, and call createMatcher() to use the
107  * matcher that the caller of the method specifies.
108  *
109  * \inlibraryapi
110  * \ingroup module_testutils
111  */
112 class ITextBlockMatcherSettings
113 {
114 public:
115     //! Factory method that constructs the matcher after parameters are set.
116     virtual TextBlockMatcherPointer createMatcher() const = 0;
117
118 protected:
119     virtual ~ITextBlockMatcherSettings();
120 };
121
122 /*! \libinternal \brief
123  * Use an exact text match (the contents should be exactly equal).
124  *
125  * \inlibraryapi
126  * \ingroup module_testutils
127  */
128 class ExactTextMatch : public ITextBlockMatcherSettings
129 {
130 public:
131     TextBlockMatcherPointer createMatcher() const override;
132 };
133
134 /*! \libinternal \brief
135  * Do not match the text (the contents are ignored).
136  *
137  * \inlibraryapi
138  * \ingroup module_testutils
139  */
140 class NoTextMatch : public ITextBlockMatcherSettings
141 {
142 public:
143     TextBlockMatcherPointer createMatcher() const override;
144 };
145
146 /*! \libinternal \brief
147  * Use an exact text match after scrubbing lines of the text
148  * that match the supplied regular expressions.
149  *
150  * This suits comparing files in tests that are intended to be
151  * localized by reporting usage, time, date, user, or file-system
152  * stamps. The latter won't be reproducible in tests until
153  * the tools that emit them can be mocked suitably.
154  *
155  * \inlibraryapi
156  * \ingroup module_testutils
157  */
158 class FilteringExactTextMatch : public ITextBlockMatcherSettings
159 {
160 public:
161     //! Constructor
162     explicit FilteringExactTextMatch(std::vector<std::string> linesToSkip);
163     //! Factory method.
164     TextBlockMatcherPointer createMatcher() const override;
165     //! Add a regular expression for which a matching line should be skipped.
166     void addRegexToSkip(const std::string& lineToSkip);
167
168 private:
169     //! The regular expressions for lines that should be skipped.
170     std::vector<std::string> linesToSkip_;
171 };
172
173 } // namespace test
174 } // namespace gmx
175
176 #endif