CbmRoot
_GTestCbmPsdPoint.cxx
Go to the documentation of this file.
1 #include "CbmPsdPoint.h"
2 
3 #include "gtest/gtest-spi.h"
4 #include "gtest/gtest.h"
5 
6 #include "comparePsdPoint.h"
7 
8 
9 TEST(_GTestCbmPsdPoint, CheckDefaultConstructor) {
10  // Create object
11  CbmPsdPoint test;
12 
14  test, -1, -1, TVector3(0., 0., 0.), TVector3(0., 0., 0.), 0., 0., 0., 0, 0);
15 
16  CbmPsdPoint* test1 = new CbmPsdPoint();
17 
19  -1,
20  -1,
21  TVector3(0., 0., 0.),
22  TVector3(0., 0., 0.),
23  0.,
24  0.,
25  0.,
26  0,
27  0);
28 }
29 
30 TEST(_GTestCbmPsdPoint, CheckStandardConstructor) {
31  Int_t trackid {34};
32  Int_t detid {45};
33  TVector3 pos {-2.1, 6.1, 23.};
34  TVector3 mom {2.5, 4.5, 78.};
35  Double_t tof {34.56};
36  Double_t length {1.2};
37  Double_t eloss {0.4567};
38  Int_t eventid {0};
39  Int_t moduleid {0};
40  // Create object
41  CbmPsdPoint test(trackid, detid, pos, mom, tof, length, eloss);
42 
44  test, trackid, detid, pos, mom, tof, length, eloss, moduleid, eventid);
45 
46  CbmPsdPoint* test1 =
47  new CbmPsdPoint(trackid, detid, pos, mom, tof, length, eloss);
48 
50  *test1, trackid, detid, pos, mom, tof, length, eloss, moduleid, eventid);
51 }
52 
53 TEST(_GTestCbmPsdPoint, CheckCopyConstructor) {
54  Int_t trackid {34};
55  Int_t detid {45};
56  TVector3 pos {-2.1, 6.1, 23.};
57  TVector3 mom {2.5, 4.5, 78.};
58  Double_t tof {34.56};
59  Double_t length {1.2};
60  Double_t eloss {0.4567};
61  Int_t eventid {0};
62  Int_t moduleid {0};
63  // Create object
64  CbmPsdPoint test(trackid, detid, pos, mom, tof, length, eloss);
65 
67  test, trackid, detid, pos, mom, tof, length, eloss, moduleid, eventid);
68 
69  // Create object by copy constructing
70  // test should be equal to test2 and
71  // test should not be changed
72  CbmPsdPoint test2 {test};
73 
75  test2, trackid, detid, pos, mom, tof, length, eloss, moduleid, eventid);
76 
77  // Test if the original object wasn't changed
79  test, trackid, detid, pos, mom, tof, length, eloss, moduleid, eventid);
80 }
81 
82 TEST(_GTestCbmPsdPoint, CheckCopyAssignmentOperator) {
83  Int_t trackid {34};
84  Int_t detid {45};
85  TVector3 pos {-2.1, 6.1, 23.};
86  TVector3 mom {2.5, 4.5, 78.};
87  Double_t tof {34.56};
88  Double_t length {1.2};
89  Double_t eloss {0.4567};
90  Int_t eventid {0};
91  Int_t moduleid {0};
92  // Create object
93  CbmPsdPoint test(trackid, detid, pos, mom, tof, length, eloss);
94 
96  test, trackid, detid, pos, mom, tof, length, eloss, moduleid, eventid);
97 
98  // Create object by copy constructing
99  // test should be equal to test2 and
100  // test should not be changed
101  CbmPsdPoint test2 {};
102  test2 = test;
103 
105  test2, trackid, detid, pos, mom, tof, length, eloss, moduleid, eventid);
106 
107  // Test if the original object wasn't changed
109  test, trackid, detid, pos, mom, tof, length, eloss, moduleid, eventid);
110 }
111 
112 TEST(_GTestCbmPsdPoint, CheckMoveConstructor) {
113  Int_t trackid {34};
114  Int_t detid {45};
115  TVector3 pos {-2.1, 6.1, 23.};
116  TVector3 mom {2.5, 4.5, 78.};
117  Double_t tof {34.56};
118  Double_t length {1.2};
119  Double_t eloss {0.4567};
120  Int_t eventid {0};
121  Int_t moduleid {0};
122  // Create object
123  CbmPsdPoint test(trackid, detid, pos, mom, tof, length, eloss);
124 
126  test, trackid, detid, pos, mom, tof, length, eloss, moduleid, eventid);
127 
128  // Create object by copy constructing
129  // test should be equal to test2 and
130  // test should not be changed
131  CbmPsdPoint test2 {std::move(test)};
132 
134  test2, trackid, detid, pos, mom, tof, length, eloss, moduleid, eventid);
135 
136  // For objects with simple types move fall back to copy so
137  // the original object is kept unchanged
139  test, trackid, detid, pos, mom, tof, length, eloss, moduleid, eventid);
140 }
141 
142 TEST(_GTestCbmPsdPoint, CheckAssignmentOperator) {
143  Int_t trackid {34};
144  Int_t detid {45};
145  TVector3 pos {-2.1, 6.1, 23.};
146  TVector3 mom {2.5, 4.5, 78.};
147  Double_t tof {34.56};
148  Double_t length {1.2};
149  Double_t eloss {0.4567};
150  Int_t eventid {0};
151  Int_t moduleid {0};
152  // Create object
153  CbmPsdPoint test(trackid, detid, pos, mom, tof, length, eloss);
154 
156  test, trackid, detid, pos, mom, tof, length, eloss, moduleid, eventid);
157 
158  // Create object by copy constructing
159  // test should be equal to test2 and
160  // test should not be changed
161  CbmPsdPoint test2 {};
162  test2 = std::move(test);
163 
165  test2, trackid, detid, pos, mom, tof, length, eloss, moduleid, eventid);
166 
167  // For objects with simple types move fall back to copy so
168  // the original object is kept unchanged
170  test, trackid, detid, pos, mom, tof, length, eloss, moduleid, eventid);
171 }
172 
173 TEST(_GTestCbmPsdPoint, CheckSetModuleID) {
174  Int_t trackid {34};
175  Int_t detid {45};
176  TVector3 pos {-2.1, 6.1, 23.};
177  TVector3 mom {2.5, 4.5, 78.};
178  Double_t tof {34.56};
179  Double_t length {1.2};
180  Double_t eloss {0.4567};
181  Int_t eventid {0};
182  Int_t moduleid {0};
183  // Create object
184  CbmPsdPoint test(trackid, detid, pos, mom, tof, length, eloss);
185 
187  test, trackid, detid, pos, mom, tof, length, eloss, moduleid, eventid);
188 
189 
190  test.SetModuleID(111);
191 
193  test, trackid, detid, pos, mom, tof, length, eloss, 111, eventid);
194 }
195 
196 TEST(_GTestCbmPsdPoint, CheckToString) {
197  Int_t trackid {34};
198  Int_t detid {45};
199  TVector3 pos {-2.1, 6.1, 23.};
200  TVector3 mom {2.5, 4.5, 78.};
201  Double_t tof {34.56};
202  Double_t length {1.2};
203  Double_t eloss {0.4567};
204  Int_t eventid {0};
205  Int_t moduleid {0};
206  // Create object
207  CbmPsdPoint test(trackid, detid, pos, mom, tof, length, eloss);
208 
210  test, trackid, detid, pos, mom, tof, length, eloss, moduleid, eventid);
211 
212  EXPECT_STREQ("PSD point for track 34 in detector 45\n Position (-2.1, "
213  "6.1, 23) cm\n Momentum (2.5, 4.5, 78) GeV\n Time 34.56 "
214  "ns, Length 1.2 cm, Energy loss 456700 keV",
215  test.ToString().c_str());
216 }
217 
218 TEST(_GTestCbmPsdPoint, CheckPrint) {
219  Int_t trackid {34};
220  Int_t detid {45};
221  TVector3 pos {-2.1, 6.1, 23.};
222  TVector3 mom {2.5, 4.5, 78.};
223  Double_t tof {34.56};
224  Double_t length {1.2};
225  Double_t eloss {0.4567};
226  Int_t eventid {0};
227  Int_t moduleid {0};
228  // Create object
229  CbmPsdPoint test(trackid, detid, pos, mom, tof, length, eloss);
230 
232  test, trackid, detid, pos, mom, tof, length, eloss, moduleid, eventid);
233 
234  testing::internal::CaptureStdout();
235  test.Print("");
236  std::string output = testing::internal::GetCapturedStdout();
237 
238  EXPECT_STREQ("[INFO] PSD point for track 34 in detector 45\n Position "
239  "(-2.1, 6.1, 23) cm\n Momentum (2.5, 4.5, 78) GeV\n Time "
240  "34.56 ns, Length 1.2 cm, Energy loss 456700 keV\n",
241  output.c_str());
242 }
comparePsdPoint.h
CbmPsdPoint
Definition: CbmPsdPoint.h:24
CbmPsdPoint::ToString
std::string ToString() const
Definition: CbmPsdPoint.cxx:40
TEST
TEST(_GTestCbmPsdPoint, CheckDefaultConstructor)
Definition: _GTestCbmPsdPoint.cxx:9
CbmPsdPoint::Print
virtual void Print(const Option_t *opt) const
Definition: CbmPsdPoint.cxx:36
comparePsdPointDataMembers
void comparePsdPointDataMembers(CbmPsdPoint &test, Int_t trackID, Int_t detID, TVector3 pos, TVector3 mom, Double_t tof, Double_t length, Double_t eLoss, Int_t moduleid, Int_t eventid)
Definition: comparePsdPoint.h:6
pos
TVector3 pos
Definition: CbmMvdSensorDigiToHitTask.cxx:60
CbmPsdPoint::SetModuleID
void SetModuleID(Int_t mod)
Definition: CbmPsdPoint.h:61
CbmPsdPoint.h