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