ATLAS Offline Software
Loading...
Searching...
No Matches
Assert.cxx
Go to the documentation of this file.
1// - 2012.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at
4// http://www.boost.org/LICENSE_1_0.txt)
5
6// Please feel free to contact me (krumnack@iastate.edu) for bug
7// reports, feature suggestions, praise and complaints.
8
9
10//
11// includes
12//
13
15
16#include <cstdlib>
17#include <string>
20
21//
22// method implementations
23//
24
25namespace RCU
26{
27 namespace Check
28 {
29 const char * const typeLiteral [typeNum] =
30 {
31 "assertion failed",
32 "assertion failed",
33 "assertion failed",
34
35 "requirement failed",
36 "requirement failed",
37 "requirement failed",
38
39 "postcondition violated",
40 "postcondition violated",
41 "postcondition violated",
42
43 "invariant violated"
44 };
45
46
47
48 const bool typeAbort [typeNum] =
49 {
50 false,
51 true,
52 true,
53
54 false,
55 true,
56 true,
57
58 false,
59 true,
60 true,
61
62 true,
63 };
64
65
66
67 void fail (const char *package, const char *file, unsigned line,
68 Type type, const char *error)
69 {
70 RCU_REQUIRE (file != 0);
71 RCU_REQUIRE (line != 0);
73 RCU_REQUIRE (error != 0);
74
76 msg.package = package;
77 msg.file = file;
78 msg.line = line;
80
81 std::string mymessage = typeLiteral[type];
82 mymessage += ": ";
83 mymessage += error;
84 msg.message = mymessage.c_str();
85
86 msg.send();
87 }
88
89
90
91 TestInvariant ::
92 TestInvariant (TestInvariantFunction function,
93 const void *object)
94 : m_function (function), m_object (object)
95 {
96 (*m_function) (m_object);
97 }
98
99
100
101 TestInvariant ::
102 ~TestInvariant ()
103 {
104 (*m_function) (m_object);
105 }
106
107
108
110 const void *object)
111 {
112 try
113 {
114 (*function) (object);
115 return false;
116 } catch (std::exception& e)
117 {
118 RCU_ERROR_MSG (e.what());
119 return true;
120 };
121 }
122 }
123}
#define RCU_REQUIRE(x)
Definition Assert.h:208
#define RCU_ERROR_MSG(message)
Definition PrintMsg.h:55
const bool typeAbort[typeNum]
Definition Assert.cxx:48
const int typeNum
Definition Assert.h:75
void fail(const char *package, const char *file, unsigned line, Type type, const char *error)
effects: report the error and abort either by exception or assert like guarantee: all-fail failures: ...
Definition Assert.cxx:67
bool testInvariantPrint(TestInvariantFunction function, const void *object)
Definition Assert.cxx:109
void(* TestInvariantFunction)(const void *object)
effects: apply the test invariant method on an object guarantee: no-fail availability: experts only r...
Definition Assert.h:98
const char *const typeLiteral[typeNum]
Definition Assert.cxx:29
This module defines a variety of assert style macros.
Definition Assert.cxx:26
@ MESSAGE_ABORT
description: print and abort
Definition MessageType.h:38
@ MESSAGE_EXCEPTION
description: send out an exception
Definition MessageType.h:35
const void * m_object
Definition Assert.h:119
TestInvariantFunction m_function
Definition Assert.h:118
MsgStream & msg
Definition testRead.cxx:32
TFile * file