ATLAS Offline Software
Loading...
Searching...
No Matches
UnitTest.h File Reference
#include <AsgMessaging/MessageCheck.h>
#include <AsgMessaging/MessagePrinterErrorCollect.h>
#include <AsgMessaging/MessagePrinterOverlay.h>
#include <string>
#include <exception>
#include <gtest/gtest.h>
Include dependency graph for Control/AthToolSupport/AsgTesting/AsgTesting/UnitTest.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  asg
namespace  asg::detail

Macros

#define ASSERT_SUCCESS(x)
#define EXPECT_SUCCESS(x)
#define ASSERT_FAILURE(x)
#define EXPECT_FAILURE(x)
#define ASSERT_FAILURE_REGEX(x, regex)
#define EXPECT_FAILURE_REGEX(x, regex)
#define ASSERT_THROW_REGEX(x, regex)
#define EXPECT_THROW_REGEX(x, regex)
#define ASSERT_MATCH_REGEX(reg, str)
#define EXPECT_MATCH_REGEX(reg, str)
#define ATLAS_GOOGLE_TEST_MAIN

Functions

bool asg::detail::matchesRegex (const std::string &regex, const std::string &str)
 return whether str matches regex

Macro Definition Documentation

◆ ASSERT_FAILURE

#define ASSERT_FAILURE ( x)
Value:
ASSERT_EQ (asg::CheckHelper<decltype(x)>::failureCode(), x)
#define x
this is an internal traits class for status codes used by the ANA_CHECK* macros

Definition at line 41 of file Control/AthToolSupport/AsgTesting/AsgTesting/UnitTest.h.

41#define ASSERT_FAILURE(x) \
42 ASSERT_EQ (asg::CheckHelper<decltype(x)>::failureCode(), x)

◆ ASSERT_FAILURE_REGEX

#define ASSERT_FAILURE_REGEX ( x,
regex )
Value:

Definition at line 49 of file Control/AthToolSupport/AsgTesting/AsgTesting/UnitTest.h.

49#define ASSERT_FAILURE_REGEX(x,regex) \
50 ASSERT_FAILURE(x)

◆ ASSERT_MATCH_REGEX

#define ASSERT_MATCH_REGEX ( reg,
str )
Value:
ASSERT_PRED2 (::asg::detail::matchesRegex, reg, str)
bool matchesRegex(const std::string &regex, const std::string &str)
return whether str matches regex

Definition at line 106 of file Control/AthToolSupport/AsgTesting/AsgTesting/UnitTest.h.

106#define ASSERT_MATCH_REGEX(reg,str) \
107 ASSERT_PRED2 (::asg::detail::matchesRegex, reg, str)

◆ ASSERT_SUCCESS

#define ASSERT_SUCCESS ( x)
Value:
ASSERT_EQ (asg::CheckHelper<decltype(x)>::successCode(), x)

Definition at line 35 of file Control/AthToolSupport/AsgTesting/AsgTesting/UnitTest.h.

35#define ASSERT_SUCCESS(x) \
36 ASSERT_EQ (asg::CheckHelper<decltype(x)>::successCode(), x)

◆ ASSERT_THROW_REGEX

