1
/*=========================================================================
3
* Copyright Insight Software Consortium
5
* Licensed under the Apache License, Version 2.0 (the "License");
6
* you may not use this file except in compliance with the License.
7
* You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0.txt
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
17
*=========================================================================*/
18
#include "sitkMacro.h"
20
#include "SimpleITKTestHarness.h"
22
static const char * DESCRIPTION = "We expect this exception";
24
class sitkExceptionsTest
25
: public ::testing::Test
29
void ThrowsitkException( void )
31
sitkExceptionMacro( << DESCRIPTION );
35
TEST_F(sitkExceptionsTest, Test1) {
36
ASSERT_THROW( ThrowsitkException(), ::itk::simple::GenericException );
42
catch ( ::itk::simple::GenericException &e )
44
// could do some nifty testing here too
45
EXPECT_EQ ( e.GetNameOfClass(), std::string("GenericException") );
46
//EXPECT_NE ( std::string ( e.GetLocation() ), "" ); HACK FIXME
51
// should gotten that exception
55
TEST_F(sitkExceptionsTest, Test2) {
57
// this can only be tested when true, if it was false the file won't compile
58
sitkStaticAssert( true, "this is just a test" );
63
TEST_F(sitkExceptionsTest, Test3) {
65
// This test is designed to improve coverage of the GenericException class
67
// Default constructor
68
const itk::simple::GenericException empty;
69
itk::simple::GenericException e0;
72
itk::simple::GenericException e1( __FILE__, __LINE__ );
74
itk::simple::GenericException e2( __FILE__, __LINE__, "testing yet another constructor" );
77
itk::simple::GenericException e3( e2 );
85
// test self assigment too
89
EXPECT_TRUE( e1 == e1 );
90
EXPECT_TRUE( empty == empty );
91
EXPECT_FALSE( e2 == e1 );
93
EXPECT_NO_THROW( e2.ToString() );
94
EXPECT_NO_THROW( e2.GetLocation() );
95
EXPECT_NO_THROW( e2.GetDescription() );
96
EXPECT_NO_THROW( e2.GetFile() );
97
EXPECT_NO_THROW( e2.GetLine() );
98
EXPECT_NO_THROW( e2.what() );
100
// check accessor for empty/null
101
EXPECT_NO_THROW( empty.ToString() );
102
EXPECT_NO_THROW( empty.GetLocation() );
103
EXPECT_NO_THROW( empty.GetDescription() );
104
EXPECT_NO_THROW( empty.GetFile() );
105
EXPECT_NO_THROW( empty.GetLine() );
106
EXPECT_NO_THROW( empty.what() );