~ubuntu-branches/debian/sid/simpleitk/sid

« back to all changes in this revision

Viewing changes to Testing/Unit/sitkExceptionsTests.cxx

  • Committer: Package Import Robot
  • Author(s): Ghislain Antony Vaillant
  • Date: 2017-11-02 08:49:18 UTC
  • Revision ID: package-import@ubuntu.com-20171102084918-7hs09ih668xq87ej
Tags: upstream-1.0.1
ImportĀ upstreamĀ versionĀ 1.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*=========================================================================
 
2
*
 
3
*  Copyright Insight Software Consortium
 
4
*
 
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
 
8
*
 
9
*         http://www.apache.org/licenses/LICENSE-2.0.txt
 
10
*
 
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.
 
16
*
 
17
*=========================================================================*/
 
18
#include "sitkMacro.h"
 
19
 
 
20
#include "SimpleITKTestHarness.h"
 
21
 
 
22
static const char * DESCRIPTION = "We expect this exception";
 
23
 
 
24
class sitkExceptionsTest
 
25
  : public ::testing::Test
 
26
{
 
27
public:
 
28
 
 
29
  void ThrowsitkException( void )
 
30
  {
 
31
    sitkExceptionMacro( << DESCRIPTION );
 
32
  }
 
33
};
 
34
 
 
35
TEST_F(sitkExceptionsTest, Test1) {
 
36
  ASSERT_THROW( ThrowsitkException(), ::itk::simple::GenericException );
 
37
 
 
38
  try
 
39
    {
 
40
    ThrowsitkException();
 
41
    }
 
42
  catch ( ::itk::simple::GenericException &e )
 
43
    {
 
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
 
47
    // exception revision
 
48
    return;
 
49
    }
 
50
 
 
51
  // should gotten that exception
 
52
  FAIL();
 
53
}
 
54
 
 
55
TEST_F(sitkExceptionsTest, Test2) {
 
56
 
 
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" );
 
59
 
 
60
  SUCCEED();
 
61
}
 
62
 
 
63
TEST_F(sitkExceptionsTest, Test3) {
 
64
 
 
65
  // This test is designed to improve coverage of the GenericException class
 
66
 
 
67
  // Default constructor
 
68
  const itk::simple::GenericException empty;
 
69
  itk::simple::GenericException e0;
 
70
 
 
71
 
 
72
  itk::simple::GenericException e1( __FILE__, __LINE__ );
 
73
 
 
74
  itk::simple::GenericException e2( __FILE__, __LINE__, "testing yet another constructor" );
 
75
 
 
76
  // copy constructor
 
77
  itk::simple::GenericException e3( e2 );
 
78
 
 
79
 
 
80
  // asignment
 
81
  e0 = e2;
 
82
  e0 = e1;
 
83
  e0 = empty;
 
84
 
 
85
  // test self assigment too
 
86
  e0 = e0;
 
87
 
 
88
 
 
89
  EXPECT_TRUE( e1 == e1 );
 
90
  EXPECT_TRUE( empty == empty );
 
91
  EXPECT_FALSE( e2 == e1 );
 
92
 
 
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() );
 
99
 
 
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() );
 
107
 
 
108
}