Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
storm_gtest.h
Go to the documentation of this file.
1#pragma once
2#if defined(__clang__)
3#pragma clang diagnostic push
4#pragma clang diagnostic ignored "-Wundef"
5#elif defined(__GNUC__)
6#pragma GCC diagnostic push
7#if __GNUC__ > 8
8
9#endif
10#endif
11
12#include "gtest/gtest.h"
13
14#if defined(__clang__)
15#pragma clang diagnostic pop
16#elif defined(__GNUC__)
17#pragma GCC diagnostic pop
18#endif
19
20#include <boost/optional/optional_io.hpp>
21
25
26namespace testing {
27namespace internal {
28
29inline GTEST_API_ AssertionResult DoubleNearPredFormat(const char* expr1, const char* expr2, const char* abs_error_expr, storm::RationalNumber val1,
30 storm::RationalNumber val2, storm::RationalNumber abs_error) {
31 const storm::RationalNumber diff = storm::utility::abs<storm::RationalNumber>(val1 - val2);
32 if (diff <= abs_error)
33 return AssertionSuccess();
34 return AssertionFailure() << "The difference between " << expr1 << " and " << expr2 << " is " << diff << " (approx. "
35 << storm::utility::convertNumber<double>(diff) << "), which exceeds " << abs_error_expr << ", where\n"
36 << expr1 << " evaluates to " << val1 << " (approx. " << storm::utility::convertNumber<double>(val1) << "),\n"
37 << expr2 << " evaluates to " << val2 << " (approx. " << storm::utility::convertNumber<double>(val2) << "),\n"
38 << abs_error_expr << " evaluates to " << abs_error << " (approx. " << storm::utility::convertNumber<double>(abs_error) << ").";
39}
40} // namespace internal
41} // namespace testing
42
43namespace storm {
44namespace test {
45extern bool noGurobi;
46
48
49inline void initialize(int* argc, char** argv) {
50 // GoogleTest-specific commandline arguments should already be processed before and removed from argc/argv
52 // Only enable error output by default.
53 storm::utility::setLogLevel(l3pp::LogLevel::ERR);
55 for (int i = 1; i < *argc; ++i) {
56 if (std::string(argv[i]) == "--nogurobi") {
57 noGurobi = true;
58 } else {
59 STORM_LOG_WARN("Unknown argument: " << argv[i]);
60 }
61 }
62}
63
64inline void enableErrorOutput() {
65 // Only decrease the log level
66 if (storm::utility::getLogLevel() > l3pp::LogLevel::ERR) {
67 storm::utility::setLogLevel(l3pp::LogLevel::ERR);
68 }
69}
70
71inline void disableOutput() {
72 storm::utility::setLogLevel(l3pp::LogLevel::OFF);
73}
74} // namespace test
75} // namespace storm
76
77// Some tests have to be skipped for specific z3 versions because of a bug that was present in z3.
78#ifdef STORM_HAVE_Z3
79#include <z3.h>
80namespace storm {
81namespace test {
82inline bool z3AtLeastVersion(unsigned expectedMajor, unsigned expectedMinor, unsigned expectedBuildNumber) {
83 std::vector<unsigned> actual(4), expected({expectedMajor, expectedMinor, expectedBuildNumber, 0u});
84 Z3_get_version(&actual[0], &actual[1], &actual[2], &actual[3]);
85 for (uint64_t i = 0; i < 4; ++i) {
86 if (actual[i] > expected[i]) {
87 return true;
88 }
89 if (actual[i] < expected[i]) {
90 return false;
91 }
92 }
93 return true; // Equal versions
94}
95} // namespace test
96} // namespace storm
97#endif
98
99#define STORM_SILENT_ASSERT_THROW(statement, expected_exception) \
100 storm::test::disableOutput(); \
101 ASSERT_THROW(statement, expected_exception); \
102 storm::test::enableErrorOutput()
103
104#define STORM_SILENT_EXPECT_THROW(statement, expected_exception) \
105 storm::test::disableOutput(); \
106 EXPECT_THROW(statement, expected_exception); \
107 storm::test::enableErrorOutput()
#define STORM_LOG_WARN(message)
Definition logging.h:30
bool testGurobiLicense()
void disableOutput()
Definition storm_gtest.h:71
void enableErrorOutput()
Definition storm_gtest.h:64
void initialize(int *argc, char **argv)
Definition storm_gtest.h:49
void initializeLogger()
Initializes the logging framework and sets up logging to console.
void setLogLevel(l3pp::LogLevel level)
Set the global log level.
l3pp::LogLevel getLogLevel()
Gets the global log level.
LabParser.cpp.
Definition cli.cpp:18
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)
Definition storm_gtest.h:29