Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
storm_gtest.h
Go to the documentation of this file.
1#pragma once
2
3#pragma clang diagnostic push
4#pragma clang diagnostic ignored "-Wundef"
5#include <gtest/gtest.h>
6#pragma clang diagnostic pop
7
8#include <type_traits>
9
10#include <boost/optional/optional_io.hpp>
11
15
16#define STORM_SILENT_ASSERT_THROW(statement, expected_exception) \
17 storm::test::disableOutput(); \
18 ASSERT_THROW(statement, expected_exception); \
19 storm::test::enableErrorOutput()
20
21#define STORM_SILENT_EXPECT_THROW(statement, expected_exception) \
22 storm::test::disableOutput(); \
23 EXPECT_THROW(statement, expected_exception); \
24 storm::test::enableErrorOutput()
25
26// Annotate test cases that are too expensive to run in every CI run (identified via profiling) with STORM_EXPENSIVE_*.
27// These macros expand to gtest's DISABLED_ prefix, so the tests are skipped by default and can be re-enabled at run time
28// without reconfiguring the build, either via --gtest_also_run_disabled_tests or the GTEST_ALSO_RUN_DISABLED_TESTS=1
29// environment variable.
30#define STORM_EXPENSIVE_TEST(test_suite_name, test_name) TEST(test_suite_name, DISABLED_##test_name)
31#define STORM_EXPENSIVE_TEST_F(test_suite_name, test_name) TEST_F(test_suite_name, DISABLED_##test_name)
32#define STORM_EXPENSIVE_TEST_P(test_suite_name, test_name) TEST_P(test_suite_name, DISABLED_##test_name)
33#define STORM_EXPENSIVE_TYPED_TEST(test_suite_name, test_name) TYPED_TEST(test_suite_name, DISABLED_##test_name)
34
35namespace storm::utility {
36// Only declared here so that the overloads below can be, which keeps this header from pulling in the rational number
37// adapter into every test.
38template<typename ValueType>
39class ExtendedNumber;
40} // namespace storm::utility
41
42namespace storm::test {
43template<typename T>
44struct IsExtendedNumber : std::false_type {};
45
46template<typename T>
47struct IsExtendedNumber<storm::utility::ExtendedNumber<T>> : std::true_type {};
48
50template<typename T>
52 typedef T type;
53};
54
55template<typename T>
59
60template<typename T>
62 return value.isInfinite();
63}
64
65template<typename T>
66 requires(!IsExtendedNumber<T>::value)
67bool isInfiniteValue(T const&) {
68 return false;
69}
70
71template<typename T>
73 return value.getFinite();
74}
75
76template<typename T>
77 requires(!IsExtendedNumber<T>::value)
78T const& finiteValue(T const& value) {
79 return value;
80}
81} // namespace storm::test
82
83namespace testing {
84namespace internal {
85
86GTEST_API_ AssertionResult DoubleNearPredFormat(const char* expr1, const char* expr2, const char* abs_error_expr, storm::RationalNumber val1,
87 storm::RationalNumber val2, storm::RationalNumber abs_error);
88
94template<typename T1, typename T2>
96AssertionResult DoubleNearPredFormat(const char* expr1, const char* expr2, const char* abs_error_expr, T1 const& val1, T2 const& val2,
97 typename storm::test::FiniteValueTypeOf<T1>::type const& absError) {
99 // An infinity is within any distance of itself and of nothing else.
100 if (val1 == val2) {
101 return AssertionSuccess();
102 }
103 return AssertionFailure() << "The difference between " << expr1 << " and " << expr2 << " is not within " << abs_error_expr << ", where\n"
104 << expr1 << " evaluates to " << val1 << ",\n"
105 << expr2 << " evaluates to " << val2 << ".";
106 }
107 return DoubleNearPredFormat(expr1, expr2, abs_error_expr, storm::test::finiteValue(val1), storm::test::finiteValue(val2), absError);
108}
109} // namespace internal
110} // namespace testing
111
112namespace storm {
113namespace test {
114extern bool noGurobi;
115
116void initialize(int* argc, char** argv);
117
118inline void enableErrorOutput() {
119 // Only decrease the log level
120 if (storm::utility::getLogLevel() > l3pp::LogLevel::ERR) {
121 storm::utility::setLogLevel(l3pp::LogLevel::ERR);
122 }
123}
124
125inline void disableOutput() {
126 storm::utility::setLogLevel(l3pp::LogLevel::OFF);
127}
128
129// Check for valid Gurobi license
130bool testGurobiLicense();
131
132// Some tests have to be skipped for specific z3 versions because of a bug that was present in z3.
133#ifdef STORM_HAVE_Z3
134bool z3AtLeastVersion(unsigned expectedMajor, unsigned expectedMinor, unsigned expectedBuildNumber);
135#endif
136} // namespace test
137} // namespace storm
A value of ValueType extended with the two infinities -infinity and +infinity.
ValueType const & getFinite() const
bool testGurobiLicense()
void disableOutput()
void enableErrorOutput()
void initialize(int *argc, char **argv)
T const & finiteValue(storm::utility::ExtendedNumber< T > const &value)
Definition storm_gtest.h:72
bool isInfiniteValue(storm::utility::ExtendedNumber< T > const &value)
Definition storm_gtest.h:61
void setLogLevel(l3pp::LogLevel level)
Set the global log level.
l3pp::LogLevel getLogLevel()
Gets the global log level.
GTEST_API_ AssertionResult DoubleNearPredFormat(const char *expr1, const char *expr2, const char *abs_error_expr, storm::RationalNumber val1, storm::RationalNumber val2, storm::RationalNumber abs_error)
The value type underlying a possibly extended one.
Definition storm_gtest.h:51