19 #include <itkObject.h>
20 #include <itkObjectFactory.h>
29 class ExceptionTestClass :
public itk::Object
33 itkFactorylessNewMacro(Self) itkCloneMacro(Self)
35 void throwExceptionManually()
42 void throwSpecializedExceptionManually()
46 throw SpecializedTestException(
"test.cpp", 155,
"",
"");
49 void throwExceptionManually(std::string message1, std::string message2)
53 throw mitk::Exception(
"testfile.cpp", 155, message1.c_str(),
"") << message2;
56 void throwExceptionWithThrowMacro() {
mitkThrow() <<
"TEST EXCEPION THROWING WITH mitkThrow()"; }
57 void throwExceptionWithThrowMacro(std::string message) {
mitkThrow() << message.c_str(); }
59 void throwSpecializedExceptionWithThrowMacro2(std::string message)
64 void reThrowExceptionWithReThrowMacro(std::string messageThrow, std::string messageReThrow)
68 throwExceptionWithThrowMacro(messageThrow);
76 static void TestExceptionConstructor()
78 bool exceptionThrown =
false;
82 myExceptionTestObject->throwExceptionManually();
86 exceptionThrown =
true;
90 exceptionThrown =
false;
93 myExceptionTestObject->throwSpecializedExceptionManually();
95 catch (SpecializedTestException)
97 exceptionThrown =
true;
100 "Testing constructor specialized exception (deriving from mitkException)");
103 static void TestExceptionMessageStream()
109 myException <<
" and additional stream";
111 "Testing mitkException message stream (adding std::string)");
113 myException.SetDescription(
"testmessage2");
114 myException <<
' ' <<
'a' <<
'n' <<
'd' <<
' ' <<
'c' <<
'h' <<
'a' <<
'r' <<
's';
116 "Testing mitkException message stream (adding single chars)");
118 myException.SetDescription(
"testmessage3");
119 myException << myException;
121 "Testing mitkException message stream (adding object)");
123 SpecializedTestException mySpecializedException =
124 SpecializedTestException(
"testfile.cpp", 111,
"testmessage",
"test");
125 mySpecializedException <<
" and additional stream";
127 mySpecializedException.GetDescription() == std::string(
"testmessage and additional stream"),
128 "Testing specialized exception message stream (adding std::string)");
131 static void TestExceptionMessageStreamThrowing()
133 bool exceptionThrown =
false;
135 std::string thrownMessage =
"";
138 myExceptionTestObject->throwExceptionManually(
"message1",
" and message2");
142 thrownMessage = e.GetDescription();
143 exceptionThrown =
true;
146 "Testing throwing and streaming of mitk::Exception together.")
149 static void TestMitkThrowMacro()
151 bool exceptionThrown =
false;
158 myExceptionTestObject->throwExceptionWithThrowMacro();
162 exceptionThrown =
true;
168 exceptionThrown =
false;
169 std::string messageText =
"";
173 myExceptionTestObject->throwExceptionWithThrowMacro(
"test123");
177 exceptionThrown =
true;
178 messageText = e.GetDescription();
181 "Testing message test of mitkThrow()");
185 exceptionThrown =
false;
190 myExceptionTestObject->throwSpecializedExceptionWithThrowMacro(
"test123");
194 exceptionThrown =
true;
195 messageText = e.GetDescription();
198 "Testing special exception with mitkThrow(mitk::Exception)");
202 exceptionThrown =
false;
207 myExceptionTestObject->throwSpecializedExceptionWithThrowMacro2(
"test123");
209 catch (SpecializedTestException &e)
211 exceptionThrown =
true;
212 messageText = e.GetDescription();
215 "Testing special exception with mitkThrow(mitk::SpecializedException)");
218 static void TestRethrowInformation()
227 "Testing GetNumberOfRethrows() with empty rethrow information");
231 std::string file =
"invalid";
233 std::string message =
"invalid";
236 "Testing GetRethrowData() with invalid rethrow number (negative).");
241 std::string file =
"invalid";
243 std::string message =
"invalid";
246 "Testing GetRethrowData() with non-existing rethrow number (0).");
251 std::string file =
"invalid";
253 std::string message =
"invalid";
256 "Testing GetRethrowData() with non-existing rethrow number (1).");
267 std::string file =
"invalid";
269 std::string message =
"invalid";
272 "Testing stored information of first rethrow.");
276 std::string file =
"invalid";
278 std::string message =
"invalid";
281 "Testing stored information of second rethrow.");
285 static void TestRethrowMacro()
287 bool exceptionThrown =
false;
288 std::string message =
"";
295 myExceptionTestObject->reThrowExceptionWithReThrowMacro(
"Test original message.",
"Test rethrow message.");
299 message = e.GetDescription();
300 exceptionThrown =
true;
304 "Testing message/descriprion after rethrow.")
311 ExceptionTestClass::TestExceptionConstructor();
312 ExceptionTestClass::TestExceptionMessageStream();
313 ExceptionTestClass::TestExceptionMessageStreamThrowing();
314 ExceptionTestClass::TestMitkThrowMacro();
315 ExceptionTestClass::TestRethrowInformation();
316 ExceptionTestClass::TestRethrowMacro();
itk::SmartPointer< Self > Pointer
void AddRethrowData(const char *file, unsigned int lineNumber, const char *message)
Adds rethrow data to this exception.
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
#define mitkReThrow(mitkexception)
void GetRethrowData(int rethrowNumber, std::string &file, int &line, std::string &message)
int mitkExceptionTest(int, char *[])
int GetNumberOfRethrows()
An object of this class represents an exception of MITK. Please don't instantiate exceptions manually...
#define mitkClassMacroItkParent(className, SuperClassName)
#define mitkExceptionClassMacro(ClassName, SuperClassName)
#define mitkThrowException(classname)
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.