#define ASSERT_THROW_REGEX ( x,
regex )
Value:
{ std::string internalTestMessage; try { \
x; internalTestMessage = std::string ("expected statement ") + #x " to throw, but it didn't"; \
} catch (std::exception& e) { \
if (!::asg::detail::matchesRegex ((regex), e.what())) { \
internalTestMessage = std::string ("expected statement ") + #x " to throw message matching " + (regex) + ", but actual message didn't match: " + e.what(); \
} } catch (...) { \
internalTestMessage = std::string ("statement ") + #x " threw an exception that didn't derive from std::exception"; } \
if (!internalTestMessage.empty()) \
FAIL() << internalTestMessage; \
else SUCCEED(); }

Definition at line 82 of file Control/AthToolSupport/AsgTesting/AsgTesting/UnitTest.h.

82#define ASSERT_THROW_REGEX(x,regex) \
83 { std::string internalTestMessage; try { \
84 x; internalTestMessage = std::string ("expected statement ") + #x " to throw, but it didn't"; \
85 } catch (std::exception& e) { \
86 if (!::asg::detail::matchesRegex ((regex), e.what())) { \
87 internalTestMessage = std::string ("expected statement ") + #x " to throw message matching " + (regex) + ", but actual message didn't match: " + e.what(); \
88 } } catch (...) { \
89 internalTestMessage = std::string ("statement ") + #x " threw an exception that didn't derive from std::exception"; } \
90 if (!internalTestMessage.empty()) \
91 FAIL() << internalTestMessage; \
92 else SUCCEED(); }

◆ ATLAS_GOOGLE_TEST_MAIN

#define ATLAS_GOOGLE_TEST_MAIN
Value:
int main (int argc, char **argv) \
{ \
::testing::InitGoogleTest (&argc, argv); \
return RUN_ALL_TESTS(); \
}
int main()
Definition hello.cxx:18

Definition at line 116 of file Control/AthToolSupport/AsgTesting/AsgTesting/UnitTest.h.

116#define ATLAS_GOOGLE_TEST_MAIN \
117 int main (int argc, char **argv) \
118 { \
119 ::testing::InitGoogleTest (&argc, argv); \
120 return RUN_ALL_TESTS(); \
121 }

◆ EXPECT_FAILURE

#define EXPECT_FAILURE ( x)
Value:
EXPECT_EQ (asg::CheckHelper<decltype(x)>::failureCode(), x)

Definition at line 44 of file Control/AthToolSupport/AsgTesting/AsgTesting/UnitTest.h.

44#define EXPECT_FAILURE(x) \
45 EXPECT_EQ (asg::CheckHelper<decltype(x)>::failureCode(), x)

◆ EXPECT_FAILURE_REGEX

#define EXPECT_FAILURE_REGEX ( x,
regex )
Value:

Definition at line 51 of file Control/AthToolSupport/AsgTesting/AsgTesting/UnitTest.h.

51#define EXPECT_FAILURE_REGEX(x,regex) \
52 EXPECT_FAILURE(x)

◆ EXPECT_MATCH_REGEX

#define EXPECT_MATCH_REGEX ( reg,
str )
Value:
EXPECT_PRED2 (::asg::detail::matchesRegex, reg, str)

Definition at line 109 of file Control/AthToolSupport/AsgTesting/AsgTesting/UnitTest.h.

109#define EXPECT_MATCH_REGEX(reg,str) \
110 EXPECT_PRED2 (::asg::detail::matchesRegex, reg, str)

◆ EXPECT_SUCCESS

#define EXPECT_SUCCESS ( x)
Value:
EXPECT_EQ (asg::CheckHelper<decltype(x)>::successCode(), x)

Definition at line 38 of file Control/AthToolSupport/AsgTesting/AsgTesting/UnitTest.h.

38#define EXPECT_SUCCESS(x) \
39 EXPECT_EQ (asg::CheckHelper<decltype(x)>::successCode(), x)

◆ EXPECT_THROW_REGEX

#define EXPECT_THROW_REGEX ( x,
regex )
Value:
{ std::string internalTestMessage; try { \
x; internalTestMessage = std::string ("expected statement ") + #x " to throw, but it didn't"; \
} catch (std::exception& e) { \
if (!::asg::detail::matchesRegex ((regex), e.what())) { \
internalTestMessage = std::string ("expected statement ") + #x " to throw message matching " + (regex) + ", but actual message didn't match: " + e.what(); \
} } catch (...) { \
internalTestMessage = std::string ("statement ") + #x " threw an exception that didn't derive from std::exception"; } \
if (!internalTestMessage.empty()) \
ADD_FAILURE() << internalTestMessage; \
else SUCCEED(); }

Definition at line 94 of file Control/AthToolSupport/AsgTesting/AsgTesting/UnitTest.h.

94#define EXPECT_THROW_REGEX(x,regex) \
95 { std::string internalTestMessage; try { \
96 x; internalTestMessage = std::string ("expected statement ") + #x " to throw, but it didn't"; \
97 } catch (std::exception& e) { \
98 if (!::asg::detail::matchesRegex ((regex), e.what())) { \
99 internalTestMessage = std::string ("expected statement ") + #x " to throw message matching " + (regex) + ", but actual message didn't match: " + e.what(); \
100 } } catch (...) { \
101 internalTestMessage = std::string ("statement ") + #x " threw an exception that didn't derive from std::exception"; } \
102 if (!internalTestMessage.empty()) \
103 ADD_FAILURE() << internalTestMessage; \
104 else SUCCEED(); }