1 #include "CoreSuite.h"
2 #include "ExceptionTest.h"
3 #include <cppunit/Exception.h>
4
5 #include <memory>
6
7
8 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ExceptionTest,
9 coreSuiteName() );
10
11
ExceptionTest()12 ExceptionTest::ExceptionTest()
13 {
14 }
15
16
~ExceptionTest()17 ExceptionTest::~ExceptionTest()
18 {
19 }
20
21
22 void
setUp()23 ExceptionTest::setUp()
24 {
25 }
26
27
28 void
tearDown()29 ExceptionTest::tearDown()
30 {
31 }
32
33
34 void
testConstructor()35 ExceptionTest::testConstructor()
36 {
37 const CPPUNIT_NS::Message message( "a message" );
38 const CPPUNIT_NS::SourceLine sourceLine( "dir/afile.cpp", 17 );
39
40 CPPUNIT_NS::Exception e( message, sourceLine );
41
42 CPPUNIT_ASSERT_EQUAL( message.shortDescription(), e.message().shortDescription() );
43 CPPUNIT_ASSERT( sourceLine == e.sourceLine() );
44 }
45
46
47 void
testDefaultConstructor()48 ExceptionTest::testDefaultConstructor()
49 {
50 CPPUNIT_NS::Exception e;
51
52 CPPUNIT_ASSERT( CPPUNIT_NS::Message() == e.message() );
53 CPPUNIT_ASSERT( !e.sourceLine().isValid() );
54 }
55
56
57 void
testCopyConstructor()58 ExceptionTest::testCopyConstructor()
59 {
60 CPPUNIT_NS::SourceLine sourceLine( "fileName.cpp", 123 );
61 CPPUNIT_NS::Exception e( CPPUNIT_NS::Message("message"), sourceLine );
62 CPPUNIT_NS::Exception other( e );
63 checkIsSame( e, other );
64 }
65
66
67 void
testAssignment()68 ExceptionTest::testAssignment()
69 {
70 CPPUNIT_NS::SourceLine sourceLine( "fileName.cpp", 123 );
71 CPPUNIT_NS::Exception e( CPPUNIT_NS::Message("message"), sourceLine );
72 CPPUNIT_NS::Exception other;
73 other = e;
74 checkIsSame( e, other );
75 }
76
77
78 void
testClone()79 ExceptionTest::testClone()
80 {
81 CPPUNIT_NS::SourceLine sourceLine( "fileName.cpp", 123 );
82 CPPUNIT_NS::Exception e( CPPUNIT_NS::Message("message"), sourceLine );
83 std::unique_ptr<CPPUNIT_NS::Exception> other( e.clone() );
84 checkIsSame( e, *other.get() );
85 }
86
87
88 void
checkIsSame(CPPUNIT_NS::Exception & e,CPPUNIT_NS::Exception & other)89 ExceptionTest::checkIsSame( CPPUNIT_NS::Exception &e,
90 CPPUNIT_NS::Exception &other )
91 {
92 std::string eWhat( e.what() );
93 std::string otherWhat( other.what() );
94 CPPUNIT_ASSERT_EQUAL( eWhat, otherWhat );
95 CPPUNIT_ASSERT( e.sourceLine() == other.sourceLine() );
96 }
97