@@ -84,18 +84,48 @@ TEST(ExceptionObject, TestDescriptionFromSpecializedExceptionMacro)
8484
8585
8686// Tests that `ExceptionObject::what()` returns the expected concatenation of
87- // file name, line number, and description.
87+ // file name, line number, location and description.
8888TEST (ExceptionObject, TestWhat)
8989{
90- const itk::ExceptionObject exceptionObject (__FILE__, __LINE__, " test description" );
90+ {
91+ // Test with empty location.
92+ const itk::ExceptionObject exceptionObject (__FILE__, __LINE__, " test description" , " " );
9193
92- const char * const what = exceptionObject.what ();
93- const char * const file = exceptionObject.GetFile ();
94- const char * const description = exceptionObject.GetDescription ();
94+ const char * const what = exceptionObject.what ();
95+ const char * const file = exceptionObject.GetFile ();
96+ const char * const description = exceptionObject.GetDescription ();
9597
96- ASSERT_NE (what, nullptr );
97- ASSERT_NE (file, nullptr );
98- ASSERT_NE (description, nullptr );
98+ ASSERT_NE (what, nullptr );
99+ ASSERT_NE (file, nullptr );
100+ ASSERT_NE (description, nullptr );
99101
100- EXPECT_EQ (what, file + (" :" + std::to_string (exceptionObject.GetLine ()) + " :\n " ) + description);
102+ EXPECT_EQ (what, file + (" :" + std::to_string (exceptionObject.GetLine ()) + " :\n " ) + description);
103+ }
104+ {
105+ // Test with location = ITK_LOCATION (as used by ITK's exception macro's).
106+ const itk::ExceptionObject exceptionObject (__FILE__, __LINE__, " test description" , ITK_LOCATION );
107+
108+ const char * const what = exceptionObject.what ();
109+ const char * const file = exceptionObject.GetFile ();
110+ const char * const description = exceptionObject.GetDescription ();
111+ const char * const location = exceptionObject.GetLocation ();
112+
113+ ASSERT_NE (what, nullptr );
114+ ASSERT_NE (file, nullptr );
115+ ASSERT_NE (description, nullptr );
116+ ASSERT_NE (location, nullptr );
117+
118+
119+ EXPECT_EQ (what,
120+ file + (" :" + std::to_string (exceptionObject.GetLine ()) + " : in '" + location + " ':\n " ) + description);
121+
122+ try
123+ {
124+ itkGenericExceptionMacro (" Oops, something went exceptionally wrong!" );
125+ }
126+ catch (const std::exception & exception)
127+ {
128+ std::cout << exception.what () << ' \n ' ;
129+ }
130+ }
101131}
0 commit comments