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