Debian Codegraph @

tests/testutils.h

raw symbols SCIP
1 #cxx . . $ `<file>/tests/testutils.h`/ifndef TESTUTILS_H
2 #define TESTUTILS_Hcxx . . $ `tests/testutils.h:2:9`!
3
4 #include "../application/argumentparser.h"cxx . . $ `<file>/application/argumentparser.h`/
5 #include "../chrono/format.h"cxx . . $ `<file>/chrono/format.h`/
6 #include "../misc/traits.h"cxx . . $ `<file>/misc/traits.h`/
7
8 #include <iomanip>
9 #include <optional>
10 #include <ostream>
11 #include <string>
12
13 #if defined(PLATFORM_UNIXcxx . . $ `application/global.h:56:9`!) || defined(CPP_UTILITIES_BOOST_PROCESS)
14 #define CPP_UTILITIES_HAS_EXEC_APPcxx . . $ `tests/testutils.h:14:9`!
15 #endif
16
17 // ensure CppUnit's macros produce unique variable names when doing unity builds
18 #if defined(__COUNTER__)
19 #undef CPPUNIT_UNIQUE_COUNTER
20 #define CPPUNIT_UNIQUE_COUNTERcxx . . $ `tests/testutils.h:20:9`! __COUNTER__
21 #endif
22
23 namespace CppUtilitiescxx . . $ CppUtilities/ {
24
25 /*!
26 * \brief The WorkingCopyMode enum specifies additional options to influence behavior of TestApplication::workingCopyPath().
27 */
28 enum class WorkingCopyModecxx . . $ CppUtilities/WorkingCopyMode# {
29 CreateCopycxx . . $ CppUtilities/WorkingCopyMode#CreateCopy., /**< a working copy of the test file is created */
30 NoCopycxx . . $ CppUtilities/WorkingCopyMode#NoCopy., /**< only the directory for the working copy is created but not the test file itself */
31 Cleanupcxx . . $ CppUtilities/WorkingCopyMode#Cleanup., /**< the directory for the working copy is created if needed or a previously existing file is deleted */
32 };
33
34 class CPP_UTILITIES_EXPORTcxx . . $ `global.h:11:9`! TestApplicationcxx . . $ CppUtilities/TestApplication# {
35 public:
36 // construction/destruction
37 explicit TestApplicationcxx . . $ CppUtilities/TestApplication#TestApplication(49f6e7a06ebc5aa8).();
38 explicit TestApplicationcxx . . $ CppUtilities/TestApplication#TestApplication(5151383285df94d8).(int argc, const char *const *argv);
39 ~cxx . . $ CppUtilities/TestApplication#`~TestApplication`(ced63f7c635d850d).TestApplicationcxx . . $ CppUtilities/TestApplication#();
40 operatorcxx . . $ CppUtilities/TestApplication#`operator bool`(50ce9a9e25b4a850). bool() const;
41
42 // helper for tests
43 stdcxx . . $ std/::stringcxx . . $ std/string# testFilePathcxx . . $ CppUtilities/TestApplication#testFilePath(ed3976f106e8bf8e).(const stdcxx . . $ std/::stringcxx . . $ std/string# &relativeTestFilePath) const;
44 stdcxx . . $ std/::stringcxx . . $ std/string# testDirPathcxx . . $ CppUtilities/TestApplication#testDirPath(ed3976f106e8bf8e).(const stdcxx . . $ std/::stringcxx . . $ std/string# &relativeTestDirPath) const;
45 stdcxx . . $ std/::stringcxx . . $ std/string# workingCopyPathcxx . . $ CppUtilities/TestApplication#workingCopyPath(c3c5822f4886442b).(const stdcxx . . $ std/::stringcxx . . $ std/string# &relativeTestFilePath, WorkingCopyModecxx . . $ CppUtilities/WorkingCopyMode# mode = WorkingCopyModecxx . . $ CppUtilities/WorkingCopyMode#::CreateCopycxx . . $ CppUtilities/WorkingCopyMode#CreateCopy.) const;
46 stdcxx . . $ std/::stringcxx . . $ std/string# workingCopyPathAscxx . . $ CppUtilities/TestApplication#workingCopyPathAs(e656189f96ce13ac).(const stdcxx . . $ std/::stringcxx . . $ std/string# &relativeTestFilePath, const stdcxx . . $ std/::stringcxx . . $ std/string# &relativeWorkingCopyPath,
47 WorkingCopyModecxx . . $ CppUtilities/WorkingCopyMode# mode = WorkingCopyModecxx . . $ CppUtilities/WorkingCopyMode#::CreateCopycxx . . $ CppUtilities/WorkingCopyMode#CreateCopy.) const;
48 #ifdef CPP_UTILITIES_HAS_EXEC_APPcxx . . $ `tests/testutils.h:14:9`!
49 int execAppcxx . . $ CppUtilities/TestApplication#execApp(846fd0e56e89d1b1).(const char *const *args, stdcxx . . $ std/::stringcxx . . $ std/string# &output, stdcxx . . $ std/::stringcxx . . $ std/string# &errors, bool suppressLogging = false, int timeout = -1) const;
50 #endif
51
52 // read-only accessors
53 const stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::stringcxx . . $ std/string#> &testFilePathscxx . . $ CppUtilities/TestApplication#testFilePaths(f5f2959be38ccc08).() const;
54 const stdcxx . . $ std/::stringcxx . . $ std/string# &workingDirectorycxx . . $ CppUtilities/TestApplication#workingDirectory(f4fff0029955a25f).() const;
55 const char *applicationPathcxx . . $ CppUtilities/TestApplication#applicationPath(33a1f659e94feb42).();
56 bool unitsSpecifiedcxx . . $ CppUtilities/TestApplication#unitsSpecified(50ce9a9e25b4a850).() const;
57 const stdcxx . . $ std/::vectorcxx . . $ std/vector#<const char *> &unitscxx . . $ CppUtilities/TestApplication#units(6073f6567d110ada).() const;
58 bool onlyListUnitscxx . . $ CppUtilities/TestApplication#onlyListUnits(50ce9a9e25b4a850).() const;
59
60 // static read-only accessors
61 static const TestApplicationcxx . . $ CppUtilities/TestApplication# *instancecxx . . $ CppUtilities/TestApplication#instance(5fe4d5890b105a5c).();
62 static const char *appPathcxx . . $ CppUtilities/TestApplication#appPath(33a1f659e94feb42).();
63
64 private:
65 static stdcxx . . $ std/::stringcxx . . $ std/string# readTestfilePathFromEnvcxx . . $ CppUtilities/TestApplication#readTestfilePathFromEnv(efd28698952f529a).();
66 static stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::stringcxx . . $ std/string#> readTestfilePathFromSrcRefcxx . . $ CppUtilities/TestApplication#readTestfilePathFromSrcRef(c1a9bfb60daa162d).();
67
68 ArgumentParsercxx . . $ CppUtilities/ArgumentParser# m_parsercxx . . $ CppUtilities/TestApplication#m_parser.;
69 OperationArgumentcxx . . $ CppUtilities/OperationArgument# m_listArgcxx . . $ CppUtilities/TestApplication#m_listArg.;
70 OperationArgumentcxx . . $ CppUtilities/OperationArgument# m_runArgcxx . . $ CppUtilities/TestApplication#m_runArg.;
71 ConfigValueArgumentcxx . . $ CppUtilities/ConfigValueArgument# m_testFilesPathArgcxx . . $ CppUtilities/TestApplication#m_testFilesPathArg.;
72 ConfigValueArgumentcxx . . $ CppUtilities/ConfigValueArgument# m_applicationPathArgcxx . . $ CppUtilities/TestApplication#m_applicationPathArg.;
73 ConfigValueArgumentcxx . . $ CppUtilities/ConfigValueArgument# m_workingDirArgcxx . . $ CppUtilities/TestApplication#m_workingDirArg.;
74 ConfigValueArgumentcxx . . $ CppUtilities/ConfigValueArgument# m_unitsArgcxx . . $ CppUtilities/TestApplication#m_unitsArg.;
75 stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::stringcxx . . $ std/string#> m_testFilesPathscxx . . $ CppUtilities/TestApplication#m_testFilesPaths.;
76 stdcxx . . $ std/::stringcxx . . $ std/string# m_workingDircxx . . $ CppUtilities/TestApplication#m_workingDir.;
77 bool m_validcxx . . $ CppUtilities/TestApplication#m_valid.;
78 static TestApplicationcxx . . $ CppUtilities/TestApplication# *s_instancecxx . . $ CppUtilities/TestApplication#s_instance.;
79 };
80
81 /*!
82 * \brief Returns whether the TestApplication instance is valid.
83 *
84 * An instance is considered invalid if an error occurred when
85 * parsing the command line arguments.
86 */
87 inline TestApplicationcxx . . $ CppUtilities/TestApplication#::operatorcxx . . $ CppUtilities/TestApplication#`operator bool`(50ce9a9e25b4a850). bool() const
88 {
89 return m_validcxx . . $ CppUtilities/TestApplication#m_valid.;
90 }
91
92 /*!
93 * \brief Returns the current TestApplication instance.
94 */
95 inline const TestApplicationcxx . . $ CppUtilities/TestApplication# *TestApplicationcxx . . $ CppUtilities/TestApplication#::instancecxx . . $ CppUtilities/TestApplication#instance(5fe4d5890b105a5c).()
96 {
97 return TestApplicationcxx . . $ CppUtilities/TestApplication#::s_instancecxx . . $ CppUtilities/TestApplication#s_instance.;
98 }
99
100 /*!
101 * \brief Returns the application path or an empty string if no application path has been set.
102 */
103 inline const char *TestApplicationcxx . . $ CppUtilities/TestApplication#::appPathcxx . . $ CppUtilities/TestApplication#appPath(33a1f659e94feb42).()
104 {
105 return s_instancecxx . . $ CppUtilities/TestApplication#s_instance. ? s_instancecxx . . $ CppUtilities/TestApplication#s_instance.->applicationPathcxx . . $ CppUtilities/TestApplication#applicationPath(33a1f659e94feb42).() : "";
106 }
107
108 /*!
109 * \brief Returns the list of directories to look for test files.
110 */
111 inline const stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::stringcxx . . $ std/string#> &TestApplicationcxx . . $ CppUtilities/TestApplication#::testFilePathscxx . . $ CppUtilities/TestApplication#testFilePaths(f5f2959be38ccc08).() const
112 {
113 return m_testFilesPathscxx . . $ CppUtilities/TestApplication#m_testFilesPaths.;
114 }
115
116 /*!
117 * \brief Returns the directory which is supposed to used for storing files created by tests.
118 */
119 inline const stdcxx . . $ std/::stringcxx . . $ std/string# &TestApplicationcxx . . $ CppUtilities/TestApplication#::workingDirectorycxx . . $ CppUtilities/TestApplication#workingDirectory(f4fff0029955a25f).() const
120 {
121 return m_workingDircxx . . $ CppUtilities/TestApplication#m_workingDir.;
122 }
123
124 /*!
125 * \brief Returns the application path or an empty string if no application path has been set.
126 */
127 inline const char *TestApplicationcxx . . $ CppUtilities/TestApplication#::applicationPathcxx . . $ CppUtilities/TestApplication#applicationPath(33a1f659e94feb42).()
128 {
129 return m_applicationPathArgcxx . . $ CppUtilities/TestApplication#m_applicationPathArg..firstValuecxx . . $ CppUtilities/Argument#firstValue(a9f41ea0e82d88cf).() ? m_applicationPathArgcxx . . $ CppUtilities/TestApplication#m_applicationPathArg..firstValuecxx . . $ CppUtilities/Argument#firstValue(a9f41ea0e82d88cf).() : "";
130 }
131
132 /*!
133 * \brief Returns whether particular units have been specified.
134 */
135 inline bool TestApplicationcxx . . $ CppUtilities/TestApplication#::unitsSpecifiedcxx . . $ CppUtilities/TestApplication#unitsSpecified(50ce9a9e25b4a850).() const
136 {
137 return m_unitsArgcxx . . $ CppUtilities/TestApplication#m_unitsArg..isPresentcxx . . $ CppUtilities/Argument#isPresent(50ce9a9e25b4a850).();
138 }
139
140 /*!
141 * \brief Returns the specified test units.
142 * \remarks The units argument must be present.
143 */
144 inline const stdcxx . . $ std/::vectorcxx . . $ std/vector#<const char *> &TestApplicationcxx . . $ CppUtilities/TestApplication#::unitscxx . . $ CppUtilities/TestApplication#units(6073f6567d110ada).() const
145 {
146 return m_unitsArgcxx . . $ CppUtilities/TestApplication#m_unitsArg..valuescxx . . $ CppUtilities/Argument#values(f310c0743d72f851).();
147 }
148
149 /*!
150 * \brief Returns whether the test application should only list available units and not actually run any tests.
151 */
152 inline bool TestApplicationcxx . . $ CppUtilities/TestApplication#::onlyListUnitscxx . . $ CppUtilities/TestApplication#onlyListUnits(50ce9a9e25b4a850).() const
153 {
154 return m_listArgcxx . . $ CppUtilities/TestApplication#m_listArg..isPresentcxx . . $ CppUtilities/Argument#isPresent(50ce9a9e25b4a850).();
155 }
156
157 /*!
158 * \brief Convenience function to invoke TestApplication::testFilePath().
159 * \remarks A TestApplication must be present.
160 */
161 inline CPP_UTILITIES_EXPORTcxx . . $ `global.h:11:9`! stdcxx . . $ std/::stringcxx . . $ std/string# testFilePathcxx . . $ CppUtilities/testFilePath(fd626fc03107dd24).(const stdcxx . . $ std/::stringcxx . . $ std/string# &relativeTestFilePath)
162 {
163 return TestApplicationcxx . . $ CppUtilities/TestApplication#::instancecxx . . $ CppUtilities/TestApplication#instance(5fe4d5890b105a5c).()->testFilePathcxx . . $ CppUtilities/TestApplication#testFilePath(ed3976f106e8bf8e).(relativeTestFilePath);
164 }
165
166 /*!
167 * \brief Convenience function to invoke TestApplication::testDirPath().
168 * \remarks A TestApplication must be present.
169 */
170 inline CPP_UTILITIES_EXPORTcxx . . $ `global.h:11:9`! stdcxx . . $ std/::stringcxx . . $ std/string# testDirPathcxx . . $ CppUtilities/testDirPath(fd626fc03107dd24).(const stdcxx . . $ std/::stringcxx . . $ std/string# &relativeTestDirPath)
171 {
172 return TestApplicationcxx . . $ CppUtilities/TestApplication#::instancecxx . . $ CppUtilities/TestApplication#instance(5fe4d5890b105a5c).()->testDirPathcxx . . $ CppUtilities/TestApplication#testDirPath(ed3976f106e8bf8e).(relativeTestDirPath);
173 }
174
175 /*!
176 * \brief Convenience function to invoke TestApplication::workingCopyPath().
177 * \remarks A TestApplication must be present.
178 */
179 inline CPP_UTILITIES_EXPORTcxx . . $ `global.h:11:9`! stdcxx . . $ std/::stringcxx . . $ std/string# workingCopyPathcxx . . $ CppUtilities/workingCopyPath(d000395245eb394c).(const stdcxx . . $ std/::stringcxx . . $ std/string# &relativeTestFilePath, WorkingCopyModecxx . . $ CppUtilities/WorkingCopyMode# mode = WorkingCopyModecxx . . $ CppUtilities/WorkingCopyMode#::CreateCopycxx . . $ CppUtilities/WorkingCopyMode#CreateCopy.)
180 {
181 return TestApplicationcxx . . $ CppUtilities/TestApplication#::instancecxx . . $ CppUtilities/TestApplication#instance(5fe4d5890b105a5c).()->workingCopyPathAscxx . . $ CppUtilities/TestApplication#workingCopyPathAs(e656189f96ce13ac).(relativeTestFilePath, relativeTestFilePath, mode);
182 }
183
184 /*!
185 * \brief Convenience function to invoke TestApplication::workingCopyPathAs().
186 * \remarks A TestApplication must be present.
187 */
188 inline CPP_UTILITIES_EXPORTcxx . . $ `global.h:11:9`! stdcxx . . $ std/::stringcxx . . $ std/string# workingCopyPathAscxx . . $ CppUtilities/workingCopyPathAs(f5b3a53c2252d9fc).(
189 const stdcxx . . $ std/::stringcxx . . $ std/string# &relativeTestFilePath, const stdcxx . . $ std/::stringcxx . . $ std/string# &relativeWorkingCopyPath, WorkingCopyModecxx . . $ CppUtilities/WorkingCopyMode# mode = WorkingCopyModecxx . . $ CppUtilities/WorkingCopyMode#::CreateCopycxx . . $ CppUtilities/WorkingCopyMode#CreateCopy.)
190 {
191 return TestApplicationcxx . . $ CppUtilities/TestApplication#::instancecxx . . $ CppUtilities/TestApplication#instance(5fe4d5890b105a5c).()->workingCopyPathAscxx . . $ CppUtilities/TestApplication#workingCopyPathAs(e656189f96ce13ac).(relativeTestFilePath, relativeWorkingCopyPath, mode);
192 }
193
194 #ifdef CPP_UTILITIES_HAS_EXEC_APPcxx . . $ `tests/testutils.h:14:9`!
195 /*!
196 * \brief Convenience function which executes the application to be tested with the specified \a args.
197 * \remarks A TestApplication must be present.
198 * \sa TestApplication::execApp()
199 */
200 inline CPP_UTILITIES_EXPORTcxx . . $ `global.h:11:9`! int execAppcxx . . $ CppUtilities/execApp(ed1051944ce4581b).(const char *const *args, stdcxx . . $ std/::stringcxx . . $ std/string# &output, stdcxx . . $ std/::stringcxx . . $ std/string# &errors)
201 {
202 return TestApplicationcxx . . $ CppUtilities/TestApplication#::instancecxx . . $ CppUtilities/TestApplication#instance(5fe4d5890b105a5c).()->execAppcxx . . $ CppUtilities/TestApplication#execApp(846fd0e56e89d1b1).(args, output, errors);
203 }
204
205 CPP_UTILITIES_EXPORTcxx . . $ `global.h:11:9`! int execHelperAppcxx . . $ CppUtilities/execHelperApp(d8bf812d8f21d316).(
206 const char *appPath, const char *const *args, stdcxx . . $ std/::stringcxx . . $ std/string# &output, stdcxx . . $ std/::stringcxx . . $ std/string# &errors, bool suppressLogging = false, int timeout = -1);
207 CPP_UTILITIES_EXPORTcxx . . $ `global.h:11:9`! int execHelperAppInSearchPathcxx . . $ CppUtilities/execHelperAppInSearchPath(d8bf812d8f21d316).(
208 const char *appName, const char *const *args, stdcxx . . $ std/::stringcxx . . $ std/string# &output, stdcxx . . $ std/::stringcxx . . $ std/string# &errors, bool suppressLogging = false, int timeout = -1);
209 #endif
210
211 /*!
212 * \brief Allows printing std::optional objects so those can be asserted using CPPUNIT_ASSERT_EQUAL.
213 */
214 template <typename Optional, Traitscxx . . $ CppUtilities/Traits/::EnableIfcxx . . $ CppUtilities/Traits/EnableIf#<Traitscxx . . $ CppUtilities/Traits/::IsSpecializationOfcxx . . $ CppUtilities/Traits/IsSpecializationOf#<Optional, stdcxx . . $ std/::optional>> * = nullptr>
215 inline stdcxx . . $ std/::ostreamcxx . . $ std/ostream# &operatorcxx . . $ CppUtilities/`operator<<`(b7de146c9cb6c8f).<<(stdcxx . . $ std/::ostreamcxx . . $ std/ostream# &out, const Optional &optional)
216 {
217 if (optional.has_value()) {
218 return out <<cxx . . $ CppUtilities/`operator<<`(b7de146c9cb6c8f). *optional;
219 } else {
220 return out <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "[no value]";
221 }
222 }
223
224 /*!
225 * \brief The AsHexNumber class allows printing values asserted with cppunit (or similar test framework) using the
226 * hex system in the error case.
227 */
228 template <typename T> class AsHexNumbercxx . . $ CppUtilities/AsHexNumber# {
229 public:
230 /// \brief Constructs a new instance; use asHexNumber() for convenience instead.
231 AsHexNumbercxx . . $ CppUtilities/AsHexNumber#`AsHexNumber<T>`(77d9f17553126ecb).(const T &value)
232 : valuecxx . . $ CppUtilities/AsHexNumber#value.(value)
233 {
234 }
235 const T &valuecxx . . $ CppUtilities/AsHexNumber#value.;
236 };
237
238 /*!
239 * \brief Provides operator == required by CPPUNIT_ASSERT_EQUAL.
240 */
241 template <typename T> bool operatorcxx . . $ CppUtilities/`operator==`(7b314e848a9da27b).==(const AsHexNumbercxx . . $ CppUtilities/AsHexNumber#<T> &lhs, const AsHexNumbercxx . . $ CppUtilities/AsHexNumber#<T> &rhs)
242 {
243 return lhs.valuecxx . . $ CppUtilities/AsHexNumber#value. ==cxx . . $ CppUtilities/`operator==`(7b314e848a9da27b). rhs.valuecxx . . $ CppUtilities/AsHexNumber#value.;
244 }
245
246 /*!
247 * \brief Provides the actual formatting of the output for AsHexNumber class.
248 */
249 template <typename T> stdcxx . . $ std/::ostreamcxx . . $ std/ostream# &operatorcxx . . $ CppUtilities/`operator<<`(29bfed747afd64fc).<<(stdcxx . . $ std/::ostreamcxx . . $ std/ostream# &out, const AsHexNumbercxx . . $ CppUtilities/AsHexNumber#<T> &value)
250 {
251 return out <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '0' <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). 'x' <<cxx . . $ std/basic_ostream#`operator<<`(d90e0e305b0e25c2). stdcxx . . $ std/::hexcxx . . $ std/hex(cf36cc481190cd1f). <<cxx . . $ std/`operator<<`(47f1cf32aeb3f1a2). stdcxx . . $ std/::setfillcxx . . $ std/setfill(ade351e831a1374a).('0') <<cxx . . $ std/`operator<<`(fe9a269018418773). stdcxx . . $ std/::setwcxx . . $ std/setw(f06ce2e9220601fb).(2) <<cxx . . $ std/basic_ostream#`operator<<`(b4c055c363850233). unsigned(value.valuecxx . . $ CppUtilities/AsHexNumber#value.) <<cxx . . $ std/basic_ostream#`operator<<`(d90e0e305b0e25c2). stdcxx . . $ std/::deccxx . . $ std/dec(cf36cc481190cd1f).;
252 }
253
254 /*!
255 * \brief Wraps a value to be printed using the hex system in the error case when asserted
256 * with cppunit (or similar test framework).
257 */
258 template <typename T> AsHexNumbercxx . . $ CppUtilities/AsHexNumber#<T> asHexNumbercxx . . $ CppUtilities/asHexNumber(f51dbe1fdd88683f).(const T &value)
259 {
260 return AsHexNumbercxx . . $ CppUtilities/AsHexNumber#<T>(value);
261 }
262
263 /*!
264 * \brief Wraps a value to be printed using the hex system in the error case when asserted
265 * with cppunit (or similar test framework).
266 * \remarks Only affects integral types. Values of other types are printed as usual.
267 */
268 template <typename T, Traitscxx . . $ CppUtilities/Traits/::EnableIfcxx . . $ CppUtilities/Traits/EnableIf#<stdcxx . . $ std/::is_integral<T>> * = nullptr> AsHexNumbercxx . . $ CppUtilities/AsHexNumber#<T> integralsAsHexNumbercxx . . $ CppUtilities/integralsAsHexNumber(f51dbe1fdd88683f).(const T &value)
269 {
270 return AsHexNumbercxx . . $ CppUtilities/AsHexNumber#<T>(value);
271 }
272
273 /*!
274 * \brief Wraps a value to be printed using the hex system in the error case when asserted
275 * with cppunit (or similar test framework).
276 * \remarks Only affects integral types. Values of other types are printed as usual.
277 */
278 template <typename T, Traitscxx . . $ CppUtilities/Traits/::DisableIfcxx . . $ CppUtilities/Traits/DisableIf#<stdcxx . . $ std/::is_integral<T>> * = nullptr> const T &integralsAsHexNumbercxx . . $ CppUtilities/integralsAsHexNumber(975d6b1eaf7f4b97).(const T &value)
279 {
280 return value;
281 }
282
283 /*!
284 * \brief Asserts successful execution of the application with the specified CLI \a args.
285 *
286 * The application is executed via TestApplication::execApp(). Output is stored in the std::string variables stdout
287 * and stderr.
288 *
289 * \remarks Requires cppunit.
290 */
291 #define TESTUTILS_ASSERT_EXECcxx . . $ `tests/testutils.h:291:9`!(args) TESTUTILS_ASSERT_EXEC_EXIT_STATUS(args, 0)
292
293 /*!
294 * \brief Asserts the execution of the application with the specified CLI \a args and the specified \a expectedExitStatus.
295 *
296 * The application is executed via TestApplication::execApp(). Output is stored in the std::string variables stdout
297 * and stderr.
298 *
299 * \remarks Requires cppunit.
300 */
301 #ifdef CPP_UTILITIES_BOOST_PROCESS
302 #define TESTUTILS_ASSERT_EXEC_EXIT_STATUS(args, expectedExitStatus) \
303 { \
304 const auto status = execApp(args, stdout, stderr); \
305 if (status != expectedExitStatus) { \
306 CPPUNIT_FAIL(::CppUtilities::argsToString( \
307 "app exited with status ", status, " (expected ", expectedExitStatus, ")\nstdout: ", stdout, "\nstderr: ", stderr)); \
308 } \
309 }
310 #else
311 #define TESTUTILS_ASSERT_EXEC_EXIT_STATUScxx . . $ `tests/testutils.h:311:9`!(args, expectedExitStatus) \
312 { \
313 const auto status = execApp(args, stdout, stderr); \
314 if (!WIFEXITED(status)) { \
315 CPPUNIT_FAIL(::CppUtilities::argsToString("app did not terminate normally\nstdout: ", stdout, "\nstderr: ", stderr)); \
316 } \
317 if (const auto exitStatus = WEXITSTATUS(status); exitStatus != expectedExitStatus) { \
318 CPPUNIT_FAIL(::CppUtilities::argsToString( \
319 "app exited with status ", exitStatus, " (expected ", expectedExitStatus, ")\nstdout: ", stdout, "\nstderr: ", stderr)); \
320 } \
321 }
322 #endif
323
324 /*!
325 * \brief Asserts whether the specified \a string matches the specified \a regex.
326 * \remarks Requires cppunit.
327 */
328 #define TESTUTILS_ASSERT_LIKE_FLAGScxx . . $ `tests/testutils.h:328:9`!(message, expectedRegex, regexFlags, actualString) \
329 CPPUNIT_ASSERT_MESSAGE( \
330 CppUtilities::argsToString('\"', actualString, "\"\n not like\n\"", expectedRegex, '\"', "\n\nExpression: " #actualString, message), \
331 (std::regex_match(actualString, std::regex(expectedRegex, regexFlags))))
332 /*!
333 * \brief Asserts whether the specified \a string matches the specified \a regex.
334 * \remarks Requires cppunit.
335 */
336 #define TESTUTILS_ASSERT_LIKEcxx . . $ `tests/testutils.h:336:9`!(message, expectedRegex, actualString) \
337 TESTUTILS_ASSERT_LIKE_FLAGS(message, expectedRegex, std::regex::ECMAScript, actualString)
338
339 /*!
340 * \brief Allows printing pairs so key/values of maps/hashes can be asserted using CPPUNIT_ASSERT_EQUAL.
341 */
342 template <typename Pair, CppUtilitiescxx . . $ CppUtilities/::Traitscxx . . $ CppUtilities/Traits/::EnableIfcxx . . $ CppUtilities/Traits/EnableIf#<CppUtilitiescxx . . $ CppUtilities/::Traitscxx . . $ CppUtilities/Traits/::IsSpecializationOfcxx . . $ CppUtilities/Traits/IsSpecializationOf#<Pair, stdcxx . . $ std/::pair>> * = nullptr>
343 inline stdcxx . . $ std/::ostreamcxx . . $ std/ostream# &operatorcxx . . $ CppUtilities/`operator<<`(b7de146c9cb6c8f).<<(stdcxx . . $ std/::ostreamcxx . . $ std/ostream# &out, const Pair &pair)
344 {
345 return out <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "key: " <<cxx . . $ CppUtilities/`operator<<`(b7de146c9cb6c8f). pair.first <<cxx . . $ CppUtilities/`operator<<`(b7de146c9cb6c8f). "; value: " <<cxx . . $ CppUtilities/`operator<<`(b7de146c9cb6c8f). pair.second <<cxx . . $ CppUtilities/`operator<<`(b7de146c9cb6c8f). '\n';
346 }
347
348 /*!
349 * \brief Allows printing iteratable objects so those can be asserted using CPPUNIT_ASSERT_EQUAL.
350 */
351 template <typename Iteratable, Traitscxx . . $ CppUtilities/Traits/::EnableIfcxx . . $ CppUtilities/Traits/EnableIf#<Traitscxx . . $ CppUtilities/Traits/::IsIteratablecxx . . $ CppUtilities/Traits/IsIteratable#<Iteratable>, Traitscxx . . $ CppUtilities/Traits/::Notcxx . . $ CppUtilities/Traits/Not#<Traitscxx . . $ CppUtilities/Traits/::IsStringcxx . . $ CppUtilities/Traits/IsString#<Iteratable>>> * = nullptr>
352 inline stdcxx . . $ std/::ostreamcxx . . $ std/ostream# &operatorcxx . . $ CppUtilities/`operator<<`(b7de146c9cb6c8f).<<(stdcxx . . $ std/::ostreamcxx . . $ std/ostream# &out, const Iteratable &iteratable)
353 {
354 out <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). '\n';
355 stdcxx . . $ std/::size_tcxx . . $ std/size_t# index = 0;
356 for (const auto &item : iteratable) {
357 out <<cxx . . $ std/`operator<<`(fe9a269018418773). stdcxx . . $ std/::setwcxx . . $ std/setw(f06ce2e9220601fb).(2) <<cxx . . $ std/basic_ostream#`operator<<`(b09cd8ec4365c7ed). index <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ':' <<cxx . . $ std/`operator<<`(dd93bb5737bfac24). ' ' <<cxx . . $ CppUtilities/`operator<<`(b7de146c9cb6c8f). integralsAsHexNumbercxx . . $ CppUtilities/integralsAsHexNumber(975d6b1eaf7f4b97).(item) <<cxx . . $ CppUtilities/`operator<<`(b7de146c9cb6c8f). '\n';
358 ++index;
359 }
360 return out;
361 }
362
363 /*!
364 * \brief Contains literals to ease asserting with CPPUNIT_ASSERT_EQUAL.
365 */
366 namespace Literalscxx . . $ CppUtilities/Literals/ {
367 /*!
368 * \brief Literal for std::size_t to ease asserting std::size_t with CPPUNIT_ASSERT_EQUAL.
369 * \remarks Just using "ul"-suffix does not compile under 32-bit architecture!
370 */
371 constexpr stdcxx . . $ std/::size_tcxx . . $ std/size_t# operatorcxx . . $ CppUtilities/Literals/`operator""_st`(88fcb47b1a0ee4ff).""_st(unsigned long long size)
372 {
373 return static_cast<stdcxx . . $ std/::size_tcxx . . $ std/size_t#>(size);
374 }
375
376 /*!
377 * \brief Literal for uint64 to ease asserting uint64 with CPPUNIT_ASSERT_EQUAL.
378 * \remarks Just using "ul"-suffix does not compile under 32-bit architecture!
379 */
380 constexpr stdcxx . . $ std/::uint64_tcxx . . $ std/uint64_t# operatorcxx . . $ CppUtilities/Literals/`operator""_uint64`(88fcb47b1a0ee4ff).""_uint64(unsigned long long size)
381 {
382 return static_cast<stdcxx . . $ std/::uint64_tcxx . . $ std/uint64_t#>(size);
383 }
384
385 /*!
386 * \brief Literal for int64 to ease asserting int64 with CPPUNIT_ASSERT_EQUAL.
387 * \remarks Just using "l"-suffix does not compile under 32-bit architecture!
388 */
389 constexpr stdcxx . . $ std/::int64_tcxx . . $ std/int64_t# operatorcxx . . $ CppUtilities/Literals/`operator""_int64`(85240eb457c3721a).""_int64(unsigned long long size)
390 {
391 return static_cast<stdcxx . . $ std/::int64_tcxx . . $ std/int64_t#>(size);
392 }
393 } // namespace Literals
394 } // namespace CppUtilities
395
396 #endif // TESTUTILS_H