CbmRoot
_GTestCbmHit.cxx
Go to the documentation of this file.
1 #include "CbmHit.h"
2 
3 #include "CbmMatch.h"
4 
5 #include "gtest/gtest-spi.h"
6 #include "gtest/gtest.h"
7 
8 #include "compareHit.h"
9 #include "compareMatch.h"
10 
11 // Since some functions in CbmHit are protected we have
12 // to create a derived class without any data members
13 // which simply forwards the function
14 // calls to the base class
15 class CbmTestHit : public CbmHit {
16 public:
17  CbmTestHit() : CbmHit() { ; }
18 
20  CbmTestHit(const CbmTestHit& hit) : CbmHit(hit) { ; }
21 
23  virtual ~CbmTestHit() { ; }
24 
26  CbmTestHit& operator=(const CbmTestHit& other) {
27  if (this != &other) { CbmHit::operator=(other); }
28  return *this;
29  }
30 };
31 
32 TEST(_GTestCbmHit, CheckDefaultConstructor) {
33  CbmHit test;
34  compareHitDataMembers(test, kHIT, 0., 0., -1, -1, nullptr, -1., -1.);
35 }
36 
37 TEST(_GTestCbmHit, CheckStandardConstructor) {
38  CbmHit test {kHIT, 0., 0., -1, -1};
39  compareHitDataMembers(test, kHIT, 0., 0., -1, -1, nullptr, -1., -1.);
40 }
41 
42 TEST(_GTestCbmHit, CheckStandardConstructorWithTime) {
43  CbmHit test {kHIT, 0., 0., -1, -1, -2., -2.};
44  compareHitDataMembers(test, kHIT, 0., 0., -1, -1, nullptr, -2., -2.);
45 }
46 
47 TEST(_GTestCbmHit, CheckCopyConstructor) {
48  CbmTestHit test;
49  {
50  SCOPED_TRACE("CheckCopyConstructor: Initial Test");
51  compareHitDataMembers(test, kHIT, 0., 0., -1, -1, nullptr, -1., -1.);
52  }
53 
54  CbmMatch* testMatch = new CbmMatch();
55 
56  compareMatchDataMembers(*testMatch, 0, 0.);
57 
58  test.SetMatch(testMatch);
59  {
60  SCOPED_TRACE("CheckCopyConstructor: Test with CbmMatch");
61  compareHitDataMembers(test, kHIT, 0., 0., -1, -1, testMatch, -1., -1.);
62  }
63 
64  CbmTestHit test2 {test};
65 
66  // Test if the new object has the same values for all data members
67  // as the original object
68  CbmMatch* testMatch1 = test2.GetMatch();
69 
70  EXPECT_EQ(nullptr, testMatch1);
71  if (testMatch1) { compareMatchDataMembers(*testMatch1, 0, 0.); }
72 
73  {
74  SCOPED_TRACE(
75  "CheckCopyConstructor: Test new object after copy construction");
76  compareHitDataMembers(test2, kHIT, 0., 0., -1, -1, nullptr, -1., -1.);
77  }
78  // Test if the original object wasn't changed
79  {
80  SCOPED_TRACE(
81  "CheckCopyConstructor: Test original object after copy construction");
82  compareHitDataMembers(test, kHIT, 0., 0., -1, -1, testMatch, -1., -1.);
83  }
84 }
85 
86 
87 TEST(_GTestCbmHit, CheckAssignmentOperator) {
88  CbmTestHit test;
89  {
90  SCOPED_TRACE("CheckAssignmentOperator: Initial Test");
91  compareHitDataMembers(test, kHIT, 0., 0., -1, -1, nullptr, -1., -1.);
92  }
93 
94  CbmMatch* testMatch = new CbmMatch();
95 
96  compareMatchDataMembers(*testMatch, 0, 0.);
97 
98  test.SetMatch(testMatch);
99  {
100  SCOPED_TRACE("CheckAssignmentOperator: Test with CbmMatch");
101  compareHitDataMembers(test, kHIT, 0., 0., -1, -1, testMatch, -1., -1.);
102  }
103 
104  CbmTestHit test2;
105  test2 = test;
106 
107  // Test if the new object has the same values for all data members
108  // as the original object
109  CbmMatch* testMatch1 = test2.GetMatch();
110 
111  EXPECT_EQ(nullptr, testMatch1);
112  if (testMatch1) { compareMatchDataMembers(*testMatch1, 0, 0.); }
113 
114  {
115  SCOPED_TRACE("CheckAssignmentOperator: Test new object after assignment");
116  compareHitDataMembers(test2, kHIT, 0., 0., -1, -1, nullptr, -1., -1.);
117  }
118  // Test if the original object wasn't changed
119  {
120  SCOPED_TRACE(
121  "CheckAssignmentOperator: Test original object after assignment");
122  compareHitDataMembers(test, kHIT, 0., 0., -1, -1, testMatch, -1., -1.);
123  }
124 }
125 
126 TEST(_GTestCbmHit, TestSettersAndGetters) {
127  CbmHit test;
128  compareHitDataMembers(test, kHIT, 0., 0., -1, -1, nullptr, -1., -1.);
129 
130  test.SetZ(-2.);
131  compareHitDataMembers(test, kHIT, -2., 0., -1, -1, nullptr, -1., -1.);
132 
133  test.SetDz(-2.);
134  compareHitDataMembers(test, kHIT, -2., -2., -1, -1, nullptr, -1., -1.);
135 
136  test.SetRefId(-2);
137  compareHitDataMembers(test, kHIT, -2., -2., -2, -1, nullptr, -1., -1.);
138 
139  test.SetAddress(-2);
140  compareHitDataMembers(test, kHIT, -2., -2., -2, -2, nullptr, -1., -1.);
141 
142  test.SetTime(-2.);
143  compareHitDataMembers(test, kHIT, -2., -2., -2, -2, nullptr, -2., -1.);
144 
145  test.SetTimeError(-2.);
146  compareHitDataMembers(test, kHIT, -2., -2., -2, -2, nullptr, -2., -2.);
147 
148  test.SetTime(-3., -3.);
149  compareHitDataMembers(test, kHIT, -2., -2., -2, -2, nullptr, -3., -3.);
150 
151  Int_t retValInt = test.GetPlaneId();
152  EXPECT_EQ(-1, retValInt);
153 
154  // Test if we can add an empty CbmMatch, get it back, and extract
155  // the expected values
156  CbmMatch* testMatch = new CbmMatch();
157 
158  compareMatchDataMembers(*testMatch, 0, 0.);
159 
160  test.SetMatch(testMatch);
161  CbmMatch* testMatch1 = test.GetMatch();
162 
163  compareMatchDataMembers(*testMatch1, 0, 0.);
164 }
165 
166 TEST(_GTestCbmHit, ToString) {
167  CbmHit test {kHIT, 0., 0., -1, -1};
168  EXPECT_STREQ("Has to be implemented in derrived class",
169  test.ToString().c_str());
170 }
CbmMatch
Definition: CbmMatch.h:22
CbmTestHit
Definition: _GTestCbmHit.cxx:15
compareMatch.h
CbmHit::SetDz
void SetDz(Double_t dz)
Definition: CbmHit.h:80
TEST
TEST(_GTestCbmHit, CheckDefaultConstructor)
Definition: _GTestCbmHit.cxx:32
compareHitDataMembers
void compareHitDataMembers(CbmHit &test, HitType type, Double_t z, Double_t dz, Int_t refid, Int_t address, CbmMatch *match, Double_t time, Double_t errortime)
Definition: compareHit.h:9
CbmHit::SetAddress
void SetAddress(Int_t address)
Definition: CbmHit.h:82
CbmTestHit::CbmTestHit
CbmTestHit(const CbmTestHit &hit)
Definition: _GTestCbmHit.cxx:20
compareHit.h
CbmMatch.h
CbmHit::GetPlaneId
virtual Int_t GetPlaneId() const
Definition: CbmHit.h:97
CbmHit::SetRefId
void SetRefId(Int_t refId)
Definition: CbmHit.h:81
CbmHit::GetMatch
CbmMatch * GetMatch() const
Definition: CbmHit.h:74
CbmHit.h
kHIT
@ kHIT
Definition: CbmHit.h:17
compareMatchDataMembers
void compareMatchDataMembers(CbmMatch &testMatch, Int_t noflinks, Double_t weight)
Definition: compareMatch.h:7
CbmHit::SetTimeError
void SetTimeError(Double_t error)
Definition: CbmHit.h:89
CbmHit::SetTime
void SetTime(Double_t time)
Definition: CbmHit.h:84
CbmHit::operator=
CbmHit & operator=(const CbmHit &)
Definition: CbmHit.cxx:46
CbmHit::SetZ
void SetZ(Double_t z)
Definition: CbmHit.h:79
CbmTestHit::operator=
CbmTestHit & operator=(const CbmTestHit &other)
Definition: _GTestCbmHit.cxx:26
CbmHit
Definition: CbmHit.h:38
CbmTestHit::CbmTestHit
CbmTestHit()
Definition: _GTestCbmHit.cxx:17
CbmHit::SetMatch
void SetMatch(CbmMatch *match)
Definition: CbmHit.cxx:66
CbmTestHit::~CbmTestHit
virtual ~CbmTestHit()
Definition: _GTestCbmHit.cxx:23
Cbm::ToString
std::string ToString(const T &value)
Definition: CbmUtils.h:16